From 2bad4aebd53a11983332f0194120f321ddf322cb Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 12:33:18 +0700 Subject: [PATCH] ui-contract: a field label without text names no control, so a custom row with an empty label leaves its control the name its own label gives it --- .../ui-contract/src/runtime/access/scope.rs | 9 ++++++--- crates/ui-widgets/tests/it/buttons.rs | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/src/runtime/access/scope.rs b/crates/ui-contract/src/runtime/access/scope.rs index c3c83e1c4..bb2ae60f6 100644 --- a/crates/ui-contract/src/runtime/access/scope.rs +++ b/crates/ui-contract/src/runtime/access/scope.rs @@ -521,13 +521,15 @@ pub(crate) enum LabelPatch { /// What `label` does to the `nodes` registered in the scope of `container`: one control is labelled by it /// (described by it when the control keeps its own name or the label describes), several make the container's node -/// labelled by it, none leaves everything alone. A label with no node of its own names its one control by its text, -/// or joins the control's description, and leaves the container its own name. +/// labelled by it, none, or a label without text, leaves everything alone. A label with no node of its own names its +/// one control by its text, or joins the control's description, and leaves the container its own name. pub(crate) fn label_patches(container: Id, label: &FieldLabel, nodes: &[ScopeNode]) -> Vec { if nodes.is_empty() { return Vec::new(); } - let own = label.shown.then_some(label.id); + // A label without text has nothing to name or describe: the controls keep their own names. + let named = !label.text.is_empty(); + let own = label.shown.then_some(label.id).filter(|_| named); let mut patches: Vec = own.map(|id| LabelPatch::Label { id, text: label.text.clone(), disabled: nodes.iter().all(|node| node.disabled) }).into_iter().collect(); // The label is about one control only when that control sits directly in the scope. One in an unlabelled row is @@ -538,6 +540,7 @@ pub(crate) fn label_patches(container: Id, label: &FieldLabel, nodes: &[ScopeNod _ => None, }; match (single, own) { + _ if !named => {} (Some(only), Some(own)) if label.role == FieldLabelRole::Describes || only.keeps_name => { patches.push(LabelPatch::DescribedBy { node: only.id, label: own }); } diff --git a/crates/ui-widgets/tests/it/buttons.rs b/crates/ui-widgets/tests/it/buttons.rs index 9d74da886..ce534c73f 100644 --- a/crates/ui-widgets/tests/it/buttons.rs +++ b/crates/ui-widgets/tests/it/buttons.rs @@ -797,3 +797,22 @@ fn a_toggle_button_reports_pressed_on_and_off() { assert_eq!(tree.toggled_of(NodeKey::of(plain)), None, "a plain button has no pressed state"); } } + +/// An icon-only toggle button in a field with no label text (a dialog's custom row with an empty label), beside an egui +/// check box in an `egui::Grid`, keeps the name its own label gives it. +#[trial] +fn an_icon_only_toggle_in_a_field_without_label_text_keeps_its_name() { + let mut fixture = Fixture::new(|ui| { + craft_ui::form::Field::new("").show(ui, |ui, _| { + egui::Grid::new("inks").num_columns(2).show(ui, |ui| { + let mut print = true; + ui.add(egui::Checkbox::without_text(&mut print)); + let _ = ToggleButton::new("Convert Cyan to process", Bind::given(false)).icon(IconId::new("eye")).icon_only().show(ui); + ui.end_row(); + }); + }); + }); + fixture.settle(); + let toggle = fixture.by_label("Convert Cyan to process").expect("the toggle keeps its name"); + assert!(fixture.by_role(Role::BUTTON).iter().any(|button| button.node == toggle.node), "the named node is the toggle button"); +}