hUI/hui-examples/examples/mom_downloader.rs

85 lines
2.8 KiB
Rust
Raw Normal View History

2024-02-17 20:43:46 +00:00
use std::time::Instant;
use hui::{
2024-03-25 15:16:56 +00:00
color, element::{
2024-02-20 16:30:26 +00:00
container::Container,
progress_bar::ProgressBar,
2024-03-06 23:41:26 +00:00
text::Text,
UiElementExt,
2024-04-17 13:57:46 +00:00
}, frame::RectFrame, rect_frame, layout::{Alignment, Direction}, size
2024-02-17 20:43:46 +00:00
};
2024-03-06 23:41:26 +00:00
#[path = "../boilerplate.rs"]
#[macro_use]
mod boilerplate;
2024-02-17 20:43:46 +00:00
2024-03-06 23:41:26 +00:00
ui_main!{
2024-03-06 23:42:01 +00:00
"Mom downloader 2000",
2024-03-06 23:41:26 +00:00
init: |ui| {
let font_handle = ui.add_font(include_bytes!("../assets/roboto/Roboto-Regular.ttf"));
ui.push_font(font_handle);
Instant::now()
},
run: |ui, max_size, instant| {
let mom_ratio = (instant.elapsed().as_secs_f32() / 60.).powf(0.5);
2024-02-17 20:43:46 +00:00
2024-03-06 23:41:26 +00:00
Container::default()
.with_align(Alignment::Center)
.with_size(size!(100%))
.with_background((0.1, 0.1, 0.1))
.with_children(|ui| {
Container::default()
.with_gap(5.)
.with_padding(10.)
.with_size(size!(450, auto))
2024-04-17 13:57:46 +00:00
.with_background(rect_frame! {
2024-03-24 01:19:26 +00:00
color: (0.2, 0.2, 0.5),
corner_radius: 8.
})
2024-03-06 23:41:26 +00:00
.with_children(|ui| {
if instant.elapsed().as_secs_f32() < 5. {
Text::default()
.with_text("Downloading your mom...")
.with_text_size(24)
.add_child(ui);
ProgressBar::default()
.with_value(mom_ratio)
2024-04-17 13:57:46 +00:00
.with_background(rect_frame! {
2024-03-25 15:16:56 +00:00
color: color::BLACK,
corner_radius: 0.125 * ProgressBar::DEFAULT_HEIGHT
})
2024-04-17 13:57:46 +00:00
.with_foreground(rect_frame! {
2024-03-25 15:16:56 +00:00
color: color::BLUE,
corner_radius: 0.125 * ProgressBar::DEFAULT_HEIGHT
})
2024-03-06 23:41:26 +00:00
.add_child(ui);
Container::default()
2024-03-07 01:06:14 +00:00
.with_direction(Direction::Horizontal)
2024-03-06 23:41:26 +00:00
.with_align((Alignment::End, Alignment::Center))
.with_size(size!(100%, auto))
.with_children(|ui| {
Text::default()
.with_text(format!("{:.2}% ({:.1} GB)", mom_ratio * 100., mom_ratio * 10000.))
.with_text_size(16)
.add_child(ui);
})
.add_child(ui);
} else if instant.elapsed().as_secs() < 10 {
Text::default()
.with_text("Error 413: Request Entity Too Large")
.with_color((1., 0.125, 0.125, 1.))
.with_text_size(20)
.add_child(ui);
Text::default()
.with_text(format!("Exiting in {}...", 10 - instant.elapsed().as_secs()))
.with_text_size(16)
.add_child(ui);
} else {
std::process::exit(0);
}
})
.add_child(ui);
})
.add_root(ui, max_size)
}
2024-02-17 20:43:46 +00:00
}