libsurfer/
statusbar.rs
1use egui::{Context, Frame, Layout, Margin, TopBottomPanel, Ui};
2use emath::Align;
3use web_time::{Duration, Instant};
4
5use crate::time::{time_string, timeunit_menu};
6use crate::wave_source::draw_progress_information;
7use crate::{message::Message, wave_data::WaveData, SystemState};
8
9impl SystemState {
10 pub fn add_statusbar_panel(
11 &self,
12 ctx: &Context,
13 waves: &Option<WaveData>,
14 msgs: &mut Vec<Message>,
15 ) {
16 TopBottomPanel::bottom("statusbar")
17 .frame(Frame {
18 fill: self.user.config.theme.primary_ui_color.background,
19 inner_margin: Margin {
20 left: 5,
21 right: 5,
22 top: 0,
23 bottom: 5,
24 },
25 ..Default::default()
26 })
27 .show(ctx, |ui| {
28 self.draw_statusbar(ui, waves, msgs);
29 });
30 }
31
32 fn draw_statusbar(&self, ui: &mut Ui, waves: &Option<WaveData>, msgs: &mut Vec<Message>) {
33 ui.visuals_mut().override_text_color =
34 Some(self.user.config.theme.primary_ui_color.foreground);
35 ui.with_layout(Layout::left_to_right(Align::RIGHT), |ui| {
36 if let Some(waves) = waves {
37 ui.label(waves.source.to_string());
38 if let Some(datetime) = waves.inner.metadata().date {
39 ui.add_space(10.0);
40 ui.label(format!("Generated: {datetime}"));
41 }
42 }
43
44 if let Some(state_file) = &self.user.state_file {
45 ui.label(" | ".to_string() + &state_file.to_string_lossy());
46 }
47
48 ui.add_space(10.0);
49 if let Some(progress_data) = &self.progress_tracker {
50 if Instant::now().duration_since(progress_data.started) > Duration::from_millis(100)
51 {
52 draw_progress_information(ui, progress_data);
53 }
54 }
55 if let Some(waves) = waves {
56 ui.with_layout(Layout::right_to_left(Align::RIGHT), |ui| {
57 if let Some(time) = &waves.cursor {
58 ui.label(time_string(
59 time,
60 &waves.inner.metadata().timescale,
61 &self.user.wanted_timeunit,
62 &self.get_time_format(),
63 ))
64 .context_menu(|ui| timeunit_menu(ui, msgs, &self.user.wanted_timeunit));
65 ui.add_space(10.0);
66 }
67 if let Some(undo_op) = &self.undo_stack.last() {
68 ui.label(format!("Undo: {}", undo_op.message));
69 ui.add_space(10.0);
70 }
71 if let Some(count) = &self.user.count {
72 ui.label(format!("Count: {count}"));
73 ui.add_space(10.0);
74 }
75 });
76 }
77 });
78 }
79}