From ffe7cd0090463a84048f39dea4f3279269f48141 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 9 Dec 2025 12:33:52 +0100 Subject: [PATCH] Fix time display to update smoothly Change position update logic to only trigger redraw when the displayed value (rounded to seconds) changes, not when the raw float value changes. This eliminates jumpy time display and reduces unnecessary redraws. --- Cargo.toml | 2 +- src/main.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 96abb5c..fafaac1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-player" -version = "0.1.17" +version = "0.1.18" edition = "2021" [dependencies] diff --git a/src/main.rs b/src/main.rs index 033b300..406da7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -183,8 +183,10 @@ async fn run_app( let new_position = player.get_position().unwrap_or(0.0); let new_duration = player.get_duration().unwrap_or(0.0); - // Only mark as changed if position moved by at least 0.5 seconds - if (new_position - last_position).abs() >= 0.5 { + // Only update if displayed value (rounded to seconds) changed + let old_display_secs = last_position as u32; + let new_display_secs = new_position as u32; + if new_display_secs != old_display_secs { state.current_position = new_position; last_position = new_position; state_changed = true;