1#![forbid(unsafe_code)]
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3#![doc(
4 html_logo_url = "https://bevyengine.org/assets/icon.png",
5 html_favicon_url = "https://bevyengine.org/assets/icon.png"
6)]
7
8extern crate alloc;
17
18use alloc::sync::Arc;
19use core::sync::atomic::{AtomicBool, Ordering};
20
21use accesskit::Node;
22use bevy_app::Plugin;
23use bevy_derive::{Deref, DerefMut};
24use bevy_ecs::{
25 prelude::{Component, Entity, Event, ReflectResource},
26 schedule::SystemSet,
27 system::Resource,
28};
29use bevy_reflect::{std_traits::ReflectDefault, Reflect};
30
31#[derive(Event, Deref, DerefMut)]
33pub struct ActionRequest(pub accesskit::ActionRequest);
34
35#[derive(Resource, Default, Clone, Debug, Deref, DerefMut)]
41pub struct AccessibilityRequested(Arc<AtomicBool>);
42
43impl AccessibilityRequested {
44 pub fn get(&self) -> bool {
47 self.load(Ordering::SeqCst)
48 }
49
50 pub fn set(&self, value: bool) {
52 self.store(value, Ordering::SeqCst);
53 }
54}
55
56#[derive(Resource, Clone, Debug, Deref, DerefMut)]
63pub struct ManageAccessibilityUpdates(bool);
64
65impl Default for ManageAccessibilityUpdates {
66 fn default() -> Self {
67 Self(true)
68 }
69}
70
71impl ManageAccessibilityUpdates {
72 pub fn get(&self) -> bool {
74 self.0
75 }
76
77 pub fn set(&mut self, value: bool) {
79 self.0 = value;
80 }
81}
82
83#[derive(Component, Clone, Deref, DerefMut)]
92pub struct AccessibilityNode(pub Node);
93
94impl From<Node> for AccessibilityNode {
95 fn from(node: Node) -> Self {
96 Self(node)
97 }
98}
99
100#[derive(Resource, Default, Deref, DerefMut, Reflect)]
102#[reflect(Resource, Default)]
103pub struct Focus(pub Option<Entity>);
104
105#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
107pub enum AccessibilitySystem {
108 Update,
110}
111
112#[derive(Default)]
114pub struct AccessibilityPlugin;
115
116impl Plugin for AccessibilityPlugin {
117 fn build(&self, app: &mut bevy_app::App) {
118 app.register_type::<Focus>();
119
120 app.init_resource::<AccessibilityRequested>()
121 .init_resource::<ManageAccessibilityUpdates>()
122 .init_resource::<Focus>()
123 .allow_ambiguous_component::<AccessibilityNode>();
124 }
125}