diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index f9c83deac..64871d1e6 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -176,6 +176,8 @@ pub enum PressPhase { Held { /// The press. start: PressStart, + /// The pointer position this pass. + pos: Pos2, }, /// The press moved past slop on a part that senses a drag. #[non_exhaustive] @@ -225,7 +227,7 @@ impl PressPhase { pub const fn start(&self) -> Option { match self { PressPhase::Down { start } - | PressPhase::Held { start } + | PressPhase::Held { start, .. } | PressPhase::DragStart { start, .. } | PressPhase::Drag { start, .. } | PressPhase::Release { start, .. } @@ -259,7 +261,7 @@ impl PressPhase { match self { PressPhase::Idle | PressPhase::Hover => self, PressPhase::Down { start } => PressPhase::Down { start: at(start) }, - PressPhase::Held { start } => PressPhase::Held { start: at(start) }, + PressPhase::Held { start, pos } => PressPhase::Held { start: at(start), pos: point(pos) }, PressPhase::DragStart { start, pos } => PressPhase::DragStart { start: at(start), pos: point(pos) }, PressPhase::Drag { start, pos, delta: d } => PressPhase::Drag { start: at(start), pos: point(pos), delta: delta(d) }, PressPhase::Release { start, pos, click } => PressPhase::Release { start: at(start), pos: point(pos), click }, @@ -642,7 +644,7 @@ impl PressMachine { } else if open.dragging { PressPhase::Drag { start: open.start, pos, delta: input.delta } } else { - PressPhase::Held { start: open.start } + PressPhase::Held { start: open.start, pos } }; open.reported = true; PressStep { target: Some(open.target), phase: Some(phase), dragging: open.drag_reported, activated: None } @@ -703,6 +705,15 @@ mod tests { .join(" ") } + #[test] + fn held_reports_the_pointer_of_its_pass_within_slop() { + let mut machine = PressMachine::new(); + pass(&mut machine, &[press(0.0, 1.0)], Sense::DRAG); + let near = pos2(SLOP / 2.0, 0.0); + let step = pass(&mut machine, &[PointerEvent::Moved { at: near, sample: None }], Sense::DRAG); + assert!(matches!(step.phase, Some(PressPhase::Held { pos, .. }) if pos == near), "{:?}", step.phase); + } + #[test] fn two_clicks_whose_passes_share_a_release_and_a_press_report_every_phase_in_order() { let up = PointerEvent::released(pos2(0.0, 0.0)); diff --git a/crates/behavior/src/sense.rs b/crates/behavior/src/sense.rs index eb396da58..077310f66 100644 --- a/crates/behavior/src/sense.rs +++ b/crates/behavior/src/sense.rs @@ -5,7 +5,7 @@ use bitflags::bitflags; bitflags! { /// What a root or a part senses. The egui adapter maps the root's sense to egui's. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] - pub struct Sense: u16 { + pub struct Sense: u32 { /// Hover only. const HOVER = 1; /// A press released within slop activates. @@ -45,6 +45,11 @@ bitflags! { /// A zoom zone: a vertical wheel over the shape zooms the view of the innermost enclosing taker of the zoom /// share (a ruler over its time area). The shape takes no wheel share itself. const WHEEL_ZOOMS_VIEW = 32768; + /// The gesture begins at the first move after the press, inside slop, and the value follows the pointer from + /// there, so it does not jump when the press passes slop. A press released with no move is a click. Declared + /// with `DRAG` by a part whose click does nothing a drag could be mistaken for (a transform box's handles). + /// The component begins the gesture from `PressPhase::Held`. + const FOLLOWS_IN_SLOP = 65536; } } diff --git a/crates/color/src/ui/info.rs b/crates/color/src/ui/info.rs index 6e8c255bd..19a8c11b9 100644 --- a/crates/color/src/ui/info.rs +++ b/crates/color/src/ui/info.rs @@ -37,6 +37,14 @@ craft_ui::words! { pos_y: "info.posY" = "Y"; w: "info.w" = "W"; h: "info.h" = "H"; + /// The Ruler tool's angle. + angle: "info.angle" = "A"; + /// A plain ruler's length. + length: "info.length" = "L"; + /// A protractor's first arm. + length1: "info.length1" = "L1"; + /// A protractor's second arm. + length2: "info.length2" = "L2"; /// The document size template. document: template "info.document" = "Doc: {width} x {height}"; no_document: "info.noDocument" = "No document"; @@ -62,6 +70,40 @@ impl InfoColor { } } +/// The Ruler tool's measure, its values as the app formats them in the ruler's unit. +#[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] +pub enum InfoMeasure { + /// A plain ruler: its angle and length. + Line { + /// The angle. + angle: Label, + /// The length. + length: Label, + }, + /// A protractor: the angle between its arms and the arms' lengths. + Protractor { + /// The angle between the arms. + angle: Label, + /// The first arm's length. + first: Label, + /// The second arm's length. + second: Label, + }, +} + +impl InfoMeasure { + /// A plain ruler's measure. + pub fn line(angle: impl Into