Skip to content

Commit 9855305

Browse files
committed
address issues
Signed-off-by: chang-ning <spiderpower02@gmail.com>
1 parent 28b1ef1 commit 9855305

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/tui/ui.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ fn pct_gauge_text(pct: Option<u32>, bar_w: usize) -> String {
287287
/// `avail >= sum(mins) + gaps`; below that all columns sit at their min
288288
/// and ratatui clips. See the shave pass for how floor overshoot is paid.
289289
fn scaled_col_widths(natural: &[u16], mins: &[u16], avail: u16) -> Vec<u16> {
290+
debug_assert_eq!(natural.len(), mins.len());
290291
if natural.is_empty() {
291292
return Vec::new();
292293
}
@@ -296,10 +297,15 @@ fn scaled_col_widths(natural: &[u16], mins: &[u16], avail: u16) -> Vec<u16> {
296297
if avail >= total - 1 {
297298
return natural.to_vec();
298299
}
300+
// Rounded division avoids a systematic downward bias; any overshoot
301+
// is paid back by the shave pass below.
299302
let mut out: Vec<u16> = natural
300303
.iter()
301304
.zip(mins)
302-
.map(|(&nat, &min)| (((nat as u32 * avail as u32) / total as u32) as u16).max(min))
305+
.map(|(&nat, &min)| {
306+
let scaled = (nat as u32 * avail as u32 + total as u32 / 2) / total as u32;
307+
(scaled as u16).max(min)
308+
})
303309
.collect();
304310
// Reclaim min-floor overshoot from columns still above their floor,
305311
// largest excess first, so the result fits whenever sum(mins) does.

0 commit comments

Comments
 (0)