forked from iced-rs/iced
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: accessibility with some widget impls
feat: stable ids a11y: Don't unconditionally pull winit (iced-rs#43)
- Loading branch information
Showing
62 changed files
with
3,043 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "iced_accessibility" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
# TODO Ashley re-export more platform adapters | ||
|
||
[dependencies] | ||
accesskit = { git = "https://github.com/wash2/accesskit.git", branch = "winit-0.29" } | ||
accesskit_unix = { git = "https://github.com/wash2/accesskit.git", branch = "winit-0.29", optional = true } | ||
accesskit_windows = { git = "https://github.com/wash2/accesskit.git", branch = "winit-0.29", optional = true} | ||
accesskit_macos = { git = "https://github.com/wash2/accesskit.git", branch = "winit-0.29", optional = true} | ||
accesskit_winit = { git = "https://github.com/wash2/accesskit.git", branch = "winit-0.29", optional = true} | ||
# accesskit = { path = "../../fork/accesskit/common/", version = "0.11.0" } | ||
# accesskit_unix = { path = "../../fork/accesskit/platforms/unix/", version = "0.4.0", optional = true } | ||
# accesskit_windows = { path = "../../fork/accesskit/platforms/windows/", version = "0.14.0", optional = true} | ||
# accesskit_macos = { path = "../../fork/accesskit/platforms/macos/", version = "0.7.0", optional = true} | ||
# accesskit_winit = { path = "../../fork/accesskit/platforms/winit/", version = "0.13.0", optional = true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use crate::{A11yId, A11yNode}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
/// Accessible tree of nodes | ||
pub struct A11yTree { | ||
/// The root of the current widget, children of the parent widget or the Window if there is no parent widget | ||
root: Vec<A11yNode>, | ||
/// The children of a widget and its children | ||
children: Vec<A11yNode>, | ||
} | ||
|
||
impl A11yTree { | ||
/// Create a new A11yTree | ||
/// XXX if you use this method, you will need to manually add the children of the root nodes | ||
pub fn new(root: Vec<A11yNode>, children: Vec<A11yNode>) -> Self { | ||
Self { root, children } | ||
} | ||
|
||
pub fn leaf<T: Into<A11yId>>(node: accesskit::NodeBuilder, id: T) -> Self { | ||
Self { | ||
root: vec![A11yNode::new(node, id)], | ||
children: vec![], | ||
} | ||
} | ||
|
||
/// Helper for creating an A11y tree with a single root node and some children | ||
pub fn node_with_child_tree(mut root: A11yNode, child_tree: Self) -> Self { | ||
root.add_children( | ||
child_tree.root.iter().map(|n| n.id()).cloned().collect(), | ||
); | ||
Self { | ||
root: vec![root], | ||
children: child_tree | ||
.children | ||
.into_iter() | ||
.chain(child_tree.root) | ||
.collect(), | ||
} | ||
} | ||
|
||
/// Joins multiple trees into a single tree | ||
pub fn join<T: Iterator<Item = Self>>(trees: T) -> Self { | ||
trees.fold(Self::default(), |mut acc, A11yTree { root, children }| { | ||
acc.root.extend(root); | ||
acc.children.extend(children); | ||
acc | ||
}) | ||
} | ||
|
||
pub fn root(&self) -> &Vec<A11yNode> { | ||
&self.root | ||
} | ||
|
||
pub fn children(&self) -> &Vec<A11yNode> { | ||
&self.children | ||
} | ||
|
||
pub fn root_mut(&mut self) -> &mut Vec<A11yNode> { | ||
&mut self.root | ||
} | ||
|
||
pub fn children_mut(&mut self) -> &mut Vec<A11yNode> { | ||
&mut self.children | ||
} | ||
|
||
pub fn contains(&self, id: &A11yId) -> bool { | ||
self.root.iter().any(|n| n.id() == id) | ||
|| self.children.iter().any(|n| n.id() == id) | ||
} | ||
} | ||
|
||
impl From<A11yTree> for Vec<(accesskit::NodeId, accesskit::Node)> { | ||
fn from(tree: A11yTree) -> Vec<(accesskit::NodeId, accesskit::Node)> { | ||
tree.root | ||
.into_iter() | ||
.map(|node| node.into()) | ||
.chain(tree.children.into_iter().map(|node| node.into())) | ||
.collect() | ||
} | ||
} |
Oops, something went wrong.