diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index 966e728809..bcb22aff24 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -885,13 +885,16 @@ fn families(entries: &[OpenEntry], raised: &IdMap) -> Vec> { groups.into_iter().map(|(_, members)| members).collect() } -/// The end hook: raises the families that appeared, were pressed or were asked to (`raise`), hands egui the order of -/// every layer above the floating windows (which keep egui's own area order, where an asked raise moves them to the -/// top), and records the open-modal fact. +/// The end hook: raises the families that appeared, also one that reopened during its own exit fade, those that were +/// pressed and those that were asked to (`raise`), hands egui the order of every layer above the floating windows +/// (which keep egui's own area order, where an asked raise moves them to the top), and records the open-modal fact. +/// A family that stands in the floating windows' order is raised there when it reopens during its fade: egui showed its +/// area in the pass before, so egui raises none. pub(crate) fn end_pass(ctx: &Context) { let viewport = pass::current_viewport(ctx); - let (current, last_ids, raise) = - with_pass(ctx, |pass| (pass.current.clone(), pass.last.iter().map(|entry| entry.id).collect::>(), pass.raise.clone())); + let (current, last, raise) = with_pass(ctx, |pass| { + (pass.current.clone(), pass.last.iter().map(|entry| (entry.id, entry.exiting)).collect::>(), pass.raise.clone()) + }); let pressed = pointer::frame_raw(ctx).press.map(|press| press.origin); let now = pass::root_frame_nr(ctx); let (order, to_top, floats, asked) = with_persist(ctx, viewport, |persist| { @@ -906,12 +909,23 @@ pub(crate) fn end_pass(ctx: &Context) { .filter(|entry| entry.parent.is_none_or(|parent| !current.iter().any(|other| other.id == parent))) .map(|entry| entry.id) .collect(); + let mut asked: Vec = Vec::new(); for root in &roots { - if !last_ids.contains(root) { - stamp(*root, persist); + let shown = current.iter().find(|entry| entry.id == *root); + // A root the last pass did not have appears, and so does one that faded out then and is open again + // (`reopened`): it shows over whatever the fade let over it. + let kept = last.iter().any(|(id, _)| id == root); + let reopened = last.iter().any(|(id, exiting)| id == root && *exiting) && shown.is_none_or(|entry| !entry.exiting); + if kept && !reopened { + continue; + } + stamp(*root, persist); + // A root that reopens during its own fade is raised in egui's area order as a press raises it: egui showed + // its area in the pass before, so it raises none. A root that first shows there is raised by egui itself. + if reopened && shown.is_some_and(|entry| !entry.window && (entry.rank == Rank::Window || entry.among_windows)) { + asked.push(*root); } } - let mut asked: Vec = Vec::new(); for id in raise { let mut at = current.iter().find(|entry| entry.id == id); while let Some(parent) = at.and_then(|entry| entry.parent).and_then(|parent| current.iter().find(|other| other.id == parent)) { diff --git a/crates/ui-patterns/tests/it/docking/columns.rs b/crates/ui-patterns/tests/it/docking/columns.rs index 50d32a7146..1ebc4dc6bc 100644 --- a/crates/ui-patterns/tests/it/docking/columns.rs +++ b/crates/ui-patterns/tests/it/docking/columns.rs @@ -522,6 +522,46 @@ fn a_flyout_stands_among_the_floating_windows_in_their_order() { assert_eq!(clicks.get(), 1, "and a press at the button now reaches it"); } +/// A flyout closed and opened again while its exit fade runs is raised over the window the fade let in front of it. A +/// flyout stands in the floating windows' order, where egui raises a layer when it first shows and when it is pressed, +/// and it does neither for a layer that shows again while its area is still up. +#[trial] +fn a_flyout_opened_again_during_its_fade_is_above_the_window_over_it() { + let workspace = Rc::new(RefCell::new(flyout_dock(None))); + let flyout = Rc::new(Cell::new(None)); + let mut panels = UnderWindow { flyout: Rc::clone(&flyout), clicks: Rc::new(Cell::new(0)) }; + let (held, specs, pass_rect) = (Rc::clone(&workspace), Tracked::new(Sides), Rc::clone(&flyout)); + let mut fixture = Fixture::new(move |ui| { + // The cell holds this pass's flyout rect, so a flyout that does not show reads as `None`. + pass_rect.set(None); + let config = DockConfig::default().native_windows(false); + let shown = Bind::given(Arc::clone(&held.borrow())); + DockArea::new("Flyout dock", shown, &specs, &mut panels, config).show(ui); + }); + fixture.room(Vec2::new(900.0, 600.0)).settle(); + let icon = fixture.by_label("Alpha").expect("Alpha's icon").rect.center(); + fixture.click_at(icon).settle(); + let open = flyout.get().expect("Alpha's flyout shows its group"); + // A point of the flyout's own top that the floating window covers too. + let tab = Pos2::new(open.left() + 60.0, open.top() + 40.0); + let ctx = fixture.ctx().clone(); + let flyout_layer = ctx.layer_id_at(tab).expect("the flyout shows at its tab"); + + // The floating window shows over the flyout, as the newest layer, so it is on top where they overlap. + *workspace.borrow_mut() = flyout_dock(Some(window_over(open))); + fixture.settle(); + let window_layer = ctx.layer_id_at(tab).expect("the window over the flyout shows"); + assert_ne!(window_layer, flyout_layer, "the window over the flyout is the layer on top at its tab"); + + // Closed, the flyout fades out over the nine frames of its 150 ms fade at 1/60 s rather than at once. + fixture.frame(vec![pointer::moved(icon)]).frame(vec![pointer::press(icon)]).frame(vec![pointer::release(icon)]); + assert!(flyout.get().is_some(), "the closed flyout still shows while its exit fade runs"); + // Opened again in the fade, the flyout is the newer layer and takes the top back. + fixture.frame(vec![pointer::moved(icon)]).frame(vec![pointer::press(icon)]).frame(vec![pointer::release(icon)]).frame(Vec::new()); + assert!(flyout.get().is_some(), "the icon opens the flyout again while it fades"); + assert_eq!(ctx.layer_id_at(tab), Some(flyout_layer), "the flyout opened again during its fade is above the window over it"); +} + #[derive(PlainData)] struct RailWithMenu;