ccf_gpui_widgets/lib.rs
1//! ccf-gpui-widgets - Reusable GPUI widgets for building desktop applications
2//!
3//! This crate provides a collection of ready-to-use UI widgets built on top of GPUI,
4//! the GPU-accelerated UI framework from Zed Industries.
5//!
6//! # Features
7//!
8//! - **Themeable**: All widgets support custom themes via a global context or per-widget override
9//! - **Accessible**: Keyboard navigation support where applicable
10//! - **Event-driven**: All widgets emit events for state changes
11//! - **Builder pattern**: Fluent API for widget configuration
12//!
13//! # Quick Start
14//!
15//! ```ignore
16//! use gpui::*;
17//! use ccf_gpui_widgets::{Theme, widgets::*};
18//!
19//! Application::new().run(|cx: &mut App| {
20//! // Register keybindings for widgets that need them
21//! register_all_keybindings(cx);
22//!
23//! // Optionally set a global theme
24//! cx.set_global(Theme::dark());
25//!
26//! cx.open_window(WindowOptions::default(), |_window, cx| {
27//! cx.new(|cx| {
28//! // Create your widgets
29//! let input = cx.new(|cx| TextInput::new(cx).placeholder("Enter text..."));
30//! let checkbox = cx.new(|cx| Checkbox::new(cx).label("Enable feature"));
31//! // ...
32//! })
33//! }).unwrap();
34//!
35//! cx.activate(true);
36//! });
37//! ```
38//!
39//! # Available Widgets
40//!
41//! ## Input Widgets
42//!
43//! - [`TextInput`](widgets::TextInput) - Full-featured text input with cursor, selection, clipboard
44//! - [`PasswordInput`](widgets::PasswordInput) - Text input with visibility toggle
45//! - [`NumberStepper`](widgets::NumberStepper) - Numeric input with +/- buttons
46//! - [`Slider`](widgets::Slider) - Horizontal slider for numeric ranges
47//!
48//! ## Selection Widgets
49//!
50//! - [`Checkbox`](widgets::Checkbox) - Simple checkbox with optional label
51//! - [`ToggleSwitch`](widgets::ToggleSwitch) - On/off toggle with configurable label position
52//! - [`Dropdown`](widgets::Dropdown) - Select/dropdown with keyboard navigation
53//! - [`RadioGroup`](widgets::RadioGroup) - Single-selection from multiple choices
54//! - [`CheckboxGroup`](widgets::CheckboxGroup) - Multi-selection from multiple choices
55//! - [`ColorSwatch`](widgets::ColorSwatch) - Color picker with hex input, HSV canvas
56//!
57//! ## Display Widgets
58//!
59//! - [`Tooltip`](widgets::Tooltip) - Hover tooltip
60//! - [`ProgressBar`](widgets::ProgressBar) - Progress indicator (determinate/indeterminate)
61//! - [`Spinner`](widgets::Spinner) - Loading spinner in multiple sizes
62//!
63//! ## Layout & Navigation
64//!
65//! - [`Collapsible`](widgets::Collapsible) - Expandable/collapsible section
66//! - [`TabBar`](widgets::TabBar) - Tab navigation with keyboard support
67//! - [`ConfirmationDialog`](widgets::ConfirmationDialog) - Modal dialogs (Info/Default/Warning/Danger styles)
68//!
69//! ## Repeatable Widgets
70//!
71//! - [`RepeatableTextInput`](widgets::RepeatableTextInput) - Text input with add/remove for lists
72//!
73#![cfg_attr(feature = "file-picker", doc = "## File Widgets (requires `file-picker` feature)")]
74#![cfg_attr(feature = "file-picker", doc = "")]
75# - File selection with native dialog")]
76# - Directory selection with native dialog")]
77# - File picker with add/remove for lists")]
78# - Directory picker with add/remove for lists")]
79//!
80//! ## Utilities
81//!
82//! - [`primary_button`](widgets::primary_button) - Blue/accent styled button
83//! - [`secondary_button`](widgets::secondary_button) - Gray styled button
84//! - [`danger_button`](widgets::danger_button) - Red styled button
85//! - [`with_focus_actions`](widgets::with_focus_actions) - Add Tab/Shift-Tab focus navigation to elements
86//!
87//! # Feature Flags
88//!
89//! - `file-picker` - Enables FilePicker and DirectoryPicker widgets (adds `rfd` and `dirs` dependencies)
90//! - `full` - Enables all optional features
91//!
92//! # Theming
93//!
94//! Widgets use a [`Theme`] struct for colors. You can:
95//!
96//! 1. Set a global theme: `cx.set_global(Theme::dark())`
97//! 2. Use per-widget themes: `TextInput::new(cx).theme(my_theme)`
98//! 3. Use the default (dark theme) if nothing is set
99//!
100//! ```ignore
101//! use ccf_gpui_widgets::Theme;
102//!
103//! // Built-in themes
104//! let dark = Theme::dark();
105//! let light = Theme::light();
106//!
107//! // Customize with builder methods (all ~30 fields have with_* methods)
108//! let custom = Theme::dark()
109//! .with_accent(0x00ff00)
110//! .with_primary(0xff0000)
111//! .with_bg_input(0x333333)
112//! .with_border_input(0x666666)
113//! .with_tooltip_bg(0x222222)
114//! .with_selection(0x264F78);
115//! ```
116
117pub mod theme;
118pub mod utils;
119pub mod widgets;
120
121// Convenient re-exports
122pub use theme::{Theme, Palette};
123pub use widgets::register_all_keybindings;
124
125/// Prelude for convenient imports
126pub mod prelude {
127 pub use crate::theme::{get_theme, get_theme_or, Theme, Palette};
128 pub use crate::widgets::{
129 register_all_keybindings,
130 TextInput, TextInputEvent,
131 Checkbox, CheckboxEvent,
132 Dropdown, DropdownEvent,
133 NumberStepper, NumberStepperEvent,
134 RadioGroup, RadioGroupEvent,
135 CheckboxGroup, CheckboxGroupEvent,
136 ColorSwatch, ColorSwatchEvent,
137 Collapsible, CollapsibleEvent,
138 Tooltip,
139 primary_button, secondary_button, danger_button,
140 PasswordInput, PasswordInputEvent,
141 TabBar, TabBarEvent,
142 RepeatableTextInput, RepeatableTextInputEvent,
143 ToggleSwitch, ToggleSwitchEvent, LabelPosition,
144 Slider, SliderEvent,
145 ProgressBar, ProgressBarEvent,
146 Spinner, SpinnerSize,
147 ConfirmationDialog, ConfirmationDialogEvent, DialogStyle, DialogButton,
148 Scrollable, scrollable_vertical, scrollable_horizontal, scrollable_both,
149 ScrollbarAxis,
150 SegmentedControl, SegmentedControlEvent, SegmentOption,
151 SidebarNav, SidebarNavEvent,
152 SelectionItem, StringItem,
153 };
154
155 #[cfg(feature = "file-picker")]
156 pub use crate::widgets::{
157 FilePicker, FilePickerEvent, FileMode, MissingDirectories,
158 DirectoryPicker, DirectoryPickerEvent,
159 RepeatableFilePicker, RepeatableFilePickerEvent,
160 RepeatableDirectoryPicker, RepeatableDirectoryPickerEvent,
161 };
162
163 pub use crate::utils::{parse_path, expand_tilde, PathInfo};
164}