Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump accesskit and accesskit_winit. #16234

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_a11y/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions crates/bevy_a11y/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -84,10 +84,17 @@ 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<NodeBuilder> for AccessibilityNode {
fn from(node: NodeBuilder) -> Self {
impl AccessibilityNode {
/// Creates a new `AccessibilityNode` with the given role.
pub fn new(role: accesskit::Role) -> Self {
Self(Node::new(role))
}
}

impl From<Node> for AccessibilityNode {
fn from(node: Node) -> Self {
Self(node)
}
}
Expand Down
46 changes: 23 additions & 23 deletions crates/bevy_ui/src/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<Item = Entity>,
) -> Option<Box<str>> {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -127,18 +127,18 @@ fn label_changed(
.iter(entity)
.map(|(_, _, text, _, _)| text.into())
.collect::<Vec<String>>();
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)
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
18 changes: 8 additions & 10 deletions crates/bevy_winit/src/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -268,7 +266,7 @@ fn queue_node_for_update(
fn add_children_nodes(
children: Option<&Children>,
node_entities: &Query<Entity, With<AccessibilityNode>>,
node: &mut NodeBuilder,
node: &mut Node,
) {
let Some(children) = children else {
return;
Expand Down
19 changes: 5 additions & 14 deletions examples/ui/scroll.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! This example illustrates scrolling in Bevy UI.

use bevy::{
a11y::{
accesskit::{NodeBuilder, Role},
AccessibilityNode,
},
a11y::{accesskit::Role, AccessibilityNode},
input::mouse::{MouseScrollUnit, MouseWheel},
picking::focus::HoverMap,
prelude::*,
Expand Down Expand Up @@ -79,7 +76,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
Label,
AccessibilityNode(NodeBuilder::new(Role::ListItem)),
AccessibilityNode::new(Role::ListItem),
))
.insert(Node {
min_width: Val::Px(200.),
Expand Down Expand Up @@ -167,9 +164,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
Label,
AccessibilityNode(NodeBuilder::new(
Role::ListItem,
)),
AccessibilityNode::new(Role::ListItem),
))
.insert(PickingBehavior {
should_block_lower: false,
Expand Down Expand Up @@ -234,9 +229,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
Label,
AccessibilityNode(NodeBuilder::new(
Role::ListItem,
)),
AccessibilityNode::new(Role::ListItem),
))
.insert(PickingBehavior {
should_block_lower: false,
Expand Down Expand Up @@ -310,9 +303,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
Label,
AccessibilityNode(NodeBuilder::new(
Role::ListItem,
)),
AccessibilityNode::new(Role::ListItem),
))
.insert(PickingBehavior {
should_block_lower: false,
Expand Down
7 changes: 2 additions & 5 deletions examples/ui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
use std::f32::consts::PI;

use bevy::{
a11y::{
accesskit::{NodeBuilder, Role},
AccessibilityNode,
},
a11y::{accesskit::Role, AccessibilityNode},
color::palettes::{basic::LIME, css::DARK_GRAY},
input::mouse::{MouseScrollUnit, MouseWheel},
picking::focus::HoverMap,
Expand Down Expand Up @@ -149,7 +146,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
Label,
AccessibilityNode(NodeBuilder::new(Role::ListItem)),
AccessibilityNode::new(Role::ListItem),
))
.insert(PickingBehavior {
should_block_lower: false,
Expand Down