widget/policycheck: update logic
* remove handling of the menu logic (isolated in dedicated widget) * reference styling via theme * update documentation strings Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -5,10 +5,8 @@
|
|||||||
* SPDX-License-Identifier: (0BSD or MIT)
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use orbtk::prelude::*;
|
use orbtk::prelude::*;
|
||||||
use orbtk::shell::event::Key;
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::process;
|
use std::process;
|
||||||
@@ -17,12 +15,12 @@ use std::time::{Duration, SystemTime};
|
|||||||
use tracing::{error, info, trace};
|
use tracing::{error, info, trace};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
widgets::global_state::GlobalState,
|
|
||||||
widgets::policycheck::policycheck_view::PolicycheckView,
|
|
||||||
data::{
|
data::{
|
||||||
structures::{PolicyCode, PolicyDataList, PolicyList},
|
structures::{PolicyCode, PolicyDataList, PolicyList},
|
||||||
constants::*,
|
constants::*,
|
||||||
},
|
},
|
||||||
|
widgets::global_state::GlobalState,
|
||||||
|
//widgets::menu::menu_view::MenuView,
|
||||||
//services::imports::allianzdirectcall::import,
|
//services::imports::allianzdirectcall::import,
|
||||||
services::imports::allianzdirectcall,
|
services::imports::allianzdirectcall,
|
||||||
};
|
};
|
||||||
@@ -35,13 +33,10 @@ pub enum PolicycheckAction {
|
|||||||
ChangeTheme(),
|
ChangeTheme(),
|
||||||
InputTextChanged(Entity),
|
InputTextChanged(Entity),
|
||||||
ImportData,
|
ImportData,
|
||||||
OpenMenu(Entity),
|
|
||||||
ParseEntry(Entity),
|
ParseEntry(Entity),
|
||||||
RemoveFocus(Entity),
|
RemoveFocus(Entity),
|
||||||
RemoveMenu(Entity),
|
|
||||||
RemovePopup(Entity),
|
RemovePopup(Entity),
|
||||||
ResetProgress,
|
ResetProgress,
|
||||||
SetMenuPopup(Entity),
|
|
||||||
SetProgress(f64),
|
SetProgress(f64),
|
||||||
SetProgressPopup(Entity),
|
SetProgressPopup(Entity),
|
||||||
SetToggleTheme(Entity),
|
SetToggleTheme(Entity),
|
||||||
@@ -66,12 +61,9 @@ pub struct PolicycheckState {
|
|||||||
duration: Duration,
|
duration: Duration,
|
||||||
label_result: Entity,
|
label_result: Entity,
|
||||||
lang: String,
|
lang: String,
|
||||||
//last_focused: Option<Entity>,
|
|
||||||
button_menu: Entity,
|
button_menu: Entity,
|
||||||
policy_data_count: u64,
|
policy_data_count: u64,
|
||||||
policy_numbers: HashMap<u64, PolicyCode>,
|
policy_numbers: HashMap<u64, PolicyCode>,
|
||||||
popup_menu: Entity,
|
|
||||||
popup_menu_toggle_theme: Entity,
|
|
||||||
progress_bar: Entity,
|
progress_bar: Entity,
|
||||||
progress_count: f64,
|
progress_count: f64,
|
||||||
progress_popup: Entity
|
progress_popup: Entity
|
||||||
@@ -79,7 +71,7 @@ pub struct PolicycheckState {
|
|||||||
|
|
||||||
impl GlobalState for PolicycheckState {}
|
impl GlobalState for PolicycheckState {}
|
||||||
|
|
||||||
/// method definitions, that react on any given state change inside the `Policycheck` widget.
|
/// Method definitions, that react on any given state change inside the `Policycheck` widget.
|
||||||
impl PolicycheckState {
|
impl PolicycheckState {
|
||||||
/// Create a hashmap (key: policy number, value: policy type).
|
/// Create a hashmap (key: policy number, value: policy type).
|
||||||
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -176,13 +168,6 @@ impl PolicycheckState {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Open menu.
|
|
||||||
pub fn open_menu(&mut self, _entity: Entity, ctx: &mut Context<'_>) {
|
|
||||||
//let menu_string = ctx.get_widget(entity).get::<String16>("text");
|
|
||||||
//.child(policycheck_menu);
|
|
||||||
self.set_popup_menu(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse validity of the given policy number.
|
/// Parse validity of the given policy number.
|
||||||
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
||||||
ctx: &mut Context<'_>) {
|
ctx: &mut Context<'_>) {
|
||||||
@@ -322,12 +307,6 @@ impl PolicycheckState {
|
|||||||
trace!(target: "advotracker", parse_entry = "finished");
|
trace!(target: "advotracker", parse_entry = "finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the menu popup box
|
|
||||||
fn remove_menu(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
|
||||||
ctx.remove_child(self.popup_menu);
|
|
||||||
println!("Popup {:?} removed !", id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Remove the popup box
|
/// Remove the popup box
|
||||||
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||||
ctx.remove_child(self.progress_popup);
|
ctx.remove_child(self.progress_popup);
|
||||||
@@ -363,61 +342,29 @@ impl PolicycheckState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a menu
|
|
||||||
fn set_popup_menu(&mut self, ctx: &mut Context<'_>) {
|
|
||||||
let stack = ctx
|
|
||||||
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
|
||||||
.expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_POPUP_MENU'.");
|
|
||||||
let current_entity = ctx.entity();
|
|
||||||
let build_context = &mut ctx.build_context();
|
|
||||||
|
|
||||||
// create a popup menu overlay
|
|
||||||
self.popup_menu = create_menu(current_entity, build_context);
|
|
||||||
|
|
||||||
// create a menu_popup widget as a child of entity "ID_POLICY_CHECK_BUTTON_MENU"
|
|
||||||
build_context.append_child(stack, self.popup_menu);
|
|
||||||
|
|
||||||
println!("Popup Menu created: {:?}", self.popup_menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set a progress popup that updates the import status in a progress bar
|
/// Set a progress popup that updates the import status in a progress bar
|
||||||
fn set_popup_progress(&mut self, ctx: &mut Context<'_>) {
|
fn set_popup_progress(&mut self, ctx: &mut Context<'_>) {
|
||||||
//println!("Set up Progress popup: {:?}", text_box);
|
// create a stack as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER"
|
||||||
let stack = ctx
|
let stack = ctx
|
||||||
.entity_of_child(ID_POLICY_CHECK_RESULT)
|
.entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||||
.expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_RESULT'.");
|
.expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_POLICY_NUMBER'.");
|
||||||
let current_entity = ctx.entity();
|
let current_entity = ctx.entity();
|
||||||
let build_context = &mut ctx.build_context();
|
let build_context = &mut ctx.build_context();
|
||||||
|
|
||||||
|
// create the progress_popup widget
|
||||||
self.progress_popup = create_popup_progress(current_entity, build_context);
|
self.progress_popup = create_popup_progress(current_entity, build_context);
|
||||||
|
println!("New entity `progress_popup` created: {:?}", self.progress_popup);
|
||||||
|
|
||||||
// create a progress_popup widget as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER"
|
// append the stack inside the progress_popup
|
||||||
build_context.append_child(stack, self.progress_popup);
|
build_context.append_child(stack, self.progress_popup);
|
||||||
|
|
||||||
|
// make sure we have a
|
||||||
self.progress_bar = ctx
|
self.progress_bar = ctx
|
||||||
.entity_of_child(ID_POLICY_CHECK_PROGRESS_BAR)
|
.entity_of_child(ID_POLICY_CHECK_PROGRESS_BAR)
|
||||||
.expect("PolicycheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_PROGRESS_BAR'.");
|
.expect("PolicycheckState.init: Can't find entity of resource 'ID_POLICY_CHECK_PROGRESS_BAR'.");
|
||||||
|
println!("New entity `progress_bar` created: {:?}", self.progress_bar);
|
||||||
|
|
||||||
println!("PopupProgress created: {:?}", self.progress_popup);
|
println!("function `set_popup_progress()` finished!");
|
||||||
}
|
|
||||||
|
|
||||||
/// Set a toggle_theme menu
|
|
||||||
fn set_menu_toggle_theme(&mut self, ctx: &mut Context<'_>) {
|
|
||||||
let stack = ctx
|
|
||||||
.entity_of_child(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME)
|
|
||||||
.expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME'.");
|
|
||||||
//.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
|
||||||
//.expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
|
||||||
let current_entity = ctx.entity();
|
|
||||||
let build_context = &mut ctx.build_context();
|
|
||||||
|
|
||||||
// create a menu overlay
|
|
||||||
self.popup_menu_toggle_theme = create_menu_toggle_theme(current_entity, build_context);
|
|
||||||
|
|
||||||
// create a menu_popup widget as a child of entity "ID_POLICY_CHECK_POPUP_MENU"
|
|
||||||
build_context.append_child(stack, self.popup_menu_toggle_theme);
|
|
||||||
|
|
||||||
println!("Popup Menu Toggle Theme created: {:?}", self.popup_menu_toggle_theme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change visibility of the result label.
|
/// Change visibility of the result label.
|
||||||
@@ -450,15 +397,15 @@ impl PolicycheckState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// upported states for our view
|
/// Supported methods handled inside the `PolicycheckState`
|
||||||
impl State for PolicycheckState {
|
impl State for PolicycheckState {
|
||||||
/// Initialize the state of widget PolicyState
|
/// Initialize the state of widgets inside `PolicycheckState`
|
||||||
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||||
let time_start= SystemTime::now();
|
let time_start= SystemTime::now();
|
||||||
|
|
||||||
trace!(target: "advotracker", policycheck_state = "init", status = "started");
|
trace!(target: "advotracker", policycheck_state = "init", status = "started");
|
||||||
|
|
||||||
// Entities
|
// Initialize required entities
|
||||||
self.button_menu = ctx
|
self.button_menu = ctx
|
||||||
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
.entity_of_child(ID_POLICY_CHECK_BUTTON_MENU)
|
||||||
.expect("PolicycheckState.init: Can't find resource entity 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
.expect("PolicycheckState.init: Can't find resource entity 'ID_POLICY_CHECK_BUTTON_MENU'.");
|
||||||
@@ -495,7 +442,7 @@ impl State for PolicycheckState {
|
|||||||
trace!(target: "advotracker", policycheck_state = "init", status = "finished", duration = ?duration);
|
trace!(target: "advotracker", policycheck_state = "init", status = "finished", duration = ?duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle messages inside the state of widget Policycheck.
|
/// Handle messages for `PolicycheckState`.
|
||||||
fn messages(
|
fn messages(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut messages: MessageReader,
|
mut messages: MessageReader,
|
||||||
@@ -504,29 +451,6 @@ impl State for PolicycheckState {
|
|||||||
) {
|
) {
|
||||||
for message in messages.read::<PolicycheckAction>() {
|
for message in messages.read::<PolicycheckAction>() {
|
||||||
match message {
|
match message {
|
||||||
PolicycheckAction::ChangeTheme() => {
|
|
||||||
let theme_index = *PolicycheckView::selected_index_ref(&ctx.widget());
|
|
||||||
|
|
||||||
cfg_if! {
|
|
||||||
if #[cfg(windows)] {
|
|
||||||
match theme_index {
|
|
||||||
0 => ctx.switch_theme(theme_default_dark()),
|
|
||||||
1 => ctx.switch_theme(theme_default_light()),
|
|
||||||
2 => ctx.switch_theme(theme_redox()),
|
|
||||||
3 => ctx.switch_theme(theme_fluent_dark()),
|
|
||||||
4 => ctx.switch_theme(theme_fluent_light()),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
match theme_index {
|
|
||||||
0 => ctx.switch_theme(theme_default_dark()),
|
|
||||||
1 => ctx.switch_theme(theme_default_light()),
|
|
||||||
2 => ctx.switch_theme(theme_redox()),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
PolicycheckAction::AddProgress(increment) => {
|
PolicycheckAction::AddProgress(increment) => {
|
||||||
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
||||||
|
|
||||||
@@ -539,12 +463,12 @@ impl State for PolicycheckState {
|
|||||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the state of widget Policycheck.
|
/// Update the state of widgets inside the `Policycheck` view.
|
||||||
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||||
// // clear focus on focus moved
|
// // clear focus on focus moved
|
||||||
// if self.last_focused != ctx.window().get::<Global>("global").focused_widget {
|
// if self.last_focused != ctx.window().get::<Global>("global").focused_widget {
|
||||||
@@ -575,9 +499,6 @@ impl State for PolicycheckState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PolicycheckAction::OpenMenu(entity) => {
|
|
||||||
self.open_menu(entity, ctx);
|
|
||||||
}
|
|
||||||
PolicycheckAction::ParseEntry(text_box) => {
|
PolicycheckAction::ParseEntry(text_box) => {
|
||||||
self.parse_entry(text_box, ctx);
|
self.parse_entry(text_box, ctx);
|
||||||
}
|
}
|
||||||
@@ -585,10 +506,8 @@ impl State for PolicycheckState {
|
|||||||
ctx.get_widget(policy_check_policy_number).set("enabled", false);
|
ctx.get_widget(policy_check_policy_number).set("enabled", false);
|
||||||
//ctx.EventAdapter(FocusEvent::RemoveFocus(policy_check_policy_number));
|
//ctx.EventAdapter(FocusEvent::RemoveFocus(policy_check_policy_number));
|
||||||
}
|
}
|
||||||
PolicycheckAction::RemoveMenu(entity) => {
|
|
||||||
self.remove_menu(entity, ctx);
|
|
||||||
}
|
|
||||||
PolicycheckAction::RemovePopup(entity) => {
|
PolicycheckAction::RemovePopup(entity) => {
|
||||||
|
//println!("WIP: remove popup");
|
||||||
self.remove_popup(entity, ctx);
|
self.remove_popup(entity, ctx);
|
||||||
}
|
}
|
||||||
PolicycheckAction::ResetProgress => {
|
PolicycheckAction::ResetProgress => {
|
||||||
@@ -598,9 +517,6 @@ impl State for PolicycheckState {
|
|||||||
//self.last_focused = Some();
|
//self.last_focused = Some();
|
||||||
self.set_entry(policy_check_policy_number, ctx);
|
self.set_entry(policy_check_policy_number, ctx);
|
||||||
}
|
}
|
||||||
PolicycheckAction::SetMenuPopup(_entity) => {
|
|
||||||
self.set_popup_menu(ctx);
|
|
||||||
}
|
|
||||||
PolicycheckAction::SetProgress(value) => {
|
PolicycheckAction::SetProgress(value) => {
|
||||||
if value >= 0. || value <= 1. {
|
if value >= 0. || value <= 1. {
|
||||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), value);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), value);
|
||||||
@@ -610,10 +526,6 @@ impl State for PolicycheckState {
|
|||||||
PolicycheckAction::SetProgressPopup(_entity) => {
|
PolicycheckAction::SetProgressPopup(_entity) => {
|
||||||
self.set_popup_progress(ctx);
|
self.set_popup_progress(ctx);
|
||||||
}
|
}
|
||||||
PolicycheckAction::SetToggleTheme(_entity) => {
|
|
||||||
self.set_menu_toggle_theme(ctx);
|
|
||||||
//self.remove_popup(_entity, ctx);
|
|
||||||
}
|
|
||||||
PolicycheckAction::SetVisibility(_entity) => {
|
PolicycheckAction::SetVisibility(_entity) => {
|
||||||
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
}
|
}
|
||||||
@@ -632,163 +544,19 @@ impl State for PolicycheckState {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a menu popup
|
|
||||||
fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|
||||||
Popup::new()
|
|
||||||
.id(ID_POLICY_CHECK_POPUP_MENU)
|
|
||||||
.style("container_menu")
|
|
||||||
.target(menu)
|
|
||||||
.open(true)
|
|
||||||
.width(280)
|
|
||||||
.height(140)
|
|
||||||
.on_key_down(move | _ctx, key_event | {
|
|
||||||
match key_event.key {
|
|
||||||
Key::Q(..) => {
|
|
||||||
//if is_ctrl_home_down(ctx) {
|
|
||||||
println!("got: Ctrl+Q");
|
|
||||||
process::exit(0);
|
|
||||||
//}
|
|
||||||
},
|
|
||||||
Key::Escape => {
|
|
||||||
println!("got: Escape");
|
|
||||||
//ctx.get::<PolicycheckState>(menu)
|
|
||||||
// .set_action(PolicycheckAction::RemoveMenu(menu));
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
true
|
|
||||||
})
|
|
||||||
.child(
|
|
||||||
Grid::new()
|
|
||||||
.id(ID_POLICY_CHECK_MENU)
|
|
||||||
.columns(
|
|
||||||
Columns::create()
|
|
||||||
.push("80") // Menu Button
|
|
||||||
.push("1") // Seperator
|
|
||||||
.push("*") // Keyboard Shortcut
|
|
||||||
.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)
|
|
||||||
.text("Account")
|
|
||||||
.build(ctx),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new()
|
|
||||||
.id(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME)
|
|
||||||
.style("button_menu")
|
|
||||||
.attach(Grid::row(1))
|
|
||||||
.attach(Grid::column(0))
|
|
||||||
.attach(Grid::column_span(2))
|
|
||||||
.icon(material_icons_font::MD_EDIT)
|
|
||||||
.text("Toggle theme")
|
|
||||||
.on_click(move |states, _| {
|
|
||||||
states.get_mut::<PolicycheckState>(menu)
|
|
||||||
.set_action(PolicycheckAction::SetToggleTheme(menu));
|
|
||||||
true
|
|
||||||
})
|
|
||||||
.build(ctx),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new()
|
|
||||||
.id(ID_POLICY_CHECK_MENU_LABEL_QUIT)
|
|
||||||
.style("button_menu")
|
|
||||||
.attach(Grid::row(2))
|
|
||||||
.attach(Grid::column(0))
|
|
||||||
.attach(Grid::column_span(2))
|
|
||||||
.icon(material_icons_font::MD_SETTINGS_POWER)
|
|
||||||
.text("Quit")
|
|
||||||
.on_mouse_down(move |_states, _| {
|
|
||||||
process::exit(0);
|
|
||||||
})
|
|
||||||
.build(ctx),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
TextBlock::new()
|
|
||||||
.id(ID_POLICY_CHECK_MENU_SHORTCUT_QUIT)
|
|
||||||
.style("button_menu")
|
|
||||||
.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 popup submenu to toogle the active theme
|
|
||||||
fn create_menu_toggle_theme(menu_toggle_theme: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
|
||||||
// define the list of supported themes
|
|
||||||
let mut themes = vec![
|
|
||||||
"default_dark".to_string(),
|
|
||||||
"default_light".to_string(),
|
|
||||||
"redox".to_string(),
|
|
||||||
];
|
|
||||||
cfg_if! {
|
|
||||||
if #[cfg(windows)] {
|
|
||||||
themes.push("fluent_dark".to_string());
|
|
||||||
themes.push("fluent_light".to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let themes_count = themes.len();
|
|
||||||
|
|
||||||
Popup::new()
|
|
||||||
.id(ID_POLICY_CHECK_POPUP_MENU_TOGGLE_THEME)
|
|
||||||
.style("container_menu")
|
|
||||||
.target(menu_toggle_theme)
|
|
||||||
.open(true)
|
|
||||||
.width(280)
|
|
||||||
.height(140)
|
|
||||||
.child(
|
|
||||||
ComboBox::new()
|
|
||||||
.attach(Grid::column(2))
|
|
||||||
.attach(Grid::row(6))
|
|
||||||
.count(themes_count)
|
|
||||||
.items_builder(move |bc, index| {
|
|
||||||
let theme_name =
|
|
||||||
PolicycheckView::themes_ref(&bc.get_widget(menu_toggle_theme))[index].clone();
|
|
||||||
TextBlock::new().v_align("center").text(theme_name).build(bc)
|
|
||||||
})
|
|
||||||
.on_changed("selected_index", move |ctx, _| {
|
|
||||||
ctx.send_message(PolicycheckAction::ChangeTheme, menu_toggle_theme);
|
|
||||||
println!("changed theme.");
|
|
||||||
})
|
|
||||||
.selected_index(menu_toggle_theme)
|
|
||||||
.build(ctx),
|
|
||||||
)
|
|
||||||
.build(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a progress popup with update status of an onging data import
|
/// Create a progress popup with update status of an onging data import
|
||||||
fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
fn create_popup_progress(id: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||||
Popup::new()
|
Popup::new()
|
||||||
.id(ID_POLICY_CHECK_POPUP_PROGRESS)
|
.id(ID_POLICY_CHECK_POPUP_PROGRESS)
|
||||||
.target(popup_progress)
|
.target(id)
|
||||||
.open(true)
|
.open(true)
|
||||||
//.style("popup_progress")
|
.style("popup_progress")
|
||||||
.width(280)
|
.width(280)
|
||||||
.height(100)
|
.height(100)
|
||||||
.on_mouse_down(move |ctx, _| {
|
.on_click(move |ctx, _| {
|
||||||
println!("create_popup_progress: on_click -> remove_popup(popup_progress)");
|
println!("create_popup_progress: on_click -> remove_popup(popup_progress)");
|
||||||
ctx.get_mut::<PolicycheckState>(popup_progress)
|
ctx.get_mut::<PolicycheckState>(id)
|
||||||
.set_action(PolicycheckAction::RemovePopup(popup_progress));
|
.set_action(PolicycheckAction::RemovePopup(id));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
@@ -800,14 +568,14 @@ fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) ->
|
|||||||
.child(
|
.child(
|
||||||
TextBlock::new()
|
TextBlock::new()
|
||||||
.id(ID_POLICY_CHECK_PROGRESS_TEXT)
|
.id(ID_POLICY_CHECK_PROGRESS_TEXT)
|
||||||
//.style("textblock_progress")
|
.style("textblock_progress")
|
||||||
.font_size(12)
|
|
||||||
.text("Importing data")
|
.text("Importing data")
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
ProgressBar::new()
|
ProgressBar::new()
|
||||||
.id(ID_POLICY_CHECK_PROGRESS_BAR)
|
.id(ID_POLICY_CHECK_PROGRESS_BAR)
|
||||||
|
.style("progress_bar")
|
||||||
.val(0)
|
.val(0)
|
||||||
//.width(250)
|
//.width(250)
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
@@ -815,9 +583,8 @@ fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) ->
|
|||||||
.child(
|
.child(
|
||||||
TextBlock::new()
|
TextBlock::new()
|
||||||
.id(ID_POLICY_CHECK_PROGRESS_TIME)
|
.id(ID_POLICY_CHECK_PROGRESS_TIME)
|
||||||
//.style("textblock_progress")
|
.style("textblock_progress")
|
||||||
.h_align("end")
|
.h_align("end")
|
||||||
.font_size(12)
|
|
||||||
.text("Processing time")
|
.text("Processing time")
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ use crate::{
|
|||||||
constants::*,
|
constants::*,
|
||||||
structures::PolicyCheck,
|
structures::PolicyCheck,
|
||||||
},
|
},
|
||||||
|
//widgets::menu::menu_state::{MenuAction, MenuState},
|
||||||
widgets::policycheck::policycheck_state::{PolicycheckAction, PolicycheckState},
|
widgets::policycheck::policycheck_state::{PolicycheckAction, PolicycheckState},
|
||||||
};
|
};
|
||||||
|
|
||||||
type List = Vec<String>;
|
// Macro that initializes the widget structures/variables for the policy check view
|
||||||
|
|
||||||
// Macro that initializes the widget structures/variables for our view
|
|
||||||
widget!(
|
widget!(
|
||||||
/// Dialog to enter a policy identifier/number.
|
/// Dialog to enter a policy identifier/number.
|
||||||
/// This identifier is checked agains a map of valid policy codes.
|
/// This identifier is checked agains a map of valid policy codes.
|
||||||
@@ -27,10 +26,7 @@ widget!(
|
|||||||
lang: String,
|
lang: String,
|
||||||
policy_check: PolicyCheck,
|
policy_check: PolicyCheck,
|
||||||
policy_check_title: String,
|
policy_check_title: String,
|
||||||
policy_data_count: u32,
|
policy_data_count: u32
|
||||||
selected_index: i32,
|
|
||||||
theme_name: String,
|
|
||||||
themes: List
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -39,14 +35,6 @@ widget!(
|
|||||||
impl Template for PolicycheckView {
|
impl Template for PolicycheckView {
|
||||||
//fn template(self, policycheck_view: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
//fn template(self, policycheck_view: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||||
let themes = vec![
|
|
||||||
"default_dark".to_string(),
|
|
||||||
"default_light".to_string(),
|
|
||||||
"redox".to_string(),
|
|
||||||
"fluent_dark".to_string(),
|
|
||||||
"fluent_light".to_string(),
|
|
||||||
];
|
|
||||||
|
|
||||||
let policy_check_bottom_bar = Container::new()
|
let policy_check_bottom_bar = Container::new()
|
||||||
//.style(STYLE_BOTTOM_BAR)
|
//.style(STYLE_BOTTOM_BAR)
|
||||||
.attach(Grid::row(4))
|
.attach(Grid::row(4))
|
||||||
@@ -83,14 +71,6 @@ impl Template for PolicycheckView {
|
|||||||
)
|
)
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
let policy_check_label_menu = TextBlock::new()
|
|
||||||
.id(ID_POLICY_CHECK_LABEL_MENU)
|
|
||||||
.style("menu")
|
|
||||||
.text("Help Menu")
|
|
||||||
.v_align("center")
|
|
||||||
.h_align("center")
|
|
||||||
.build(ctx);
|
|
||||||
|
|
||||||
let policy_check_button_menu = Button::new()
|
let policy_check_button_menu = Button::new()
|
||||||
.id(ID_POLICY_CHECK_BUTTON_MENU)
|
.id(ID_POLICY_CHECK_BUTTON_MENU)
|
||||||
.style("button_single_content")
|
.style("button_single_content")
|
||||||
@@ -98,10 +78,10 @@ impl Template for PolicycheckView {
|
|||||||
.attach(Grid::column(2))
|
.attach(Grid::column(2))
|
||||||
//.min_size(16, 16)
|
//.min_size(16, 16)
|
||||||
.h_align("end")
|
.h_align("end")
|
||||||
.on_click(move |ctx, _| {
|
.on_click(move |_ctx, _| {
|
||||||
//ctx.get_mut::<PolicycheckState>(policycheck_state)
|
println!("WIP: open menu popup from MenuView");
|
||||||
ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<MenuState>(id)
|
||||||
.set_action(PolicycheckAction::OpenMenu(policy_check_label_menu));
|
// .set_action(MenuAction::CreateMenu(ID_MENU_STACK));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
@@ -372,7 +352,6 @@ impl Template for PolicycheckView {
|
|||||||
self.name("PolicycheckView")
|
self.name("PolicycheckView")
|
||||||
// initialize struct (derived default macro)
|
// initialize struct (derived default macro)
|
||||||
.policy_check(PolicyCheck::default())
|
.policy_check(PolicyCheck::default())
|
||||||
.themes(themes)
|
|
||||||
.child(
|
.child(
|
||||||
Grid::new()
|
Grid::new()
|
||||||
.id(ID_POLICY_CHECK_WIDGET)
|
.id(ID_POLICY_CHECK_WIDGET)
|
||||||
|
|||||||
Reference in New Issue
Block a user