Fix time display to update smoothly
All checks were successful
Build and Release / build-and-release (push) Successful in 54s
All checks were successful
Build and Release / build-and-release (push) Successful in 54s
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.
This commit is contained in:
parent
907a734be3
commit
ffe7cd0090
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-player"
|
name = "cm-player"
|
||||||
version = "0.1.17"
|
version = "0.1.18"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -183,8 +183,10 @@ async fn run_app<B: ratatui::backend::Backend>(
|
|||||||
let new_position = player.get_position().unwrap_or(0.0);
|
let new_position = player.get_position().unwrap_or(0.0);
|
||||||
let new_duration = player.get_duration().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
|
// Only update if displayed value (rounded to seconds) changed
|
||||||
if (new_position - last_position).abs() >= 0.5 {
|
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;
|
state.current_position = new_position;
|
||||||
last_position = new_position;
|
last_position = new_position;
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user