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::{
169    HorizontalScrollClaim, RoundedFrameCover, ScrollableMask, last_horizontal_scroll_claim,
170};
171pub use scrollbar::{
172    Scrollbar, ScrollbarAxis, ScrollbarEntrance, ScrollbarHandle, ScrollbarMode, ScrollbarMotion,
173    ScrollbarStyles, ScrollbarThumbStyle, ScrollbarTrackStyle,
174};
175pub use select::Select;
176pub use selectable_text::SelectableText;
177pub use sheet::Sheet;
178pub use slider::{Slider, SliderIndicator, SliderThumb, SliderTrack};
179pub use state_style::StateStyle;
180#[cfg(any(feature = "inspector", debug_assertions))]
181pub use styled::styled_ext_reflection_methods;
182pub use styled::{RoleOverride, StyledExt, box_shadow, h_flex, v_flex};
183pub use switch::{
184    Switch, SwitchStyles, SwitchThumb, SwitchThumbStyles, SwitchTrack, SwitchTrackStyles,
185};
186pub use table::{Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow};
187pub use tabs::{Tab, TabStyles, Tabs};
188pub use text::{
189    InlineElement, InlineRenderContext, MarkdownExtensions, MarkdownNode, MarkdownParseContext,
190    MarkdownPlugin, RangeHighlight, RangeHighlightError, RenderedText, SelectionFormat, TableData,
191    Text, TextView, TextViewDefaults, TextViewMotion, TextViewPlugin, TextViewState, TextViewStyle,
192    html, markdown, markdown_ast,
193};
194pub use text_selection::{
195    TextSelection, TextSelectionContentKey, TextSelectionCoverage, TextSelectionEndpoint,
196    TextSelectionEvent, TextSelectionHandle, TextSelectionLayer, TextSelectionProjection,
197    TextSelectionRegistration, TextSelectionRun, TextSelectionScopeId, TextSelectionSnapshot,
198    TextSelectionWindowPoints, TouchHandleLayout,
199};
200pub use theme::{PlotTheme, ResizableTheme, ScrollbarTheme, Theme, ThemeAppearance};
201pub use theme_tokens::{
202    ColorTokens, RadiusTokens, SemanticThemeTokens, ShadowTokens, SpacingTokens, TextStyleToken,
203    TypographyTokens,
204};
205pub use time_field::{
206    HourCycle, TimeField, TimeFieldEvent, TimeFieldSegment, TimeFieldSegmentState, TimeFieldState,
207    TimePrecision, TimeSegment,
208};
209pub use toast::{
210    Toast, ToastAdvance, ToastManager, ToastMotion, ToastOptions, ToastStack, ToastStackState,
211    ToastTransitionStatus,
212};
213pub use toggle::{Toggle, ToggleStyles};
214pub use toggle_group::ToggleGroup;
215pub use toolbar::{Toolbar, ToolbarGroup};
216pub use tooltip::{
217    Tooltip, TooltipDefaults, TooltipOverlay, TooltipPositioner, TooltipRequest, TooltipTransition,
218};
219pub use touch_selection::{SelectionEdge, TouchHandle, TouchSelectionSnapshot};
220pub use tree::{Tree, TreeEntry, TreeEntryState, TreeEvent, TreeItem, TreeState};
221#[doc(hidden)]
222pub use tree::{init as init_tree, key_context as tree_key_context};
223pub use undo_history::UndoHistory;
224#[doc(hidden)]
225pub use virtual_list::virtual_list;
226pub use virtual_list::{VirtualList, VirtualListScrollHandle, h_virtual_list, v_virtual_list};
227
228use gpui::App;
229
230/// Returns whether the application is compiled for iOS or Android.
231///
232/// This is a compile-time platform check, not a screen-size or input-device check.
233#[inline]
234pub const fn is_mobile() -> bool {
235    cfg!(any(target_os = "ios", target_os = "android"))
236}
237
238/// Initializes global infrastructure owned by the base layer.
239pub fn init(cx: &mut App) {
240    let _ = Theme::global_mut(cx);
241    GlobalState::init(cx);
242    reduce_motion::init(cx);
243    dialog::init(cx);
244    focus_trap::init(cx);
245    popover::init(cx);
246    sheet::init(cx);
247    combobox::init(cx);
248    color_picker::init(cx);
249    select::init(cx);
250    number_input::init(cx);
251    time_field::init(cx);
252    input::init(cx);
253    tree::init(cx);
254    text::init(cx);
255    root::init(cx);
256}
257
258#[cfg(feature = "test-support")]
259pub mod test_support;