From d0a903d69aabb635776e255f1b21af241815151e Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 11 Nov 2026 23:51:52 +0000 Subject: [PATCH] Field adornments carry text: a unit after a number is a text adornment Adornment::text(label, role) is measured with the field and placed by place/reserve like a glyph or a button, against the text with no gap. NumberField's unit is its first trailing adornment; its own unit layout goes. --- crates/ui-widgets/src/text/adorn.rs | 135 +++++++++++++++++---------- crates/ui-widgets/src/text/number.rs | 67 ++++++------- 2 files changed, 116 insertions(+), 86 deletions(-) diff --git a/crates/ui-widgets/src/text/adorn.rs b/crates/ui-widgets/src/text/adorn.rs index 0858995f2..7dad3c36b 100644 --- a/crates/ui-widgets/src/text/adorn.rs +++ b/crates/ui-widgets/src/text/adorn.rs @@ -3,59 +3,95 @@ use super::FieldStyle; use crate::buttons::IconButton; -use crate::contract::{PaintUi, Props as _}; -use crate::primitives::IconSpec; +use crate::contract::{MeasureCx, PaintUi, Props as _}; +use crate::primitives::{IconSpec, TextRun}; use crate::runtime::env::Label; -use crate::style::StyleColor; +use crate::style::{StyleColor, TypeRole}; use craft_behavior::{Flow, PartKey}; use craft_theme::ControlSize; -use egui::{Rect, vec2}; +use egui::{Rect, Vec2, vec2}; use smallvec::SmallVec; /// Something a field draws beside its text. pub struct Adornment { - icon: IconSpec<'static>, - button: Option<(PartKey, Label)>, + kind: Kind, +} + +enum Kind { + Glyph(IconSpec<'static>), + Button(PartKey, IconSpec<'static>, Label), + /// Text in the line, of `role`; `size` is its measured run, zero until [`Adornment::measured`]. + Text { + label: Label, + role: TypeRole, + size: Vec2, + }, } impl Adornment { /// A decorative icon of the style's glyph side. pub fn glyph(icon: impl Into>) -> Adornment { - Adornment { icon: icon.into(), button: None } + Adornment { kind: Kind::Glyph(icon.into()) } } /// An icon button, the part `part` named `name`, of the style's button side. pub fn button(part: PartKey, icon: impl Into>, name: Label) -> Adornment { - Adornment { icon: icon.into(), button: Some((part, name)) } + Adornment { kind: Kind::Button(part, icon.into(), name) } } - /// The part key of a button; `None` for a glyph. + /// Text in the field's line, in `role`: a unit after a number, a fixed `#` before hex digits. It takes the width of + /// its run, which the field measures with [`Adornment::measured`] before placing it, and sits against the text + /// with no gap between them. + pub fn text(label: impl Into