From 747dad4c1ce99ab1748d522d724f6e30a7930e9a Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 24 Nov 2026 22:21:42 +0700 Subject: [PATCH] ui-contract: CaptionInk, an env style value for the ink of a side label's name: Muted (default) or Normal, VectorCraft's field labels as production drew them; Field story field_caption_ink --- crates/ui-contract/src/contract/label.rs | 3 +- crates/ui-contract/src/contract/label/leaf.rs | 9 +++--- .../ui-contract/src/contract/label/props.rs | 15 ++++++++++ crates/ui-contract/src/contract/mod.rs | 4 +-- crates/ui-widgets/src/form/stories.rs | 28 ++++++++++++++++++- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/crates/ui-contract/src/contract/label.rs b/crates/ui-contract/src/contract/label.rs index 236d7bf1a..881564478 100644 --- a/crates/ui-contract/src/contract/label.rs +++ b/crates/ui-contract/src/contract/label.rs @@ -14,6 +14,7 @@ pub use leaf::colon_of; pub(crate) use place::{control_after, label_gap}; pub(crate) use props::inside; pub use props::{ - CaptionColumn, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, LinkLabelInk, Scrub, SideLabel, + CaptionColumn, CaptionInk, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, LinkLabelInk, 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 62274da56..3e0f7cb32 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, GlyphColon, LabelKind, LabelScheme, LinkLabelInk}; +use super::props::{CaptionInk, FieldLayout, Glyph, GlyphColon, LabelKind, LabelScheme, LinkLabelInk}; use super::step::LabelIn; use crate::contract::InBar; use crate::contract::{Component, Props}; @@ -30,8 +30,8 @@ pub(super) struct LabelStyle { gap: f32, /// The detail: `text.muted`, `text.disabled` with a disabled control. detail: Stateful, - /// The name: `TypeRole::Label` in `text.muted`; after a check box or a radio, `TypeRole::Body` in `text.normal`. - /// `text.disabled` with a disabled control. + /// The name: `TypeRole::Label` in the [`CaptionInk`]; after a check box or a radio, `TypeRole::Body` in + /// `text.normal`. `text.disabled` with a disabled control. #[style(text)] name: TextLook, /// The glyph and icon: their own ink (`None`), `text.disabled` with a disabled control. @@ -173,7 +173,8 @@ impl Component for LabelLeaf { // A caption reads as secondary; a check box's or a radio's text after it is the control's own. name: { let text = &cx.tokens.color.text; - let (role, ink) = if key.after { (TypeRole::Body, text.normal) } else { (TypeRole::Label, text.muted) }; + let caption = if cx.env::() == CaptionInk::Normal { text.normal } else { text.muted }; + let (role, ink) = if key.after { (TypeRole::Body, text.normal) } else { (TypeRole::Label, caption) }; let neutral = cx.env::() == LinkLabelInk::Neutral; if key.link && !neutral { // A link label keeps its role, so it takes the room of the caption it is, in the link's ink. diff --git a/crates/ui-contract/src/contract/label/props.rs b/crates/ui-contract/src/contract/label/props.rs index 8e5785bc8..548ed5e22 100644 --- a/crates/ui-contract/src/contract/label/props.rs +++ b/crates/ui-contract/src/contract/label/props.rs @@ -136,6 +136,21 @@ pub enum LinkLabelInk { Neutral, } +/// The ink of a side label's name, other than a link's ([`LinkLabelInk`]) and the text after a check box or a radio, +/// which reads at full ink. An app sets it once at its root (`RootEnv::values`); the default is the muted ink of a +/// caption that reads as secondary. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum CaptionInk { + /// `text.muted`. + #[default] + Muted, + /// `text.normal`, the ink of the values beside it: VectorCraft's field labels ("X:", "Angle:", "Opacity"), as + /// production drew them. + Normal, +} + /// Whether the beside captions of a [`LabelScheme::Inline`] form share one column. Off (the default), each caption is /// as wide as its own text and its control follows it at once. On, the captions keep to the row start in one column as /// wide as the widest, so the controls after them line up (production's Rotate Pages dialog: Direction:, Pages: and diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 9ba2a3a73..e0ddf2ff5 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -93,8 +93,8 @@ pub use items::{measure_item, show_item, show_item_in_flow}; #[doc(hidden)] pub use label::colon_of; pub use label::{ - CaptionColumn, CellWidth, FieldLabelRole, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, LinkLabelInk, - Scrub, SideLabel, + CaptionColumn, CaptionInk, CellWidth, FieldLabelRole, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, + LinkLabelInk, Scrub, SideLabel, }; pub use lazy::Lazy; #[doc(hidden)] diff --git a/crates/ui-widgets/src/form/stories.rs b/crates/ui-widgets/src/form/stories.rs index 6531e98b4..94eb9530f 100644 --- a/crates/ui-widgets/src/form/stories.rs +++ b/crates/ui-widgets/src/form/stories.rs @@ -5,7 +5,8 @@ use super::{Field, FieldGroup}; use crate::buttons::Link; use crate::choice::Swatch; use crate::contract::{ - FieldLayout, GlyphColon, GlyphLabel, LabelKind, LabelScheme, LinkLabelInk, Props as _, Show as _, ShowContainer as _, SideLabel, Validity, + CaptionInk, FieldLayout, GlyphColon, GlyphLabel, LabelKind, LabelScheme, LinkLabelInk, Props as _, Show as _, ShowContainer as _, SideLabel, + Validity, }; use crate::layout_components::{Row, Stack}; use crate::runtime::env::{Message, with_env}; @@ -86,6 +87,31 @@ fn field_link_label_ink(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { StoryOutput { clicked: accent || neutral, ..StoryOutput::default() } } +/// A field's label under each `CaptionInk`, enabled and disabled: the muted ink (the default), then the normal ink +/// VectorCraft sets at its root. A disabled label reads in the disabled ink under both. +#[story(Field, covers = [], drive = Drive::Never)] +fn field_caption_ink(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let mut rows = |ui: &mut Ui, key: &'static str| { + Stack::new().id_salt(key).show(ui, |ui, _| { + for (salt, enabled) in [("enabled", true), ("disabled", false)] { + Field::new("Angle") + .id_salt(salt) + .enabled(enabled) + .show(ui, |ui, _| NumberField::new("Angle", data.bind(key, Some(SIZE))).unit("°").show(ui)); + } + }); + }; + rows(ui, "muted"); + with_env( + ui, + |overrides| { + overrides.values.set(CaptionInk::Normal); + }, + |ui| rows(ui, "normal"), + ); + StoryOutput::default() +} + /// A glyph label: the icon shows, the text only names the control. #[story(Field, covers = [], drive = Drive::Never)] fn field_icon_label(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {