From 8a2729d7c8f8f8ccac77c38bba93de9797de7dcf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 21:33:54 -0800 Subject: [PATCH] form_dialogs: a radio row's options start in the control column In a form whose rows share a label column, a radio row started at the form's left edge, in the label column, while the check boxes and the fields of the other rows started past it. A radio group lays out apart from the label column of the form around it, so its radios never read the column. A radio row now shows its group in a field with a hidden caption, in each of its three layouts (a caption over the options, stacked_options and options_in_row), so the first radio starts where a check box row starts. A radio row in a shared line and a row nested under an option stand where they stood. A document form without a shared caption column is unchanged. The new test shows a text row, a check box row and a radio row in each layout, and compares where the check box label and the first option start. --- .../src/patterns/form_dialogs/rows.rs | 27 ++++++++++++++++--- .../tests/it/form_dialogs/params.rs | 24 +++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs index 277316e071..fbfce2508a 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs @@ -480,6 +480,24 @@ impl Line<'_> { }); } + /// Shows `body` in a field named by the row with its caption hidden: where the rows of the form share a label + /// column, `body` starts past that column, where the controls of the captioned rows and the check boxes start. A + /// `bare` row and a row in a shared line show `body` where they stand. + fn show_uncaptioned(&self, ui: &mut Ui, mut body: impl FnMut(&mut Ui)) { + if self.bare || self.compact { + body(ui); + return; + } + let env = Env::of(ui); + let view = env.view(); + let own_caption = view.get::() == LabelScheme::Inline && !view.get::().shared(); + let mut field = Field::new(self.name.clone()).id_salt(self.key).enabled(self.enabled).side(SideLabel::new().kind(LabelKind::Hidden)); + if own_caption { + field = field.layout(FieldLayout::Above); + } + field.show(ui, |ui, _| body(ui)); + } + /// The help button after a row's control: a press is noted for the pass, which reports the row's link. fn help_button(&self, ui: &mut Ui) { let help = Env::of(ui).words::().help.clone(); @@ -1197,15 +1215,16 @@ impl<'p> Pass<'p> { } /// A radio row is its own section: the title shows the row's name once, and the group it names follows. A row with - /// [`options_in_row`](Param::options_in_row) has no title and stands its options side by side. + /// [`options_in_row`](Param::options_in_row) has no title and stands its options side by side. In a form whose + /// rows share a label column, the options start in the control column ([`Line::show_uncaptioned`]). fn radio_options(&mut self, ui: &mut Ui, line: &Line<'_>, options: &[(String, Label)], details: &[Label]) { let inline = Env::of(ui).view().get::() == LabelScheme::Inline; if line.param.option().options_in_row() { - self.radio_group(ui, line, options, details, true); + line.show_uncaptioned(ui, |ui| self.radio_group(ui, line, options, details, true)); return; } if line.param.option().stacked_options() { - self.radio_group(ui, line, options, details, false); + line.show_uncaptioned(ui, |ui| self.radio_group(ui, line, options, details, false)); return; } // A document dialog sets the caption and its options on one line, as production's do; the caption is left out @@ -1221,7 +1240,7 @@ impl<'p> Pass<'p> { return; } Section::fixed(line.name.clone()).strength(HeaderStrength::Caption).id_salt(line.key).show(ui, |ui, _| { - self.radio_group(ui, line, options, details, false); + line.show_uncaptioned(ui, |ui| self.radio_group(ui, line, options, details, false)); }); } diff --git a/crates/ui-patterns/tests/it/form_dialogs/params.rs b/crates/ui-patterns/tests/it/form_dialogs/params.rs index 379139f48b..2ccc18a1fd 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/params.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/params.rs @@ -334,6 +334,30 @@ fn a_radio_row_in_a_row_stands_its_options_side_by_side_without_a_caption() { assert_eq!(values.borrow().text("layout"), Some("horizontal")); } +// In a form whose rows share a label column, the options of a radio row start where the label of a check box row +// starts, past the label column, in each of the row's layouts. +#[trial] +fn a_radio_rows_options_start_in_the_control_column() { + let pages = || ParamKind::radio(vec![("all".into(), "All".into()), ("range".into(), "Range".into())], Some("all".into())); + let layouts = [ + ("captioned", Param::new("pages", "Pages", pages())), + ("stacked", Param::new("pages", "Pages", pages()).stacked_options()), + ("in a row", Param::new("pages", "Pages", pages()).options_in_row()), + ]; + for (layout, radio) in layouts { + let values = Rc::new(RefCell::new(DialogFields::new())); + let params = vec![Param::new("title", "A long caption", ParamKind::text("")), Param::new("keep", "Keep", ParamKind::bool(false)), radio]; + let fixture = rows(params, &values); + let left = |text: &str| { + let painted = fixture.texts().iter().find(|painted| painted.text == text).unwrap_or_else(|| panic!("{layout}: the text {text}")); + painted.rect.left() + }; + let (caption, check, option) = (left("A long caption"), left("Keep"), left("All")); + assert!(check > caption + 1.0, "{layout}: the check box row starts past the label column: {check} against {caption}"); + assert!((option - check).abs() < 0.5, "{layout}: the first option starts where the check box row starts: {option} against {check}"); + } +} + // A text row with `field_chars` asks for that many characters instead of the field length: a wide row's field is wider // than a plain row's, and `0` keeps the field length. #[trial]