pub struct ModalStack { /* private fields */ }Expand description
Stack of active modals with z-ordering and input routing.
§Invariants
modalsis ordered by z_index (lowest to highest).next_zalways produces a z_index greater than any existing modal.- Input is only routed to the top modal (last in the vec).
Implementations§
Source§impl ModalStack
impl ModalStack
Sourcepub fn push(&mut self, modal: Box<dyn StackModal>) -> ModalId
pub fn push(&mut self, modal: Box<dyn StackModal>) -> ModalId
Push a modal onto the stack.
Returns the unique ModalId for the pushed modal.
Sourcepub fn push_with_focus(
&mut self,
modal: Box<dyn StackModal>,
focus_group_id: Option<u32>,
) -> ModalId
pub fn push_with_focus( &mut self, modal: Box<dyn StackModal>, focus_group_id: Option<u32>, ) -> ModalId
Push a modal with an associated focus group ID.
The focus group ID is used to integrate with FocusManager:
- Before calling this, create a focus group with
focus_manager.create_group(id, members) - Then call
focus_manager.push_trap(id)to trap focus within the modal - When the modal closes, call
focus_manager.pop_trap()to restore focus
Returns the unique ModalId for the pushed modal.
Sourcepub fn focus_group_id(&self, modal_id: ModalId) -> Option<u32>
pub fn focus_group_id(&self, modal_id: ModalId) -> Option<u32>
Get the focus group ID for a modal.
Returns None if the modal doesn’t exist or has no focus group.
Sourcepub fn top_focus_group_id(&self) -> Option<u32>
pub fn top_focus_group_id(&self) -> Option<u32>
Get the focus group ID for the top modal.
Useful for checking if focus trap should be active.
Sourcepub fn pop(&mut self) -> Option<ModalResult>
pub fn pop(&mut self) -> Option<ModalResult>
Pop the top modal from the stack.
Returns the result if a modal was popped, or None if the stack is empty.
If the modal had a focus group, the caller should call FocusManager::pop_trap().
Sourcepub fn pop_id(&mut self, id: ModalId) -> Option<ModalResult>
pub fn pop_id(&mut self, id: ModalId) -> Option<ModalResult>
Pop a specific modal by ID.
Returns the result if the modal was found and removed, or None if not found.
Note: This breaks strict LIFO ordering but is sometimes needed.
If the modal had a focus group, the caller should handle focus restoration.
Sourcepub fn pop_all(&mut self) -> Vec<ModalResult>
pub fn pop_all(&mut self) -> Vec<ModalResult>
Pop all modals from the stack.
Returns results in LIFO order (top first).
Sourcepub fn top(&self) -> Option<&(dyn StackModal + 'static)>
pub fn top(&self) -> Option<&(dyn StackModal + 'static)>
Get a reference to the top modal.
Sourcepub fn top_mut(&mut self) -> Option<&mut (dyn StackModal + 'static)>
pub fn top_mut(&mut self) -> Option<&mut (dyn StackModal + 'static)>
Get a mutable reference to the top modal.
Sourcepub fn contains(&self, id: ModalId) -> bool
pub fn contains(&self, id: ModalId) -> bool
Check if a modal with the given ID exists in the stack.
Sourcepub fn handle_event(&mut self, event: &Event) -> Option<ModalResult>
pub fn handle_event(&mut self, event: &Event) -> Option<ModalResult>
Handle an event, routing it to the top modal only.
Returns Some(ModalResult) if the top modal closed, otherwise None.
If the result contains a focus_group_id, the caller should call
FocusManager::pop_trap() to restore focus.