From e117e783cb334a6f55509150c592f637ec9c45fe Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 22:11:46 -0500 Subject: [PATCH] TransformBox::round_handles: circular corner and side handles (trial) --- crates/draw/src/ui/transform/transform_box.rs | 13 +++++++++++-- crates/draw/tests/it/transform_box.rs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/draw/src/ui/transform/transform_box.rs b/crates/draw/src/ui/transform/transform_box.rs index 9248541e1..7bcf9794f 100644 --- a/crates/draw/src/ui/transform/transform_box.rs +++ b/crates/draw/src/ui/transform/transform_box.rs @@ -395,6 +395,9 @@ pub struct TransformBox<'a> { /// Ellipse tool's. It takes no press: a press there is the inside's, or the tool's. #[prop] centre_mark: bool, + /// Whether the corner and side handles are circles (a rounded document editor's look) instead of squares. + #[prop] + round_handles: bool, /// Draws the box as a live line's controls (the Line tool's live line as the whole selection). Only the two ends /// take a press and the keys, each as the box handle it points to ([`LineLook`]), so an end drag scales the box as /// that handle does; while it is dragged, the box shows as it scales. No other part is declared. @@ -428,6 +431,7 @@ impl<'a> TransformBox<'a> { overflow: false, session_arrows: true, centre_mark: false, + round_handles: false, line: None, reach: TransformReach::Box, pivot_held: false, @@ -817,12 +821,17 @@ impl<'a> TransformBox<'a> { } impl TransformBox<'_> { + /// The shape of a handle of `side` at `at`: a square, or a circle of that diameter with round handles. + fn handle_shape(&self, at: Pos2, side: f32) -> PaintShape { + if self.round_handles { PaintShape::Circle(at, side / 2.0) } else { PaintShape::Rect(Rect::from_center_size(at, Vec2::splat(side)), CornerRadius::ZERO) } + } + /// The square of handle `part` at `at` on the screen, filled as the part's state shows when the rules let it take a /// press; `enlarged` with the overflow plus. fn paint_handle(&self, draw: &Draw<'_>, cx: &Cx<'_, Self>, part: BoxPart, at: Pos2, enlarged: bool) { let look = &cx.style.handle; let side = if enlarged { look.side * OVERFLOW_IN_HANDLES } else { look.side }; - let square = PaintShape::Rect(Rect::from_center_size(at, Vec2::splat(side)), CornerRadius::ZERO); + let square = self.handle_shape(at, side); let fill = if self.rules.allows(part) { cx.resolve_part(BOX.at(part.index()), &look.fill) } else { cx.resolve(&look.fill) }; draw.fill(&square, fill); draw.stroke(&square, StrokeWidth::Thin, look.stroke); @@ -841,7 +850,7 @@ impl TransformBox<'_> { let look = &style.handle; for k in 0..4 { let middle = corners[k].lerp(corners[(k + 1) % 4], 0.5); - let square = PaintShape::Rect(Rect::from_center_size(middle, Vec2::splat(look.side)), CornerRadius::ZERO); + let square = self.handle_shape(middle, look.side); draw.fill(&square, cx.resolve(&look.fill)); draw.stroke(&square, StrokeWidth::Thin, look.stroke); } diff --git a/crates/draw/tests/it/transform_box.rs b/crates/draw/tests/it/transform_box.rs index aa49908df..8689dc0cc 100644 --- a/crates/draw/tests/it/transform_box.rs +++ b/crates/draw/tests/it/transform_box.rs @@ -54,6 +54,7 @@ struct Config { /// The host keeps the box in f32, as a text layer keeps its box, and gives it back with its centre as the pivot. f32_host: bool, centre_mark: bool, + round_handles: bool, line: Option, /// Snap targets beside the guides at [`SNAP_XS`]. targets: Vec, @@ -102,6 +103,7 @@ fn defaults() -> Config { rulers: None, f32_host: false, centre_mark: false, + round_handles: false, line: None, targets: Vec::new(), } @@ -187,6 +189,7 @@ fn harness(state: BoxState, setup: impl FnOnce(&mut Config)) -> Harness { .inside_moves(config.inside_moves) .reference_point(config.reference_point) .centre_mark(config.centre_mark) + .round_handles(config.round_handles) }; if let Some(mods) = config.mods { control = control.mods(mods); @@ -1269,3 +1272,14 @@ fn a_linked_corner_dragged_inward_along_one_axis_shrinks_both_sides() { // 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. } + +/// Round handles draw the eight corner and side handles as circles, where the default draws squares. +#[trial] +fn round_handles_are_circles() { + let circles = |round: bool| { + let mut h = harness(BoxState::from_rect(RECT), |config| config.round_handles = round); + h.fixture.frame_shapes().iter().filter(|shape| matches!(shape, egui::Shape::Circle(_))).count() + }; + // Each handle is a filled circle and its stroke. + assert_eq!(circles(true), circles(false) + 16, "the four corners and four sides are circles"); +}