2024-02-17 14:43:46 -06:00
|
|
|
use std::time::Instant;
|
|
|
|
use hui::{
|
2024-12-11 13:36:14 -06:00
|
|
|
color,
|
|
|
|
element::{
|
2024-02-20 10:30:26 -06:00
|
|
|
container::Container,
|
|
|
|
progress_bar::ProgressBar,
|
2024-03-06 17:41:26 -06:00
|
|
|
text::Text,
|
|
|
|
UiElementExt,
|
2024-12-11 13:36:14 -06:00
|
|
|
},
|
|
|
|
layout::{Alignment, Direction},
|
|
|
|
rect_frame,
|
|
|
|
size
|
2024-02-17 14:43:46 -06:00
|
|
|
};
|
|
|
|
|
2024-03-06 17:41:26 -06:00
|
|
|
#[path = "../boilerplate.rs"]
|
|
|
|
#[macro_use]
|
|
|
|
mod boilerplate;
|
2024-02-17 14:43:46 -06:00
|
|
|
|
2024-03-06 17:41:26 -06:00
|
|
|
ui_main!{
|
2024-03-06 17:42:01 -06:00
|
|
|
"Mom downloader 2000",
|
2024-03-06 17:41:26 -06: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 14:43:46 -06:00
|
|
|
|
2024-03-06 17:41:26 -06: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 08:57:46 -05:00
|
|
|
.with_background(rect_frame! {
|
2024-03-23 20:19:26 -05:00
|
|
|
color: (0.2, 0.2, 0.5),
|
|
|
|
corner_radius: 8.
|
|
|
|
})
|
2024-03-06 17:41:26 -06: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 08:57:46 -05:00
|
|
|
.with_background(rect_frame! {
|
2024-03-25 10:16:56 -05:00
|
|
|
color: color::BLACK,
|
|
|
|
corner_radius: 0.125 * ProgressBar::DEFAULT_HEIGHT
|
|
|
|
})
|
2024-04-17 08:57:46 -05:00
|
|
|
.with_foreground(rect_frame! {
|
2024-03-25 10:16:56 -05:00
|
|
|
color: color::BLUE,
|
|
|
|
corner_radius: 0.125 * ProgressBar::DEFAULT_HEIGHT
|
|
|
|
})
|
2024-03-06 17:41:26 -06:00
|
|
|
.add_child(ui);
|
|
|
|
Container::default()
|
2024-03-06 19:06:14 -06:00
|
|
|
.with_direction(Direction::Horizontal)
|
2024-03-06 17:41:26 -06: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 14:43:46 -06:00
|
|
|
}
|