Skip to main content

tui/
overlay.rs

1//! Overlay stack — LIFO focus layer rendered on top of the main view.
2
3use crate::modal::Modal;
4
5#[cfg(test)]
6mod tests;
7
8/// LIFO stack of overlays. The topmost overlay owns keyboard focus.
9#[derive(Debug, Default)]
10pub struct OverlayStack {
11    items: Vec<Modal>,
12}
13
14impl OverlayStack {
15    #[must_use]
16    pub const fn new() -> Self {
17        Self { items: Vec::new() }
18    }
19
20    pub fn push(&mut self, modal: Modal) {
21        self.items.push(modal);
22    }
23
24    pub fn pop(&mut self) -> Option<Modal> {
25        self.items.pop()
26    }
27
28    #[must_use]
29    pub fn top(&self) -> Option<&Modal> {
30        self.items.last()
31    }
32
33    #[must_use]
34    pub fn top_mut(&mut self) -> Option<&mut Modal> {
35        self.items.last_mut()
36    }
37
38    #[must_use]
39    pub fn is_empty(&self) -> bool {
40        self.items.is_empty()
41    }
42}