use crate::{ prelude::{Button, Label}, Node, UiImage, }; use bevy_a11y::{ accesskit::{NodeBuilder, Rect, Role}, 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_hierarchy::Children; use bevy_render::{camera::CameraUpdateSystem, prelude::Camera}; use bevy_text::Text; use bevy_transform::prelude::GlobalTransform; fn calc_name(texts: &Query<&Text>, children: &Children) -> Option> { let mut name = None; for child in children { if let Ok(text) = texts.get(*child) { let values = text .sections .iter() .map(|v| v.value.to_string()) .collect::>(); 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 Some(translation) = camera.world_to_viewport(camera_transform, transform.translation()) { let bounds = Rect::new( translation.x.into(), translation.y.into(), (translation.x + node.calculated_size.x).into(), (translation.y + node.calculated_size.y).into(), ); accessible.set_bounds(bounds); } } } } } fn button_changed( mut commands: Commands, mut query: Query<(Entity, &Children, Option<&mut AccessibilityNode>), Changed