From 849edf71db44dd49fc27510e217a50304289bdd6 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Thu, 14 Aug 2025 20:56:06 -0400 Subject: [PATCH] bug: fix issue with battery widget time and small widths (#1787) * bug: fix issue with battery time and small widths * changelog --- CHANGELOG.md | 3 ++- src/canvas/widgets/battery_display.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f8c7564..ca006864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,8 @@ That said, these are more guidelines rather than hardset rules, though the proje ### Bug Fixes -- [#1776](https://github.com/ClementTsang/bottom/pull/1776): Fix disk.columns being incorrectly interpreted as blank. +- [#1776](https://github.com/ClementTsang/bottom/pull/1776): Fix `disk.columns` being incorrectly interpreted as blank. +- [1787](https://github.com/ClementTsang/bottom/pull/1787): Fix issue with battery widget time and small widths. ## [0.11.0] - 2025-08-05 diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs index 8cfa0f52..f0b42b24 100644 --- a/src/canvas/widgets/battery_display.rs +++ b/src/canvas/widgets/battery_display.rs @@ -117,11 +117,11 @@ impl Painter { let is_basic = app_state.app_config_fields.use_basic_mode; - let margined_draw_loc = Layout::default() + let [margined_draw_loc] = Layout::default() .constraints([Constraint::Percentage(100)]) .horizontal_margin(u16::from(is_basic && !is_selected)) .direction(Direction::Horizontal) - .split(draw_loc)[0]; + .areas(draw_loc); if let Some(battery_details) = battery_harvest.get(battery_widget_state.currently_selected_battery_index) @@ -168,13 +168,15 @@ impl Painter { let mut time: String; // Keep string lifetime in scope. { let style = self.styles.text_style; + let time_width = (full_width / 2) as usize; + match &battery_details.state { BatteryState::Charging { time_to_full: Some(secs), } => { time = long_time(*secs); - if full_width as usize > time.len() { + if time_width >= time.len() { battery_rows.push(Row::new(["Time to full", &time]).style(style)); } else { time = short_time(*secs); @@ -186,7 +188,7 @@ impl Painter { } => { time = long_time(*secs); - if full_width as usize > time.len() { + if time_width >= time.len() { battery_rows.push(Row::new(["Time to empty", &time]).style(style)); } else { time = short_time(*secs);