Skip to main content

guise/input/
mod.rs

1//! Form inputs.
2//!
3//! Two flavors, matching how each control naturally behaves in gpui:
4//!
5//! - **Controlled** ([`Checkbox`], [`Switch`], [`Radio`]) are `RenderOnce`
6//!   builders. The parent view owns the value and passes a change handler —
7//!   wire it with `cx.listener(...)`.
8//! - **Stateful** ([`TextInput`], [`Select`]) are gpui entities (`Render` +
9//!   `EventEmitter`) that own their buffer/open-state. Create with
10//!   `cx.new(|cx| TextInput::new(cx))` and subscribe for changes.
11
12mod checkbox;
13mod checkboxgroup;
14mod colorinput;
15mod combobox;
16mod edit;
17mod field;
18mod keys;
19mod number;
20mod password;
21mod pin;
22mod radio;
23mod radiogroup;
24mod rangeslider;
25mod rating;
26mod segmented;
27mod select;
28mod slider;
29mod switch;
30mod tags;
31mod text;
32mod textarea;
33
34pub use checkbox::Checkbox;
35pub use checkboxgroup::CheckboxGroup;
36pub use colorinput::{ColorInput, ColorInputEvent};
37pub use combobox::{Combobox, ComboboxEvent};
38pub use edit::TextEdit;
39pub use field::Field;
40pub use keys::{apply_key, KeyOutcome};
41pub use number::{NumberInput, NumberInputEvent};
42pub use password::{PasswordInput, PasswordInputEvent};
43pub use pin::{PinInput, PinInputEvent};
44pub use radio::Radio;
45pub use radiogroup::RadioGroup;
46pub use rangeslider::{RangeSlider, RangeSliderEvent};
47pub use rating::Rating;
48pub use segmented::{SegmentedControl, SegmentedControlEvent};
49pub use select::{Select, SelectEvent};
50pub use slider::{Slider, SliderEvent};
51pub use switch::Switch;
52pub use tags::{TagsInput, TagsInputEvent};
53pub use text::{TextInput, TextInputEvent};
54pub use textarea::{TextArea, TextAreaEvent};
55
56use gpui::{App, ClickEvent, Window};
57
58use crate::theme::Size;
59
60/// Boxed click handler shared by the controlled inputs.
61pub(crate) type ClickHandler = Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>;
62
63/// Box dimension (px) for square toggle controls (Checkbox, Radio).
64pub(crate) fn control_box_size(size: Size) -> f32 {
65    match size {
66        Size::Xs => 16.0,
67        Size::Sm => 18.0,
68        Size::Md => 20.0,
69        Size::Lg => 24.0,
70        Size::Xl => 28.0,
71    }
72}
73
74/// (height, horizontal padding, font size) for text-like controls.
75pub(crate) fn control_metrics(size: Size) -> (f32, f32, f32) {
76    match size {
77        Size::Xs => (30.0, 10.0, 12.0),
78        Size::Sm => (36.0, 12.0, 14.0),
79        Size::Md => (42.0, 14.0, 16.0),
80        Size::Lg => (50.0, 16.0, 18.0),
81        Size::Xl => (60.0, 20.0, 20.0),
82    }
83}