From 4737161b835daea6fb41a43ef53b91aba8da955d Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 11 Nov 2026 23:17:48 +0000 Subject: [PATCH] Content inside a label shows before the label scope opens The size samples in LayersOptionsDialog registered as a second control of their radio's label scope, so the label named the group and left the radio without a name. --- crates/ui-contract/src/contract/body/hooks.rs | 2 +- crates/ui-contract/src/contract/label/step.rs | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index 3cb538229..78b39ae56 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -751,7 +751,7 @@ impl ShapeHooks for BodyHooks<'_> { claims: false, trailing: Vec2::ZERO, }; - body_rect = label::run(ui, env, &input).control; + body_rect = label::run(ui, env, &input, None).control; label_input = Some(input); } let label_extra = label_extra_of(regions.body, body_rect); diff --git a/crates/ui-contract/src/contract/label/step.rs b/crates/ui-contract/src/contract/label/step.rs index 82831490a..1df584fff 100644 --- a/crates/ui-contract/src/contract/label/step.rs +++ b/crates/ui-contract/src/contract/label/step.rs @@ -95,7 +95,7 @@ impl LeafPlaced { } } -/// The label step for one leaf child: measures the child's narrowest width, runs the step in `row`, shows the +/// The label step for one leaf child: measures the child's narrowest width, runs the step in `row` with the /// `trailing` content inside the label and returns the rect left for the child. The caller shows the child there and /// then calls `LeafPlaced::finish`. pub(crate) fn leaf(ui: &mut Ui, env: &Env, at: &LeafLabel<'_>, child: &mut C, trailing: Option>) -> LeafPlaced { @@ -120,17 +120,14 @@ pub(crate) fn leaf(ui: &mut Ui, env: &Env, at: &LeafLabel<'_>, child: & claims: C::LABELLED_AFTER, trailing: trailing.as_ref().map_or(Vec2::ZERO, |trailing| trailing.size), }; - let placed = run(ui, env, &input); - // The content shows before the control, so a control that claims the label lies over it and takes its presses. - if let Some(trailing) = trailing { - (trailing.show)(ui, placed.trailing); - } + let placed = run(ui, env, &input, trailing); LeafPlaced { control: placed.control, label: placed.label, scope } } -/// Runs the label step in `ui`: shows the label, opens the label scope and returns where the label and the control -/// sit. The caller closes the scope with `scope::finish` after the control ran. -pub(crate) fn run(ui: &mut Ui, env: &Env, input: &LabelIn<'_>) -> Placed { +/// Runs the label step in `ui`: shows the label and the `trailing` content inside it (`input.trailing` is its size), +/// opens the label scope and returns where the label and the control sit. The caller closes the scope with +/// `scope::finish` after the control ran. +pub(crate) fn run(ui: &mut Ui, env: &Env, input: &LabelIn<'_>, trailing: Option>) -> Placed { let ctx = ui.ctx().clone(); let rtl = env.direction.is_rtl(); let tokens = &env.tokens; @@ -185,6 +182,11 @@ pub(crate) fn run(ui: &mut Ui, env: &Env, input: &LabelIn<'_>) -> Placed { if let Some(fact) = reset.filter(|_| shown.double_click || shown.dot_click) { keys::route_whole_reset(&ctx, fact.control); } + // The content belongs to the label, not to the controls it names, so it shows before the scope opens. It also + // shows before the control, so a control that claims the label lies over it and takes its presses. + if let Some(trailing) = trailing { + (trailing.show)(ui, placed.trailing); + } let label = field_label(env, input, label_id_for_scope, placed.label).with_press(shown.press).with_hover(shown.hovered).activated(shown.activated); scope::begin(&ctx, input.scope, input.owner, scope::Kind::Label(label));