Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the accesskit feature on egui #4997

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ default = [
]

## Enable platform accessibility API implementations through [AccessKit](https://accesskit.dev/).
accesskit = ["egui/accesskit", "egui-winit/accesskit"]
accesskit = ["egui-winit/accesskit"]

# Allow crates to choose an android-activity backend via Winit
# - It's important that most applications should not have to depend on android-activity directly, and can
Expand Down
3 changes: 1 addition & 2 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ impl AppRunner {
events: _, // already handled
mutable_text_under_cursor: _, // TODO(#4569): https://github.com/emilk/egui/issues/4569
ime,
#[cfg(feature = "accesskit")]
accesskit_update: _, // not currently implemented
..
} = platform_output;

super::set_cursor_icon(cursor_icon);
Expand Down
2 changes: 1 addition & 1 deletion crates/egui-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ all-features = true
default = ["clipboard", "links", "wayland", "winit/default", "x11"]

## Enable platform accessibility API implementations through [AccessKit](https://accesskit.dev/).
accesskit = ["accesskit_winit", "egui/accesskit"]
accesskit = ["accesskit_winit"]

# Allow crates to choose an android-activity backend via Winit
# - It's important that most applications should not have to depend on android-activity directly, and can
Expand Down
5 changes: 2 additions & 3 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,7 @@ impl State {
events: _, // handled elsewhere
mutable_text_under_cursor: _, // only used in eframe web
ime,
#[cfg(feature = "accesskit")]
accesskit_update,
..
} = platform_output;

