fix(stack): set correct colors for light theme

This commit is contained in:
Michael Aaron Murphy 2024-02-27 00:29:23 +01:00 committed by Victoria Brekenfeld
parent 21483b8d41
commit d9750ffb76
4 changed files with 45 additions and 13 deletions

View file

@ -861,7 +861,9 @@ impl Program for CosmicStackInternal {
theme::Container::custom(|theme| iced_widget::container::Appearance { theme::Container::custom(|theme| iced_widget::container::Appearance {
icon_color: Some(Color::from(theme.cosmic().background.on)), icon_color: Some(Color::from(theme.cosmic().background.on)),
text_color: Some(Color::from(theme.cosmic().background.on)), text_color: Some(Color::from(theme.cosmic().background.on)),
background: Some(Background::Color(theme.cosmic().palette.neutral_3.into())), background: Some(Background::Color(tab::primary_container_color(
theme.cosmic(),
))),
border_radius: BorderRadius::from([8.0, 8.0, 0.0, 0.0]), border_radius: BorderRadius::from([8.0, 8.0, 0.0, 0.0]),
border_width: 0.0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,

View file

@ -28,6 +28,30 @@ use cosmic::{
use super::tab_text::tab_text; use super::tab_text::tab_text;
/// The background color of the stack tab header.
pub(super) fn primary_container_color(theme: &cosmic::cosmic_theme::Theme) -> Color {
const PRIMARY_CONTAINER_DARK: Color = Color::from_rgba(0.149, 0.149, 0.149, 1.0);
const PRIMARY_CONTAINER_LIGHT: Color = Color::from_rgba(0.894, 0.894, 0.894, 1.0);
if theme.is_dark {
PRIMARY_CONTAINER_DARK
} else {
PRIMARY_CONTAINER_LIGHT
}
}
/// The background color for the selected stack tab.
pub(super) fn selected_state_color(theme: &cosmic::cosmic_theme::Theme) -> Color {
const SELECTED_STATE_DARK: Color = Color::from_rgba(0.302, 0.302, 0.302, 0.3);
const SELECTED_STATE_LIGHT: Color = Color::from_rgba(0.596, 0.596, 0.596, 0.2);
if theme.is_dark {
SELECTED_STATE_DARK
} else {
SELECTED_STATE_LIGHT
}
}
pub(super) enum TabRuleTheme { pub(super) enum TabRuleTheme {
ActiveActivated, ActiveActivated,
ActiveDeactivated, ActiveDeactivated,
@ -59,6 +83,7 @@ impl Into<theme::Rule> for TabRuleTheme {
} }
} }
#[derive(Clone, Copy)]
pub(super) enum TabBackgroundTheme { pub(super) enum TabBackgroundTheme {
ActiveActivated, ActiveActivated,
ActiveDeactivated, ActiveDeactivated,
@ -66,34 +91,36 @@ pub(super) enum TabBackgroundTheme {
} }
impl TabBackgroundTheme { impl TabBackgroundTheme {
fn background_color(&self) -> Color { /// Select the background color of stack tabs based on dark theme preference.
fn background_color(self, theme: &theme::Theme) -> Color {
match self { match self {
TabBackgroundTheme::ActiveActivated => Color::from_rgba(0.365, 0.365, 0.365, 1.0), TabBackgroundTheme::ActiveActivated | TabBackgroundTheme::ActiveDeactivated => {
TabBackgroundTheme::ActiveDeactivated => Color::from_rgba(0.365, 0.365, 0.365, 1.0), selected_state_color(theme.cosmic())
TabBackgroundTheme::Default => Color::from_rgba(0.26, 0.26, 0.26, 1.0), }
TabBackgroundTheme::Default => primary_container_color(theme.cosmic()),
} }
} }
} }
impl Into<theme::Container> for TabBackgroundTheme { impl Into<theme::Container> for TabBackgroundTheme {
fn into(self) -> theme::Container { fn into(self) -> theme::Container {
let background_color = cosmic::iced::Background::Color(self.background_color());
match self { match self {
Self::ActiveActivated => { Self::ActiveActivated => {
theme::Container::custom(move |theme| widget::container::Appearance { theme::Container::custom(move |theme| widget::container::Appearance {
icon_color: Some(Color::from(theme.cosmic().accent_text_color())), icon_color: Some(Color::from(theme.cosmic().accent_text_color())),
text_color: Some(Color::from(theme.cosmic().accent_text_color())), text_color: Some(Color::from(theme.cosmic().accent_text_color())),
background: Some(background_color), background: Some(self.background_color(theme).into()),
border_radius: 0.0.into(), border_radius: 0.0.into(),
border_width: 0.0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}) })
} }
Self::ActiveDeactivated => { Self::ActiveDeactivated => {
theme::Container::custom(move |_theme| widget::container::Appearance { theme::Container::custom(move |theme| widget::container::Appearance {
icon_color: None, icon_color: None,
text_color: None, text_color: None,
background: Some(background_color), background: Some(self.background_color(theme).into()),
border_radius: 0.0.into(), border_radius: 0.0.into(),
border_width: 0.0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
@ -224,7 +251,10 @@ impl<Message: TabMessage> Tab<Message> {
.horizontal_alignment(alignment::Horizontal::Left) .horizontal_alignment(alignment::Horizontal::Left)
.vertical_alignment(alignment::Vertical::Center) .vertical_alignment(alignment::Vertical::Center)
.apply(tab_text) .apply(tab_text)
.background(self.background_theme.background_color()) .background(
self.background_theme
.background_color(&cosmic::theme::active()),
)
.height(Length::Fill) .height(Length::Fill)
.width(Length::Fill), .width(Length::Fill),
), ),

View file

@ -131,7 +131,7 @@ where
..bounds ..bounds
}; };
let mut transparent_background = self.background.clone(); let mut transparent_background = self.background;
transparent_background.a = 0.0; transparent_background.a = 0.0;
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {

View file

@ -526,8 +526,8 @@ where
&theme::Container::custom(|theme| widget::container::Appearance { &theme::Container::custom(|theme| widget::container::Appearance {
icon_color: None, icon_color: None,
text_color: None, text_color: None,
background: Some(Background::Color(Color::from( background: Some(Background::Color(super::tab::primary_container_color(
theme.cosmic().palette.neutral_3, theme.cosmic(),
))), ))),
border_radius: 0.0.into(), border_radius: 0.0.into(),
border_width: 0.0, border_width: 0.0,