Compare commits
13 Commits
ticketdata
...
wip_toggle
| Author | SHA1 | Date | |
|---|---|---|---|
| fafd38f210 | |||
| 667a2e39bf | |||
| c90099e1cf | |||
| 9624567dbd | |||
| 014b98bd85 | |||
| 8fd512b83f | |||
| 85f9fdf7db | |||
| c4d6506dee | |||
| 646955c0fb | |||
| df6bae482c | |||
| 00ad56ce71 | |||
| 6350d14ce7 | |||
| e8a86e8afd |
@@ -30,8 +30,7 @@ Dictionary (
|
|||||||
"Quit": "Beenden",
|
"Quit": "Beenden",
|
||||||
|
|
||||||
// localization view
|
// localization view
|
||||||
"Hello": "Hallo",
|
"Language ID": "Sprache ID",
|
||||||
"User": "Anwender",
|
|
||||||
"Localization dialog": "Lokalisierungs-Dialog",
|
"Localization dialog": "Lokalisierungs-Dialog",
|
||||||
"German": "Deutsch",
|
"German": "Deutsch",
|
||||||
"English": "Englisch",
|
"English": "Englisch",
|
||||||
|
|||||||
54
advotracker/assets/advotracker/default_dark.ron
Normal file
54
advotracker/assets/advotracker/default_dark.ron
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
Theme (
|
||||||
|
styles: {
|
||||||
|
"button_menu": (
|
||||||
|
base: "button",
|
||||||
|
properties: {
|
||||||
|
"padding": 4,
|
||||||
|
"border_radius": 0,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"container_form": (
|
||||||
|
base: "container",
|
||||||
|
properties: {
|
||||||
|
"padding": 14,
|
||||||
|
"border_width": 1,
|
||||||
|
"border_radius": 0,
|
||||||
|
"border_brush": "$CONTAINER_BORDER",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"configuration_form": (
|
||||||
|
base: "container",
|
||||||
|
properties: {
|
||||||
|
"margin": 4,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"container_progress": (
|
||||||
|
base: "container",
|
||||||
|
properties: {
|
||||||
|
"padding": 14,
|
||||||
|
//"border_width": 1,
|
||||||
|
//"border_radius": 0,
|
||||||
|
"border_brush": "$CONTAINER_BORDER",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"popup_progress": (
|
||||||
|
base: "popup",
|
||||||
|
properties: {
|
||||||
|
//"background": "$BACKGROUND",
|
||||||
|
"padding": 4,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"text_block_progress": (
|
||||||
|
base: "small_text",
|
||||||
|
properties: {
|
||||||
|
"background": "$PROGRESS_BAR_BACKGROUND",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
"stack_progress": (
|
||||||
|
base: "container",
|
||||||
|
properties: {
|
||||||
|
"spacing": 10,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -1,15 +1,9 @@
|
|||||||
Theme (
|
Theme (
|
||||||
styles: {
|
styles: {
|
||||||
"button_single_content_segmdl2": (
|
"container_form": (
|
||||||
base: "button_single_content",
|
|
||||||
properties: {
|
|
||||||
"icon font": "$SEGEO_ICON_FONT",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
"container_master_detail": (
|
|
||||||
base: "container",
|
base: "container",
|
||||||
properties: {
|
properties: {
|
||||||
"padding": 14,
|
"border": 1,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,19 @@ pub static ID_CONFIGURATION_LANGUAGE_ID: &str = "configuration_language_id";
|
|||||||
pub static ID_LOCALIZATION_FORM: &str = "localization_form";
|
pub static ID_LOCALIZATION_FORM: &str = "localization_form";
|
||||||
pub static ID_LOCALIZATION_HEADER: &str = "localization_header";
|
pub static ID_LOCALIZATION_HEADER: &str = "localization_header";
|
||||||
pub static ID_LOCALIZATION_LANGUAGES: &str = "localization_languages";
|
pub static ID_LOCALIZATION_LANGUAGES: &str = "localization_languages";
|
||||||
|
pub static ID_LOCALIZATION_LABEL_LANGUAGE_NAME: &str = "localization_label_language_name";
|
||||||
pub static ID_LOCALIZATION_LANGUAGE_NAME: &str = "localization_language_name";
|
pub static ID_LOCALIZATION_LANGUAGE_NAME: &str = "localization_language_name";
|
||||||
|
|
||||||
|
pub static ID_MENU_POPUP: &str = "menu_popup";
|
||||||
|
pub static ID_MENU_STACK: &str = "menu_stack";
|
||||||
|
pub static ID_MENU_BUTTON: &str = "menu_button";
|
||||||
|
pub static ID_MENU_GRID: &str = "menu_grid";
|
||||||
|
pub static ID_MENU_LABEL_ACCOUNT: &str = "menu_label_account";
|
||||||
|
pub static ID_MENU_LABEL_QUIT: &str = "menu_label_quit";
|
||||||
|
pub static ID_MENU_LABEL_TOGGLE_THEME: &str = "menu_label_toggle_theme";
|
||||||
|
pub static ID_MENU_SHORTCUT_QUIT: &str = "menu_shortcut_quit";
|
||||||
|
pub static ID_MENU_TOGGLE_THEME: &str = "menu_toggle_theme";
|
||||||
|
|
||||||
pub static ID_POLICY_CHECK_FORM: &str = "policy_check_form";
|
pub static ID_POLICY_CHECK_FORM: &str = "policy_check_form";
|
||||||
pub static ID_POLICY_CHECK_FORM_ROW_0: &str = "policy_check_form_row_0";
|
pub static ID_POLICY_CHECK_FORM_ROW_0: &str = "policy_check_form_row_0";
|
||||||
pub static ID_POLICY_CHECK_FORM_ROW_1: &str = "policy_check_form_row_1";
|
pub static ID_POLICY_CHECK_FORM_ROW_1: &str = "policy_check_form_row_1";
|
||||||
@@ -41,14 +52,7 @@ pub static ID_POLICY_CHECK_LABEL_HINT: &str = "policy_check_label_hint";
|
|||||||
pub static ID_POLICY_CHECK_LABEL_MENU: &str = "policy_check_label_menu";
|
pub static ID_POLICY_CHECK_LABEL_MENU: &str = "policy_check_label_menu";
|
||||||
pub static ID_POLICY_CHECK_LABEL_POLICY_NUMBER: &str = "policy_check_label_policy_number";
|
pub static ID_POLICY_CHECK_LABEL_POLICY_NUMBER: &str = "policy_check_label_policy_number";
|
||||||
pub static ID_POLICY_CHECK_LABEL_RESULT: &str = "policy_check_label_result";
|
pub static ID_POLICY_CHECK_LABEL_RESULT: &str = "policy_check_label_result";
|
||||||
pub static ID_POLICY_CHECK_MENU: &str = "policy_check_menu";
|
|
||||||
pub static ID_POLICY_CHECK_MENU_LABEL_ACCOUNT: &str = "policy_check_menu_label_account";
|
|
||||||
pub static ID_POLICY_CHECK_MENU_LABEL_QUIT: &str = "policy_check_menu_label_quit";
|
|
||||||
pub static ID_POLICY_CHECK_MENU_SHORTCUT_QUIT: &str = "policy_check_menu_shortcut_quit";
|
|
||||||
pub static ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME: &str = "policy_check_menu_label_toggle_theme";
|
|
||||||
pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_check_policy_number";
|
pub static ID_POLICY_CHECK_POLICY_NUMBER: &str = "policy_check_policy_number";
|
||||||
pub static ID_POLICY_CHECK_POPUP_MENU: &str = "policy_check_popup_menu";
|
|
||||||
pub static ID_POLICY_CHECK_POPUP_MENU_TOGGLE_THEME: &str = "policy_check_popup_menu_toggle_theme";
|
|
||||||
pub static ID_POLICY_CHECK_POPUP_PROGRESS: &str = "policy_check_popup_progress";
|
pub static ID_POLICY_CHECK_POPUP_PROGRESS: &str = "policy_check_popup_progress";
|
||||||
pub static ID_POLICY_CHECK_PROGRESS_BAR: &str = "policy_check_progress_bar";
|
pub static ID_POLICY_CHECK_PROGRESS_BAR: &str = "policy_check_progress_bar";
|
||||||
pub static ID_POLICY_CHECK_PROGRESS_TIME: &str = "policy_check_progress_time";
|
pub static ID_POLICY_CHECK_PROGRESS_TIME: &str = "policy_check_progress_time";
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
//use chrono::{Local, DateTime};
|
//use chrono::{Local, DateTime};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::env;
|
use std::env;
|
||||||
//use std::process;
|
//use std::process;
|
||||||
@@ -21,15 +22,15 @@ use tracing::{info, trace, Level};
|
|||||||
|
|
||||||
use orbtk::{
|
use orbtk::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
theme_default::{THEME_DEFAULT, THEME_DEFAULT_COLORS_DARK, THEME_DEFAULT_FONTS},
|
||||||
|
theming::config::ThemeConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
use orbtk::theme_fluent::{THEME_FLUENT, THEME_FLUENT_COLORS_DARK, THEME_FLUENT_FONTS};
|
||||||
|
|
||||||
// The Main view
|
// The Main view
|
||||||
use advotracker::{
|
use advotracker::widgets::main_view;
|
||||||
widgets::{
|
|
||||||
main_view,
|
|
||||||
//policycheck::policycheck_state::PolicyCheckState,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
mod parse_args;
|
mod parse_args;
|
||||||
|
|
||||||
@@ -44,8 +45,13 @@ struct Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Style extension
|
// Style extension
|
||||||
//static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/fluent_dark.ron");
|
static DEFAULT_DARK_EXT: &str = include_str!("../assets/advotracker/default_dark.ron");
|
||||||
//static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/fluent_light.ron");
|
cfg_if! {
|
||||||
|
if #[cfg(windows)] {
|
||||||
|
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.
|
// German localization file.
|
||||||
static ADVOTRACKER_DE_DE: &str = include_str!("../assets/advotracker/advotracker_de_DE.ron");
|
static ADVOTRACKER_DE_DE: &str = include_str!("../assets/advotracker/advotracker_de_DE.ron");
|
||||||
@@ -67,19 +73,42 @@ fn get_lang() -> String {
|
|||||||
lang
|
lang
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Extend and register theme assets.
|
cfg_if! {
|
||||||
// fn theme() -> Theme {
|
if #[cfg(windows)] {
|
||||||
// register_default_fonts(Theme::from_config(
|
/// Extend and register theme assets.
|
||||||
// ThemeConfig::from(FLUENT_DARK_EXT)
|
fn theme() -> Theme {
|
||||||
// .extend(ThemeConfig::from(THEME_FLUENT))
|
register_default_fonts(Theme::from_config(
|
||||||
// .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK))
|
ThemeConfig::from(DEFAULT_DARK_EXT)
|
||||||
// .extend(ThemeConfig::from(THEME_FLUENT_FONTS)),
|
.extend(ThemeConfig::from(THEME_DEFAULT))
|
||||||
// // ThemeConfig::from(FLUENT_LIGHT_EXT)
|
.extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK))
|
||||||
// // .extend(ThemeConfig::from(THEME_FLUENT))
|
.extend(ThemeConfig::from(THEME_DEFAULT_FONTS)),
|
||||||
// // .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK))
|
))
|
||||||
// // .extend(ThemeConfig::from(THEME_FLUENT_FONTS)),
|
}
|
||||||
// ))
|
fn theme_fluent() -> Theme {
|
||||||
// }
|
register_fluent_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)),
|
||||||
|
))
|
||||||
|
// register_fluent_fonts(Theme::from_config(
|
||||||
|
// ThemeConfig::from(FLUENT_LIGHT_EXT)
|
||||||
|
// .extend(ThemeConfig::from(THEME_FLUENT))
|
||||||
|
// .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK))
|
||||||
|
// .extend(ThemeConfig::from(THEME_FLUENT_FONTS)),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/// Extend and register theme assets.
|
||||||
|
fn theme() -> Theme {
|
||||||
|
register_default_fonts(Theme::from_config(
|
||||||
|
ThemeConfig::from(DEFAULT_DARK_EXT)
|
||||||
|
.extend(ThemeConfig::from(THEME_DEFAULT))
|
||||||
|
.extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK))
|
||||||
|
.extend(ThemeConfig::from(THEME_DEFAULT_FONTS)),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
use parse_args::parse_args;
|
use parse_args::parse_args;
|
||||||
@@ -152,6 +181,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
Application::from_name("nwx.advotracker")
|
Application::from_name("nwx.advotracker")
|
||||||
.localization(localization)
|
.localization(localization)
|
||||||
|
.theme(theme())
|
||||||
.window(|ctx| {
|
.window(|ctx| {
|
||||||
Window::new()
|
Window::new()
|
||||||
.title("AdvoTracker - DirectCall")
|
.title("AdvoTracker - DirectCall")
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ impl Template for ConfigurationView {
|
|||||||
self.child(
|
self.child(
|
||||||
Grid::new()
|
Grid::new()
|
||||||
.id(ID_CONFIGURATION_FORM)
|
.id(ID_CONFIGURATION_FORM)
|
||||||
.margin(4)
|
.style(configuration_form)
|
||||||
.columns(
|
.columns(
|
||||||
Columns::create()
|
Columns::create()
|
||||||
.push(120)
|
.push(120)
|
||||||
@@ -56,7 +56,7 @@ impl Template for ConfigurationView {
|
|||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
TextBlock::new()
|
TextBlock::new()
|
||||||
.id(ID_CONFIGURATION_CONFIG_FILE)
|
.id(ID_CONFIGURATION_LABEL_CONFIG_FILE)
|
||||||
.attach(Grid::column(0))
|
.attach(Grid::column(0))
|
||||||
.attach(Grid::row(2))
|
.attach(Grid::row(2))
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ impl Template for LocalizationView {
|
|||||||
Columns::create()
|
Columns::create()
|
||||||
.push(120)
|
.push(120)
|
||||||
.push(12)
|
.push(12)
|
||||||
.push("auto")
|
.push(150)
|
||||||
)
|
)
|
||||||
.rows(Rows::create()
|
.rows(Rows::create()
|
||||||
.push("auto")
|
.push("auto")
|
||||||
@@ -59,10 +59,22 @@ impl Template for LocalizationView {
|
|||||||
.style("header")
|
.style("header")
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
|
.child(
|
||||||
|
TextBlock::new()
|
||||||
|
.id(ID_LOCALIZATION_LABEL_LANGUAGE_NAME)
|
||||||
|
.attach(Grid::column(0))
|
||||||
|
.attach(Grid::row(2))
|
||||||
|
.v_align("center")
|
||||||
|
.h_align("end")
|
||||||
|
.text("Language ID")
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
ComboBox::new()
|
ComboBox::new()
|
||||||
.id(ID_LOCALIZATION_LANGUAGES)
|
.id(ID_LOCALIZATION_LANGUAGES)
|
||||||
.count(count)
|
.count(count)
|
||||||
|
.attach(Grid::column(2))
|
||||||
|
.attach(Grid::row(2))
|
||||||
.items_builder(move |bc, index| {
|
.items_builder(move |bc, index| {
|
||||||
let text = bc.get_widget(id)
|
let text = bc.get_widget(id)
|
||||||
.get::<Vec<String>>("languages")[index]
|
.get::<Vec<String>>("languages")[index]
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use crate::{
|
|||||||
widgets::policycheck::policycheck_view::PolicycheckView,
|
widgets::policycheck::policycheck_view::PolicycheckView,
|
||||||
widgets::localization::localization_view::LocalizationView,
|
widgets::localization::localization_view::LocalizationView,
|
||||||
widgets::configuration::configuration_view::ConfigurationView,
|
widgets::configuration::configuration_view::ConfigurationView,
|
||||||
|
widgets::menu::menu_view::MenuView,
|
||||||
};
|
};
|
||||||
|
|
||||||
// [START] views
|
// [START] views
|
||||||
@@ -57,6 +58,7 @@ impl Template for MainView {
|
|||||||
.tab("Policynumber check", policycheck_view)
|
.tab("Policynumber check", policycheck_view)
|
||||||
.tab("Localization", LocalizationView::new().build(ctx))
|
.tab("Localization", LocalizationView::new().build(ctx))
|
||||||
.tab("Configuration", ConfigurationView::new().build(ctx))
|
.tab("Configuration", ConfigurationView::new().build(ctx))
|
||||||
|
.tab("Menu", MenuView::new().build(ctx))
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
//.child(policycheck_view)
|
//.child(policycheck_view)
|
||||||
|
|||||||
300
advotracker/src/widgets/menu/menu_state.rs
Normal file
300
advotracker/src/widgets/menu/menu_state.rs
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
/*
|
||||||
|
* advotracker - Hotline tackingtool for Advocats
|
||||||
|
*
|
||||||
|
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||||
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
|
*/
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
use orbtk::prelude::*;
|
||||||
|
use orbtk::shell::event::Key;
|
||||||
|
|
||||||
|
use std::process;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
data::constants::*,
|
||||||
|
widgets::menu::menu_view::MenuView,
|
||||||
|
//widgets::policycheck::policycheck_view::PolicycheckView,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Valid `actions` that are handled as state changes in the `Menu` widget.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum MenuAction {
|
||||||
|
CreateMenu,
|
||||||
|
CreateMenuToggleTheme(Entity),
|
||||||
|
RemoveMenu,
|
||||||
|
RemoveMenuToggleTheme(Entity),
|
||||||
|
SetTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Valid `structures` that are handled inside the state of the `Menu` widget.
|
||||||
|
#[derive(AsAny, Default)]
|
||||||
|
pub struct MenuState {
|
||||||
|
action: Option<MenuAction>,
|
||||||
|
menu: Entity,
|
||||||
|
menu_toggle_theme: Entity
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Method definitions, that react on any given state change inside the `Menu` widget.
|
||||||
|
impl MenuState {
|
||||||
|
/// Set a menu holding all valid menu elements
|
||||||
|
/// The elements are ordered compontents inside a stack
|
||||||
|
pub fn create_menu(&mut self, ctx: &mut Context<'_>) {
|
||||||
|
// create a stack as a child of the given component
|
||||||
|
let stack = ctx
|
||||||
|
.entity_of_child(ID_MENU_BUTTON)
|
||||||
|
.expect("PolicycheckState: Can't find entity of resource 'ID_MENU_BUTTON'.");
|
||||||
|
//.entity_of_child(<PolicycheckView>ID_MENU_BUTTON)
|
||||||
|
//.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 new popup menu overlay
|
||||||
|
self.menu = create_menu_popup(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.menu);
|
||||||
|
|
||||||
|
println!("Popup Menu created: {:?}", self.menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set a toggle_theme menu
|
||||||
|
/// Select the active theme from a `ComboBox` offering a list of valid `themes``
|
||||||
|
fn create_menu_toggle_theme(&mut self, ctx: &mut Context<'_>) {
|
||||||
|
let stack = ctx
|
||||||
|
.entity_of_child(ID_MENU_LABEL_TOGGLE_THEME)
|
||||||
|
.expect("MenuState: Can't find entity of resource 'ID_MENU_LABEL_TOGGLE_THEME'.");
|
||||||
|
let current_entity = ctx.entity();
|
||||||
|
let build_context = &mut ctx.build_context();
|
||||||
|
|
||||||
|
// create a new menu overlay
|
||||||
|
self.menu_toggle_theme = create_menu_toggle_theme_popup(current_entity, build_context);
|
||||||
|
|
||||||
|
// create a menu_popup widget as a child of entity "ID_POPUP_MENU"
|
||||||
|
build_context.append_child(stack, self.menu_toggle_theme);
|
||||||
|
|
||||||
|
println!("Popup Menu Toggle Theme created: {:?}", self.menu_toggle_theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove the menu popup box
|
||||||
|
fn remove_menu(&mut self, ctx: &mut Context<'_>) {
|
||||||
|
ctx.remove_child(ctx.entity());
|
||||||
|
println!("Popup {:?} removed !", ctx.entity());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove the menu popup box
|
||||||
|
fn remove_menu_toggle_theme(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||||
|
ctx.remove_child(self.menu_toggle_theme);
|
||||||
|
println!("Popup {:?} removed !", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets a new action.
|
||||||
|
pub fn set_action(&mut self, action: MenuAction) {
|
||||||
|
self.action = action.into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Supported methods handled inside the `MenuState`
|
||||||
|
impl State for MenuState {
|
||||||
|
/// Initialize the state of widgets inside `MenuState`
|
||||||
|
fn init(&mut self, _: &mut Registry, _ctx: &mut Context<'_>) {
|
||||||
|
// Initialize required entities
|
||||||
|
// let menu_button = ctx
|
||||||
|
// .entity_of_child(ID_MENU_STACK)
|
||||||
|
// .expect("MenuState.init: Can't find resource entity 'PolicycheckView::ID_POLICY_CHECK_BUTTON_MENU'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle messages for the `MenuState`
|
||||||
|
fn messages(
|
||||||
|
&mut self,
|
||||||
|
mut messages: MessageReader,
|
||||||
|
_registry: &mut Registry,
|
||||||
|
ctx: &mut Context<'_>,
|
||||||
|
) {
|
||||||
|
for message in messages.read::<MenuAction>() {
|
||||||
|
match message {
|
||||||
|
MenuAction::SetTheme => {
|
||||||
|
let theme_index = *MenuView::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()),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the state of widgets inside the `Menu` view.
|
||||||
|
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||||
|
if let Some(action) = self.action {
|
||||||
|
match action {
|
||||||
|
MenuAction::CreateMenu => {
|
||||||
|
println!("MenuAction::CreateMenu(_entity)");
|
||||||
|
self.create_menu(ctx);
|
||||||
|
}
|
||||||
|
MenuAction::CreateMenuToggleTheme(_entity) => {
|
||||||
|
self.create_menu_toggle_theme(ctx);
|
||||||
|
}
|
||||||
|
MenuAction::RemoveMenu => {
|
||||||
|
self.remove_menu(ctx);
|
||||||
|
}
|
||||||
|
MenuAction::RemoveMenuToggleTheme(entity) => {
|
||||||
|
self.remove_menu_toggle_theme(entity, ctx);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new popup presenting the menu components
|
||||||
|
pub fn create_menu_popup(id: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||||
|
Popup::new()
|
||||||
|
.id(ID_MENU_POPUP)
|
||||||
|
.style("container_menu")
|
||||||
|
.target(id)
|
||||||
|
.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!("KeyHandler: got Ctrl+Q");
|
||||||
|
process::exit(0);
|
||||||
|
//}
|
||||||
|
},
|
||||||
|
Key::Escape => {
|
||||||
|
println!("KeyHandler: got Escape");
|
||||||
|
ctx.get_mut::<MenuState>(id)
|
||||||
|
.set_action(MenuAction::RemoveMenu);
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
println!("KeyHandler: got {:?}", key_event.key);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
true
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
Grid::new()
|
||||||
|
.id(ID_MENU_GRID)
|
||||||
|
.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_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_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 |ctx, _| {
|
||||||
|
// ctx.get_mut::<MenuState>(id)
|
||||||
|
// .set_action(MenuAction::SetTheme(id));
|
||||||
|
// true
|
||||||
|
// })
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new()
|
||||||
|
.id(ID_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_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 new popup submenu to toogle the active theme
|
||||||
|
pub fn create_menu_toggle_theme_popup(id: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||||
|
//let themes_count = themes.len();
|
||||||
|
//ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), new_width);
|
||||||
|
|
||||||
|
Popup::new()
|
||||||
|
.id(ID_MENU_TOGGLE_THEME)
|
||||||
|
.style("container_menu")
|
||||||
|
.target(id)
|
||||||
|
.open(true)
|
||||||
|
.width(280)
|
||||||
|
.height(140)
|
||||||
|
.child(
|
||||||
|
ComboBox::new()
|
||||||
|
.attach(Grid::column(2))
|
||||||
|
.attach(Grid::row(6))
|
||||||
|
//.count(themes_count)
|
||||||
|
.items_builder(move |build_ctx, index| {
|
||||||
|
let theme_name =
|
||||||
|
MenuView::themes_ref(&build_ctx.get_widget(id))[index].clone();
|
||||||
|
TextBlock::new().v_align("center").text(theme_name).build(build_ctx)
|
||||||
|
})
|
||||||
|
.on_changed("selected_index", move |ctx, _| {
|
||||||
|
ctx.send_message(MenuAction::SetTheme, id);
|
||||||
|
println!("changed theme.");
|
||||||
|
})
|
||||||
|
.selected_index(id)
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
|
.build(ctx)
|
||||||
|
}
|
||||||
82
advotracker/src/widgets/menu/menu_view.rs
Normal file
82
advotracker/src/widgets/menu/menu_view.rs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* advotracker - Hotline tackingtool for Advocats
|
||||||
|
*
|
||||||
|
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||||
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
|
*/
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
use orbtk::prelude::*;
|
||||||
|
|
||||||
|
use crate::data::constants::*;
|
||||||
|
use crate::widgets::menu::menu_state::{MenuAction, MenuState};
|
||||||
|
|
||||||
|
type List = Vec<String>;
|
||||||
|
|
||||||
|
// Macro that initializes the widget structures/variables for the menu view
|
||||||
|
widget!(
|
||||||
|
MenuView<MenuState> {
|
||||||
|
//menu_stack: Entity,
|
||||||
|
//button_menu: Entity,
|
||||||
|
selected_index: i32,
|
||||||
|
themes: List
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/// The template implementation of the menu view
|
||||||
|
/// All GUI elements are styled using the "style" attribute referencing to a ron based css
|
||||||
|
impl Template for MenuView {
|
||||||
|
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(windows)] {
|
||||||
|
// define the list of supported themes
|
||||||
|
let themes = vec![
|
||||||
|
"default_dark".to_string(),
|
||||||
|
"default_light".to_string(),
|
||||||
|
"redox".to_string(),
|
||||||
|
"fluent_dark".to_string(),
|
||||||
|
"fluent_light".to_string()
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// define the list of supported themes
|
||||||
|
let themes = vec![
|
||||||
|
"default_dark".to_string(),
|
||||||
|
"default_light".to_string(),
|
||||||
|
"redox".to_string(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//self.themes(themes).child(MenuState::create_menu(ID_MENU_POPUP, ctx))
|
||||||
|
self.themes(themes).child(
|
||||||
|
Stack::new()
|
||||||
|
.id(ID_MENU_STACK)
|
||||||
|
.child(
|
||||||
|
TextBlock::new()
|
||||||
|
.style("header")
|
||||||
|
.attach(Grid::row(0))
|
||||||
|
.attach(Grid::column(0))
|
||||||
|
.style("small_text")
|
||||||
|
.text("Select theme")
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new()
|
||||||
|
//.id("button_menu")
|
||||||
|
.id(ID_MENU_BUTTON)
|
||||||
|
.style("button_single_content")
|
||||||
|
.icon(material_icons_font::MD_MENU)
|
||||||
|
.attach(Grid::column(2))
|
||||||
|
.h_align("end")
|
||||||
|
.on_click(move |ctx, _| {
|
||||||
|
println!("WIP: open menu popup from MenuView");
|
||||||
|
ctx.get_mut::<MenuState>(id)
|
||||||
|
.set_action(MenuAction::CreateMenu);
|
||||||
|
true
|
||||||
|
})
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
|
.build(ctx),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
12
advotracker/src/widgets/menu/mod.rs
Normal file
12
advotracker/src/widgets/menu/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* advotracker - Hotline tackingtool for Advocats
|
||||||
|
*
|
||||||
|
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||||
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// The menu view
|
||||||
|
pub mod menu_view;
|
||||||
|
|
||||||
|
/// The menu state
|
||||||
|
pub mod menu_state;
|
||||||
@@ -5,23 +5,26 @@
|
|||||||
* SPDX-License-Identifier: (0BSD or MIT)
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/// The configuration widget.
|
/// Configuration widget.
|
||||||
pub mod configuration;
|
pub mod configuration;
|
||||||
|
|
||||||
/// The global helper functions.
|
/// Global helper functions.
|
||||||
pub mod global_state;
|
pub mod global_state;
|
||||||
|
|
||||||
/// The localization widget.
|
/// Localization widget.
|
||||||
pub mod localization;
|
pub mod localization;
|
||||||
|
|
||||||
/// The starting point (Main View).
|
/// The starting point (Main View).
|
||||||
pub mod main_view;
|
pub mod main_view;
|
||||||
|
|
||||||
/// The policycheck wigdet.
|
/// Menu widget.
|
||||||
|
pub mod menu;
|
||||||
|
|
||||||
|
/// Policycheck wigdet.
|
||||||
pub mod policycheck;
|
pub mod policycheck;
|
||||||
|
|
||||||
// /// The policydata widget.
|
// /// Policydata widget.
|
||||||
// pub mod policydata;
|
// pub mod policydata;
|
||||||
|
|
||||||
// /// The policylists widget.
|
// /// Policylists widget.
|
||||||
// pub mod policylist;
|
// pub mod policylist;
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* advotracker - Hotline tackingtool for Advocats
|
|
||||||
*
|
|
||||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
|
||||||
* SPDX-License-Identifier: (0BSD or MIT)
|
|
||||||
*/
|
|
||||||
|
|
||||||
use orbtk::prelude::*;
|
|
||||||
|
|
||||||
use crate::data::constants::*;
|
|
||||||
|
|
||||||
widget!(
|
|
||||||
PolicyCheckMenu {
|
|
||||||
is_active: Bool
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
impl Template for PolicyCheckMenu {
|
|
||||||
fn template(self, _id: Entity, ctx: &mut BuildContext) -> Self {
|
|
||||||
// let policy_check_menu_container = Container::new()
|
|
||||||
// .id(ID_POLICY_CHECK_MENU_CONTAINER)
|
|
||||||
// .class(CLASS_MENU)
|
|
||||||
// .attach(Grid::row(3))
|
|
||||||
// .attach(Grid::column(8))
|
|
||||||
// .margin((0.0, 0.0, 4.0, 0.0))
|
|
||||||
// .enabled(false)
|
|
||||||
// .min_size(120.0, 180.0)
|
|
||||||
// .v_align("center")
|
|
||||||
// .on_click(move |ctx, _| {
|
|
||||||
// ctx.get_mut::<PolicyCheckState>(id)
|
|
||||||
// .action(Action::NewEntry(quit));
|
|
||||||
// true
|
|
||||||
// })
|
|
||||||
// .build(ctx);
|
|
||||||
|
|
||||||
// let policycheck_menu_container = Container::new()
|
|
||||||
// .id(ID_POLICY_CHECK_MENU_CONTAINER)
|
|
||||||
// .background("#dfebf5")
|
|
||||||
// .width(200.0)
|
|
||||||
// .height(200.0)
|
|
||||||
// .child(
|
|
||||||
|
|
||||||
// The menu implemented as an overlay
|
|
||||||
//ctx.append_child_to_overlay(policy_check_menu_button).unwrap();
|
|
||||||
|
|
||||||
self.name("PolicyCheckMenu").child(
|
|
||||||
Stack::new()
|
|
||||||
.id(ID_POLICY_CHECK_MENU)
|
|
||||||
.orientation("vertical")
|
|
||||||
.spacing(8)
|
|
||||||
.h_align("center")
|
|
||||||
.child(
|
|
||||||
Button::new()
|
|
||||||
.icon(material_icons_font::MD_VERIFIED_USER)
|
|
||||||
.text("angemeldeter Benutzer")
|
|
||||||
.margin((0, 8, 0, 0))
|
|
||||||
.build(ctx),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Button::new()
|
|
||||||
.icon(material_icons_font::MD_EXIT_TO_APP)
|
|
||||||
.text("Quit")
|
|
||||||
.margin((0, 8, 0, 0))
|
|
||||||
.build(ctx),
|
|
||||||
)
|
|
||||||
.build(ctx),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* advotracker - Hotline tackingtool for Advocats
|
||||||
|
*
|
||||||
|
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||||
|
* SPDX-License-Identifier: (0BSD or MIT)
|
||||||
|
*/
|
||||||
|
|
||||||
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;
|
||||||
@@ -9,16 +15,17 @@ 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::*,
|
||||||
},
|
},
|
||||||
services::imports::allianzdirectcall::import,
|
widgets::global_state::GlobalState,
|
||||||
|
//widgets::menu::menu_view::MenuView,
|
||||||
|
//services::imports::allianzdirectcall::import,
|
||||||
|
services::imports::allianzdirectcall,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Actions that can execute on the task view.
|
/// Valid `actions` that are handled as state changes in the `Policycheck` widget.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum PolicycheckAction {
|
pub enum PolicycheckAction {
|
||||||
AddProgress(f64),
|
AddProgress(f64),
|
||||||
@@ -26,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),
|
||||||
@@ -41,28 +45,25 @@ pub enum PolicycheckAction {
|
|||||||
TextChanged(Entity, usize)
|
TextChanged(Entity, usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// define valid environment variables provided via .env files
|
/// Define valid environment variables provided via .env files
|
||||||
/// located in the current call directory
|
/// located in the current call directory.
|
||||||
/// this is primarily used in testing scenarios (eg. debugging)
|
/// This is primarily used in testing scenarios (eg. debugging).
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Environment {
|
struct Environment {
|
||||||
test_lang: String,
|
test_lang: String,
|
||||||
rust_log: String,
|
rust_log: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles the requests from `PolicycheckView`.
|
/// Valid `structures` that are handled inside the state of the `Policycheck` widget.
|
||||||
#[derive(AsAny, Default)]
|
#[derive(AsAny, Default)]
|
||||||
pub struct PolicycheckState {
|
pub struct PolicycheckState {
|
||||||
action: Option<PolicycheckAction>,
|
action: Option<PolicycheckAction>,
|
||||||
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
|
||||||
@@ -70,13 +71,8 @@ pub struct PolicycheckState {
|
|||||||
|
|
||||||
impl GlobalState for PolicycheckState {}
|
impl GlobalState for PolicycheckState {}
|
||||||
|
|
||||||
/// method definitions, that react on any given state change inside the view
|
/// Method definitions, that react on any given state change inside the `Policycheck` widget.
|
||||||
impl PolicycheckState {
|
impl PolicycheckState {
|
||||||
/// Sets a new action.
|
|
||||||
pub fn action(&mut self, action: PolicycheckAction) {
|
|
||||||
self.action = action.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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>> {
|
||||||
trace!(target: "advotracker", create_hashmap = "started");
|
trace!(target: "advotracker", create_hashmap = "started");
|
||||||
@@ -94,7 +90,7 @@ impl PolicycheckState {
|
|||||||
// Wip: use cli parameter stored in viperus ...
|
// Wip: use cli parameter stored in viperus ...
|
||||||
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||||
let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt");
|
let mut csv_import_path = String::from("POLLFNR_WOECHENTLICH.txt");
|
||||||
match import(&mut csv_import_path, &mut policy_data,
|
match allianzdirectcall::import(&mut csv_import_path, &mut policy_data,
|
||||||
&mut policy_numbers, &mut self.policy_data_count,
|
&mut policy_numbers, &mut self.policy_data_count,
|
||||||
&self.lang) {
|
&self.lang) {
|
||||||
Ok((count, duration)) => {
|
Ok((count, duration)) => {
|
||||||
@@ -131,7 +127,6 @@ impl PolicycheckState {
|
|||||||
|
|
||||||
if self.policy_numbers.len() == 0 {
|
if self.policy_numbers.len() == 0 {
|
||||||
// initialize popup widget
|
// initialize popup widget
|
||||||
//let sender = ctx.send_window_request();
|
|
||||||
self.set_popup_progress(ctx);
|
self.set_popup_progress(ctx);
|
||||||
self.progress_count += 0.33;
|
self.progress_count += 0.33;
|
||||||
self.update_progress_bar(ctx);
|
self.update_progress_bar(ctx);
|
||||||
@@ -173,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<'_>) {
|
||||||
@@ -319,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);
|
||||||
@@ -344,6 +326,11 @@ impl PolicycheckState {
|
|||||||
// ctx.get_widget(self.policy_check_policy_number).update_theme_by_state(true);
|
// ctx.get_widget(self.policy_check_policy_number).update_theme_by_state(true);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/// Sets a new action.
|
||||||
|
pub fn set_action(&mut self, action: PolicycheckAction) {
|
||||||
|
self.action = action.into();
|
||||||
|
}
|
||||||
|
|
||||||
/// Change status of given text box to edit mode.
|
/// Change status of given text box to edit mode.
|
||||||
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
||||||
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
||||||
@@ -355,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.
|
||||||
@@ -442,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 widget state
|
/// 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'.");
|
||||||
@@ -487,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 widget state.
|
/// Handle messages for `PolicycheckState`.
|
||||||
fn messages(
|
fn messages(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut messages: MessageReader,
|
mut messages: MessageReader,
|
||||||
@@ -496,24 +451,24 @@ impl State for PolicycheckState {
|
|||||||
) {
|
) {
|
||||||
for message in messages.read::<PolicycheckAction>() {
|
for message in messages.read::<PolicycheckAction>() {
|
||||||
match message {
|
match message {
|
||||||
PolicycheckAction::ChangeTheme() => {
|
PolicycheckAction::AddProgress(increment) => {
|
||||||
let theme_index = *PolicycheckView::selected_index_ref(&ctx.widget());
|
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
||||||
|
|
||||||
match theme_index {
|
let new_width = old_width + increment;
|
||||||
0 => ctx.switch_theme(theme_default_dark()),
|
// Set the ProgressBar's val property to the calculated percentage
|
||||||
1 => ctx.switch_theme(theme_default_light()),
|
// (whereas 0.0 means 0%, and 1.0 means 100%)
|
||||||
2 => ctx.switch_theme(theme_redox()),
|
if new_width <= 1. {
|
||||||
//3 => ctx.switch_theme(theme_fluent_dark()),
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), new_width);
|
||||||
//4 => ctx.switch_theme(theme_fluent_light()),
|
} else {
|
||||||
_ => {}
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the widget state.
|
/// 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 {
|
||||||
@@ -527,18 +482,6 @@ impl State for PolicycheckState {
|
|||||||
|
|
||||||
if let Some(action) = self.action {
|
if let Some(action) = self.action {
|
||||||
match action {
|
match action {
|
||||||
PolicycheckAction::AddProgress(increment) => {
|
|
||||||
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
|
||||||
|
|
||||||
let new_width = old_width + increment;
|
|
||||||
// Set the ProgressBar's val property to the calculated percentage
|
|
||||||
// (whereas 0.0 means 0 %, and 1.0 means 100 %) to increment the progress
|
|
||||||
if new_width <= 1. {
|
|
||||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), new_width);
|
|
||||||
} else {
|
|
||||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PolicycheckAction::ClearEntry(policy_check_policy_number) => {
|
PolicycheckAction::ClearEntry(policy_check_policy_number) => {
|
||||||
ctx.get_widget(policy_check_policy_number).set("enabled", false);
|
ctx.get_widget(policy_check_policy_number).set("enabled", false);
|
||||||
}
|
}
|
||||||
@@ -556,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);
|
||||||
}
|
}
|
||||||
@@ -566,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 => {
|
||||||
@@ -579,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);
|
||||||
@@ -591,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);
|
||||||
}
|
}
|
||||||
@@ -613,161 +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 => {
|
|
||||||
ctx.get_mut::<PolicycheckState>(menu)
|
|
||||||
.action(PolicycheckAction::RemoveMenu(menu));
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
true
|
|
||||||
})
|
|
||||||
.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)
|
|
||||||
.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)
|
|
||||||
.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 themes = vec![
|
|
||||||
"default_dark".to_string(),
|
|
||||||
"default_light".to_string(),
|
|
||||||
"redox".to_string(),
|
|
||||||
"fluent_dark".to_string(),
|
|
||||||
"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)
|
||||||
.action(PolicycheckAction::RemovePopup(popup_progress));
|
.set_action(PolicycheckAction::RemovePopup(id));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.child(
|
.child(
|
||||||
@@ -779,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)
|
||||||
@@ -794,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)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,29 +6,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use orbtk::prelude::*;
|
use orbtk::prelude::*;
|
||||||
|
use orbtk::shell::event::Key;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data::{
|
data::{
|
||||||
constants::*,
|
constants::*,
|
||||||
structures::PolicyCheck,
|
structures::PolicyCheck,
|
||||||
},
|
},
|
||||||
widgets::policycheck::policycheck_state::*,
|
//widgets::menu::menu_state::{MenuAction, MenuState},
|
||||||
|
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.
|
||||||
|
// PolicycheckView<PolicycheckState>: KeyDownHandler {
|
||||||
PolicycheckView<PolicycheckState> {
|
PolicycheckView<PolicycheckState> {
|
||||||
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
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -37,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))
|
||||||
@@ -81,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")
|
||||||
@@ -96,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)
|
||||||
.action(PolicycheckAction::OpenMenu(policy_check_label_menu));
|
// .set_action(MenuAction::CreateMenu(ID_MENU_STACK));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
@@ -169,32 +151,34 @@ impl Template for PolicycheckView {
|
|||||||
.on_activate(move |ctx, entity| {
|
.on_activate(move |ctx, entity| {
|
||||||
// Entity is entered/activated via Mouse/Keyboard
|
// 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)
|
ctx.get_mut::<PolicycheckState>(id)
|
||||||
.action(PolicycheckAction::ParseEntry(entity));
|
.set_action(PolicycheckAction::ParseEntry(entity));
|
||||||
})
|
})
|
||||||
//.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity))
|
//.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity))
|
||||||
// .on_changed(move |ctx, entity, _| {
|
// .on_changed(move |ctx, entity, _| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::SetProgressBox(entity));
|
// .set_action(Action::SetProgressBox(entity));
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::AddProgress(0.5));
|
// .set_action(Action::AddProgress(0.5));
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::InputTextChanged(entity));
|
// .set_action(Action::InputTextChanged(entity));
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::SetVisibility(entity));
|
// .set_action(Action::SetVisibility(entity));
|
||||||
// ctx.get_widget(policy_check_label_policy_number).set("visible");
|
// ctx.get_widget(policy_check_label_policy_number).set("visible");
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::SetVisility(entity));
|
// .set_action(Action::SetVisility(entity));
|
||||||
// })
|
// })
|
||||||
// .on_mouse_down | .on_mouse_move | .on_mouse_up (move |ctx, entity| {
|
// .on_mouse_down | .on_mouse_move | .on_mouse_up (move |ctx, entity| {
|
||||||
// state(id, states).action(Action::AddItem);
|
// state(id, states).set_action(Action::AddItem);
|
||||||
// })
|
// })
|
||||||
//.on_key_down(move |ctx, _| {
|
.on_key_down(move |_, key_event| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
if key_event.key == Key::A(true) {
|
||||||
// .action(Action::ImportData);
|
println!("A key down");
|
||||||
// true
|
}
|
||||||
//})
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
|
// .set_action(Action::ImportData);
|
||||||
|
true
|
||||||
|
})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.child(policy_check_button_result)
|
.child(policy_check_button_result)
|
||||||
@@ -313,7 +297,8 @@ impl Template for PolicycheckView {
|
|||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
// WIP: this widget type should handle our target natively
|
// WIP: this widget type should handle our target natively
|
||||||
// but it isn't able to get textinput ... yet
|
// but it isn't able to get textinput, nor handle usize values
|
||||||
|
// ... yet
|
||||||
let _policy_check_numeric_box = NumericBox::new()
|
let _policy_check_numeric_box = NumericBox::new()
|
||||||
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||||
.h_align("start")
|
.h_align("start")
|
||||||
@@ -326,14 +311,16 @@ impl Template for PolicycheckView {
|
|||||||
// WIP code @kivimango
|
// WIP code @kivimango
|
||||||
// .on_activate(move |ctx, entity| {
|
// .on_activate(move |ctx, entity| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::ParseEntry(entity));
|
// .set_action(Action::ParseEntry(entity));
|
||||||
// })
|
// })
|
||||||
// .on_changed(move |ctx, entity| {
|
// .on_changed(move |ctx, entity| {
|
||||||
// ctx.get_mut::<PolicycheckState>(id)
|
// ctx.get_mut::<PolicycheckState>(id)
|
||||||
// .action(Action::InputTextChanged(entity));
|
// .set_action(Action::InputTextChanged(entity));
|
||||||
//})
|
//})
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
|
// row3: only shown, if we read in `policy numbers` in
|
||||||
|
// a hashmap as values
|
||||||
let policy_data_stack = Stack::new()
|
let policy_data_stack = Stack::new()
|
||||||
.id(ID_POLICY_DATA_STACK)
|
.id(ID_POLICY_DATA_STACK)
|
||||||
.attach(Grid::row(3))
|
.attach(Grid::row(3))
|
||||||
@@ -365,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