rat_dialog/
lib.rs

1//!
2//! rat-dialog contains two structs that manage TUI windows.
3//!
4//! * [DialogStack]
5//!
6//! A pure stack of modal windows.
7//!
8//! * [WindowList]
9//!
10//! A list of modeless windows.
11//!
12//! There are also some window-decoration widgets that can handle
13//! the moving/resizing part. See [decorations](crate::decorations)
14//!
15
16#![allow(clippy::question_mark)]
17#![allow(clippy::type_complexity)]
18
19use rat_event::{ConsumedEvent, Outcome};
20
21pub mod decorations;
22
23mod dialog_stack;
24mod window_list;
25
26pub use dialog_stack::DialogStack;
27pub use dialog_stack::handle_dialog_stack;
28pub use window_list::Window;
29pub use window_list::WindowFrameOutcome;
30pub use window_list::WindowList;
31pub use window_list::handle_window_list;
32
33/// Result of event-handling for [DialogStack] and [WindowList].
34#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
35#[must_use]
36pub enum WindowControl<Event> {
37    /// Continue with event-handling.
38    /// In the event-loop this waits for the next event.
39    Continue,
40    /// Break event-handling without repaint.
41    /// In the event-loop this waits for the next event.
42    Unchanged,
43    /// Break event-handling and repaints/renders the application.
44    /// In the event-loop this calls `render`.
45    Changed,
46    /// Return back some application event.
47    Event(Event),
48    /// Close the dialog
49    Close(Event),
50}
51
52// Replace WindowControl with this
53
54// pub trait WindowClose {
55//     fn is_close(&self) -> bool;
56// }
57
58impl<Event> ConsumedEvent for WindowControl<Event> {
59    fn is_consumed(&self) -> bool {
60        !matches!(self, WindowControl::Continue)
61    }
62}
63
64impl<Event, T: Into<Outcome>> From<T> for WindowControl<Event> {
65    fn from(value: T) -> Self {
66        let r = value.into();
67        match r {
68            Outcome::Continue => WindowControl::Continue,
69            Outcome::Unchanged => WindowControl::Unchanged,
70            Outcome::Changed => WindowControl::Changed,
71        }
72    }
73}
74
75mod _private {
76    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
77    pub struct NonExhaustive;
78}