self.set_cursor_icon(window, cursor_icon);
Expand Down Expand Up @@ -867,7 +866,7 @@ impl State {

#[cfg(feature = "accesskit")]
if let Some(accesskit) = self.accesskit.as_mut() {
if let Some(update) = accesskit_update {
if let Some(update) = platform_output.accesskit_update {
crate::profile_scope!("accesskit");
accesskit.update_if_active(|| update);
}
Expand Down
9 changes: 2 additions & 7 deletions crates/egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ all-features = true
[features]
default = ["default_fonts"]

## Exposes detailed accessibility implementation required by platform
## accessibility APIs. Also requires support in the egui integration.
accesskit = ["dep:accesskit"]

## [`bytemuck`](https://docs.rs/bytemuck) enables you to cast [`epaint::Vertex`], [`emath::Vec2`] etc to `&[u8]`.
bytemuck = ["epaint/bytemuck"]

Expand Down Expand Up @@ -72,7 +68,7 @@ puffin = ["dep:puffin", "epaint/puffin"]
rayon = ["epaint/rayon"]

## Allow serialization using [`serde`](https://docs.rs/serde).
serde = ["dep:serde", "epaint/serde", "accesskit?/serde"]
serde = ["dep:serde", "epaint/serde", "accesskit/serde"]

## Change Vertex layout to be compatible with unity
unity = ["epaint/unity"]
Expand All @@ -82,12 +78,11 @@ unity = ["epaint/unity"]
emath = { workspace = true, default-features = false }
epaint = { workspace = true, default-features = false }

accesskit = "0.16"
ahash.workspace = true
nohash-hasher.workspace = true

#! ### Optional dependencies
accesskit = { version = "0.16", optional = true }

backtrace = { workspace = true, optional = true }

## Enable this when generating docs.
Expand Down
54 changes: 20 additions & 34 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ struct ContextImpl {

embed_viewports: bool,

#[cfg(feature = "accesskit")]
is_accesskit_enabled: bool,

loaders: Arc<Loaders>,
Expand Down Expand Up @@ -505,7 +504,6 @@ impl ContextImpl {
},
);

#[cfg(feature = "accesskit")]
if self.is_accesskit_enabled {
crate::profile_scope!("accesskit");
use crate::frame_state::AccessKitFrameState;
Expand Down Expand Up @@ -573,7 +571,6 @@ impl ContextImpl {
}
}

#[cfg(feature = "accesskit")]
fn accesskit_node_builder(&mut self, id: Id) -> &mut accesskit::NodeBuilder {
let state = self.viewport().this_frame.accesskit_state.as_mut().unwrap();
let builders = &mut state.node_builders;
Expand Down Expand Up @@ -1061,7 +1058,6 @@ impl Context {
#[allow(clippy::let_and_return)]
let res = self.get_response(w);

#[cfg(feature = "accesskit")]
if w.sense.focusable {
// Make sure anything that can receive focus has an AccessKit node.
// TODO(mwcampbell): For nodes that are filled from widget info,
Expand Down Expand Up @@ -1150,7 +1146,6 @@ impl Context {
res.fake_primary_click = true;
}

#[cfg(feature = "accesskit")]
if enabled
&& sense.click
&& input.has_accesskit_action_request(id, accesskit::Action::Default)
Expand Down Expand Up @@ -2001,32 +1996,28 @@ impl ContextImpl {
// Inform the backend of all textures that have been updated (including font atlas).
let textures_delta = self.tex_manager.0.write().take_delta();

#[cfg_attr(not(feature = "accesskit"), allow(unused_mut))]
let mut platform_output: PlatformOutput = std::mem::take(&mut viewport.output);

#[cfg(feature = "accesskit")]
{
crate::profile_scope!("accesskit");
let state = viewport.this_frame.accesskit_state.take();
if let Some(state) = state {
let root_id = crate::accesskit_root_id().accesskit_id();
let nodes = {
state
.node_builders
.into_iter()
.map(|(id, builder)| (id.accesskit_id(), builder.build()))
.collect()
};
let focus_id = self
.memory
.focused()
.map_or(root_id, |id| id.accesskit_id());
platform_output.accesskit_update = Some(accesskit::TreeUpdate {
nodes,
tree: Some(accesskit::Tree::new(root_id)),
focus: focus_id,
});
}
crate::profile_scope!("accesskit");
let state = viewport.this_frame.accesskit_state.take();
if let Some(state) = state {
let root_id = crate::accesskit_root_id().accesskit_id();
let nodes = {
state
.node_builders
.into_iter()
.map(|(id, builder)| (id.accesskit_id(), builder.build()))
.collect()
};
let focus_id = self
.memory
.focused()
.map_or(root_id, |id| id.accesskit_id());
platform_output.accesskit_update = Some(accesskit::TreeUpdate {
nodes,
tree: Some(accesskit::Tree::new(root_id)),
focus: focus_id,
});
}

let shapes = viewport
Expand Down Expand Up @@ -2859,7 +2850,6 @@ impl Context {
#[inline]
pub fn with_accessibility_parent(&self, _id: Id, f: impl FnOnce()) {
// TODO(emilk): this isn't thread-safe - another thread can call this function between the push/pop calls
#[cfg(feature = "accesskit")]
self.frame_state_mut(|fs| {
if let Some(state) = fs.accesskit_state.as_mut() {
state.parent_stack.push(_id);
Expand All @@ -2868,7 +2858,6 @@ impl Context {

f();

#[cfg(feature = "accesskit")]
self.frame_state_mut(|fs| {
if let Some(state) = fs.accesskit_state.as_mut() {
assert_eq!(state.parent_stack.pop(), Some(_id));
Expand All @@ -2885,7 +2874,6 @@ impl Context {
///
/// Returns `None` if acesskit is off.
// TODO(emilk): consider making both read-only and read-write versions
#[cfg(feature = "accesskit")]
pub fn accesskit_node_builder<R>(
&self,
id: Id,
Expand All @@ -2902,13 +2890,11 @@ impl Context {
}

/// Enable generation of AccessKit tree updates in all future frames.
#[cfg(feature = "accesskit")]
pub fn enable_accesskit(&self) {
self.write(|ctx| ctx.is_accesskit_enabled = true);
}

/// Disable generation of AccessKit tree updates in all future frames.
#[cfg(feature = "accesskit")]
pub fn disable_accesskit(&self) {
self.write(|ctx| ctx.is_accesskit_enabled = false);
}
Expand Down
1 change: 0 additions & 1 deletion crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ pub enum Event {
WindowFocused(bool),

/// An assistive technology (e.g. screen reader) requested an action.
#[cfg(feature = "accesskit")]
AccessKitActionRequest(accesskit::ActionRequest),

/// The reply of a screenshot requested with [`crate::ViewportCommand::Screenshot`].
Expand Down
11 changes: 3 additions & 8 deletions crates/egui/src/data/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub struct PlatformOutput {
/// The difference in the widget tree since last frame.
///
/// NOTE: this needs to be per-viewport.
#[cfg(feature = "accesskit")]
pub accesskit_update: Option<accesskit::TreeUpdate>,
}

Expand Down Expand Up @@ -153,7 +152,6 @@ impl PlatformOutput {
mut events,
mutable_text_under_cursor,
ime,
#[cfg(feature = "accesskit")]
accesskit_update,
} = newer;

Expand All @@ -168,12 +166,9 @@ impl PlatformOutput {
self.mutable_text_under_cursor = mutable_text_under_cursor;
self.ime = ime.or(self.ime);

#[cfg(feature = "accesskit")]
{
// egui produces a complete AccessKit tree for each frame,
// so overwrite rather than appending.
self.accesskit_update = accesskit_update;
}
// egui produces a complete AccessKit tree for each frame,
// so overwrite rather than appending.
self.accesskit_update = accesskit_update;
}

/// Take everything ephemeral (everything except `cursor_icon` currently)
Expand Down
9 changes: 1 addition & 8 deletions crates/egui/src/frame_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ impl ScrollTarget {
}
}

#[cfg(feature = "accesskit")]
#[derive(Clone)]
pub struct AccessKitFrameState {
pub node_builders: IdMap<accesskit::NodeBuilder>,
Expand Down Expand Up @@ -209,7 +208,6 @@ pub struct FrameState {
/// as when swiping down on a touch-screen or track-pad with natural scrolling.
pub scroll_delta: (Vec2, style::ScrollAnimation),

#[cfg(feature = "accesskit")]
pub accesskit_state: Option<AccessKitFrameState>,

/// Highlight these widgets the next frame.
Expand All @@ -231,7 +229,6 @@ impl Default for FrameState {
used_by_panels: Rect::NAN,
scroll_target: [None, None],
scroll_delta: (Vec2::default(), style::ScrollAnimation::none()),
#[cfg(feature = "accesskit")]
accesskit_state: None,
highlight_next_frame: Default::default(),

Expand All @@ -254,7 +251,6 @@ impl FrameState {
used_by_panels,
scroll_target,
scroll_delta,
#[cfg(feature = "accesskit")]
accesskit_state,
highlight_next_frame,

Expand All @@ -277,10 +273,7 @@ impl FrameState {
*debug_rect = None;
}

#[cfg(feature = "accesskit")]
{
*accesskit_state = None;
}
*accesskit_state = None;

highlight_next_frame.clear();
}
Expand Down
1 change: 0 additions & 1 deletion crates/egui/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ impl Id {
self.0.get()
}

#[cfg(feature = "accesskit")]
pub(crate) fn accesskit_id(&self) -> accesskit::NodeId {
self.value().into()
}
Expand Down
3 changes: 0 additions & 3 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ impl InputState {
}
}

#[cfg(feature = "accesskit")]
pub fn accesskit_action_requests(
&self,
id: crate::Id,
Expand All @@ -640,12 +639,10 @@ impl InputState {
})
}

#[cfg(feature = "accesskit")]
pub fn has_accesskit_action_request(&self, id: crate::Id, action: accesskit::Action) -> bool {
self.accesskit_action_requests(id, action).next().is_some()
}

#[cfg(feature = "accesskit")]
pub fn num_accesskit_action_requests(&self, id: crate::Id, action: accesskit::Action) -> usize {
self.accesskit_action_requests(id, action).count()
}
Expand Down
2 changes: 0 additions & 2 deletions crates/egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ pub mod widgets;
#[cfg(debug_assertions)]
mod callstack;

#[cfg(feature = "accesskit")]
pub use accesskit;

pub use ahash;
Expand Down Expand Up @@ -659,7 +658,6 @@ pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
});
}

#[cfg(feature = "accesskit")]
pub fn accesskit_root_id() -> Id {
Id::new("accesskit_root")
}
Expand Down
Loading
Loading