1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

kittest: add drag-and-drop helpers (#7690)

This commit is contained in:
Emil Ernerfeldt
2025-11-07 14:46:09 +01:00
committed by GitHub
parent 1d4d14f18e
commit d8dcb31673

View File

@@ -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,
@@ -598,6 +603,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.