Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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 @@ -40,7 +40,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 @@ -324,8 +324,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
accesskit_update: _, // not currently implemented
num_completed_passes: _, // handled by `Context::run`
request_discard_reasons: _, // handled by `Context::run`
} = platform_output;
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 @@ rustdoc-args = ["--generate-link-to-definition"]
default = ["clipboard", "links", "wayland", "winit/default", "x11"]

## Enable platform accessibility API implementations through [AccessKit](https://accesskit.dev/).
accesskit = ["dep:accesskit_winit", "egui/accesskit"]
accesskit = ["dep: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
4 changes: 3 additions & 1 deletion crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ impl State {
events: _, // handled elsewhere
mutable_text_under_cursor: _, // only used in eframe web
ime,
#[cfg(feature = "accesskit")]
accesskit_update,
num_completed_passes: _, // `egui::Context::run` handles this
request_discard_reasons: _, // `egui::Context::run` handles this
Expand Down Expand Up @@ -947,6 +946,9 @@ impl State {
profiling::scope!("accesskit");
accesskit.update_if_active(|| update);
}

#[cfg(not(feature = "accesskit"))]
let _ = accesskit_update;
}

fn set_cursor_icon(&mut self, window: &Window, cursor_icon: egui::CursorIcon) {
Expand Down
8 changes: 2 additions & 6 deletions crates/egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ rustdoc-args = ["--generate-link-to-definition"]
[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 @@ -61,7 +57,7 @@ persistence = ["serde", "epaint/serde", "ron"]
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 @@ -75,6 +71,7 @@ _override_unity = ["epaint/_override_unity"]
emath = { workspace = true, default-features = false }
epaint = { workspace = true, default-features = false }

accesskit.workspace = true
ahash.workspace = true
bitflags.workspace = true
log.workspace = true
Expand All @@ -84,7 +81,6 @@ smallvec.workspace = true
unicode-segmentation.workspace = true

#! ### Optional dependencies
accesskit = { workspace = true, optional = true }

backtrace = { workspace = true, optional = true }

Expand Down
1 change: 0 additions & 1 deletion crates/egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,6 @@ fn resize_interaction(
let rect = outer_rect.shrink(window_frame.stroke.width / 2.0);

let side_response = |rect, id| {
#[cfg(feature = "accesskit")]
ctx.register_accesskit_parent(id, _accessibility_parent);
let response = ctx.create_widget(
WidgetRect {
Expand Down
28 changes: 10 additions & 18 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use crate::{
viewport::ViewportClass,
};

#[cfg(feature = "accesskit")]
use crate::IdMap;

/// Information given to the backend about when it is time to repaint the ui.
Expand Down Expand Up @@ -404,7 +403,6 @@ struct ContextImpl {

embed_viewports: bool,

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

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

#[cfg(feature = "accesskit")]
if self.is_accesskit_enabled {
profiling::scope!("accesskit");
use crate::pass_state::AccessKitPassState;
Expand Down Expand Up @@ -589,10 +586,10 @@ impl ContextImpl {
}
}

#[cfg(feature = "accesskit")]
fn accesskit_node_builder(&mut self, id: Id) -> &mut accesskit::Node {
let state = self.viewport().this_pass.accesskit_state.as_mut().unwrap();
let builders = &mut state.nodes;

if let std::collections::hash_map::Entry::Vacant(entry) = builders.entry(id) {
entry.insert(Default::default());

Expand All @@ -619,6 +616,7 @@ impl ContextImpl {
let parent_builder = builders.get_mut(&parent_id).unwrap();
parent_builder.push_child(id.accesskit_id());
}

builders.get_mut(&id).unwrap()
}

Expand Down Expand Up @@ -1204,28 +1202,28 @@ impl Context {
plugins.on_widget_under_pointer(self, &w);
}

#[cfg(feature = "accesskit")]
if allow_focus && w.sense.is_focusable() {
// Make sure anything that can receive focus has an AccessKit node.
// TODO(mwcampbell): For nodes that are filled from widget info,
// some information is written to the node twice.
self.accesskit_node_builder(w.id, |builder| res.fill_accesskit_node_common(builder));
}

#[cfg(feature = "accesskit")]
self.write(|ctx| {
use crate::{Align, pass_state::ScrollTarget, style::ScrollAnimation};
let viewport = ctx.viewport_for(ctx.viewport_id());

viewport
.input
.consume_accesskit_action_requests(res.id, |request| {
use accesskit::Action;

// TODO(lucasmerlin): Correctly handle the scroll unit:
// https://github.com/AccessKit/accesskit/blob/e639c0e0d8ccbfd9dff302d972fa06f9766d608e/common/src/lib.rs#L2621
const DISTANCE: f32 = 100.0;

match &request.action {
accesskit::Action::ScrollIntoView => {
Action::ScrollIntoView => {
viewport.this_pass.scroll_target = [
Some(ScrollTarget::new(
res.rect.x_range(),
Expand All @@ -1239,16 +1237,16 @@ impl Context {
)),
];
}
accesskit::Action::ScrollDown => {
Action::ScrollDown => {
viewport.this_pass.scroll_delta.0 += DISTANCE * Vec2::UP;
}
accesskit::Action::ScrollUp => {
Action::ScrollUp => {
viewport.this_pass.scroll_delta.0 += DISTANCE * Vec2::DOWN;
}
accesskit::Action::ScrollLeft => {
Action::ScrollLeft => {
viewport.this_pass.scroll_delta.0 += DISTANCE * Vec2::LEFT;
}
accesskit::Action::ScrollRight => {
Action::ScrollRight => {
viewport.this_pass.scroll_delta.0 += DISTANCE * Vec2::RIGHT;
}
_ => return false,
Expand Down Expand Up @@ -1341,7 +1339,6 @@ impl Context {
res.flags.set(Flags::FAKE_PRIMARY_CLICKED, true);
}

#[cfg(feature = "accesskit")]
if enabled
&& sense.senses_click()
&& input.has_accesskit_action_request(id, accesskit::Action::Click)
Expand Down Expand Up @@ -2498,7 +2495,6 @@ impl ContextImpl {

let mut platform_output: PlatformOutput = std::mem::take(&mut viewport.output);

#[cfg(feature = "accesskit")]
{
profiling::scope!("accesskit");
let state = viewport.this_pass.accesskit_state.take();
Expand Down Expand Up @@ -3497,9 +3493,8 @@ impl Context {
///
/// The `Context` lock is held while the given closure is called!
///
/// Returns `None` if acesskit is off.
/// Returns `None` if accesskit 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 @@ -3515,7 +3510,6 @@ impl Context {
})
}

#[cfg(feature = "accesskit")]
pub(crate) fn register_accesskit_parent(&self, id: Id, parent_id: Id) {
self.write(|ctx| {
if let Some(state) = ctx.viewport().this_pass.accesskit_state.as_mut() {
Expand All @@ -3525,13 +3519,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 @@ -548,7 +548,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
10 changes: 2 additions & 8 deletions crates/egui/src/data/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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>,

/// How many ui passes is this the sum of?
Expand Down Expand Up @@ -175,7 +174,6 @@ impl PlatformOutput {
mut events,
mutable_text_under_cursor,
ime,
#[cfg(feature = "accesskit")]
accesskit_update,
num_completed_passes,
mut request_discard_reasons,
Expand All @@ -190,12 +188,8 @@ impl PlatformOutput {
self.request_discard_reasons
.append(&mut request_discard_reasons);

#[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 append:
self.accesskit_update = accesskit_update;
}

/// Take everything ephemeral (everything except `cursor_icon` currently)
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 @@ -79,7 +79,6 @@ impl Id {
self.0.get()
}

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

#[cfg(feature = "accesskit")]
pub fn accesskit_action_requests(
&self,
id: crate::Id,
Expand All @@ -873,7 +872,6 @@ impl InputState {
})
}

#[cfg(feature = "accesskit")]
pub fn consume_accesskit_action_requests(
&mut self,
id: crate::Id,
Expand All @@ -890,12 +888,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 @@ -448,7 +448,6 @@ pub mod widgets;
#[cfg(debug_assertions)]
mod callstack;

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

#[deprecated = "Use the ahash crate directly."]
Expand Down Expand Up @@ -708,7 +707,6 @@ pub fn __run_test_ui(add_contents: impl Fn(&mut Ui)) {
});
}

#[cfg(feature = "accesskit")]
pub fn accesskit_root_id() -> Id {
Id::new("accesskit_root")
}
34 changes: 12 additions & 22 deletions crates/egui/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ pub(crate) struct Focus {
/// The ID of a widget to give the focus to in the next frame.
id_next_frame: Option<Id>,

#[cfg(feature = "accesskit")]
id_requested_by_accesskit: Option<accesskit::NodeId>,

/// If set, the next widget that is interested in focus will automatically get it.
Expand Down Expand Up @@ -529,10 +528,7 @@ impl Focus {
}
let event_filter = self.focused_widget.map(|w| w.filter).unwrap_or_default();

#[cfg(feature = "accesskit")]
{
self.id_requested_by_accesskit = None;
}
self.id_requested_by_accesskit = None;

self.focus_direction = FocusDirection::None;

Expand Down Expand Up @@ -567,16 +563,13 @@ impl Focus {
self.focus_direction = cardinality;
}

#[cfg(feature = "accesskit")]
if let crate::Event::AccessKitActionRequest(accesskit::ActionRequest {
action: accesskit::Action::Focus,
target,
data: None,
}) = event
{
if let crate::Event::AccessKitActionRequest(accesskit::ActionRequest {
action: accesskit::Action::Focus,
target,
data: None,
}) = event
{
self.id_requested_by_accesskit = Some(*target);
}
self.id_requested_by_accesskit = Some(*target);
}
}
}
Expand Down Expand Up @@ -606,14 +599,11 @@ impl Focus {
}

fn interested_in_focus(&mut self, id: Id) {
#[cfg(feature = "accesskit")]
{
if self.id_requested_by_accesskit == Some(id.accesskit_id()) {
self.focused_widget = Some(FocusWidget::new(id));
self.id_requested_by_accesskit = None;
self.give_to_next = false;
self.reset_focus();
}
if self.id_requested_by_accesskit == Some(id.accesskit_id()) {
self.focused_widget = Some(FocusWidget::new(id));
self.id_requested_by_accesskit = None;
self.give_to_next = false;
self.reset_focus();
}

// The rect is updated at the end of the frame.
Expand Down
Loading
Loading