Label scheme Inline: captions at the row start, controls right after them, no shared column (L-304)

This commit is contained in:
Dylan M. Taylor committed 2026-11-22 01:20:41 -05:00
1 parent 9cea328024
commit b7ef69b8e0
4 files changed
+20 -2

No files matched your search

@@ -398,7 +398,7 @@ impl Component for LabelLeaf {
/// 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.
pub(super) fn colon(env: &Env, input: &LabelIn<'_>) -> Option<String> {
if input.side.layout != FieldLayout::Beside || env.values.get::<LabelScheme>() != LabelScheme::Form {
if input.side.layout != FieldLayout::Beside || env.values.get::<LabelScheme>() == LabelScheme::Inspector {
return None;
}
let text = match &input.side.kind {
@@ -105,8 +105,10 @@ pub(super) fn decide(ctx: &egui::Context, env: &Env, input: &LabelIn<'_>, kids:
let (column, stack_below) = match input.side.layout {
FieldLayout::Beside => {
let own = natural.x;
// An inline form shares no label column: each caption is as wide as its own text.
let shared = env.values.get::<LabelScheme>() != LabelScheme::Inline;
let width = crate::layout::ambient_width(ctx, &if glyph { crate::layout::GLYPHS } else { crate::layout::LABELS }, own)
.filter(|width| *width > 0.0)
.filter(|width| shared && *width > 0.0)
.unwrap_or(own);
(width, width + gap + input.control_min)
}
@@ -81,6 +81,9 @@ pub enum LabelScheme {
Form,
/// An inspector: a beside label sits at the row's start with no colon, and its control fills the rest of the row.
Inspector,
/// A document dialog: a beside label starts at the row's start and ends with a colon, and its control follows it
/// at once, at the control's own width. Labels share no column, so each row reads as one line.
Inline,
}
impl crate::runtime::env::EnvValue for LabelScheme {
@@ -57,6 +57,19 @@ 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:?}");
}
/// 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]
fn an_inline_form_sets_each_control_right_after_its_caption() {
let form = rows(LabelScheme::Form);
let inline = rows(LabelScheme::Inline);
assert_eq!(colons(&inline), 2, "an inline form's captions end with a colon");
assert!((caption(&inline, SHORT).min.x - caption(&inline, LONG).min.x).abs() <= SLACK, "the captions start at the row's start");
let (short, long) = (control(&inline, SHORT), control(&inline, LONG));
assert!(short.min.x + SLACK < long.min.x, "no shared column: the short caption's control comes first: {short:?} {long:?}");
assert!((short.width() - control(&form, SHORT).width()).abs() <= SLACK, "the control keeps its width");
}
fn glyph_field(ui: &mut Ui) {
let side = SideLabel::new().kind(LabelKind::Glyph(GlyphLabel::text("X")));
Field::new("Horizontal position").side(side).show(ui, |ui, _| {