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