mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 05:34:57 +02:00
other: full width battery bar (#1251)
This commit is contained in:
parent
c9a42f7061
commit
83a8607e5b
@ -131,9 +131,8 @@ impl Painter {
|
|||||||
.battery_data
|
.battery_data
|
||||||
.get(battery_widget_state.currently_selected_battery_index)
|
.get(battery_widget_state.currently_selected_battery_index)
|
||||||
{
|
{
|
||||||
// Assuming a 50/50 split in width
|
let full_width = draw_loc.width.saturating_sub(2);
|
||||||
let half_width = draw_loc.width.saturating_sub(2) / 2;
|
let bar_length = usize::from(full_width.saturating_sub(6));
|
||||||
let bar_length = usize::from(half_width.saturating_sub(8));
|
|
||||||
let charge_percentage = battery_details.charge_percentage;
|
let charge_percentage = battery_details.charge_percentage;
|
||||||
let num_bars = calculate_basic_use_bars(charge_percentage, bar_length);
|
let num_bars = calculate_basic_use_bars(charge_percentage, bar_length);
|
||||||
let bars = format!(
|
let bars = format!(
|
||||||
@ -183,17 +182,22 @@ impl Painter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut battery_rows = Vec::with_capacity(4);
|
let mut battery_charge_rows = Vec::with_capacity(2);
|
||||||
battery_rows.push(Row::new([
|
battery_charge_rows.push(Row::new([
|
||||||
Cell::from("Charge").style(self.colours.text_style),
|
Cell::from("Charge").style(self.colours.text_style)
|
||||||
Cell::from(bars).style(if charge_percentage < 10.0 {
|
]));
|
||||||
|
battery_charge_rows.push(Row::new([Cell::from(bars).style(
|
||||||
|
if charge_percentage < 10.0 {
|
||||||
self.colours.low_battery_colour
|
self.colours.low_battery_colour
|
||||||
} else if charge_percentage < 50.0 {
|
} else if charge_percentage < 50.0 {
|
||||||
self.colours.medium_battery_colour
|
self.colours.medium_battery_colour
|
||||||
} else {
|
} else {
|
||||||
self.colours.high_battery_colour
|
self.colours.high_battery_colour
|
||||||
}),
|
},
|
||||||
]));
|
)]));
|
||||||
|
|
||||||
|
let mut battery_rows = Vec::with_capacity(3);
|
||||||
|
battery_rows.push(Row::new([""]).bottom_margin(table_gap * 2));
|
||||||
battery_rows.push(
|
battery_rows.push(
|
||||||
Row::new(["Rate", &battery_details.watt_consumption])
|
Row::new(["Rate", &battery_details.watt_consumption])
|
||||||
.style(self.colours.text_style),
|
.style(self.colours.text_style),
|
||||||
@ -210,7 +214,7 @@ impl Painter {
|
|||||||
BatteryDuration::ToEmpty(secs) => {
|
BatteryDuration::ToEmpty(secs) => {
|
||||||
time = long_time(*secs);
|
time = long_time(*secs);
|
||||||
|
|
||||||
if half_width as usize > time.len() {
|
if full_width as usize > time.len() {
|
||||||
battery_rows.push(Row::new(["Time to empty", &time]).style(style));
|
battery_rows.push(Row::new(["Time to empty", &time]).style(style));
|
||||||
} else {
|
} else {
|
||||||
time = short_time(*secs);
|
time = short_time(*secs);
|
||||||
@ -220,7 +224,7 @@ impl Painter {
|
|||||||
BatteryDuration::ToFull(secs) => {
|
BatteryDuration::ToFull(secs) => {
|
||||||
time = long_time(*secs);
|
time = long_time(*secs);
|
||||||
|
|
||||||
if half_width as usize > time.len() {
|
if full_width as usize > time.len() {
|
||||||
battery_rows.push(Row::new(["Time to full", &time]).style(style));
|
battery_rows.push(Row::new(["Time to full", &time]).style(style));
|
||||||
} else {
|
} else {
|
||||||
time = short_time(*secs);
|
time = short_time(*secs);
|
||||||
@ -243,7 +247,16 @@ impl Painter {
|
|||||||
Row::default()
|
Row::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Draw
|
// Draw bar
|
||||||
|
f.render_widget(
|
||||||
|
Table::new(battery_charge_rows)
|
||||||
|
.block(battery_block.clone())
|
||||||
|
.header(header.clone())
|
||||||
|
.widths(&[Constraint::Percentage(100)]),
|
||||||
|
margined_draw_loc,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Draw info
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
Table::new(battery_rows)
|
Table::new(battery_rows)
|
||||||
.block(battery_block)
|
.block(battery_block)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user