Centralize accent foreground contrast across Ferese UI

This commit is contained in:
Samuel Onoja committed 2026-09-28 08:58:51 +01:00
1 parent 299f60e671
commit 24e15f76cb
14 files changed
+327 -64

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ license.workspace = true
rust-version = "1.95"
[dependencies]
ferese-theme = { path = "../../crates/ferese-theme" }
ferese-config = { path = "../../crates/ferese-config" }
libcosmic.workspace = true
jiff.workspace = true
+9 -9
View File
@@ -115,15 +115,15 @@ impl Appearance {
corners.radius_m = [self.radius; 4];
corners.radius_l = [self.radius; 4];
corners.radius_xl = [self.radius; 4];
cosmic::Theme::custom(std::sync::Arc::new(
builder
.corner_radii(corners)
.bg_color(color(self.panel))
.primary_container_bg(color(self.panel))
.text_tint(color(self.text).color)
.accent(color(self.accent).color)
.build(),
))
let mut native = builder
.corner_radii(corners)
.bg_color(color(self.panel))
.primary_container_bg(color(self.panel))
.text_tint(color(self.text).color)
.accent(ferese_theme::accent_color(self.accent, self.panel))
.build();
ferese_theme::apply(&mut native, self.text);
cosmic::Theme::custom(std::sync::Arc::new(native))
}
}
+5 -2
View File
@@ -362,9 +362,12 @@ impl Locker {
.center_x(avatar_size)
.center_y(avatar_size)
.class(theme::Container::custom(move |_| {
let fill = ferese_theme::composite(a.accent.scale_alpha(0.18), a.panel);
let on = ferese_theme::foreground(fill, a.accent);
widget::container::Style {
background: Some(iced::Background::Color(a.accent.scale_alpha(0.18))),
text_color: Some(a.accent),
background: Some(iced::Background::Color(fill)),
text_color: Some(on),
icon_color: Some(on),
border: iced::Border {
radius: (avatar_size / 2.).into(),
width: 1.,
+1
View File
@@ -6,6 +6,7 @@ license.workspace = true
rust-version = "1.93"
[dependencies]
ferese-theme = { path = "../../crates/ferese-theme" }
ferese-config = { path = "../../crates/ferese-config" }
libcosmic = { workspace = true, features = ["wgpu", "a11y", "xdg-portal"] }
ferese-ipc = { path = "../../crates/ferese-ipc" }
+31 -28
View File
@@ -62,16 +62,7 @@ impl Palette {
}
}
fn luminance(color: Color) -> f32 {
let channel = |value: f32| {
if value <= 0.04045 {
value / 12.92
} else {
((value + 0.055) / 1.055).powf(2.4)
}
};
0.2126 * channel(color.r) + 0.7152 * channel(color.g) + 0.0722 * channel(color.b)
}
use ferese_theme::luminance;
fn surface_shade(base: Color) -> Color {
if luminance(base) > 0.5 {
@@ -145,8 +136,8 @@ pub fn input_style(p: Palette) -> theme::TextInput {
}
fn styled_button(p: Palette, selected: bool, navigation: bool) -> theme::Button {
let style = move |hover: bool| button::Style {
background: Some(Background::Color(if selected {
let style = move |hover: bool| {
let background = if selected {
mix(p.sidebar, p.accent, if hover { 0.24 } else { 0.17 })
} else if hover {
mix(p.card, surface_shade(p.sidebar), 0.06)
@@ -154,20 +145,28 @@ fn styled_button(p: Palette, selected: bool, navigation: bool) -> theme::Button
p.sidebar
} else {
p.card
})),
text_color: Some(p.text),
icon_color: None,
border_radius: 9.into(),
border_width: if selected { 1. } else { 0. },
border_color: if selected {
p.accent
};
let on = if selected {
ferese_theme::foreground(background, p.text)
} else {
Color::TRANSPARENT
},
outline_width: 0.,
outline_color: Color::TRANSPARENT,
overlay: None,
shadow_offset: Vector::ZERO,
p.text
};
button::Style {
background: Some(Background::Color(background)),
text_color: Some(on),
icon_color: Some(on),
border_radius: 9.into(),
border_width: if selected { 1. } else { 0. },
border_color: if selected {
p.accent
} else {
Color::TRANSPARENT
},
outline_width: 0.,
outline_color: Color::TRANSPARENT,
overlay: None,
shadow_offset: Vector::ZERO,
}
};
theme::Button::Custom {
@@ -180,7 +179,10 @@ fn styled_button(p: Palette, selected: bool, navigation: bool) -> theme::Button
pub fn native_theme(snapshot: Option<&Snapshot>) -> cosmic::Theme {
let Some(snapshot) = snapshot else {
return cosmic::Theme::custom(std::sync::Arc::new(cosmic::theme::COSMIC_DARK.clone()));
let mut native = cosmic::theme::COSMIC_DARK.clone();
let preferred = native.background(false).on.into();
ferese_theme::apply(&mut native, preferred);
return cosmic::Theme::custom(std::sync::Arc::new(native));
};
let palette = Palette::from(snapshot);
let builder = if luminance(palette.sidebar) > 0.5 {
@@ -188,12 +190,13 @@ pub fn native_theme(snapshot: Option<&Snapshot>) -> cosmic::Theme {
} else {
cosmic::cosmic_theme::ThemeBuilder::dark()
};
let theme = builder
let mut theme = builder
.bg_color(cosmic_color(palette.background))
.primary_container_bg(cosmic_color(palette.card))
.text_tint(cosmic_color(palette.text).color)
.accent(cosmic_color(palette.accent).color)
.accent(ferese_theme::accent_color(palette.accent, palette.card))
.build();
ferese_theme::apply(&mut theme, palette.text);
cosmic::Theme::custom(std::sync::Arc::new(theme))
}
+1
View File
@@ -6,6 +6,7 @@ license.workspace = true
rust-version = "1.93"
[dependencies]
ferese-theme = { path = "../../crates/ferese-theme" }
ferese-config = { path = "../../crates/ferese-config" }
ferese-core = { path = "../../crates/ferese-core" }
ferese-protocols = { path = "../../crates/ferese-protocols", default-features = false, features = ["client"] }
+11 -14
View File
@@ -65,18 +65,6 @@ fn blend(base: Color, foreground: Color, amount: f32) -> Color {
}
}
fn contrast_text(background: Color, opacity: f32) -> Color {
let level = background.r * 0.2126 + background.g * 0.7152 + background.b * 0.0722;
Color {
a: opacity,
..if level > 0.6 {
Color::BLACK
} else {
Color::WHITE
}
}
}
fn age_label(age: Duration) -> String {
match age.as_secs() {
0..60 => "now".into(),
@@ -345,16 +333,25 @@ impl FereseShell {
..Default::default()
}));
let icon: Element<'_, cosmic::Action<Message>> = if count > 1 {
let badge_fill = ferese_theme::composite(
color(palette.accent),
color(if history {
palette.surface_base
} else {
palette.surface_popover
}),
);
let badge_text = ferese_theme::foreground(badge_fill, color(palette.text_primary));
let badge = container(
text(count.to_string())
.size(10)
.font(bold)
.class(theme::Text::Color(contrast_text(accent, opacity))),
.class(theme::Text::Color(badge_text.scale_alpha(opacity))),
)
.center_x(16)
.center_y(16)
.class(theme::Container::custom(move |_| container::Style {
background: Some(Background::Color(accent)),
background: Some(Background::Color(badge_fill.scale_alpha(opacity))),
border: Border {
radius: motion::radius(8.0).into(),
..Default::default()