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