ratatui_toolkit/primitives/dialog/
mod.rs

1//! Dialog component
2//!
3//! Provides modal dialog widgets with customizable buttons and styles.
4
5pub mod constructors;
6pub mod methods;
7pub mod traits;
8pub mod widget;
9
10pub use widget::DialogWidget;
11
12use ratatui::layout::Rect;
13use ratatui::style::{Color, Style};
14
15/// Dialog type
16///
17/// Represents different types of dialogs with associated visual styles.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum DialogType {
20    /// Informational dialog (cyan border)
21    Info,
22    /// Success dialog (green border)
23    Success,
24    /// Warning dialog (yellow border)
25    Warning,
26    /// Error dialog (red border)
27    Error,
28    /// Confirmation dialog (blue border)
29    Confirm,
30}
31
32/// A dialog/modal widget that overlays content
33///
34/// Dialogs are centered modals that display a message and buttons.
35/// They support different visual styles (info, success, warning, error, confirm)
36/// and can handle mouse clicks on buttons.
37#[allow(dead_code)]
38pub struct Dialog<'a> {
39    /// Dialog title
40    title: &'a str,
41    /// Dialog message
42    message: &'a str,
43    /// Dialog type
44    dialog_type: DialogType,
45    /// Buttons to show
46    buttons: Vec<&'a str>,
47    /// Selected button index
48    selected_button: usize,
49    /// Width percentage (0.0 to 1.0)
50    width_percent: f32,
51    /// Height percentage (0.0 to 1.0)
52    height_percent: f32,
53    /// Footer text below the message
54    footer: Option<&'a str>,
55    /// Footer style
56    footer_style: Style,
57    /// Whether to show title inside content instead of border
58    title_inside: bool,
59    /// Whether to render a screen overlay behind the dialog
60    overlay: bool,
61    /// Style for the overlay background
62    overlay_style: Style,
63    /// Override color for dialog border
64    border_color: Option<Color>,
65    /// Style for the dialog
66    style: Style,
67    /// Style for selected button
68    button_selected_style: Style,
69    /// Style for unselected button
70    button_style: Style,
71    /// Areas for buttons (for click detection)
72    button_areas: Vec<Rect>,
73    /// Theme color for info dialogs (overrides default when set)
74    theme_info_color: Option<Color>,
75    /// Theme color for success dialogs (overrides default when set)
76    theme_success_color: Option<Color>,
77    /// Theme color for warning dialogs (overrides default when set)
78    theme_warning_color: Option<Color>,
79    /// Theme color for error dialogs (overrides default when set)
80    theme_error_color: Option<Color>,
81    /// Theme color for confirm dialogs (overrides default when set)
82    theme_confirm_color: Option<Color>,
83}