Skip to content

Commit

Permalink
feat: better a11y support
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Nov 11, 2024
1 parent be4c0a0 commit 86de25e
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rust-version = "1.80"
name = "cosmic"

[features]
default = ["multi-window"]
default = ["multi-window", "a11y"]
# Accessibility support
a11y = ["iced/a11y", "iced_accessibility"]
# Enable about widget
Expand Down
2 changes: 1 addition & 1 deletion iced
11 changes: 11 additions & 0 deletions src/widget/aspect_ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ where
) -> Option<overlay::Element<'b, Message, crate::Theme, Renderer>> {
self.container.overlay(tree, layout, renderer, translation)
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
self.container.a11y_nodes(layout, state, p)
}
}

impl<'a, Message, Renderer> From<AspectRatio<'a, Message, Renderer>>
Expand Down
22 changes: 16 additions & 6 deletions src/widget/autosize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,9 @@ where
renderer: &Renderer,
translation: Vector,
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
self.content.as_widget_mut().overlay(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
translation,
)
self.content
.as_widget_mut()
.overlay(&mut tree.children[0], layout, renderer, translation)
}

fn drag_destinations(
Expand All @@ -261,6 +258,19 @@ where
fn set_id(&mut self, id: crate::widget::Id) {
self.id = id;
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_layout = layout.children().next().unwrap();
let c_state = &state.children[0];
self.content.as_widget().a11y_nodes(c_layout, c_state, p)
}
}

impl<'a, Message, Theme, Renderer> From<Autosize<'a, Message, Theme, Renderer>>
Expand Down
3 changes: 1 addition & 2 deletions src/widget/context_drawer/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ impl<'a, Message: Clone> Widget<Message, crate::Theme, Renderer> for ContextDraw
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_layout = layout.children().next().unwrap();
let c_state = &state.children[0];
self.content.as_widget().a11y_nodes(c_layout, c_state, p)
self.content.as_widget().a11y_nodes(layout, c_state, p)
}

fn drag_destinations(
Expand Down
12 changes: 12 additions & 0 deletions src/widget/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ impl<'a, Message: Clone> Widget<Message, crate::Theme, crate::Renderer>
.overlay(),
)
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: iced_core::Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_state = &state.children[0];
self.content.as_widget().a11y_nodes(layout, c_state, p)
}
}

impl<'a, Message: Clone + 'a> From<ContextMenu<'a, Message>> for crate::Element<'a, Message> {
Expand Down
12 changes: 12 additions & 0 deletions src/widget/dnd_destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,18 @@ impl<'a, Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
fn set_id(&mut self, id: Id) {
self.id = id;
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: iced_core::Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_state = &state.children[0];
self.container.as_widget().a11y_nodes(layout, c_state, p)
}
}

#[derive(Default)]
Expand Down
12 changes: 12 additions & 0 deletions src/widget/dnd_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ impl<
fn set_id(&mut self, id: Id) {
self.id = id;
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: iced_core::Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_state = &state.children[0];
self.container.as_widget().a11y_nodes(layout, c_state, p)
}
}

impl<
Expand Down
11 changes: 11 additions & 0 deletions src/widget/dropdown/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ impl<'a, S: AsRef<str>, Message: 'a> Widget<Message, crate::Theme, crate::Render
translation,
)
}

// #[cfg(feature = "a11y")]
// /// get the a11y nodes for the widget
// fn a11y_nodes(
// &self,
// layout: Layout<'_>,
// state: &Tree,
// p: mouse::Cursor,
// ) -> iced_accessibility::A11yTree {
// // TODO
// }
}

impl<'a, S: AsRef<str>, Message: 'a> From<Dropdown<'a, S, Message>>
Expand Down
17 changes: 17 additions & 0 deletions src/widget/header_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ impl<'a, Message: Clone + 'static> Widget<Message, crate::Theme, crate::Renderer
);
}
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: iced_core::Layout<'_>,
state: &tree::Tree,
p: iced::mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_layout = layout.children().next().unwrap();
let c_state = &state.children[0];
let ret = self
.header_bar_inner
.as_widget()
.a11y_nodes(c_layout, c_state, p);
ret
}
}

impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
Expand Down
22 changes: 16 additions & 6 deletions src/widget/id_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,9 @@ where
renderer: &Renderer,
translation: Vector,
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
self.content.as_widget_mut().overlay(
&mut tree.children[0],
layout.children().next().unwrap(),
renderer,
translation,
)
self.content
.as_widget_mut()
.overlay(&mut tree.children[0], layout, renderer, translation)
}

fn drag_destinations(
Expand All @@ -196,6 +193,19 @@ where
fn set_id(&mut self, id: crate::widget::Id) {
self.id = id;
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_layout = layout.children().next().unwrap();
let c_state = &state.children[0];
self.content.as_widget().a11y_nodes(c_layout, c_state, p)
}
}

impl<'a, Message, Theme, Renderer> From<IdContainer<'a, Message, Theme, Renderer>>
Expand Down
11 changes: 11 additions & 0 deletions src/widget/layer_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ where
fn set_id(&mut self, id: crate::widget::Id) {
self.container.set_id(id);
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: iced_core::Layout<'_>,
state: &Tree,
p: iced::mouse::Cursor,
) -> iced_accessibility::A11yTree {
self.container.a11y_nodes(layout, state, p)
}
}

impl<'a, Message, Renderer> From<LayerContainer<'a, Message, Renderer>>
Expand Down
12 changes: 12 additions & 0 deletions src/widget/popover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@ where
dnd_rectangles,
);
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
let c_state = &state.children[0];
self.content.as_widget().a11y_nodes(layout, c_state, p)
}
}

impl<'a, Message, Renderer> From<Popover<'a, Message, Renderer>>
Expand Down
11 changes: 11 additions & 0 deletions src/widget/rectangle_tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ where
self.container
.drag_destinations(state, layout, renderer, dnd_rectangles);
}

#[cfg(feature = "a11y")]
/// get the a11y nodes for the widget
fn a11y_nodes(
&self,
layout: Layout<'_>,
state: &Tree,
p: mouse::Cursor,
) -> iced_accessibility::A11yTree {
self.container.a11y_nodes(layout, state, p)
}
}

impl<'a, Message, Renderer, I> From<RectangleTrackingContainer<'a, Message, Renderer, I>>
Expand Down

0 comments on commit 86de25e

Please sign in to comment.