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