diff --git a/crates/menu/src/ribbon/group.rs b/crates/menu/src/ribbon/group.rs index 64b67c08d1..7a96562af7 100644 --- a/crates/menu/src/ribbon/group.rs +++ b/crates/menu/src/ribbon/group.rs @@ -70,7 +70,16 @@ impl<'a> RibbonGroup<'a> { /// popup the content opens does not close the popover: the overlay family keeps it open. fn collapsed(&self, ui: &mut Ui, add: &mut dyn FnMut(&mut Ui)) { let button = Button::new(self.title.clone()).icon(self.icon.clone()).arrangement(Arrangement::Stacked).show(ui); + if craft_ui::contract::clicked(&button.response) { + eprintln!( + "DIAG a_collapsed_groups_popover_stays_open_while_a_child_popup_is_used: collapsed button {:?} clicked at {:?}, sizing {}", + button.response.id, + button.response.rect, + ui.is_sizing_pass() + ); + } Popover::new(self.title.clone(), Bind::kept()).overlay(|overlay| overlay.opened_by(&button.response, Trigger::Click)).show(ui, |ui, _| { + eprintln!("DIAG a_collapsed_groups_popover_stays_open_while_a_child_popup_is_used: popover body of {:?} runs", self.title.as_str()); with_env( ui, |overrides| { diff --git a/crates/ui-contract/src/layout/body.rs b/crates/ui-contract/src/layout/body.rs index 1774db3965..0186ccb850 100644 --- a/crates/ui-contract/src/layout/body.rs +++ b/crates/ui-contract/src/layout/body.rs @@ -364,9 +364,17 @@ pub fn levelled_unit(ui: &mut Ui, key: Id, levels: usize, mut show: impl FnMut(& let rtl = Env::of(ui).direction.is_rtl(); let mut widths = Vec::with_capacity(levels); let mut widest = Vec2::ZERO; + // Each level measures at what it takes in no room: unbounded along x, in a region as wide as the row's. + // An infinite egui region would put right-to-left content's start edge at infinity. + let no_room = own_room.derive_local(|scoped| scoped.unbounded.0 = true); + let width = ui.max_rect().width(); for level in 0..levels.max(1) { - let installed = Env::install_for(ui, own_room.clone()); - let (_, took) = crate::runtime::egui::sizing::run_sized(ui, f32::INFINITY, child::column_layout(rtl), |ui| show(ui, level)); + let installed = Env::install_for(ui, no_room.clone()); + // Every level shows the same bodies under the same ids: each measures as a probe, so no level reuses a + // record another level left, and none serves the sweep at the levels given, which records its own. + let (_, took) = layout_memory::probing(&ctx, || { + crate::runtime::egui::sizing::run_sized(ui, width, child::column_layout(rtl), |ui| show(ui, level)) + }); Env::restore(&ctx, installed); if level == 0 { widest = took; @@ -605,6 +613,9 @@ fn run_shrinking(ui: &mut Ui, id: Id, mut body: impl FnMut(&mut Ui) -> R) -> } else { vec![0; levelled.len()] }; + if !levelled.is_empty() { + eprintln!("DIAG groups_with_the_same_title_keep_their_own_level: row {id:?} room {room} fixed {fixed} level widths {level_widths:?} levels {levels:?}"); + } let width_at = |leaf: &Reported, level: usize| leaf.levels.get(level).copied().unwrap_or_default(); let held: f32 = levelled.iter().zip(&levels).map(|(leaf, level)| width_at(*leaf, *level)).sum(); let widths = if room.is_finite() { diff --git a/crates/ui-contract/src/runtime/egui/sizing.rs b/crates/ui-contract/src/runtime/egui/sizing.rs index b1748c492e..785d8dff9b 100644 --- a/crates/ui-contract/src/runtime/egui/sizing.rs +++ b/crates/ui-contract/src/runtime/egui/sizing.rs @@ -83,10 +83,12 @@ pub(crate) fn discardable(ctx: &Context) -> bool { ctx.current_pass_index() + 1 < ctx.options(|options| options.max_passes.get()) } -/// Runs `f` in an invisible sizing pass `width` wide, from the parent's cursor, and returns what it took. +/// Runs `f` in an invisible sizing pass `width` wide, at the start of the rest of the parent's region, and returns +/// what it took. /// The parent allocates nothing. pub(crate) fn run_sized(ui: &mut Ui, width: f32, layout: Layout, f: impl FnOnce(&mut Ui) -> R) -> (R, Vec2) { - let room = Rect::from_min_size(ui.cursor().min, Vec2::new(width, f32::INFINITY)); + // The rest of the parent's region, not its cursor: a right-to-left cursor starts at negative infinity. + let room = Rect::from_min_size(ui.available_rect_before_wrap().min, Vec2::new(width, f32::INFINITY)); let mut child = ui.new_child(UiBuilder::new().max_rect(room).layout(layout).sizing_pass().invisible()); let inner = f(&mut child); (inner, child.min_rect().size())