structure update

* rename PolicyCheckView to PolicycheckView
* rename PolicyCheckState to PolicycheckState
* rename menu to popup_menu

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-11-01 19:48:05 +01:00
parent 7d459516d9
commit 520b959302
4 changed files with 111 additions and 89 deletions

View File

@@ -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<dyn std::error::Error>> {
use parse_args::parse_args;
use tracing_subscriber::fmt;

View File

@@ -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<String>;
@@ -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);

View File

@@ -9,15 +9,18 @@ use tracing::{error, info, trace};
use crate::{
widgets::global_state::GlobalState,
data::structures::{PolicyCode, PolicyDataList, PolicyList},
data::constants::*,
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),
@@ -33,7 +36,7 @@ pub enum Action {
SetEntry(Entity),
SetVisibility(Entity),
TextChanged(Entity, usize),
ToggleTheme(Entity),
ToggleTheme(Entity)
}
/// define valid environment variables provided via .env files
@@ -45,30 +48,29 @@ struct Environment {
rust_log: String,
}
/// Handles the requests from `PolicyCheckView`.
/// Handles the requests from `PolicycheckView`.
#[derive(AsAny, Default)]
pub struct PolicyCheckState {
action: Option<Action>,
pub struct PolicycheckState {
action: Option<PolicycheckAction>,
duration: Duration,
label_result: Entity,
lang: String,
//last_focused: Option<Entity>,
button_menu: Entity,
menu: Entity,
policy_data_count: u64,
policy_numbers: HashMap<u64, PolicyCode>,
popup_menu: Entity,
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();
}
@@ -172,8 +174,7 @@ impl PolicyCheckState {
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);
self.set_menu(ctx);
self.set_popup_menu(ctx);
}
/// Parse validity of the given policy number.
@@ -317,11 +318,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);
@@ -352,22 +353,20 @@ impl PolicyCheckState {
}
/// Set a menu
fn set_menu(&mut self, ctx: &mut Context<'_>) {
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_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 +374,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 +385,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 +421,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 +431,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 +444,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 +479,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 +491,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,49 +511,50 @@ 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) => {
self.set_menu(ctx);
PolicycheckAction::SetMenu(_entity) => {
self.set_popup_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};
PolicycheckAction::ToggleTheme(_entity) => {
println!("TODO: toggle active theme");
//self.toggle_theme(entity, ctx);
}
}
}
@@ -566,18 +569,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::<PolicyCheckState>(menu)
.action(Action::RemoveMenu(menu));
ctx.get_mut::<PolicycheckState>(target)
.action(PolicycheckAction::RemoveMenu(target));
true
})
.child(
@@ -614,7 +617,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))
@@ -622,8 +624,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::<PolicyCheckState>(menu)
.action(Action::ToggleTheme(menu));
states.get_mut::<PolicycheckState>(target)
.action(PolicycheckAction::ToggleTheme(target));
true
})
.build(ctx),
@@ -670,8 +672,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::<PolicyCheckState>(target)
.action(Action::RemovePopup(target));
ctx.get_mut::<PolicycheckState>(target)
.action(PolicycheckAction::RemovePopup(target));
true
})
.child(

View File

@@ -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<PolicyCheckState> {
PolicycheckView<PolicycheckState> {
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::<PolicyCheckState>(policycheck_state)
ctx.get_mut::<PolicyCheckState>(id)
.action(Action::OpenMenu(policy_check_label_menu));
//ctx.get_mut::<PolicycheckState>(policycheck_state)
ctx.get_mut::<PolicycheckState>(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::<PolicyCheckState>(policy_check_view)
//ctx.get_mut::<PolicycheckState>(policy_check_view)
println!("ParseEntry: {:?}", entity);
ctx.get_mut::<PolicyCheckState>(id)
.action(Action::ParseEntry(entity));
ctx.get_mut::<PolicycheckState>(id)
.action(PolicycheckAction::ParseEntry(entity));
})
//.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity))
// .on_changed(move |ctx, entity, _| {
// ctx.get_mut::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(id)
// .action(Action::SetProgressBox(entity));
// ctx.get_mut::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(id)
// .action(Action::AddProgress(0.5));
// ctx.get_mut::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(id)
// .action(Action::InputTextChanged(entity));
// ctx.get_mut::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(id)
// .action(Action::SetVisibility(entity));
// ctx.get_widget(policy_check_label_policy_number).set("visible");
// ctx.get_mut::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(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::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(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::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(id)
// .action(Action::ParseEntry(entity));
// })
// .on_changed(move |ctx, entity| {
// ctx.get_mut::<PolicyCheckState>(id)
// ctx.get_mut::<PolicycheckState>(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)
//}