From 10ae05108db18aad6e0952f028d85bacb902c46a Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 19 Nov 2026 13:19:46 +0000 Subject: [PATCH] Two-window trial; a child window's frame takes no app input of its own --- crates/ui-contract/src/testing/frames.rs | 5 +++- crates/ui-shell/tests/it/commands/resolve.rs | 26 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/ui-contract/src/testing/frames.rs b/crates/ui-contract/src/testing/frames.rs index d6a856419..938170f56 100644 --- a/crates/ui-contract/src/testing/frames.rs +++ b/crates/ui-contract/src/testing/frames.rs @@ -189,7 +189,10 @@ impl Frames { /// per pass. Returns the number of passes. The child opens with its first frame and stays open, listed in the root's /// frames too, until [`close_viewport`](Self::close_viewport) or a `ViewportCommand::Close` for it. pub fn frame_in_viewport(&mut self, viewport: egui::ViewportId, events: Vec, mut ui: impl FnMut(&mut Ui)) -> usize { - set_input(&self.ctx, self.input()); + // The app's input is the root's, once per app frame: a child window's frame runs inside it. + if viewport == egui::ViewportId::ROOT { + set_input(&self.ctx, self.input()); + } let mut passes = 0; self.run(viewport, events, |root| { passes += 1; diff --git a/crates/ui-shell/tests/it/commands/resolve.rs b/crates/ui-shell/tests/it/commands/resolve.rs index a82393fd4..d3d3aed0b 100644 --- a/crates/ui-shell/tests/it/commands/resolve.rs +++ b/crates/ui-shell/tests/it/commands/resolve.rs @@ -52,11 +52,13 @@ struct Scene { global: bool, /// Pane `a` is left out of the next pass. skip_a: Cell, + /// Salts the panes' ids, so two windows show panes of their own. + window: &'static str, } impl Scene { fn new() -> Self { - Scene { zoom: Cell::new(true), ids: RefCell::new(Vec::new()), global: false, skip_a: Cell::new(false) } + Scene { zoom: Cell::new(true), ids: RefCell::new(Vec::new()), global: false, skip_a: Cell::new(false), window: "" } } fn show(&self, ui: &mut Ui) { @@ -66,7 +68,7 @@ impl Scene { if pane == 0 && skip_a { continue; } - Pane::new().id_salt(*salt).show(ui, |ui, cx| { + Pane::new().id_salt((self.window, *salt)).show(ui, |ui, cx| { if pane == 0 { cx.publish(PaneCommand::ZoomIn, CommandState::new().enabled(self.zoom.get())); } @@ -142,6 +144,26 @@ fn an_idle_frame_resolves_no_command() { assert_eq!(counts(&frames.ctx), (0, 0), "a pointer move away from the taps resolves nothing"); } +/// Two windows with frames alternating between them, idle: each frame resolves nothing and walks nothing, as the +/// child stays open across the root's frames and the root's across the child's. +#[trial] +fn idle_frames_alternating_between_two_windows_resolve_nothing() { + let root = Scene::new(); + let other = Scene { window: "child", ..Scene::new() }; + let child = ViewportId::from_hash_of("second window"); + let mut frames = Frames::new(); + let states = Tracked::new(CommandStates::new()); + frames.commands(gated(&states, false)); + for _ in 0..3 { + frame_walks(&mut frames, ViewportId::ROOT, &mut |ui| root.show(ui)); + frame_walks(&mut frames, child, &mut |ui| other.show(ui)); + } + for round in 0..4 { + assert_eq!(frame_walks(&mut frames, ViewportId::ROOT, &mut |ui| root.show(ui)), (0, 0, 0), "root frame {round}"); + assert_eq!(frame_walks(&mut frames, child, &mut |ui| other.show(ui)), (0, 0, 0), "child frame {round}"); + } +} + /// Editing one app-scope state resolves again only that command's readers, once. #[trial] fn one_state_change_resolves_only_its_readers() {