diff --git a/src/main.rs b/src/main.rs index f0af6f1..62a0112 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1522,8 +1522,8 @@ struct Moorly { command_palette_enabled: bool, command_palette_enabled_draft: bool, advanced_open: bool, - colors: [Color; 5], - saved_colors: [Color; 5], + colors: [Color; 6], + saved_colors: [Color; 6], custom_toasts: bool, toast_colors: [Color; 9], builtin_custom_toasts: bool, @@ -1578,15 +1578,17 @@ enum ColorOption { MainBackground, SidebarBackground, Text, + Border, } impl ColorOption { - const ALL: [Self; 5] = [ + const ALL: [Self; 6] = [ Self::Accent, Self::ActiveTabOutline, Self::MainBackground, Self::SidebarBackground, Self::Text, + Self::Border, ]; fn label(self) -> &'static str { @@ -1596,6 +1598,7 @@ impl ColorOption { Self::MainBackground => "Main background", Self::SidebarBackground => "Sidebar background", Self::Text => "Text color", + Self::Border => "Border color", } } @@ -1606,16 +1609,18 @@ impl ColorOption { Self::MainBackground => 2, Self::SidebarBackground => 3, Self::Text => 4, + Self::Border => 5, } } } -const DEFAULT_COLORS: [Color; 5] = [ +const DEFAULT_COLORS: [Color; 6] = [ theme::SETTINGS_ACTIVE, theme::ACTIVE_TAB, theme::TAB_ACTIVE_BG, theme::TAB_INACTIVE_BG, theme::TAB_TEXT, + Color::WHITE, ]; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -1714,7 +1719,7 @@ struct CustomTheme { id: String, name: String, based_on: theme::Preference, - colors: [Color; 5], + colors: [Color; 6], custom_toasts: bool, toast_colors: [Color; 9], typography: Typography, @@ -1734,6 +1739,8 @@ struct ThemeFile { sidebar_background: Option, #[serde(skip_serializing_if = "Option::is_none")] text: Option, + #[serde(skip_serializing_if = "Option::is_none")] + border: Option, #[serde(default)] typography: TypographyConfig, #[serde(default)] @@ -1768,8 +1775,8 @@ impl ThemeFile { fn from_colors( name: String, based_on: theme::Preference, - colors: &[Color; 5], - base: &[Color; 5], + colors: &[Color; 6], + base: &[Color; 6], custom_toasts: bool, toast_colors: &[Color; 9], typography: &Typography, @@ -1788,12 +1795,13 @@ impl ThemeFile { main_background: changed(ColorOption::MainBackground), sidebar_background: changed(ColorOption::SidebarBackground), text: changed(ColorOption::Text), + border: changed(ColorOption::Border), typography: TypographyConfig::from_typography(typography), toast: ToastFile::from_colors(custom_toasts, toast_colors), } } - fn colors(&self, based_on: theme::Preference) -> [Color; 5] { + fn colors(&self, based_on: theme::Preference) -> [Color; 6] { let mut colors = builtin_colors(based_on); let mut apply = |option: ColorOption, value: &Option| { @@ -1807,6 +1815,7 @@ impl ThemeFile { apply(ColorOption::MainBackground, &self.main_background); apply(ColorOption::SidebarBackground, &self.sidebar_background); apply(ColorOption::Text, &self.text); + apply(ColorOption::Border, &self.border); colors } @@ -1851,7 +1860,7 @@ impl ToastFile { } } -fn builtin_colors(_preference: theme::Preference) -> [Color; 5] { +fn builtin_colors(_preference: theme::Preference) -> [Color; 6] { DEFAULT_COLORS } @@ -2609,7 +2618,7 @@ fn write_custom_theme( id: &str, name: &str, based_on: theme::Preference, - colors: &[Color; 5], + colors: &[Color; 6], custom_toasts: bool, toast_colors: &[Color; 9], typography: &Typography, @@ -3999,7 +4008,7 @@ fn resolve_theme( ) -> ( ThemeChoice, theme::Preference, - [Color; 5], + [Color; 6], bool, [Color; 9], Typography, @@ -6371,7 +6380,7 @@ fn tab_view( hide_close: bool, close_opacity: f32, width: f32, - colors: [Color; 5], + colors: [Color; 6], ) -> Element<'static, Message> { let title = tab.title(); let padding = Padding::new(10.0); @@ -6485,7 +6494,7 @@ fn tab_view( fn drag_ghost( state: &Moorly, window: window::Id, - colors: [Color; 5], + colors: [Color; 6], ) -> Option> { let drag = state .drag @@ -6548,7 +6557,7 @@ fn drag_ghost( fn tab_drop_bar( state: &Moorly, window: window::Id, - colors: [Color; 5], + colors: [Color; 6], ) -> Option> { let drag = state .drag @@ -6618,7 +6627,7 @@ fn tab_drop_bar( fn drop_panel( state: &Moorly, window: window::Id, - colors: [Color; 5], + colors: [Color; 6], ) -> Option> { let drag = state.drag.as_ref().filter(|drag| drag.window == window)?; let window_state = state.windows.get(&window)?; @@ -6870,10 +6879,9 @@ fn font_family_picker(state: &Moorly, level: TypographyLevel) -> Element<'_, Mes .width(Length::Fill) .padding([6, 10]) .style(|theme: &iced::Theme, status| { - let palette = theme.extended_palette(); let mut button = button::text(theme, status); button.border = Border { - color: palette.background.strong.color, + color: theme::border_color(), width: 1.0, radius: 4.0.into(), }; @@ -6907,17 +6915,13 @@ fn font_family_picker(state: &Moorly, level: TypographyLevel) -> Element<'_, Mes ) .width(Length::Fill) .padding(2) - .style(|theme: &iced::Theme| { - let palette = theme.extended_palette(); - - container::Style { - border: Border { - color: palette.background.strong.color, - width: 1.0, - radius: 4.0.into(), - }, - ..container::Style::default() - } + .style(|_theme: &iced::Theme| container::Style { + border: Border { + color: theme::border_color(), + width: 1.0, + radius: 4.0.into(), + }, + ..container::Style::default() }); column = column.push(list); @@ -7139,7 +7143,7 @@ fn color_swatch_row<'a>( .style(move |_| container::Style { background: Some(color.into()), border: Border { - color: theme::ADVANCED_BORDER, + color: theme::border_color(), width: 1.0, radius: 3.0.into(), }, @@ -7990,7 +7994,7 @@ fn profile_dialog_view<'a>( .style(move |_| container::Style { background: Some(draft.glyph_color.into()), border: Border { - color: theme::ADVANCED_BORDER, + color: theme::border_color(), width: 1.0, radius: 3.0.into(), }, @@ -9322,17 +9326,13 @@ fn command_palette_item( container(text("Enter").size(11)) .align_y(Alignment::Center) .padding([0, 8]) - .style(|theme: &iced::Theme| { - let palette = theme.extended_palette(); - - container::Style { - border: Border { - color: palette.background.strong.color, - width: 1.0, - radius: 4.0.into(), - }, - ..container::Style::default() - } + .style(|_theme: &iced::Theme| container::Style { + border: Border { + color: theme::border_color(), + width: 1.0, + radius: 4.0.into(), + }, + ..container::Style::default() }), ); } @@ -9417,6 +9417,7 @@ fn command_palette_layer(state: &Moorly, window: window::Id) -> Option Element<'_, Message> { + theme::set_border_color(state.colors[ColorOption::Border.index()]); let content = main_view(state, window); let palette = command_palette_layer(state, window); @@ -9961,6 +9962,7 @@ mod tests { fn theme_file_only_stores_changed_colors() { let mut colors = super::DEFAULT_COLORS; colors[super::ColorOption::Accent.index()] = iced::Color::from_rgb8(1, 2, 3); + colors[super::ColorOption::Border.index()] = iced::Color::from_rgb8(4, 5, 6); let file = super::ThemeFile::from_colors( "Test theme".to_owned(), @@ -9976,6 +9978,7 @@ mod tests { assert!(text.contains("name = \"Test theme\"")); assert!(text.contains("based_on = \"dark\"")); assert!(text.contains("accent = \"#010203\"")); + assert!(text.contains("border = \"#040506\"")); assert!(!text.contains("active_tab_outline")); assert!(text.contains("[typography.h1]")); assert!(text.contains(&format!("font = \"{}\"", super::default_ui_font()))); diff --git a/src/theme.rs b/src/theme.rs index b124b66..4238cca 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -6,6 +6,7 @@ use std::env; use std::path::PathBuf; +use std::sync::{OnceLock, RwLock}; use iced::border::Radius; use iced::widget::{button, container, text_input}; @@ -18,7 +19,6 @@ 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); @@ -28,6 +28,25 @@ pub const TAB_TEXT: Color = Color::from_rgb8(0xe6, 0xe6, 0xe6); /// to a path missing from `folders.toml`. pub const UNTRACKED_FOLDER: Color = Color::from_rgb8(0x4a, 0x90, 0xd9); +/// Border color shared by every styled frame and control. +static BORDER_COLOR: OnceLock> = OnceLock::new(); + +pub fn set_border_color(color: Color) { + let lock = BORDER_COLOR.get_or_init(|| RwLock::new(Color::WHITE)); + + if let Ok(mut current) = lock.write() { + *current = color; + } +} + +pub fn border_color() -> Color { + BORDER_COLOR + .get_or_init(|| RwLock::new(Color::WHITE)) + .read() + .map(|color| *color) + .unwrap_or(Color::WHITE) +} + #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] pub enum Preference { #[default] @@ -156,7 +175,7 @@ pub fn tab_outline(_theme: &Theme, color: Color) -> container::Style { pub fn advanced_frame(_theme: &Theme) -> container::Style { container::Style { border: Border { - color: ADVANCED_BORDER, + color: border_color(), width: 1.0, radius: 6.0.into(), }, @@ -197,11 +216,9 @@ pub fn selected_option(theme: &Theme, _status: button::Status) -> button::Style /// Style for an unselected choice button: outlined so it reads as a button /// rather than a plain text label. pub fn outlined_option(theme: &Theme, status: button::Status) -> button::Style { - let palette = theme.extended_palette(); - button::Style { border: Border { - color: palette.background.strong.color, + color: border_color(), width: 1.0, radius: 4.0.into(), }, @@ -283,18 +300,17 @@ pub fn selectable_row(theme: &Theme, status: button::Status, selected: bool) -> /// Style for filter/text fields: a thicker outline while focused. pub fn filter_field(theme: &Theme, status: text_input::Status) -> text_input::Style { - let palette = theme.extended_palette(); let mut style = text_input::default(theme, status); style.border = if matches!(status, text_input::Status::Focused { .. }) { Border { - color: palette.primary.strong.color, + color: border_color(), width: 2.0, radius: 4.0.into(), } } else { Border { - color: palette.background.strong.color, + color: border_color(), width: 1.0, radius: 4.0.into(), } @@ -310,7 +326,7 @@ pub fn settings_bar(theme: &Theme) -> container::Style { container::Style { background: Some(palette.background.weak.color.into()), border: Border { - color: palette.background.strong.color, + color: border_color(), width: 1.0, radius: Radius { top_left: 6.0, @@ -329,7 +345,7 @@ pub fn settings_frame(theme: &Theme) -> container::Style { container::Style { background: Some(palette.background.base.color.into()), border: Border { - color: palette.background.strong.color, + color: border_color(), width: 1.0, radius: 6.0.into(), },