From 9cd0dcf2baf417062e0f2feaa83207ac22cefe00 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 07:02:50 +0000 Subject: [PATCH] Dialog host forgets a layer's open slot through runtime memory, not the body layer --- crates/ui-contract/src/contract/body.rs | 2 +- crates/ui-contract/src/contract/body/open.rs | 11 ++--------- crates/ui-contract/src/runtime/memory.rs | 7 +++++++ crates/ui-contract/src/runtime/overlay.rs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/ui-contract/src/contract/body.rs b/crates/ui-contract/src/contract/body.rs index ac6e40a93..d984f7b64 100644 --- a/crates/ui-contract/src/contract/body.rs +++ b/crates/ui-contract/src/contract/body.rs @@ -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; diff --git a/crates/ui-contract/src/contract/body/open.rs b/crates/ui-contract/src/contract/body/open.rs index a383855ad..ed1d5f1d0 100644 --- a/crates/ui-contract/src/contract/body/open.rs +++ b/crates/ui-contract/src/contract/body/open.rs @@ -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); fn open_slot<'s>(stage: &'s mut MemoryStage, id: Id, save: Option<&SaveKey>) -> &'s mut OpenState { match save { Some(key) => stage.saved::(key), - None => stage.session::(sub(id, "open")), + None => stage.session::(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(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. diff --git a/crates/ui-contract/src/runtime/memory.rs b/crates/ui-contract/src/runtime/memory.rs index 763870ec7..4ebedc657 100644 --- a/crates/ui-contract/src/runtime/memory.rs +++ b/crates/ui-contract/src/runtime/memory.rs @@ -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 { diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index 052eb29b6..1553099a3 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -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)); } }