use egui::{Color32, RichText, Ui};
const SHOWN: f64 = 5.0;
#[derive(Debug, Default)]
pub(crate) struct StatusLine {
edit: Option<(String, f64)>,
hardware: Option<(String, f64)>,
}
impl StatusLine {
pub(crate) fn edit(&mut self, ui: &Ui, message: impl Into<String>) {
self.edit = Some((message.into(), ui.input(|input| input.time)));
}
pub(crate) fn hardware(&mut self, ui: &Ui, message: impl Into<String>) {
self.hardware = Some((message.into(), ui.input(|input| input.time)));
}
pub(crate) fn show(&mut self, ui: &mut Ui) {
let now = ui.input(|input| input.time);
ui.horizontal(|ui| {
for (slot, color) in [
(&mut self.edit, ui.visuals().text_color()),
(&mut self.hardware, Color32::from_rgb(94, 194, 122)),
] {
if let Some((message, since)) = slot {
let age = now - *since;
if age > SHOWN {
*slot = None;
continue;
}
let fade = (1.0 - (age - (SHOWN - 1.0)).max(0.0)) as f32;
ui.label(RichText::new(message.as_str()).color(color.gamma_multiply(fade)));
ui.ctx().request_repaint();
}
}
});
}
}