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

Fix Node::simulate_click not centering cursor over widget #4

Merged
merged 6 commits into from
Nov 28, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: default
toolchain: 1.76.0
toolchain: 1.77.0
override: true

- name: Install packages (Linux)
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.76.0
toolchain: 1.77.0
target: wasm32-unknown-unknown
override: true
components: clippy
Expand Down Expand Up @@ -147,6 +147,6 @@ jobs:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
with:
rust-version: "1.76.0"
rust-version: "1.77.0"
log-level: warn
command: check
36 changes: 15 additions & 21 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,17 @@ checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046"

[[package]]
name = "accesskit"
version = "0.16.1"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef7442f1f520649b8e11ee3af6caeec24123fed4b63bc36a85b67308d8514fdf"

[[package]]
name = "accesskit"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45c97bb3cc1dacbdc6d1147040fc61309590d3e1ab5efd92a8a09c7a2e07284c"
checksum = "d3d3b8f9bae46a948369bc4a03e815d4ed6d616bd00de4051133a5019dc31c5a"

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

Expand Down Expand Up @@ -78,18 +72,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "ecolor"
version = "0.28.1"
source = "git+https://github.com/emilk/egui?rev=dae1979dd334ace310b6e3ef02e98281ed7dfb8e#dae1979dd334ace310b6e3ef02e98281ed7dfb8e"
version = "0.29.1"
source = "git+https://github.com/emilk/egui?rev=84cc1572b175d49a64f1b323a6d7e56b1f1fba66#84cc1572b175d49a64f1b323a6d7e56b1f1fba66"
dependencies = [
"emath",
]

