* helper function to test validity of given policynumber - use a hashmap as a reference store with valid policynumbers - check the given policynumber against the reference Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
236 lines
5.6 KiB
Rust
236 lines
5.6 KiB
Rust
use orbtk::prelude::*;
|
|
use orbtk::theme::DEFAULT_THEME_CSS;
|
|
//use orbtk::theme::LIGHT_THEME_EXTENSION_CSS;
|
|
|
|
//#[cfg(feature = "light-theme")]
|
|
static WIDGET_EXT: &'static str = include_str!("../resources/stylesheets/policyholder_check.css");
|
|
|
|
fn get_theme() -> ThemeValue {
|
|
//ThemeValue::create_from_css(LIGHT_THEME_EXTENSION_CSS)
|
|
ThemeValue::create_from_css(DEFAULT_THEME_CSS)
|
|
.extension_css(WIDGET_EXT)
|
|
.build()
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
enum Action {
|
|
ClearText,
|
|
EntryActivated(Entity),
|
|
EntryChanged(Entity),
|
|
//ValueChanged(Entity),
|
|
ValueOk,
|
|
ValueNone,
|
|
}
|
|
|
|
#[derive(AsAny)]
|
|
pub struct MainViewState {
|
|
action: Option<Action>,
|
|
}
|
|
|
|
impl Default for MainViewState {
|
|
fn default() -> Self {
|
|
MainViewState { action: None }
|
|
}
|
|
}
|
|
|
|
impl MainViewState {
|
|
fn action(&mut self, action: impl Into<Option<Action>>) {
|
|
self.action = action.into();
|
|
}
|
|
}
|
|
|
|
impl State for MainViewState {
|
|
fn update(&mut self, _: &mut Registry, ctx: &mut Context<'_>) {
|
|
if let Some(action) = self.action {
|
|
match action {
|
|
Action::ClearText => {
|
|
ctx.widget().set("policynumber", String16::from(""));
|
|
}
|
|
Action::ValueOk => {
|
|
//let mut text_box = TextBox::get(ctx.get_widget(entity));
|
|
//let text = text_box.text_mut();
|
|
//ctx.widget().set("policynumber", background("#4d4c4c"));
|
|
}
|
|
Action::ValueNone => {
|
|
//let mut text_box = TextBox::get(ctx.get_widget(entity));
|
|
//let text = text_box.text_mut();
|
|
//ctx.widget().set("policynumber", background("#5b0f22"));
|
|
}
|
|
Action::EntryActivated(entity) => {
|
|
let mut text_box = TextBox::get(ctx.get_widget(entity));
|
|
let text = text_box.text_mut();
|
|
//let mut widget = ctx.get_widget(entity);
|
|
//let text = widget.get_mut::<String16>("text");
|
|
println!("got value policynumber: {}", text);
|
|
//text.clear();
|
|
}
|
|
Action::EntryChanged(entity) => {
|
|
let widget = ctx.get_widget(entity);
|
|
let text = widget.get::<String16>("text");
|
|
println!("entry changed: {}", text);
|
|
}
|
|
// Action::ValueChanged(entity) => {
|
|
// let val =
|
|
// ((*ctx.get_widget(entity).get::<f64>("val")).floor() as i32).to_string();
|
|
// ctx.child("value_text").set("text", String16::from(val));
|
|
//}
|
|
}
|
|
|
|
self.action = None;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn create_header(ctx: &mut BuildContext, text: &str) -> Entity {
|
|
TextBlock::new()
|
|
.text(text)
|
|
.element("text-block")
|
|
.class("h1")
|
|
.build(ctx)
|
|
}
|
|
|
|
widget!(
|
|
MainView<MainViewState> {
|
|
sum_policynumbers: usize,
|
|
policynumber: String16,
|
|
result: String16
|
|
}
|
|
);
|
|
|
|
impl Template for MainView {
|
|
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
|
self.name("MainView").child(
|
|
//.result("Anzahl Versicherungsnummern: 0")
|
|
//.result("Policyholders count: 0").sum_policynumbers(0)
|
|
//.sum_policynumbers(0)
|
|
Grid::new()
|
|
.background("#fafafa")
|
|
//.width(200.0)
|
|
//.height(360.0)
|
|
.columns(
|
|
Columns::new()
|
|
.add(150.0)
|
|
.add("*")
|
|
//.add(120.0)
|
|
//.add("auto")
|
|
.add(150.0)
|
|
.build(),
|
|
)
|
|
.rows(
|
|
Rows::new()
|
|
.add("*")
|
|
.add("*")
|
|
.build(),
|
|
)
|
|
.child(
|
|
Grid::new()
|
|
.element("policyholder_check")
|
|
.margin((4.0, 24.0, 24.0, 4.0))
|
|
.min_width(180.0)
|
|
.min_height(80.0)
|
|
.attach(Grid::column(1))
|
|
.attach(Grid::row(0))
|
|
.child(
|
|
Stack::new()
|
|
.spacing(8.0)
|
|
.orientation("vertical")
|
|
.h_align("center")
|
|
//.child(create_header(ctx, "Validation number policyholder"))
|
|
.child(create_header(ctx, "Validierung Versicherungsnummer"))
|
|
.child(
|
|
TextBox::new()
|
|
//.class("text_box")
|
|
// overwriting the class defaults
|
|
/* .background("transparent")
|
|
.foreground("#9dafbf")
|
|
.background("#fafafa")
|
|
/* .foreground(colors::LINK_WATER_COLOR) */
|
|
.border_brush("#5b0f22")
|
|
.border_width(5)
|
|
.border_radius(15) */
|
|
//.name("policynumber")
|
|
.focused(true)
|
|
.water_mark("Versicherungs-Nr...")
|
|
//.text("Number policyholder", id)
|
|
.text(("policynumber", id))
|
|
.font_size(24.0)
|
|
.h_align("stretch")
|
|
.on_activate(move |states, entity| {
|
|
state(id, states).action(Action::EntryActivated(entity));
|
|
})
|
|
.on_changed(move |states, entity| {
|
|
state(id, states).action(Action::EntryChanged(entity));
|
|
})
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
TextBlock::new()
|
|
.element("text-block")
|
|
.id("result")
|
|
.min_width(80.0)
|
|
.max_width(180.0)
|
|
//.text("Result:")
|
|
.text("Ergebnis:")
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.build(ctx)
|
|
)
|
|
.child(
|
|
Grid::new()
|
|
.element("logo_customer")
|
|
.margin((9.0, 16.0, 16.0, 9.0))
|
|
.attach(Grid::column(0))
|
|
.attach(Grid::row(1))
|
|
.v_align("end")
|
|
.child(
|
|
ImageWidget::new()
|
|
.image("./resources/images/hiedemann_logo.png")
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.child(
|
|
Grid::new()
|
|
.element("logo_vendor")
|
|
.margin((9.0, 16.0, 16.0, 9.0))
|
|
.attach(Grid::column(2))
|
|
.attach(Grid::row(1))
|
|
.v_align("end")
|
|
.child(
|
|
ImageWidget::new()
|
|
.image("./resources/images/networkx_logo.png")
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
)
|
|
.build(ctx),
|
|
) // MainView
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
Application::new()
|
|
.window(|ctx| {
|
|
Window::new()
|
|
//.title("OrbTk - Policyholder checker example")
|
|
.name("MainWindow")
|
|
.title("AdvoTracker - Versicherungsnummern")
|
|
.position((-500.0, -100.0))
|
|
.size(480.0, 260.0)
|
|
.min_width(460.0)
|
|
.min_height(180.0)
|
|
.resizeable(true)
|
|
.theme(get_theme())
|
|
.child(MainView::new().build(ctx))
|
|
.build(ctx)
|
|
})
|
|
.run();
|
|
}
|
|
|
|
// helper to request MainViewState
|
|
fn state<'a>(id: Entity, states: &'a mut StatesContext) -> &'a mut MainViewState {
|
|
states.get_mut(id)
|
|
}
|