From de96ac0c86e3d64f1e1f89e774a6410f0ac5482e Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 13:14:17 +0000 Subject: [PATCH] merge-fwf: F3/F4 trials: the box trials press inside away from the reference point; the Ruler trial's tool forwards its cursor; the ruler's line part names its keyboard path (the tool's arrows move the whole ruler); rustfmt --- crates/draw/src/ui/measure/overlay.rs | 3 ++- crates/draw/tests/it/measure.rs | 15 +++++++++++---- crates/draw/tests/it/transform_box.rs | 7 ++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/draw/src/ui/measure/overlay.rs b/crates/draw/src/ui/measure/overlay.rs index 0d8b63e37..2469215b1 100644 --- a/crates/draw/src/ui/measure/overlay.rs +++ b/crates/draw/src/ui/measure/overlay.rs @@ -205,7 +205,8 @@ impl Component for RulerOverlay<'_> { let across = along.normalized().rot90() * reach; cx.part(LINE.at(0), HitShape::Polygon(vec![a + across, b + across, b - across, a - across])) .sense(Sense::DRAG) - .priority(HitPriority::new(HitLevel::Edge, 0)); + .priority(HitPriority::new(HitLevel::Edge, 0)) + .pointer_only("the arrow keys move the whole ruler while no end has focus"); } } diff --git a/crates/draw/tests/it/measure.rs b/crates/draw/tests/it/measure.rs index 00da3a3f5..03666fb25 100644 --- a/crates/draw/tests/it/measure.rs +++ b/crates/draw/tests/it/measure.rs @@ -111,6 +111,11 @@ impl CanvasTool for Driven { fn paint(&self, _: &Draw<'_>, _: &ToolContext<'_>) {} + // The Ruler's cursor reads only the line and the canvas, so a pass of a new tool gives it. + fn cursor(&self, cx: &ToolContext<'_>) -> craft_behavior::Cursor { + RulerTool::new().pass(*self.line.borrow()).cursor(cx) + } + fn command_form(&self) -> ToolPath { ToolPath::Command("the Ruler Line... command") } @@ -385,11 +390,13 @@ fn a_read_only_ruler_paints_and_takes_no_press() { fixture.fixture().frame(Vec::new()); let end = screen(ruler.end); let shapes = fixture.fixture().frame_shapes(); - let paths = |test: &dyn Fn(&[egui::Pos2]) -> bool| { - shapes.iter().filter(|shape| matches!(shape, egui::Shape::Path(path) if test(&path.points))).count() - }; + let paths = + |test: &dyn Fn(&[egui::Pos2]) -> bool| shapes.iter().filter(|shape| matches!(shape, egui::Shape::Path(path) if test(&path.points))).count(); let close = |a: egui::Pos2, b: egui::Pos2| (a - b).length() < 0.5; - assert!(paths(&|points: &[egui::Pos2]| points.iter().any(|p| close(*p, screen(ruler.start))) && points.iter().any(|p| close(*p, end))) > 0, "the line paints"); + assert!( + paths(&|points: &[egui::Pos2]| points.iter().any(|p| close(*p, screen(ruler.start))) && points.iter().any(|p| close(*p, end))) > 0, + "the line paints" + ); assert!(paths(&|points: &[egui::Pos2]| points.len() == 2 && close(points[0].lerp(points[1], 0.5), end)) >= 2, "the cross at the end paints"); fixture.press_at(end).release_at(end); diff --git a/crates/draw/tests/it/transform_box.rs b/crates/draw/tests/it/transform_box.rs index da6d034a2..0948c25f1 100644 --- a/crates/draw/tests/it/transform_box.rs +++ b/crates/draw/tests/it/transform_box.rs @@ -683,7 +683,8 @@ fn moved_by(h: &Harness) -> Vec2 { fn the_box_moves_from_the_first_pointer_move_after_the_press_and_keeps_up_with_no_jump() { let mut h = upright(); let slop = craft_ui::testing::input::slop(h.fixture.ctx()); - let from = h.screen(Point::new(200.0, 150.0)); + // Inside, away from the reference point at the box's centre. + let from = h.screen(Point::new(150.0, 120.0)); frame(&mut h, vec![pointer::moved(from)]); frame(&mut h, vec![pointer::press(from)]); frame(&mut h, Vec::new()); @@ -703,7 +704,7 @@ fn the_box_moves_from_the_first_pointer_move_after_the_press_and_keeps_up_with_n // A move inside the slop and a release there still commit the move the user saw. let mut h = upright(); - let from = h.screen(Point::new(200.0, 150.0)); + let from = h.screen(Point::new(150.0, 120.0)); frame(&mut h, vec![pointer::moved(from)]); frame(&mut h, vec![pointer::press(from)]); frame(&mut h, vec![pointer::moved(from + by(slop / 2.0, 0.0))]); @@ -717,7 +718,7 @@ fn the_box_moves_from_the_first_pointer_move_after_the_press_and_keeps_up_with_n fn a_click_on_the_box_moves_nothing_and_a_jittery_click_outside_applies_the_box_as_it_was() { let mut h = upright(); let slop = craft_ui::testing::input::slop(h.fixture.ctx()); - let inside = h.screen(Point::new(200.0, 150.0)); + let inside = h.screen(Point::new(150.0, 120.0)); frame(&mut h, vec![pointer::moved(inside)]); frame(&mut h, vec![pointer::press(inside)]); frame(&mut h, vec![pointer::release(inside)]);