1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 23:00:04 -04:00

Add support for scrolling via accesskit / kittest (#7286)

I need to scroll in a snapshot test in my app, and kittest had no
utilities for this. Event::MouseWheel is error prone. This adds support
for some accesskit scroll actions, and uses this in kittest to add
helpers to scroll to a node / scroll the scroll area surrounding a node.

The accesskit code says down/up/left/right `Scrolls by approximately one
screen in a specific direction.`. Unfortunately it's difficult to get
the size of a "screen" (I guess that would be the size of the containing
scroll area)where I implemented the scrolling, so for now I've hardcoded
it to 100px. I think scrolling a fixed amount is still better than not
scrolling at all.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Lucas Meurer
2025-07-03 12:02:05 +02:00
committed by GitHub
parent 378e22e6ec
commit 6d312cc4c7
7 changed files with 186 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
use egui::{Modifiers, Vec2, include_image};
use egui_kittest::Harness;
use egui::{Modifiers, ScrollArea, Vec2, include_image};
use egui_kittest::{Harness, SnapshotResults};
use kittest::Queryable as _;
#[test]
@@ -81,3 +81,60 @@ fn should_wait_for_images() {
harness.snapshot("should_wait_for_images");
}
fn test_scroll_harness() -> Harness<'static, bool> {
Harness::builder()
.with_size(Vec2::new(100.0, 200.0))
.build_ui_state(
|ui, state| {
ScrollArea::vertical().show(ui, |ui| {
for i in 0..20 {
ui.label(format!("Item {i}"));
}
if ui.button("Hidden Button").clicked() {
*state = true;
};
});
},
false,
)
}
#[test]
fn test_scroll_to_me() {
let mut harness = test_scroll_harness();
let mut results = SnapshotResults::new();
results.add(harness.try_snapshot("test_scroll_initial"));
harness.get_by_label("Hidden Button").scroll_to_me();
harness.run();
results.add(harness.try_snapshot("test_scroll_scrolled"));
harness.get_by_label("Hidden Button").click();
harness.run();
assert!(
harness.state(),
"The button was not clicked after scrolling."
);
}
#[test]
fn test_scroll_down() {
let mut harness = test_scroll_harness();
let button = harness.get_by_label("Hidden Button");
button.scroll_down();
button.scroll_down();
harness.run();
harness.get_by_label("Hidden Button").click();
harness.run();
assert!(
harness.state(),
"The button was not clicked after scrolling down. (Probably not scrolled enough / at all)"
);
}