callbacks/policycheck_state: convert to new API (orbtk-alpha4)
Before
* let text = *button(&mut ctx.widget()).text();
* let text = Button::get(&mut ctx.widget()).text();
* let text = *button(&mut ctx.widget()).clone_text();
* let text = Button::get(&mut ctx.widget()).clone_text();
* button(&mut ctx.widget()).text_mut().push_str("test");
* Button::get(&mut ctx.widget()).text_mut().push_str("test");
* button(&mut ctx.widget()).set_text(String16::from("test"));
* Button::get(&mut ctx.widget()).set_text(String16::from("test"));
Now
* let text = Button::text_clone(&ctx.widget());
* Button::text_mut(&mut ctx.widget()).push_str("test");
* Button::text_set(&mut ctx.widget(), String16::from("test"));
* ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), new_width);
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -20,13 +20,11 @@ use std::collections::HashMap;
|
|||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
use tracing::{debug, error, info, trace};
|
use tracing::{debug, error, info, trace};
|
||||||
|
|
||||||
use crate::services::imports::allianzdirectcall::import;
|
|
||||||
//use crate::callbacks::policy_check::is_valid;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
callbacks::global_state::GlobalState,
|
callbacks::global_state::GlobalState,
|
||||||
data::structures::{PolicyCode, PolicyDataList, PolicyList},
|
data::structures::{PolicyCode, PolicyDataList, PolicyList},
|
||||||
data::constants::*,
|
data::constants::*,
|
||||||
|
services::imports::allianzdirectcall::import,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Actions that can execute on the task view.
|
/// Actions that can execute on the task view.
|
||||||
@@ -69,11 +67,11 @@ pub struct PolicyCheckState {
|
|||||||
last_focused: Option<Entity>,
|
last_focused: Option<Entity>,
|
||||||
button_menu: Entity,
|
button_menu: Entity,
|
||||||
menu: Entity,
|
menu: Entity,
|
||||||
popup_progress: Entity,
|
|
||||||
policy_data_count: u64,
|
policy_data_count: u64,
|
||||||
policy_numbers: HashMap<u64, PolicyCode>,
|
policy_numbers: HashMap<u64, PolicyCode>,
|
||||||
progress_bar: Entity,
|
progress_bar: Entity,
|
||||||
progress_count: f64,
|
progress_count: f64,
|
||||||
|
progress_popup: Entity,
|
||||||
theme_name: String
|
theme_name: String
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,9 +132,8 @@ impl PolicyCheckState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Clear text in text box.
|
/// Clear text in text box.
|
||||||
pub fn clear_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
pub fn clear_entry(&mut self, _text_box: Entity, ctx: &mut Context<'_>) {
|
||||||
let mut text_box = TextBox::get(ctx.get_widget(text_box));
|
TextBox::text_set(&mut ctx.widget(), String::from(""));
|
||||||
let _text = text_box.text_mut();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the active language environment.
|
/// Get the active language environment.
|
||||||
@@ -160,8 +157,7 @@ impl PolicyCheckState {
|
|||||||
-> Result<(), Box<dyn std::error::Error>> {
|
-> Result<(), Box<dyn std::error::Error>> {
|
||||||
// WIP: for now, only import once per session
|
// WIP: for now, only import once per session
|
||||||
if self.policy_data_count == 0 {
|
if self.policy_data_count == 0 {
|
||||||
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
||||||
text_block_wrapper.set_enabled(true);
|
|
||||||
|
|
||||||
if self.policy_numbers.len() == 0 {
|
if self.policy_numbers.len() == 0 {
|
||||||
// initialize popup widget
|
// initialize popup widget
|
||||||
@@ -220,7 +216,8 @@ impl PolicyCheckState {
|
|||||||
ctx: &mut Context<'_>) {
|
ctx: &mut Context<'_>) {
|
||||||
trace!(target: "advotracker", parse_entry = "started");
|
trace!(target: "advotracker", parse_entry = "started");
|
||||||
|
|
||||||
let policy_number_string = ctx.get_widget(policy_check_policy_number).get::<String16>("text").as_string();
|
//let policy_number_string = ctx.get_widget(policy_check_policy_number).get::<String16>("text").as_string();
|
||||||
|
let policy_number_string = TextBox::text_clone(&mut ctx.get_widget(policy_check_policy_number));
|
||||||
let policy_number_length = policy_number_string.len();
|
let policy_number_length = policy_number_string.len();
|
||||||
|
|
||||||
// // WIP: redundant lang selection (already in main!)
|
// // WIP: redundant lang selection (already in main!)
|
||||||
@@ -245,80 +242,78 @@ impl PolicyCheckState {
|
|||||||
// Parse policy code: "AS-123456789"
|
// Parse policy code: "AS-123456789"
|
||||||
// DION VERS POLLFNR
|
// DION VERS POLLFNR
|
||||||
// 1 AS 1515735810
|
// 1 AS 1515735810
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Collapsed);
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Collapsed);
|
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
||||||
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
Button::background_set(&mut ctx.child("policy_check_button_result"), String::from("transparent"));
|
||||||
|
|
||||||
if policy_number_length == 10 {
|
if policy_number_length == 10 {
|
||||||
// cast policy_number_sting to <u64>
|
// cast policy_number_sting to <u64>
|
||||||
match policy_number_string.parse::<u64>() {
|
match policy_number_string.parse::<u64>() {
|
||||||
Ok(p) => {
|
Ok(p) => {
|
||||||
let mut result_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(""));
|
||||||
result_wrapper.set_text("");
|
|
||||||
// match hashmap's key
|
// match hashmap's key
|
||||||
match self.policy_numbers.get(&p) {
|
match self.policy_numbers.get(&p) {
|
||||||
Some(policy_code) => {
|
Some(policy_code) => {
|
||||||
// matching key, get associated value
|
// matching key, get associated value
|
||||||
trace!(target: "advotracker", state = "success",
|
trace!(target: "advotracker", state = "success",
|
||||||
policy_number = ?p, policy_code = ?policy_code);
|
policy_number = ?p, policy_code = ?policy_code);
|
||||||
result_wrapper.set_enabled(true);
|
|
||||||
let string_result = format!("1-{:?}-{}",
|
let string_result = format!("1-{:?}-{}",
|
||||||
policy_code, p);
|
policy_code, p);
|
||||||
result_wrapper.set_text(string_result);
|
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CHECK);
|
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(string_result));
|
||||||
button(ctx.child("policy_check_button_result")).set_icon_brush("#008000");
|
|
||||||
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
||||||
let res = t!("policy.validation.button_success", self.lang);
|
let res = t!("policy.validation.button_success", self.lang);
|
||||||
button(ctx.child("policy_check_button_result")).set_text(res);
|
Button::text_set(&mut ctx.child("policy_check_button_result"), String::from(res));
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
||||||
button(ctx.child("policy_check_button_result")).set_foreground("#008000");
|
Button::icon_set(&mut ctx.child("policy_check_button_result"), material_icons_font::MD_CHECK);
|
||||||
button(ctx.child("policy_check_button_result")).set_background("transparent");
|
Button::icon_brush_set(&mut ctx.child("policy_check_button_result"), String::from("#008000"));
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
Button::foreground_set(&mut ctx.child("policy_check_button_result"), String::from("#008000"));
|
||||||
|
Button::background_set(&mut ctx.child("policy_check_button_result"), String::from("transparent"));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// no matching key
|
// no matching key
|
||||||
let res = t!("policy.validation.failed", self.lang);
|
let res = t!("policy.validation.failed", self.lang);
|
||||||
trace!(target: "advotracker", state = ?res, policy_number = ?p);
|
trace!(target: "advotracker", state = ?res, policy_number = ?p);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
|
|
||||||
button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
||||||
let res = t!("policy.validation.button_failed", self.lang);
|
let res = t!("policy.validation.button_failed", self.lang);
|
||||||
button(ctx.child("policy_check_button_result")).set_text(res);
|
Button::text_set(&mut ctx.child("policy_check_button_result"), String::from(res));
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
||||||
button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
|
Button::icon_set(&mut ctx.child("policy_check_button_result"), material_icons_font::MD_CLEAR);
|
||||||
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
Button::icon_brush_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
||||||
|
Button::foreground_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
||||||
let res = t!("policy.validation.not_found", self.lang);
|
let res = t!("policy.validation.not_found", self.lang);
|
||||||
text_block_wrapper.set_text(res);
|
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e);
|
trace!(target: "advotracker", state = "error", error_type = "invalid type", error = ?e);
|
||||||
button(ctx.child("policy_check_button_result")).set_icon(material_icons_font::MD_CLEAR);
|
|
||||||
button(ctx.child("policy_check_button_result")).set_icon_brush("#FF0000");
|
Button::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
||||||
button(ctx.child("policy_check_button_result")).set_visibility(Visibility::Visible);
|
Button::icon_set(&mut ctx.child("policy_check_button_result"), material_icons_font::MD_CLEAR);
|
||||||
button(ctx.child("policy_check_button_result")).set_foreground("#FF0000");
|
Button::icon_brush_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
Button::foreground_set(&mut ctx.child("policy_check_button_result"), String::from("#FF0000"));
|
||||||
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
|
||||||
let res = t!("policy.validation.invalid_input", self.lang);
|
let res = t!("policy.validation.invalid_input", self.lang);
|
||||||
text_block_wrapper.set_text(res);
|
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
||||||
text_block_wrapper.set_enabled(true);
|
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if policy_number_length < 10 {
|
if policy_number_length < 10 {
|
||||||
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
|
||||||
text_block_wrapper.set_enabled(true);
|
|
||||||
let res = t!("policy.validation.to_short", self.lang);
|
let res = t!("policy.validation.to_short", self.lang);
|
||||||
text_block_wrapper.set_text(res);
|
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
||||||
//self.set_visibility(policy_check_policy_number, ctx);
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
||||||
}
|
}
|
||||||
if policy_number_length > 10 {
|
if policy_number_length > 10 {
|
||||||
let mut text_block_wrapper: TextBlockCtx<'_> = text_block(ctx.child("policy_check_result"));
|
|
||||||
text_block_wrapper.set_enabled(true);
|
|
||||||
let res = t!("policy.validation.to_long", self.lang);
|
let res = t!("policy.validation.to_long", self.lang);
|
||||||
text_block_wrapper.set_text(res);
|
TextBlock::text_set(&mut ctx.child("policy_check_result"), String::from(res));
|
||||||
text_block(ctx.child("policy_check_label_result")).set_visibility(Visibility::Visible);
|
TextBlock::enabled_set(&mut ctx.child("policy_check_result"), true);
|
||||||
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
trace!(target: "advotracker", parse_entry = "finished");
|
trace!(target: "advotracker", parse_entry = "finished");
|
||||||
@@ -327,7 +322,7 @@ impl PolicyCheckState {
|
|||||||
/// Remove the menu popup box
|
/// Remove the menu 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.menu);
|
ctx.remove_child(self.menu);
|
||||||
ctx.remove_child(self.popup_progress);
|
ctx.remove_child(self.progress_popup);
|
||||||
println!("Popup {:?} removed !", id);
|
println!("Popup {:?} removed !", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,17 +340,13 @@ impl PolicyCheckState {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
/// Change status of given text box to edit mode.
|
/// Change status of given text box to edit mode.
|
||||||
fn set_entry(&mut self, policy_check_policy_number: Entity, ctx: &mut Context<'_>) {
|
fn set_entry(&mut self, text_box: Entity, ctx: &mut Context<'_>) {
|
||||||
if *ctx.get_widget(policy_check_policy_number).get::<bool>("focused") {
|
if ctx.get_widget(text_box).get::<String16>("text").is_empty() {
|
||||||
let mut text_box_wrapper: TextBoxCtx<'_> = text_box(ctx.child("policy_check_policy_number"));
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Collapsed);
|
||||||
text_box_wrapper.set_visibility( Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Collapsed);
|
||||||
text_box_wrapper.set_enabled(true);
|
} else {
|
||||||
text_box_wrapper.set_text("");
|
TextBlock::visibility_set(&mut ctx.child("policy_check_label_result"), Visibility::Visible);
|
||||||
return;
|
TextBlock::visibility_set(&mut ctx.child("policy_check_button_result"), Visibility::Visible);
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(old_focused_element) = ctx.window().get::<Global>("global").focused_widget {
|
|
||||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(old_focused_element));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,11 +361,11 @@ impl PolicyCheckState {
|
|||||||
.expect("PolicyCheckState: Can't create overlay as child of entity");
|
.expect("PolicyCheckState: Can't create overlay as child of entity");
|
||||||
|
|
||||||
let label_account = t!("policy.menu.label_account", self.lang);
|
let label_account = t!("policy.menu.label_account", self.lang);
|
||||||
button(ctx.child(ID_POLICY_CHECK_MENU_LABEL_ACCOUNT)).set_text(label_account);
|
Button::text_set(&mut ctx.child(ID_POLICY_CHECK_MENU_LABEL_ACCOUNT), String::from(label_account));
|
||||||
let label_quit = t!("policy.menu.label_quit", self.lang);
|
let label_quit = t!("policy.menu.label_quit", self.lang);
|
||||||
button(ctx.child(ID_POLICY_CHECK_MENU_LABEL_QUIT)).set_text(label_quit);
|
Button::text_set(&mut ctx.child(ID_POLICY_CHECK_MENU_LABEL_QUIT), String::from(label_quit));
|
||||||
let label_toggle_theme = t!("policy.menu.label_toggle_theme", self.lang);
|
let label_toggle_theme = t!("policy.menu.label_toggle_theme", self.lang);
|
||||||
button(ctx.child(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME)).set_text(label_toggle_theme);
|
Button::text_set(&mut ctx.child(ID_POLICY_CHECK_MENU_LABEL_TOGGLE_THEME), String::from(label_toggle_theme));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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
|
||||||
@@ -387,29 +378,29 @@ impl PolicyCheckState {
|
|||||||
let build_context = &mut ctx.build_context();
|
let build_context = &mut ctx.build_context();
|
||||||
|
|
||||||
let res = t!("policy.string.progress_text", self.lang);
|
let res = t!("policy.string.progress_text", self.lang);
|
||||||
self.popup_progress = create_popup_progress(current_entity, &res, build_context);
|
self.progress_popup = create_popup_progress(current_entity, &res, build_context);
|
||||||
|
|
||||||
// create a progress_popup widget as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER"
|
// create a progress_popup widget as a child of entity "ID_POLICY_CHECK_POLICY_NUMBER"
|
||||||
build_context.append_child(stack, self.popup_progress);
|
build_context.append_child(stack, self.progress_popup);
|
||||||
|
|
||||||
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!("PopupProgress created: {:?}", self.popup_progress);
|
println!("PopupProgress created: {:?}", self.progress_popup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change visibility of the result label.
|
/// Change visibility of the result label.
|
||||||
fn _set_visibility(&self, entity: Entity, ctx: &mut Context<'_>) {
|
fn _set_visibility(&self, entity: Entity, ctx: &mut Context<'_>) {
|
||||||
if ctx.get_widget(entity).get::<String16>("text").is_empty() {
|
if ctx.get_widget(entity).get::<String16>("text").is_empty() {
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_BUTTON_RESULT)).set_visibility(Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Collapsed);
|
||||||
} else {
|
} else {
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Visible);
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_BUTTON_RESULT)).set_visibility(Visibility::Visible);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_BUTTON_RESULT), Visibility::Visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ctx.get_widget(self.label_result).update_theme_by_state(true);
|
//ctx.get_widget(self.label_result).update_theme_by_state(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -444,7 +435,8 @@ impl PolicyCheckState {
|
|||||||
fn update_progress_bar(&self, ctx: &mut Context<'_>) {
|
fn update_progress_bar(&self, ctx: &mut Context<'_>) {
|
||||||
let res = t!("policy.string.progress_time", self.lang);
|
let res = t!("policy.string.progress_time", self.lang);
|
||||||
let string_duration = format!("{}: {:?}", res, self.duration);
|
let string_duration = format!("{}: {:?}", res, self.duration);
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_PROGRESS_TIME)).set_text(string_duration);
|
|
||||||
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_TIME), String::from(string_duration));
|
||||||
|
|
||||||
let mut progress_bar = ctx.child(ID_POLICY_CHECK_PROGRESS_BAR);
|
let mut progress_bar = ctx.child(ID_POLICY_CHECK_PROGRESS_BAR);
|
||||||
progress_bar.set::<f64>("val", self.progress_count);
|
progress_bar.set::<f64>("val", self.progress_count);
|
||||||
@@ -482,16 +474,16 @@ impl State for PolicyCheckState {
|
|||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
let res = t!("policy.string.header", self.lang);
|
let res = t!("policy.string.header", self.lang);
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_HEADER)).set_text(res);
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_HEADER), String::from(res));
|
||||||
|
|
||||||
let res = t!("policy.string.label_policy_number", self.lang);
|
let res = t!("policy.string.label_policy_number", self.lang);
|
||||||
let string_label_policy_number = format!("{}:", res);
|
let string_label_policy_number = format!("{}:", res);
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_POLICY_NUMBER)).set_text(string_label_policy_number);
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_POLICY_NUMBER), String::from(string_label_policy_number));
|
||||||
|
|
||||||
let res = t!("policy.string.label_result", self.lang);
|
let res = t!("policy.string.label_result", self.lang);
|
||||||
let string_label_result = format!("{}:", res);
|
let string_label_result = format!("{}:", res);
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_text(string_label_result);
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), String::from(string_label_result));
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
|
|
||||||
// // Load the saved data from a file in 'ron' format into our data structure.
|
// // Load the saved data from a file in 'ron' format into our data structure.
|
||||||
// // The cargo package identifier (default: 'nwx.advotracker') is used as the
|
// // The cargo package identifier (default: 'nwx.advotracker') is used as the
|
||||||
@@ -526,21 +518,22 @@ impl State for PolicyCheckState {
|
|||||||
if let Some(action) = self.action {
|
if let Some(action) = self.action {
|
||||||
match action {
|
match action {
|
||||||
Action::AddProgress(increment) => {
|
Action::AddProgress(increment) => {
|
||||||
let old_width = *progress_bar(ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)).val();
|
let old_width = ProgressBar::val_clone(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR));
|
||||||
|
|
||||||
let new_width = old_width + increment;
|
let new_width = old_width + increment;
|
||||||
// Set the ProgressBar's val property to the calculated percentage
|
// Set the ProgressBar's val property to the calculated percentage
|
||||||
// (whereas 0.0 means 0 %, and 1.0 means 100 %) to increment the progress
|
// (whereas 0.0 means 0 %, and 1.0 means 100 %) to increment the progress
|
||||||
if new_width <= 1. {
|
if new_width <= 1. {
|
||||||
progress_bar(ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)).set_val(new_width);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), new_width);
|
||||||
} else {
|
} else {
|
||||||
progress_bar(ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)).set_val(1.);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 1.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::ClearEntry(policy_check_policy_number) => {
|
Action::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);
|
||||||
}
|
}
|
||||||
Action::InputTextChanged(entity) => {
|
Action::InputTextChanged(entity) => {
|
||||||
println!("entry changed: {}", text_box(ctx.get_widget(entity)).text());
|
println!("entry changed: {}", TextBox::text_clone(&ctx.get_widget(entity)));
|
||||||
}
|
}
|
||||||
Action::ImportData => {
|
Action::ImportData => {
|
||||||
match self.import_data(ctx) {
|
match self.import_data(ctx) {
|
||||||
@@ -567,7 +560,7 @@ impl State for PolicyCheckState {
|
|||||||
self.remove_popup(entity, ctx);
|
self.remove_popup(entity, ctx);
|
||||||
}
|
}
|
||||||
Action::ResetProgress => {
|
Action::ResetProgress => {
|
||||||
progress_bar(ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)).set_val(0.);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.);
|
||||||
}
|
}
|
||||||
Action::SetEntry(policy_check_policy_number) => {
|
Action::SetEntry(policy_check_policy_number) => {
|
||||||
//self.last_focused = Some();
|
//self.last_focused = Some();
|
||||||
@@ -578,16 +571,15 @@ impl State for PolicyCheckState {
|
|||||||
}
|
}
|
||||||
Action::SetProgress(value) => {
|
Action::SetProgress(value) => {
|
||||||
if value >= 0. || value <= 1. {
|
if value >= 0. || value <= 1. {
|
||||||
progress_bar(ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)).set_val(value);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), value);
|
||||||
} else {
|
} else {
|
||||||
progress_bar(ctx.child(ID_POLICY_CHECK_PROGRESS_BAR)).set_val(0.);
|
ProgressBar::val_set(&mut ctx.child(ID_POLICY_CHECK_PROGRESS_BAR), 0.);
|
||||||
}
|
} }
|
||||||
}
|
|
||||||
Action::SetProgressPopup(_entity) => {
|
Action::SetProgressPopup(_entity) => {
|
||||||
self.set_popup_progress(ctx);
|
self.set_popup_progress(ctx);
|
||||||
}
|
}
|
||||||
Action::SetVisibility(_entity) => {
|
Action::SetVisibility(_entity) => {
|
||||||
text_block(ctx.child(ID_POLICY_CHECK_LABEL_RESULT)).set_visibility(Visibility::Collapsed);
|
TextBlock::visibility_set(&mut ctx.child(ID_POLICY_CHECK_LABEL_RESULT), Visibility::Collapsed);
|
||||||
}
|
}
|
||||||
Action::TextChanged(entity, _index) => {
|
Action::TextChanged(entity, _index) => {
|
||||||
self.set_entry(entity, ctx);
|
self.set_entry(entity, ctx);
|
||||||
@@ -628,7 +620,7 @@ impl State for PolicyCheckState {
|
|||||||
|
|
||||||
let res = t!("policy.string.data_count", lang);
|
let res = t!("policy.string.data_count", lang);
|
||||||
let string_data_count = format!("{}: {:?}", res, self.policy_numbers.len());
|
let string_data_count = format!("{}: {:?}", res, self.policy_numbers.len());
|
||||||
text_block(ctx.child(ID_POLICY_DATA_COUNT_BLOCK)).set_text(string_data_count);
|
TextBlock::text_set(&mut ctx.child(ID_POLICY_DATA_COUNT_BLOCK), String::from(string_data_count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,7 +713,7 @@ fn create_popup_progress(target: Entity, text: &str, ctx: &mut BuildContext<'_>)
|
|||||||
.id(ID_POLICY_CHECK_POPUP_PROGRESS)
|
.id(ID_POLICY_CHECK_POPUP_PROGRESS)
|
||||||
.target(target)
|
.target(target)
|
||||||
.open(true)
|
.open(true)
|
||||||
//.style("popup_progress")
|
//.style("popup_progress")
|
||||||
.width(280)
|
.width(280)
|
||||||
.height(100)
|
.height(100)
|
||||||
.on_mouse_down(move |ctx, _| {
|
.on_mouse_down(move |ctx, _| {
|
||||||
@@ -738,7 +730,7 @@ fn create_popup_progress(target: Entity, text: &str, 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)
|
.font_size(12)
|
||||||
.text(text)
|
.text(text)
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
@@ -747,13 +739,13 @@ fn create_popup_progress(target: Entity, text: &str, ctx: &mut BuildContext<'_>)
|
|||||||
ProgressBar::new()
|
ProgressBar::new()
|
||||||
.id(ID_POLICY_CHECK_PROGRESS_BAR)
|
.id(ID_POLICY_CHECK_PROGRESS_BAR)
|
||||||
.val(0)
|
.val(0)
|
||||||
//.width(250)
|
//.width(250)
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
)
|
)
|
||||||
.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)
|
.font_size(12)
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
|
|||||||
Reference in New Issue
Block a user