Refactor lazy activation
This commit is contained in:
parent
3109ee9825
commit
18ccf1fd10
4 changed files with 27 additions and 30 deletions
|
@ -272,8 +272,17 @@ impl EpiIntegration {
|
|||
window: &winit::window::Window,
|
||||
event_loop_proxy: winit::event_loop::EventLoopProxy<E>,
|
||||
) {
|
||||
let egui_ctx = self.egui_ctx.clone();
|
||||
self.egui_winit
|
||||
.init_accesskit(window, event_loop_proxy, self.egui_ctx.clone());
|
||||
.init_accesskit(window, event_loop_proxy, move || {
|
||||
// This function is called when an accessibility client
|
||||
// (e.g. screen reader) makes its first request. If we got here,
|
||||
// we know that an accessibility tree is actually wanted.
|
||||
egui_ctx.enable_accesskit();
|
||||
// Enqueue a repaint so we'll receive a full tree update soon.
|
||||
egui_ctx.request_repaint();
|
||||
egui::accesskit_placeholder_tree_update()
|
||||
});
|
||||
}
|
||||
|
||||
pub fn warm_up(&mut self, app: &mut dyn epi::App, window: &winit::window::Window) {
|
||||
|
|
|
@ -132,21 +132,11 @@ impl State {
|
|||
&mut self,
|
||||
window: &winit::window::Window,
|
||||
event_loop_proxy: winit::event_loop::EventLoopProxy<T>,
|
||||
egui_ctx: egui::Context,
|
||||
initial_tree_update_factory: impl 'static + FnOnce() -> accesskit::TreeUpdate + Send,
|
||||
) {
|
||||
self.accesskit = Some(accesskit_winit::Adapter::new(
|
||||
window,
|
||||
move || {
|
||||
// This function is called when an accessibility client
|
||||
// (e.g. screen reader) makes its first request. If we got here,
|
||||
// we know that an accessibility tree is actually wanted.
|
||||
// Tell egui that AccessKit is active, and return a placeholder
|
||||
// tree for now. `egui::Context::accesskit_activated`
|
||||
// will request a repaint, and that will provide the first
|
||||
// real accessibility tree.
|
||||
egui_ctx.accesskit_activated();
|
||||
egui::accesskit_placeholder_tree_update()
|
||||
},
|
||||
initial_tree_update_factory,
|
||||
event_loop_proxy,
|
||||
));
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ struct ContextImpl {
|
|||
layer_rects_prev_frame: ahash::HashMap<LayerId, Vec<(Id, Rect)>>,
|
||||
|
||||
#[cfg(feature = "accesskit")]
|
||||
was_accesskit_activated: bool,
|
||||
is_accesskit_enabled: bool,
|
||||
}
|
||||
|
||||
impl ContextImpl {
|
||||
|
@ -110,7 +110,7 @@ impl ContextImpl {
|
|||
);
|
||||
|
||||
#[cfg(feature = "accesskit")]
|
||||
if self.was_accesskit_activated {
|
||||
if self.is_accesskit_enabled {
|
||||
assert!(self.output.accesskit_update.is_none());
|
||||
let id = crate::accesskit_root_id();
|
||||
let accesskit_id = id.accesskit_id();
|
||||
|
@ -1607,20 +1607,18 @@ impl Context {
|
|||
self.output().accesskit_update.is_some()
|
||||
}
|
||||
|
||||
/// Indicates that AccessKit has been activated and egui should generate
|
||||
/// AccessKit tree updates for all subsequent frames. Also requests a repaint
|
||||
/// so a full AccessKit tree will be available as soon as the repaint
|
||||
/// is done. As soon as the egui integration knows that accessibility support
|
||||
/// is desired, it must call this method and provide a placeholder tree
|
||||
/// to AccessKit through the [`crate::accesskit_placeholder_tree_update`] method.
|
||||
/// Enable generation of AccessKit tree updates in all future frames.
|
||||
///
|
||||
/// If it's practical for the egui integration to immediately run the egui
|
||||
/// application when it is either initializing the AccessKit adapter or
|
||||
/// being called by the AccessKit adapter to provide the initial tree update,
|
||||
/// then it should do so, to provide a complete AccessKit tree to the adapter
|
||||
/// immediately. Otherwise, it should enqueue a repaint and use the
|
||||
/// placeholder tree update from [`crate::accesskit_placeholder_tree_update`]
|
||||
/// in the meantime.
|
||||
#[cfg(feature = "accesskit")]
|
||||
pub fn accesskit_activated(&self) {
|
||||
let mut ctx = self.write();
|
||||
if !ctx.was_accesskit_activated {
|
||||
ctx.was_accesskit_activated = true;
|
||||
drop(ctx);
|
||||
self.request_repaint();
|
||||
}
|
||||
pub fn enable_accesskit(&self) {
|
||||
self.write().is_accesskit_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -559,8 +559,8 @@ pub fn accesskit_root_id() -> Id {
|
|||
}
|
||||
|
||||
/// Return a tree update that the egui integration should provide to the
|
||||
/// AccessKit adapter before a real tree update is available. See also
|
||||
/// [`crate::Context::accesskit_activated`].
|
||||
/// AccessKit adapter if it cannot immediately run the egui application
|
||||
/// to get a full tree update after running [`Context::enable_accesskit`].
|
||||
#[cfg(feature = "accesskit")]
|
||||
pub fn accesskit_placeholder_tree_update() -> accesskit::TreeUpdate {
|
||||
use accesskit::{Node, Role, Tree, TreeUpdate};
|
||||
|
|
Loading…
Reference in a new issue