From 9292ea647b42787cd8b219e50026ac4bdb00d716 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 17 May 2024 19:42:02 +0200 Subject: [PATCH] feat: inactive window header icon/text colors --- src/theme/style/iced.rs | 50 ++++++++++++++++++++++++++-------------- src/widget/header_bar.rs | 4 +++- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/theme/style/iced.rs b/src/theme/style/iced.rs index 87058bc5..94dee4c5 100644 --- a/src/theme/style/iced.rs +++ b/src/theme/style/iced.rs @@ -373,7 +373,9 @@ pub enum Container { Custom(Box container::Appearance>), Dialog, Dropdown, - HeaderBar, + HeaderBar { + focused: bool, + }, List, Primary, Secondary, @@ -473,22 +475,36 @@ impl container::StyleSheet for Theme { } } - Container::HeaderBar => container::Appearance { - icon_color: Some(Color::from(cosmic.accent.base)), - text_color: Some(Color::from(cosmic.background.on)), - background: Some(iced::Background::Color(cosmic.background.base.into())), - border: Border { - radius: [ - cosmic.corner_radii.radius_xs[0], - cosmic.corner_radii.radius_xs[1], - cosmic.corner_radii.radius_0[2], - cosmic.corner_radii.radius_0[3], - ] - .into(), - ..Default::default() - }, - shadow: Shadow::default(), - }, + Container::HeaderBar { focused } => { + let (icon_color, text_color) = if *focused { + ( + Color::from(cosmic.accent.base), + Color::from(cosmic.background.on), + ) + } else { + use crate::ext::ColorExt; + let unfocused_color = Color::from(cosmic.background.component.on) + .blend_alpha(cosmic.background.base.into(), 0.75); + (unfocused_color, unfocused_color) + }; + + container::Appearance { + icon_color: Some(icon_color), + text_color: Some(text_color), + background: Some(iced::Background::Color(cosmic.background.base.into())), + border: Border { + radius: [ + cosmic.corner_radii.radius_xs[0], + cosmic.corner_radii.radius_xs[1], + cosmic.corner_radii.radius_0[2], + cosmic.corner_radii.radius_0[3], + ] + .into(), + ..Default::default() + }, + shadow: Shadow::default(), + } + } Container::ContextDrawer => { let mut appearance = crate::style::Container::primary(cosmic); diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index c30a7089..6d47d2d5 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -299,7 +299,9 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { .padding(8) .spacing(8) .apply(widget::container) - .style(crate::theme::Container::HeaderBar) + .style(crate::theme::Container::HeaderBar { + focused: self.focused, + }) .center_y() .apply(widget::mouse_area);