From 3ad264aa7b6d08975de7a14b8447b21dcc4b7b2e Mon Sep 17 00:00:00 2001 From: shy Date: Tue, 6 Apr 2021 16:36:01 +0200 Subject: [PATCH] Refactored invocation of layout.update(). --- src/layout.rs | 4 ++-- src/main.rs | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/layout.rs b/src/layout.rs index 65b63ff..d0b3091 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -55,8 +55,8 @@ impl Layout { } } - pub fn update(&mut self, display_hours: bool) { - if self.force_recalc.swap(false, Ordering::Relaxed) { + pub fn update(&mut self, display_hours: bool, force: bool) { + if self.force_recalc.swap(false, Ordering::Relaxed) || force { let (width, height) = termion::terminal_size() .expect("Could not read terminal size!"); self.width = width; diff --git a/src/main.rs b/src/main.rs index 6a30628..a2503e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -231,12 +231,10 @@ fn main() { layout.force_recalc.store(true, Ordering::Relaxed); } - // Force recalculation of layout if we start displaying hours. - if clock.elapsed == 3600 { - layout.force_recalc.store(true, Ordering::Relaxed); - } // Update window size information and calculate the clock position. - layout.update(clock.elapsed >= 3600); + // Also enforce recalculation of layout if we start displaying + // hours. + layout.update(clock.elapsed >= 3600, clock.elapsed == 3600); // Check for exceeded alarms. if alarm_roster.check(&mut clock, &layout, &mut countdown) {