Labels: LabelGap env value for a property list's value column

LabelGap::Section sets beside controls a section gap past the label
column, so a readout's value does not run into its name; Inline (the
root) keeps space.gap.inline. Bars keep space.gap.item. Story and trial.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-29 21:15:02 +00:00
1 parent 9ee16bf740
commit dc39554e8b
6 files changed
+89 -11

No files matched your search

+2 -2
View File
@@ -14,7 +14,7 @@ pub use leaf::colon_of;
pub(crate) use place::{control_after, label_gap};
pub(crate) use props::inside;
pub use props::{
CaptionColumn, CaptionInk, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, LinkLabelInk,
LinkLabelUnderline, Scrub, SideLabel,
CaptionColumn, CaptionInk, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelGap, LabelKind, LabelPress, LabelScheme,
LinkLabelInk, LinkLabelUnderline, 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,7 +1,7 @@
//! Where the label and its control sit: the beside, above and after placements and the gap.
use super::leaf::{LabelLeaf, colon};
use super::props::{CaptionColumn, FieldLayout, LabelKind, LabelScheme};
use super::props::{CaptionColumn, FieldLayout, LabelGap, LabelKind, LabelScheme};
use super::step::LabelIn;
use crate::contract::Show;
use crate::runtime::access::scope::{self};
@@ -232,10 +232,16 @@ fn widened(flow: Flow, need: f32, grows: Grows) -> Flow {
Flow::new(wide, flow.is_rtl())
}
/// The gap between a label and its control: `space.gap.inline`, `space.gap.item` inside a bar.
/// The gap between a label and its control: `space.gap.item` inside a bar, else the scope's [`LabelGap`].
pub(crate) fn label_gap(env: &Env) -> f32 {
let gaps = &env.tokens.space.gap;
if env.values.get::<crate::contract::container::InBar>().0 { gaps.item } else { gaps.inline }
if env.values.get::<crate::contract::container::InBar>().0 {
return gaps.item;
}
match env.values.get::<LabelGap>() {
LabelGap::Inline => gaps.inline,
LabelGap::Section => gaps.section,
}
}
/// Where the control sits once `input.control_min` is known: the decision `run` takes, without showing the label. A
@@ -191,6 +191,25 @@ impl crate::runtime::env::EnvValue for CaptionColumn {
}
}
/// The gap between a beside label's column and its control, outside a bar (a bar's labels keep `space.gap.item`). A
/// container sets it for what it holds (`with_env`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, crate::contract::MemoProps)]
#[non_exhaustive]
pub enum LabelGap {
/// `space.gap.inline`: the label reads with its control, as in a panel or a dialog.
#[default]
Inline,
/// `space.gap.section`: a page's property list, whose values stand in their own column apart from the names
/// (DeckCraft's Info page).
Section,
}
impl crate::runtime::env::EnvValue for LabelGap {
fn root() -> Self {
LabelGap::Inline
}
}
/// Where a side label sits relative to its control.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[non_exhaustive]
+2 -2
View File
@@ -98,8 +98,8 @@ pub use items::{measure_item, show_item, show_item_in_flow};
#[doc(hidden)]
pub use label::colon_of;
pub use label::{
CaptionColumn, CaptionInk, CellWidth, FieldLabelRole, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme,
LinkLabelInk, LinkLabelUnderline, Scrub, SideLabel,
CaptionColumn, CaptionInk, CellWidth, FieldLabelRole, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelGap, LabelKind, LabelPress,
LabelScheme, LinkLabelInk, LinkLabelUnderline, Scrub, SideLabel,
};
pub use lazy::Lazy;
#[doc(hidden)]
+23 -3
View File
@@ -5,13 +5,14 @@ use super::{Field, FieldGroup};
use crate::buttons::Link;
use crate::choice::Swatch;
use crate::contract::{
CaptionInk, FieldLayout, GlyphColon, GlyphLabel, LabelKind, LabelScheme, LinkLabelInk, Props as _, Show as _, ShowContainer as _, SideLabel,
Validity,
CaptionInk, FieldLayout, GlyphColon, GlyphLabel, LabelGap, LabelKind, LabelScheme, LinkLabelInk, Props as _, Show as _, ShowContainer as _,
SideLabel, Validity,
};
use crate::display::Text;
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};
use crate::text::{HexField, NumberField, TextField};
use craft_behavior::IconId;
use craft_theme::Srgba;
use craft_theme::variant::Tone;
@@ -191,6 +192,25 @@ fn field_glyph_captions_with_colons(ui: &mut Ui, data: &mut StoryData) -> StoryO
.into()
}
/// A page's property list under `LabelGap::Section`: the values stand in their own column, a section gap past the
/// widest name, so a value never reads as part of its name.
#[story(FieldGroup, covers = [], drive = Drive::Never)]
fn field_property_list_gap(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
with_env(
ui,
|overrides| {
overrides.values.set(LabelGap::Section);
},
|ui| {
FieldGroup::new("Properties").labels(LabelScheme::Inspector).show(ui, |ui, _| {
Field::new("Hidden slides").value("0").show(ui, |ui, _| Text::new("0").show(ui));
Field::new("Title").show(ui, |ui, _| TextField::new("Title", data.bind("title", String::new())).placeholder("Add a title").show(ui));
})
},
)
.into()
}
/// The rows of an inspector: glyph labels W and H sharing a row, word labels at the row's start without a colon, and
/// controls that fill the rest of the row.
#[story(FieldGroup, covers = [], drive = Drive::Never)]
+34 -1
View File
@@ -2,8 +2,11 @@
use craft_ui::bars::{Bar, BarKind};
use craft_ui::choice::{Checkbox, Radio, RadioGroup};
use craft_ui::contract::{Bind, FieldLayout, GlyphColon, GlyphLabel, LabelKind, LabelScheme, Props as _, Show as _, ShowContainer as _, SideLabel};
use craft_ui::contract::{
Bind, FieldLayout, GlyphColon, GlyphLabel, LabelGap, LabelKind, LabelScheme, Props as _, Show as _, ShowContainer as _, SideLabel,
};
use craft_ui::form::{Field, FieldGroup};
use craft_ui::runtime::env::with_env;
use craft_ui::testing::{Fixture, trial};
use craft_ui::text::{HexField, NumberField};
use egui::{Rect, Ui};
@@ -57,6 +60,36 @@ fn a_form_and_an_inspector_lay_out_the_same_rows_their_own_way() {
assert!(short.width() > kept.width() + SLACK, "an inspector's control fills the row, a form's keeps its width: {short:?} {kept:?}");
}
/// Under `LabelGap::Section` an inspector's controls stand farther from the widest caption than under the default
/// gap, so a readout's value does not run into its name.
#[trial]
fn a_section_label_gap_sets_the_controls_apart_from_the_widest_caption() {
let gap = |wide: LabelGap| {
let mut fixture = Fixture::new(move |ui| {
with_env(
ui,
|overrides| {
overrides.values.set(wide);
},
|ui| {
FieldGroup::new("Shape").labels(LabelScheme::Inspector).show(ui, |ui, _| {
for name in [SHORT, LONG] {
Field::new(name).show(ui, |ui, _| {
NumberField::new(name, Bind::given(Some(8.0))).show(ui);
});
}
})
},
);
});
fixture.settle();
control(&fixture, LONG).min.x - caption(&fixture, LONG).max.x
};
let (inline, section) = (gap(LabelGap::Inline), gap(LabelGap::Section));
assert!(inline >= 0.0, "the control follows its caption: {inline}");
assert!(section > inline + SLACK, "the section gap sets the control farther off: {section} against {inline}");
}
/// An inline form sets each caption at the row's start with a colon, its control right after it at its own width: the
/// controls share no column.
#[trial]