ui-widgets: ReferencePointLook::Squares fills the pick in the normal text ink and draws no sunken well or border, as production's locator; compact squares story

This commit is contained in:
bflatastic
2026-11-24 22:21:42 +07:00
parent 747dad4c1c
commit c7ce7e5460
2 changed files with 29 additions and 9 deletions
@@ -12,6 +12,7 @@ use crate::runtime::env::Label;
use crate::runtime::focus::{ActivateKeys, KeyUse};
use crate::style::{ComponentStyle, Flags, FocusLook, Stateful, States, StyleColor, StyleCx, SurfaceKind, SurfaceLook, UiTokens};
use craft_behavior::{Anchor9, Metrics, NavShape, PartKey, PartRef, Roving, Sense};
use craft_theme::Rgba;
use egui::{CornerRadius, Pos2, Rect, Vec2, vec2};
#[cfg(feature = "suite")]
@@ -62,7 +63,7 @@ pub struct ReferencePointStyle {
picked_dot: f32,
/// The dots' corner radius.
dot_radius: egui::CornerRadius,
/// The picked point's dot.
/// The picked point's dot or square: `accent.text`, `text.normal` in the `Squares` look.
ink: Stateful<StyleColor>,
/// The side of the square one growth arrow fits in.
arrow: f32,
@@ -104,8 +105,9 @@ pub enum ReferencePointLook {
/// A dot for each point, the pick's twice as wide.
#[default]
Dots,
/// Eight outer squares joined by one line round the box and a lone centre square, the pick filled, with growth
/// arrows in `Dots` only.
/// Eight outer squares joined by one line round the box and a lone centre square in the muted ink, the pick
/// filled in the normal text ink, on the surface around the picker with no well of its own. Growth arrows are
/// in `Dots` only.
Squares,
}
@@ -213,18 +215,25 @@ impl Component for ReferencePoint<'_> {
let edge = Stateful::new(cx.color(colors.line.control_edge));
let disabled = cx.color(colors.text.disabled);
let look = |rest: StyleColor| Stateful::new(rest).off(States::new(rest, rest, rest, disabled));
ReferencePointStyle {
metrics: Metrics::new(),
surface: SurfaceLook::new(Stateful::new(StyleColor(sunken.fill)))
let squares = key.look == ReferencePointLook::Squares;
// The squares stand on the surface around them, joined by their own line; the dots sit in a sunken well.
let surface = if squares {
SurfaceLook::new(Stateful::new(cx.color(Rgba::TRANSPARENT)))
} else {
SurfaceLook::new(Stateful::new(StyleColor(sunken.fill)))
.kind(SurfaceKind::Sunken)
.radius(sunken.radius)
.border(edge, cx.tokens.stroke.thin),
.border(edge, cx.tokens.stroke.thin)
};
ReferencePointStyle {
metrics: Metrics::new(),
surface,
focus: cx.focus_look(),
cell: if key.compact { cx.tokens.size.icon.md / GRID as f32 } else { cx.tokens.size.control.md },
dot: DOT,
picked_dot: if key.compact { DOT } else { DOT * 2.0 },
dot_radius: UiTokens::corner(cx.tokens.shape.radius.sm),
ink: look(cx.color(colors.accent.text)),
ink: look(cx.color(if squares { colors.text.normal } else { colors.accent.text })),
arrow: cx.tokens.size.icon.sm,
arrow_ink: look(cx.color(colors.text.muted)),
square: cx.tokens.size.handle.sm,
@@ -51,7 +51,8 @@ fn reference_point_alignment_unset(ui: &mut Ui, data: &mut StoryData) -> StoryOu
ReferencePoint::new("Alignment", data.bind("alignment_unset", None::<Anchor9>)).kind(ReferencePointKind::Alignment).show(ui).into()
}
/// The squares look: eight squares joined by a line round the box, the centre one alone, the pick filled.
/// The squares look: eight squares joined by a line round the box, the centre one alone, the pick filled in the text
/// ink, with no well behind them.
#[story(ReferencePoint<'static>, covers = [], drive = Drive::Never)]
fn reference_point_squares(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
ReferencePoint::new("Reference point", data.bind("squares", Some(Anchor9::TopRight))).look(ReferencePointLook::Squares).show(ui).into()
@@ -71,3 +72,13 @@ fn reference_point_squares_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutp
fn reference_point_compact(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
ReferencePoint::new("Reference point", data.bind("compact", Some(Anchor9::Centre))).compact().show(ui).into()
}
/// The squares look at the options bar's size, as an inspector's transform fields lead with it.
#[story(ReferencePoint<'static>, covers = [], drive = Drive::Never)]
fn reference_point_squares_compact(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
ReferencePoint::new("Reference point", data.bind("squares_compact", Some(Anchor9::Centre)))
.look(ReferencePointLook::Squares)
.compact()
.show(ui)
.into()
}