use crate::ui::{Model, theme};
pub const HINT: &str = "Esc closes";
pub const BOX: &str = "the overlay's box";
pub fn ceiling(ui: &egui::Ui) -> f32 {
(ui.max_rect().height() - theme::space::XS).max(0.0)
}
pub fn float(ui: &mut egui::Ui, name: &'static str, height: f32, body: impl FnOnce(&mut egui::Ui)) {
let room = ui.max_rect();
let height = height.min(ceiling(ui));
let rect = egui::Rect::from_min_max(
egui::pos2(room.left() + theme::space::L, room.bottom() - height),
egui::pos2(room.right() - theme::space::L, room.bottom()),
);
let mut child = ui.new_child(
egui::UiBuilder::new()
.max_rect(rect)
.layout(egui::Layout::top_down(egui::Align::Min))
.id_salt(name),
);
egui::Frame::none()
.fill(theme::SURFACE)
.stroke(egui::Stroke::new(1.0, theme::HAIRLINE))
.rounding(theme::RADIUS)
.inner_margin(egui::Margin::symmetric(theme::space::S, theme::space::XS))
.show(&mut child, |ui| {
let inner = rect.size() - egui::vec2(2.0 * theme::space::S, 2.0 * theme::space::XS);
ui.set_min_size(inner);
ui.set_max_height(inner.y);
ui.data_mut(|d| d.insert_temp(egui::Id::new(BOX), ui.max_rect()));
egui::ScrollArea::vertical()
.id_salt(name)
.auto_shrink(false)
.show(ui, body);
});
}
pub fn name(ui: &mut egui::Ui, word: &str) {
about(ui, word, None);
}
pub fn about(ui: &mut egui::Ui, word: &str, subject: Option<&str>) {
ui.horizontal(|ui| {
ui.label(egui::RichText::new(word).color(theme::INK));
if let Some(subject) = subject {
ui.label(egui::RichText::new(subject).color(theme::INK_WEAK));
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.label(egui::RichText::new(HINT).small().color(theme::INK_WEAK));
});
});
ui.add_space(theme::space::XS);
}
pub fn stand(ui: &mut egui::Ui, model: &mut Model) {
if !model.covered() || model.enroll.is_some() {
return;
}
float(ui, "the overlay", ceiling(ui), |ui| {
use crate::ui::{
board, clear, clients, commands, config, doctor, find, fleet, login, prices, queue,
records, switcher, trail, tuning, unmake,
};
let _ = switcher::render(ui, model)
|| tuning::render(ui, model)
|| records::render(ui, model)
|| queue::render(ui, model)
|| trail::render(ui, model)
|| clear::render(ui, model)
|| board::render(ui, model)
|| fleet::render(ui, model)
|| commands::render(ui, model)
|| doctor::render(ui, model)
|| find::render(ui, model)
|| prices::render(ui, model)
|| login::render(ui, model)
|| clients::render(ui, model)
|| config::render(ui, model)
|| unmake::render(ui, model);
});
}
#[cfg(test)]
mod tests;