frontend: update example widgets and linked in resources
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
213
frontend/examples/policyholder_check.rs
Normal file
213
frontend/examples/policyholder_check.rs
Normal file
@@ -0,0 +1,213 @@
|
||||
use orbtk::prelude::*;
|
||||
use orbtk::theme::DEFAULT_THEME_CSS;
|
||||
|
||||
static WIDGET_EXT: &'static str = include_str!("../resources/stylesheets/policyholder-check.css");
|
||||
|
||||
fn get_theme() -> ThemeValue {
|
||||
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),
|
||||
}
|
||||
|
||||
#[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::EntryActivated(entity) => {
|
||||
let mut widget = ctx.get_widget(entity);
|
||||
let text = widget.get_mut::<String16>("text");
|
||||
println!("submitting {}", 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()
|
||||
//.width(200.0)
|
||||
//.height(360.0)
|
||||
.columns(
|
||||
Columns::new()
|
||||
.add(200.0)
|
||||
.add("*")
|
||||
//.add(120.0)
|
||||
.add(200.0)
|
||||
//.add("auto")
|
||||
)
|
||||
.rows(
|
||||
Rows::new()
|
||||
//.add("auto")
|
||||
//.add(150.0)
|
||||
//.add(200.0)
|
||||
.add("*")
|
||||
.add("*")
|
||||
.build(),
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
.element("policholder_check")
|
||||
.background("fafafa")
|
||||
.margin((4.0, 24.0, 4.0, 4.0))
|
||||
.min_width(80.0)
|
||||
.min_height(180.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")
|
||||
.water_mark("Versicherungs-Nr...")
|
||||
//.text("Number policyholder", id)
|
||||
.text(("policynumber", id))
|
||||
.font_size(24.0)
|
||||
.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((4.0, 0.0, 0.0, 4.0))
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(1))
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
.image("../resources/images/hiedemann_logo.png")
|
||||
//.h_align("center")
|
||||
//.v_align("bottom")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
.element("logo_vendor")
|
||||
.margin((4.0, 0.0, 0.0, 4.0))
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(1))
|
||||
//.v_align("bottom")
|
||||
.child(
|
||||
ImageWidget::new()
|
||||
//.image("../resources/images/networkx_logo.jpg")
|
||||
.image("../resources/images/networkx_logo.png")
|
||||
//.h_align("center")
|
||||
//.v_align("bottom")
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
) // MainView
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Application::new()
|
||||
.window(|ctx| {
|
||||
Window::new()
|
||||
//.title("OrbTk - Policyholder checker example")
|
||||
.title("AdvoTracker - Versicherungsnummern")
|
||||
.position((-500.0, -100.0))
|
||||
.size(480.0, 360.0)
|
||||
.min_width(80.0)
|
||||
.min_height(180.0)
|
||||
.resizeable(true)
|
||||
//.theme(get_theme())
|
||||
.background("#fafafa")
|
||||
.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)
|
||||
}
|
||||
Reference in New Issue
Block a user