hUI/hui-examples/examples/ui_test_6_slider.rs

83 lines
2.2 KiB
Rust
Raw Normal View History

2024-03-14 07:30:44 -05:00
use hui::{
draw::TextureFormat,
element::{
br::Break,
2024-03-14 07:30:44 -05:00
container::Container,
image::Image,
slider::Slider,
text::Text,
2024-03-14 07:30:44 -05:00
UiElementExt,
},
signal::Signal,
layout::{Alignment, Direction},
size,
2024-03-14 07:30:44 -05:00
};
2024-03-25 11:51:34 -05:00
#[derive(Signal)]
2024-03-14 07:30:44 -05:00
enum CounterSignal {
2024-03-21 13:43:53 -05:00
ChangeValue(u32)
2024-03-14 07:30:44 -05:00
}
#[path = "../boilerplate.rs"]
#[macro_use]
mod boilerplate;
const IMAGE_DATA: &[u8] = include_bytes!("../assets/icons/visual-studio-code-icon_32x32.rgba");
ui_main!(
"hUI: Internal input test",
init: |ui| {
let image = ui.add_image(TextureFormat::Rgba, IMAGE_DATA, 32);
(0, image)
},
run: |ui, size, (ref mut counter, image)| {
Container::default()
.with_size(size!(100%))
.with_padding(10.)
.with_align((Alignment::Center, Alignment::Begin))
.with_direction(Direction::Horizontal)
.with_gap(5.)
2024-03-23 19:17:26 -05:00
.with_background((0.1, 0.1, 0.1))
2024-03-14 07:30:44 -05:00
.with_wrap(true)
.with_children(|ui| {
Text::new(format!("Number of images: {counter}"))
2024-03-22 09:25:01 -05:00
.with_text_size(32)
.add_child(ui);
2024-03-23 09:52:54 -05:00
Break.add_child(ui);
2024-03-22 09:25:01 -05:00
Text::new("Absolute tracking slider:")
.with_text_size(16)
.add_child(ui);
2024-03-23 09:52:54 -05:00
Break.add_child(ui);
2024-03-22 09:25:01 -05:00
Slider::new(*counter as f32 / 100.)
.with_size(size!(66%, 20))
.on_change(|x| {
CounterSignal::ChangeValue((x * 100.).round() as u32)
})
.add_child(ui);
2024-03-23 09:52:54 -05:00
Break.add_child(ui);
2024-03-22 09:25:01 -05:00
Text::new("Relative tracking slider (Experimental):")
.with_text_size(16)
2024-03-14 07:30:44 -05:00
.add_child(ui);
2024-03-23 09:52:54 -05:00
Break.add_child(ui);
2024-03-21 12:41:28 -05:00
Slider::new(*counter as f32 / 100.)
2024-03-14 07:30:44 -05:00
.with_size(size!(66%, 20))
2024-03-22 09:25:01 -05:00
.with_follow_mode(hui::element::slider::SliderFollowMode::Relative)
2024-03-21 13:43:53 -05:00
.on_change(|x| {
CounterSignal::ChangeValue((x * 100.).round() as u32)
})
2024-03-14 07:30:44 -05:00
.add_child(ui);
2024-03-23 09:52:54 -05:00
Break.add_child(ui);
2024-03-14 07:30:44 -05:00
for _ in 0..*counter {
Image::new(*image)
.with_size(size!(48, 48))
.add_child(ui);
}
})
.add_root(ui, size);
ui.process_signals(|sig| match sig {
2024-03-21 13:43:53 -05:00
CounterSignal::ChangeValue(v) => *counter = v,
2024-03-14 07:30:44 -05:00
});
}
);