diff --git a/advotracker/src/main.rs b/advotracker/src/main.rs index 5afc14e..37c39a8 100644 --- a/advotracker/src/main.rs +++ b/advotracker/src/main.rs @@ -19,13 +19,15 @@ use std::env; //use std::process; use tracing::{info, trace, Level}; -use orbtk::prelude::*; +use orbtk::{ + prelude::*, +}; // The Main view use advotracker::{ widgets::{ main_view, - policycheck::policycheck_state::PolicyCheckState, + //policycheck::policycheck_state::PolicyCheckState, } }; @@ -42,8 +44,8 @@ struct Environment { } // Style extension -static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/advotracker_dark.ron"); -static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/advotracker_light.ron"); +//static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/fluent_dark.ron"); +//static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/fluent_light.ron"); // German localization file. static ADVOTRACKER_DE_DE: &str = include_str!("../assets/advotracker/advotracker_de_DE.ron"); @@ -65,6 +67,20 @@ fn get_lang() -> String { lang } +// /// Extend and register theme assets. +// fn theme() -> Theme { +// register_default_fonts(Theme::from_config( +// ThemeConfig::from(FLUENT_DARK_EXT) +// .extend(ThemeConfig::from(THEME_FLUENT)) +// .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK)) +// .extend(ThemeConfig::from(THEME_FLUENT_FONTS)), +// // ThemeConfig::from(FLUENT_LIGHT_EXT) +// // .extend(ThemeConfig::from(THEME_FLUENT)) +// // .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK)) +// // .extend(ThemeConfig::from(THEME_FLUENT_FONTS)), +// )) +// } + fn main() -> Result<(), Box> { use parse_args::parse_args; use tracing_subscriber::fmt; diff --git a/advotracker/src/widgets/main_view.rs b/advotracker/src/widgets/main_view.rs index 8e646f8..9553c77 100644 --- a/advotracker/src/widgets/main_view.rs +++ b/advotracker/src/widgets/main_view.rs @@ -9,7 +9,7 @@ use orbtk::prelude::*; use crate::{ data::structures::PolicyCheck, - widgets::policycheck::policycheck_view::PolicyCheckView, + widgets::policycheck::policycheck_view::PolicycheckView, }; type List = Vec; @@ -26,7 +26,7 @@ widget!(MainView { impl Template for MainView { fn template(self, _id: Entity, ctx: &mut BuildContext<'_>) -> Self { - let policycheck_view = PolicyCheckView::new() + let policycheck_view = PolicycheckView::new() //.policy_number_count(0) //.policylist_view(id) .build(ctx); diff --git a/advotracker/src/widgets/policycheck/policycheck_state.rs b/advotracker/src/widgets/policycheck/policycheck_state.rs index b4cfc66..b5fd862 100644 --- a/advotracker/src/widgets/policycheck/policycheck_state.rs +++ b/advotracker/src/widgets/policycheck/policycheck_state.rs @@ -8,16 +8,22 @@ use std::time::{Duration, SystemTime}; use tracing::{error, info, trace}; use crate::{ - widgets::global_state::GlobalState, - data::structures::{PolicyCode, PolicyDataList, PolicyList}, - data::constants::*, + widgets::{ + global_state::GlobalState, + policycheck::policycheck_view::PolicycheckView, + }, + data::{ + structures::{PolicyCode, PolicyDataList, PolicyList}, + constants::*, + }, services::imports::allianzdirectcall::import, }; /// Actions that can execute on the task view. #[derive(Debug, Clone, Copy)] -pub enum Action { +pub enum PolicycheckAction { ClearEntry(Entity), + ChangeTheme(), InputTextChanged(Entity), ImportData, OpenMenu(Entity), @@ -45,30 +51,28 @@ struct Environment { rust_log: String, } -/// Handles the requests from `PolicyCheckView`. +/// Handles the requests from `PolicycheckView`. #[derive(AsAny, Default)] -pub struct PolicyCheckState { - action: Option, +pub struct PolicycheckState { + action: Option, duration: Duration, label_result: Entity, lang: String, //last_focused: Option, button_menu: Entity, - menu: Entity, policy_data_count: u64, policy_numbers: HashMap, progress_bar: Entity, progress_count: f64, - progress_popup: Entity, - theme_name: String + progress_popup: Entity } -impl GlobalState for PolicyCheckState {} +impl GlobalState for PolicycheckState {} /// method definitions, that react on any given state change inside the view -impl PolicyCheckState { +impl PolicycheckState { /// Sets a new action. - pub fn action(&mut self, action: Action) { + pub fn action(&mut self, action: PolicycheckAction) { self.action = action.into(); } @@ -317,11 +321,11 @@ impl PolicyCheckState { /// Remove the menu popup box fn remove_menu(&mut self, id: Entity, ctx: &mut Context<'_>) { - ctx.remove_child(self.menu); + ctx.remove_child(self.popup_menu); println!("Popup {:?} removed !", id); } - /// Remove the menu popup box + /// Remove the popup box fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) { ctx.remove_child(self.progress_popup); println!("Popup {:?} removed !", id); @@ -355,19 +359,17 @@ impl PolicyCheckState { fn set_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_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 menu overlay - self.menu = create_menu(current_entity, 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_POLICY_NUMBER" - build_context.append_child(stack, self.menu); - //.expect("PolicyCheckState: Can't find entity of resource 'ID_POLICY_CHECK_MENU'"); - //.expect("PolicyCheckState: Can't create overlay as child of entity"); + // 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.menu); + println!("Popup Menu created: {:?}", self.popup_menu); } /// Set a progress popup that updates the import status in a progress bar @@ -375,7 +377,7 @@ impl PolicyCheckState { //println!("Set up Progress popup: {:?}", text_box); let stack = ctx .entity_of_child(ID_POLICY_CHECK_RESULT) - .expect("PolicyCheckState: Can't find entity of resource 'ID_POLICY_CHECK_RESULT'."); + .expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_RESULT'."); let current_entity = ctx.entity(); let build_context = &mut ctx.build_context(); @@ -386,7 +388,7 @@ impl PolicyCheckState { self.progress_bar = ctx .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!("PopupProgress created: {:?}", self.progress_popup); } @@ -422,7 +424,7 @@ impl PolicyCheckState { } /// upported states for our view -impl State for PolicyCheckState { +impl State for PolicycheckState { /// Initialize the widget state fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) { let time_start= SystemTime::now(); @@ -432,11 +434,11 @@ impl State for PolicyCheckState { // Entities self.button_menu = ctx .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'."); self.label_result = ctx .entity_of_child(ID_POLICY_CHECK_LABEL_RESULT) - .expect("PolicyCheckState.init: Can't find resource entity 'ID_POLICY_CHECK_LABEL_RESULT'."); + .expect("PolicycheckState.init: Can't find resource entity 'ID_POLICY_CHECK_LABEL_RESULT'."); //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); @@ -445,7 +447,7 @@ impl State for PolicyCheckState { Stack::visibility_set(&mut ctx.child(ID_POLICY_CHECK_FORM_ROW_2), Visibility::Collapsed); // Preset localization with given environment lang - self.lang = PolicyCheckState::get_lang(); + self.lang = PolicycheckState::get_lang(); ctx.set_language(&self.lang); // // Load the saved data from a file in 'ron' format into our data structure. @@ -480,7 +482,7 @@ impl State for PolicyCheckState { if let Some(action) = self.action { match action { - Action::AddProgress(increment) => { + PolicycheckAction::AddProgress(increment) => { let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)); let new_width = old_width + increment; @@ -492,13 +494,16 @@ impl State for PolicyCheckState { ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.); } } - Action::ClearEntry(policy_check_policy_number) => { + PolicycheckAction::ChangeTheme() => { + println!("Changing active theme."); + } + PolicycheckAction::ClearEntry(policy_check_policy_number) => { ctx.get_widget(policy_check_policy_number).set("enabled", false); } - Action::InputTextChanged(entity) => { + PolicycheckAction::InputTextChanged(entity) => { println!("entry changed: {}", TextBox::text_clone(&ctx.get_widget(entity))); } - Action::ImportData => { + PolicycheckAction::ImportData => { match self.import_data(ctx) { Ok(()) => { trace!(target: "advotracker", import_data = "success"); @@ -509,50 +514,47 @@ impl State for PolicyCheckState { } } } - Action::OpenMenu(entity) => { + PolicycheckAction::OpenMenu(entity) => { self.open_menu(entity, ctx); } - Action::ParseEntry(text_box) => { + PolicycheckAction::ParseEntry(text_box) => { self.parse_entry(text_box, ctx); } - Action::RemoveFocus(policy_check_policy_number) => { + PolicycheckAction::RemoveFocus(policy_check_policy_number) => { ctx.get_widget(policy_check_policy_number).set("enabled", false); //ctx.EventAdapter(FocusEvent::RemoveFocus(policy_check_policy_number)); } - Action::RemoveMenu(entity) => { + PolicycheckAction::RemoveMenu(entity) => { self.remove_menu(entity, ctx); } - Action::RemovePopup(entity) => { + PolicycheckAction::RemovePopup(entity) => { self.remove_popup(entity, ctx); } - Action::ResetProgress => { + PolicycheckAction::ResetProgress => { ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.); } - Action::SetEntry(policy_check_policy_number) => { + PolicycheckAction::SetEntry(policy_check_policy_number) => { //self.last_focused = Some(); self.set_entry(policy_check_policy_number, ctx); } - Action::SetMenu(_entity) => { + PolicycheckAction::SetMenu(_entity) => { self.set_menu(ctx); } - Action::SetProgress(value) => { + PolicycheckAction::SetProgress(value) => { if value >= 0. || value <= 1. { ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), value); } else { ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.); } } - Action::SetProgressPopup(_entity) => { + PolicycheckAction::SetProgressPopup(_entity) => { self.set_popup_progress(ctx); } - Action::SetVisibility(_entity) => { + PolicycheckAction::SetVisibility(_entity) => { TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed); } - Action::TextChanged(entity, _index) => { + PolicycheckAction::TextChanged(entity, _index) => { self.set_entry(entity, ctx); } - Action::ToggleTheme(_entity) => { - println!{"Switch theme to {:?}", self.theme_name}; - } } } // Reset action @@ -565,18 +567,18 @@ impl State for PolicyCheckState { } /// Create a menu popup -fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity { +fn create_menu(target: Entity, ctx: &mut BuildContext<'_>) -> Entity { Popup::new() .id(ID_POLICY_CHECK_POPUP_MENU) .style("container_menu") - .target(menu) + .target(target) .open(true) .width(280) .height(140) .on_mouse_down(move |ctx, _| { println!("on_click -> remove_menu()"); - ctx.get_mut::(menu) - .action(Action::RemoveMenu(menu)); + ctx.get_mut::(target) + .action(PolicycheckAction::RemoveMenu(target)); true }) .child( @@ -613,7 +615,6 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity { .child( Button::new() .id(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME) - //.style("body") .style("button_menu") .attach(Grid::row(1)) .attach(Grid::column(0)) @@ -621,8 +622,8 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity { .icon(material_icons_font::MD_EDIT) .text("Toggle theme") .on_click(move |states, _| { - states.get_mut::(menu) - .action(Action::ToggleTheme(menu)); + states.get_mut::(target) + .action(PolicycheckAction::ToggleTheme(target)); true }) .build(ctx), @@ -669,8 +670,8 @@ fn create_popup_progress(target: Entity, ctx: &mut BuildContext<'_>) -> Entity { .height(100) .on_mouse_down(move |ctx, _| { println!("on_click -> remove_popup_progress()"); - ctx.get_mut::(target) - .action(Action::RemovePopup(target)); + ctx.get_mut::(target) + .action(PolicycheckAction::RemovePopup(target)); true }) .child( diff --git a/advotracker/src/widgets/policycheck/policycheck_view.rs b/advotracker/src/widgets/policycheck/policycheck_view.rs index f70d63d..59f00c0 100644 --- a/advotracker/src/widgets/policycheck/policycheck_view.rs +++ b/advotracker/src/widgets/policycheck/policycheck_view.rs @@ -8,8 +8,10 @@ use orbtk::prelude::*; use crate::{ - data::constants::*, - data::structures::PolicyCheck, + data::{ + constants::*, + structures::PolicyCheck, + }, widgets::policycheck::policycheck_state::*, }; @@ -17,20 +19,21 @@ use crate::{ widget!( /// Dialog to enter a policy identifier/number. /// This identifier is checked agains a map of valid policy codes. - PolicyCheckView { + PolicycheckView { lang: String, policy_check: PolicyCheck, - policy_check_title: String16, + policy_check_title: String, policy_data_count: u32 } ); /// The template implementation of the policy check view /// All GUI elements are styled using the "style" attribute referencing to a ron based css -impl Template for PolicyCheckView { +impl Template for PolicycheckView { //fn template(self, policycheck_view: Entity, ctx: &mut BuildContext<'_>) -> Self { fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self { - let policy_check_bottom_bar = Container::new() + + let policy_check_bottom_bar = Container::new() //.style(STYLE_BOTTOM_BAR) .attach(Grid::row(4)) .attach(Grid::column(1)) @@ -82,9 +85,9 @@ impl Template for PolicyCheckView { //.min_size(16, 16) .h_align("end") .on_click(move |ctx, _| { - //ctx.get_mut::(policycheck_state) - ctx.get_mut::(id) - .action(Action::OpenMenu(policy_check_label_menu)); + //ctx.get_mut::(policycheck_state) + ctx.get_mut::(id) + .action(PolicycheckAction::OpenMenu(policy_check_label_menu)); true }) .build(ctx); @@ -153,30 +156,30 @@ impl Template for PolicyCheckView { .water_mark("10-stellig") .on_activate(move |ctx, entity| { // Entity is entered/activated via Mouse/Keyboard - //ctx.get_mut::(policy_check_view) + //ctx.get_mut::(policy_check_view) println!("ParseEntry: {:?}", entity); - ctx.get_mut::(id) - .action(Action::ParseEntry(entity)); + ctx.get_mut::(id) + .action(PolicycheckAction::ParseEntry(entity)); }) //.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity)) // .on_changed(move |ctx, entity, _| { - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::SetProgressBox(entity)); - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::AddProgress(0.5)); - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::InputTextChanged(entity)); - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::SetVisibility(entity)); // ctx.get_widget(policy_check_label_policy_number).set("visible"); - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::SetVisility(entity)); // }) // .on_mouse_down | .on_mouse_move | .on_mouse_up (move |ctx, entity| { // state(id, states).action(Action::AddItem); // }) //.on_key_down(move |ctx, _| { - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::ImportData); // true //}) @@ -216,6 +219,7 @@ impl Template for PolicyCheckView { .attach(Grid::column(2)) .h_align("start") .v_align("center") + .text("empty") .build(ctx) ) .build(ctx); @@ -309,11 +313,11 @@ impl Template for PolicyCheckView { .margin((0, 0, 0, 16)) // WIP code @kivimango // .on_activate(move |ctx, entity| { - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::ParseEntry(entity)); // }) // .on_changed(move |ctx, entity| { - // ctx.get_mut::(id) + // ctx.get_mut::(id) // .action(Action::InputTextChanged(entity)); //}) .build(ctx); @@ -346,7 +350,7 @@ impl Template for PolicyCheckView { .build(ctx); // Starter page: check policy numbers - self.name("PolicyCheckView") + self.name("PolicycheckView") // initialize struct (derived default macro) .policy_check(PolicyCheck::default()) .child( @@ -387,7 +391,7 @@ impl Template for PolicyCheckView { } } -// helper to request PolicyCheckState -//fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut PolicyCheckState { +// helper to request PolicycheckState +//fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut PolicycheckState { // states.get_mut(id) //}