Compare commits
13 Commits
main
...
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",
|
||||
|
||||
// localization view
|
||||
"Hello": "Hallo",
|
||||
"User": "Anwender",
|
||||
"Language ID": "Sprache ID",
|
||||
"Localization dialog": "Lokalisierungs-Dialog",
|
||||
"German": "Deutsch",
|
||||
"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 (
|
||||
styles: {
|
||||
"button_single_content_segmdl2": (
|
||||
base: "button_single_content",
|
||||
properties: {
|
||||
"icon font": "$SEGEO_ICON_FONT",
|
||||
},
|
||||
),
|
||||
"container_master_detail": (
|
||||
"container_form": (
|
||||
base: "container",
|
||||
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_HEADER: &str = "localization_header";
|
||||
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_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_ROW_0: &str = "policy_check_form_row_0";
|
||||
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_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_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_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_PROGRESS_BAR: &str = "policy_check_progress_bar";
|
||||
pub static ID_POLICY_CHECK_PROGRESS_TIME: &str = "policy_check_progress_time";
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
//use chrono::{Local, DateTime};
|
||||
use dotenv::dotenv;
|
||||
use locales::t;
|
||||
use cfg_if::cfg_if;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
//use std::process;
|
||||
@@ -21,15 +22,15 @@ use tracing::{info, trace, Level};
|
||||
|
||||
use orbtk::{
|
||||
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
|
||||
use advotracker::{
|
||||
widgets::{
|
||||
main_view,
|
||||
//policycheck::policycheck_state::PolicyCheckState,
|
||||
}
|
||||
};
|
||||
use advotracker::widgets::main_view;
|
||||
|
||||
mod parse_args;
|
||||
|
||||
@@ -44,8 +45,13 @@ struct Environment {
|
||||
}
|
||||
|
||||
// Style extension
|
||||
//static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/fluent_dark.ron");
|
||||
//static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/fluent_light.ron");
|
||||
static DEFAULT_DARK_EXT: &str = include_str!("../assets/advotracker/default_dark.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.
|
||||
static ADVOTRACKER_DE_DE: &str = include_str!("../assets/advotracker/advotracker_de_DE.ron");
|
||||
@@ -67,19 +73,42 @@ 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)),
|
||||
// ))
|
||||
// }
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
/// 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 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>> {
|
||||
use parse_args::parse_args;
|
||||
@@ -152,6 +181,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
Application::from_name("nwx.advotracker")
|
||||
.localization(localization)
|
||||
.theme(theme())
|
||||
.window(|ctx| {
|
||||
Window::new()
|
||||
.title("AdvoTracker - DirectCall")
|
||||
|
||||
@@ -27,7 +27,7 @@ impl Template for ConfigurationView {
|
||||
self.child(
|
||||
Grid::new()
|
||||
.id(ID_CONFIGURATION_FORM)
|
||||
.margin(4)
|
||||
.style(configuration_form)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(120)
|
||||
@@ -56,7 +56,7 @@ impl Template for ConfigurationView {
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_CONFIGURATION_CONFIG_FILE)
|
||||
.id(ID_CONFIGURATION_LABEL_CONFIG_FILE)
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(2))
|
||||
.v_align("center")
|
||||
|
||||
@@ -37,7 +37,7 @@ impl Template for LocalizationView {
|
||||
Columns::create()
|
||||
.push(120)
|
||||
.push(12)
|
||||
.push("auto")
|
||||
.push(150)
|
||||
)
|
||||
.rows(Rows::create()
|
||||
.push("auto")
|
||||
@@ -59,10 +59,22 @@ impl Template for LocalizationView {
|
||||
.style("header")
|
||||
.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(
|
||||
ComboBox::new()
|
||||
.id(ID_LOCALIZATION_LANGUAGES)
|
||||
.count(count)
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(2))
|
||||
.items_builder(move |bc, index| {
|
||||
let text = bc.get_widget(id)
|
||||
.get::<Vec<String>>("languages")[index]
|
||||
|
||||
@@ -12,6 +12,7 @@ use crate::{
|
||||
widgets::policycheck::policycheck_view::PolicycheckView,
|
||||
widgets::localization::localization_view::LocalizationView,
|
||||
widgets::configuration::configuration_view::ConfigurationView,
|
||||
widgets::menu::menu_view::MenuView,
|
||||
};
|
||||
|
||||
// [START] views
|
||||
@@ -57,6 +58,7 @@ impl Template for MainView {
|
||||
.tab("Policynumber check", policycheck_view)
|
||||
.tab("Localization", LocalizationView::new().build(ctx))
|
||||
.tab("Configuration", ConfigurationView::new().build(ctx))
|
||||
.tab("Menu", MenuView::new().build(ctx))
|
||||
.build(ctx),
|
||||
)
|
||||
//.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)
|
||||
*/
|
||||
|
||||
/// The configuration widget.
|
||||
/// Configuration widget.
|
||||
pub mod configuration;
|
||||
|
||||
/// The global helper functions.
|
||||
/// Global helper functions.
|
||||
pub mod global_state;
|
||||
|
||||
/// The localization widget.
|
||||
/// Localization widget.
|
||||
pub mod localization;
|
||||
|
||||
/// The starting point (Main View).
|
||||
pub mod main_view;
|
||||
|
||||
/// The policycheck wigdet.
|
||||
/// Menu widget.
|
||||
pub mod menu;
|
||||
|
||||
/// Policycheck wigdet.
|
||||
pub mod policycheck;
|
||||
|
||||
// /// The policydata widget.
|
||||
// /// Policydata widget.
|
||||
// pub mod policydata;
|
||||
|
||||
// /// The policylists widget.
|
||||
// /// Policylists widget.
|
||||
// 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 orbtk::prelude::*;
|
||||
use orbtk::shell::event::Key;
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::process;
|
||||
@@ -9,16 +15,17 @@ use std::time::{Duration, SystemTime};
|
||||
use tracing::{error, info, trace};
|
||||
|
||||
use crate::{
|
||||
widgets::global_state::GlobalState,
|
||||
widgets::policycheck::policycheck_view::PolicycheckView,
|
||||
data::{
|
||||
structures::{PolicyCode, PolicyDataList, PolicyList},
|
||||
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)]
|
||||
pub enum PolicycheckAction {
|
||||
AddProgress(f64),
|
||||
@@ -26,13 +33,10 @@ pub enum PolicycheckAction {
|
||||
ChangeTheme(),
|
||||
InputTextChanged(Entity),
|
||||
ImportData,
|
||||
OpenMenu(Entity),
|
||||
ParseEntry(Entity),
|
||||
RemoveFocus(Entity),
|
||||
RemoveMenu(Entity),
|
||||
RemovePopup(Entity),
|
||||
ResetProgress,
|
||||
SetMenuPopup(Entity),
|
||||
SetProgress(f64),
|
||||
SetProgressPopup(Entity),
|
||||
SetToggleTheme(Entity),
|
||||
@@ -41,28 +45,25 @@ pub enum PolicycheckAction {
|
||||
TextChanged(Entity, usize)
|
||||
}
|
||||
|
||||
/// define valid environment variables provided via .env files
|
||||
/// located in the current call directory
|
||||
/// this is primarily used in testing scenarios (eg. debugging)
|
||||
/// Define valid environment variables provided via .env files
|
||||
/// located in the current call directory.
|
||||
/// This is primarily used in testing scenarios (eg. debugging).
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Environment {
|
||||
test_lang: String,
|
||||
rust_log: String,
|
||||
}
|
||||
|
||||
/// Handles the requests from `PolicycheckView`.
|
||||
/// Valid `structures` that are handled inside the state of the `Policycheck` widget.
|
||||
#[derive(AsAny, Default)]
|
||||
pub struct PolicycheckState {
|
||||
action: Option<PolicycheckAction>,
|
||||
duration: Duration,
|
||||
label_result: Entity,
|
||||
lang: String,
|
||||
//last_focused: Option<Entity>,
|
||||
button_menu: Entity,
|
||||
policy_data_count: u64,
|
||||
policy_numbers: HashMap<u64, PolicyCode>,
|
||||
popup_menu: Entity,
|
||||
popup_menu_toggle_theme: Entity,
|
||||
progress_bar: Entity,
|
||||
progress_count: f64,
|
||||
progress_popup: Entity
|
||||
@@ -70,13 +71,8 @@ pub struct 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 {
|
||||
/// Sets a new action.
|
||||
pub fn action(&mut self, action: PolicycheckAction) {
|
||||
self.action = action.into();
|
||||
}
|
||||
|
||||
/// Create a hashmap (key: policy number, value: policy type).
|
||||
pub fn create_hashmap(&mut self, _ctx: &mut Context<'_>) -> Result<(), Box<dyn std::error::Error>> {
|
||||
trace!(target: "advotracker", create_hashmap = "started");
|
||||
@@ -94,7 +90,7 @@ impl PolicycheckState {
|
||||
// Wip: use cli parameter stored in viperus ...
|
||||
//let mut csv_import_path = v.get::<String>("import_file").unwrap();
|
||||
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,
|
||||
&self.lang) {
|
||||
Ok((count, duration)) => {
|
||||
@@ -131,7 +127,6 @@ impl PolicycheckState {
|
||||
|
||||
if self.policy_numbers.len() == 0 {
|
||||
// initialize popup widget
|
||||
//let sender = ctx.send_window_request();
|
||||
self.set_popup_progress(ctx);
|
||||
self.progress_count += 0.33;
|
||||
self.update_progress_bar(ctx);
|
||||
@@ -173,13 +168,6 @@ impl PolicycheckState {
|
||||
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.
|
||||
fn parse_entry(&mut self, policy_check_policy_number: Entity,
|
||||
ctx: &mut Context<'_>) {
|
||||
@@ -319,12 +307,6 @@ impl PolicycheckState {
|
||||
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
|
||||
fn remove_popup(&mut self, id: Entity, ctx: &mut Context<'_>) {
|
||||
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);
|
||||
// }
|
||||
|
||||
/// 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.
|
||||
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
||||
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
|
||||
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
|
||||
.entity_of_child(ID_POLICY_CHECK_RESULT)
|
||||
.expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_RESULT'.");
|
||||
.entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||
.expect("PolicycheckState: Can't find entity of resource 'ID_POLICY_CHECK_POLICY_NUMBER'.");
|
||||
let current_entity = ctx.entity();
|
||||
let build_context = &mut ctx.build_context();
|
||||
|
||||
// create the progress_popup widget
|
||||
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);
|
||||
|
||||
// make sure we have a
|
||||
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'.");
|
||||
println!("New entity `progress_bar` created: {:?}", self.progress_bar);
|
||||
|
||||
println!("PopupProgress created: {:?}", self.progress_popup);
|
||||
}
|
||||
|
||||
/// 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);
|
||||
println!("function `set_popup_progress()` finished!");
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
/// Initialize the widget state
|
||||
/// Initialize the state of widgets inside `PolicycheckState`
|
||||
fn init(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
||||
let time_start= SystemTime::now();
|
||||
|
||||
trace!(target: "advotracker", policycheck_state = "init", status = "started");
|
||||
|
||||
// Entities
|
||||
// Initialize required 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'.");
|
||||
@@ -487,7 +442,7 @@ impl State for PolicycheckState {
|
||||
trace!(target: "advotracker", policycheck_state = "init", status = "finished", duration = ?duration);
|
||||
}
|
||||
|
||||
/// Handle messages inside the widget state.
|
||||
/// Handle messages for `PolicycheckState`.
|
||||
fn messages(
|
||||
&mut self,
|
||||
mut messages: MessageReader,
|
||||
@@ -496,24 +451,24 @@ impl State for PolicycheckState {
|
||||
) {
|
||||
for message in messages.read::<PolicycheckAction>() {
|
||||
match message {
|
||||
PolicycheckAction::ChangeTheme() => {
|
||||
let theme_index = *PolicycheckView::selected_index_ref(&ctx.widget());
|
||||
PolicycheckAction::AddProgress(increment) => {
|
||||
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
||||
|
||||
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()),
|
||||
_ => {}
|
||||
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%)
|
||||
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.);
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the widget state.
|
||||
/// Update the state of widgets inside the `Policycheck` view.
|
||||
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context<'_>) {
|
||||
// // clear focus on focus moved
|
||||
// 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 {
|
||||
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) => {
|
||||
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) => {
|
||||
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.EventAdapter(FocusEvent::RemoveFocus(policy_check_policy_number));
|
||||
}
|
||||
PolicycheckAction::RemoveMenu(entity) => {
|
||||
self.remove_menu(entity, ctx);
|
||||
}
|
||||
PolicycheckAction::RemovePopup(entity) => {
|
||||
//println!("WIP: remove popup");
|
||||
self.remove_popup(entity, ctx);
|
||||
}
|
||||
PolicycheckAction::ResetProgress => {
|
||||
@@ -579,9 +517,6 @@ impl State for PolicycheckState {
|
||||
//self.last_focused = Some();
|
||||
self.set_entry(policy_check_policy_number, ctx);
|
||||
}
|
||||
PolicycheckAction::SetMenuPopup(_entity) => {
|
||||
self.set_popup_menu(ctx);
|
||||
}
|
||||
PolicycheckAction::SetProgress(value) => {
|
||||
if value >= 0. || value <= 1. {
|
||||
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), value);
|
||||
@@ -591,10 +526,6 @@ impl State for PolicycheckState {
|
||||
PolicycheckAction::SetProgressPopup(_entity) => {
|
||||
self.set_popup_progress(ctx);
|
||||
}
|
||||
PolicycheckAction::SetToggleTheme(_entity) => {
|
||||
self.set_menu_toggle_theme(ctx);
|
||||
//self.remove_popup(_entity, ctx);
|
||||
}
|
||||
PolicycheckAction::SetVisibility(_entity) => {
|
||||
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
|
||||
fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
fn create_popup_progress(id: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
Popup::new()
|
||||
.id(ID_POLICY_CHECK_POPUP_PROGRESS)
|
||||
.target(popup_progress)
|
||||
.target(id)
|
||||
.open(true)
|
||||
//.style("popup_progress")
|
||||
.style("popup_progress")
|
||||
.width(280)
|
||||
.height(100)
|
||||
.on_mouse_down(move |ctx, _| {
|
||||
.on_click(move |ctx, _| {
|
||||
println!("create_popup_progress: on_click -> remove_popup(popup_progress)");
|
||||
ctx.get_mut::<PolicycheckState>(popup_progress)
|
||||
.action(PolicycheckAction::RemovePopup(popup_progress));
|
||||
ctx.get_mut::<PolicycheckState>(id)
|
||||
.set_action(PolicycheckAction::RemovePopup(id));
|
||||
true
|
||||
})
|
||||
.child(
|
||||
@@ -779,14 +568,14 @@ fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) ->
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_PROGRESS_TEXT)
|
||||
//.style("textblock_progress")
|
||||
.font_size(12)
|
||||
.style("textblock_progress")
|
||||
.text("Importing data")
|
||||
.build(ctx)
|
||||
)
|
||||
.child(
|
||||
ProgressBar::new()
|
||||
.id(ID_POLICY_CHECK_PROGRESS_BAR)
|
||||
.style("progress_bar")
|
||||
.val(0)
|
||||
//.width(250)
|
||||
.build(ctx)
|
||||
@@ -794,9 +583,8 @@ fn create_popup_progress(popup_progress: Entity, ctx: &mut BuildContext<'_>) ->
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.id(ID_POLICY_CHECK_PROGRESS_TIME)
|
||||
//.style("textblock_progress")
|
||||
.style("textblock_progress")
|
||||
.h_align("end")
|
||||
.font_size(12)
|
||||
.text("Processing time")
|
||||
.build(ctx)
|
||||
)
|
||||
|
||||
@@ -6,29 +6,27 @@
|
||||
*/
|
||||
|
||||
use orbtk::prelude::*;
|
||||
use orbtk::shell::event::Key;
|
||||
|
||||
use crate::{
|
||||
data::{
|
||||
constants::*,
|
||||
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 our view
|
||||
// Macro that initializes the widget structures/variables for the policy check view
|
||||
widget!(
|
||||
/// Dialog to enter a policy identifier/number.
|
||||
/// This identifier is checked agains a map of valid policy codes.
|
||||
// PolicycheckView<PolicycheckState>: KeyDownHandler {
|
||||
PolicycheckView<PolicycheckState> {
|
||||
lang: String,
|
||||
policy_check: PolicyCheck,
|
||||
policy_check_title: String,
|
||||
policy_data_count: u32,
|
||||
selected_index: i32,
|
||||
theme_name: String,
|
||||
themes: List
|
||||
policy_data_count: u32
|
||||
}
|
||||
);
|
||||
|
||||
@@ -37,14 +35,6 @@ widget!(
|
||||
impl Template for PolicycheckView {
|
||||
//fn template(self, policycheck_view: 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()
|
||||
//.style(STYLE_BOTTOM_BAR)
|
||||
.attach(Grid::row(4))
|
||||
@@ -81,14 +71,6 @@ impl Template for PolicycheckView {
|
||||
)
|
||||
.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()
|
||||
.id(ID_POLICY_CHECK_BUTTON_MENU)
|
||||
.style("button_single_content")
|
||||
@@ -96,10 +78,10 @@ impl Template for PolicycheckView {
|
||||
.attach(Grid::column(2))
|
||||
//.min_size(16, 16)
|
||||
.h_align("end")
|
||||
.on_click(move |ctx, _| {
|
||||
//ctx.get_mut::<PolicycheckState>(policycheck_state)
|
||||
ctx.get_mut::<PolicycheckState>(id)
|
||||
.action(PolicycheckAction::OpenMenu(policy_check_label_menu));
|
||||
.on_click(move |_ctx, _| {
|
||||
println!("WIP: open menu popup from MenuView");
|
||||
// ctx.get_mut::<MenuState>(id)
|
||||
// .set_action(MenuAction::CreateMenu(ID_MENU_STACK));
|
||||
true
|
||||
})
|
||||
.build(ctx);
|
||||
@@ -169,32 +151,34 @@ impl Template for PolicycheckView {
|
||||
.on_activate(move |ctx, entity| {
|
||||
// Entity is entered/activated via Mouse/Keyboard
|
||||
//ctx.get_mut::<PolicycheckState>(policy_check_view)
|
||||
println!("ParseEntry: {:?}", entity);
|
||||
ctx.get_mut::<PolicycheckState>(id)
|
||||
.action(PolicycheckAction::ParseEntry(entity));
|
||||
.set_action(PolicycheckAction::ParseEntry(entity));
|
||||
})
|
||||
//.on_changed(|_, entity, _, _| println!("Selection changed: {:?}", entity))
|
||||
// .on_changed(move |ctx, entity, _| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::SetProgressBox(entity));
|
||||
// .set_action(Action::SetProgressBox(entity));
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::AddProgress(0.5));
|
||||
// .set_action(Action::AddProgress(0.5));
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::InputTextChanged(entity));
|
||||
// .set_action(Action::InputTextChanged(entity));
|
||||
// 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_mut::<PolicycheckState>(id)
|
||||
// .action(Action::SetVisility(entity));
|
||||
// .set_action(Action::SetVisility(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, _| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::ImportData);
|
||||
// true
|
||||
//})
|
||||
.on_key_down(move |_, key_event| {
|
||||
if key_event.key == Key::A(true) {
|
||||
println!("A key down");
|
||||
}
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .set_action(Action::ImportData);
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(policy_check_button_result)
|
||||
@@ -313,7 +297,8 @@ impl Template for PolicycheckView {
|
||||
.build(ctx);
|
||||
|
||||
// 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()
|
||||
.id(ID_POLICY_CHECK_POLICY_NUMBER)
|
||||
.h_align("start")
|
||||
@@ -326,14 +311,16 @@ impl Template for PolicycheckView {
|
||||
// WIP code @kivimango
|
||||
// .on_activate(move |ctx, entity| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::ParseEntry(entity));
|
||||
// .set_action(Action::ParseEntry(entity));
|
||||
// })
|
||||
// .on_changed(move |ctx, entity| {
|
||||
// ctx.get_mut::<PolicycheckState>(id)
|
||||
// .action(Action::InputTextChanged(entity));
|
||||
// .set_action(Action::InputTextChanged(entity));
|
||||
//})
|
||||
.build(ctx);
|
||||
|
||||
// row3: only shown, if we read in `policy numbers` in
|
||||
// a hashmap as values
|
||||
let policy_data_stack = Stack::new()
|
||||
.id(ID_POLICY_DATA_STACK)
|
||||
.attach(Grid::row(3))
|
||||
@@ -365,7 +352,6 @@ impl Template for PolicycheckView {
|
||||
self.name("PolicycheckView")
|
||||
// initialize struct (derived default macro)
|
||||
.policy_check(PolicyCheck::default())
|
||||
.themes(themes)
|
||||
.child(
|
||||
Grid::new()
|
||||
.id(ID_POLICY_CHECK_WIDGET)
|
||||
|
||||
Reference in New Issue
Block a user