1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Clarify logic around how viewports are retained, and add ViewportIdSet

This commit is contained in:
Emil Ernerfeldt
2023-11-07 11:14:04 +01:00
parent 54c6d51b66
commit 645521bcee
5 changed files with 32 additions and 15 deletions

View File

@@ -1551,7 +1551,7 @@ impl Context {
let was_used = viewport.used;
if viewport_id == viewport.id_pair.parent {
viewport.used = false;
viewport.used = false; // reset so we can check again next frame
}
viewports.push(ViewportOutput {
@@ -1560,8 +1560,19 @@ impl Context {
viewport_ui_cb: viewport.viewport_ui_cb.clone(),
});
(was_used || viewport_id != viewport.id_pair.parent)
&& all_viewport_ids.contains(&viewport.id_pair.parent)
if !all_viewport_ids.contains(&viewport.id_pair.parent) {
// Parent is gone - remove this viewport.
return false;
}
let is_child = viewport_id == viewport.id_pair.parent;
if is_child {
// Keep all children that have been updated this frame
was_used
} else {
// Somebody elses child - don't touch
true
}
});
});

View File

@@ -22,8 +22,10 @@ pub struct FullOutput {
/// You can use [`crate::Context::tessellate`] to turn this into triangles.
pub shapes: Vec<epaint::ClippedShape>,
/// All the active viewports, including the root.
pub viewports: Vec<ViewportOutput>,
/// Commands sent to different viewports.
pub viewport_commands: Vec<(ViewportId, ViewportCommand)>,
}

View File

@@ -641,6 +641,7 @@ pub(crate) struct Viewport {
/// Id of us and our parent.
pub(crate) id_pair: ViewportIdPair,
/// Has this viewport been updated this frame?
pub(crate) used: bool,
/// The user-code that shows the GUI, used for "async" viewports.