From 5f3373afb9e22c0576caab500d860fc464b1d894 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 22 Nov 2026 09:10:44 +0700 Subject: [PATCH] ui-contract: a fixture's root window reports its inner rect, so WindowHost::facts and its focus exist in trials --- .../ui-contract/src/runtime/egui/fixture.rs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/ui-contract/src/runtime/egui/fixture.rs b/crates/ui-contract/src/runtime/egui/fixture.rs index f21e99a85..976d72e95 100644 --- a/crates/ui-contract/src/runtime/egui/fixture.rs +++ b/crates/ui-contract/src/runtime/egui/fixture.rs @@ -129,15 +129,25 @@ impl egui::DroppedFile for DroppedPath { } } -/// The viewport facts a frame reports: a window-focus event also sets the root viewport's focus fact, as a host -/// reports both, and the fact stays until the next such event. Before any event the focus is unknown. -fn window_focus_facts(ctx: &Context, events: &[Event], native_pixels_per_point: Option) -> egui::ViewportIdMap { +/// The viewport facts a frame reports: the root window's inner rect when the frame is the root's (`inner`), and its +/// focus: a window-focus event also sets the root viewport's focus fact, as a host reports both, and the fact stays +/// until the next such event. Before any event the focus is unknown. +fn window_facts( + ctx: &Context, + events: &[Event], + native_pixels_per_point: Option, + inner: Option, +) -> egui::ViewportIdMap { let last = events.iter().rev().find_map(|event| if let Event::WindowFocused(focused) = event { Some(*focused) } else { None }); let focused = Service::::run(ctx, |state| { state.0 = last.or(state.0); state.0 }); - std::iter::once((egui::ViewportId::ROOT, egui::ViewportInfo { focused, native_pixels_per_point, ..egui::ViewportInfo::default() })).collect() + std::iter::once(( + egui::ViewportId::ROOT, + egui::ViewportInfo { focused, native_pixels_per_point, inner_rect: inner, ..egui::ViewportInfo::default() }, + )) + .collect() } /// The focus the fixture's window last reported; unset before any focus event. @@ -250,7 +260,7 @@ pub(crate) fn run_frame( let hovered_files = files.hovered.iter().map(|(name, mime)| egui::HoveredFile { path: Some(name.into()), mime: mime.clone() }).collect(); let dropped_files = files.dropped.iter().map(|name| Arc::new(DroppedPath(name.into())) as egui::DroppedFileHandle).collect(); Service::::run(ctx, |resets| resets.input(viewport, &mut events)); - let mut viewports = window_focus_facts(ctx, &events, native_pixels_per_point); + let mut viewports = window_facts(ctx, &events, native_pixels_per_point, (viewport == egui::ViewportId::ROOT).then_some(screen)); let children = open_children(ctx, viewport); for child in &children { viewports