Skip to content

Commit

Permalink
Simplify AccessibilityNode creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndarilek committed Nov 4, 2024
1 parent f8f330e commit 3bad1ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
7 changes: 7 additions & 0 deletions crates/bevy_a11y/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> for AccessibilityNode {
fn from(node: Node) -> Self {
Self(node)
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::{Node as Accessible, 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(Accessible::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(Accessible::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(Accessible::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(Accessible::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::{Node as Accessible, 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(Accessible::new(Role::ListItem)),
AccessibilityNode::new(Role::ListItem),
))
.insert(PickingBehavior {
should_block_lower: false,
Expand Down

0 comments on commit 3bad1ec

Please sign in to comment.