Skip to content

Commit 3cd8303

Browse files
ickshonpemockersf
authored andcommitted
Fix AccessKit node bounds (#18706)
# Objective Fixes #18685 ## Solution * Don't apply the camera translation. * Calculate the min and max bounds of the accessibility node rect taking the UI translation relative to its center not the top-left corner. ## Testing Install [NVDA](https://www.nvaccess.org/). In NVDA set `Preferences -> Settings -> Vision -> Enable Highlighting`. Then run bevy's `tab_navigation` example: ``` cargo run --example tab_navigation ``` If everything is working correctly, NVDA should draw a border around the currently selected tab button: ![Screenshot 2025-04-07 130523](https://github.com/user-attachments/assets/07d9a795-5d55-4b61-9602-2e8917020245)
1 parent c439fdb commit 3cd8303

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

crates/bevy_ui/src/accessibility.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use bevy_ecs::{
1313
system::{Commands, Query},
1414
world::Ref,
1515
};
16-
use bevy_render::{camera::CameraUpdateSystem, prelude::Camera};
16+
use bevy_math::Vec3Swizzles;
17+
use bevy_render::camera::CameraUpdateSystem;
1718
use bevy_transform::prelude::GlobalTransform;
1819

1920
use accesskit::{Node, Rect, Role};
@@ -36,28 +37,20 @@ fn calc_label(
3637
}
3738

3839
fn calc_bounds(
39-
camera: Query<(&Camera, &GlobalTransform)>,
4040
mut nodes: Query<(
4141
&mut AccessibilityNode,
4242
Ref<ComputedNode>,
4343
Ref<GlobalTransform>,
4444
)>,
4545
) {
46-
if let Ok((camera, camera_transform)) = camera.single() {
47-
for (mut accessible, node, transform) in &mut nodes {
48-
if node.is_changed() || transform.is_changed() {
49-
if let Ok(translation) =
50-
camera.world_to_viewport(camera_transform, transform.translation())
51-
{
52-
let bounds = Rect::new(
53-
translation.x.into(),
54-
translation.y.into(),
55-
(translation.x + node.size.x).into(),
56-
(translation.y + node.size.y).into(),
57-
);
58-
accessible.set_bounds(bounds);
59-
}
60-
}
46+
for (mut accessible, node, transform) in &mut nodes {
47+
if node.is_changed() || transform.is_changed() {
48+
let center = transform.translation().xy();
49+
let half_size = 0.5 * node.size;
50+
let min = center - half_size;
51+
let max = center + half_size;
52+
let bounds = Rect::new(min.x as f64, min.y as f64, max.x as f64, max.y as f64);
53+
accessible.set_bounds(bounds);
6154
}
6255
}
6356
}

0 commit comments

Comments
 (0)