1
//! Overlay stack — LIFO focus layer rendered on top of the main view.
2

            
3
use crate::modal::Modal;
4

            
5
#[cfg(test)]
6
mod tests;
7

            
8
/// LIFO stack of overlays. The topmost overlay owns keyboard focus.
9
#[derive(Debug, Default)]
10
pub struct OverlayStack {
11
    items: Vec<Modal>,
12
}
13

            
14
impl OverlayStack {
15
    #[must_use]
16
161
    pub const fn new() -> Self {
17
161
        Self { items: Vec::new() }
18
161
    }
19

            
20
51
    pub fn push(&mut self, modal: Modal) {
21
51
        self.items.push(modal);
22
51
    }
23

            
24
7
    pub fn pop(&mut self) -> Option<Modal> {
25
7
        self.items.pop()
26
7
    }
27

            
28
    #[must_use]
29
86
    pub fn top(&self) -> Option<&Modal> {
30
86
        self.items.last()
31
86
    }
32

            
33
    #[must_use]
34
38
    pub fn top_mut(&mut self) -> Option<&mut Modal> {
35
38
        self.items.last_mut()
36
38
    }
37

            
38
    #[must_use]
39
482
    pub fn is_empty(&self) -> bool {
40
482
        self.items.is_empty()
41
482
    }
42
}