Skip to content

Commit

Permalink
Quick and dirty integration of the AccessKit web adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
mwcampbell authored and DataTriny committed Jul 17, 2024
1 parent d75121a commit 6b0e32c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
40 changes: 19 additions & 21 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@ checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046"

[[package]]
name = "accesskit"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ac5b518d65f20dc920b3a7bb92bb2b90cdb301416f27c2a55a128cd99f75c0c"
version = "0.16.0"
dependencies = [
"enumn",
"serde",
]

[[package]]
name = "accesskit_atspi_common"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3869678048c6c1eb71b2c91c17be99edae309f88ead11ee96c831d9144ce9201"
version = "0.9.0"
dependencies = [
"accesskit",
"accesskit_consumer",
Expand All @@ -44,19 +40,15 @@ dependencies = [

[[package]]
name = "accesskit_consumer"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17fa06310c6256253ef3474cb4694346222b4bca85a53aec7f796a73d18e7082"
version = "0.24.0"
dependencies = [
"accesskit",
"immutable-chunkmap",
]

[[package]]
name = "accesskit_macos"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46a3c2a5bb8b5e403502faff2bbb85de5c14bb822a0ba7e9561cb5229b42a176"
version = "0.17.0"
dependencies = [
"accesskit",
"accesskit_consumer",
Expand All @@ -68,9 +60,7 @@ dependencies = [

[[package]]
name = "accesskit_unix"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e60feaa57f707d53047f508b55074e904126bf71f916c21d940ac0d8b40333"
version = "0.12.0"
dependencies = [
"accesskit",
"accesskit_atspi_common",
Expand All @@ -84,11 +74,19 @@ dependencies = [
"zbus",
]

[[package]]
name = "accesskit_web"
version = "0.1.0"
dependencies = [
"accesskit",
"accesskit_consumer",
"wasm-bindgen",
"web-sys",
]

[[package]]
name = "accesskit_windows"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ab7baf1a8adacddc2c5a4f14d1f936f73a0f0e1c6d4592514992c4d4c57743"
version = "0.22.0"
dependencies = [
"accesskit",
"accesskit_consumer",
Expand All @@ -99,13 +97,12 @@ dependencies = [

[[package]]
name = "accesskit_winit"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e7490b3beef9621c28bbe306abbcb7560a6591444bc498f9b9f6637e1ed8783"
version = "0.22.0"
dependencies = [
"accesskit",
"accesskit_macos",
"accesskit_unix",
"accesskit_web",
"accesskit_windows",
"raw-window-handle 0.6.2",
"winit",
Expand Down Expand Up @@ -1172,6 +1169,7 @@ dependencies = [
name = "eframe"
version = "0.27.2"
dependencies = [
"accesskit_web",
"ahash",
"bytemuck",
"directories-next",
Expand Down
3 changes: 2 additions & 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 = ["accesskit_web", "egui/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 Expand Up @@ -246,6 +246,7 @@ web-sys = { workspace = true, features = [
] }

# optional web:
accesskit_web = { path = "../../../accesskit/platforms/web", optional = true }
egui-wgpu = { workspace = true, optional = true } # if wgpu is used, use it without (!) winit
wgpu = { workspace = true, optional = true, features = [
# Let's enable some backends so that users can use `eframe` out-of-the-box
Expand Down
25 changes: 24 additions & 1 deletion crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#[cfg(feature = "accesskit")]
use egui::accesskit;
use egui::TexturesDelta;

use crate::{epi, App};

use super::{now_sec, text_agent::TextAgent, web_painter::WebPainter, NeedRepaint};

#[cfg(feature = "accesskit")]
struct StubActionHandler {}

#[cfg(feature = "accesskit")]
impl accesskit::ActionHandler for StubActionHandler {
fn do_action(&mut self, _request: accesskit::ActionRequest) {}
}

pub struct AppRunner {
#[allow(dead_code)]
web_options: crate::WebOptions,
Expand All @@ -20,6 +30,8 @@ pub struct AppRunner {
// Output for the last run:
textures_delta: TexturesDelta,
clipped_primitives: Option<Vec<egui::ClippedPrimitive>>,
#[cfg(feature = "accesskit")]
accesskit: accesskit_web::Adapter,
}

impl Drop for AppRunner {
Expand Down Expand Up @@ -114,6 +126,12 @@ impl AppRunner {
let mut runner = Self {
web_options,
frame,
#[cfg(feature = "accesskit")]
accesskit: accesskit_web::Adapter::new(
canvas_id,
egui_ctx.clone(),
StubActionHandler {},
),
egui_ctx,
painter,
input: Default::default(),
Expand Down Expand Up @@ -253,7 +271,7 @@ impl AppRunner {
mutable_text_under_cursor,
ime,
#[cfg(feature = "accesskit")]
accesskit_update: _, // not currently implemented
accesskit_update,
} = platform_output;

super::set_cursor_icon(cursor_icon);
Expand All @@ -277,6 +295,11 @@ impl AppRunner {
super::string_from_js_value(&err)
);
}

#[cfg(feature = "accesskit")]
if let Some(update) = accesskit_update {
self.accesskit.update_if_active(|| update);
}
}
}

Expand Down

0 comments on commit 6b0e32c

Please sign in to comment.