From f8f330e49a09a03e2886b45584e9ff658aafa236 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 4 Nov 2024 13:49:34 -0600 Subject: [PATCH 1/2] Bump accesskit and accesskit_winit. --- crates/bevy_a11y/Cargo.toml | 2 +- crates/bevy_a11y/src/lib.rs | 8 ++--- crates/bevy_ui/src/accessibility.rs | 46 +++++++++++++------------- crates/bevy_winit/Cargo.toml | 2 +- crates/bevy_winit/src/accessibility.rs | 18 +++++----- examples/ui/scroll.rs | 10 +++--- examples/ui/ui.rs | 4 +-- 7 files changed, 44 insertions(+), 46 deletions(-) diff --git a/crates/bevy_a11y/Cargo.toml b/crates/bevy_a11y/Cargo.toml index 62cf5ef240f35..82a3da1f297e5 100644 --- a/crates/bevy_a11y/Cargo.toml +++ b/crates/bevy_a11y/Cargo.toml @@ -15,7 +15,7 @@ bevy_derive = { path = "../bevy_derive", version = "0.15.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev" } -accesskit = "0.16" +accesskit = "0.17" [lints] workspace = true diff --git a/crates/bevy_a11y/src/lib.rs b/crates/bevy_a11y/src/lib.rs index f73a529f33e0b..49943bd719726 100644 --- a/crates/bevy_a11y/src/lib.rs +++ b/crates/bevy_a11y/src/lib.rs @@ -13,7 +13,7 @@ use alloc::sync::Arc; use core::sync::atomic::{AtomicBool, Ordering}; pub use accesskit; -use accesskit::NodeBuilder; +use accesskit::Node; use bevy_app::Plugin; use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{ @@ -84,10 +84,10 @@ impl ManageAccessibilityUpdates { /// If the entity doesn't have a parent, or if the immediate parent doesn't have /// an `AccessibilityNode`, its node will be an immediate child of the primary window. #[derive(Component, Clone, Deref, DerefMut)] -pub struct AccessibilityNode(pub NodeBuilder); +pub struct AccessibilityNode(pub Node); -impl From for AccessibilityNode { - fn from(node: NodeBuilder) -> Self { +impl From for AccessibilityNode { + fn from(node: Node) -> Self { Self(node) } } diff --git a/crates/bevy_ui/src/accessibility.rs b/crates/bevy_ui/src/accessibility.rs index 941282eac4c73..f4d331b9ca7cd 100644 --- a/crates/bevy_ui/src/accessibility.rs +++ b/crates/bevy_ui/src/accessibility.rs @@ -5,7 +5,7 @@ use crate::{ ComputedNode, }; use bevy_a11y::{ - accesskit::{NodeBuilder, Rect, Role}, + accesskit::{Node, Rect, Role}, AccessibilityNode, }; use bevy_app::{App, Plugin, PostUpdate}; @@ -19,7 +19,7 @@ use bevy_ecs::{ use bevy_render::{camera::CameraUpdateSystem, prelude::Camera}; use bevy_transform::prelude::GlobalTransform; -fn calc_name( +fn calc_label( text_reader: &mut TextUiReader, children: impl Iterator, ) -> Option> { @@ -70,18 +70,18 @@ fn button_changed( mut text_reader: TextUiReader, ) { for (entity, accessible) in &mut query { - let name = calc_name(&mut text_reader, ui_children.iter_ui_children(entity)); + let label = calc_label(&mut text_reader, ui_children.iter_ui_children(entity)); if let Some(mut accessible) = accessible { accessible.set_role(Role::Button); - if let Some(name) = name { - accessible.set_name(name); + if let Some(name) = label { + accessible.set_label(name); } else { - accessible.clear_name(); + accessible.clear_label(); } } else { - let mut node = NodeBuilder::new(Role::Button); - if let Some(name) = name { - node.set_name(name); + let mut node = Node::new(Role::Button); + if let Some(label) = label { + node.set_label(label); } commands .entity(entity) @@ -97,18 +97,18 @@ fn image_changed( mut text_reader: TextUiReader, ) { for (entity, accessible) in &mut query { - let name = calc_name(&mut text_reader, ui_children.iter_ui_children(entity)); + let label = calc_label(&mut text_reader, ui_children.iter_ui_children(entity)); if let Some(mut accessible) = accessible { accessible.set_role(Role::Image); - if let Some(name) = name { - accessible.set_name(name); + if let Some(label) = label { + accessible.set_label(label); } else { - accessible.clear_name(); + accessible.clear_label(); } } else { - let mut node = NodeBuilder::new(Role::Image); - if let Some(name) = name { - node.set_name(name); + let mut node = Node::new(Role::Image); + if let Some(label) = label { + node.set_label(label); } commands .entity(entity) @@ -127,18 +127,18 @@ fn label_changed( .iter(entity) .map(|(_, _, text, _, _)| text.into()) .collect::>(); - let name = Some(values.join(" ").into_boxed_str()); + let label = Some(values.join(" ").into_boxed_str()); if let Some(mut accessible) = accessible { accessible.set_role(Role::Label); - if let Some(name) = name { - accessible.set_name(name); + if let Some(label) = label { + accessible.set_label(label); } else { - accessible.clear_name(); + accessible.clear_label(); } } else { - let mut node = NodeBuilder::new(Role::Label); - if let Some(name) = name { - node.set_name(name); + let mut node = Node::new(Role::Label); + if let Some(label) = label { + node.set_label(label); } commands .entity(entity) diff --git a/crates/bevy_winit/Cargo.toml b/crates/bevy_winit/Cargo.toml index 427dc848383e3..3e9e2ea5f09b7 100644 --- a/crates/bevy_winit/Cargo.toml +++ b/crates/bevy_winit/Cargo.toml @@ -43,7 +43,7 @@ bevy_image = { path = "../bevy_image", version = "0.15.0-dev", optional = true } # other # feature rwh_06 refers to window_raw_handle@v0.6 winit = { version = "0.30", default-features = false, features = ["rwh_06"] } -accesskit_winit = { version = "0.22", default-features = false, features = [ +accesskit_winit = { version = "0.23", default-features = false, features = [ "rwh_06", ] } approx = { version = "0.5", default-features = false } diff --git a/crates/bevy_winit/src/accessibility.rs b/crates/bevy_winit/src/accessibility.rs index b0b88ff220edb..d2b57fbd044fa 100644 --- a/crates/bevy_winit/src/accessibility.rs +++ b/crates/bevy_winit/src/accessibility.rs @@ -6,8 +6,8 @@ use std::sync::Mutex; use accesskit_winit::Adapter; use bevy_a11y::{ accesskit::{ - ActionHandler, ActionRequest, ActivationHandler, DeactivationHandler, Node, NodeBuilder, - NodeId, Role, Tree, TreeUpdate, + ActionHandler, ActionRequest, ActivationHandler, DeactivationHandler, Node, NodeId, Role, + Tree, TreeUpdate, }, AccessibilityNode, AccessibilityRequested, AccessibilitySystem, ActionRequest as ActionRequestWrapper, Focus, ManageAccessibilityUpdates, @@ -64,9 +64,9 @@ impl AccessKitState { } fn build_root(&mut self) -> Node { - let mut builder = NodeBuilder::new(Role::Window); - builder.set_name(self.name.clone()); - builder.build() + let mut node = Node::new(Role::Window); + node.set_label(self.name.clone()); + node } fn build_initial_tree(&mut self) -> TreeUpdate { @@ -227,16 +227,14 @@ fn update_adapter( queue_node_for_update(entity, parent, &node_entities, &mut window_children); add_children_nodes(children, &node_entities, &mut node); let node_id = NodeId(entity.to_bits()); - let node = node.build(); to_update.push((node_id, node)); } - let mut window_node = NodeBuilder::new(Role::Window); + let mut window_node = Node::new(Role::Window); if primary_window.focused { let title = primary_window.title.clone(); - window_node.set_name(title.into_boxed_str()); + window_node.set_label(title.into_boxed_str()); } window_node.set_children(window_children); - let window_node = window_node.build(); let node_id = NodeId(primary_window_id.to_bits()); let window_update = (node_id, window_node); to_update.insert(0, window_update); @@ -268,7 +266,7 @@ fn queue_node_for_update( fn add_children_nodes( children: Option<&Children>, node_entities: &Query>, - node: &mut NodeBuilder, + node: &mut Node, ) { let Some(children) = children else { return; diff --git a/examples/ui/scroll.rs b/examples/ui/scroll.rs index 152ea7189ffc1..9fc2f14f0f468 100644 --- a/examples/ui/scroll.rs +++ b/examples/ui/scroll.rs @@ -2,7 +2,7 @@ use bevy::{ a11y::{ - accesskit::{NodeBuilder, Role}, + accesskit::{Node as Accessible, Role}, AccessibilityNode, }, input::mouse::{MouseScrollUnit, MouseWheel}, @@ -79,7 +79,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(NodeBuilder::new(Role::ListItem)), + AccessibilityNode(Accessible::new(Role::ListItem)), )) .insert(Node { min_width: Val::Px(200.), @@ -167,7 +167,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(NodeBuilder::new( + AccessibilityNode(Accessible::new( Role::ListItem, )), )) @@ -234,7 +234,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(NodeBuilder::new( + AccessibilityNode(Accessible::new( Role::ListItem, )), )) @@ -310,7 +310,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(NodeBuilder::new( + AccessibilityNode(Accessible::new( Role::ListItem, )), )) diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index 24647b469aa1a..62367e20fd913 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -4,7 +4,7 @@ use std::f32::consts::PI; use bevy::{ a11y::{ - accesskit::{NodeBuilder, Role}, + accesskit::{Node as Accessible, Role}, AccessibilityNode, }, color::palettes::{basic::LIME, css::DARK_GRAY}, @@ -149,7 +149,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(NodeBuilder::new(Role::ListItem)), + AccessibilityNode(Accessible::new(Role::ListItem)), )) .insert(PickingBehavior { should_block_lower: false, From 3bad1ece30b667bdf7cf88daac8deb2fe3219992 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 4 Nov 2024 14:26:04 -0600 Subject: [PATCH 2/2] Simplify `AccessibilityNode` creation. --- crates/bevy_a11y/src/lib.rs | 7 +++++++ examples/ui/scroll.rs | 19 +++++-------------- examples/ui/ui.rs | 7 ++----- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/crates/bevy_a11y/src/lib.rs b/crates/bevy_a11y/src/lib.rs index 49943bd719726..b77349e895ab9 100644 --- a/crates/bevy_a11y/src/lib.rs +++ b/crates/bevy_a11y/src/lib.rs @@ -86,6 +86,13 @@ impl ManageAccessibilityUpdates { #[derive(Component, Clone, Deref, DerefMut)] pub struct AccessibilityNode(pub Node); +impl AccessibilityNode { + /// Creates a new `AccessibilityNode` with the given role. + pub fn new(role: accesskit::Role) -> Self { + Self(Node::new(role)) + } +} + impl From for AccessibilityNode { fn from(node: Node) -> Self { Self(node) diff --git a/examples/ui/scroll.rs b/examples/ui/scroll.rs index 9fc2f14f0f468..e94334a38131d 100644 --- a/examples/ui/scroll.rs +++ b/examples/ui/scroll.rs @@ -1,10 +1,7 @@ //! This example illustrates scrolling in Bevy UI. use bevy::{ - a11y::{ - accesskit::{Node as Accessible, Role}, - AccessibilityNode, - }, + a11y::{accesskit::Role, AccessibilityNode}, input::mouse::{MouseScrollUnit, MouseWheel}, picking::focus::HoverMap, prelude::*, @@ -79,7 +76,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(Accessible::new(Role::ListItem)), + AccessibilityNode::new(Role::ListItem), )) .insert(Node { min_width: Val::Px(200.), @@ -167,9 +164,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(Accessible::new( - Role::ListItem, - )), + AccessibilityNode::new(Role::ListItem), )) .insert(PickingBehavior { should_block_lower: false, @@ -234,9 +229,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(Accessible::new( - Role::ListItem, - )), + AccessibilityNode::new(Role::ListItem), )) .insert(PickingBehavior { should_block_lower: false, @@ -310,9 +303,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(Accessible::new( - Role::ListItem, - )), + AccessibilityNode::new(Role::ListItem), )) .insert(PickingBehavior { should_block_lower: false, diff --git a/examples/ui/ui.rs b/examples/ui/ui.rs index 62367e20fd913..f389fc215d88e 100644 --- a/examples/ui/ui.rs +++ b/examples/ui/ui.rs @@ -3,10 +3,7 @@ use std::f32::consts::PI; use bevy::{ - a11y::{ - accesskit::{Node as Accessible, Role}, - AccessibilityNode, - }, + a11y::{accesskit::Role, AccessibilityNode}, color::palettes::{basic::LIME, css::DARK_GRAY}, input::mouse::{MouseScrollUnit, MouseWheel}, picking::focus::HoverMap, @@ -149,7 +146,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, Label, - AccessibilityNode(Accessible::new(Role::ListItem)), + AccessibilityNode::new(Role::ListItem), )) .insert(PickingBehavior { should_block_lower: false,