Skip to content

Commit

Permalink
Build example accesskit tree
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Jun 21, 2024
1 parent a6c643c commit f4d03f7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
13 changes: 13 additions & 0 deletions examples/accessibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use dioxus::prelude::*;

fn main() {
dioxus_blitz::launch(app);
}

fn app() -> Element {
rsx! {
body {
"Dioxus 4 all"
}
}
}
5 changes: 1 addition & 4 deletions packages/dioxus-blitz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ fn launch_with_window<Doc: DocumentLike + 'static>(window: View<'static, Doc>) {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let mut initial = true;


// Setup hot-reloading if enabled.
#[cfg(all(
feature = "hot-reload",
Expand All @@ -127,8 +126,6 @@ fn launch_with_window<Doc: DocumentLike + 'static>(window: View<'static, Doc>) {
});
}



// the move to winit wants us to use a struct with a run method instead of the callback approach
// we want to just keep the callback approach for now
#[allow(deprecated)]
Expand Down Expand Up @@ -194,7 +191,7 @@ fn launch_with_window<Doc: DocumentLike + 'static>(window: View<'static, Doc>) {
#[cfg(feature = "accesskit")]
UserEvent::Accessibility(accessibility_event) => {
if let Some(window) = windows.get_mut(&accessibility_event.window_id) {
window.handle_accessibility_event(&accessibility_event);
window.handle_accessibility_event(&accessibility_event.window_event);
}
}
#[cfg(all(
Expand Down
3 changes: 1 addition & 2 deletions packages/dioxus-blitz/src/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum UserEvent {
/// An accessibility event from `accesskit`.
#[cfg(feature = "accesskit")]
Accessibility(Arc<AccessibilityEvent>),

/// A hotreload event, basically telling us to update our templates.
#[cfg(all(
feature = "hot-reload",
Expand All @@ -33,7 +33,6 @@ impl From<AccessibilityEvent> for UserEvent {
}
}


#[derive(Debug, Clone)]
pub enum EventData {
Poll,
Expand Down
38 changes: 36 additions & 2 deletions packages/dioxus-blitz/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,42 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> {
}

#[cfg(feature = "accesskit")]
pub fn handle_accessibility_event(&mut self, event: &accesskit_winit::Event) {
todo!()
pub fn handle_accessibility_event(&mut self, event: &accesskit_winit::WindowEvent) {
let Some(ref mut state) = self.state else {
return;
};

match event {
accesskit_winit::WindowEvent::InitialTreeRequested => {
let doc = self.renderer.dom.as_ref();
let root = doc.root_node();

let mut window = accesskit::NodeBuilder::new(accesskit::Role::Window);

let mut text = accesskit::NodeBuilder::new(accesskit::Role::StaticText);

text.set_name(dbg!(doc.get_node(root.children[0]).unwrap().text_content()));
window.push_child(accesskit::NodeId(1));

let tree = accesskit::Tree::new(accesskit::NodeId(0));
let tree_update = accesskit::TreeUpdate {
nodes: vec![
(accesskit::NodeId(0), window.build()),
(accesskit::NodeId(1), text.build()),
],
tree: Some(tree),
focus: accesskit::NodeId(1),
};

state.adapter.update_if_active(|| tree_update)
}
accesskit_winit::WindowEvent::AccessibilityDeactivated => {
// TODO
}
accesskit_winit::WindowEvent::ActionRequested(_action) => {
// TODO
}
}
}

pub fn resume(
Expand Down

0 comments on commit f4d03f7

Please sign in to comment.