mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 16:59:56 +01:00
Read a popup layer's appearance by its pass, and drop two dead assignments
The opener's pass held an outside press off a layer that appeared anywhere in the running frame. A layer shown in a popup window that appeared in an earlier pass of the same frame (a discard) is not one that appears in this pass, so a real press held for the next pass could not close it. The opener's pass now reads the popup's pass number before the popup runs, and the layer's first appearance must be that pass of the frame: the popup's begin pass stamps the number the opener read, because egui counts a viewport's pass when it ends. `appeared_in_frame` becomes `appeared_in_pass`, and `popup_dismissal` takes the pass beside the popup window. The trial's two frames before the double right-click assigned the frame output and never read it, which clippy reports as an unused assignment; they now just run, as the neighbouring frames do. The trial itself is unchanged and still covers the guard: the menu appears in the popup pass nested in the opener pass that recorded the press.
This commit is contained in:
1 parent
3d91d41ed8
commit
41675ba15a
4 files changed
+22
-14
No files matched your search
@@ -81,21 +81,23 @@ pub(super) fn dismissal(
|
||||
/// own pass decides: a layer that closes on outside presses closes on one in the opener outside it and its anchor
|
||||
/// (absorbed or not, as its rule says), and on one in any other window of the app; a popup also closes once the app
|
||||
/// has no focus. An absorbing layer can't keep a press in another OS window from reaching that window. A press recorded
|
||||
/// in the pass the layer appears in is not outside it: it was made before the layer opened.
|
||||
/// in the pass the layer appears in is not outside it: it was made before the layer opened. That pass is the popup
|
||||
/// window's, read as `pass` before it ran, and not an earlier pass of the frame.
|
||||
pub(super) fn popup_dismissal(
|
||||
ctx: &Context,
|
||||
layer: &Layer<'_>,
|
||||
rect: Rect,
|
||||
anchor: Rect,
|
||||
popup: egui::ViewportId,
|
||||
pass: u64,
|
||||
appears: bool,
|
||||
) -> Option<CloseReason> {
|
||||
let here = match layer.overlay.dismiss.outside {
|
||||
Outside::Keep => return None,
|
||||
// A layer that appears in this pass opened after the press was made, so the press is not outside it, as in
|
||||
// `dismissal`: the pass that shows the layer is the popup window's, which runs inside this one, and its first
|
||||
// appearance in that pass is what the frame holds.
|
||||
Outside::Absorb => overlay::absorbed_press(ctx).is_some() && !overlay::appeared_in_frame(ctx, popup, layer.id),
|
||||
// appearance is read by that pass's number, not by the frame's.
|
||||
Outside::Absorb => overlay::absorbed_press(ctx).is_some() && !overlay::appeared_in_pass(ctx, popup, layer.id, pass),
|
||||
Outside::Close => press_outside(ctx, layer, rect, anchor),
|
||||
};
|
||||
let away = layer.overlay.rank == Rank::Popup && crate::runtime::windows::app_away(ctx);
|
||||
|
||||
@@ -311,6 +311,11 @@ fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut
|
||||
let spec = WindowSpec::popup().takes_focus(!tooltip && (scope.is_some() || overlay.rank.takes_keys())).passes_pointer(tooltip);
|
||||
let known = measured.map(|size| Rect::from_min_size(unplaced.at, size));
|
||||
let open = PopupOpen { id: layer.id, spec: &spec, rect: known.map(|rect| rect.translate(popup.origin.to_vec2())) };
|
||||
// The popup's pass runs nested in this one and its begin pass stamps a layer's first appearance with its own
|
||||
// number: read that number before the pass runs, so this pass tells a layer appearing in it from one that appeared
|
||||
// in an earlier pass of the frame.
|
||||
let viewport = crate::runtime::egui::viewports::viewport_id(layer.id);
|
||||
let popup_pass = crate::runtime::egui::pass::pass_nr(ctx, viewport);
|
||||
let mut shown = None;
|
||||
windows::show_popup(ctx, &open, |ui| {
|
||||
let at = unplaced.at.to_vec2();
|
||||
@@ -335,8 +340,7 @@ fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut
|
||||
entry.window = true;
|
||||
entry.popup = true;
|
||||
overlay::record(ctx, entry);
|
||||
let viewport = crate::runtime::egui::viewports::viewport_id(layer.id);
|
||||
let dismissed = if layer.exiting { None } else { dismissed.or_else(|| popup_dismissal(ctx, layer, rect, anchor, viewport, appears)) };
|
||||
let dismissed = if layer.exiting { None } else { dismissed.or_else(|| popup_dismissal(ctx, layer, rect, anchor, viewport, popup_pass, appears)) };
|
||||
close_family(ctx, layer, layer.exiting || dismissed.is_some(), &mut memory);
|
||||
remember(layer, ctx, memory);
|
||||
LayerOut { dismissed }
|
||||
|
||||
@@ -616,13 +616,15 @@ pub fn opening(ctx: &Context, id: Id) -> bool {
|
||||
with_persist(ctx, viewport, |persist| persist.appeared.get(&id) == Some(&now))
|
||||
}
|
||||
|
||||
/// Whether the layer `id` first ran its body in the running frame, in the stack of `viewport`: a layer shown in a popup
|
||||
/// window appears in the popup's pass, which runs inside its opener's, so the opener's pass reads it once that pass ended,
|
||||
/// where [`opening`] reads the layer's own. Only the frame tells the two apart then: `pass_nr` of a passed viewport names
|
||||
/// the pass after the one that showed the layer.
|
||||
pub(crate) fn appeared_in_frame(ctx: &Context, viewport: ViewportId, id: Id) -> bool {
|
||||
let frame = pass::root_frame_nr(ctx);
|
||||
with_persist(ctx, viewport, |persist| persist.appeared.get(&id).is_some_and(|(first, _)| *first == frame))
|
||||
/// Whether the layer `id` first ran its body in the pass `pass` of the popup window `viewport`, in the running frame: a
|
||||
/// layer shown in a popup window appears in the popup's pass, which runs inside its opener's, so the opener's pass reads
|
||||
/// it once that pass ended, where [`opening`] reads the layer's own. `pass_nr` of a passed viewport names the pass after
|
||||
/// the one that showed the layer, but the opener's pass reads the popup's number before it runs, which is the number the
|
||||
/// popup's begin pass stamps the layer with: the two numbers name one pass, so a layer that appeared in an earlier pass of
|
||||
/// the same frame (a discard) is not one that appears in this one.
|
||||
pub(crate) fn appeared_in_pass(ctx: &Context, viewport: ViewportId, id: Id, pass: u64) -> bool {
|
||||
let now = (pass::root_frame_nr(ctx), pass);
|
||||
with_persist(ctx, viewport, |persist| persist.appeared.get(&id) == Some(&now))
|
||||
}
|
||||
|
||||
/// Queues a close of every layer opened from inside the layer `id`, so the open state of a popup in its body does
|
||||
|
||||
@@ -1845,8 +1845,8 @@ fn a_context_menu_a_palette_opens_is_not_closed_by_the_press_that_opened_it() {
|
||||
assert!(!palette_menu_shows(&dock, &out, "First action"), "the first menu closed");
|
||||
// The double right-click on the first target: the press that begins it closes the second menu, its release opens the
|
||||
// first target's menu in the pass of the second press, which the pass records as an outside press.
|
||||
out = collapsed_frame(&mut dock, &mut panels, &mut at, vec![], vec![moved(first)]);
|
||||
out = collapsed_frame(&mut dock, &mut panels, &mut at, vec![], vec![secondary(first, true)]);
|
||||
collapsed_frame(&mut dock, &mut panels, &mut at, vec![], vec![moved(first)]);
|
||||
collapsed_frame(&mut dock, &mut panels, &mut at, vec![], vec![secondary(first, true)]);
|
||||
out = collapsed_frame(&mut dock, &mut panels, &mut at, vec![], vec![secondary(first, false), secondary(first, true)]);
|
||||
// A menu a pass closes leaves the tree in the pass after it, while it fades; nothing presses again in these.
|
||||
for _ in 0..3 {
|
||||
|
||||
Reference in new issue
Block a user