mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
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
This commit is contained in:
@@ -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};
|
||||
|
||||
@@ -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<StyleColor>,
|
||||
/// 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>() == 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>() == 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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user