ratatui_toolkit/primitives/button/mod.rs
1//! Button component
2//!
3//! Provides clickable button widgets for UI interactions.
4//!
5//! # Structure
6//!
7//! - [`Button`] - The button widget struct
8//! - [`constructors`] - Constructor functions (`new`, builder methods)
9//! - [`methods`] - Instance methods (`render`, `is_clicked`, etc.)
10//! - [`traits`] - Trait implementations (`Default`)
11//! - [`render_title_with_buttons`] - Standalone function for rendering title with buttons
12//!
13//! # Example
14//!
15//! ```rust
16//! use ratatui::style::{Color, Style};
17//! use ratatui_toolkit::Button;
18//!
19//! let button = Button::new("Click Me")
20//! .normal_style(Style::default().fg(Color::White))
21//! .hover_style(Style::default().fg(Color::Yellow));
22//! ```
23//!
24//! # Click Detection
25//!
26//! Buttons track their own area for click detection. Use [`Button::is_clicked`] to
27//! check if a click occurred within the button's bounds after rendering.
28
29pub mod constructors;
30pub mod methods;
31pub mod render_title_with_buttons;
32pub mod traits;
33
34use ratatui::style::Style;
35
36/// A clickable button widget for the UI
37#[derive(Debug, Clone)]
38pub struct Button {
39 text: String,
40 area: Option<ratatui::layout::Rect>,
41 hovered: bool,
42 normal_style: Style,
43 hover_style: Style,
44}