mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 06:24:39 +00:00
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
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)]);
|
||||
|
||||
Reference in New Issue
Block a user