From b75793951ee65eb127b0ef2d0b4cb6f6358efb00 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Thu, 19 Nov 2026 13:16:18 -0500 Subject: [PATCH] Framework follow-ups F-31, F-52, F-53, F-55, F-56 (app red 7, L-244): a right-click during an open press is an aside (PressStep::aside, PressState::context); Draw::cached_texture; Draw::role; AppCatalog::defs public; request_rename repaints settled regions --- crates/behavior/src/lib.rs | 4 +- crates/behavior/src/press.rs | 109 +++++++++++++++--- crates/ui-canvas/src/canvas/space.rs | 5 +- crates/ui-canvas/src/canvas/tool_host.rs | 4 + crates/ui-canvas/tests/it/canvas/tool.rs | 21 ++++ crates/ui-canvas/tests/it/canvas/tool_keys.rs | 14 +++ .../ui-contract/src/contract/items/request.rs | 3 +- crates/ui-contract/src/primitives/draw.rs | 14 +++ crates/ui-contract/src/primitives/sensing.rs | 22 +++- .../ui-contract/src/runtime/commands/mod.rs | 4 +- crates/ui-contract/src/style/cx.rs | 3 +- .../ui-contract/tests/it/collection/rows.rs | 22 ++++ 12 files changed, 201 insertions(+), 24 deletions(-) diff --git a/crates/behavior/src/lib.rs b/crates/behavior/src/lib.rs index b6f160632..75357d8b7 100644 --- a/crates/behavior/src/lib.rs +++ b/crates/behavior/src/lib.rs @@ -101,8 +101,8 @@ pub use part::{PartKey, PartRef}; pub use pixel_size::PixelSize; pub use press::{ - Buttons, MultiTouch, PassInput, PointerButton, PointerEvent, PointerKind, PointerSample, PressCancel, PressMachine, PressPhase, PressPick, - PressStart, PressState, PressStep, count_clicks, + Buttons, MultiTouch, PassInput, PointerButton, PointerEvent, PointerKind, PointerSample, PressAside, PressCancel, PressMachine, PressPhase, + PressPick, PressStart, PressState, PressStep, count_clicks, }; pub use quantity::Reader; pub use role_rule::{GridFacts, RoleRule, is_checkable, is_selectable, role_violations}; diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index 79304a22e..9e9aaa2f9 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -284,15 +284,24 @@ pub struct PressState { pub sample: Option, /// A drag holds the pointer: nothing else hovers. pub captured: bool, + /// Where a secondary press made during another open press came up on this part in this pass + /// ([`PressStep::aside`]): a context request beside the running phase, which goes on. + pub context: Option, } impl PressState { /// A part with no press history. pub const IDLE: PressState = PressState::new(PressPhase::Idle); - /// A state in `phase` with no modifiers, sample or capture. + /// A state in `phase` with no modifiers, sample, capture or aside context request. pub const fn new(phase: PressPhase) -> Self { - PressState { phase, mods: Mods::NONE, sample: None, captured: false } + PressState { phase, mods: Mods::NONE, sample: None, captured: false, context: None } + } + + /// The aside secondary press that came up on the part at `at` in this pass. + pub const fn context(mut self, at: Option) -> Self { + self.context = at; + self } /// The modifiers held. @@ -458,14 +467,30 @@ pub struct PressStep { /// The start of an open press whose sense has `PASSES_DRAG` and no `DRAG` that moved past slop in this pass: /// the caller may hand it to the shape below with [`PressMachine::hand_over`]. pub passes: Option, + /// A secondary press that came up in this pass while a primary press stayed open: a right-click during a drag. The + /// open press goes on; the aside asks its target for a context menu. + pub aside: Option>, } impl Default for PressStep { fn default() -> Self { - PressStep { target: None, phase: None, dragging: false, activated: None, passes: None } + PressStep { target: None, phase: None, dragging: false, activated: None, passes: None, aside: None } } } +/// A secondary press made and released while a primary press was open ([`PressStep::aside`]). Its target is the one +/// `pick` gave the secondary press, so it senses `Sense::CONTEXT_CLICK`. +#[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] +pub struct PressAside { + /// The target of the secondary press. + pub target: T, + /// Where and when the secondary button went down. + pub start: PressStart, + /// Where it came up, in screen space. + pub pos: Pos2, +} + /// The press winner a root picks at a press position, as [`PressMachine::step`]'s `pick` returns it. #[derive(Clone, Copy, Debug, PartialEq)] #[non_exhaustive] @@ -533,18 +558,20 @@ impl Open { #[derive(Clone, Copy, Debug)] pub struct PressMachine { open: Option>, + /// The secondary press held beside the open primary press, with its target and start. + aside: Option<(T, PressStart)>, } impl Default for PressMachine { fn default() -> Self { - PressMachine { open: None } + PressMachine { open: None, aside: None } } } impl PressMachine { /// A machine with no press. pub const fn new() -> Self { - PressMachine { open: None } + PressMachine { open: None, aside: None } } /// The target of the open press. @@ -576,6 +603,7 @@ impl PressMachine { // The press released or cancelled in this pass, and whether it was silent: one that ends silent reports nothing. let mut released: Option<(T, PressStart, Pos2, bool, bool, bool)> = None; let mut cancelled: Option<(T, PressStart, PressCancel, bool)> = None; + let mut aside: Option> = None; // A press passed in the last pass that no shape took is abandoned; that pass reported its `Down`. if let Some(open) = &mut self.open && open.passing.is_some() @@ -630,6 +658,16 @@ impl PressMachine { released = Some((open.target, open.start, up, open.dragging, click, open.silent)); self.open = None; } + // A secondary press during an open primary press goes beside it, to the context target `pick` gives + // it, and the primary press goes on (a right-click during a drag asks for the menu there). + if button == PointerButton::Secondary + && self.aside.is_none() + && self.open.is_some_and(|open| open.start.button == PointerButton::Primary) + { + let start = PressStart::new(at, button, time, clicks); + self.aside = pick(at, button).filter(|pick| pick.sense.contains(Sense::CONTEXT_CLICK)).map(|pick| (pick.target, start)); + continue; + } // An open press keeps the pointer until its button comes up: no press starts over it, of its own // button (a repeated Down, as a window never sends one) or another. Its moves and its release still // reach it when a modal opened over its target since. A middle press captures for a drag (a canvas @@ -674,6 +712,12 @@ impl PressMachine { } PointerEvent::Released { button, pos: at } => { pos = at; + if button == PointerButton::Secondary + && let Some((target, start)) = self.aside.take() + { + aside = Some(PressAside { target, start, pos: at }); + continue; + } if self.open.is_some_and(|open| open.start.button != button || open.released_at.is_some()) { continue; } @@ -691,16 +735,21 @@ impl PressMachine { if self.open.is_some_and(|open| open.released_at.is_none()) && !input.held && released.is_none() { self.open = None; } + // An aside press lasts no longer than the press it went beside. + if self.open.is_none() { + self.aside = None; + } + let quiet = PressStep { aside, ..PressStep::default() }; if let Some((target, start, reason, silent)) = cancelled { if silent { - return PressStep::default(); + return quiet; } let phase = PressPhase::Cancel { start, reason }; - return PressStep { target: Some(target), phase: Some(phase), dragging: false, activated: None, passes: None }; + return PressStep { target: Some(target), phase: Some(phase), ..quiet }; } if let Some((target, start, at, was_dragging, click, silent)) = released { if silent { - return PressStep::default(); + return quiet; } let phase = PressPhase::Release { start, pos: at, click }; return PressStep { @@ -708,12 +757,12 @@ impl PressMachine { phase: Some(phase), dragging: was_dragging, activated: (click && start.button == PointerButton::Primary).then_some(target), - passes: None, + ..quiet }; } - let Some(open) = self.open.as_mut() else { return PressStep::default() }; + let Some(open) = self.open.as_mut() else { return quiet }; if open.silent { - return PressStep::default(); + return quiet; } if let Some(at) = &mut open.passing { *at = pos; @@ -733,13 +782,14 @@ impl PressMachine { open.reported = true; } let passes = open.passing.map(|_| open.start); - PressStep { target: Some(open.target), phase: Some(phase), dragging: open.drag_reported, activated: None, passes } + PressStep { target: Some(open.target), phase: Some(phase), dragging: open.drag_reported, passes, ..quiet } } /// Makes `target` the open press's target in the pass that reported `passes`, dragging from the same /// `PressStart`. It returns the `DragStart` step when an earlier pass reported the press, and the `Down` step /// (the `DragStart` follows in the next pass) when the move past slop came in the pass of the press itself. - /// `None` when no press passes in this pass or `sense` has no `DRAG`; the next pass abandons the press. + /// `None` when no press passes in this pass or `sense` has no `DRAG`; the next pass abandons the press. The step + /// has no [`aside`](PressStep::aside): that stays the pass's own step's. pub fn hand_over(&mut self, target: T, sense: Sense) -> Option> { let open = self.open.as_mut().filter(|open| !open.abandoned && sense.contains(Sense::DRAG))?; let at = open.passing.take()?; @@ -753,7 +803,7 @@ impl PressMachine { open.reported = true; PressPhase::Down { start: open.start } }; - Some(PressStep { target: Some(target), phase: Some(phase), dragging: open.drag_reported, activated: None, passes: None }) + Some(PressStep { target: Some(target), phase: Some(phase), dragging: open.drag_reported, ..PressStep::default() }) } } @@ -789,6 +839,37 @@ mod tests { assert_eq!(step.activated, Some(1)); } + /// A right-click during a drag goes beside it: the secondary release reports an aside on the context target, and the + /// drag goes on to its own release. A secondary press on a target without `CONTEXT_CLICK` reports none. + #[test] + fn a_secondary_click_during_a_drag_reports_an_aside_and_the_drag_goes_on() { + let (from, to, menu) = (pos2(0.0, 0.0), pos2(40.0, 0.0), pos2(40.0, 5.0)); + let mut machine = PressMachine::new(); + let mut pass = |events: &[PointerEvent]| { + machine.step(PassInput::new(events, SLOP, to, true), |_, button| match button { + PointerButton::Secondary => Some(PressPick::new(2, Sense::CLICK | Sense::CONTEXT_CLICK)), + _ => Some(PressPick::new(1, Sense::DRAG)), + }) + }; + pass(&[PointerEvent::pressed(from, 1.0, 1)]); + pass(&[PointerEvent::moved(to, None)]); + let down = pass(&[PointerEvent::pressed_by(PointerButton::Secondary, menu, 1.2, 1)]); + assert!(down.aside.is_none(), "nothing asks before the secondary button comes up"); + assert!(matches!(down.phase, Some(PressPhase::Drag { .. })), "the drag goes on: {down:?}"); + let up = pass(&[PointerEvent::released_by(PointerButton::Secondary, menu)]); + assert_eq!(up.aside.map(|aside| (aside.target, aside.pos)), Some((2, menu)), "the release asks the context target"); + assert_eq!(up.target, Some(1), "the drag keeps its target"); + assert!(up.phase.is_some_and(|phase| phase.is_drag()), "and its drag: {up:?}"); + let end = pass(&[PointerEvent::released(to)]); + assert!(matches!(end.phase, Some(PressPhase::Release { .. })) && end.aside.is_none(), "the drag ends on its own release: {end:?}"); + + let mut machine = PressMachine::new(); + let mut pass = |events: &[PointerEvent]| machine.step(PassInput::new(events, SLOP, to, true), |_, _| Some(PressPick::new(1, Sense::DRAG))); + pass(&[PointerEvent::pressed(from, 1.0, 1)]); + pass(&[PointerEvent::pressed_by(PointerButton::Secondary, menu, 1.2, 1)]); + assert!(pass(&[PointerEvent::released_by(PointerButton::Secondary, menu)]).aside.is_none(), "a drag-only target takes no aside"); + } + /// The phases a sequence of passes reports, as `D`own, `H`eld, `S` (drag start), `G` (drag), `R`elease with `!` for an /// activation, `-` for none. fn phases(passes: &[&[PointerEvent]], sense: Sense) -> String { diff --git a/crates/ui-canvas/src/canvas/space.rs b/crates/ui-canvas/src/canvas/space.rs index 2830eec46..77b7206df 100644 --- a/crates/ui-canvas/src/canvas/space.rs +++ b/crates/ui-canvas/src/canvas/space.rs @@ -338,11 +338,12 @@ impl BackgroundPress { /// Where `press` is the release of a secondary press: the one reading of a context press from a part's press. The press /// machine gives a secondary press only to a part that senses `CONTEXT_CLICK`, so the release is the request whether -/// or not the pointer moved. +/// or not the pointer moved. A secondary press made during another open press (a right-click during a drag) comes up +/// beside that press's phase, as `PressState::context`, and is the request too. pub fn context_click(press: &PressState) -> Option { match press.phase { PressPhase::Release { start, pos, .. } if start.button == PointerButton::Secondary => Some(pos), - _ => None, + _ => press.context, } } diff --git a/crates/ui-canvas/src/canvas/tool_host.rs b/crates/ui-canvas/src/canvas/tool_host.rs index 3dd7336d6..cafcec80e 100644 --- a/crates/ui-canvas/src/canvas/tool_host.rs +++ b/crates/ui-canvas/src/canvas/tool_host.rs @@ -1214,6 +1214,10 @@ impl<'a, 't: 'a> Run<'a, 't> { /// The canvas background's press phase of this pass. A pass carries one phase, so a press that moved or /// released in the pass it began in starts here. fn phase(&mut self, press: &PressState, frame: &PointerFrame) { + // A right-click during the gesture asks for the menu where it came up; the gesture goes on. + if let Some(at) = press.context { + self.response.context = Some(ContextRequest { at, mods: press.mods, momentary: self.momentary }); + } match press.phase { PressPhase::Idle => self.state.spent = false, PressPhase::Hover => { diff --git a/crates/ui-canvas/tests/it/canvas/tool.rs b/crates/ui-canvas/tests/it/canvas/tool.rs index ff2b11aef..b8fddb65a 100644 --- a/crates/ui-canvas/tests/it/canvas/tool.rs +++ b/crates/ui-canvas/tests/it/canvas/tool.rs @@ -1333,6 +1333,27 @@ fn moves_inside_the_click_distance_reach_a_tool_that_takes_every_move() { } } +/// A right-click during a drag asks for the menu where it came up and leaves the drag to the tool: no release and no +/// cancel until the primary button comes up (a dragged comment keeps moving while its page menu opens). +#[trial] +fn a_secondary_click_during_a_drag_asks_for_the_menu_and_the_drag_goes_on() { + let log = Log::default(); + let mut rig = Rig::new(Probe::new("main", &log), &log, None); + let at = rig.centre(); + let menu = at + BY; + rig.fixture.frame(vec![pointer::press(at)]).frame(vec![pointer::moved(menu)]); + rig.fixture.frame(vec![pointer::secondary(menu, true)]).frame(vec![pointer::secondary(menu, false)]); + let asked = rig.contexts.borrow().clone(); + assert_eq!(asked.iter().map(|request| request.at).collect::>(), [menu], "the secondary release asks once, where it came up"); + let calls = rig.calls(); + assert!(!calls.iter().any(|call| call.ends_with("release") || call.ends_with("cancel")), "the drag goes on: {calls:?}"); + rig.fixture.frame(vec![pointer::moved(menu + BY)]).frame(vec![pointer::release(menu + BY)]); + let calls = rig.calls(); + assert_eq!(calls.iter().filter(|call| call.ends_with("press")).count(), 1, "one gesture: {calls:?}"); + assert_eq!(calls.last().map(String::as_str), Some("main release"), "it ends on the primary release: {calls:?}"); + assert_eq!(rig.contexts.borrow().len(), 1, "and asks no more"); +} + #[trial] fn a_secondary_click_the_tool_did_not_take_asks_for_the_menu() { let log = Log::default(); diff --git a/crates/ui-canvas/tests/it/canvas/tool_keys.rs b/crates/ui-canvas/tests/it/canvas/tool_keys.rs index b36a6e704..0f23d37f0 100644 --- a/crates/ui-canvas/tests/it/canvas/tool_keys.rs +++ b/crates/ui-canvas/tests/it/canvas/tool_keys.rs @@ -173,6 +173,20 @@ fn with_no_session_control_the_arrows_and_enter_reach_the_tool_with_nothing_focu assert!(matches!(seen[..], [ToolKey::Nudge { .. }, ToolKey::Submit]), "{seen:?}"); } +/// Escape reaches the active tool as `Cancel` with nothing focused and with the canvas focused, so a tool steps back +/// out of what it holds (a comment or fill tool leaves for Select) without a gesture to cancel. +#[trial] +fn escape_reaches_the_tool_as_cancel_with_nothing_or_the_canvas_focused() { + let (mut canvas, ..) = session(false); + canvas.fixture().settle(); + canvas.fixture().key(Key::Escape, Modifiers::NONE).settle(); + assert_eq!(canvas.tool().seen, [ToolKey::Cancel], "nothing focused: the window's Escape is the tool's"); + canvas.fixture().key(Key::Tab, Modifiers::NONE).settle(); + assert_eq!(canvas.fixture().focused(), Some(canvas.canvas_id()), "Tab focuses the canvas"); + canvas.fixture().key(Key::Escape, Modifiers::NONE).settle(); + assert_eq!(canvas.tool().seen, [ToolKey::Cancel, ToolKey::Cancel], "the focused canvas's Escape is the tool's"); +} + /// The chords `Claimer` takes through `ToolClaims::keys`. fn enter_and_escape() -> &'static [Chord] { static KEYS: std::sync::OnceLock<[Chord; 2]> = std::sync::OnceLock::new(); diff --git a/crates/ui-contract/src/contract/items/request.rs b/crates/ui-contract/src/contract/items/request.rs index 00e666d37..85723e26a 100644 --- a/crates/ui-contract/src/contract/items/request.rs +++ b/crates/ui-contract/src/contract/items/request.rs @@ -24,7 +24,8 @@ pub fn request_rename(ctx: &Context, collectio requests.0.retain(|(id, _)| *id != collection); requests.0.push((collection, key.clone())); }); - crate::runtime::egui::repaint::request_of(ctx, crate::runtime::egui::pass::current_viewport(ctx)); + // The collection may sit in a settled region, which a plain repaint replays without running its steps. + crate::runtime::frame::request_repaint(ctx); } /// The rename request addressed to `collection`, once. diff --git a/crates/ui-contract/src/primitives/draw.rs b/crates/ui-contract/src/primitives/draw.rs index 7df88fb6c..41892a99b 100644 --- a/crates/ui-contract/src/primitives/draw.rs +++ b/crates/ui-contract/src/primitives/draw.rs @@ -263,6 +263,13 @@ impl<'a> Draw<'a> { } } + /// A colour role of the scope's theme, for content that paints a state with no style of its own: a selected row in + /// `draw.role(|c| c.state.selected)`, its text in `|c| c.text.on_selected`. It is the colour a style function + /// gets from `cx.color(cx.tokens.color.…)` for the same role. + pub fn role(&self, pick: impl FnOnce(&craft_theme::ColorTokens) -> craft_theme::Rgba) -> StyleColor { + StyleColor(crate::style::rgba_color(pick(&self.env.tokens.color))) + } + #[doc(hidden)] pub fn width(&self, width: StrokeWidth) -> f32 { width.points(self.env.tokens, self.painter.pixels_per_point()) @@ -519,6 +526,13 @@ impl<'a> Draw<'a> { data_picture(self.painter, self.env.tokens, self.data, texture, rect, uv, CornerRadius::ZERO); } + /// The texture for `key` from the `TextureCache` of the context this painter paints in, for [`texture`](Self::texture): + /// `image()` is built on the first request only (see `TextureCache::texture`). A painter with no `egui::Context` + /// of its own, such as a canvas tool's paint call, loads its pictures through here. + pub fn cached_texture(&self, key: K, image: impl FnOnce() -> egui::ColorImage) -> TextureId { + super::TextureCache::texture(self.painter.ctx(), key, image) + } + /// Paints `checker` over `rect` with corners `radius`, a light cell at the rect's top left. It shows through data, /// so it paints as the data over it: at `Opacity::DISABLED` for a disabled component, and for an inactive part as /// the theme's disabled fill, as `data_fill` does. diff --git a/crates/ui-contract/src/primitives/sensing.rs b/crates/ui-contract/src/primitives/sensing.rs index 24b06a831..a045b7cf9 100644 --- a/crates/ui-contract/src/primitives/sensing.rs +++ b/crates/ui-contract/src/primitives/sensing.rs @@ -242,6 +242,9 @@ pub(crate) struct Outcome { pub dragging: bool, /// The press winner released as a click this pass. pub activated: Option, + /// The target of a secondary press made beside the open press that came up this pass, and where + /// (`PressStep::aside`). + pub aside: Option<(Hit, Pos2)>, xf: Option, } @@ -905,6 +908,7 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab // press split gave it at the press (`pointer::press_winners` at the press's origin, with the press's own // targets). When that shape is this root's, the press carries on there from its start; another root's took the // drag at the press, and this press, no click any more, is abandoned. + let aside = step.aside.map(|aside| (aside.target, aside.pos)); let step = match step.passes { Some(start) => { let root = state.root.map(|root| root.id); @@ -929,7 +933,8 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab None if others_press => Hovered::default(), None => under, }; - let outcome = Outcome { pass: pass_nr, hover, contains, target: step.target, phase: step.phase, dragging, activated: step.activated, xf }; + let outcome = + Outcome { pass: pass_nr, hover, contains, target: step.target, phase: step.phase, dragging, activated: step.activated, aside, xf }; state.outcome = Some(outcome); outcome }); @@ -1049,10 +1054,20 @@ fn part_press_in( _ => PressPhase::Idle, }; let captured = won.is_some() && outcome.dragging && phase.is_drag(); - let press = PressState::new(phase).mods(mods).sample(sample).captured(captured); + let context = aside_at(outcome, |hit| is_known && mine(hit)); + let press = PressState::new(phase).mods(mods).sample(sample).captured(captured).context(context); PartPress { press, hovered, hover_pos } } +/// Where the aside secondary press of the pass came up, in its target's space, when `mine` takes its target. +fn aside_at(outcome: &Outcome, mine: impl Fn(&Hit) -> bool) -> Option { + let (hit, at) = outcome.aside.filter(|(hit, _)| mine(hit))?; + Some(match outcome.xf { + Some(map) if hit.local => map.to_layer(at), + _ => at, + }) +} + /// The owner's own shape's press state: a member's root shape or the root background. `Idle` unless it won. fn shape_press_in(outcome: &Outcome, mods: Mods, sample: Option, owner: Id) -> PressState { let won = outcome.target.filter(|target| target.owner == owner && target.part.is_none()); @@ -1062,7 +1077,8 @@ fn shape_press_in(outcome: &Outcome, mods: Mods, sample: Option, _ => PressPhase::Idle, }; let captured = won.is_some() && phase.is_drag(); - PressState::new(phase).mods(mods).sample(sample).captured(captured) + let context = aside_at(outcome, |hit| hit.owner == owner && hit.part.is_none()); + PressState::new(phase).mods(mods).sample(sample).captured(captured).context(context) } /// The cursor a hovered part of `decls` declares, if any: the sensing core's request for the cursor service. diff --git a/crates/ui-contract/src/runtime/commands/mod.rs b/crates/ui-contract/src/runtime/commands/mod.rs index 21a58a0c5..815976a16 100644 --- a/crates/ui-contract/src/runtime/commands/mod.rs +++ b/crates/ui-contract/src/runtime/commands/mod.rs @@ -72,7 +72,9 @@ impl AppCatalog { self.generation } - pub(crate) fn defs(&self) -> &[CommandDef] { + /// The catalog's rows in the order the app gave them, each with its scope (always [`Scope::app`]), kind and + /// default bindings, as a shortcuts list reads them. + pub fn defs(&self) -> &[CommandDef] { &self.defs } diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index bb83a5a11..2fcd8eafe 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -217,7 +217,8 @@ impl<'a> StyleCx<'a> { self.values.get::() } - /// The one constructor of `StyleColor`: a semantic token read or a token-group field becomes a style colour here. + /// The constructor of `StyleColor` for styles: a semantic token read or a token-group field becomes a style colour + /// here. Content paint picks a role through `Draw::role`. pub fn color(&self, color: Rgba) -> StyleColor { StyleColor(egui_color(color)) } diff --git a/crates/ui-contract/tests/it/collection/rows.rs b/crates/ui-contract/tests/it/collection/rows.rs index 127494095..6c87d6965 100644 --- a/crates/ui-contract/tests/it/collection/rows.rs +++ b/crates/ui-contract/tests/it/collection/rows.rs @@ -542,3 +542,25 @@ fn enter_on_an_untyped_rename_commits_only_a_proposed_draft() { assert_eq!(renamed("proposed"), ["proposed"], "Enter accepts the proposed draft"); assert!(renamed("b").is_empty(), "a draft equal to the row's text reports no commit"); } + +/// A rename requested from outside a settled region (`Lazy::settles` with a content version, as a docked panel's +/// body) runs the region, so its collection takes the request and opens the rename field. +#[trial] +fn a_rename_request_runs_the_settled_region_of_its_collection() { + use craft_ui::contract::Lazy; + let (log, enter, words) = (Log::new(), Cell::new(false), Words::flat(&["a", "b", "c"])); + let mut frames = Frames::new(); + let mut show = |ui: &mut Ui| { + in_region(ui, Rect::from_min_size(ORIGIN, VIEW), |ui| { + Lazy::new("panel", 0.0).settles(true).content(1).show(ui, |ui| { + let list = Probe::new(SelectMode::Single).id_salt("list").renaming("b", &enter); + log.take(list.show_items(ui, &words, &mut |key, _| ProbeRow::new(*key, log))); + }); + }); + }; + frames.idle(30, &mut show); + request_rename(&frames.ctx, log.id(), &1_usize); + frames.idle(3, &mut show); + let begun = log.events.borrow().iter().any(|event| matches!(event, CollectionEvent::Rename(EditEvent::Begin { .. }))); + assert!(begun, "the settled region ran and its collection opened the requested rename"); +}