From 9b1bb1a4aec49fae6d59d24ce03de3df16711275 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 17:07:55 +0000 Subject: [PATCH 1/2] Label scope: controls inside layout-only containers are direct controls of the label; static texts are not controls --- .../ui-contract/src/contract/steps/report.rs | 6 +- crates/ui-contract/src/runtime/access/emit.rs | 1 + .../ui-contract/src/runtime/access/scope.rs | 55 ++++++++++++++----- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/crates/ui-contract/src/contract/steps/report.rs b/crates/ui-contract/src/contract/steps/report.rs index 9e63e7f27..2dd8a846d 100644 --- a/crates/ui-contract/src/contract/steps/report.rs +++ b/crates/ui-contract/src/contract/steps/report.rs @@ -125,7 +125,10 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_> } scope::finish(ctx, id, None); let carried = scope::carried_name(ctx, id); - let Role::Node(role) = role else { return }; + let Role::Node(role) = role else { + scope::leave(ctx, id); + return; + }; if !input.node { return; } @@ -164,6 +167,7 @@ fn report_access(p: &dyn ErasedPass<'_>, facts: &TypeFacts, input: &ReportIn<'_> if let Some(owner) = inner_of { // Shown as the owner's control: the owner's node is the one node, and stands for this root's key focus. access::hide(ctx, id); + scope::leave(ctx, id); access::fold::offer(ctx, owner, access::fold::Folded { inner: id, value: access.value.clone() }); if flags.contains(Flags::FOCUSED) { access::set_focus(ctx, owner); diff --git a/crates/ui-contract/src/runtime/access/emit.rs b/crates/ui-contract/src/runtime/access/emit.rs index a398579e6..5d44b14e3 100644 --- a/crates/ui-contract/src/runtime/access/emit.rs +++ b/crates/ui-contract/src/runtime/access/emit.rs @@ -329,6 +329,7 @@ pub(crate) fn report(ctx: &Context, own: &Own<'_>) { unnamed, inner_stop: None, disabled: !own.enabled, + display: own.display, }, ); } diff --git a/crates/ui-contract/src/runtime/access/scope.rs b/crates/ui-contract/src/runtime/access/scope.rs index 999882d85..3a7bfa2ab 100644 --- a/crates/ui-contract/src/runtime/access/scope.rs +++ b/crates/ui-contract/src/runtime/access/scope.rs @@ -127,8 +127,14 @@ struct Scope { /// The component whose eviction takes the facts the scope records. owner: Id, kind: Kind, - /// The direct controls: node components inside this scope that sit in no other node component of it. + /// The direct controls, decided when the scope closes: node components inside this scope that sit in no other + /// component that has a node. nodes: Vec, + /// Every node component that reported inside this scope, with the node components that were open around it. + reported: Vec<(ScopeNode, Vec)>, + /// Node components that began as a node at step 8 and turned out to have none at step 16 (a layout container + /// with no label): the controls inside them are direct controls of the scope. + hollow: Vec, /// Node components inside this scope whose step 16 has not come yet, outermost first, with the number of focus stops /// registered before they began. open: Vec<(Id, usize)>, @@ -168,6 +174,8 @@ pub(crate) struct ScopeNode { pub inner_stop: Option, /// The control is disabled: a label that names only disabled controls is disabled too. pub disabled: bool, + /// The node is static display (a text): it is no control of the scope. + pub display: bool, } /// What a control tells its label scope about its reset (10.2). @@ -206,6 +214,8 @@ pub(crate) fn begin(ctx: &Context, container: Id, owner: Id, kind: Kind) { owner, kind, nodes: Vec::new(), + reported: Vec::new(), + hollow: Vec::new(), open: Vec::new(), control_top: 0.0, first_bottom: None, @@ -240,29 +250,39 @@ pub(crate) fn enter(ctx: &Context, id: Id) { }); } -/// Registers the node `id` with the innermost scope at its step 16, when no other node component of the scope -/// holds it. Children reach step 16 first, so they find their parent still open. +/// Registers the node `id` with the innermost scope at its step 16. Children reach step 16 first, so they find their +/// parent still open. Whether it is a direct control is decided when the scope closes, once every node component +/// around it has said whether it has a node (`leave`). pub(crate) fn register(ctx: &Context, mut node: ScopeNode) { let unnamed = pass_state::with::(ctx, |stack| { let Some(scope) = stack.0.last_mut() else { return node.unnamed.take() }; - let direct = match scope.open.iter().rposition(|(open, _)| *open == node.id) { + let around = match scope.open.iter().rposition(|(open, _)| *open == node.id) { Some(at) => { node.inner_stop = crate::runtime::focus::first_stop_inside(ctx, node.id, scope.open[at].1); + let around = scope.open[..at].iter().map(|(open, _)| *open).collect(); scope.open.truncate(at); - at == 0 + around } - None => scope.open.is_empty(), + None => scope.open.iter().map(|(open, _)| *open).collect(), }; - if direct { - scope.nodes.push(node); - None - } else { - node.unnamed.take() - } + scope.reported.push((node, around)); + None }); report_unnamed(ctx, unnamed); } +/// Notes that the node component `id`, which began as a node at step 8, reports none at step 16. +pub(crate) fn leave(ctx: &Context, id: Id) { + pass_state::with::(ctx, |stack| { + if let Some(scope) = stack.0.last_mut() + && let Some(at) = scope.open.iter().rposition(|(open, _)| *open == id) + { + scope.open.truncate(at); + scope.hollow.push(id); + } + }); +} + fn report_unnamed(ctx: &Context, unnamed: Option) { if let Some(finding) = unnamed { emit::report_finding(ctx, finding); @@ -549,7 +569,16 @@ pub(crate) fn finish(ctx: &Context, container: Id, merged: Option) { let scope = pass_state::with::(ctx, |stack| { (stack.0.last().is_some_and(|scope| scope.container == container)).then(|| stack.0.pop()).flatten() }); - let Some(scope) = scope else { return }; + let Some(mut scope) = scope else { return }; + for (node, around) in std::mem::take(&mut scope.reported) { + // A label scope's controls are not its static texts; a merged container shows whatever one component it has. + let counts = !node.display || matches!(scope.kind, Kind::Merge); + if counts && around.iter().all(|id| scope.hollow.contains(id)) { + scope.nodes.push(node); + } else { + report_unnamed(ctx, node.unnamed); + } + } match scope.kind { Kind::Label(label) => { let patches = label_patches(scope.container, &label, &scope.nodes); From e6f337caa1c006f80df9c9567697f6724745a0a2 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 17:07:55 +0000 Subject: [PATCH 2/2] Controls that show their own text keep their name in a labelled row (output path link, preset buttons) --- .../ui-patterns/src/patterns/form_dialogs/export/path_row.rs | 3 ++- crates/ui-patterns/src/patterns/presets/named.rs | 4 ++-- crates/ui-widgets/tests/it/label/baseline.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs b/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs index 3de925cd8..a80597ff4 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/export/path_row.rs @@ -111,7 +111,8 @@ impl<'a> OutputPathRow<'a> { editing = match std::mem::take(&mut editing) { Editing::Off => { let shown = if current.is_empty() { words.browse.clone() } else { Label::from(current.clone()) }; - let link = Link::new(shown).wrap(Wrap::ElidePath).tooltip(words.edit_template.clone()).id_salt("file").show(ui); + let link = + Link::new(shown).wrap(Wrap::ElidePath).tooltip(words.edit_template.clone()).keeps_name(true).id_salt("file").show(ui); if !clicked(&link) { Editing::Off } else if link.mods.alt { diff --git a/crates/ui-patterns/src/patterns/presets/named.rs b/crates/ui-patterns/src/patterns/presets/named.rs index ef92e4272..b5e03f2ed 100644 --- a/crates/ui-patterns/src/patterns/presets/named.rs +++ b/crates/ui-patterns/src/patterns/presets/named.rs @@ -299,11 +299,11 @@ impl<'a, K: Value + Eq + Hash + 'static> NamedPresetRow<'a, K> { NamedPresetStyle::Buttons => { for command in files.map(PresetFiles::commands).unwrap_or_default() { let enabled = files.is_some_and(|files| files.enabled(command, held.as_ref())); - if clicked(&Button::new(Label::Empty).command(command).enabled(enabled).show(ui)) { + if clicked(&Button::new(Label::Empty).command(command).keeps_name(true).enabled(enabled).show(ui)) { asked.push(Ask::File(command)); } } - let _ = Button::new(Label::Empty).command(NamedPresetCommands::New).show(ui); + let _ = Button::new(Label::Empty).command(NamedPresetCommands::New).keeps_name(true).show(ui); if let Some(field) = &field { let _ = Menu::new(words.more.clone()).opened_by(field, Trigger::Context).show(ui, |ui, _| { let _ = MenuItem::command(NamedPresetCommands::Rename).show(ui); diff --git a/crates/ui-widgets/tests/it/label/baseline.rs b/crates/ui-widgets/tests/it/label/baseline.rs index 73af3072c..6982fb900 100644 --- a/crates/ui-widgets/tests/it/label/baseline.rs +++ b/crates/ui-widgets/tests/it/label/baseline.rs @@ -63,7 +63,7 @@ fn a_side_label_stays_on_the_first_line_of_its_control() { let fixture = settled_in(|ui| { Field::new("Light theme").show(ui, |ui, _| { Stack::new().show(ui, |ui, _| { - Swatch::new("Light", GREY).show(ui); + Swatch::new("Light", GREY).keeps_name(true).show(ui); Text::new("Active").show(ui); }); });