battery
This commit is contained in:
@@ -72,10 +72,21 @@ fn shell_style(status: BatteryStatus) -> impl Fn(&Theme) -> container::Style {
|
||||
}
|
||||
}
|
||||
|
||||
/// Solid fill (and nub cap) tinted by charge state.
|
||||
fn solid_style(status: BatteryStatus) -> impl Fn(&Theme) -> container::Style {
|
||||
move |theme: &Theme| container::Style {
|
||||
background: Some(ink(status, theme).into()),
|
||||
/// Solid fill (and nub cap) tinted by charge state. `dim` renders the
|
||||
/// Android-style muted fill that sits behind the in-icon number.
|
||||
fn solid_style(status: BatteryStatus, dim: bool) -> impl Fn(&Theme) -> container::Style {
|
||||
move |theme: &Theme| {
|
||||
let palette = theme.palette();
|
||||
let background = if dim {
|
||||
Color {
|
||||
a: 0.45,
|
||||
..palette.text
|
||||
}
|
||||
} else {
|
||||
ink(status, theme)
|
||||
};
|
||||
container::Style {
|
||||
background: Some(background.into()),
|
||||
border: Border {
|
||||
radius: 2.0.into(),
|
||||
..Default::default()
|
||||
@@ -83,6 +94,15 @@ fn solid_style(status: BatteryStatus) -> impl Fn(&Theme) -> container::Style {
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Bold face of the bar font, matching Android's bold in-icon digits.
|
||||
fn bold() -> iced::Font {
|
||||
iced::Font {
|
||||
weight: iced::font::Weight::Bold,
|
||||
..iced::Font::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl BarModule for Battery {
|
||||
fn id(&self) -> &'static str {
|
||||
@@ -95,20 +115,23 @@ impl BarModule for Battery {
|
||||
container(text(""))
|
||||
.width(Length::Fixed(self.fill_w()))
|
||||
.height(Length::Fill)
|
||||
.style(solid_style(status)),
|
||||
.style(solid_style(status, self.numbers_in_icon)),
|
||||
)
|
||||
.width(Length::Fixed(SHELL_W))
|
||||
.height(Length::Fixed(SHELL_H))
|
||||
.padding(PAD)
|
||||
.style(shell_style(status));
|
||||
// Optional percentage readout centered over the fill, in the bar's
|
||||
// background color — legible on the light fill, dim where unfilled.
|
||||
// Optional percentage readout centered over the fill, in the frame's
|
||||
// light color — legible on the dimmed fill, like Android.
|
||||
let shell: Element<'_, Wire> = match (self.numbers_in_icon, self.percent) {
|
||||
(true, Some(percent)) => stack![
|
||||
shell,
|
||||
container(
|
||||
text(format!("{percent}")).size(9).style(|theme: &Theme| text::Style {
|
||||
color: Some(theme.palette().background),
|
||||
text(format!("{percent}"))
|
||||
.size(10)
|
||||
.font(bold())
|
||||
.style(|theme: &Theme| text::Style {
|
||||
color: Some(theme.palette().text),
|
||||
}),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
@@ -125,7 +148,7 @@ impl BarModule for Battery {
|
||||
container(text(""))
|
||||
.width(Length::Fixed(2.5))
|
||||
.height(Length::Fixed(6.0))
|
||||
.style(solid_style(status)),
|
||||
.style(solid_style(status, false)),
|
||||
]
|
||||
.spacing(2)
|
||||
.align_y(iced::Alignment::Center);
|
||||
|
||||
Reference in New Issue
Block a user