Skip to content

Commit

Permalink
lib: Fix panic in table progress calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
erak committed Mar 4, 2024
1 parent 1519703 commit c9a7dfe
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/flux/ui/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,16 @@ impl<A> Table<A> {
let len = len as f64;

let lines = page_size + step.saturating_sub(page_size as usize) as f64;
let progress = (lines / len * 100_f64).ceil() as usize;
let progress = (lines / len * 100.0).ceil();

if progress > 97 {
Self::map_range((0, progress), (0, 100), progress)
if progress > 97.0 {
Self::map_range((0.0, progress), (0.0, 100.0), progress) as usize
} else {
progress
progress as usize
}
}

fn map_range(from: (usize, usize), to: (usize, usize), value: usize) -> usize {
fn map_range(from: (f64, f64), to: (f64, f64), value: f64) -> f64 {
to.0 + (value - from.0) * (to.1 - to.0) / (from.1 - from.0)
}
}
Expand Down

0 comments on commit c9a7dfe

Please sign in to comment.