use crate::{ experimental::UiChildren, prelude::{Button, Label}, widget::{ImageNode, TextUiReader}, ComputedNode, }; use bevy_a11y::AccessibilityNode; use bevy_app::{App, Plugin, PostUpdate}; use bevy_ecs::{ prelude::{DetectChanges, Entity}, query::{Changed, Without}, schedule::IntoSystemConfigs, system::{Commands, Query}, world::Ref, }; use bevy_render::{camera::CameraUpdateSystem, prelude::Camera}; use bevy_transform::prelude::GlobalTransform; use accesskit::{Node, Rect, Role}; fn calc_label( text_reader: &mut TextUiReader, children: impl Iterator, ) -> Option> { let mut name = None; for child in children { let values = text_reader .iter(child) .map(|(_, _, text, _, _)| text.into()) .collect::>(); if !values.is_empty() { name = Some(values.join(" ")); } } name.map(String::into_boxed_str) } fn calc_bounds( camera: Query<(&Camera, &GlobalTransform)>, mut nodes: Query<( &mut AccessibilityNode, Ref, Ref, )>, ) { if let Ok((camera, camera_transform)) = camera.get_single() { for (mut accessible, node, transform) in &mut nodes { if node.is_changed() || transform.is_changed() { if let Ok(translation) = camera.world_to_viewport(camera_transform, transform.translation()) { let bounds = Rect::new( translation.x.into(), translation.y.into(), (translation.x + node.size.x).into(), (translation.y + node.size.y).into(), ); accessible.set_bounds(bounds); } } } } } fn button_changed( mut commands: Commands, mut query: Query<(Entity, Option<&mut AccessibilityNode>), Changed