iced_winit/
a11y.rs
1use crate::futures::futures::channel::mpsc;
2use crate::program::Control;
3
4use iced_accessibility::accesskit::{
5 ActivationHandler, NodeBuilder, NodeId, Role, Tree, TreeUpdate,
6};
7use iced_accessibility::accesskit_winit::Adapter;
8use iced_runtime::core;
9
10pub struct WinitActivationHandler {
11 pub proxy: mpsc::UnboundedSender<Control>,
12 pub title: String,
13}
14
15impl ActivationHandler for WinitActivationHandler {
16 fn request_initial_tree(
17 &mut self,
18 ) -> Option<iced_accessibility::accesskit::TreeUpdate> {
19 let node_id = core::id::window_node_id();
20
21 let _ = self
22 .proxy
23 .unbounded_send(Control::AccessibilityEnabled(true));
24 let mut node = NodeBuilder::new(Role::Window);
25 node.set_name(self.title.clone());
26 let node = node.build();
27 let root = NodeId(node_id);
28 Some(TreeUpdate {
29 nodes: vec![(root, node)],
30 tree: Some(Tree::new(root)),
31 focus: root,
32 })
33 }
34}
35
36pub struct WinitActionHandler {
37 pub id: core::window::Id,
38 pub proxy: mpsc::UnboundedSender<Control>,
39}
40
41impl iced_accessibility::accesskit::ActionHandler for WinitActionHandler {
42 fn do_action(
43 &mut self,
44 request: iced_accessibility::accesskit::ActionRequest,
45 ) {
46 let _ = self
47 .proxy
48 .unbounded_send(Control::Accessibility(self.id, request));
49 }
50}
51
52pub struct WinitDeactivationHandler {
53 pub proxy: mpsc::UnboundedSender<Control>,
54}
55
56impl iced_accessibility::accesskit::DeactivationHandler
57 for WinitDeactivationHandler
58{
59 fn deactivate_accessibility(&mut self) {
60 let _ = self
61 .proxy
62 .unbounded_send(Control::AccessibilityEnabled(false));
63 }
64}