Skip to content

Commit

Permalink
Clamped progress bars to solve problems with -ve numbers (#274)
Browse files Browse the repository at this point in the history
Co-authored-by: Thang Pham <[email protected]>
  • Loading branch information
whiskyplausible and aome510 authored Oct 23, 2023
1 parent 68da72f commit 3b2a366
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions spotify_player/src/ui/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,16 @@ fn render_playback_progress_bar(
track: &rspotify_model::FullTrack,
rect: Rect,
) {
// Negative numbers can sometimes appear from progress.num_seconds() so this stops
// them coming through into the ratios
let ratio =
(progress.num_seconds() as f64 / track.duration.num_seconds() as f64).clamp(0.0, 1.0);

match state.app_config.progress_bar_type {
config::ProgressBarType::Line => frame.render_widget(
LineGauge::default()
.gauge_style(ui.theme.playback_progress_bar())
.ratio(progress.num_seconds() as f64 / track.duration.num_seconds() as f64)
.ratio(ratio)
.label(Span::styled(
format!(
"{}/{}",
Expand All @@ -250,7 +255,7 @@ fn render_playback_progress_bar(
config::ProgressBarType::Rectangle => frame.render_widget(
Gauge::default()
.gauge_style(ui.theme.playback_progress_bar())
.ratio(progress.num_seconds() as f64 / track.duration.num_seconds() as f64)
.ratio(ratio)
.label(Span::styled(
format!(
"{}/{}",
Expand Down

0 comments on commit 3b2a366

Please sign in to comment.