improv: section descriptions may now be stored as static strings

This commit is contained in:
Michael Aaron Murphy 2024-02-19 04:50:11 +01:00 committed by Michael Murphy
parent 1460ab723d
commit 926692200d
14 changed files with 261 additions and 250 deletions

View file

@ -33,6 +33,11 @@ use super::wallpaper::widgets::color_image;
pub static COLOR_PICKER_DIALOG_ID: Lazy<window::Id> = 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<Config>, ThemeMode, Option<Config>, 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<crate::pages::Message> {
.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::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
@ -1044,7 +1049,7 @@ pub fn mode_and_colors() -> Section<crate::pages::Message> {
.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<crate::pages::Message> {
.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<crate::pages::Message> {
.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<crate::pages::Message> {
.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<crate::pages::Message> {
),
)
.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<crate::pages::Message> {
),
)
.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<crate::pages::Message> {
),
)
.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<crate::pages::Message> {
),
)
.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<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
@ -1282,7 +1287,7 @@ pub fn style() -> Section<crate::pages::Message> {
.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<crate::pages::Message> {
.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<crate::pages::Message> {
.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<crate::pages::Message> {
.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<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
settings::view_section(&section.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<crate::pages::Message> {
#[allow(clippy::too_many_lines)]
pub fn reset_button() -> Section<crate::pages::Message> {
Section::default()
.descriptions(vec![fl!("reset-default")])
.descriptions(vec![fl!("reset-default").into()])
.view::<Page>(|_binder, page, section| {
let spacing = &page.theme_builder.spacing;
let descriptions = &section.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)

View file

@ -126,7 +126,7 @@ impl Default for Page {
pub(crate) fn enable() -> Section<crate::pages::Message> {
Section::default()
.descriptions(vec![fl!("dock")])
.descriptions(vec![fl!("dock").into()])
.view::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
let Some(container_config) = page.inner.container_config.as_ref() else {
@ -134,7 +134,7 @@ pub(crate) fn enable() -> Section<crate::pages::Message> {
};
settings::view_section(&section.title)
.add(settings::item(
&descriptions[0],
&*descriptions[0],
toggler(
None,
container_config

View file

@ -48,24 +48,24 @@ pub fn super_key_action() -> Section<crate::pages::Message> {
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::<Page>(|_binder, _page, section| {
let descriptions = &section.descriptions;
settings::view_section(&section.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<crate::pages::Message> {
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::<Page>(|binder, _page, section| {
let desktop = binder
@ -87,7 +87,7 @@ pub fn window_controls() -> Section<crate::pages::Message> {
settings::view_section(&section.title)
.add(settings::item(
&descriptions[0],
&*descriptions[0],
toggler(
None,
desktop.show_minimize_button,
@ -95,7 +95,7 @@ pub fn window_controls() -> Section<crate::pages::Message> {
),
))
.add(settings::item(
&descriptions[1],
&*descriptions[1],
toggler(
None,
desktop.show_maximize_button,

View file

@ -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::<P>(move |_binder, page, section| {
let descriptions = &section.descriptions;
@ -90,13 +90,13 @@ pub(crate) fn behavior_and_position<
};
settings::view_section(&section.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::<P>(move |_binder, page, section| {
let descriptions = &section.descriptions;
@ -144,19 +144,19 @@ pub(crate) fn style<
};
settings::view_section(&section.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<P: page::Page<crate::pages::Message> + PanelPage>(
) -> Section<crate::pages::Message> {
Section::default()
.title(fl!("panel-applets"))
.descriptions(vec![p.configure_applets_label()])
.descriptions(vec![p.configure_applets_label().into()])
.view::<P>(move |binder, page, section| {
let mut settings = settings::view_section(&section.title);
let descriptions = &section.descriptions;
@ -238,7 +238,7 @@ pub(crate) fn configuration<P: page::Page<crate::pages::Message> + 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::<P>(move |_binder, _page, section| {
// _descriptions = &section.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(),
}
}
}

View file

@ -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<crate::pages::Message> {
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::<Page>(|_binder, page, _section| {
let mut children = Vec::with_capacity(3);

View file

@ -133,21 +133,21 @@ fn multi_behavior() -> Section<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
settings::view_section(&section.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<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
let descriptions = &section.descriptions;
settings::view_section(&section.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)

View file

@ -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<crate::pages::Message> 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::<Page>(|_binder, page, _section| page.graphics_mode_view()),
),
@ -190,8 +190,8 @@ impl page::Page<crate::pages::Message> 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| page.list.outputs.len() > 1)
@ -200,13 +200,13 @@ impl page::Page<crate::pages::Message> 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::<Page>(|_binder, page, _section| page.display_view()),
),

View file

@ -265,8 +265,8 @@ fn special_character_entry() -> Section<crate::pages::Message> {
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::<Page>(|_binder, _page, section| {
let descriptions = &section.descriptions;
@ -274,11 +274,11 @@ fn special_character_entry() -> Section<crate::pages::Message> {
// TODO dialogs
settings::view_section(&section.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<crate::pages::Message> {
fn keyboard_shortcuts() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("keyboard-shortcuts"))
.descriptions(vec![fl!("keyboard-shortcuts", "desc")])
.descriptions(vec![fl!("keyboard-shortcuts", "desc").into()])
.view::<Page>(|binder, _page, section| {
let descriptions = &section.descriptions;
@ -300,7 +300,7 @@ fn keyboard_shortcuts() -> Section<crate::pages::Message> {
.find(|(_, v)| v.id == "keyboard-shortcuts")
{
section = section.add(go_next_item(
&descriptions[0],
&*descriptions[0],
crate::pages::Message::Page(shortcuts_entity),
));
}

View file

@ -40,12 +40,12 @@ impl page::AutoBind<crate::pages::Message> for Page {}
fn mouse() -> Section<crate::pages::Message> {
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::<Page>(|binder, _page, section| {
let descriptions = &section.descriptions;
@ -54,12 +54,12 @@ fn mouse() -> Section<crate::pages::Message> {
settings::view_section(&section.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<crate::pages::Message> {
)),
)
.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<crate::pages::Message> {
),
)
.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<crate::pages::Message> {
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::<Page>(|binder, _page, section| {
let descriptions = &section.descriptions;
@ -110,7 +110,7 @@ fn scrolling() -> Section<crate::pages::Message> {
settings::view_section(&section.title)
.add(settings::item(
&descriptions[0],
&*descriptions[0],
// TODO show numeric value
// TODO desired range?
widget::slider(
@ -128,8 +128,8 @@ fn scrolling() -> Section<crate::pages::Message> {
),
))
.add(
settings::item::builder(&descriptions[1])
.description(&descriptions[2])
settings::item::builder(&*descriptions[1])
.description(&*descriptions[2])
.toggler(
input
.input_default

View file

@ -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<crate::pages::Message> for Page {}
fn touchpad() -> Section<crate::pages::Message> {
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::<Page>(|binder, _page, section| {
let descriptions = &section.descriptions;
let input = binder.page::<super::Page>().expect("input page not found");
settings::view_section(&section.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<crate::pages::Message> {
)),
)
.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<crate::pages::Message> {
)
// 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<crate::pages::Message> {
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::<Page>(|binder, _page, section| {
let descriptions = &section.descriptions;
let input = binder.page::<super::Page>().expect("input page not found");
settings::view_section(&section.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<crate::pages::Message> {
),
))
.add(
settings::item::builder(&descriptions[1])
.description(&descriptions[2])
settings::item::builder(&*MOUSE_SCROLL_NATURAL)
.description(&*MOUSE_SCROLL_NATURAL_DESC)
.toggler(
input
.input_touchpad

View file

@ -51,13 +51,13 @@ fn alerts() -> Section<crate::pages::Message> {
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::<Page>(|_binder, _page, section| {
settings::view_section(&section.title)
.add(settings::item(&section.descriptions[0], text("TODO")))
.add(settings::item(&section.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<crate::pages::Message> {
fn applications() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("sound-applications"))
.descriptions(vec![fl!("sound-applications", "desc")])
.descriptions(vec![fl!("sound-applications", "desc").into()])
.view::<Page>(|_binder, _page, section| {
settings::view_section(&section.title)
.add(settings::item(&section.descriptions[0], text("TODO")))
.add(settings::item(&*section.descriptions[0], text("TODO")))
.into()
})
}
@ -77,15 +77,15 @@ fn input() -> Section<crate::pages::Message> {
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::<Page>(|_binder, _page, section| {
settings::view_section(&section.title)
.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[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<crate::pages::Message> {
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::<Page>(|_binder, _page, section| {
settings::view_section(&section.title)
.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")))
.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()
})
}

View file

@ -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<crate::pages::Message> {
Section::default()
.descriptions(vec![fl!("about-device"), fl!("about-device", "desc")])
.descriptions(vec![
fl!("about-device").into(),
fl!("about-device", "desc").into(),
])
.view::<Page>(|_binder, page, section| {
let desc = &section.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<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
let desc = &section.descriptions;
let mut sections = settings::view_section(&section.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<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
let desc = &section.descriptions;
settings::view_section(&section.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<crate::pages::Message> {
fn related() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("about-related"))
.descriptions(vec![fl!("about-related", "support")])
.descriptions(vec![fl!("about-related", "support").into()])
.view::<Page>(|_binder, _page, section| {
settings::view_section(&section.title)
.add(settings::item(&section.descriptions[0], text("TODO")))
.add(settings::item(&*section.descriptions[0], text("TODO")))
.into()
})
}

View file

@ -61,15 +61,18 @@ impl page::AutoBind<crate::pages::Message> for Page {}
fn date() -> Section<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
settings::view_section(&section.title)
.add(
settings::item::builder(&section.descriptions[0])
settings::item::builder(&*section.descriptions[0])
.toggler(page.auto, Message::Automatic),
)
.add(settings::item(
&section.descriptions[1],
&*section.descriptions[1],
horizontal_space(Length::Fill),
))
.apply(cosmic::Element::from)
@ -81,19 +84,19 @@ fn format() -> Section<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
settings::view_section(&section.title)
// 24-hour toggle
.add(
settings::item::builder(&section.descriptions[0])
settings::item::builder(&*section.descriptions[0])
.toggler(page.military_time, Message::MilitaryTime),
)
// First day of week
.add(settings::item(
&section.descriptions[1],
&*section.descriptions[1],
horizontal_space(Length::Fill),
))
.apply(cosmic::Element::from)
@ -105,21 +108,21 @@ fn timezone() -> Section<crate::pages::Message> {
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::<Page>(|_binder, page, section| {
settings::view_section(&section.title)
// Automatic timezone toggle
.add(
settings::item::builder(&section.descriptions[0])
.description(&section.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(&section.descriptions[2])
settings::item::builder(&*section.descriptions[2])
.control(horizontal_space(Length::Fill)),
)
.apply(cosmic::Element::from)

View file

@ -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<Message> = Box<
pub struct Section<Message> {
#[setters(into)]
pub title: String,
pub descriptions: Vec<String>,
#[setters(into)]
pub descriptions: Vec<Cow<'static, str>>,
#[setters(skip)]
pub show_while: Option<ShowWhileFn<Message>>,
#[setters(skip)]
@ -61,8 +63,8 @@ impl<Message: 'static> Section<Message> {
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;
}
}