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