Dialog host forgets a layer's open slot through runtime memory, not the body layer

This commit is contained in:
aiongg
2026-11-17 07:02:50 +00:00
parent 0c671476e9
commit 9cd0dcf2ba
4 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ mod size;
pub(crate) use size::EnvFacts;
mod window;
pub(crate) use open::{forget_open, unshown};
pub(crate) use open::unshown;
pub(crate) use placement::shown_placement;
#[doc(hidden)]
pub(crate) use regions::HeaderSlots;
+2 -9
View File
@@ -3,7 +3,7 @@
use super::BodyHooks;
use super::placement::opener_of;
use crate::contract::{Container, ContainerProps, Cx, Internal, Mount};
use crate::runtime::memory::{MemoryStage, SaveKey, sub};
use crate::runtime::memory::{MemoryStage, SaveKey, open_slot as session_open_slot, sub};
use craft_behavior::{EditEvent, Mixed};
use egui::{Context, Id};
use serde::{Deserialize, Serialize};
@@ -15,17 +15,10 @@ struct OpenState(Option<bool>);
fn open_slot<'s>(stage: &'s mut MemoryStage, id: Id, save: Option<&SaveKey>) -> &'s mut OpenState {
match save {
Some(key) => stage.saved::<OpenState>(key),
None => stage.session::<OpenState>(sub(id, "open")),
None => stage.session::<OpenState>(session_open_slot(id)),
}
}
/// Forgets the open state the container `id` keeps for the session, so its next show starts at its initial state. A
/// dialog host calls it for each layer of a dialog it removed (`overlay::end_stack_dialog`): a dialog that closed
/// itself and opens again under the same id opens. A binding or a save key keeps the state elsewhere and is untouched.
pub(crate) fn forget_open(ctx: &Context, id: Id) {
crate::runtime::memory::forget(ctx, sub(id, "open"));
}
/// Whether the container is open this pass: its binding, else its opener's state, else its slot.
pub(super) fn open_now<C: Container>(comp: &mut C, stage: &mut MemoryStage, id: Id, props: &ContainerProps) -> bool {
// A popup's layer (`OverlayUi::show_container`) is open while the popup is: the popup's slot is the one owner.
+7
View File
@@ -772,6 +772,13 @@ pub fn sub(base: Id, tag: impl Hash + Debug) -> Id {
base.with(Sub(tag))
}
/// The slot a container with no binding or save key keeps its open state in for the session (`body::open`). A dialog
/// host forgets it for each layer of a dialog it removed (`overlay::end_stack_dialog`), so a dialog that closed itself
/// and opens again under the same id opens.
pub(crate) fn open_slot(id: Id) -> Id {
sub(id, "open")
}
/// The id of a runtime singleton named `name`, optionally under a `scope` such as a viewport.
#[doc(hidden)]
pub fn global(name: &'static str, scope: impl Hash + Debug) -> Id {
+2 -2
View File
@@ -642,7 +642,7 @@ pub fn take_keys_for_new_dialog(ctx: &Context) {
/// A dialog host removed `dialog`: the layers it showed for it (`stack_place`) in the running or the last pass end
/// their shown life at once (`memory::end_shown`), as a container that shows nothing does, and forget the open state
/// they kept for the session (`body::forget_open`), so the next open of the dialog is a first pass and starts open: the
/// they kept for the session (`memory::open_slot`), so the next open of the dialog is a first pass and starts open: the
/// close that ended the dialog wrote that state closed.
#[doc(hidden)]
pub fn end_stack_dialog(ctx: &Context, dialog: Id) {
@@ -650,7 +650,7 @@ pub fn end_stack_dialog(ctx: &Context, dialog: Id) {
with_pass(ctx, |pass| pass.current.iter().chain(&pass.last).filter(|entry| entry.dialog == Some(dialog)).map(|entry| entry.id).collect());
for id in shown {
crate::runtime::memory::end_shown(ctx, id);
crate::contract::body::forget_open(ctx, id);
crate::runtime::memory::forget(ctx, crate::runtime::memory::open_slot(id));
}
}