fix(accessibility): use popup_dropdown

This commit is contained in:
Vukašin Vojinović 2025-03-26 17:01:57 +01:00 committed by Michael Murphy
parent 81aa5413e5
commit 486b4b9cad
21 changed files with 160 additions and 144 deletions

View file

@ -2,24 +2,23 @@ use std::collections::HashSet;
use std::fmt::Write;
use cosmic::{
Apply,
iced::{Element, Length},
iced_core::text::Wrapping,
surface,
widget::{self, icon, settings, svg, text},
Apply,
};
use cosmic_comp_config::{ZoomConfig, ZoomMovement};
use cosmic_config::{ConfigGet, ConfigSet};
use cosmic_settings_config::{shortcuts, Action, Binding};
use cosmic_settings_config::{Action, Binding, shortcuts};
use cosmic_settings_page::{
self as page,
self as page, Entity,
section::{self, Section},
Entity,
};
use slotmap::SlotMap;
use tracing::error;
use super::{wayland, AccessibilityEvent, AccessibilityRequest};
use super::{AccessibilityEvent, AccessibilityRequest, wayland};
#[derive(Debug)]
pub struct Page {
@ -254,10 +253,12 @@ pub fn tip() -> section::Section<crate::pages::Message> {
.view::<Page>(move |_binder, _page, section| {
let descriptions = &section.descriptions;
let mut items = vec![text::body(&descriptions[applet])
.wrapping(Wrapping::Word)
.width(Length::Shrink)
.into()];
let mut items = vec![
text::body(&descriptions[applet])
.wrapping(Wrapping::Word)
.width(Length::Shrink)
.into(),
];
if let Some(illustration) = applet_illustration.clone() {
items.push(svg(illustration).width(Length::Fill).into());
}
@ -283,30 +284,36 @@ pub fn view_movement() -> section::Section<crate::pages::Message> {
settings::section()
.title(&section.title)
.add(widget::settings::item_row(vec![widget::radio(
text::body(&descriptions[continuous]),
ZoomMovement::Continuously,
Some(page.zoom_config.view_moves),
Message::SetMovement,
)
.width(Length::Fill)
.into()]))
.add(widget::settings::item_row(vec![widget::radio(
text::body(&descriptions[onedge]),
ZoomMovement::OnEdge,
Some(page.zoom_config.view_moves),
Message::SetMovement,
)
.width(Length::Fill)
.into()]))
.add(widget::settings::item_row(vec![widget::radio(
text::body(&descriptions[centered]),
ZoomMovement::Centered,
Some(page.zoom_config.view_moves),
Message::SetMovement,
)
.width(Length::Fill)
.into()]))
.add(widget::settings::item_row(vec![
widget::radio(
text::body(&descriptions[continuous]),
ZoomMovement::Continuously,
Some(page.zoom_config.view_moves),
Message::SetMovement,
)
.width(Length::Fill)
.into(),
]))
.add(widget::settings::item_row(vec![
widget::radio(
text::body(&descriptions[onedge]),
ZoomMovement::OnEdge,
Some(page.zoom_config.view_moves),
Message::SetMovement,
)
.width(Length::Fill)
.into(),
]))
.add(widget::settings::item_row(vec![
widget::radio(
text::body(&descriptions[centered]),
ZoomMovement::Centered,
Some(page.zoom_config.view_moves),
Message::SetMovement,
)
.width(Length::Fill)
.into(),
]))
.apply(Element::from)
.map(crate::pages::Message::AccessibilityMagnifier)
})

View file

@ -1,9 +1,10 @@
use cosmic::{
Apply, Task,
Task,
cosmic_theme::{CosmicPalette, ThemeBuilder},
iced_core::text::Wrapping,
theme::{self, CosmicTheme},
widget::{button, container, dropdown, horizontal_space, icon, settings, text, toggler},
surface,
theme::CosmicTheme,
widget::{dropdown, settings, text, toggler},
};
pub use cosmic_comp_config::ZoomMovement;
use cosmic_config::CosmicConfigEntry;
@ -68,6 +69,7 @@ pub enum Message {
SetScreenInverted(bool),
SetScreenFilterActive(bool),
SetScreenFilterSelection(ColorFilter),
Surface(surface::Action),
}
impl page::Page<crate::pages::Message> for Page {
@ -178,19 +180,9 @@ pub fn vision() -> section::Section<crate::pages::Message> {
&descriptions[unavailable]
};
settings::item_row(vec![
text::body(&descriptions[magnifier])
.wrapping(Wrapping::Word)
.into(),
horizontal_space().into(),
text::body(status_text).wrapping(Wrapping::Word).into(),
icon::from_name("go-next-symbolic").size(16).into(),
])
.apply(container)
.class(cosmic::theme::Container::List)
.apply(button::custom)
.class(theme::Button::Transparent)
.on_press_maybe(
crate::widget::go_next_with_item(
&descriptions[magnifier],
text::body(status_text).wrapping(Wrapping::Word),
page.wayland_available
.is_some()
.then_some(crate::pages::Message::Page(magnifier_entity)),
@ -235,13 +227,20 @@ pub fn vision() -> section::Section<crate::pages::Message> {
};
cosmic::Element::from(
settings::item::builder(&descriptions[color_filter_type]).control(
dropdown(
dropdown::popup_dropdown(
selections,
Some(page.screen_filter_selection as usize),
move |idx| {
let filter = ColorFilter::from_usize(idx).unwrap_or_default();
Message::SetScreenFilterSelection(filter)
},
cosmic::iced::window::Id::RESERVED,
Message::Surface,
|a| {
crate::app::Message::PageMessage(
crate::pages::Message::Accessibility(a),
)
},
),
),
)
@ -361,6 +360,9 @@ impl Page {
self.screen_filter_selection = filter;
}
}
Message::Surface(a) => {
return cosmic::task::message(crate::app::Message::Surface(a));
}
}
cosmic::iced::Task::none()

View file

@ -1,6 +1,6 @@
use cosmic::iced::{Alignment, Length};
use cosmic::widget::{button, icon, settings, text};
use cosmic::{widget, Apply, Element, Task};
use cosmic::{Apply, Element, Task, widget};
use cosmic_settings_page::section::Entity;
use cosmic_settings_page::{self as page, Content, Info, Section};
use freedesktop_desktop_entry::DesktopEntry;
@ -66,9 +66,11 @@ enum Context {
impl Into<Vec<PathBuf>> for DirectoryType {
fn into(self) -> Vec<PathBuf> {
match self {
DirectoryType::User => vec![dirs::config_dir()
.expect("config dir not found")
.join("autostart")],
DirectoryType::User => vec![
dirs::config_dir()
.expect("config dir not found")
.join("autostart"),
],
}
}
}
@ -309,7 +311,7 @@ impl Page {
) -> Element<'_, crate::pages::Message> {
let cosmic::cosmic_theme::Spacing {
space_s, space_l, ..
} = cosmic::theme::active().cosmic().spacing;
} = cosmic::theme::spacing();
let search = widget::search_input(fl!("type-to-search"), &self.application_search)
.on_input(Message::ApplicationSearch)
@ -328,12 +330,12 @@ impl Page {
{
let mut row = widget::row::with_capacity(2).spacing(space_s);
row = row.push(icon::from_name(app.icon().unwrap_or("application-default")));
row = row
.push(icon::from_name(app.icon().unwrap_or("application-default")));
if let Some(name) = app.name(&startup_apps.locales) {
row = row.push(text(name));
}
else {
} else {
row = row.push(text(&app.appid));
}
@ -363,13 +365,14 @@ impl Page {
}
fn apps() -> Section<crate::pages::Message> {
let cosmic::cosmic_theme::Spacing { space_s, .. } = cosmic::theme::active().cosmic().spacing;
let cosmic::cosmic_theme::Spacing {
space_xxs, space_s, ..
} = cosmic::theme::spacing();
Section::default()
.title(fl!("startup-apps"))
.view::<Page>(move |_binder, page, _section| {
let mut view = widget::column::with_capacity(4)
.spacing(cosmic::theme::active().cosmic().space_xxs());
let mut view = widget::column::with_capacity(4).spacing(space_xxs);
if let Some(startup_apps) = &page.cached_startup_apps {
let order = vec![DirectoryType::User];
@ -386,12 +389,12 @@ fn apps() -> Section<crate::pages::Message> {
for app in apps {
let mut row = widget::row::with_capacity(2).spacing(space_s);
row = row.push(icon::from_name(app.icon().unwrap_or("application-default")));
row = row
.push(icon::from_name(app.icon().unwrap_or("application-default")));
if let Some(name) = app.name(&startup_apps.locales) {
row = row.push(text(name));
}
else {
} else {
row = row.push(text(&app.appid));
}

View file

@ -8,10 +8,10 @@ use cosmic::iced::{Alignment, Length};
use cosmic::iced_core::text::Wrapping;
use cosmic::widget::color_picker::ColorPickerUpdate;
use cosmic::widget::{
self, button, column, container, divider, horizontal_space, icon, row, settings, text,
vertical_space, ColorPickerModel,
self, ColorPickerModel, button, column, container, divider, horizontal_space, icon, row,
settings, text, vertical_space,
};
use cosmic::{theme, Apply, Element};
use cosmic::{Apply, Element, theme};
use cosmic_settings_page as page;
pub fn color_picker_context_view<'a, Message: Clone + 'static>(
@ -124,7 +124,7 @@ pub fn page_list_item<'a, Message: 'static + Clone>(
space_s,
space_m,
..
} = cosmic::theme::active().cosmic().spacing;
} = cosmic::theme::spacing();
let mut builder = cosmic::widget::settings::item::builder(title);
@ -181,7 +181,10 @@ pub fn sub_page_header<'a, Message: 'static + Clone>(
.into()
}
pub fn go_next_item<Msg: Clone + 'static>(description: &str, msg: Msg) -> cosmic::Element<'_, Msg> {
pub fn go_next_item<Msg: Clone + 'static>(
description: &str,
msg_opt: impl Into<Option<Msg>>,
) -> cosmic::Element<'_, Msg> {
settings::item_row(vec![
text::body(description).wrapping(Wrapping::Word).into(),
horizontal_space().into(),
@ -190,15 +193,16 @@ pub fn go_next_item<Msg: Clone + 'static>(description: &str, msg: Msg) -> cosmic
.apply(widget::container)
.class(cosmic::theme::Container::List)
.apply(button::custom)
.padding(0)
.class(theme::Button::Transparent)
.on_press(msg)
.on_press_maybe(msg_opt.into())
.into()
}
pub fn go_next_with_item<'a, Msg: Clone + 'static>(
description: &'a str,
item: impl Into<cosmic::Element<'a, Msg>>,
msg: Msg,
msg_opt: impl Into<Option<Msg>>,
) -> cosmic::Element<'a, Msg> {
settings::item_row(vec![
text::body(description).wrapping(Wrapping::Word).into(),
@ -207,13 +211,14 @@ pub fn go_next_with_item<'a, Msg: Clone + 'static>(
.push(item)
.push(icon::from_name("go-next-symbolic").size(16).icon())
.align_y(Alignment::Center)
.spacing(cosmic::theme::active().cosmic().spacing.space_s)
.spacing(cosmic::theme::spacing().space_s)
.into(),
])
.apply(widget::container)
.class(cosmic::theme::Container::List)
.apply(button::custom)
.padding(0)
.class(theme::Button::Transparent)
.on_press(msg)
.on_press_maybe(msg_opt.into())
.into()
}