mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-25 21:50:20 +00:00
bug: Fix battery widget color and mouse (#504)
Fixes two bugs causing the battery widget colours and mouse events to be broken.
This commit is contained in:
parent
e3ebc48ce8
commit
3313e88334
4 changed files with 32 additions and 23 deletions
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.6.2]/[0.7.0] - Unreleased
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
|
||||||
|
- [#504](https://github.com/ClementTsang/bottom/pull/504): Fixes two bugs causing the battery widget colours and mouse events to be broken.
|
||||||
|
|
||||||
## [0.6.1] - 2021-05-11
|
## [0.6.1] - 2021-05-11
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 166 KiB |
|
@ -3112,7 +3112,8 @@ impl App {
|
||||||
for (itx, ((tlc_x, tlc_y), (brc_x, brc_y))) in
|
for (itx, ((tlc_x, tlc_y), (brc_x, brc_y))) in
|
||||||
tab_spacing.iter().enumerate()
|
tab_spacing.iter().enumerate()
|
||||||
{
|
{
|
||||||
if (x >= *tlc_x && y >= *tlc_y) && (x < *brc_x && y < *brc_y) {
|
if (x >= *tlc_x && y >= *tlc_y) && (x <= *brc_x && y <= *brc_y)
|
||||||
|
{
|
||||||
battery_widget_state.currently_selected_battery_index = itx;
|
battery_widget_state.currently_selected_battery_index = itx;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use tui::{
|
||||||
layout::{Constraint, Direction, Layout, Rect},
|
layout::{Constraint, Direction, Layout, Rect},
|
||||||
terminal::Frame,
|
terminal::Frame,
|
||||||
text::{Span, Spans},
|
text::{Span, Spans},
|
||||||
widgets::{Block, Borders, Paragraph, Row, Table, Tabs},
|
widgets::{Block, Borders, Cell, Paragraph, Row, Table, Tabs},
|
||||||
};
|
};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
|
@ -129,30 +129,33 @@ impl BatteryDisplayWidget for Painter {
|
||||||
charge_percentage,
|
charge_percentage,
|
||||||
);
|
);
|
||||||
|
|
||||||
let battery_items: Vec<Vec<&str>> = vec![
|
let battery_rows = vec![
|
||||||
vec!["Charge %", &bars],
|
Row::new(vec![
|
||||||
vec!["Consumption", &battery_details.watt_consumption],
|
Cell::from("Charge %").style(self.colours.text_style),
|
||||||
|
Cell::from(bars).style(if charge_percentage < 10.0 {
|
||||||
|
self.colours.low_battery_colour
|
||||||
|
} else if charge_percentage < 50.0 {
|
||||||
|
self.colours.medium_battery_colour
|
||||||
|
} else {
|
||||||
|
self.colours.high_battery_colour
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
Row::new(vec!["Consumption", &battery_details.watt_consumption])
|
||||||
|
.style(self.colours.text_style),
|
||||||
if let Some(duration_until_full) = &battery_details.duration_until_full {
|
if let Some(duration_until_full) = &battery_details.duration_until_full {
|
||||||
vec!["Time to full", duration_until_full]
|
Row::new(vec!["Time to full", duration_until_full])
|
||||||
|
.style(self.colours.text_style)
|
||||||
} else if let Some(duration_until_empty) = &battery_details.duration_until_empty
|
} else if let Some(duration_until_empty) = &battery_details.duration_until_empty
|
||||||
{
|
{
|
||||||
vec!["Time to empty", duration_until_empty]
|
Row::new(vec!["Time to empty", duration_until_empty])
|
||||||
|
.style(self.colours.text_style)
|
||||||
} else {
|
} else {
|
||||||
vec!["Time to full/empty", "N/A"]
|
Row::new(vec!["Time to full/empty", "N/A"]).style(self.colours.text_style)
|
||||||
},
|
},
|
||||||
vec!["Health %", &battery_details.health],
|
Row::new(vec!["Health %", &battery_details.health])
|
||||||
|
.style(self.colours.text_style),
|
||||||
];
|
];
|
||||||
|
|
||||||
let battery_rows = battery_items.into_iter().map(|item| {
|
|
||||||
Row::new(item).style(if charge_percentage < 10.0 {
|
|
||||||
self.colours.low_battery_colour
|
|
||||||
} else if charge_percentage < 50.0 {
|
|
||||||
self.colours.medium_battery_colour
|
|
||||||
} else {
|
|
||||||
self.colours.high_battery_colour
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
Table::new(battery_rows)
|
Table::new(battery_rows)
|
||||||
|
@ -183,14 +186,13 @@ impl BatteryDisplayWidget for Painter {
|
||||||
let mut tab_click_locs: Vec<((u16, u16), (u16, u16))> = vec![];
|
let mut tab_click_locs: Vec<((u16, u16), (u16, u16))> = vec![];
|
||||||
for battery in battery_names {
|
for battery in battery_names {
|
||||||
// +1 because there's a space after the tab label.
|
// +1 because there's a space after the tab label.
|
||||||
let width =
|
let width = unicode_width::UnicodeWidthStr::width(battery.as_str()) as u16;
|
||||||
unicode_width::UnicodeWidthStr::width(battery.as_str()) as u16 + 1;
|
|
||||||
tab_click_locs
|
tab_click_locs
|
||||||
.push(((current_x, current_y), (current_x + width, current_y)));
|
.push(((current_x, current_y), (current_x + width, current_y)));
|
||||||
|
|
||||||
// +2 because we want to go one space past to get to the '|', then one MORE
|
// +4 because we want to go one space, then one space past to get to the '|', then 2 more
|
||||||
// to start at the blank space before the tab label.
|
// to start at the blank space before the tab label.
|
||||||
current_x = current_x + width + 2;
|
current_x += width + 4;
|
||||||
}
|
}
|
||||||
battery_widget_state.tab_click_locs = Some(tab_click_locs);
|
battery_widget_state.tab_click_locs = Some(tab_click_locs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue