BreweryControlSystem/code/src/payment_tab.rs

54 lines
1.4 KiB
Rust

use crate::{
database::DBOperator,
tab::{TABS_CAN_BE_WINDOWS, Tab, TabTypes},
};
/*
* Я не придумал, зачем я сделал данный файл. Мой глупый разум решил, что он нужен.
*/
pub struct PaymentTabViewer {
db_oper: DBOperator,
is_admin: bool,
rt: tokio::runtime::Runtime,
}
impl PaymentTabViewer {
pub fn new(is_admin: bool) -> Self {
Self {
is_admin,
..Default::default()
}
}
}
impl egui_dock::TabViewer for PaymentTabViewer {
type Tab = Tab;
fn title(&mut self, tab: &mut Self::Tab) -> egui::WidgetText {
(&*tab.title).into()
}
fn ui(&mut self, ui: &mut egui::Ui, tab: &mut Self::Tab) {
match &tab.tab_type {
_ => {
ui.label("Nope");
}
}
}
fn id(&mut self, tab: &mut Self::Tab) -> egui::Id {
egui::Id::new(&tab.title)
}
fn allowed_in_windows(&self, _tab: &mut Self::Tab) -> bool {
TABS_CAN_BE_WINDOWS
}
fn is_closeable(&self, _tab: &Self::Tab) -> bool {
!self.is_admin
}
}
impl Default for PaymentTabViewer {
fn default() -> Self {
let rt = tokio::runtime::Runtime::new().unwrap();
let db_oper = rt.block_on(async { DBOperator::new().await });
Self {
db_oper,
rt,
is_admin: false,
}
}
}