diff --git a/advotracker/src/callbacks/policycheck_state.rs b/advotracker/src/callbacks/policycheck_state.rs index b7cb3c3..575cfa4 100644 --- a/advotracker/src/callbacks/policycheck_state.rs +++ b/advotracker/src/callbacks/policycheck_state.rs @@ -59,7 +59,7 @@ struct Environment { rust_log: String, } -/// Handles the requests of the `PolicyCheckView`. +/// Handles the requests from `PolicyCheckView`. #[derive(AsAny, Default)] pub struct PolicyCheckState { action: Option, @@ -74,7 +74,7 @@ pub struct PolicyCheckState { policy_numbers: HashMap, progress_bar: Entity, progress_count: f64, - theme: String + theme_name: String } #[cfg(not(feature = "light"))] @@ -593,19 +593,19 @@ impl State for PolicyCheckState { self.set_entry(entity, ctx); } Action::ToggleTheme(_entity) => { - if self.theme == "light" { - self.theme = "dark_theme".to_string(); - } else { - self.theme = "light_theme".to_string(); + if self.theme_name == "light" { + let theme = dark_theme(); + self.theme_name = "dark".to_string(); + ctx.switch_theme(theme); } - //match &self.theme { - // light => { self.theme = "dark_theme".to_string(); } - // dark => { self.theme = "light_theme".to_string(); } - // _ => { debug!(target: "advotracker", "theme not supported!"); } - // } - println!{"Switch theme to {:?}", self.theme} - let theme = dark_theme(); - ctx.switch_theme(theme); + + if self.theme_name == "dark" { + let theme = light_theme(); + self.theme_name = "light".to_string(); + ctx.switch_theme(theme); + }; + + println!{"Switch theme to {:?}", self.theme_name}; } } } @@ -632,140 +632,140 @@ impl State for PolicyCheckState { } } - /// Create a menu popup - fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity { - Container::new() - .style("container_menu") - .width(280.0) - .height(140.0) - .position((100.0, 100.0)) - .child( - Grid::new() - .id(ID_POLICY_CHECK_MENU) - .columns( - Columns::create() - // Menu Button - .push("80") - // Seperator - .push("1") - // Keyboard Shortcut - .push("*") - .build(), - ) - .rows( - Rows::create() - .push("auto") - .push("auto") - .push("auto") - .build(), - ) - .child( - Button::new() - .id(ID_POLICY_CHECK_MENU_LABEL_ACCOUNT) - .style("button_menu") - .attach(Grid::row(0)) - .attach(Grid::column(0)) - .attach(Grid::column_span(2)) - .icon(material_icons_font::MD_PERSON) - .build(ctx), - ) - .child( - Button::new() - .id(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME) - //.style("body") - .style("button_menu") - .attach(Grid::row(1)) - .attach(Grid::column(0)) - .attach(Grid::column_span(2)) - .icon(material_icons_font::MD_EDIT) - .on_click(move |states, _| { - states.get_mut::(menu) - .action(Action::ToggleTheme(menu)); - true - }) - .build(ctx), - ) - .child( - Button::new() - .id(ID_POLICY_CHECK_MENU_LABEL_QUIT) - //.style("body") - .style("button_menu") - .attach(Grid::row(2)) - .attach(Grid::column(0)) - .attach(Grid::column_span(2)) - .icon(material_icons_font::MD_SETTINGS_POWER) - .on_mouse_down(move |_states, _| { - process::exit(0); - }) - // .on_key_down(move | ctx, "Ctlr+Q"| { - // process::exit(0); - // }) - .build(ctx), - ) - .child( - TextBlock::new() - .id(ID_POLICY_CHECK_MENU_SHORTCUT_QUIT) - .style("button_menu") - //.style("body") - .attach(Grid::row(2)) - .attach(Grid::column(2)) - .margin((0, 0, 16, 0)) - .h_align("end") - .v_align("center") - .text("CTRL+Q") - .build(ctx), - ) - .build(ctx), - ) - .build(ctx) - } +/// Create a menu popup +fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity { + Container::new() + .style("container_menu") + .width(280.0) + .height(140.0) + .position((100.0, 100.0)) + .child( + Grid::new() + .id(ID_POLICY_CHECK_MENU) + .columns( + Columns::create() + // Menu Button + .push("80") + // Seperator + .push("1") + // Keyboard Shortcut + .push("*") + .build(), + ) + .rows( + Rows::create() + .push("auto") + .push("auto") + .push("auto") + .build(), + ) + .child( + Button::new() + .id(ID_POLICY_CHECK_MENU_LABEL_ACCOUNT) + .style("button_menu") + .attach(Grid::row(0)) + .attach(Grid::column(0)) + .attach(Grid::column_span(2)) + .icon(material_icons_font::MD_PERSON) + .build(ctx), + ) + .child( + Button::new() + .id(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME) + //.style("body") + .style("button_menu") + .attach(Grid::row(1)) + .attach(Grid::column(0)) + .attach(Grid::column_span(2)) + .icon(material_icons_font::MD_EDIT) + .on_click(move |states, _| { + states.get_mut::(menu) + .action(Action::ToggleTheme(menu)); + true + }) + .build(ctx), + ) + .child( + Button::new() + .id(ID_POLICY_CHECK_MENU_LABEL_QUIT) + //.style("body") + .style("button_menu") + .attach(Grid::row(2)) + .attach(Grid::column(0)) + .attach(Grid::column_span(2)) + .icon(material_icons_font::MD_SETTINGS_POWER) + .on_mouse_down(move |_states, _| { + process::exit(0); + }) + // .on_key_down(move | ctx, "Ctlr+Q"| { + // process::exit(0); + // }) + .build(ctx), + ) + .child( + TextBlock::new() + .id(ID_POLICY_CHECK_MENU_SHORTCUT_QUIT) + .style("button_menu") + //.style("body") + .attach(Grid::row(2)) + .attach(Grid::column(2)) + .margin((0, 0, 16, 0)) + .h_align("end") + .v_align("center") + .text("CTRL+Q") + .build(ctx), + ) + .build(ctx), + ) + .build(ctx) +} - /// Create a progress popup with update status of an onging data import - fn create_popup_progress(target: Entity, text: &str, ctx: &mut BuildContext<'_>) -> Entity { - Popup::new() - .id(ID_POLICY_CHECK_POPUP_PROGRESS) - .target(target) - .open(true) - //.style("popup_progress") - .width(280) - .height(100) - .on_mouse_down(move |ctx, _| { - println!("on_click -> remove_popup_progress()"); - ctx.get_mut::(target) - .action(Action::RemovePopup(target)); - true - }) - .child( - Container::new() - .style("container_progress") - .child( Stack::new() - .style("stack_progress") - .child( - TextBlock::new() - .id(ID_POLICY_CHECK_PROGRESS_TEXT) - //.style("textblock_progress") - .font_size(12) - .text(text) - .build(ctx) - ) - .child( - ProgressBar::new() - .id(ID_POLICY_CHECK_PROGRESS_BAR) - .val(0) - //.width(250) - .build(ctx) - ) - .child( - TextBlock::new() - .id(ID_POLICY_CHECK_PROGRESS_TIME) - //.style("textblock_progress") - .h_align("end") - .font_size(12) - .build(ctx) - ) - .build(ctx) - ) - .build(ctx) - ) - .build(ctx) - } +/// Create a progress popup with update status of an onging data import +fn create_popup_progress(target: Entity, text: &str, ctx: &mut BuildContext<'_>) -> Entity { + Popup::new() + .id(ID_POLICY_CHECK_POPUP_PROGRESS) + .target(target) + .open(true) + //.style("popup_progress") + .width(280) + .height(100) + .on_mouse_down(move |ctx, _| { + println!("on_click -> remove_popup_progress()"); + ctx.get_mut::(target) + .action(Action::RemovePopup(target)); + true + }) + .child( + Container::new() + .style("container_progress") + .child( Stack::new() + .style("stack_progress") + .child( + TextBlock::new() + .id(ID_POLICY_CHECK_PROGRESS_TEXT) + //.style("textblock_progress") + .font_size(12) + .text(text) + .build(ctx) + ) + .child( + ProgressBar::new() + .id(ID_POLICY_CHECK_PROGRESS_BAR) + .val(0) + //.width(250) + .build(ctx) + ) + .child( + TextBlock::new() + .id(ID_POLICY_CHECK_PROGRESS_TIME) + //.style("textblock_progress") + .h_align("end") + .font_size(12) + .build(ctx) + ) + .build(ctx) + ) + .build(ctx) + ) + .build(ctx) +}