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