Skip to content

Commit 86493b7

Browse files
mmstickDrakulix
authored andcommitted
improv(stack): use system theme colors
1 parent 7ccfd73 commit 86493b7

File tree

4 files changed

+28
-52
lines changed

4 files changed

+28
-52
lines changed

src/shell/element/stack.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,18 +1077,18 @@ impl Program for CosmicStackInternal {
10771077
.apply(iced_widget::container)
10781078
.align_y(Alignment::Center)
10791079
.class(theme::Container::custom(move |theme| {
1080+
let cosmic_theme = theme.cosmic();
1081+
10801082
let background = if group_focused {
1081-
Some(Background::Color(theme.cosmic().accent_color().into()))
1083+
cosmic_theme.accent_color()
10821084
} else {
1083-
Some(Background::Color(tab::primary_container_color(
1084-
theme.cosmic(),
1085-
)))
1085+
cosmic_theme.primary_container_color()
10861086
};
10871087

10881088
iced_widget::container::Style {
1089-
icon_color: Some(Color::from(theme.cosmic().background.on)),
1090-
text_color: Some(Color::from(theme.cosmic().background.on)),
1091-
background,
1089+
icon_color: Some(cosmic_theme.background.on.into()),
1090+
text_color: Some(cosmic_theme.background.on.into()),
1091+
background: Some(Background::Color(background.into())),
10921092
border: Border {
10931093
radius,
10941094
width: 0.0,

src/shell/element/stack/tab.rs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use cosmic::{
22
font::Font,
3-
iced::widget::{self, container::draw_background, rule::FillMode},
3+
iced::{
4+
widget::{self, container::draw_background, rule::FillMode},
5+
Background,
6+
},
47
iced_core::{
58
alignment, event,
69
layout::{Layout, Limits, Node},
@@ -16,30 +19,6 @@ use cosmic::{
1619

1720
use super::tab_text::tab_text;
1821

19-
/// The background color of the stack tab header.
20-
pub(super) fn primary_container_color(theme: &cosmic::cosmic_theme::Theme) -> Color {
21-
const PRIMARY_CONTAINER_DARK: Color = Color::from_rgba(0.149, 0.149, 0.149, 1.0);
22-
const PRIMARY_CONTAINER_LIGHT: Color = Color::from_rgba(0.894, 0.894, 0.894, 1.0);
23-
24-
if theme.is_dark {
25-
PRIMARY_CONTAINER_DARK
26-
} else {
27-
PRIMARY_CONTAINER_LIGHT
28-
}
29-
}
30-
31-
/// The background color for the selected stack tab.
32-
pub(super) fn selected_state_color(theme: &cosmic::cosmic_theme::Theme) -> Color {
33-
const SELECTED_STATE_DARK: Color = Color::from_rgba(0.195, 0.195, 0.195, 1.0);
34-
const SELECTED_STATE_LIGHT: Color = Color::from_rgba(0.8344, 0.8344, 0.8344, 1.0);
35-
36-
if theme.is_dark {
37-
SELECTED_STATE_DARK
38-
} else {
39-
SELECTED_STATE_LIGHT
40-
}
41-
}
42-
4322
#[derive(Clone, Copy)]
4423
pub(super) enum TabRuleTheme {
4524
ActiveActivated,
@@ -79,27 +58,16 @@ pub(super) enum TabBackgroundTheme {
7958
Default,
8059
}
8160

82-
impl TabBackgroundTheme {
83-
/// Select the background color of stack tabs based on dark theme preference.
84-
fn background_color(self, theme: &theme::Theme) -> Color {
85-
match self {
86-
TabBackgroundTheme::ActiveActivated | TabBackgroundTheme::ActiveDeactivated => {
87-
selected_state_color(theme.cosmic())
88-
}
89-
90-
TabBackgroundTheme::Default => primary_container_color(theme.cosmic()),
91-
}
92-
}
93-
}
94-
9561
impl From<TabBackgroundTheme> for theme::Container<'_> {
9662
fn from(background_theme: TabBackgroundTheme) -> Self {
9763
match background_theme {
9864
TabBackgroundTheme::ActiveActivated => {
9965
Self::custom(move |theme| widget::container::Style {
10066
icon_color: Some(Color::from(theme.cosmic().accent_text_color())),
10167
text_color: Some(Color::from(theme.cosmic().accent_text_color())),
102-
background: Some(background_theme.background_color(theme).into()),
68+
background: Some(Background::Color(
69+
theme.cosmic().primary.component.selected.into(),
70+
)),
10371
border: Border {
10472
radius: 0.0.into(),
10573
width: 0.0,
@@ -112,7 +80,9 @@ impl From<TabBackgroundTheme> for theme::Container<'_> {
11280
Self::custom(move |theme| widget::container::Style {
11381
icon_color: None,
11482
text_color: None,
115-
background: Some(background_theme.background_color(theme).into()),
83+
background: Some(Background::Color(
84+
theme.cosmic().primary.component.base.into(),
85+
)),
11686
border: Border {
11787
radius: 0.0.into(),
11888
width: 0.0,

src/shell/element/stack/tab_text.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl TabText {
7171
fn create_hash(&self) -> u64 {
7272
let mut hasher = std::collections::hash_map::DefaultHasher::new();
7373
self.text.hash(&mut hasher);
74+
self.selected.hash(&mut hasher);
7475
hasher.finish()
7576
}
7677

@@ -149,9 +150,14 @@ impl<Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for TabText {
149150

150151
if state.overflowed {
151152
let background = if self.selected {
152-
super::tab::selected_state_color(theme.cosmic())
153+
theme
154+
.cosmic()
155+
.primary
156+
.component
157+
.selected_state_color()
158+
.into()
153159
} else {
154-
super::tab::primary_container_color(theme.cosmic())
160+
theme.cosmic().primary_container_color().into()
155161
};
156162
let transparent = Color {
157163
a: 0.0,

src/shell/element/stack/tabs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,9 @@ where
511511
&theme::Container::custom(|theme| widget::container::Style {
512512
icon_color: None,
513513
text_color: None,
514-
background: Some(Background::Color(super::tab::primary_container_color(
515-
theme.cosmic(),
516-
))),
514+
background: Some(Background::Color(
515+
theme.cosmic().primary_container_color().into(),
516+
)),
517517
border: Border {
518518
radius: 0.0.into(),
519519
width: 0.0,

0 commit comments

Comments
 (0)