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