diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index 3265508d7..4b93f560d 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -695,14 +695,17 @@ impl<'a, S> AppShell<'a, S> { if !*shown || covers(&placed.slot, only) != covering { continue; } - let extent = placed.extent(&tokens, &measured_before); let by_content = placed.sized_by_content(); let along_x = placed.along_x(); - let Placed { slot, edge, named, add, .. } = placed; // A slot sized by its content is as large as its content from its outer edge, in the room it - // can grow into; any other slot fills its rect. - let pane = ShellPane::new(slot.key()).edge(*edge).extent(extent); - let pane = if by_content { pane.at_content_extent(grow_room(slot.key())) } else { pane.at(rect_of(slot.key())) }; + // can grow into; any other slot takes its extent and fills its rect. + let pane = ShellPane::new(placed.slot.key()).edge(placed.edge); + let pane = if by_content { + pane.at_content_extent(grow_room(placed.slot.key())) + } else { + pane.extent(placed.extent(&tokens, &measured_before)).at(rect_of(placed.slot.key())) + }; + let Placed { slot, named, add, .. } = placed; // Every slot is a chrome pane: it paints the surface under its bar or rail and the rule toward // the body. let mut region = ShellRegion::chrome(pane).id_salt(("slot", slot.key())); @@ -722,17 +725,17 @@ impl<'a, S> AppShell<'a, S> { } // The slot's extent along its edge is the pane's: its content's, with what the pane keeps // around its body (its rule). A top or bottom slot's content fills its width and is as tall - // as it is; a rail's is as wide as it is. - let pane = region - .show(ui, |ui, bcx| { - let stack = if along_x { Stack::new() } else { Stack::new().fill_width() }; - stack.show(ui, |ui, _| add(ui, bcx, app)); - }) - .output - .response - .rect; + // as it is; a rail's is as wide as it is. Only the slot's own real run records it: a run in a + // sizing pass (the scope's measuring run, which alone runs for a shell out of sight) is not + // what shows. + let shown = region.show(ui, |ui, bcx| { + let stack = if along_x { Stack::new() } else { Stack::new().fill_width() }; + stack.show(ui, |ui, _| add(ui, bcx, app)); + !ui.is_sizing_pass() + }); + let pane = shown.output.response.rect; let took = if along_x { pane.width() } else { pane.height() }; - if took.is_finite() && took > 0.0 { + if shown.inner == Some(true) && took.is_finite() && took > 0.0 { measured_now.push((key, took)); } } diff --git a/crates/ui-shell/tests/it/dialog/contained.rs b/crates/ui-shell/tests/it/dialog/contained.rs index e049c8daa..70a82595e 100644 --- a/crates/ui-shell/tests/it/dialog/contained.rs +++ b/crates/ui-shell/tests/it/dialog/contained.rs @@ -6,7 +6,7 @@ use craft_ui::dialog::Dialog; use craft_ui::layout_components::Stack; use craft_ui::runtime::env::WindowKey; use craft_ui::sections::{DialogRole, FooterButton}; -use craft_ui::shell::AppShell; +use craft_ui::shell::{AppShell, Slot, SlotSize}; use craft_ui::testing::contract::clicked; use craft_ui::testing::{Fixture, trial}; use egui::{Rect, Ui}; @@ -87,16 +87,24 @@ fn a_dialog_in_an_embedded_region_is_placed_in_it_and_blocks_only_it() { } /// An embedded shell scrolled out of sight with its dialog open shows nothing and does not fail: its region has no -/// room, so neither its body nor its dialog runs in that pass. +/// room, so neither its body, its dialog nor a slot sized by its content runs in that pass. #[trial] fn an_embedded_shell_out_of_sight_shows_nothing() { - let mut fixture = Fixture::new(|ui| { + let real = Rc::new(Cell::new(0_u32)); + let count = Rc::clone(&real); + let mut fixture = Fixture::new(move |ui| { Stack::new().fill().scroll(Scroll::vertical()).show(ui, |ui, _| { let _ = Button::new("Top").show(ui); let view = ui.clip_rect(); let below = Rect::from_min_size(egui::pos2(view.min.x, view.max.y + view.height()), egui::vec2(view.width(), view.height())); let mut open = true; AppShell::embedded(WindowKey::new("out-of-sight")) + .top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| { + if !ui.is_sizing_pass() { + count.set(count.get() + 1); + } + let _ = Button::new("Slot").show(ui); + }) .body(|ui, _, _| { let _ = Button::new("Hidden").show(ui); Dialog::new("Out of sight").opened(Bind::bound(&mut open)).show(ui, |_, _| {}); @@ -108,4 +116,5 @@ fn an_embedded_shell_out_of_sight_shows_nothing() { assert!(fixture.by_label("Top").is_some(), "the visible part is shown"); assert!(fixture.by_role(Role::DIALOG).is_empty(), "the dialog of a shell out of sight is not shown"); assert!(fixture.by_label("Hidden").is_none(), "the body of a shell out of sight does not run"); + assert!(fixture.by_label("Slot").is_none() && real.get() == 0, "the content slot of a shell out of sight does not run"); }