diff --git a/crates/modules/src/battery.rs b/crates/modules/src/battery.rs index 342b2f5..cc05e76 100644 --- a/crates/modules/src/battery.rs +++ b/crates/modules/src/battery.rs @@ -72,15 +72,35 @@ 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()), - border: Border { - radius: 2.0.into(), - ..Default::default() - }, - ..container::Style::default() +/// 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() + }, + ..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() } } @@ -95,21 +115,24 @@ 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) .height(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);