From dc817ed512e71abe3c5d3517cbdb824a37d616f7 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 04:21:09 +0000 Subject: [PATCH] B15 phase 3 fixes: the picker caption row is ListRow::caption (ListRow already has a heading prop); a click on a row a collection does not take keeps the layers open; a new right-click moves an open context menu to the pointer; an open menu blocks only the tooltips outside it; Menu runs the row Enter names on its own key activation; trials adjusted (submenu rect, bar shortcut and Help search on a scoped command) --- .../ui-contract/src/contract/items/press.rs | 11 +++ .../src/contract/overlay/container_open.rs | 3 +- .../ui-contract/src/contract/overlay/host.rs | 12 ++- crates/ui-contract/src/contract/tooltip.rs | 8 +- crates/ui-contract/src/runtime/overlay.rs | 10 +- crates/ui-widgets/src/list/row.rs | 8 +- crates/ui-widgets/src/list/row/show.rs | 12 +-- crates/ui-widgets/src/menu/popup.rs | 9 +- crates/ui-widgets/src/pickers/rows.rs | 2 +- crates/ui-widgets/src/text/number/popups.rs | 2 +- crates/ui-widgets/tests/it/menu/pick_focus.rs | 97 +++++++++++++++---- crates/ui-widgets/tests/it/menu/submenus.rs | 3 +- 12 files changed, 135 insertions(+), 42 deletions(-) diff --git a/crates/ui-contract/src/contract/items/press.rs b/crates/ui-contract/src/contract/items/press.rs index 23e57a865..d45b7a1af 100644 --- a/crates/ui-contract/src/contract/items/press.rs +++ b/crates/ui-contract/src/contract/items/press.rs @@ -53,6 +53,17 @@ impl ItemsHooks<'_, '_, C> { if layout.mirrors() && rtl { flow.to_physical(Rect::from_min_size(at, Vec2::ZERO)).min } else { at } }; let mods_now = crate::runtime::pointer::frame(&ctx).mods; + // A click on a row the collection does not take (a caption, a disabled row) is no pick: the layers around the + // collection (a dropdown's list) stay open. + if cx.core.activation.as_ref().is_some_and(|activation| !activation.by_key) + && let Some(pos) = crate::runtime::pointer::frame(&ctx).pos + && local(pos).y >= 0.0 + && layout + .hit(local(pos), offset) + .is_some_and(|at| !self.source.enabled(at) || (self.source.is_section(at) && !self.source.section_stop(at))) + { + cx.keep_open(); + } self.pressed = match cx.core.press.phase { PressPhase::Down { start, .. } | PressPhase::Held { start, .. } if start.button == craft_behavior::PointerButton::Primary && local(start.origin).y >= 0.0 => diff --git a/crates/ui-contract/src/contract/overlay/container_open.rs b/crates/ui-contract/src/contract/overlay/container_open.rs index 165de3212..2d470d779 100644 --- a/crates/ui-contract/src/contract/overlay/container_open.rs +++ b/crates/ui-contract/src/contract/overlay/container_open.rs @@ -30,7 +30,8 @@ pub(crate) fn opener_open(stage: &mut MemoryStage, first: &Opener) -> bool { let slot = stage.session::(sub(first.id, "opens")); if let Some(opener) = first.all().find(|opener| opener.fired) { if slot.applied != frame { - slot.open = !slot.open; + // A context request opens, also over the open layer: a new right-click moves it to the pointer. + slot.open = opener.trigger == Trigger::Context || !slot.open; slot.by = Some((opener.id, opener.trigger, opener.opening)); } slot.applied = frame; diff --git a/crates/ui-contract/src/contract/overlay/host.rs b/crates/ui-contract/src/contract/overlay/host.rs index c53984d06..98f19d7df 100644 --- a/crates/ui-contract/src/contract/overlay/host.rs +++ b/crates/ui-contract/src/contract/overlay/host.rs @@ -1,7 +1,7 @@ //! The overlay host: shows a layer on an egui layer, remembers it while shown and closes its family. use super::dismissal::dismissal; -use super::opener::Opening; +use super::opener::{Opening, Trigger}; use super::place::{OverlayFit, Place}; use super::placement::{anchor_rect, opened_overlay, placement}; use super::props::{Outside, Overlay}; @@ -117,6 +117,16 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U // A layer that appears starts with nothing it remembered while shown before, also when it opens again during its // exit fade or its host never saw it hide: the focus that was inside it does not close it as `focus_left`. let mut memory = if overlay::appears(ctx, layer.id, layer.exiting) { LayerMemory::default() } else { recall(layer, ctx) }; + // A right-click on a context opener while its layer is open hangs the layer at the new pointer. + let pointed = layer + .overlay + .opener + .as_ref() + .is_some_and(|first| first.all().any(|opener| opener.fired && opener.trigger == Trigger::Context && opener.opening == Opening::Pointer)); + if pointed { + memory.opening = None; + memory.pointer_at = None; + } let opened = opened_overlay(ctx, layer.overlay, memory.opening); if let Some((_, opening)) = &opened { memory.opening.get_or_insert(*opening); diff --git a/crates/ui-contract/src/contract/tooltip.rs b/crates/ui-contract/src/contract/tooltip.rs index 8762a341b..34bb3afa7 100644 --- a/crates/ui-contract/src/contract/tooltip.rs +++ b/crates/ui-contract/src/contract/tooltip.rs @@ -238,7 +238,8 @@ fn show_tip(call: TipCall<'_>) { } let when_now = spec.as_ref().is_some_and(|spec| spec.when == TooltipWhen::Now); let wants = has_content && wants_input; - let suppressed = pressed || overlay_blocks(ctx) || pointer::press_captured(ctx) || drag::running(ctx); + let screen = areas::layer_to_screen(ctx, rect_layer) * rect; + let suppressed = pressed || overlay_blocks(ctx, screen.center()) || pointer::press_captured(ctx) || drag::running(ctx); if wants { state.since.get_or_insert(now); } else { @@ -305,8 +306,9 @@ fn overlay_motion() -> motion::MotionSpec { } /// Whether a menu owns the keys: tooltips stay hidden then. -fn overlay_blocks(ctx: &egui::Context) -> bool { - crate::runtime::overlay::class_open(ctx, OwnerClass::Menu) +/// An open menu blocks the tooltips of what lies outside it; its own rows keep theirs. +fn overlay_blocks(ctx: &egui::Context, at: egui::Pos2) -> bool { + crate::runtime::overlay::class_open_away_from(ctx, OwnerClass::Menu, at) } /// The look of a tooltip card. diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index 28d89ae34..007f2885b 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -722,9 +722,13 @@ pub(crate) fn modal_viewport(ctx: &Context, viewport: ViewportId) -> Option bool { - with_pass(ctx, |pass| pass.last.iter().any(|entry| !entry.exiting && entry.keys == class)) +/// Whether a layer of key class `class` that is not fading out was shown last frame and the screen point `at` lies in +/// none of those layers. +pub(crate) fn class_open_away_from(ctx: &Context, class: OwnerClass, at: Pos2) -> bool { + with_pass(ctx, |pass| { + let mut open = pass.last.iter().filter(|entry| !entry.exiting && entry.keys == class).peekable(); + open.peek().is_some() && open.all(|entry| !entry.rect.contains(at)) + }) } // The facts the canvas reach under a modal reads (`runtime::sampler`). diff --git a/crates/ui-widgets/src/list/row.rs b/crates/ui-widgets/src/list/row.rs index 81996db1e..1e2bd3f2e 100644 --- a/crates/ui-widgets/src/list/row.rs +++ b/crates/ui-widgets/src/list/row.rs @@ -178,7 +178,7 @@ pub struct ListRow<'a> { #[prop(into)] pub(super) accessible_name: Option, pub(super) spacer: bool, - pub(super) heading: bool, + pub(super) caption: bool, pub(super) cells: Vec<(ColumnKey, Rect)>, /// Each column's alignment and whether its figures are tabular, from `columns(..)`. pub(super) aligns: Vec<(ColumnKey, HAlign, bool)>, @@ -271,7 +271,7 @@ impl<'a> ListRow<'a> { progress: None, accessible_name: None, spacer: false, - heading: false, + caption: false, cells: Vec::new(), aligns: Vec::new(), muted: Vec::new(), @@ -315,9 +315,9 @@ impl<'a> ListRow<'a> { /// A caption over the rows after it (a group's name in a picker's list): `label` in the caption role and /// `text.muted` at the row's start, a row high. Like a spacer it senses nothing and takes no lead; its AccessKit /// node is a heading. Mark its position `ItemSource::is_section` so keys and clicks skip it. - pub fn heading(label: impl Into