frontend: function update

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-06-27 22:30:50 +02:00
parent 22ecaaa0fe
commit 267c4faa2c
11 changed files with 972 additions and 691 deletions

View File

@@ -2,7 +2,7 @@ use orbtk::prelude::*;
use crate::{
base_state::BaseState,
//data::{PolicyData, PolicyList},
data::{PolicyData, PolicyDataList},
keys::*,
};
@@ -11,13 +11,14 @@ use crate::{
pub enum Action {
ClearEntry(Entity),
InputTextChanged(Entity),
OpenMenu(Entity),
ParseEntry(Entity),
RemoveFocus(Entity),
SetEntry(Entity),
TextChanged(Entity, usize),
}
/// Handles the requests of the `OverviewView`.
/// Handles the requests of the `PolicyCheckView`.
#[derive(Default, AsAny)]
pub struct PolicyCheckState {
action:Option<Action>,
@@ -42,9 +43,13 @@ impl PolicyCheckState {
println!("reset {}", text);
}
/// Open menu.
pub fn open_menu(&mut self, text_block: Entity, ctx: &mut Context) {
let mut text_block = TextBlock::get(ctx.get_widget(text_block));
let text = text_block.text_mut();
println!("Menu text: {}", text);
}
/// Parse and verify given policy code to match a valid policy data element.
//fn parse_entry(&self, text_box: Entity, ctx: &mut Context) -> Result<(), Box<dyn std::error::Error>> {
fn parse_entry(&self, text_box: Entity, ctx: &mut Context) {
// Old style
//let length = ctx.get_widget(text_box).get::<String>("policy_number").len();
@@ -125,10 +130,10 @@ impl State for PolicyCheckState {
fn init(&mut self, _: &mut Registry, ctx: &mut Context) {
self.menu_button = ctx
.entity_of_child(ID_POLICY_CHECK_MENU_BUTTON)
.expect("PolicyState.init: Can't find child 'Menu button'.");
.expect("PolicyCheckState.init: Can't find child 'Menu button'.");
self.text_box = ctx
.entity_of_child(ID_POLICY_CHECK_POLICY_NUMBER)
.expect("PolicyState.init: Can't find child 'Text Box'.");
.expect("PolicyCheckState.init: Can't find child 'Text Box'.");
}
fn update(&mut self, _registry: &mut Registry, ctx: &mut Context) {
@@ -149,6 +154,9 @@ impl State for PolicyCheckState {
Action::InputTextChanged(text_box) => {
self.set_check_button(text_box, ctx);
}
Action::OpenMenu(text_block) => {
self.open_menu(text_block, ctx);
}
Action::ParseEntry(text_box) => {
self.parse_entry(text_box, ctx);
}