Skip to main content

fresh/view/controls/
mod.rs

1//! Reusable form controls for settings and dialogs
2//!
3//! This module provides a set of form controls that can be used across
4//! the application for settings screens, dialogs, and other interactive UI.
5//!
6//! ## Available Controls
7//! - `Toggle` - Boolean on/off switch
8//! - `NumberInput` - Numeric input with increment/decrement
9//! - `Dropdown` - Selection from a list of options
10//! - `TextInput` - Single-line text entry
11//! - `TextList` - List of strings with add/remove
12//! - `MapInput` - Key-value map with expandable entries
13//! - `Button` - Clickable action button
14//!
15//! ## Pattern
16//! Each control follows a consistent pattern:
17//! - `*State` struct containing the control's data
18//! - `*Colors` struct for theming
19//! - `render_*` function that renders to a frame and returns hit areas
20
21pub mod button;
22pub mod dropdown;
23pub mod dual_list;
24pub mod keybinding_list;
25pub mod map_input;
26pub mod number_input;
27pub mod text_input;
28pub mod text_list;
29pub mod toggle;
30
31pub use button::{
32    render_button, render_button_row, ButtonColors, ButtonEvent, ButtonLayout, ButtonState,
33};
34pub use dropdown::{
35    render_dropdown, render_dropdown_aligned, DropdownColors, DropdownEvent, DropdownLayout,
36    DropdownState,
37};
38pub use dual_list::{
39    render_dual_list_partial, DualListColors, DualListColumn, DualListHit, DualListLayout,
40    DualListState,
41};
42pub use keybinding_list::{
43    render_keybinding_list, KeybindingListColors, KeybindingListEvent, KeybindingListLayout,
44    KeybindingListState,
45};
46pub use map_input::{render_map, MapColors, MapEvent, MapLayout, MapState};
47pub use number_input::{
48    render_number_input, render_number_input_aligned, NumberInputColors, NumberInputEvent,
49    NumberInputLayout, NumberInputState,
50};
51pub use text_input::{
52    render_text_input, render_text_input_aligned, TextInputColors, TextInputEvent, TextInputLayout,
53    TextInputState,
54};
55pub use text_list::{
56    render_text_list, TextListColors, TextListEvent, TextListLayout, TextListState,
57};
58pub use toggle::{
59    render_toggle, render_toggle_aligned, ToggleColors, ToggleEvent, ToggleLayout, ToggleState,
60};
61
62use ratatui::style::Color;
63
64/// Common colors shared across controls
65#[derive(Debug, Clone, Copy)]
66pub struct ControlColors {
67    /// Background color
68    pub bg: Color,
69    /// Foreground/text color
70    pub fg: Color,
71    /// Border color
72    pub border: Color,
73    /// Focused/active accent color
74    pub accent: Color,
75    /// Disabled text color
76    pub disabled: Color,
77}
78
79impl Default for ControlColors {
80    fn default() -> Self {
81        Self {
82            bg: Color::Black,
83            fg: Color::White,
84            border: Color::DarkGray,
85            accent: Color::Cyan,
86            disabled: Color::DarkGray,
87        }
88    }
89}
90
91impl ControlColors {
92    /// Create control colors from a theme
93    pub fn from_theme(theme: &crate::view::theme::Theme) -> Self {
94        Self {
95            bg: theme.editor_bg,
96            fg: theme.editor_fg,
97            border: theme.split_separator_fg,
98            accent: theme.selection_bg,
99            disabled: theme.line_number_fg,
100        }
101    }
102}
103
104/// Focus state for controls
105#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
106pub enum FocusState {
107    #[default]
108    Normal,
109    Focused,
110    Hovered,
111    Disabled,
112}