Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/components/format_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ impl<'a, Msg: 'static + Clone> From<FormatIndicator<'a, Msg>> for Element<'a, Ms

let content = match fi.format {
SettingsFormat::Icon => fi.icon.to_text().into(),
SettingsFormat::Percentage | SettingsFormat::Time | SettingsFormat::Name => {
fi.label_element
}
SettingsFormat::Percentage
| SettingsFormat::Time
| SettingsFormat::Name
| SettingsFormat::PercentageAndTime => fi.label_element,
SettingsFormat::IconAndPercentage
| SettingsFormat::IconAndTime
| SettingsFormat::IconAndName => row![fi.icon.to_text(), fi.label_element]
| SettingsFormat::IconAndName
| SettingsFormat::IconAndPercentageAndTime => row![fi.icon.to_text(), fi.label_element]
.spacing(space.xxs)
.align_y(Alignment::Center)
.into(),
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ pub enum SettingsFormat {
IconAndTime,
Name,
IconAndName,
PercentageAndTime,
IconAndPercentageAndTime,
}

#[derive(Deserialize, Clone, Default, PartialEq, Eq, Debug)]
Expand Down
25 changes: 25 additions & 0 deletions src/modules/settings/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,21 @@ impl PowerSettings {
SettingsFormat::Name | SettingsFormat::IconAndName => {
convert::Into::<Element<'a, Message>>::into(icon(p.get_icon_state()))
}
SettingsFormat::PercentageAndTime => row!(
text(format!("{}%", p.data.capacity)),
text(format_time_for_battery(&p.data))
)
.spacing(space.xxs)
.align_y(Alignment::Center)
.into(),
SettingsFormat::IconAndPercentageAndTime => row!(
icon(p.get_icon_state()),
text(format!("{}%", p.data.capacity)),
text(format_time_for_battery(&p.data))
)
.spacing(space.xxs)
.align_y(Alignment::Center)
.into(),
Comment thread
InnocentZero marked this conversation as resolved.
})
.style(move |theme: &Theme| container::Style {
text_color: Some(match state {
Expand Down Expand Up @@ -333,6 +348,16 @@ impl PowerSettings {
SettingsFormat::Time | SettingsFormat::IconAndTime => {
format_time_for_battery(&battery)
}
SettingsFormat::PercentageAndTime
| SettingsFormat::IconAndPercentageAndTime => {
let battery_time = format_time_for_battery(&battery);
let battery_capacity = format!("{}%", battery.capacity);
if battery_time != "100%" || battery_time != battery_capacity {
battery_capacity + " " + &battery_time
} else {
battery_capacity
}
}
Comment thread
InnocentZero marked this conversation as resolved.
_ => format!("{}%", battery.capacity),
};

Expand Down
2 changes: 2 additions & 0 deletions website/docs/configuration/modules/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ The possible values are:
- `IconAndPercentage` - Show both the battery icon and percentage (default)
- `Time` - Show smart time display (time to full when charging, time to empty when discharging, "100%" when full)
- `IconAndTime` - Show battery icon with smart time display
- `PercentageAndTime` - Show the battery percentage along with smart time display
- `IconAndPercentageAndTime` - Show battery icon with battery percentage and smart time display

```toml
[settings]
Expand Down