mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -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:
@@ -28,6 +28,7 @@ pub use builder::*;
|
||||
pub use node::*;
|
||||
pub use renderer::*;
|
||||
|
||||
use egui::style::ScrollAnimation;
|
||||
use egui::{Key, Modifiers, Pos2, Rect, RepaintCause, Vec2, ViewportId};
|
||||
use kittest::Queryable;
|
||||
|
||||
@@ -55,6 +56,10 @@ impl Display for ExceededMaxStepsError {
|
||||
/// The [Harness] has a optional generic state that can be used to pass data to the app / ui closure.
|
||||
/// In _most cases_ it should be fine to just store the state in the closure itself.
|
||||
/// The state functions are useful if you need to access the state after the harness has been created.
|
||||
///
|
||||
/// Some egui style options are changed from the defaults:
|
||||
/// - The cursor blinking is disabled
|
||||
/// - The scroll animation is disabled
|
||||
pub struct Harness<'a, State = ()> {
|
||||
pub ctx: egui::Context,
|
||||
input: egui::RawInput,
|
||||
@@ -96,8 +101,12 @@ impl<'a, State> Harness<'a, State> {
|
||||
let ctx = ctx.unwrap_or_default();
|
||||
ctx.set_theme(theme);
|
||||
ctx.enable_accesskit();
|
||||
// Disable cursor blinking so it doesn't interfere with snapshots
|
||||
ctx.all_styles_mut(|style| style.visuals.text_cursor.blink = false);
|
||||
ctx.all_styles_mut(|style| {
|
||||
// Disable cursor blinking so it doesn't interfere with snapshots
|
||||
style.visuals.text_cursor.blink = false;
|
||||
style.scroll_animation = ScrollAnimation::none();
|
||||
style.animation_time = 0.0;
|
||||
});
|
||||
let mut input = egui::RawInput {
|
||||
screen_rect: Some(screen_rect),
|
||||
..Default::default()
|
||||
@@ -564,7 +573,8 @@ impl<'a, State> Harness<'a, State> {
|
||||
.expect("Missing root viewport")
|
||||
}
|
||||
|
||||
fn root(&self) -> Node<'_> {
|
||||
/// The root node of the test harness.
|
||||
pub fn root(&self) -> Node<'_> {
|
||||
Node {
|
||||
accesskit_node: self.kittest.root(),
|
||||
queue: &self.queued_events,
|
||||
|
||||
Reference in New Issue
Block a user