From c2f9580eeae723b337db9ece406dd7c262d9c67b Mon Sep 17 00:00:00 2001 From: squid Date: Fri, 6 Nov 2026 22:53:18 +0100 Subject: [PATCH] Added scrollable view in the theme customization --- src/main.rs | 122 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 111 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 96abafe..c476ffc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -663,6 +663,8 @@ struct Moorly { saved_colors: [Color; 5], custom_toasts: bool, toast_colors: [Color; 9], + builtin_custom_toasts: bool, + builtin_toast_colors: [Color; 9], open_color_picker: Option, open_toast_color_picker: Option, fade_animation: Animation, @@ -869,7 +871,7 @@ struct ThemeFile { toast: ToastFile, } -#[derive(Debug, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] struct ToastFile { #[serde(default)] enabled: bool, @@ -1048,6 +1050,8 @@ struct AppearanceConfig { custom_theme: Option, #[serde(default = "default_true")] hide_tab_close: bool, + #[serde(default)] + toast: ToastFile, } impl Default for AppearanceConfig { @@ -1056,6 +1060,7 @@ impl Default for AppearanceConfig { theme: default_theme(), custom_theme: None, hide_tab_close: true, + toast: ToastFile::default(), } } } @@ -1248,8 +1253,8 @@ fn apply_theme_choice(state: &mut Moorly, choice: ThemeChoice) { ThemeChoice::BuiltIn(preference) => { state.theme = *preference; state.colors = builtin_colors(*preference); - state.custom_toasts = false; - state.toast_colors = builtin_toast_colors(*preference); + state.custom_toasts = state.builtin_custom_toasts; + state.toast_colors = state.builtin_toast_colors; } ThemeChoice::Custom { id, .. } => { if let Some(theme) = state.custom_themes.iter().find(|theme| theme.id == *id) { @@ -1348,6 +1353,16 @@ fn load_config() -> ConfigFile { config } +/// Toast customization saved for built-in themes in `config.toml`. +fn builtin_toast_config(appearance: &AppearanceConfig) -> (bool, [Color; 9]) { + let preference = theme::Preference::parse(&appearance.theme).unwrap_or_default(); + + ( + appearance.toast.enabled, + appearance.toast.colors(preference), + ) +} + /// Resolves the saved theme selection to its live theme and colors. fn resolve_theme( appearance: &AppearanceConfig, @@ -1369,13 +1384,14 @@ fn resolve_theme( } let preference = theme::Preference::parse(&appearance.theme).unwrap_or_default(); + let (custom_toasts, toast_colors) = builtin_toast_config(appearance); ( ThemeChoice::BuiltIn(preference), preference, builtin_colors(preference), - false, - builtin_toast_colors(preference), + custom_toasts, + toast_colors, ) } @@ -1428,13 +1444,19 @@ fn undo_settings(state: &mut Moorly) { state.colors = state.saved_colors; let (custom_toasts, toast_colors) = match &state.saved_theme_choice { - ThemeChoice::BuiltIn(preference) => (false, builtin_toast_colors(*preference)), + ThemeChoice::BuiltIn(_) => ( + state.builtin_custom_toasts, + state.builtin_toast_colors, + ), ThemeChoice::Custom { id, .. } => state .custom_themes .iter() .find(|theme| theme.id == *id) .map(|theme| (theme.custom_toasts, theme.toast_colors)) - .unwrap_or_else(|| (false, builtin_toast_colors(state.saved_theme))), + .unwrap_or(( + state.builtin_custom_toasts, + state.builtin_toast_colors, + )), }; state.custom_toasts = custom_toasts; @@ -1442,6 +1464,11 @@ fn undo_settings(state: &mut Moorly) { } fn save_config(state: &Moorly) { + // Never let the unit tests overwrite the developer's real settings. + if cfg!(test) { + return; + } + let Some(path) = config_path() else { return; }; @@ -1471,6 +1498,10 @@ fn config_file(state: &Moorly) -> ConfigFile { ThemeChoice::BuiltIn(_) => None, }, hide_tab_close: state.hide_tab_close, + toast: ToastFile::from_colors( + state.builtin_custom_toasts, + &state.builtin_toast_colors, + ), }, shortcuts: ShortcutConfig { settings: state @@ -1495,6 +1526,8 @@ impl Default for Moorly { let custom_themes = load_custom_themes(); let (theme_choice, theme, colors, custom_toasts, toast_colors) = resolve_theme(&config.appearance, &custom_themes); + let (builtin_custom_toasts, builtin_toast_palette) = + builtin_toast_config(&config.appearance); let show_start_tab = config.startup.show_start_tab; let fade_settings = config.general.fade_settings; let hide_tab_close = config.appearance.hide_tab_close; @@ -1535,6 +1568,8 @@ impl Default for Moorly { saved_colors: colors, custom_toasts, toast_colors, + builtin_custom_toasts, + builtin_toast_colors: builtin_toast_palette, open_color_picker: None, open_toast_color_picker: None, fade_animation: new_fade_animation(), @@ -1858,8 +1893,8 @@ fn update(state: &mut Moorly, message: Message) -> Task { } else { state.theme_choice = ThemeChoice::BuiltIn(state.theme); state.colors = builtin_colors(state.theme); - state.custom_toasts = false; - state.toast_colors = builtin_toast_colors(state.theme); + state.custom_toasts = state.builtin_custom_toasts; + state.toast_colors = state.builtin_toast_colors; if matches!( &state.saved_theme_choice, @@ -1917,6 +1952,11 @@ fn update(state: &mut Moorly, message: Message) -> Task { if !value { state.open_toast_color_picker = None; } + + if matches!(state.theme_choice, ThemeChoice::BuiltIn(_)) { + state.builtin_custom_toasts = value; + save_config(state); + } } Message::OpenColorPicker(option) => { state.open_color_picker = Some(option); @@ -1933,6 +1973,11 @@ fn update(state: &mut Moorly, message: Message) -> Task { Message::SubmitToastColor(option, color) => { state.toast_colors[option.index()] = color; state.open_toast_color_picker = None; + + if matches!(state.theme_choice, ThemeChoice::BuiltIn(_)) { + state.builtin_toast_colors = state.toast_colors; + save_config(state); + } } Message::CancelColorPicker => { state.open_color_picker = None; @@ -3675,7 +3720,14 @@ fn settings_page(state: &Moorly) -> Element<'_, Message> { .height(Length::Fill) .padding(8); - let mut content = column![].spacing(12); + let scrolls = state.settings_section != SettingsSection::Profiles; + + // Leave room for the overlay scrollbar so right-aligned controls do not + // move or get covered when it appears. + let mut content = column![] + .spacing(12) + .width(Length::Fill) + .padding(Padding::ZERO.right(if scrolls { 12.0 } else { 0.0 })); content = content.push(text(state.settings_section.label()).size(18)); if state.settings_section == SettingsSection::General { content = content.push(general_panel(state)); @@ -3693,7 +3745,16 @@ fn settings_page(state: &Moorly) -> Element<'_, Message> { content = content.push(profiles_panel(state, true)); } - let content = container(content) + let body: Element<'_, Message> = if scrolls { + scrollable(content) + .width(Length::Fill) + .height(Length::Fill) + .into() + } else { + content.into() + }; + + let content = container(body) .width(Length::Fill) .height(Length::Fill) .padding(16); @@ -4171,6 +4232,8 @@ mod tests { saved_colors: super::DEFAULT_COLORS, custom_toasts: false, toast_colors: super::builtin_toast_colors(theme::Preference::default()), + builtin_custom_toasts: false, + builtin_toast_colors: super::builtin_toast_colors(theme::Preference::default()), open_color_picker: None, open_toast_color_picker: None, fade_animation: super::new_fade_animation(), @@ -4307,6 +4370,9 @@ mod tests { state.hide_tab_close = false; state.saved_theme = theme::Preference::Dark; state.saved_theme_choice = super::ThemeChoice::BuiltIn(theme::Preference::Dark); + state.builtin_custom_toasts = true; + state.builtin_toast_colors[super::ToastColorOption::Info.index()] = + iced::Color::from_rgb8(1, 2, 3); let text = toml::to_string_pretty(&super::config_file(&state)).unwrap(); let parsed: toml::Value = toml::from_str(&text).unwrap(); @@ -4314,9 +4380,15 @@ mod tests { assert!(text.contains("[general]\nfade_settings = false")); assert!(text.contains("[startup]\nshow_start_tab = false")); assert!(text.contains("[appearance]\ntheme = \"dark\"")); + assert!(text.contains("[appearance.toast]")); assert!(text.contains("[shortcuts]")); assert_eq!(parsed["general"]["fade_settings"].as_bool(), Some(false)); assert_eq!(parsed["appearance"]["theme"].as_str(), Some("dark")); + assert_eq!(parsed["appearance"]["toast"]["enabled"].as_bool(), Some(true)); + assert_eq!( + parsed["appearance"]["toast"]["info"].as_str(), + Some("#010203") + ); assert_eq!(parsed["shortcuts"]["settings"].as_str(), Some("Ctrl+,")); state.saved_theme_choice = super::ThemeChoice::Custom { @@ -4448,6 +4520,11 @@ mod tests { #[test] fn toaster_color_picker_updates_only_toast_colors() { let mut state = state(); + // A custom theme keeps edits out of config.toml and in the theme file. + state.theme_choice = super::ThemeChoice::Custom { + id: "test".to_owned(), + name: "Test".to_owned(), + }; let option = super::ToastColorOption::Info; let color = iced::Color::from_rgb(0.4, 0.5, 0.6); @@ -4464,6 +4541,29 @@ mod tests { assert!(!state.custom_toasts); } + #[test] + fn builtin_toast_config_is_loaded_from_toml() { + let config: super::ConfigFile = toml::from_str( + r##" + [appearance] + theme = "dark" + + [appearance.toast] + enabled = true + info = "#010203" + "##, + ) + .unwrap(); + + let (enabled, colors) = super::builtin_toast_config(&config.appearance); + + assert!(enabled); + assert_eq!( + colors[super::ToastColorOption::Info.index()], + iced::Color::from_rgb8(1, 2, 3) + ); + } + #[test] fn theme_file_round_trips_toast_settings() { let mut toast = super::builtin_toast_colors(theme::Preference::Dark);