diff --git a/crates/ui-contract/src/contract/label/leaf.rs b/crates/ui-contract/src/contract/label/leaf.rs index e449920db..f7cafd22e 100644 --- a/crates/ui-contract/src/contract/label/leaf.rs +++ b/crates/ui-contract/src/contract/label/leaf.rs @@ -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 { - if input.side.layout != FieldLayout::Beside || env.values.get::() != LabelScheme::Form { + if input.side.layout != FieldLayout::Beside || env.values.get::() == LabelScheme::Inspector { return None; } let text = match &input.side.kind { diff --git a/crates/ui-contract/src/contract/label/place.rs b/crates/ui-contract/src/contract/label/place.rs index f86ab6e67..57a8c01e9 100644 --- a/crates/ui-contract/src/contract/label/place.rs +++ b/crates/ui-contract/src/contract/label/place.rs @@ -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::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) } diff --git a/crates/ui-contract/src/contract/label/props.rs b/crates/ui-contract/src/contract/label/props.rs index 5f80ba2a3..7d9e326d5 100644 --- a/crates/ui-contract/src/contract/label/props.rs +++ b/crates/ui-contract/src/contract/label/props.rs @@ -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 { diff --git a/crates/ui-widgets/tests/it/label/scheme.rs b/crates/ui-widgets/tests/it/label/scheme.rs index 02aa7be00..a5ec7240c 100644 --- a/crates/ui-widgets/tests/it/label/scheme.rs +++ b/crates/ui-widgets/tests/it/label/scheme.rs @@ -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, _| {