2024-03-06 13:39:25 -06:00
|
|
|
use std::time::Instant;
|
2024-03-06 08:44:02 -06:00
|
|
|
use hui::{
|
2024-03-06 10:00:18 -06:00
|
|
|
color, size,
|
2024-03-06 19:06:14 -06:00
|
|
|
layout::{Alignment, Direction},
|
2024-03-06 10:00:18 -06:00
|
|
|
element::{
|
2024-03-06 08:44:02 -06:00
|
|
|
container::Container,
|
|
|
|
fill_rect::FillRect,
|
|
|
|
UiElementExt
|
2024-03-06 10:00:18 -06:00
|
|
|
},
|
2024-03-06 08:44:02 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#[path = "../boilerplate.rs"]
|
|
|
|
#[macro_use]
|
|
|
|
mod boilerplate;
|
|
|
|
|
2024-03-06 13:39:25 -06:00
|
|
|
ui_main!(
|
2024-03-06 18:15:33 -06:00
|
|
|
"hUI: Wrapping demo",
|
2024-03-06 13:39:25 -06: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-06 19:06:14 -06:00
|
|
|
.with_direction(Direction::Horizontal)
|
2024-03-06 13:39:25 -06: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 {
|
|
|
|
FillRect::default()
|
|
|
|
.with_size(size!((40 + i * 10)))
|
|
|
|
.with_corner_radius(8.)
|
|
|
|
.with_background(color::DARK_RED)
|
|
|
|
.add_child(ui);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.add_root(ui, size);
|
|
|
|
}
|
|
|
|
);
|