mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-28 17:19:24 +01:00
- The app's dispatcher declines a Delete binding for a Backspace press (and the reverse): craft_keymap's Matcher lets the two stand for each other, and TextureCraft binds them apart (Delete removes the layer, Backspace a Path tool point). - A plain Enter with nothing focused is the runtime's window submit: menus::shortcuts puts it back as an Enter press, as it does the window's Escape, for Reset UI, project config, import resources and the Path tool. - Each closable dock tab has its close button, as each group header had one. - Tests: the pointer-lock helper no longer rewrites input the app's raw_input_hook already rewrote (egui_kittest runs the hook before every pass); tab lookups by role; next's workspace format version; measured view edges instead of the old dock gap; a click's commit settles a frame later; tests of the old header painting and old divider geometry deleted; rustfmt.
91 lines
4.0 KiB
Rust
91 lines
4.0 KiB
Rust
//! The system's pointer in tests: the mouse moves it, and it obeys the app's put-backs, grabs and hidden cursor as a window system does
|
|
|
|
use egui::{CursorGrab, CursorIcon, Event, Modifiers, PointerButton, Pos2, Vec2, ViewportCommand, ViewportId};
|
|
use egui_kittest::Harness;
|
|
|
|
/// Where the system's pointer is and how the app holds it
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub(crate) struct SystemPointer {
|
|
pub(crate) at: Pos2,
|
|
pub(crate) locked: bool,
|
|
pub(crate) hidden: bool,
|
|
pub(crate) put_backs: usize,
|
|
/// The system folds a put-back into the next move, as Windows does, instead of reporting it as a move of its own
|
|
pub(crate) folds: bool,
|
|
/// The harness has no eframe app, so the test runs the app's raw input rewrite itself; an app harness runs the
|
|
/// app's `raw_input_hook` before every pass, as eframe does
|
|
rewrites: bool,
|
|
}
|
|
|
|
impl SystemPointer {
|
|
/// The pointer resting at `at` over a window that shows a bare UI, whose raw input the test rewrites as the
|
|
/// app's hook would
|
|
pub(crate) fn at<S>(harness: &mut Harness<'_, S>, at: Pos2) -> SystemPointer {
|
|
Self::start(harness, at, true)
|
|
}
|
|
|
|
/// The pointer resting at `at` over the app's window, whose own raw input hook rewrites the input
|
|
pub(crate) fn in_app<S>(harness: &mut Harness<'_, S>, at: Pos2) -> SystemPointer {
|
|
Self::start(harness, at, false)
|
|
}
|
|
|
|
fn start<S>(harness: &mut Harness<'_, S>, at: Pos2, rewrites: bool) -> SystemPointer {
|
|
let mut pointer = SystemPointer { at, locked: false, hidden: false, put_backs: 0, folds: false, rewrites };
|
|
harness.input_mut().events.push(Event::PointerMoved(at));
|
|
pointer.frame(harness);
|
|
pointer
|
|
}
|
|
|
|
/// One frame in which the mouse moves by `by` with `modifiers` held: a held pointer reports raw motion only, a free one moves
|
|
pub(crate) fn moves<S>(&mut self, harness: &mut Harness<'_, S>, by: Vec2, modifiers: Modifiers) {
|
|
let input = harness.input_mut();
|
|
input.events.push(Event::ModifiersChanged(modifiers));
|
|
input.events.push(Event::MouseMoved(by));
|
|
if !self.locked {
|
|
self.at += by;
|
|
input.events.push(Event::PointerMoved(self.at));
|
|
}
|
|
self.frame(harness);
|
|
}
|
|
|
|
/// The mouse moves by `by` over `frames` frames
|
|
pub(crate) fn drags<S>(&mut self, harness: &mut Harness<'_, S>, by: Vec2, frames: usize, modifiers: Modifiers) {
|
|
for _ in 0..frames {
|
|
self.moves(harness, by / frames as f32, modifiers);
|
|
}
|
|
}
|
|
|
|
/// One frame in which `button` goes down or up where the pointer is
|
|
pub(crate) fn button<S>(&mut self, harness: &mut Harness<'_, S>, button: PointerButton, pressed: bool, modifiers: Modifiers) {
|
|
let input = harness.input_mut();
|
|
input.events.push(Event::ModifiersChanged(modifiers));
|
|
input.events.push(Event::PointerButton { pos: self.at, button, pressed, modifiers });
|
|
self.frame(harness);
|
|
}
|
|
|
|
/// One frame of everything the system sent since the last: the app's raw input hook rewrites it, the app runs, and the pointer does what the app asked
|
|
pub(crate) fn frame<S>(&mut self, harness: &mut Harness<'_, S>) {
|
|
if self.rewrites {
|
|
let ctx = harness.ctx.clone();
|
|
super::rewrite(&ctx, harness.input_mut());
|
|
}
|
|
harness.step();
|
|
let output = harness.output();
|
|
self.hidden = output.platform_output.cursor_icon == CursorIcon::None;
|
|
let commands = output.viewport_output.get(&ViewportId::ROOT).map(|viewport| viewport.commands.clone()).unwrap_or_default();
|
|
for command in commands {
|
|
match command {
|
|
ViewportCommand::CursorPosition(to) => {
|
|
self.at = to;
|
|
self.put_backs += 1;
|
|
if !self.folds {
|
|
harness.input_mut().events.push(Event::PointerMoved(to));
|
|
}
|
|
}
|
|
ViewportCommand::CursorGrab(grab) => self.locked = grab == CursorGrab::Locked,
|
|
_ => {}
|
|
}
|
|
}
|
|
}
|
|
}
|