hUI/hui-examples/examples/ui_test_5_input.rs

71 lines
1.7 KiB
Rust
Raw Normal View History

2024-03-11 14:48:39 -05:00
use hui::{
color, size,
layout::{Alignment, Direction},
element::{
container::Container,
2024-03-11 18:29:26 -05:00
text::Text,
2024-03-11 14:48:39 -05:00
interactable::ElementInteractableExt,
UiElementExt
},
2024-03-11 18:29:26 -05:00
signal::UiSignal,
2024-03-11 14:48:39 -05:00
};
2024-03-11 18:29:26 -05:00
enum CounterSignal {
Increment,
Decrement,
}
impl UiSignal for CounterSignal {}
2024-03-11 14:48:39 -05:00
#[path = "../boilerplate.rs"]
#[macro_use]
mod boilerplate;
ui_main!(
"hUI: Internal input test",
2024-03-11 14:52:25 -05:00
init: |_| {
0
},
2024-03-11 18:29:26 -05:00
run: |ui, size, counter| {
2024-03-11 14:48:39 -05:00
Container::default()
.with_size(size!(100%))
.with_align(Alignment::Center)
2024-03-11 18:29:26 -05:00
.with_direction(Direction::Horizontal)
.with_gap(5.)
2024-03-11 14:48:39 -05:00
.with_background(color::WHITE)
.with_children(|ui| {
2024-03-11 18:29:26 -05:00
Container::default()
.with_padding(10.)
.with_corner_radius(8.)
.with_background(color::DARK_RED)
.with_children(|ui| {
Text::new("-")
.add_child(ui);
})
2024-03-11 19:06:03 -05:00
.on_click(CounterSignal::Increment)
2024-03-11 18:29:26 -05:00
.add_child(ui);
Text::new(counter.to_string())
.with_color(color::BLACK)
.with_text_size(32)
.add_child(ui);
Container::default()
.with_padding(10.)
2024-03-11 14:48:39 -05:00
.with_corner_radius(8.)
.with_background(color::DARK_RED)
2024-03-11 18:29:26 -05:00
.with_children(|ui| {
Text::new("+")
.add_child(ui);
})
2024-03-11 19:06:03 -05:00
.on_click(CounterSignal::Decrement)
2024-03-11 14:48:39 -05:00
.add_child(ui);
})
.add_root(ui, size);
2024-03-11 18:29:26 -05:00
ui.process_signals(|sig| {
match sig {
CounterSignal::Increment => *counter += 1,
CounterSignal::Decrement => *counter -= 1,
}
});
2024-03-11 14:48:39 -05:00
}
);