From b83509532ea5934dd68565659fc84d0aa517fe5d Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 04:34:15 +0000 Subject: [PATCH] Preset picker: the caption range sizes the field as a number field does The field measured its face over both formatted ends of the range, in the caption's proportional figures, so a value between them could still be wider (4888 beside 5000) and change the chip's width. caption_range now names the numeric range and decimal places of the caption; the field measures with NumberCodec::widest of that range, and a face's thumbnail caption shows in tabular figures, so the widest text is the widest number whatever its digits. BrushPresetPicker writes its caption with the same codec. Part of storytold/photocraft#15476, for storytold/photocraft#15859. --- crates/draw/src/ui/brush_presets/picker.rs | 6 ++--- .../src/patterns/presets/picker.rs | 26 +++++++++---------- .../src/patterns/presets/picker/stories.rs | 6 ++--- crates/ui-patterns/tests/it/presets/picker.rs | 11 ++++---- crates/ui-widgets/src/pickers/face.rs | 10 ++++--- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/crates/draw/src/ui/brush_presets/picker.rs b/crates/draw/src/ui/brush_presets/picker.rs index 74ef04d95..fb51e253a 100644 --- a/crates/draw/src/ui/brush_presets/picker.rs +++ b/crates/draw/src/ui/brush_presets/picker.rs @@ -4,7 +4,7 @@ use std::cell::{Cell, RefCell}; use std::hash::Hash; -use craft_behavior::{EditEvent, EditEvents, IconId, Mixed, Value}; +use craft_behavior::{Codec as _, EditEvent, EditEvents, IconId, Mixed, NumberCodec, Value}; use craft_ui::buttons::IconButton; use craft_ui::contract::{ Bind, BodyCx, EditResponse, Outcome, Props as _, Remember as _, SaveKey, Show as _, ShowContainer as _, TooltipSpec, Trigger, clicked, @@ -466,8 +466,8 @@ impl<'a, K: Value + Eq + Hash> BrushPresetPicker<'a, K> { }; let mut picker = PresetPicker::new(words.picker.clone(), current.reborrowed(), rows, Bind::bound(&mut browser)) .field(PickerField::Chip) - .caption(env.units().number(values.diameter.round(), 0..=0)) - .caption_range([1.0, max_diameter].map(|diameter| Label::from(env.units().number(diameter.round(), 0..=0)))) + .caption(NumberCodec::new(env.units().reader(None), 0).format(&Some(values.diameter.round()))) + .caption_range((1.0..=max_diameter.round(), 0)) .cell_shape(CellShape::Square) .view(if parts.tip_only() { PresetView::Grid } else { PresetView::List }) .browser(!compact) diff --git a/crates/ui-patterns/src/patterns/presets/picker.rs b/crates/ui-patterns/src/patterns/presets/picker.rs index b70e0d2b1..7aefb3eab 100644 --- a/crates/ui-patterns/src/patterns/presets/picker.rs +++ b/crates/ui-patterns/src/patterns/presets/picker.rs @@ -30,9 +30,10 @@ use crate::runtime::memory::StageAccess; use crate::runtime::overlay::CloseReason; use crate::style::{ComponentStyle, FocusLook, StyleCx, SurfaceLook, UiTokens}; use crate::tile_grid::TileZoom; -use craft_behavior::{EditEvent, EditEvents, HitLevel, HitPriority, Intent, Metrics, Mixed, PartKey, PressPhase, Sense, Value}; +use craft_behavior::{EditEvent, EditEvents, HitLevel, HitPriority, Intent, Metrics, Mixed, NumberCodec, PartKey, PressPhase, Sense, Value}; use egui::{Pos2, Rect, Response, Ui, Vec2}; use std::hash::Hash; +use std::ops::RangeInclusive; /// The face under the whole field. const FACE: PartKey = PartKey::new("face"); @@ -193,11 +194,12 @@ pub struct PresetPicker<'a, K: Value + Eq + Hash + 'static> { /// A short line under the field's thumbnail (a brush's current size). #[prop(into)] caption: Option