[[package]]
name = "egui"
version = "0.28.1"
source = "git+https://github.com/emilk/egui?rev=dae1979dd334ace310b6e3ef02e98281ed7dfb8e#dae1979dd334ace310b6e3ef02e98281ed7dfb8e"
version = "0.29.1"
source = "git+https://github.com/emilk/egui?rev=84cc1572b175d49a64f1b323a6d7e56b1f1fba66#84cc1572b175d49a64f1b323a6d7e56b1f1fba66"
dependencies = [
"accesskit 0.16.1",
"accesskit",
"ahash",
"emath",
"epaint",
Expand All @@ -98,13 +92,13 @@ dependencies = [

[[package]]
name = "emath"
version = "0.28.1"
source = "git+https://github.com/emilk/egui?rev=dae1979dd334ace310b6e3ef02e98281ed7dfb8e#dae1979dd334ace310b6e3ef02e98281ed7dfb8e"
version = "0.29.1"
source = "git+https://github.com/emilk/egui?rev=84cc1572b175d49a64f1b323a6d7e56b1f1fba66#84cc1572b175d49a64f1b323a6d7e56b1f1fba66"

[[package]]
name = "epaint"
version = "0.28.1"
source = "git+https://github.com/emilk/egui?rev=dae1979dd334ace310b6e3ef02e98281ed7dfb8e#dae1979dd334ace310b6e3ef02e98281ed7dfb8e"
version = "0.29.1"
source = "git+https://github.com/emilk/egui?rev=84cc1572b175d49a64f1b323a6d7e56b1f1fba66#84cc1572b175d49a64f1b323a6d7e56b1f1fba66"
dependencies = [
"ab_glyph",
"ahash",
Expand All @@ -117,8 +111,8 @@ dependencies = [

[[package]]
name = "epaint_default_fonts"
version = "0.28.1"
source = "git+https://github.com/emilk/egui?rev=dae1979dd334ace310b6e3ef02e98281ed7dfb8e#dae1979dd334ace310b6e3ef02e98281ed7dfb8e"
version = "0.29.1"
source = "git+https://github.com/emilk/egui?rev=84cc1572b175d49a64f1b323a6d7e56b1f1fba66#84cc1572b175d49a64f1b323a6d7e56b1f1fba66"

[[package]]
name = "immutable-chunkmap"
Expand All @@ -133,7 +127,7 @@ dependencies = [
name = "kittest"
version = "0.1.0"
dependencies = [
"accesskit 0.17.0",
"accesskit",
"accesskit_consumer",
"egui",
"parking_lot",
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = "kittest"
publish = true
readme = "README.md"
repository = "https://github.com/rerun-io/kittest"
rust-version = "1.76"
rust-version = "1.77"
version = "0.1.0"

[package.metadata.docs.rs]
Expand All @@ -29,10 +29,10 @@ accesskit = "0.17.0"
parking_lot = "0.12"

[dev-dependencies]
egui = { version = "0.28.1", features = ["accesskit"] }
egui = { version = "0.29.1", features = ["accesskit"] }

[patch.crates-io]
egui = { git = "https://github.com/emilk/egui", rev = "dae1979dd334ace310b6e3ef02e98281ed7dfb8e" }
egui = { git = "https://github.com/emilk/egui", rev = "84cc1572b175d49a64f1b323a6d7e56b1f1fba66" }

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# -----------------------------------------------------------------------------
# Section identical to scripts/clippy_wasm/clippy.toml:

msrv = "1.76"
msrv = "1.77"

allow-unwrap-in-tests = true

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".

[toolchain]
channel = "1.76" # Avoid specifying a patch version here; see https://github.com/emilk/eframe_template/issues/145
channel = "1.77" # Avoid specifying a patch version here; see https://github.com/emilk/eframe_template/issues/145
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]
2 changes: 1 addition & 1 deletion scripts/clippy_wasm/clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# -----------------------------------------------------------------------------
# Section identical to the main clippy.toml:

msrv = "1.76"
msrv = "1.77"

allow-unwrap-in-tests = true

Expand Down
17 changes: 16 additions & 1 deletion src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,20 @@ impl<'a> By<'a> {
}

/// Filter by the label of the node with an exact match.
///
/// Note that [in AccessKit](https://docs.rs/accesskit/latest/accesskit/struct.Node.html#method.label),
/// a widget with `Role::Label`, stores it's label in `Node::value`.
/// We check for this and use the value if the role is `Role::Label`.
pub fn label(mut self, label: &'a str) -> Self {
self.label = Some(label);
self
}

/// Filter by the label of the node with a substring match.
///
/// Note that [in AccessKit](https://docs.rs/accesskit/latest/accesskit/struct.Node.html#method.label),
/// a widget with `Role::Label`, stores it's label in `Node::value`.
/// We check for this and use the value if the role is `Role::Label`.
pub fn label_contains(mut self, label: &'a str) -> Self {
self.label = Some(label);
self.label_contains = true;
Expand Down Expand Up @@ -156,7 +164,14 @@ impl<'a> By<'a> {
/// Note: Remember to check for recursive filtering
pub(crate) fn matches(&self, node: &Node<'_>) -> bool {
if let Some(label) = self.label {
if let Some(node_label) = node.label() {
// In AccessKit, a widget with `Role::Label`, stores it's label in `Node::value`.
let node_label = if node.role() == Role::Label {
node.value()
} else {
node.label()
};

if let Some(node_label) = node_label {
if self.label_contains {
if !node_label.contains(label) {
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'tree> Node<'tree> {
}));
}

/// Click the node via accesskit. This will trigger a [`accesskit::Action::Default`] action
/// Click the node via accesskit. This will trigger a [`accesskit::Action::Click`] action
pub fn click(&self) {
self.event(Event::ActionRequest(ActionRequest {
data: None,
Expand All @@ -88,14 +88,15 @@ impl<'tree> Node<'tree> {
/// Hover the cursor at the node center
pub fn hover(&self) {
let rect = self.node.raw_bounds().expect("Node has no bounds");
let center = Vec2::new(rect.x0 + rect.x1 / 2.0, rect.y0 + rect.y1 / 2.0);
let center = Vec2::new((rect.x0 + rect.x1) / 2.0, (rect.y0 + rect.y1) / 2.0);
self.event(Event::Simulated(SimulatedEvent::CursorMoved {
position: center,
}));
}

/// Simulate a click event at the node center
pub fn simulate_click(&self) {
self.hover();
ElementState::click().for_each(|state| {
self.event(Event::Simulated(SimulatedEvent::MouseInput {
button: MouseButton::Left,
Expand Down
Loading