diff --git a/src/widgets/clock.rs b/src/widgets/clock.rs index 7b33825..a33cbf0 100644 --- a/src/widgets/clock.rs +++ b/src/widgets/clock.rs @@ -5,11 +5,12 @@ use strum::Display; use ratatui::{ buffer::Buffer, - layout::{Constraint, Layout, Position, Rect, Size}, - symbols, - widgets::{Block, Borders, StatefulWidget, Widget}, + layout::{Constraint, Layout, Position, Rect}, + widgets::StatefulWidget, }; +use crate::utils::center_horizontal; + #[derive(Debug, Copy, Clone, Display, PartialEq, Eq)] pub enum Time { Seconds, @@ -63,9 +64,13 @@ const ONE_SECOND: Duration = Duration::from_secs(1); const ONE_MINUTE: Duration = Duration::from_secs(SECS_PER_MINUTE); const ONE_HOUR: Duration = Duration::from_secs(MINS_PER_HOUR * SECS_PER_MINUTE); -#[derive(Debug, Copy, Clone, PartialEq, Eq, Display)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Display, PartialOrd, Ord)] pub enum Format { + S, + Ss, + MSs, MmSs, + HMmSs, HhMmSs, } @@ -106,7 +111,13 @@ impl Clock { p } } - mode => Mode::Editable(Time::Minutes, Box::new(mode)), + mode => { + if self.format <= Format::Ss { + Mode::Editable(Time::Seconds, Box::new(mode)) + } else { + Mode::Editable(Time::Minutes, Box::new(mode)) + } + } }; } @@ -116,7 +127,7 @@ impl Clock { if self .current_value // < 99:59:58 - .lt(&MAX_EDITABLE_DURATION.saturating_sub(ONE_SECOND)) + .le(&MAX_EDITABLE_DURATION.saturating_sub(ONE_SECOND)) { self.current_value.saturating_add(ONE_SECOND) } else { @@ -127,7 +138,7 @@ impl Clock { if self .current_value // < 99:58:59 - .lt(&MAX_EDITABLE_DURATION.saturating_sub(ONE_MINUTE)) + .le(&MAX_EDITABLE_DURATION.saturating_sub(ONE_MINUTE)) { self.current_value.saturating_add(ONE_MINUTE) } else { @@ -147,6 +158,7 @@ impl Clock { } _ => self.current_value, }; + self.update_format(); } pub fn edit_current_down(&mut self) { self.current_value = match self.mode { @@ -155,6 +167,7 @@ impl Clock { Mode::Editable(Time::Hours, _) => self.current_value.saturating_sub(ONE_HOUR), _ => self.current_value, }; + self.update_format(); self.update_mode(); } @@ -166,51 +179,49 @@ impl Clock { matches!(self.mode, Mode::Editable(_, _)) } - pub fn edit_mode(&mut self) -> Option