diff --git a/crates/ui-contract/src/contract/label.rs b/crates/ui-contract/src/contract/label.rs index 49da6126c..236d7bf1a 100644 --- a/crates/ui-contract/src/contract/label.rs +++ b/crates/ui-contract/src/contract/label.rs @@ -13,5 +13,7 @@ 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, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, Scrub, SideLabel}; +pub use props::{ + CaptionColumn, 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 3268419fb..62274da56 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}; +use super::props::{FieldLayout, Glyph, GlyphColon, LabelKind, LabelScheme, LinkLabelInk}; use super::step::LabelIn; use crate::contract::InBar; use crate::contract::{Component, Props}; @@ -174,10 +174,13 @@ impl Component for LabelLeaf { name: { let text = &cx.tokens.color.text; let (role, ink) = if key.after { (TypeRole::Body, text.normal) } else { (TypeRole::Label, text.muted) }; - if key.link { + 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. TextLook { role, ..cx.link_look(true) } } else { + // A neutral link label reads in the body ink; its underline still marks it. + let ink = if key.link { text.normal } else { ink }; let (ink, off) = (cx.color(ink), cx.color(text.disabled)); TextLook::new(role, Stateful::new(ink).off(States::new(ink, ink, ink, off))) } diff --git a/crates/ui-contract/src/contract/label/props.rs b/crates/ui-contract/src/contract/label/props.rs index 01fd5e9c4..8e5785bc8 100644 --- a/crates/ui-contract/src/contract/label/props.rs +++ b/crates/ui-contract/src/contract/label/props.rs @@ -121,6 +121,21 @@ impl crate::runtime::env::EnvValue for GlyphColon { } } +/// The ink of a field's label shown as a link ([`SideLabel::link`]), which opens its control's options. An app sets it +/// once at its root (`RootEnv::values`); the default is the link look's accent. Either way it stays underlined, so +/// colour is not its only cue. A free `Link` keeps the accent: one that opens options asks for `Tone::Neutral`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum LinkLabelInk { + /// The link look (`StyleCx::link_look`): `accent.solid`, `accent.text` at high contrast. + #[default] + Accent, + /// `text.normal`, the ink of a `Link` in `Tone::Neutral`: VectorCraft's "Opacity:" and "Stroke" labels, as + /// production drew them. + Neutral, +} + /// 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 eb92e07be..cb309b921 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -93,7 +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, Scrub, SideLabel, + CaptionColumn, 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 7a8c6259c..6531e98b4 100644 --- a/crates/ui-widgets/src/form/stories.rs +++ b/crates/ui-widgets/src/form/stories.rs @@ -2,9 +2,12 @@ use super::Help; use super::{Field, FieldGroup}; +use crate::buttons::Link; use crate::choice::Swatch; -use crate::contract::{FieldLayout, GlyphColon, GlyphLabel, LabelKind, LabelScheme, Show as _, ShowContainer as _, SideLabel, Validity}; -use crate::layout_components::Row; +use crate::contract::{ + 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}; use crate::testing::{Drive, StoryData, StoryOutput, story}; use crate::text::{HexField, NumberField}; @@ -49,6 +52,40 @@ fn field_link_label(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { StoryOutput { clicked: facts.clicked || link, ..facts } } +/// A field's link label under each `LinkLabelInk`, each with a free link to options under it: the accent (the default) +/// with a plain `Link`, then the body ink VectorCraft sets at its root with a `Link` in `Tone::Neutral`, the same ink. +/// Both stay underlined. +#[story(Field, covers = [], drive = Drive::Never)] +fn field_link_label_ink(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let mut rows = |ui: &mut Ui, key: &'static str, tone: Option| { + Stack::new() + .id_salt(key) + .show(ui, |ui, _| { + let side = SideLabel::new().link(); + let field = Field::new("Opacity").side(side).show(ui, |ui, _| NumberField::new("Opacity", data.bind(key, Some(100.0))).show(ui)); + let link = Link::new("Stroke"); + let link = match tone { + Some(tone) => link.tone(tone), + None => link, + } + .show(ui); + // The field the label names reports the link click; the story is its host. + field.inner.as_ref().is_some_and(|field| field.link) || link.clicked() + }) + .inner + == Some(true) + }; + let accent = rows(ui, "accent", None); + let neutral = with_env( + ui, + |overrides| { + overrides.values.set(LinkLabelInk::Neutral); + }, + |ui| rows(ui, "neutral", Some(Tone::Neutral)), + ); + StoryOutput { clicked: accent || neutral, ..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 {