Files
advotracker/advotracker_client/examples/pager_test.rs
2021-05-23 14:36:35 +02:00

113 lines
3.1 KiB
Rust

// SPDX-License-Identifier: (0BSD or MIT)
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
*/
use orbtk::prelude::*;
fn main() {
// use this only if you want to run it as web application.
orbtk::initialize();
Application::new()
.window(|ctx| {
Window::new()
.title("OrbTk - Pager test")
.position((100, 100))
.size(800, 600)
.resizeable(true)
.child(PagerTestView::new().build(ctx))
.build(ctx)
})
.run();
}
// Views
widget!(
PagerTestView<PagerTestState> {}
);
impl Template for PagerTestView {
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
let pager = Pager::new()
.attach(Grid::row(1))
.child(TextBlock::new().text("Page 1").build(ctx))
.child(TextBlock::new().text("Page 2").build(ctx))
.child(TextBlock::new().text("Page 3").build(ctx))
.build(ctx);
let next_button = Button::new()
.style("button_single_content")
.icon(material_icons_font::MD_KEYBOARD_ARROW_RIGHT)
.h_align("end")
.attach(Grid::row(2))
.enabled(("next_enabled", pager))
.text("next")
.on_click(move |states, _| {
states.send_message(PagerAction::Next, pager);
true
})
.build(ctx);
let previous_button = Button::new()
.style("button_single_content")
.icon(material_icons_font::MD_KEYBOARD_ARROW_LEFT)
.h_align("start")
.attach(Grid::row(2))
.enabled(("previous_enabled", pager))
.text("previous")
.on_click(move |states, _| {
states.send_message(PagerAction::Previous, pager);
true
})
.build(ctx);
self.child(
Grid::new()
.margin(16)
.rows("32, *, 32")
.child(TextBlock::new().text("Pager Widget").build(ctx))
.child(pager)
.child(previous_button)
.child(next_button)
.build(ctx),
)
}
}
// States
static ID_PAGER_TEST: &str = "id_pager_test";
#[derive(Debug, Clone, Copy)]
pub enum PagerTestAction {}
/// Valid `structures` that are handled inside the state of the `PagerTest` widget.
#[derive(AsAny, Debug, Default)]
pub struct PagerTestState {
pager_test: Entity,
}
/// Method definitions, that react on any given state change inside the `Menu` widget.
impl PagerTestState {
fn init(&mut self, _registry: &mut Registry, ctx: &mut Context) {
self.pager_test = ctx.child(ID_PAGER_TEST).entity();
}
}
impl State for PagerTestState {
/// Handle messages for the `PagerTestState`
fn messages(
&mut self,
mut messages: MessageReader,
_registry: &mut Registry,
ctx: &mut Context<'_>,
) {
for message in messages.read::<PagerTestAction>() {
ctx.send_message(message, self.pager_test);
}
}
}