hUI/hui-examples/examples/ui_test_4_wrapping.rs

43 lines
1 KiB
Rust
Raw Normal View History

2024-03-06 19:39:25 +00:00
use std::time::Instant;
2024-03-06 14:44:02 +00:00
use hui::{
2024-03-24 21:18:15 +00:00
color, element::{
2024-03-06 14:44:02 +00:00
container::Container,
frame_view::FrameView,
2024-03-06 14:44:02 +00:00
UiElementExt
2024-04-17 13:57:46 +00:00
}, rect_frame, layout::{Alignment, Direction}, size
2024-03-06 14:44:02 +00:00
};
#[path = "../boilerplate.rs"]
#[macro_use]
mod boilerplate;
2024-03-06 19:39:25 +00:00
ui_main!(
2024-03-07 00:15:33 +00:00
"hUI: Wrapping demo",
2024-03-06 19:39:25 +00:00
init: |_| {
Instant::now()
},
run: |ui, size, instant| {
let width_ratio = 0.5 + 0.5 * instant.elapsed().as_secs_f32().sin().powi(2);
Container::default()
.with_size(size!(width_ratio/, 100%))
2024-03-07 01:06:14 +00:00
.with_direction(Direction::Horizontal)
2024-03-06 19:39:25 +00:00
.with_align(Alignment::Center)
.with_padding(5.)
.with_gap(10.)
.with_background(color::WHITE)
.with_wrap(true)
.with_children(|ui| {
for i in 0..10 {
2024-04-17 13:44:47 +00:00
FrameView::default()
2024-03-06 19:39:25 +00:00
.with_size(size!((40 + i * 10)))
2024-04-17 13:57:46 +00:00
.with_frame(rect_frame! {
2024-03-24 21:18:15 +00:00
color: color::DARK_RED,
corner_radius: 8.
})
2024-03-06 19:39:25 +00:00
.add_child(ui);
}
})
.add_root(ui, size);
}
);