Skip to main content

ModalStack

Struct ModalStack 

Source
pub struct ModalStack { /* private fields */ }
Expand description

Stack of active modals with z-ordering and input routing.

§Invariants

  • modals is ordered by z_index (lowest to highest).
  • next_z always 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

Source

pub fn new() -> Self

Create an empty modal stack.

Source

pub fn push(&mut self, modal: Box<dyn StackModal>) -> ModalId

Push a modal onto the stack.

Returns the unique ModalId for the pushed modal.

Source

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:

  1. Before calling this, create a focus group with focus_manager.create_group(id, members)
  2. Then call focus_manager.push_trap(id) to trap focus within the modal
  3. When the modal closes, call focus_manager.pop_trap() to restore focus

Returns the unique ModalId for the pushed modal.

Source

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.

Source

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.

Source

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().

Source

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.

Source

pub fn pop_all(&mut self) -> Vec<ModalResult>

Pop all modals from the stack.

Returns results in LIFO order (top first).

Source

pub fn top(&self) -> Option<&(dyn StackModal + 'static)>

Get a reference to the top modal.

Source

pub fn top_mut(&mut self) -> Option<&mut (dyn StackModal + 'static)>

Get a mutable reference to the top modal.

Source

pub fn is_empty(&self) -> bool

Check if the stack is empty.

Source

pub fn depth(&self) -> usize

Get the number of modals in the stack.

Source

pub fn contains(&self, id: ModalId) -> bool

Check if a modal with the given ID exists in the stack.

Source

pub fn top_id(&self) -> Option<ModalId>

Get the ID of the top modal, if any.

Source

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.

Source

pub fn render(&self, frame: &mut Frame<'_>, screen: Rect)

Render all modals in z-order.

Modals are rendered from bottom to top. Lower modals have reduced backdrop opacity to create a visual depth effect.

Trait Implementations§

Source§

impl Default for ModalStack

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more