From b808cac9fc0b9531da220f02e0049d9c454ebb2c Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 24 Nov 2026 13:10:03 +0700 Subject: [PATCH] labels: GlyphColon::Form gives a glyph caption (GlyphLabel::caption) a form's colon; draw's X/Y/W/H are captions --- crates/draw/src/ui/artboard/properties.rs | 2 +- crates/draw/src/ui/shape/panel.rs | 2 +- .../draw/src/ui/transform/transform_fields.rs | 2 +- crates/ui-contract/src/contract/label.rs | 2 +- crates/ui-contract/src/contract/label/leaf.rs | 16 +++++---- .../ui-contract/src/contract/label/props.rs | 35 ++++++++++++++++-- crates/ui-contract/src/contract/mod.rs | 2 +- crates/ui-widgets/src/form/stories.rs | 32 +++++++++++++++-- crates/ui-widgets/tests/it/label/scheme.rs | 36 +++++++++++++++++-- 9 files changed, 109 insertions(+), 20 deletions(-) diff --git a/crates/draw/src/ui/artboard/properties.rs b/crates/draw/src/ui/artboard/properties.rs index 3951d5e6b..aa3521991 100644 --- a/crates/draw/src/ui/artboard/properties.rs +++ b/crates/draw/src/ui/artboard/properties.rs @@ -87,7 +87,7 @@ impl<'a> ArtboardProperties<'a> { }); // A glyph-labelled number field; the pairs share a row, as W and H in the shape panel. let field = |ui: &mut Ui, glyph: &Label, name: &Label, value: f64, range: &RangeInclusive| { - let side = SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::text(glyph.clone()))).scrub(true); + let side = SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::caption(glyph.clone()))).scrub(true); Field::new(name.clone()) .side(side) .show(ui, |ui, _| { diff --git a/crates/draw/src/ui/shape/panel.rs b/crates/draw/src/ui/shape/panel.rs index c0fadd96e..7dbd80260 100644 --- a/crates/draw/src/ui/shape/panel.rs +++ b/crates/draw/src/ui/shape/panel.rs @@ -527,7 +527,7 @@ impl<'p, 'a> Cells<'p, 'a> { /// The side label of a cell shown by a short glyph (W, H) instead of its caption, which scrubs it. pub(super) fn glyph_side(glyph: &Label) -> SideLabel { - SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::text(glyph.clone()))).scrub(true) + SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::caption(glyph.clone()))).scrub(true) } /// The change a Sides value makes: a whole number of sides in range. diff --git a/crates/draw/src/ui/transform/transform_fields.rs b/crates/draw/src/ui/transform/transform_fields.rs index b792fe940..cfc007bbf 100644 --- a/crates/draw/src/ui/transform/transform_fields.rs +++ b/crates/draw/src/ui/transform/transform_fields.rs @@ -503,7 +503,7 @@ impl Cells<'_> { /// inside the field. fn side_and_name(&self, field: TransformField, form: Form) -> (SideLabel, Label) { let words = &self.words; - let beside = |glyph: &Label| SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::text(glyph.clone()))); + let beside = |glyph: &Label| SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::caption(glyph.clone()))); let (side, name) = match field { TransformField::X => (beside(&words.x_glyph), &words.x_name), TransformField::Y => (beside(&words.y_glyph), &words.y_name), diff --git a/crates/ui-contract/src/contract/label.rs b/crates/ui-contract/src/contract/label.rs index b10a44bcb..49da6126c 100644 --- a/crates/ui-contract/src/contract/label.rs +++ b/crates/ui-contract/src/contract/label.rs @@ -13,5 +13,5 @@ mod step; pub use leaf::colon_of; pub(crate) use place::{control_after, label_gap}; pub(crate) use props::inside; -pub use props::{CaptionColumn, CellWidth, FieldLayout, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, Scrub, SideLabel}; +pub use props::{CaptionColumn, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, Scrub, SideLabel}; pub(crate) use step::{LabelIn, LeafLabel, Trailing, flow_leaf, in_column, leaf, leaf_under, report_after_reach, run, show_leaf_in_flow}; diff --git a/crates/ui-contract/src/contract/label/leaf.rs b/crates/ui-contract/src/contract/label/leaf.rs index 671948bf9..3268419fb 100644 --- a/crates/ui-contract/src/contract/label/leaf.rs +++ b/crates/ui-contract/src/contract/label/leaf.rs @@ -1,6 +1,6 @@ //! The side label as a leaf component: its node, press state, reset dot and colon. -use super::props::{FieldLayout, Glyph, LabelKind, LabelScheme}; +use super::props::{FieldLayout, Glyph, GlyphColon, LabelKind, LabelScheme}; use super::step::LabelIn; use crate::contract::InBar; use crate::contract::{Component, Props}; @@ -411,18 +411,20 @@ impl Component for LabelLeaf { } /// The colon a beside label draws after its shown text in a form (`LabelScheme::Form`), unless that text ends in one: -/// a text label's, and in a bar a glyph text's as well ("X:"). An inspector's labels draw none. The label's node and -/// the control keep the name as given. +/// a text label's, in a bar a glyph text's as well ("X:"), and under `GlyphColon::Form` a glyph caption's. An +/// inspector's labels draw none. The label's node and the control keep the name as given. pub(super) fn colon(env: &Env, input: &LabelIn<'_>) -> Option { if input.side.layout != FieldLayout::Beside || env.values.get::() == LabelScheme::Inspector { return None; } let text = match &input.side.kind { LabelKind::Text | LabelKind::Short(_) => env.view().resolve(input.side.kind.shown(input.text)), - LabelKind::Glyph(glyph) if env.values.get::().0 => match glyph.resolved(env.view()) { - Glyph::Text(text) => text, - Glyph::Icon(_) => return None, - }, + LabelKind::Glyph(glyph) if env.values.get::().0 || (glyph.caption && env.values.get::() == GlyphColon::Form) => { + match glyph.resolved(env.view()) { + Glyph::Text(text) => text, + Glyph::Icon(_) => return None, + } + } _ => return None, }; if text.as_str().is_empty() || text.as_str().ends_with([':', '\u{ff1a}']) { diff --git a/crates/ui-contract/src/contract/label/props.rs b/crates/ui-contract/src/contract/label/props.rs index 07d50ddcc..01fd5e9c4 100644 --- a/crates/ui-contract/src/contract/label/props.rs +++ b/crates/ui-contract/src/contract/label/props.rs @@ -48,17 +48,26 @@ pub(super) enum Glyph { #[derive(Clone, Debug, PartialEq)] pub struct GlyphLabel { shown: Glyph, + /// The text stands for a word caption ([`GlyphLabel::caption`]). + pub(super) caption: bool, } impl GlyphLabel { /// Shows `icon`, as large as the control's icons. pub fn icon(icon: impl Into>) -> Self { - GlyphLabel { shown: Glyph::Icon(icon.into()) } + GlyphLabel { shown: Glyph::Icon(icon.into()), caption: false } } /// Shows `text`, resolved in the scope's language. pub fn text(text: impl Into