diff --git a/crates/behavior/src/geometry/quad.rs b/crates/behavior/src/geometry/quad.rs index b7489a3a35..82e36e2837 100644 --- a/crates/behavior/src/geometry/quad.rs +++ b/crates/behavior/src/geometry/quad.rs @@ -268,10 +268,14 @@ impl BoxRules { self } - /// Whether the box shows `part`: `Corners` shows the four corners, `Sides` the right and left sides. + /// Whether the box shows `part`: `Corners` shows the four corners and no side, `Sides` the right and left sides + /// and no corner. The inside, the outside and the reference point always show. pub fn shows(&self, part: BoxPart) -> bool { - let _ = part; - todo!("ED-F5") + match (self.handles, part) { + (BoxHandles::Corners, BoxPart::Edge(_)) | (BoxHandles::Sides, BoxPart::Corner(_)) => false, + (BoxHandles::Sides, BoxPart::Edge(k)) => k % 2 == 1, + _ => true, + } } /// The mode drags follow: a mode the content refuses scales as Free Transform does. @@ -287,14 +291,15 @@ impl BoxRules { /// Whether a drag of `part` changes the box: in Distort only the corners, the inside and the /// reference point; in Skew everything but the outside; the outside only where rotating is - /// allowed. A click outside a refused zone still applies the box (the overlay's rule). + /// allowed; and never a handle the box does not [show](Self::shows). A click outside a refused + /// zone still applies the box (the overlay's rule). pub fn allows(&self, part: BoxPart) -> bool { let by_mode = match self.effective_mode() { TransformMode::Distort => !matches!(part, BoxPart::Outside | BoxPart::Edge(_)), TransformMode::Skew => part != BoxPart::Outside, _ => true, }; - by_mode && (self.allow.rotate || part != BoxPart::Outside) + by_mode && (self.allow.rotate || part != BoxPart::Outside) && self.shows(part) } /// The modifiers a drag of `part` acts on, from the keys held: ⌘ is dropped on a corner or diff --git a/crates/draw/src/ui/transform/transform_box.rs b/crates/draw/src/ui/transform/transform_box.rs index 62b7356d77..1d94f3702e 100644 --- a/crates/draw/src/ui/transform/transform_box.rs +++ b/crates/draw/src/ui/transform/transform_box.rs @@ -35,6 +35,10 @@ pub const BOX: PartKey = PartKey::new("box"); /// outside. const OUTSIDE: PartKey = PartKey::new("outside"); +/// The round rotate handle of [`RotateZone::Knob`], `KNOB.at(0)`: it stands for the outside, so a drag on it turns the +/// box as a drag outside does. +const KNOB: PartKey = PartKey::new("knob"); + /// The pointer-only part of an edge: the band along the whole side, outside it, beside the midpoint handle `BOX.at(Edge(k))` that the keyboard /// and the focus ring use. One part key carries one shape, so the side cannot reuse the handle's key. const EDGE: PartKey = PartKey::new("edge"); @@ -126,8 +130,7 @@ impl RotateZone { fn rotates_at(self, quad: &[Point; 4], pointer: Pos2) -> bool { match self { RotateZone::Border { points } => border_distance(quad, pointer) <= points, - RotateZone::Outside | RotateZone::Band => true, - RotateZone::Knob => todo!("ED-F7"), + RotateZone::Outside | RotateZone::Band | RotateZone::Knob => true, } } } @@ -289,6 +292,8 @@ struct Grip { follows: bool, /// An Alt press away from the handles: a click there moves the reference point. moves_pivot: bool, + /// The press is on the rotate knob: a click there is not a click outside, so it applies nothing. + knob: bool, /// The box at the press. pressed: BoxState, /// The box the drag last produced. @@ -298,7 +303,17 @@ struct Grip { impl Default for Grip { fn default() -> Self { let none = BoxState::from_rect(DocRect::ZERO); - Grip { part: BoxPart::Inside, start: none, from: Point::ZERO, began: false, follows: false, moves_pivot: false, pressed: none, last: none } + Grip { + part: BoxPart::Inside, + start: none, + from: Point::ZERO, + began: false, + follows: false, + moves_pivot: false, + knob: false, + pressed: none, + last: none, + } } } @@ -451,6 +466,12 @@ impl<'a> TransformBox<'a> { self.move_only().filter(|&points| points > 0.0 && self.rules.allows(BoxPart::Inside)) } + /// Whether the box declares, draws and names a rotate knob: the knob zone on a box drawn as a box, where the rules + /// let it turn. + fn has_knob(&self) -> bool { + matches!(self.rotate_zone, RotateZone::Knob) && self.line.is_none() && self.move_only().is_none() && self.rules.allows(BoxPart::Outside) + } + /// The parts the keyboard walks, in order. A box whose inside does not move has no inside part, so a press or drag /// over its body reaches what lies beneath (a type editor under a paragraph frame). A box that offers only its /// move reach has none. @@ -549,7 +570,10 @@ impl<'a> TransformBox<'a> { match (kind, part) { (BoxDrag::Rotate, BoxPart::Outside) if !dragging && !self.rotate_zone.rotates_at(&screen.quad, pointer) => CursorIcon::Default.into(), (BoxDrag::Rotate, BoxPart::Outside) => { - if dragging || matches!(self.rotate_zone, RotateZone::Band | RotateZone::Border { .. }) || away <= style.rotate_reach { + if dragging + || matches!(self.rotate_zone, RotateZone::Band | RotateZone::Knob | RotateZone::Border { .. }) + || away <= style.rotate_reach + { turn() } else { CursorIcon::Alias.into() @@ -615,8 +639,8 @@ impl<'a> TransformBox<'a> { } /// The parts that take a press, with the box part each stands for. Mirrors what [`parts`](Component::parts) - /// declares: the keyboard parts, a segment per allowed edge, the centre where declared, and the outside; or only the - /// move strips. + /// declares: the keyboard parts, a segment per allowed edge, the centre where declared, and the outside (the knob in + /// [`RotateZone::Knob`]); or only the move strips. fn pointer_parts(&self) -> Vec<(PartRef, BoxPart)> { if self.move_only().is_some() { let parts = if self.ring_reach().is_some() { 0..8 } else { 0..0 }; @@ -635,7 +659,13 @@ impl<'a> TransformBox<'a> { if self.declares_centre() { parts.push((CENTRE.at(0), BoxPart::Inside)); } - parts.extend((0..4).map(|corner| (OUTSIDE.at(corner), BoxPart::Outside))); + if matches!(self.rotate_zone, RotateZone::Knob) { + if self.has_knob() { + parts.push((KNOB.at(0), BoxPart::Outside)); + } + } else { + parts.extend((0..4).map(|corner| (OUTSIDE.at(corner), BoxPart::Outside))); + } parts } @@ -661,11 +691,13 @@ impl<'a> TransformBox<'a> { PressPhase::Down { start, .. } if part == BoxPart::Outside && !self.rotate_zone.rotates_at(&screen.quad, start.origin) => {} PressPhase::Down { start, .. } if start.button == PointerButton::Primary => { let from = space.view.to_doc(start.origin); - // The move reach only moves: an Alt press there is a move too. - let moves_pivot = mods.alt && self.move_only().is_none() && matches!(part, BoxPart::Inside | BoxPart::Outside); + let knob = reference.key == KNOB; + // The move reach only moves: an Alt press there is a move too. The knob is a handle, so an Alt + // press on it turns the box rather than moving the reference point onto it. + let moves_pivot = mods.alt && self.move_only().is_none() && !knob && matches!(part, BoxPart::Inside | BoxPart::Outside); let follows = follows_in_slop(part); let (part, begin) = if moves_pivot { (BoxPart::Pivot, BoxState::new(shown.quad, from)) } else { (part, *shown) }; - held = Some(Grip { part, start: begin, from, began: false, follows, moves_pivot, pressed: *shown, last: *shown }); + held = Some(Grip { part, start: begin, from, began: false, follows, moves_pivot, knob, pressed: *shown, last: *shown }); } // Inside the slop a part that follows there moves the box from the first move; the outside starts at // the drag. @@ -707,7 +739,7 @@ impl<'a> TransformBox<'a> { cx.cancel(CancelReason::Unchanged); } else if grip.began { cx.commit(); - } else if grip.part == BoxPart::Outside && click && start.clicks <= 1 { + } else if grip.part == BoxPart::Outside && !grip.knob && click && start.clicks <= 1 { self.report.apply = Some(ApplyBy::ClickOutside { at: space.view.to_doc(start.origin) }); } else if grip.moves_pivot && click { cx.set(grip.start); @@ -860,6 +892,19 @@ fn outward_normals(quad: &[Pos2; 4]) -> [Vec2; 4] { }) } +/// The rotate knob of the box whose corners are `quad` on the screen, in the canvas body `within`: the knob and the foot +/// of its stem. The knob stands `rotate_reach` out from the middle of the top side, along the side's outward normal so a +/// turned box's knob turns with it; where that point is outside `within`, it stands out from the bottom side instead. +fn knob_at(quad: &[Pos2; 4], within: Rect, style: &TransformBoxStyle) -> (Pos2, Pos2) { + let outward = outward_normals(quad); + let off = |side: usize| { + let foot = quad[side].lerp(quad[(side + 1) % 4], 0.5); + (foot + outward[side] * style.rotate_reach, foot) + }; + let top = off(0); + if within.contains(top.0) { top } else { off(2) } +} + /// The reference point's glyph centred at `centre`: a circle crossed by two arms, over its halo. The one glyph of the /// reference point and of the centre mark. fn paint_centre_glyph(draw: &Draw<'_>, centre: Pos2, style: &TransformBoxStyle) { @@ -1038,7 +1083,16 @@ impl Component for TransformBox<'_> { } } RotateZone::Band => {} - RotateZone::Knob => todo!("ED-F7"), + // The knob alone turns the box; the rest of the outside is the tool's. + RotateZone::Knob => { + if self.has_knob() { + let (knob, _) = knob_at(&quad, rect, style); + cx.part(KNOB.at(0), HitShape::circle(knob, style.handle_reach)) + .sense(Sense::DRAG | Sense::CLICK | slop_sense(BoxPart::Outside)) + .priority(HitPriority::new(HitLevel::Handle, HANDLE_SUB)) + .pointer_only(ROTATE_BY_KEY); + } + } } } @@ -1074,12 +1128,17 @@ impl Component for TransformBox<'_> { let centre = screen.quad.iter().fold(Vec2::ZERO, |sum, corner| sum + pos(*corner).to_vec2()) / 4.0; paint_centre_glyph(&draw, centre.to_pos2(), style); } - for i in 0..4u8 { - for part in [BoxPart::Corner(i), BoxPart::Edge(i)] { - let Some(at) = handle_point(&screen, part) else { continue }; - let enlarged = self.overflow && part == BoxPart::Corner(2); - self.paint_handle(&draw, cx, part, pos(at), enlarged); - } + // A handle the handle set hides is not drawn; one the mode refuses still draws, dimmed by + // `paint_handle`. + for part in (0..4u8).flat_map(|i| [BoxPart::Corner(i), BoxPart::Edge(i)]).filter(|part| self.rules.shows(*part)) { + let Some(at) = handle_point(&screen, part) else { continue }; + let enlarged = self.overflow && part == BoxPart::Corner(2); + self.paint_handle(&draw, cx, part, pos(at), enlarged); + } + if self.has_knob() { + let (knob, foot) = knob_at(&screen.quad.map(pos), cx.rect, style); + draw.stroke(&PaintShape::Path(vec![foot, knob]), StrokeWidth::Thin, style.line); + paint_widget(&draw, knob, &style.widget); } } } @@ -1089,7 +1148,7 @@ impl Component for TransformBox<'_> { } /// One node per part: the whole box, the corners, the edges and the reference point, each described by its point - /// in the canvas's units. + /// in the canvas's units, and the rotate knob where the box has one. fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) { let (Some(space), Some(state)) = (canvas_space(&cx.env), cx.value()) else { return }; let words = cx.words::(); @@ -1103,6 +1162,10 @@ impl Component for TransformBox<'_> { node.description = Some(format!("{}, {}", across_x.format_value(&units, at.x, zero_x), across_y.format_value(&units, at.y, zero_y))); } } + // The knob is pointer-only, so it is not among the keyboard parts; its node names it for assistive tools. + if self.has_knob() { + access.node(KNOB.at(0), Role::BUTTON).name = Name::Text(words.rotate_knob.as_str().to_owned()); + } } fn finish(self, cx: Cx<'_, Self>) -> TransformBoxOutput { diff --git a/crates/draw/src/ui/transform/transform_box/stories.rs b/crates/draw/src/ui/transform/transform_box/stories.rs index 9dc87eb10c..d5394d24b5 100644 --- a/crates/draw/src/ui/transform/transform_box/stories.rs +++ b/crates/draw/src/ui/transform/transform_box/stories.rs @@ -1,9 +1,10 @@ //! Stories of the transform box: Free Transform with its reference point, the Move tool's controls, Distort, the -//! Ellipse tool's centre mark and the Line tool's live-line controls. +//! Ellipse tool's centre mark, the Line tool's live-line controls, the corner-only and side-only handle sets and the +//! rotate knob. use super::{BOX, LineLook, RotateZone, TransformBox}; -use craft_behavior::geometry::quad::{BoxPart, BoxRules, BoxState, TransformMode}; -use craft_behavior::kurbo::{Point, Rect as DocRect}; +use craft_behavior::geometry::quad::{BoxHandles, BoxPart, BoxRules, BoxState, TransformMode}; +use craft_behavior::kurbo::{Point, Rect as DocRect, Vec2 as DocVec}; use craft_ui::canvas::Canvas; use craft_ui::contract::{Bind, Show as _, ShowContainer as _}; use craft_ui::testing::canvas_story::{OUTLINE, StoryDocument, StoryPicture, StoryShape, paint_shapes, show_document, show_quad}; @@ -27,9 +28,20 @@ fn free_box(state: Bind<'_, BoxState>) -> TransformBox<'_> { /// Shows the box `make` builds over the story's box as the only canvas control of a canvas. fn on_canvas(ui: &mut Ui, data: &mut StoryData, make: impl for<'a> Fn(Bind<'a, BoxState>) -> TransformBox<'a>) -> StoryOutput { + show_on_canvas(ui, data, false, make) +} + +/// [`on_canvas`], the view centred on the picture; `at_top` scrolls it so the picture's top side lies on the +/// canvas's top edge. +fn show_on_canvas(ui: &mut Ui, data: &mut StoryData, at_top: bool, make: impl for<'a> Fn(Bind<'a, BoxState>) -> TransformBox<'a>) -> StoryOutput { let state = data.value("box", BoxState::from_rect(PICTURE)); let room = craft_ui::testing::stage(ui); - let view = craft_ui::testing::canvas_story::story_view(room, ui.pixels_per_point(), PICTURE.center(), 100.0); + let ppp = ui.pixels_per_point(); + let mut view = craft_ui::testing::canvas_story::story_view(room, ppp, PICTURE.center(), 100.0); + if at_top { + let top = view.to_doc(room.center_top()); + view = craft_ui::testing::canvas_story::story_view(room, ppp, PICTURE.center() + DocVec::new(0.0, PICTURE.y0 - top.y), 100.0); + } let layer = layer(); let shown = Canvas::new("Document").view(view).show_at(ui, room, |ui, body| { show_document(ui, body.rect, &StoryDocument::STANDARD); @@ -54,6 +66,30 @@ fn distort(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { on_canvas(ui, data, |state| free_box(state).rules(BoxRules::in_mode(TransformMode::Distort))) } +/// A box with handles at its corners only: a picture that scales from its corners. +#[story(TransformBox<'static>, covers = [Default])] +fn corners_only(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + on_canvas(ui, data, |state| free_box(state).rules(BoxRules::default().with_handles(BoxHandles::Corners))) +} + +/// A box with handles on its right and left sides only: a paragraph frame that changes only its width. +#[story(TransformBox<'static>, covers = [Default])] +fn sides_only(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + on_canvas(ui, data, |state| free_box(state).rules(BoxRules::default().with_handles(BoxHandles::Sides))) +} + +/// A box that turns by a round knob on a stem above its top side; the rest of the outside is the tool's. +#[story(TransformBox<'static>, covers = [Default])] +fn rotate_knob(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + on_canvas(ui, data, |state| free_box(state).rotate_zone(RotateZone::Knob).reference_point(false)) +} + +/// The knob of a box at the canvas's top edge, with no room above: it stands below the bottom side. +#[story(TransformBox<'static>, covers = [Default])] +fn rotate_knob_at_top(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + show_on_canvas(ui, data, true, |state| free_box(state).rotate_zone(RotateZone::Knob).reference_point(false)) +} + /// The box of an upright paragraph frame: free sides, no rotation, no reference point. #[story(TransformBox<'static>, covers = [Default])] fn text_frame(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { diff --git a/crates/draw/tests/it/transform_box.rs b/crates/draw/tests/it/transform_box.rs index 4f4b106083..9438d82de0 100644 --- a/crates/draw/tests/it/transform_box.rs +++ b/crates/draw/tests/it/transform_box.rs @@ -1,7 +1,7 @@ //! `TransformBox`, `TransformOverlay` and `TransformTool`: the parts the pointer takes, what each drag does, the //! keys, the readout and the overlay's edits. -use craft_behavior::geometry::quad::{BoxPart, BoxRules, BoxState, ScaleRule, TransformMode}; +use craft_behavior::geometry::quad::{BoxAllow, BoxHandles, BoxPart, BoxRules, BoxState, ScaleRule, TransformMode}; use craft_behavior::geometry::{SnapKind, SnapOptions, SnapTarget, SnapTargets}; use craft_behavior::kurbo::{Point, Rect}; use craft_behavior::{CanvasView, EditEvent, RulerUnits, Ticks}; @@ -1003,3 +1003,129 @@ fn the_reference_point_snaps_to_the_turned_boxs_points_only() { assert_eq!(h.state().quad, turned.quad, "the box never moved"); } } + +/// A box whose handle set shows only some handles takes no press, key or drag on the others: a sides-only box (a +/// paragraph frame's width) takes its right and left edges only, a corners-only box no edge. +#[trial] +fn a_sides_only_box_takes_presses_on_its_side_edges_only() { + // Rotation refused: no outside parts and no knob, so a press off the shown handles reaches nothing of the box. + let no_turn = || free_rules().with_allow(BoxAllow::new(false, true, true)); + let sides = |config: &mut Config| { + config.rules = no_turn().with_handles(BoxHandles::Sides); + config.inside_moves = false; + config.reference_point = false; + }; + // Just off the bottom right corner: within the corner's reach, outside both side bands that meet there. + let off_corner = Point::new(305.0, 225.0); + let mut all = harness(BoxState::from_rect(RECT), |config| { + sides(config); + config.rules = no_turn(); + }); + hover(&mut all, off_corner); + assert_eq!(all.host.borrow().hovered, Some(BoxPart::Corner(2)), "with every handle the corner takes the point"); + + let mut h = harness(BoxState::from_rect(RECT), sides); + hover(&mut h, off_corner); + assert_eq!(h.host.borrow().hovered, None, "a hidden corner takes no press"); + drag(&mut h, off_corner, Point::new(325.0, 245.0)); + assert_eq!(h.state(), BoxState::from_rect(RECT), "a drag from a hidden corner moves nothing"); + assert!(h.host.borrow().events.is_empty(), "and starts no gesture: {:?}", h.host.borrow().events); + for hidden in [Point::new(200.0, 80.0), Point::new(200.0, 220.0)] { + hover(&mut h, hidden); + assert_eq!(h.host.borrow().hovered, None, "the hidden edge at {hidden:?} takes no press"); + } + + drag(&mut h, Point::new(300.0, 110.0), Point::new(320.0, 110.0)); + let quad = h.state().quad; + assert!((quad[1].x - 320.0).abs() < 1e-6 && (quad[2].x - 320.0).abs() < 1e-6, "the right side moved: {quad:?}"); + drag(&mut h, Point::new(100.0, 110.0), Point::new(80.0, 110.0)); + let quad = h.state().quad; + assert!((quad[0].x - 80.0).abs() < 1e-6 && (quad[3].x - 80.0).abs() < 1e-6, "the left side moved: {quad:?}"); + + let mut picks = Vec::new(); + h.fixture.key(egui::Key::Tab, egui::Modifiers::NONE).settle(); + picks.extend(h.host.borrow().picked); + for _ in 0..3 { + h.fixture.key(egui::Key::PageDown, egui::Modifiers::NONE).settle(); + picks.extend(h.host.borrow().picked); + } + assert!(picks.iter().all(|part| matches!(part, BoxPart::Edge(1) | BoxPart::Edge(3))), "the keys reach the shown sides only: {picks:?}"); + assert!(picks.contains(&BoxPart::Edge(1)) && picks.contains(&BoxPart::Edge(3)), "and both of them: {picks:?}"); + + let mut corners = harness(BoxState::from_rect(RECT), |config| { + sides(config); + config.rules = no_turn().with_handles(BoxHandles::Corners); + }); + for hidden in [Point::new(200.0, 80.0), Point::new(200.0, 220.0), Point::new(300.0, 150.0)] { + hover(&mut corners, hidden); + assert_eq!(corners.host.borrow().hovered, None, "a corners-only box's edge at {hidden:?} takes no press"); + } + hover(&mut corners, off_corner); + assert_eq!(corners.host.borrow().hovered, Some(BoxPart::Corner(2)), "its corners still do"); +} + +/// The rotate knob stands above the box, or below it at the canvas's top edge; a ⇧ drag on it turns the box by whole +/// rotate steps, and a click on it applies nothing. The knob is found as the app finds it, by its access-tree name. +#[trial] +fn a_knob_sits_below_a_box_at_the_top_turns_in_shift_steps_and_a_click_on_it_applies_nothing() { + let knob_of = |h: &Harness| h.fixture.by_label("Rotate").map(|target| target.center()); + let knob_zone = |config: &mut Config| { + config.zone = RotateZone::Knob; + config.reference_point = false; + }; + + // The harness's view puts the document's origin at the canvas's top left: a box at y 0 has no room above. + let at_top = Rect::new(100.0, 0.0, 300.0, 140.0); + let h = harness(BoxState::from_rect(at_top), knob_zone); + let knob = knob_of(&h).expect("the knob has a node named by the box's words"); + let bottom = h.screen(Point::new(200.0, 140.0)); + assert!((knob.x - bottom.x).abs() < 0.5 && knob.y > bottom.y, "at the top edge the knob stands below: {knob:?} vs {bottom:?}"); + + let mut h = harness(BoxState::from_rect(RECT), knob_zone); + let knob = knob_of(&h).expect("the knob has a node"); + let top = h.screen(Point::new(200.0, 80.0)); + assert!((knob.x - top.x).abs() < 0.5 && knob.y < top.y, "with room above the knob stands above: {knob:?} vs {top:?}"); + + frame(&mut h, vec![pointer::moved(knob)]); + frame(&mut h, vec![pointer::press(knob)]); + frame(&mut h, vec![pointer::release(knob)]); + frame(&mut h, Vec::new()); + assert_eq!(h.host.borrow().applied, 0, "a click on the knob is not a click outside"); + assert_eq!(h.state(), BoxState::from_rect(RECT), "and turns nothing"); + + h.config.borrow_mut().mods = Some(Mods::SHIFT); + let centre = h.screen(RECT.center()); + let around = |degrees: f32| { + let (sin, cos) = degrees.to_radians().sin_cos(); + let v = knob - centre; + centre + by(v.x * cos - v.y * sin, v.x * sin + v.y * cos) + }; + frame(&mut h, vec![pointer::moved(knob)]); + frame(&mut h, vec![pointer::press(knob)]); + frame(&mut h, vec![pointer::moved(around(10.0))]); + frame(&mut h, vec![pointer::moved(around(25.0))]); + frame(&mut h, vec![pointer::release(around(25.0))]); + frame(&mut h, Vec::new()); + let angle = h.state().angle().rem_euclid(360.0); + let step = BoxRules::default().rotate_step; + let steps = angle / step; + assert!(steps.round() >= 1.0 && (steps - steps.round()).abs() < 1e-6, "a ⇧ drag turns the box by whole rotate steps: {angle}"); + assert!((angle - 25.0).abs() > 1.0, "not by the unstepped 25° of the drag: {angle}"); + assert_eq!(h.host.borrow().events.last(), Some(&Seen::Commit)); + assert_eq!(h.host.borrow().applied, 0, "a drag on the knob applies nothing"); +} + +/// A linked corner dragged inward along one axis, the other barely moving, still shrinks both sides in proportion +/// (#4477): the box does not freeze because one axis did not shrink. +#[trial] +fn a_linked_corner_dragged_inward_along_one_axis_shrinks_both_sides() { + let mut h = upright(); + drag(&mut h, Point::new(300.0, 220.0), Point::new(220.0, 222.0)); + let quad = h.state().quad; + let (width, height) = (quad[2].x - quad[0].x, quad[2].y - quad[0].y); + assert_eq!(quad[0], Point::new(RECT.x0, RECT.y0), "the opposite corner stays: {quad:?}"); + assert!(width < RECT.width() - 1.0 && height < RECT.height() - 1.0, "both sides shrink: {width} by {height}"); + assert!((width / height - RECT.width() / RECT.height()).abs() < 1e-6, "in proportion: {width} by {height}"); + // PLAN: the framework scales a linked corner by the drag's projection on the anchor–corner diagonal (here 0.736 of + // the box); production scaled by the larger axis share (0.6, the 40 % the app test asserted). The rule is left as it is. +}