From 926692200d0a68aca286d30a59f011da82f90379 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Mon, 19 Feb 2024 04:50:11 +0100 Subject: [PATCH] improv: section descriptions may now be stored as static strings --- app/src/pages/desktop/appearance.rs | 123 +++++++++++++------------ app/src/pages/desktop/dock/mod.rs | 4 +- app/src/pages/desktop/options.rs | 20 ++-- app/src/pages/desktop/panel/inner.rs | 48 +++++----- app/src/pages/desktop/wallpaper/mod.rs | 27 +++--- app/src/pages/desktop/workspaces.rs | 16 ++-- app/src/pages/display/mod.rs | 36 ++++---- app/src/pages/input/keyboard/mod.rs | 12 +-- app/src/pages/input/mouse.rs | 36 ++++---- app/src/pages/input/touchpad.rs | 53 ++++++----- app/src/pages/sound.rs | 42 ++++----- app/src/pages/system/about.rs | 57 ++++++------ app/src/pages/time/date.rs | 29 +++--- page/src/section.rs | 8 +- 14 files changed, 261 insertions(+), 250 deletions(-) diff --git a/app/src/pages/desktop/appearance.rs b/app/src/pages/desktop/appearance.rs index 057e9bc..d4238a2 100644 --- a/app/src/pages/desktop/appearance.rs +++ b/app/src/pages/desktop/appearance.rs @@ -33,6 +33,11 @@ use super::wallpaper::widgets::color_image; pub static COLOR_PICKER_DIALOG_ID: Lazy = Lazy::new(window::Id::unique); +crate::cache_dynamic_lazy! { + static HEX: String = fl!("hex"); + static RGB: String = fl!("rgb"); +} + enum NamedColorPicker { CustomAccent, ApplicationBackground, @@ -116,38 +121,38 @@ impl From<(Option, ThemeMode, Option, ThemeBuilder)> for Page { }, roundness: theme_builder.corner_radii.into(), custom_accent: ColorPickerModel::new( - fl!("hex"), - fl!("rgb"), + &*HEX, + &*RGB, None, custom_accent.map(Color::from), ), application_background: ColorPickerModel::new( - fl!("hex"), - fl!("rgb"), + &*HEX, + &*RGB, Some(theme.background.base.into()), theme_builder.bg_color.map(Color::from), ), container_background: ColorPickerModel::new( - fl!("hex"), - fl!("rgb"), + &*HEX, + &*RGB, None, theme_builder.primary_container_bg.map(Color::from), ), interface_text: ColorPickerModel::new( - fl!("hex"), - fl!("rgb"), + &*HEX, + &*RGB, Some(theme.background.on.into()), theme_builder.text_tint.map(Color::from), ), control_component: ColorPickerModel::new( - fl!("hex"), - fl!("rgb"), + &*HEX, + &*RGB, Some(theme.palette.neutral_5.into()), theme_builder.neutral_tint.map(Color::from), ), accent_window_hint: ColorPickerModel::new( - fl!("hex"), - fl!("rgb"), + &*HEX, + &*RGB, None, theme_builder.window_hint.map(Color::from), ), @@ -634,7 +639,7 @@ impl Page { async { SelectedFiles::open_file() .modal(true) - .filter(FileFilter::glob(FileFilter::new("ron"), "*.ron")) + .filter(FileFilter::glob(FileFilter::new("ron").into(), "*.ron")) .send() .await? .response() @@ -999,29 +1004,29 @@ pub fn mode_and_colors() -> Section { .title(fl!("mode-and-colors")) .descriptions(vec![ // 0 - fl!("auto-switch"), - fl!("auto-switch", "desc"), + fl!("auto-switch").into(), + fl!("auto-switch", "desc").into(), //2 - fl!("accent-color"), + fl!("accent-color").into(), //3 - fl!("app-background"), + fl!("app-background").into(), //4 - fl!("container-background"), - fl!("container-background", "desc"), - fl!("container-background", "desc-detail"), - fl!("container-background", "reset"), + fl!("container-background").into(), + fl!("container-background", "desc").into(), + fl!("container-background", "desc-detail").into(), + fl!("container-background", "reset").into(), // 8 - fl!("text-tint"), - fl!("text-tint", "desc"), + fl!("text-tint").into(), + fl!("text-tint", "desc").into(), // 10 - fl!("control-tint"), - fl!("control-tint", "desc"), + fl!("control-tint").into(), + fl!("control-tint", "desc").into(), // 12 - fl!("window-hint-accent-toggle"), - fl!("window-hint-accent"), + fl!("window-hint-accent-toggle").into(), + fl!("window-hint-accent").into(), // 14 - fl!("dark"), - fl!("light"), + fl!("dark").into(), + fl!("light").into(), ]) .view::(|_binder, page, section| { let descriptions = §ion.descriptions; @@ -1044,7 +1049,7 @@ pub fn mode_and_colors() -> Section { .padding([8, 0]) .selected(page.theme_mode.is_dark) .on_press(Message::DarkMode(true)), - text(&descriptions[14]) + text(&*descriptions[14]) ] .spacing(8) .width(Length::FillPortion(1)) @@ -1059,7 +1064,7 @@ pub fn mode_and_colors() -> Section { .selected(!page.theme_mode.is_dark) .padding([8, 0]) .on_press(Message::DarkMode(false)), - text(&descriptions[15]) + text(&*descriptions[15]) ] .spacing(8) .width(Length::FillPortion(1)) @@ -1073,13 +1078,13 @@ pub fn mode_and_colors() -> Section { .align_x(cosmic::iced_core::alignment::Horizontal::Center), ) .add( - settings::item::builder(&descriptions[0]) - .description(&descriptions[1]) + settings::item::builder(&*descriptions[0]) + .description(&*descriptions[1]) .toggler(page.theme_mode.auto_switch, Message::Autoswitch), ) .add( cosmic::iced::widget::column![ - text(&descriptions[2]), + text(&*descriptions[2]), scrollable( cosmic::iced::widget::row![ color_button( @@ -1175,7 +1180,7 @@ pub fn mode_and_colors() -> Section { .spacing(8), ) .add( - settings::item::builder(&descriptions[3]).control( + settings::item::builder(&*descriptions[3]).control( page.application_background .picker_button(Message::ApplicationBackground, Some(24)) .width(Length::Fixed(48.0)) @@ -1183,8 +1188,8 @@ pub fn mode_and_colors() -> Section { ), ) .add( - settings::item::builder(&descriptions[4]) - .description(&descriptions[5]) + settings::item::builder(&*descriptions[4]) + .description(&*descriptions[5]) .control( if let Some(c) = page.container_background.get_applied_color() { container(color_button( @@ -1208,8 +1213,8 @@ pub fn mode_and_colors() -> Section { ), ) .add( - settings::item::builder(&descriptions[8]) - .description(&descriptions[9]) + settings::item::builder(&*descriptions[8]) + .description(&*descriptions[9]) .control( page.interface_text .picker_button(Message::InterfaceText, Some(24)) @@ -1218,8 +1223,8 @@ pub fn mode_and_colors() -> Section { ), ) .add( - settings::item::builder(&descriptions[10]) - .description(&descriptions[11]) + settings::item::builder(&*descriptions[10]) + .description(&*descriptions[11]) .control( page.control_component .picker_button(Message::ControlComponent, Some(24)) @@ -1228,12 +1233,12 @@ pub fn mode_and_colors() -> Section { ), ) .add( - settings::item::builder(&descriptions[12]) + settings::item::builder(&*descriptions[12]) .toggler(page.no_custom_window_hint, Message::UseDefaultWindowHint), ); if !page.no_custom_window_hint { section = section.add( - settings::item::builder(&descriptions[13]).control( + settings::item::builder(&*descriptions[13]).control( page.accent_window_hint .picker_button(Message::AccentWindowHint, Some(24)) .width(Length::Fixed(48.0)) @@ -1252,11 +1257,11 @@ pub fn style() -> Section { Section::default() .title(fl!("style")) .descriptions(vec![ - fl!("style", "round"), - fl!("style", "slightly-round"), - fl!("style", "square"), - fl!("frosted"), - fl!("frosted", "desc"), + fl!("style", "round").into(), + fl!("style", "slightly-round").into(), + fl!("style", "square").into(), + fl!("frosted").into(), + fl!("frosted", "desc").into(), ]) .view::(|_binder, page, section| { let descriptions = §ion.descriptions; @@ -1282,7 +1287,7 @@ pub fn style() -> Section { .style(button::Style::Image) .padding(8) .on_press(Message::Roundness(Roundness::Round)), - text(&descriptions[0]) + text(&*descriptions[0]) ] .spacing(8) .width(Length::FillPortion(1)) @@ -1304,7 +1309,7 @@ pub fn style() -> Section { .style(button::Style::Image) .padding(8) .on_press(Message::Roundness(Roundness::SlightlyRound)), - text(&descriptions[1]) + text(&*descriptions[1]) ] .spacing(8) .width(Length::FillPortion(1)) @@ -1327,7 +1332,7 @@ pub fn style() -> Section { .style(button::Style::Image) .padding(8) .on_press(Message::Roundness(Roundness::Square)), - text(&descriptions[2]) + text(&*descriptions[2]) ] .spacing(8) .align_items(cosmic::iced_core::Alignment::Center) @@ -1341,8 +1346,8 @@ pub fn style() -> Section { .align_x(cosmic::iced_core::alignment::Horizontal::Center), ) .add( - settings::item::builder(&descriptions[3]) - .description(&descriptions[4]) + settings::item::builder(&*descriptions[3]) + .description(&*descriptions[4]) .toggler(page.theme_builder.is_frosted, Message::Frosted), ) .apply(Element::from) @@ -1355,20 +1360,20 @@ pub fn window_management() -> Section { Section::default() .title(fl!("window-management")) .descriptions(vec![ - fl!("window-management", "active-hint"), - fl!("window-management", "gaps"), + fl!("window-management", "active-hint").into(), + fl!("window-management", "gaps").into(), ]) .view::(|_binder, page, section| { let descriptions = §ion.descriptions; settings::view_section(§ion.title) - .add(settings::item::builder(&descriptions[0]).control( + .add(settings::item::builder(&*descriptions[0]).control( cosmic::widget::spin_button( page.theme_builder.active_hint.to_string(), Message::WindowHintSize, ), )) - .add(settings::item::builder(&descriptions[1]).control( + .add(settings::item::builder(&*descriptions[1]).control( cosmic::widget::spin_button( page.theme_builder.gaps.1.to_string(), Message::GapSize, @@ -1382,12 +1387,12 @@ pub fn window_management() -> Section { #[allow(clippy::too_many_lines)] pub fn reset_button() -> Section { Section::default() - .descriptions(vec![fl!("reset-default")]) + .descriptions(vec![fl!("reset-default").into()]) .view::(|_binder, page, section| { let spacing = &page.theme_builder.spacing; let descriptions = §ion.descriptions; if page.can_reset { - cosmic::iced::widget::row![button(text(&descriptions[0])) + cosmic::iced::widget::row![button(text(&*descriptions[0])) .on_press(Message::Reset) .padding([spacing.space_xxs, spacing.space_xs])] .apply(Element::from) diff --git a/app/src/pages/desktop/dock/mod.rs b/app/src/pages/desktop/dock/mod.rs index 47b64fd..0ccd934 100644 --- a/app/src/pages/desktop/dock/mod.rs +++ b/app/src/pages/desktop/dock/mod.rs @@ -126,7 +126,7 @@ impl Default for Page { pub(crate) fn enable() -> Section { Section::default() - .descriptions(vec![fl!("dock")]) + .descriptions(vec![fl!("dock").into()]) .view::(|_binder, page, section| { let descriptions = §ion.descriptions; let Some(container_config) = page.inner.container_config.as_ref() else { @@ -134,7 +134,7 @@ pub(crate) fn enable() -> Section { }; settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*descriptions[0], toggler( None, container_config diff --git a/app/src/pages/desktop/options.rs b/app/src/pages/desktop/options.rs index afb3ebb..c6ad51a 100644 --- a/app/src/pages/desktop/options.rs +++ b/app/src/pages/desktop/options.rs @@ -48,24 +48,24 @@ pub fn super_key_action() -> Section { Section::default() .title(fl!("super-key-action")) .descriptions(vec![ - fl!("super-key-action", "launcher"), - fl!("super-key-action", "workspaces"), - fl!("super-key-action", "applications"), + fl!("super-key-action", "launcher").into(), + fl!("super-key-action", "workspaces").into(), + fl!("super-key-action", "applications").into(), ]) .view::(|_binder, _page, section| { let descriptions = §ion.descriptions; settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*descriptions[0], horizontal_space(Length::Fill), )) .add(settings::item( - &descriptions[1], + &*descriptions[1], horizontal_space(Length::Fill), )) .add(settings::item( - &descriptions[2], + &*descriptions[2], horizontal_space(Length::Fill), )) .into() @@ -76,8 +76,8 @@ pub fn window_controls() -> Section { Section::default() .title(fl!("window-controls")) .descriptions(vec![ - fl!("window-controls", "minimize"), - fl!("window-controls", "maximize"), + fl!("window-controls", "minimize").into(), + fl!("window-controls", "maximize").into(), ]) .view::(|binder, _page, section| { let desktop = binder @@ -87,7 +87,7 @@ pub fn window_controls() -> Section { settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*descriptions[0], toggler( None, desktop.show_minimize_button, @@ -95,7 +95,7 @@ pub fn window_controls() -> Section { ), )) .add(settings::item( - &descriptions[1], + &*descriptions[1], toggler( None, desktop.show_maximize_button, diff --git a/app/src/pages/desktop/panel/inner.rs b/app/src/pages/desktop/panel/inner.rs index e428332..d04baf0 100644 --- a/app/src/pages/desktop/panel/inner.rs +++ b/app/src/pages/desktop/panel/inner.rs @@ -78,9 +78,9 @@ pub(crate) fn behavior_and_position< Section::default() .title(fl!("panel-behavior-and-position")) .descriptions(vec![ - p.autohide_label(), - fl!("panel-behavior-and-position", "position"), - fl!("panel-behavior-and-position", "display"), + p.autohide_label().into(), + fl!("panel-behavior-and-position", "position").into(), + fl!("panel-behavior-and-position", "display").into(), ]) .view::

(move |_binder, page, section| { let descriptions = §ion.descriptions; @@ -90,13 +90,13 @@ pub(crate) fn behavior_and_position< }; settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*descriptions[0], toggler(None, panel_config.autohide.is_some(), |value| { Message::AutoHidePanel(value) }), )) .add(settings::item( - &descriptions[1], + &*descriptions[1], dropdown( page.anchors.as_slice(), Some(panel_config.anchor as usize), @@ -104,7 +104,7 @@ pub(crate) fn behavior_and_position< ), )) .add(settings::item( - &descriptions[2], + &*descriptions[2], dropdown( page.outputs.as_slice(), match &panel_config.output { @@ -130,11 +130,11 @@ pub(crate) fn style< Section::default() .title(fl!("panel-style")) .descriptions(vec![ - p.gap_label(), - p.extend_label(), - fl!("panel-style", "appearance"), - fl!("panel-style", "size"), - fl!("panel-style", "background-opacity"), + p.gap_label().into(), + p.extend_label().into(), + fl!("panel-style", "appearance").into(), + fl!("panel-style", "size").into(), + fl!("panel-style", "background-opacity").into(), ]) .view::

(move |_binder, page, section| { let descriptions = §ion.descriptions; @@ -144,19 +144,19 @@ pub(crate) fn style< }; settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*descriptions[0], toggler(None, panel_config.anchor_gap, |value| { Message::AnchorGap(value) }), )) .add(settings::item( - &descriptions[1], + &*descriptions[1], toggler(None, panel_config.expand_to_edges, |value| { Message::ExtendToEdge(value) }), )) .add(settings::item( - &descriptions[2], + &*descriptions[2], dropdown( inner.backgrounds.as_slice(), match panel_config.background { @@ -169,7 +169,7 @@ pub(crate) fn style< ), )) .add(settings::item( - &descriptions[3], + &*descriptions[3], // TODO custom discrete slider variant row::with_children(vec![ text(fl!("small")).into(), @@ -202,7 +202,7 @@ pub(crate) fn style< .spacing(12), )) .add(settings::item( - &descriptions[4], + &*descriptions[4], row::with_children(vec![ text(fl!("number", HashMap::from_iter(vec![("number", 0)]))).into(), slider(0..=100, (panel_config.opacity * 100.0) as i32, |v| { @@ -223,7 +223,7 @@ pub(crate) fn configuration + PanelPage>( ) -> Section { Section::default() .title(fl!("panel-applets")) - .descriptions(vec![p.configure_applets_label()]) + .descriptions(vec![p.configure_applets_label().into()]) .view::

(move |binder, page, section| { let mut settings = settings::view_section(§ion.title); let descriptions = §ion.descriptions; @@ -238,7 +238,7 @@ pub(crate) fn configuration + PanelPage>( ]); settings.add( - settings::item::builder(&descriptions[0]) + settings::item::builder(&*descriptions[0]) .control(control) .spacing(16) .apply(container) @@ -265,8 +265,8 @@ pub(crate) fn add_panel< Section::default() .title(fl!("panel-missing")) .descriptions(vec![ - fl!("panel-missing", "desc"), - fl!("panel-missing", "fix"), + fl!("panel-missing", "desc").into(), + fl!("panel-missing", "fix").into(), ]) .view::

(move |_binder, _page, section| { // _descriptions = §ion.descriptions; @@ -282,10 +282,10 @@ pub struct Anchor(PanelAnchor); impl ToString for Anchor { fn to_string(&self) -> String { match self.0 { - PanelAnchor::Top => fl!("panel-top"), - PanelAnchor::Bottom => fl!("panel-bottom"), - PanelAnchor::Left => fl!("panel-left"), - PanelAnchor::Right => fl!("panel-right"), + PanelAnchor::Top => fl!("panel-top").into(), + PanelAnchor::Bottom => fl!("panel-bottom").into(), + PanelAnchor::Left => fl!("panel-left").into(), + PanelAnchor::Right => fl!("panel-right").into(), } } } diff --git a/app/src/pages/desktop/wallpaper/mod.rs b/app/src/pages/desktop/wallpaper/mod.rs index 129ccbe..e886c7e 100644 --- a/app/src/pages/desktop/wallpaper/mod.rs +++ b/app/src/pages/desktop/wallpaper/mod.rs @@ -46,7 +46,7 @@ use cosmic_settings_wallpaper::{self as wallpaper, Entry, ScalingMode}; use image::imageops::FilterType::Lanczos3; use image::{ImageBuffer, Rgba}; use slotmap::{DefaultKey, SecondaryMap, SlotMap}; -use static_init::dynamic; +use std::borrow::Cow; const ZOOM: usize = 0; const FIT: usize = 1; @@ -1056,26 +1056,21 @@ pub async fn change_folder(current_folder: PathBuf) -> Context { update } -#[dynamic] -static WALLPAPER_SAME: String = fl!("wallpaper", "same"); - -#[dynamic] -static WALLPAPER_FIT: String = fl!("wallpaper", "fit"); - -#[dynamic] -static WALLPAPER_SLIDE: String = fl!("wallpaper", "slide"); - -#[dynamic] -static WALLPAPER_CHANGE: String = fl!("wallpaper", "change"); +crate::cache_dynamic_lazy! { + static WALLPAPER_SAME: String = fl!("wallpaper", "same"); + static WALLPAPER_FIT: String = fl!("wallpaper", "fit"); + static WALLPAPER_SLIDE: String = fl!("wallpaper", "slide"); + static WALLPAPER_CHANGE: String = fl!("wallpaper", "change"); +} #[allow(clippy::too_many_lines)] pub fn settings() -> Section { Section::default() .descriptions(vec![ - WALLPAPER_SAME.clone(), - WALLPAPER_FIT.clone(), - WALLPAPER_SLIDE.clone(), - WALLPAPER_CHANGE.clone(), + WALLPAPER_SAME.as_str().into(), + WALLPAPER_FIT.as_str().into(), + WALLPAPER_SLIDE.as_str().into(), + WALLPAPER_CHANGE.as_str().into(), ]) .view::(|_binder, page, _section| { let mut children = Vec::with_capacity(3); diff --git a/app/src/pages/desktop/workspaces.rs b/app/src/pages/desktop/workspaces.rs index 1d2bd5e..ea78eba 100644 --- a/app/src/pages/desktop/workspaces.rs +++ b/app/src/pages/desktop/workspaces.rs @@ -133,21 +133,21 @@ fn multi_behavior() -> Section { Section::default() .title(fl!("workspaces-multi-behavior")) .descriptions(vec![ - fl!("workspaces-multi-behavior", "span"), - fl!("workspaces-multi-behavior", "separate"), + fl!("workspaces-multi-behavior", "span").into(), + fl!("workspaces-multi-behavior", "separate").into(), ]) .view::(|_binder, page, section| { let descriptions = §ion.descriptions; settings::view_section(§ion.title) .add(settings::item_row(vec![radio( - &descriptions[0], + &*descriptions[0], WorkspaceMode::Global, Some(page.comp_workspace_config.workspace_mode), Message::SetWorkspaceMode, ) .into()])) .add(settings::item_row(vec![radio( - &descriptions[1], + &*descriptions[1], WorkspaceMode::OutputBound, Some(page.comp_workspace_config.workspace_mode), Message::SetWorkspaceMode, @@ -162,18 +162,18 @@ fn overview_thumbnails() -> Section { Section::default() .title(fl!("workspaces-overview-thumbnails")) .descriptions(vec![ - fl!("workspaces-overview-thumbnails", "show-number"), - fl!("workspaces-overview-thumbnails", "show-name"), + fl!("workspaces-overview-thumbnails", "show-number").into(), + fl!("workspaces-overview-thumbnails", "show-name").into(), ]) .view::(|_binder, page, section| { let descriptions = §ion.descriptions; settings::view_section(§ion.title) .add( - settings::item::builder(&descriptions[0]) + settings::item::builder(&*descriptions[0]) .toggler(page.show_workspace_number, Message::SetShowNumber), ) .add( - settings::item::builder(&descriptions[1]) + settings::item::builder(&*descriptions[1]) .toggler(page.show_workspace_name, Message::SetShowName), ) .apply(Element::from) diff --git a/app/src/pages/display/mod.rs b/app/src/pages/display/mod.rs index fafaedb..ee568e8 100644 --- a/app/src/pages/display/mod.rs +++ b/app/src/pages/display/mod.rs @@ -10,7 +10,6 @@ use apply::Apply; use arrangement::Arrangement; use cosmic::iced::Length; use cosmic::iced_widget::scrollable::{Direction, Properties, RelativeOffset}; -use cosmic::prelude::CollectionWidget; use cosmic::widget::{ column, container, dropdown, list_column, segmented_button, toggler, view_switcher, }; @@ -18,6 +17,7 @@ use cosmic::{command, Command, Element}; use cosmic_randr_shell::{List, Output, OutputKey, Transform}; use cosmic_settings_page::{self as page, section, Section}; use slotmap::{Key, SlotMap}; +use std::borrow::Cow; use std::collections::BTreeMap; use std::{process::ExitStatus, sync::Arc}; @@ -174,14 +174,14 @@ impl page::Page for Page { sections.insert( Section::default() .descriptions(vec![ - text::GRAPHICS_MODE.clone(), - text::GRAPHICS_MODE_COMPUTE_DESC.clone(), - text::GRAPHICS_MODE_HYBRID_DESC.clone(), - text::GRAPHICS_MODE_INTEGRATED_DESC.clone(), - text::GRAPHICS_MODE_NVIDIA_DESC.clone(), - text::NIGHT_LIGHT.clone(), - text::NIGHT_LIGHT_AUTO.clone(), - text::NIGHT_LIGHT_DESCRIPTION.clone(), + text::GRAPHICS_MODE.as_str().into(), + text::GRAPHICS_MODE_COMPUTE_DESC.as_str().into(), + text::GRAPHICS_MODE_HYBRID_DESC.as_str().into(), + text::GRAPHICS_MODE_INTEGRATED_DESC.as_str().into(), + text::GRAPHICS_MODE_NVIDIA_DESC.as_str().into(), + text::NIGHT_LIGHT.as_str().into(), + text::NIGHT_LIGHT_AUTO.as_str().into(), + text::NIGHT_LIGHT_DESCRIPTION.as_str().into(), ]) .view::(|_binder, page, _section| page.graphics_mode_view()), ), @@ -190,8 +190,8 @@ impl page::Page for Page { Section::default() .title(&*text::DISPLAY_ARRANGEMENT) .descriptions(vec![ - text::DISPLAY_ARRANGEMENT.clone(), - text::DISPLAY_ARRANGEMENT_DESC.clone(), + text::DISPLAY_ARRANGEMENT.as_str().into(), + text::DISPLAY_ARRANGEMENT_DESC.as_str().into(), ]) // Show section when there is more than 1 display .show_while::(|page| page.list.outputs.len() > 1) @@ -200,13 +200,13 @@ impl page::Page for Page { // Display configuration sections.insert( Section::default() - .descriptions(vec![ - text::DISPLAY.clone(), - text::DISPLAY_REFRESH_RATE.clone(), - text::DISPLAY_SCALE.clone(), - text::ORIENTATION.clone(), - text::ORIENTATION_LANDSCAPE.clone(), - text::ORIENTATION_PORTRAIT.clone(), + .descriptions([ + text::DISPLAY.as_str().into(), + text::DISPLAY_REFRESH_RATE.as_str().into(), + text::DISPLAY_SCALE.as_str().into(), + text::ORIENTATION.as_str().into(), + text::ORIENTATION_LANDSCAPE.as_str().into(), + text::ORIENTATION_PORTRAIT.as_str().into(), ]) .view::(|_binder, page, _section| page.display_view()), ), diff --git a/app/src/pages/input/keyboard/mod.rs b/app/src/pages/input/keyboard/mod.rs index 2ddac4a..92af960 100644 --- a/app/src/pages/input/keyboard/mod.rs +++ b/app/src/pages/input/keyboard/mod.rs @@ -265,8 +265,8 @@ fn special_character_entry() -> Section { Section::default() .title(fl!("keyboard-special-char")) .descriptions(vec![ - fl!("keyboard-special-char", "alternate"), - fl!("keyboard-special-char", "compose"), + fl!("keyboard-special-char", "alternate").into(), + fl!("keyboard-special-char", "compose").into(), ]) .view::(|_binder, _page, section| { let descriptions = §ion.descriptions; @@ -274,11 +274,11 @@ fn special_character_entry() -> Section { // TODO dialogs settings::view_section(§ion.title) .add(go_next_item( - &descriptions[0], + &*descriptions[0], Message::OpenSpecialCharacterDialog(SpecialKey::AlternateCharacters), )) .add(go_next_item( - &descriptions[1], + &*descriptions[1], Message::OpenSpecialCharacterDialog(SpecialKey::Compose), )) .apply(cosmic::Element::from) @@ -289,7 +289,7 @@ fn special_character_entry() -> Section { fn keyboard_shortcuts() -> Section { Section::default() .title(fl!("keyboard-shortcuts")) - .descriptions(vec![fl!("keyboard-shortcuts", "desc")]) + .descriptions(vec![fl!("keyboard-shortcuts", "desc").into()]) .view::(|binder, _page, section| { let descriptions = §ion.descriptions; @@ -300,7 +300,7 @@ fn keyboard_shortcuts() -> Section { .find(|(_, v)| v.id == "keyboard-shortcuts") { section = section.add(go_next_item( - &descriptions[0], + &*descriptions[0], crate::pages::Message::Page(shortcuts_entity), )); } diff --git a/app/src/pages/input/mouse.rs b/app/src/pages/input/mouse.rs index da01172..8787d24 100644 --- a/app/src/pages/input/mouse.rs +++ b/app/src/pages/input/mouse.rs @@ -40,12 +40,12 @@ impl page::AutoBind for Page {} fn mouse() -> Section { Section::default() .descriptions(vec![ - fl!("mouse", "primary-button"), - fl!("mouse", "speed"), - fl!("mouse", "acceleration"), - fl!("mouse", "acceleration-desc"), - fl!("mouse", "double-click-speed"), - fl!("mouse", "double-click-speed-desc"), + fl!("mouse", "primary-button").into(), + fl!("mouse", "speed").into(), + fl!("mouse", "acceleration").into(), + fl!("mouse", "acceleration-desc").into(), + fl!("mouse", "double-click-speed").into(), + fl!("mouse", "double-click-speed-desc").into(), ]) .view::(|binder, _page, section| { let descriptions = §ion.descriptions; @@ -54,12 +54,12 @@ fn mouse() -> Section { settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*descriptions[0], cosmic::widget::segmented_selection::horizontal(&input.primary_button) .on_activate(|x| Message::PrimaryButtonSelected(x, false)), )) .add( - settings::item::builder(&descriptions[1]).control(widget::slider( + settings::item::builder(&*descriptions[1]).control(widget::slider( 0.0..=100.0, (input .input_default @@ -72,8 +72,8 @@ fn mouse() -> Section { )), ) .add( - settings::item::builder(&descriptions[2]) - .description(&descriptions[3]) + settings::item::builder(&*descriptions[2]) + .description(&*descriptions[3]) .toggler( input .input_default @@ -84,8 +84,8 @@ fn mouse() -> Section { ), ) .add( - settings::item::builder(&descriptions[4]) - .description(&descriptions[5]) + settings::item::builder(&*descriptions[4]) + .description(&*descriptions[5]) .control(widget::slider(0..=100, 0, |x| { Message::SetDoubleClickSpeed(x, false) })), @@ -99,9 +99,9 @@ fn scrolling() -> Section { Section::default() .title(fl!("mouse-scrolling")) .descriptions(vec![ - fl!("mouse-scrolling", "speed"), - fl!("mouse-scrolling", "natural"), - fl!("mouse-scrolling", "natural-desc"), + fl!("mouse-scrolling", "speed").into(), + fl!("mouse-scrolling", "natural").into(), + fl!("mouse-scrolling", "natural-desc").into(), ]) .view::(|binder, _page, section| { let descriptions = §ion.descriptions; @@ -110,7 +110,7 @@ fn scrolling() -> Section { settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*descriptions[0], // TODO show numeric value // TODO desired range? widget::slider( @@ -128,8 +128,8 @@ fn scrolling() -> Section { ), )) .add( - settings::item::builder(&descriptions[1]) - .description(&descriptions[2]) + settings::item::builder(&*descriptions[1]) + .description(&*descriptions[2]) .toggler( input .input_default diff --git a/app/src/pages/input/touchpad.rs b/app/src/pages/input/touchpad.rs index 951ecd8..ac62773 100644 --- a/app/src/pages/input/touchpad.rs +++ b/app/src/pages/input/touchpad.rs @@ -5,9 +5,22 @@ use cosmic_comp_config::input::AccelProfile; use cosmic_settings_page::Section; use cosmic_settings_page::{self as page, section}; use slotmap::SlotMap; +use std::borrow::Cow; use super::Message; +crate::cache_dynamic_lazy! { + static MOUSE_SCROLL_SPEED: String = fl!("mouse-scrolling", "speed"); + static MOUSE_SCROLL_NATURAL: String = fl!("mouse-scrolling", "natural"); + static MOUSE_SCROLL_NATURAL_DESC: String = fl!("mouse-scrolling", "natural-desc"); + static TOUCHPAD_PRIMARY_BUTTON: String = fl!("touchpad", "primary-button"); + static TOUCHPAD_SPEED: String = fl!("touchpad", "speed"); + static TOUCHPAD_ACCELERAION: String = fl!("touchpad", "acceleration"); + static TOUCHPAD_ACCELERAION_DESC: String = fl!("touchpad", "acceleration-desc"); + static TOUCHPAD_DOUBLE_CLICK_SPEED: String = fl!("touchpad", "double-click-speed"); + static TOUCHPAD_DOUBLE_CLICK_SPEED_DESC: String = fl!("touchpad", "double-click-speed-desc"); +} + #[derive(Default)] pub struct Page; @@ -34,26 +47,24 @@ impl page::AutoBind for Page {} fn touchpad() -> Section { Section::default() .descriptions(vec![ - fl!("touchpad", "primary-button"), - fl!("touchpad", "speed"), - fl!("touchpad", "acceleration"), - fl!("touchpad", "acceleration-desc"), - fl!("touchpad", "double-click-speed"), - fl!("touchpad", "double-click-speed-desc"), + TOUCHPAD_PRIMARY_BUTTON.as_str().into(), + TOUCHPAD_SPEED.as_str().into(), + TOUCHPAD_ACCELERAION.as_str().into(), + TOUCHPAD_ACCELERAION_DESC.as_str().into(), + TOUCHPAD_DOUBLE_CLICK_SPEED.as_str().into(), + TOUCHPAD_DOUBLE_CLICK_SPEED_DESC.as_str().into(), ]) .view::(|binder, _page, section| { - let descriptions = §ion.descriptions; - let input = binder.page::().expect("input page not found"); settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*TOUCHPAD_PRIMARY_BUTTON, cosmic::widget::segmented_selection::horizontal(&input.touchpad_primary_button) .on_activate(|x| Message::PrimaryButtonSelected(x, true)), )) .add( - settings::item::builder(&descriptions[1]).control(widget::slider( + settings::item::builder(&*TOUCHPAD_SPEED).control(widget::slider( 0.0..=100.0, (input .input_touchpad @@ -66,8 +77,8 @@ fn touchpad() -> Section { )), ) .add( - settings::item::builder(&descriptions[2]) - .description(&descriptions[3]) + settings::item::builder(&*TOUCHPAD_ACCELERAION) + .description(&*TOUCHPAD_ACCELERAION_DESC) .toggler( input .input_touchpad @@ -79,8 +90,8 @@ fn touchpad() -> Section { ) // TODO disable while typing .add( - settings::item::builder(&descriptions[4]) - .description(&descriptions[5]) + settings::item::builder(&*TOUCHPAD_DOUBLE_CLICK_SPEED) + .description(&*TOUCHPAD_DOUBLE_CLICK_SPEED_DESC) .control(widget::slider(0..=100, 0, |x| { Message::SetDoubleClickSpeed(x, true) })), @@ -94,18 +105,16 @@ fn scrolling() -> Section { Section::default() .title(fl!("mouse-scrolling")) .descriptions(vec![ - fl!("mouse-scrolling", "speed"), - fl!("mouse-scrolling", "natural"), - fl!("mouse-scrolling", "natural-desc"), + MOUSE_SCROLL_SPEED.as_str().into(), + MOUSE_SCROLL_NATURAL.as_str().into(), + MOUSE_SCROLL_NATURAL_DESC.as_str().into(), ]) .view::(|binder, _page, section| { - let descriptions = §ion.descriptions; - let input = binder.page::().expect("input page not found"); settings::view_section(§ion.title) .add(settings::item( - &descriptions[0], + &*MOUSE_SCROLL_SPEED, // TODO show numeric value // TODO desired range? widget::slider( @@ -123,8 +132,8 @@ fn scrolling() -> Section { ), )) .add( - settings::item::builder(&descriptions[1]) - .description(&descriptions[2]) + settings::item::builder(&*MOUSE_SCROLL_NATURAL) + .description(&*MOUSE_SCROLL_NATURAL_DESC) .toggler( input .input_touchpad diff --git a/app/src/pages/sound.rs b/app/src/pages/sound.rs index 0a03627..c265138 100644 --- a/app/src/pages/sound.rs +++ b/app/src/pages/sound.rs @@ -51,13 +51,13 @@ fn alerts() -> Section { Section::default() .title(fl!("sound-alerts")) .descriptions(vec![ - fl!("sound-alerts", "volume"), - fl!("sound-alerts", "sound"), + fl!("sound-alerts", "volume").into(), + fl!("sound-alerts", "sound").into(), ]) .view::(|_binder, _page, section| { settings::view_section(§ion.title) - .add(settings::item(§ion.descriptions[0], text("TODO"))) - .add(settings::item(§ion.descriptions[1], text("TODO"))) + .add(settings::item(&*section.descriptions[0], text("TODO"))) + .add(settings::item(&*section.descriptions[1], text("TODO"))) .into() }) } @@ -65,10 +65,10 @@ fn alerts() -> Section { fn applications() -> Section { Section::default() .title(fl!("sound-applications")) - .descriptions(vec![fl!("sound-applications", "desc")]) + .descriptions(vec![fl!("sound-applications", "desc").into()]) .view::(|_binder, _page, section| { settings::view_section(§ion.title) - .add(settings::item(§ion.descriptions[0], text("TODO"))) + .add(settings::item(&*section.descriptions[0], text("TODO"))) .into() }) } @@ -77,15 +77,15 @@ fn input() -> Section { Section::default() .title(fl!("sound-input")) .descriptions(vec![ - fl!("sound-input", "volume"), - fl!("sound-input", "device"), - fl!("sound-input", "level"), + fl!("sound-input", "volume").into(), + fl!("sound-input", "device").into(), + fl!("sound-input", "level").into(), ]) .view::(|_binder, _page, section| { settings::view_section(§ion.title) - .add(settings::item(§ion.descriptions[0], text("TODO"))) - .add(settings::item(§ion.descriptions[1], text("TODO"))) - .add(settings::item(§ion.descriptions[2], text("TODO"))) + .add(settings::item(&*section.descriptions[0], text("TODO"))) + .add(settings::item(&*section.descriptions[1], text("TODO"))) + .add(settings::item(&*section.descriptions[2], text("TODO"))) .into() }) } @@ -94,18 +94,18 @@ fn output() -> Section { Section::default() .title(fl!("sound-output")) .descriptions(vec![ - fl!("sound-output", "volume"), - fl!("sound-output", "device"), - fl!("sound-output", "level"), - fl!("sound-output", "config"), - fl!("sound-output", "balance"), + fl!("sound-output", "volume").into(), + fl!("sound-output", "device").into(), + fl!("sound-output", "level").into(), + fl!("sound-output", "config").into(), + fl!("sound-output", "balance").into(), ]) .view::(|_binder, _page, section| { settings::view_section(§ion.title) - .add(settings::item(§ion.descriptions[0], text("TODO"))) - .add(settings::item(§ion.descriptions[1], text("TODO"))) - .add(settings::item(§ion.descriptions[2], text("TODO"))) - .add(settings::item(§ion.descriptions[3], text("TODO"))) + .add(settings::item(&*section.descriptions[0], text("TODO"))) + .add(settings::item(&*section.descriptions[1], text("TODO"))) + .add(settings::item(&*section.descriptions[2], text("TODO"))) + .add(settings::item(&*section.descriptions[3], text("TODO"))) .into() }) } diff --git a/app/src/pages/system/about.rs b/app/src/pages/system/about.rs index a265fc1..8e33035 100644 --- a/app/src/pages/system/about.rs +++ b/app/src/pages/system/about.rs @@ -3,14 +3,8 @@ use cosmic_settings_page::{self as page, section, Section}; +use cosmic::widget::{list_column, settings, text}; use cosmic::{command, Command}; -use cosmic::{ - iced::{ - widget::{horizontal_space, row}, - Length, - }, - widget::{icon, list_column, settings, text}, -}; use cosmic_settings_system::about::Info; use slotmap::SlotMap; @@ -63,11 +57,14 @@ impl Page { fn device() -> Section { Section::default() - .descriptions(vec![fl!("about-device"), fl!("about-device", "desc")]) + .descriptions(vec![ + fl!("about-device").into(), + fl!("about-device", "desc").into(), + ]) .view::(|_binder, page, section| { let desc = §ion.descriptions; - let device_name = settings::item::builder(&desc[0]) - .description(&desc[1]) + let device_name = settings::item::builder(&*desc[0]) + .description(&*desc[1]) .control(text(&page.info.device_name)); list_column().add(device_name).into() @@ -78,26 +75,26 @@ fn hardware() -> Section { Section::default() .title(fl!("about-hardware")) .descriptions(vec![ - fl!("about-hardware", "model"), - fl!("about-hardware", "memory"), - fl!("about-hardware", "processor"), - fl!("about-hardware", "graphics"), - fl!("about-hardware", "disk-capacity"), + fl!("about-hardware", "model").into(), + fl!("about-hardware", "memory").into(), + fl!("about-hardware", "processor").into(), + fl!("about-hardware", "graphics").into(), + fl!("about-hardware", "disk-capacity").into(), ]) .view::(|_binder, page, section| { let desc = §ion.descriptions; let mut sections = settings::view_section(§ion.title) - .add(settings::item(&desc[0], text(&page.info.hardware_model))) - .add(settings::item(&desc[1], text(&page.info.memory))) - .add(settings::item(&desc[2], text(&page.info.processor))); + .add(settings::item(&*desc[0], text(&page.info.hardware_model))) + .add(settings::item(&*desc[1], text(&page.info.memory))) + .add(settings::item(&*desc[2], text(&page.info.processor))); for card in &page.info.graphics { - sections = sections.add(settings::item(&desc[3], text(card.as_str()))); + sections = sections.add(settings::item(&*desc[3], text(card.as_str()))); } sections - .add(settings::item(&desc[4], text(&page.info.disk_capacity))) + .add(settings::item(&*desc[4], text(&page.info.disk_capacity))) .into() }) } @@ -106,21 +103,21 @@ fn os() -> Section { Section::default() .title(fl!("about-os")) .descriptions(vec![ - fl!("about-os", "os"), - fl!("about-os", "os-architecture"), - fl!("about-os", "desktop-environment"), - fl!("about-os", "windowing-system"), + fl!("about-os", "os").into(), + fl!("about-os", "os-architecture").into(), + fl!("about-os", "desktop-environment").into(), + fl!("about-os", "windowing-system").into(), ]) .view::(|_binder, page, section| { let desc = §ion.descriptions; settings::view_section(§ion.title) - .add(settings::item(&desc[0], text(&page.info.operating_system))) - .add(settings::item(&desc[1], text(&page.info.os_architecture))) + .add(settings::item(&*desc[0], text(&page.info.operating_system))) + .add(settings::item(&*desc[1], text(&page.info.os_architecture))) .add(settings::item( - &desc[2], + &*desc[2], text(&page.info.desktop_environment), )) - .add(settings::item(&desc[3], text(&page.info.windowing_system))) + .add(settings::item(&*desc[3], text(&page.info.windowing_system))) .into() }) } @@ -128,10 +125,10 @@ fn os() -> Section { fn related() -> Section { Section::default() .title(fl!("about-related")) - .descriptions(vec![fl!("about-related", "support")]) + .descriptions(vec![fl!("about-related", "support").into()]) .view::(|_binder, _page, section| { settings::view_section(§ion.title) - .add(settings::item(§ion.descriptions[0], text("TODO"))) + .add(settings::item(&*section.descriptions[0], text("TODO"))) .into() }) } diff --git a/app/src/pages/time/date.rs b/app/src/pages/time/date.rs index de00850..004508c 100644 --- a/app/src/pages/time/date.rs +++ b/app/src/pages/time/date.rs @@ -61,15 +61,18 @@ impl page::AutoBind for Page {} fn date() -> Section { Section::default() .title(fl!("time-date")) - .descriptions(vec![fl!("time-date", "auto"), fl!("time-date")]) + .descriptions(vec![ + fl!("time-date", "auto").into(), + fl!("time-date").into(), + ]) .view::(|_binder, page, section| { settings::view_section(§ion.title) .add( - settings::item::builder(§ion.descriptions[0]) + settings::item::builder(&*section.descriptions[0]) .toggler(page.auto, Message::Automatic), ) .add(settings::item( - §ion.descriptions[1], + &*section.descriptions[1], horizontal_space(Length::Fill), )) .apply(cosmic::Element::from) @@ -81,19 +84,19 @@ fn format() -> Section { Section::default() .title(fl!("time-format")) .descriptions(vec![ - fl!("time-format", "twenty-four"), - fl!("time-format", "first"), + fl!("time-format", "twenty-four").into(), + fl!("time-format", "first").into(), ]) .view::(|_binder, page, section| { settings::view_section(§ion.title) // 24-hour toggle .add( - settings::item::builder(§ion.descriptions[0]) + settings::item::builder(&*section.descriptions[0]) .toggler(page.military_time, Message::MilitaryTime), ) // First day of week .add(settings::item( - §ion.descriptions[1], + &*section.descriptions[1], horizontal_space(Length::Fill), )) .apply(cosmic::Element::from) @@ -105,21 +108,21 @@ fn timezone() -> Section { Section::default() .title(fl!("time-zone")) .descriptions(vec![ - fl!("time-zone", "auto"), - fl!("time-zone", "auto-info"), - fl!("time-zone"), + fl!("time-zone", "auto").into(), + fl!("time-zone", "auto-info").into(), + fl!("time-zone").into(), ]) .view::(|_binder, page, section| { settings::view_section(§ion.title) // Automatic timezone toggle .add( - settings::item::builder(§ion.descriptions[0]) - .description(§ion.descriptions[1]) + settings::item::builder(&*section.descriptions[0]) + .description(&*section.descriptions[1]) .toggler(page.auto_timezone, Message::AutomaticTimezone), ) // Time zone select .add( - settings::item::builder(§ion.descriptions[2]) + settings::item::builder(&*section.descriptions[2]) .control(horizontal_space(Length::Fill)), ) .apply(cosmic::Element::from) diff --git a/page/src/section.rs b/page/src/section.rs index 6d75b08..335eb84 100644 --- a/page/src/section.rs +++ b/page/src/section.rs @@ -3,6 +3,7 @@ use derive_setters::Setters; use regex::Regex; +use std::borrow::Cow; use crate::{Binder, Page}; @@ -29,7 +30,8 @@ pub type ViewFn = Box< pub struct Section { #[setters(into)] pub title: String, - pub descriptions: Vec, + #[setters(into)] + pub descriptions: Vec>, #[setters(skip)] pub show_while: Option>, #[setters(skip)] @@ -61,8 +63,8 @@ impl Section { return true; } - for description in &self.descriptions { - if rule.is_match(description.as_str()) { + for description in &*self.descriptions { + if rule.is_match(description) { return true; } }