diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index bb497bb8a..b3379d798 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -8,9 +8,7 @@ mod builder; mod snapshot; #[cfg(feature = "snapshot")] -pub use snapshot::*; -use std::fmt::{Debug, Display, Formatter}; -use std::time::Duration; +pub use crate::snapshot::*; mod app_kind; mod node; @@ -20,19 +18,26 @@ mod texture_to_image; #[cfg(feature = "wgpu")] pub mod wgpu; -pub use kittest; +// re-exports: +pub use { + self::{builder::*, node::*, renderer::*}, + kittest, +}; + +use std::{ + fmt::{Debug, Display, Formatter}, + time::Duration, +}; + +use egui::{ + Color32, Key, Modifiers, PointerButton, Pos2, Rect, RepaintCause, Shape, Vec2, ViewportId, + epaint::{ClippedShape, RectShape}, + style::ScrollAnimation, +}; +use kittest::Queryable; use crate::app_kind::AppKind; -pub use builder::*; -pub use node::*; -pub use renderer::*; - -use egui::epaint::{ClippedShape, RectShape}; -use egui::style::ScrollAnimation; -use egui::{Color32, Key, Modifiers, Pos2, Rect, RepaintCause, Shape, Vec2, ViewportId}; -use kittest::Queryable; - #[derive(Debug, Clone)] pub struct ExceededMaxStepsError { pub max_steps: u64, @@ -607,6 +612,32 @@ impl<'a, State> Harness<'a, State> { self.key_combination_modifiers(modifiers, &[key]); } + /// Move mouse cursor to this position. + pub fn hover_at(&self, pos: egui::Pos2) { + self.event(egui::Event::PointerMoved(pos)); + } + + /// Start dragging from a position. + pub fn drag_at(&self, pos: egui::Pos2) { + self.event(egui::Event::PointerButton { + pos, + button: PointerButton::Primary, + pressed: true, + modifiers: Modifiers::NONE, + }); + } + + /// Stop dragging and remove cursor. + pub fn drop_at(&self, pos: egui::Pos2) { + self.event(egui::Event::PointerButton { + pos, + button: PointerButton::Primary, + pressed: false, + modifiers: Modifiers::NONE, + }); + self.remove_cursor(); + } + /// Remove the cursor from the screen. /// /// Will fire a [`egui::Event::PointerGone`] event.