From 3d5426bdf1d6193717b5b4f7945d67ada4d1321b Mon Sep 17 00:00:00 2001 From: skylar Date: Sat, 14 Nov 2026 21:19:31 -0600 Subject: [PATCH] ui: add connected-square reference point presentation --- crates/ui-widgets/src/pickers/mod.rs | 2 +- .../ui-widgets/src/pickers/reference_point.rs | 104 +++++++- .../src/pickers/reference_point/stories.rs | 24 +- crates/ui-widgets/tests/it/pickers/mod.rs | 1 + .../tests/it/pickers/reference_point.rs | 224 ++++++++++++++++++ 5 files changed, 341 insertions(+), 14 deletions(-) create mode 100644 crates/ui-widgets/tests/it/pickers/reference_point.rs diff --git a/crates/ui-widgets/src/pickers/mod.rs b/crates/ui-widgets/src/pickers/mod.rs index 7252bf34b..e9fd972a9 100644 --- a/crates/ui-widgets/src/pickers/mod.rs +++ b/crates/ui-widgets/src/pickers/mod.rs @@ -26,4 +26,4 @@ pub use tree_picker::{TreeEntry, TreePicker, TreePickerStyle}; pub use unit_select::{UnitSelect, UnitSelectOutput, UnitSelectStyle}; pub use craft_behavior::Anchor9; -pub use reference_point::{ReferencePoint, ReferencePointStyle}; +pub use reference_point::{PointPresentation, ReferencePoint, ReferencePointStyle}; diff --git a/crates/ui-widgets/src/pickers/reference_point.rs b/crates/ui-widgets/src/pickers/reference_point.rs index e66ee2a65..60397962d 100644 --- a/crates/ui-widgets/src/pickers/reference_point.rs +++ b/crates/ui-widgets/src/pickers/reference_point.rs @@ -1,13 +1,14 @@ //! `ReferencePoint`: the 3 by 3 picker of a box's nine points. A leaf with a part per point, one roving group over a //! grid: one Tab stop, the arrows move the focus over the grid in both directions and stop at its edges, Home and End -//! go to the first and last point, and Space, Enter or a click picks the focused one. +//! go to the first and last point, and Space, Enter or a click picks the focused one. A `PointPresentation` picks how a +//! point is marked: a dot, or a square joined to the squares beside it. use super::words::PickerWords; use crate::contract::{ Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Input, MeasureCx, Name, PaintUi, PartsCx, Props as _, Role, SetPosition, Styled as _, WordSetCx as _, }; -use crate::primitives::{PaintShape, StrokeWidth}; +use crate::primitives::{Draw, PaintShape, StrokeWidth}; use crate::runtime::env::Label; use crate::runtime::focus::{ActivateKeys, KeyUse}; use crate::style::{ComponentStyle, Flags, FocusLook, Stateful, States, StyleColor, StyleCx, SurfaceKind, SurfaceLook, UiTokens}; @@ -25,6 +26,10 @@ const GRID: usize = 3; /// The side of the dot every point shows; the large picker draws the picked one twice as wide. const DOT: f32 = 3.5; +/// The side of a point's square in the connected-squares presentation, as a share of its cell: the observed proxy's +/// squares leave about a third of the pitch for the line that joins them. +const SQUARE: f32 = 0.7; + /// The arrow's tip, from the cell's centre, as a share of the arrow's extent. const ARROW_TIP: f32 = 0.5; /// The arrow's tail, behind the cell's centre, as a share of the arrow's extent. @@ -36,6 +41,18 @@ const ARROW_HEAD: f32 = 3.5 / 12.0; /// The head's half width, as a share of the arrow's extent. const ARROW_HEAD_HALF_WIDTH: f32 = 3.5 / 12.0; +/// How a reference point picker marks its nine points. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum PointPresentation { + /// A dot at each point, the picked point's dot twice as wide: the default. + #[default] + Dots, + /// A square at each point, each joined to the squares beside it by a line, so the nine points read as the box's + /// grid. The picked point's square is filled; the others are outlined. + ConnectedSquares, +} + /// The style of a reference point picker. #[derive(Clone, Debug, PartialEq, ComponentStyle)] #[non_exhaustive] @@ -52,23 +69,28 @@ pub struct ReferencePointStyle { dot: f32, /// The side of the picked point's dot. picked_dot: f32, + /// The side of one point's square: the connected-squares presentation's mark. + square: f32, /// The dots' corner radius. dot_radius: egui::CornerRadius, - /// The picked point's dot. + /// The picked point's dot, or the fill of its square. ink: Stateful, /// The side of the square one growth arrow fits in. arrow: f32, - /// The unpicked dots and the growth arrows. + /// The unpicked dots and squares, the lines between the squares and the growth arrows. arrow_ink: Stateful, } /// The 3 by 3 picker of a box's nine points: the point a transform, a resize or a watermark works about. The nine /// points are one Tab stop; the arrows move the focus and stop at the grid's edges, and Space, Enter or a click picks /// the focused point. The arrows are directions in the box, so they do not mirror in a right-to-left interface and -/// neither does the grid. Every point shows a muted dot, the pick's twice as wide in the accent colour, and the cell -/// under the pointer takes the hover fill. A mixed value picks no point. With [`growth`](ReferencePoint::growth) the -/// cells next to the pick show arrows toward where the box grows. The [`compact`](ReferencePoint::compact) picker is -/// the size of an options bar's icon, its pick's dot as wide as the others, with no arrows. +/// neither does the grid. A point shows a muted dot, the pick's twice as wide in the accent colour, and the cell under +/// the pointer takes the hover fill; a mixed value picks no point. The +/// [`presentation`](ReferencePoint::presentation) picks that mark instead: the square of +/// [`PointPresentation::ConnectedSquares`], the nine joined into the box's grid, with the pick's square filled and the +/// others outlined. With [`growth`](ReferencePoint::growth) the cells next to the pick show arrows toward where the +/// box grows, over whatever the presentation marks them with. The [`compact`](ReferencePoint::compact) picker is the +/// size of an options bar's icon, its pick's dot as wide as the others, with no arrows. #[derive(crate::contract::Component, crate::contract::Props)] #[component(exempt(case = "rtl", reason = "The nine points are positions in a box, not reading order: the left point stays on the left."))] pub struct ReferencePoint<'a> { @@ -83,12 +105,16 @@ pub struct ReferencePoint<'a> { #[style_key] #[prop(flag)] compact: bool, + /// How the nine points are marked: a dot each, or squares joined into the box's grid. + #[style_key] + #[prop] + presentation: PointPresentation, } impl<'a> ReferencePoint<'a> { /// A picker named `label` over `value`. pub fn new(label: impl Into