diff --git a/src/gui/modular/label.rs b/src/gui/modular/label.rs index 1c97fd6..56b2b5a 100644 --- a/src/gui/modular/label.rs +++ b/src/gui/modular/label.rs @@ -29,6 +29,9 @@ pub enum LabelContent { format: Arc, timezone: Option>, }, + Timer { + format: Arc, + }, Battery { device: usize, low_threshold: f32, @@ -49,6 +52,10 @@ pub enum LabelData { format: Arc, timezone: Option, }, + Timer { + format: Arc, + start: Instant, + }, Exec { last_exec: Instant, interval: f32, @@ -85,6 +92,10 @@ pub fn modular_label_init(label: &mut ModularControl, content: &LabelContent) { timezone: tz, }) } + LabelContent::Timer { format } => Some(LabelData::Timer { + format: format.clone(), + start: Instant::now(), + }), LabelContent::Exec { command, interval } => Some(LabelData::Exec { last_exec: Instant::now(), interval: *interval, @@ -155,6 +166,14 @@ pub(super) fn label_update(control: &mut ModularControl, _: &mut (), app: &mut A control.set_text(&format!("{}", &date.format(&format))); } } + LabelData::Timer { format, start } => { + let mut format = format.clone().to_lowercase(); + let duration = start.elapsed().as_secs(); + format = format.replace("%s", &format!("{:02}", (duration % 60))); + format = format.replace("%m", &format!("{:02}", ((duration / 60) % 60))); + format = format.replace("%h", &format!("{:02}", ((duration / 60) / 60))); + control.set_text(&format); + } LabelData::Exec { last_exec, interval,