2024-03-11 14:48:39 -05:00
|
|
|
use hui::{
|
2024-03-25 11:51:34 -05:00
|
|
|
color, size, Signal,
|
2024-03-11 19:51:27 -05:00
|
|
|
draw::TextureFormat,
|
2024-03-11 14:48:39 -05:00
|
|
|
layout::{Alignment, Direction},
|
|
|
|
element::{
|
|
|
|
container::Container,
|
2024-03-11 18:29:26 -05:00
|
|
|
text::Text,
|
2024-03-11 19:51:27 -05:00
|
|
|
image::Image,
|
2024-03-23 09:52:54 -05:00
|
|
|
br::Break,
|
2024-03-11 14:48:39 -05:00
|
|
|
interactable::ElementInteractableExt,
|
2024-03-11 19:51:27 -05:00
|
|
|
UiElementExt,
|
2024-03-11 14:48:39 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-03-25 11:51:34 -05:00
|
|
|
#[derive(Signal)]
|
2024-03-11 18:29:26 -05:00
|
|
|
enum CounterSignal {
|
|
|
|
Increment,
|
|
|
|
Decrement,
|
|
|
|
}
|
|
|
|
|
2024-03-11 14:48:39 -05:00
|
|
|
#[path = "../boilerplate.rs"]
|
|
|
|
#[macro_use]
|
|
|
|
mod boilerplate;
|
|
|
|
|
2024-03-11 19:51:27 -05:00
|
|
|
const IMAGE_DATA: &[u8] = include_bytes!("../assets/icons/visual-studio-code-icon_32x32.rgba");
|
|
|
|
|
2024-03-11 14:48:39 -05:00
|
|
|
ui_main!(
|
|
|
|
"hUI: Internal input test",
|
2024-03-11 19:51:27 -05:00
|
|
|
init: |ui| {
|
|
|
|
let image = ui.add_image(TextureFormat::Rgba, IMAGE_DATA, 32);
|
|
|
|
(0, image)
|
2024-03-11 14:52:25 -05:00
|
|
|
},
|
2024-03-11 19:51:27 -05:00
|
|
|
run: |ui, size, (ref mut counter, image)| {
|
2024-03-11 14:48:39 -05:00
|
|
|
Container::default()
|
|
|
|
.with_size(size!(100%))
|
2024-03-12 12:36:47 -05:00
|
|
|
.with_padding(10.)
|
|
|
|
.with_align((Alignment::Center, Alignment::Begin))
|
2024-03-11 18:29:26 -05:00
|
|
|
.with_direction(Direction::Horizontal)
|
|
|
|
.with_gap(5.)
|
2024-03-11 19:51:27 -05:00
|
|
|
.with_background((0.1, 0.1, 0.1))
|
|
|
|
.with_wrap(true)
|
2024-03-11 14:48:39 -05:00
|
|
|
.with_children(|ui| {
|
2024-03-12 12:36:47 -05:00
|
|
|
Text::new("Number of images:")
|
|
|
|
.with_text_size(24)
|
|
|
|
.add_child(ui);
|
2024-03-23 09:52:54 -05:00
|
|
|
Break.add_child(ui);
|
2024-03-11 18:29:26 -05:00
|
|
|
Container::default()
|
|
|
|
.with_padding(10.)
|
2024-03-11 19:51:27 -05:00
|
|
|
.with_background(color::ORANGE)
|
2024-03-11 18:29:26 -05:00
|
|
|
.with_children(|ui| {
|
|
|
|
Text::new("-")
|
2024-03-11 19:51:27 -05:00
|
|
|
.with_text_size(32)
|
2024-03-11 18:29:26 -05:00
|
|
|
.add_child(ui);
|
|
|
|
})
|
2024-03-23 09:50:44 -05:00
|
|
|
.on_click(|| CounterSignal::Decrement)
|
2024-03-11 18:29:26 -05:00
|
|
|
.add_child(ui);
|
2024-03-11 19:23:26 -05:00
|
|
|
Container::default()
|
2024-03-11 19:51:27 -05:00
|
|
|
.with_size(size!(60, auto))
|
2024-03-11 19:23:26 -05:00
|
|
|
.with_align(Alignment::Center)
|
|
|
|
.with_children(|ui| {
|
|
|
|
Text::new(counter.to_string())
|
2024-03-11 19:51:27 -05:00
|
|
|
.with_text_size(64)
|
2024-03-11 19:23:26 -05:00
|
|
|
.add_child(ui);
|
|
|
|
})
|
2024-03-11 18:29:26 -05:00
|
|
|
.add_child(ui);
|
|
|
|
Container::default()
|
|
|
|
.with_padding(10.)
|
2024-03-11 19:51:27 -05:00
|
|
|
.with_background(color::ORANGE)
|
2024-03-11 18:29:26 -05:00
|
|
|
.with_children(|ui| {
|
|
|
|
Text::new("+")
|
2024-03-11 19:51:27 -05:00
|
|
|
.with_text_size(32)
|
2024-03-11 18:29:26 -05:00
|
|
|
.add_child(ui);
|
|
|
|
})
|
2024-03-23 09:50:44 -05:00
|
|
|
.on_click(|| CounterSignal::Increment)
|
2024-03-11 14:48:39 -05:00
|
|
|
.add_child(ui);
|
2024-03-23 09:52:54 -05:00
|
|
|
Break.add_child(ui);
|
2024-03-11 19:51:27 -05:00
|
|
|
for _ in 0..*counter {
|
|
|
|
Image::new(*image)
|
|
|
|
.with_size(size!(48, 48))
|
|
|
|
.add_child(ui);
|
|
|
|
}
|
2024-03-11 14:48:39 -05:00
|
|
|
})
|
|
|
|
.add_root(ui, size);
|
2024-03-11 18:29:26 -05:00
|
|
|
|
2024-03-12 12:36:47 -05:00
|
|
|
ui.process_signals(|sig| match sig {
|
|
|
|
CounterSignal::Increment => *counter += 1,
|
|
|
|
CounterSignal::Decrement => *counter -= 1,
|
2024-03-11 18:29:26 -05:00
|
|
|
});
|
2024-03-11 14:48:39 -05:00
|
|
|
}
|
|
|
|
);
|