Added theme management, custom theme colors
Moorly CI / windows-build (push) Successful in 3m4s
Moorly CI / linux-build (push) Successful in 3m36s

This commit is contained in:
Squid committed 2026-11-06 21:58:06 +01:00
1 parent da752bcfd7
commit 188e4f64d4
77 files changed
+40005 -104

No files matched your search

+792 -61
View File
File diff suppressed because it is too large. Load diff
+47 -34
View File
@@ -18,6 +18,8 @@ pub const DANGER: Color = Color::from_rgb8(0xff, 0x3b, 0x30);
pub const ACTIVE_TAB: Color = Color::from_rgb8(0x60, 0x82, 0xB6);
/// Highlight for the selected settings section.
pub const SETTINGS_ACTIVE: Color = Color::from_rgb8(0x5D, 0x3F, 0xD3);
/// Border for the collapsible advanced-settings area.
pub const ADVANCED_BORDER: Color = Color::from_rgb8(0xD0, 0xD0, 0xD0);
/// Tab bar surfaces: the active tab merges with the content area below.
pub const TAB_ACTIVE_BG: Color = Color::from_rgb8(0x19, 0x19, 0x19);
pub const TAB_INACTIVE_BG: Color = Color::from_rgb8(0x13, 0x13, 0x13);
@@ -51,7 +53,7 @@ impl Preference {
}
}
fn as_str(self) -> &'static str {
pub fn as_str(self) -> &'static str {
match self {
Self::System => "system",
Self::Light => "light",
@@ -59,7 +61,7 @@ impl Preference {
}
}
fn parse(value: &str) -> Option<Self> {
pub fn parse(value: &str) -> Option<Self> {
Self::ALL.into_iter().find(|pref| pref.as_str() == value)
}
}
@@ -105,20 +107,20 @@ pub(crate) fn config_path() -> Option<PathBuf> {
}
/// Style for the top menubar.
pub fn menubar(_theme: &Theme) -> container::Style {
pub fn menubar(_theme: &Theme, background: Color) -> container::Style {
container::Style {
background: Some(TAB_INACTIVE_BG.into()),
background: Some(background.into()),
..container::Style::default()
}
}
/// Style for buttons that sit directly on the dark menubar.
pub fn menubar_button(theme: &Theme, status: button::Status) -> button::Style {
pub fn menubar_button(theme: &Theme, status: button::Status, text_color: Color) -> button::Style {
let mut style = button::text(theme, status);
style.text_color = if matches!(status, button::Status::Disabled) {
TAB_TEXT.scale_alpha(0.4)
text_color.scale_alpha(0.4)
} else {
TAB_TEXT
text_color
};
style
}
@@ -132,12 +134,17 @@ pub fn menu(theme: &Theme) -> container::Style {
/// Style for a tab in the menubar; active tabs sit on the content surface.
/// The active outline is drawn separately so it has no bottom edge.
pub fn tab(_theme: &Theme, active: bool) -> container::Style {
pub fn tab(
_theme: &Theme,
active: bool,
active_bg: Color,
inactive_bg: Color,
) -> container::Style {
container::Style {
background: Some(if active {
TAB_ACTIVE_BG.into()
active_bg.into()
} else {
TAB_INACTIVE_BG.into()
inactive_bg.into()
}),
border: Border {
color: Color::TRANSPARENT,
@@ -154,36 +161,32 @@ pub fn tab(_theme: &Theme, active: bool) -> container::Style {
}
/// Style for the active tab's thin top/left/right outline.
pub fn tab_outline(_theme: &Theme) -> container::Style {
pub fn tab_outline(_theme: &Theme, color: Color) -> container::Style {
container::Style {
background: Some(ACTIVE_TAB.into()),
background: Some(color.into()),
..container::Style::default()
}
}
/// Rounded frame around the advanced-settings area.
pub fn advanced_frame(_theme: &Theme) -> container::Style {
container::Style {
border: Border {
color: ADVANCED_BORDER,
width: 1.0,
radius: 6.0.into(),
},
..container::Style::default()
}
}
/// Style for the selected settings section in the settings menu.
pub fn settings_active(_theme: &Theme, _status: button::Status) -> button::Style {
pub fn settings_active(_theme: &Theme, _status: button::Status, accent: Color) -> button::Style {
button::Style {
background: Some(SETTINGS_ACTIVE.into()),
background: Some(accent.into()),
text_color: Color::WHITE,
border: Border {
color: SETTINGS_ACTIVE,
width: 1.0,
radius: 4.0.into(),
},
..button::Style::default()
}
}
/// Style for the currently selected option in a group of choice buttons.
pub fn selected_option(theme: &Theme, _status: button::Status) -> button::Style {
let palette = theme.extended_palette();
button::Style {
background: Some(palette.primary.base.color.into()),
text_color: palette.primary.base.text,
border: Border {
color: palette.primary.base.color,
color: accent,
width: 1.0,
radius: 4.0.into(),
},
@@ -325,14 +328,24 @@ mod tests {
#[test]
fn active_tabs_are_visually_distinct() {
let theme = Theme::Light;
let active = super::tab(&theme, true);
let inactive = super::tab(&theme, false);
let active = super::tab(
&theme,
true,
super::TAB_ACTIVE_BG,
super::TAB_INACTIVE_BG,
);
let inactive = super::tab(
&theme,
false,
super::TAB_ACTIVE_BG,
super::TAB_INACTIVE_BG,
);
assert_ne!(active.background, inactive.background);
assert_eq!(active.border.width, 0.0);
assert_eq!(inactive.border.width, 0.0);
assert_eq!(
super::tab_outline(&theme).background,
super::tab_outline(&theme, super::ACTIVE_TAB).background,
Some(super::ACTIVE_TAB.into())
);
}