Skip to main content

gpui_base/
lib.rs

1//! Behavior and infrastructure foundations for GPUI applications.
2//!
3//! Primitives deliberately avoid presentation styles. Layout, positioning,
4//! colors, sizing, and motion belong to applications or the
5//! `gpui-component` façade.
6
7mod accordion;
8pub mod actions;
9mod alert_dialog;
10pub mod animation;
11#[doc(hidden)]
12pub mod async_util;
13mod auto_scroll;
14mod avatar;
15mod button;
16mod calendar;
17mod checkbox;
18mod collapsible;
19mod color_picker;
20mod combobox;
21pub mod component_traits;
22mod date_picker;
23mod dialog;
24pub mod dock;
25mod element_ext;
26mod event;
27mod focus_trap;
28mod geometry;
29mod global_state;
30mod history;
31mod hover_card;
32mod index_path;
33pub mod input;
34mod link;
35mod list_settings;
36#[cfg(all(target_os = "macos", not(test)))]
37mod macos_accessibility;
38mod measure;
39pub mod motion;
40mod nav_stack;
41mod number_input;
42mod observe;
43mod otp_input;
44mod pagination;
45pub mod plot;
46mod popover;
47mod popup;
48mod positioner;
49mod progress;
50pub mod questionnaire;
51mod radio;
52mod radio_group;
53mod reduce_motion;
54mod resizable;
55mod root;
56mod scroll_bounce;
57mod scrollable_mask;
58mod scrollbar;
59mod select;
60mod selectable_text;
61mod sheet;
62pub mod slider;
63mod state_style;
64mod styled;
65mod switch;
66mod table;
67mod tabs;
68pub mod text;
69mod text_boundary;
70mod text_selection;
71mod theme;
72pub mod theme_tokens;
73mod time_field;
74mod toast;
75mod toggle;
76mod toggle_group;
77mod toolbar;
78mod tooltip;
79mod touch_selection;
80mod tree;
81mod undo_history;
82mod virtual_list;
83
84pub use accordion::{Accordion, AccordionHeader, AccordionItem, AccordionPanel, AccordionTrigger};
85pub use alert_dialog::{
86    AlertDialog, AlertDialogAction, AlertDialogBackdrop, AlertDialogCancel, AlertDialogClose,
87    AlertDialogDescription, AlertDialogPopup, AlertDialogTitle, AlertDialogTrigger,
88};
89pub use auto_scroll::AutoScroll;
90pub use avatar::{Avatar, AvatarFallback, AvatarImage};
91pub use button::{Button, ButtonStyles};
92pub use calendar::{
93    Calendar, CalendarEvent, CalendarItem, CalendarItemKind, CalendarItemState, CalendarState,
94    CalendarView, Date, IntervalMatcher, Matcher, RangeMatcher,
95};
96pub use checkbox::{
97    Checkbox, CheckboxIndicator, CheckboxIndicatorStyles, CheckboxState, CheckboxStyles,
98};
99pub use collapsible::Collapsible;
100pub use color_picker::{ColorPicker, ColorPickerEvent, ColorPickerState, ColorSwatch, HslaSliders};
101pub use combobox::Combobox;
102pub use component_traits::FocusableExt;
103pub use component_traits::{Disableable, Selectable};
104pub use date_picker::DatePicker;
105pub use dialog::{
106    Dialog, DialogBackdrop, DialogChangeReason, DialogClose, DialogDescription, DialogHandle,
107    DialogPopup, DialogTitle, DialogTrigger,
108};
109pub use element_ext::ElementExt;
110pub use event::{InteractiveElementExt, OngoingScrollExt};
111pub use focus_trap::FocusTrapElement;
112#[doc(hidden)]
113pub use focus_trap::active_focus_trap;
114pub use geometry::*;
115pub use global_state::{DeferredPopover, GlobalState};
116pub use history::History;
117pub use hover_card::{HoverCard, HoverCardState};
118pub use index_path::IndexPath;
119pub use input::{Editor, Input, InputBase, InputStyles, Textarea};
120pub use link::{Link, LinkStyles};
121pub use list_settings::ListSettings;
122#[cfg(all(target_os = "macos", not(test)))]
123#[doc(hidden)]
124pub use macos_accessibility::install_window_hit_test_forwarder;
125#[doc(hidden)]
126pub use measure::measurement_enabled;
127pub use measure::{Measure, measure, measure_if};
128pub use motion::{
129    Discrete, DiscreteError, Easing, EasingError, Interpolate, IterationCount, Keyframe,
130    KeyframeError, Keyframes, LinearStop, MotionPhase, MotionReveal, MotionStatus, MotionTransform,
131    MotionValue, PlaybackDirection, Presence, PresencePhase, PresenceSample, Sequence,
132    SequenceSample, SequenceStep, SignedDuration, Spring, SpringError, Stagger, StaggerOrigin,
133    StepPosition, Timing, TimingSample, Transition, TransitionId, animate_keyframes, spring,
134    transition, transition_with_status,
135};
136pub use nav_stack::{NavMotion, NavOperation, NavPage, NavStack, NavStackEvent, NavStackState};
137pub use number_input::{
138    Decrement, Increment, NumberInput, NumberInputEvent, NumberInputText, NumberStep, StepAction,
139    step_value,
140};
141pub use observe::{ObservedElement, TestSupportExt};
142pub use otp_input::{OtpEvent, OtpInput, OtpState};
143pub use pagination::{Pagination, PaginationItem, PaginationState};
144pub use plot::PlotMotion;
145pub use popover::{Popover, PopoverState};
146pub use popup::{POPUP_PRIORITY, Popup};
147pub use positioner::{Align, Positioner, ResolvedPosition};
148pub use progress::{Progress, ProgressIndicator, ProgressTrack};
149pub use radio::{Radio, RadioStyles};
150pub use radio_group::RadioGroup;
151pub use reduce_motion::apply_system_reduce_motion;
152pub use resizable::{
153    HandleEdge, ResizablePanel, ResizablePanelEvent, ResizablePanelGroup, ResizableState,
154    ResizeHandleContext, ResizeHandleRenderer, ResizeHandleState, h_resizable, resizable_panel,
155    v_resizable,
156};
157#[doc(hidden)]
158pub use resizable::{PANEL_MIN_SIZE, resize_handle};
159pub use root::{Root, RootPlugin};
160pub use scroll_bounce::{ScrollBounce, ScrollBounceMotion};
161pub use scrollable_mask::ScrollableMask;
162pub use scrollbar::{
163    Scrollbar, ScrollbarAxis, ScrollbarEntrance, ScrollbarHandle, ScrollbarMode, ScrollbarMotion,
164    ScrollbarStyles, ScrollbarThumbStyle, ScrollbarTrackStyle,
165};
166pub use select::Select;
167pub use selectable_text::SelectableText;
168pub use sheet::Sheet;
169pub use slider::{Slider, SliderIndicator, SliderThumb, SliderTrack};
170pub use state_style::StateStyle;
171#[cfg(any(feature = "inspector", debug_assertions))]
172pub use styled::styled_ext_reflection_methods;
173pub use styled::{RoleOverride, StyledExt, box_shadow, h_flex, v_flex};
174pub use switch::{
175    Switch, SwitchStyles, SwitchThumb, SwitchThumbStyles, SwitchTrack, SwitchTrackStyles,
176};
177pub use table::{Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow};
178pub use tabs::{Tab, TabStyles, Tabs};
179pub use text::{
180    InlineElement, InlineRenderContext, MarkdownExtensions, MarkdownNode, MarkdownParseContext,
181    MarkdownPlugin, RangeHighlight, RangeHighlightError, RenderedText, SelectionFormat, TableData,
182    Text, TextView, TextViewDefaults, TextViewMotion, TextViewPlugin, TextViewState, TextViewStyle,
183    html, markdown, markdown_ast,
184};
185pub use text_selection::{
186    TextSelection, TextSelectionContentKey, TextSelectionCoverage, TextSelectionEndpoint,
187    TextSelectionEvent, TextSelectionHandle, TextSelectionLayer, TextSelectionProjection,
188    TextSelectionRegistration, TextSelectionRun, TextSelectionScopeId, TextSelectionSnapshot,
189    TextSelectionWindowPoints, TouchHandleLayout,
190};
191pub use theme::{PlotTheme, ResizableTheme, ScrollbarTheme, Theme, ThemeAppearance};
192pub use theme_tokens::{
193    ColorTokens, RadiusTokens, SemanticThemeTokens, ShadowTokens, SpacingTokens, TextStyleToken,
194    TypographyTokens,
195};
196pub use time_field::{
197    HourCycle, TimeField, TimeFieldEvent, TimeFieldSegment, TimeFieldSegmentState, TimeFieldState,
198    TimePrecision, TimeSegment,
199};
200pub use toast::{
201    Toast, ToastAdvance, ToastManager, ToastMotion, ToastOptions, ToastStack, ToastStackState,
202    ToastTransitionStatus,
203};
204pub use toggle::{Toggle, ToggleStyles};
205pub use toggle_group::ToggleGroup;
206pub use toolbar::{Toolbar, ToolbarGroup};
207pub use tooltip::{Tooltip, TooltipOverlay, TooltipPositioner, TooltipRequest, TooltipTransition};
208pub use touch_selection::{SelectionEdge, TouchHandle, TouchSelectionSnapshot};
209pub use tree::{Tree, TreeEntry, TreeEntryState, TreeEvent, TreeItem, TreeState};
210#[doc(hidden)]
211pub use tree::{init as init_tree, key_context as tree_key_context};
212pub use undo_history::UndoHistory;
213#[doc(hidden)]
214pub use virtual_list::virtual_list;
215pub use virtual_list::{VirtualList, VirtualListScrollHandle, h_virtual_list, v_virtual_list};
216
217use gpui::App;
218
219/// Returns whether the application is compiled for iOS or Android.
220///
221/// This is a compile-time platform check, not a screen-size or input-device check.
222#[inline]
223pub const fn is_mobile() -> bool {
224    cfg!(any(target_os = "ios", target_os = "android"))
225}
226
227/// Initializes global infrastructure owned by the base layer.
228pub fn init(cx: &mut App) {
229    let _ = Theme::global_mut(cx);
230    GlobalState::init(cx);
231    reduce_motion::init(cx);
232    dialog::init(cx);
233    focus_trap::init(cx);
234    popover::init(cx);
235    sheet::init(cx);
236    combobox::init(cx);
237    color_picker::init(cx);
238    select::init(cx);
239    number_input::init(cx);
240    time_field::init(cx);
241    input::init(cx);
242    tree::init(cx);
243    text::init(cx);
244    root::init(cx);
245}
246
247#[cfg(feature = "test-support")]
248pub mod test_support;