Skip to main content

gpui_component/
lib.rs

1#[cfg(feature = "gpui-fast")]
2extern crate gpui_fast as gpui;
3
4use gpui::App;
5use std::ops::Deref;
6use std::sync::LazyLock;
7
8mod component_traits;
9mod element_ext;
10pub mod global_state;
11mod icon;
12mod index_path;
13#[cfg(any(feature = "inspector", debug_assertions))]
14mod inspector;
15mod root;
16mod sizing;
17mod styled;
18mod time;
19mod title_bar;
20mod touch_selection;
21mod virtual_list;
22mod window_border;
23mod window_ext;
24
25pub(crate) mod actions {
26    pub use gpui_base::actions::*;
27}
28
29pub mod accordion;
30pub mod alert;
31pub mod attachment;
32pub mod avatar;
33pub mod badge;
34pub mod breadcrumb;
35pub mod bubble;
36pub mod button;
37pub mod carousel;
38pub mod chart;
39pub mod checkbox;
40pub mod clipboard;
41pub mod collapsible;
42pub mod color_picker;
43pub mod combobox;
44pub mod command;
45pub mod description_list;
46pub mod dialog;
47pub mod diff;
48pub mod dock;
49pub mod empty;
50pub mod form;
51pub mod grid_layout;
52pub mod group_box;
53pub mod highlighter;
54pub mod history;
55pub mod hover_card;
56pub mod input;
57pub mod kbd;
58pub mod label;
59pub mod link;
60pub mod list;
61pub mod marker;
62pub mod menu;
63pub mod message;
64pub mod message_scroller;
65pub mod native_menu;
66pub mod notification;
67pub mod pagination;
68pub mod plot;
69pub mod popover;
70pub mod progress;
71pub mod questionnaire;
72pub mod radio;
73pub mod rating;
74pub mod resizable;
75pub mod scroll;
76pub mod searchable_list;
77pub mod select;
78pub mod separator;
79pub mod setting;
80pub mod sheet;
81pub mod shimmer;
82pub mod sidebar;
83pub mod skeleton;
84pub mod slider;
85pub mod speech;
86pub mod spinner;
87pub mod status_bar;
88pub mod stepper;
89pub mod switch;
90pub mod tab;
91pub mod table;
92pub mod tag;
93pub mod text;
94pub mod theme;
95pub mod toolbar;
96pub mod tooltip;
97pub mod tree;
98
99pub use crate::Disableable;
100pub use element_ext::*;
101pub use global_state::GlobalState;
102pub use gpui_base::Root;
103pub use gpui_base::animation;
104pub use gpui_base::{
105    AxisExt, Edges, FocusTrapElement, InteractiveElementExt, LengthExt, Measure, OngoingScrollExt,
106    Placement, Side, measure, measure_if,
107};
108pub use gpui_component_macros::icon_named;
109pub use icon::*;
110pub use index_path::IndexPath;
111pub use input::{Rope, RopeExt, RopeLines};
112#[cfg(any(feature = "inspector", debug_assertions))]
113pub use inspector::*;
114pub use resizable::{
115    ResizablePanel, ResizablePanelEvent, ResizablePanelGroup, ResizableState, h_resizable,
116    resizable_panel, resize_handle, resize_handle_appearance, v_resizable,
117};
118pub use styled::*;
119pub use theme::*;
120pub use time::{calendar, date_picker, time_field};
121pub use title_bar::*;
122pub use virtual_list::{VirtualList, VirtualListScrollHandle, h_virtual_list, v_virtual_list};
123pub use window_border::{WindowBorder, window_border, window_corner_radii, window_paddings};
124pub use window_ext::WindowExt;
125
126rust_i18n::i18n!("locales", fallback = "en");
127
128/// Initialize the components.
129///
130/// You must initialize the components at your application's entry point.
131pub fn init(cx: &mut App) {
132    theme::init(cx);
133    global_state::init(cx);
134    #[cfg(any(feature = "inspector", debug_assertions))]
135    inspector::init(cx);
136    root::init(cx);
137    gpui_base::init(cx);
138    input::init(cx);
139    diff::init(cx);
140    date_picker::init(cx);
141    dock::init(cx);
142    sheet::init(cx);
143    list::init(cx);
144    command::init(cx);
145    carousel::init(cx);
146    notification::init(cx);
147    popover::init(cx);
148    questionnaire::init(cx);
149    menu::init(cx);
150    table::init(cx);
151    tooltip::init(cx);
152}
153
154#[inline]
155pub fn locale() -> impl Deref<Target = str> {
156    rust_i18n::locale()
157}
158
159#[inline]
160pub fn set_locale(locale: &str) {
161    rust_i18n::set_locale(locale)
162}
163
164/// Whether measurement logging is enabled, read once per process.
165///
166/// Measurement is a startup debug flag, and the table queries it for every
167/// rendered cell, so cache it instead of reading the environment each call.
168#[inline]
169pub(crate) fn measure_enable() -> bool {
170    static MEASURE_ENABLED: LazyLock<bool> = LazyLock::new(gpui_base::measurement_enabled);
171    *MEASURE_ENABLED
172}
173
174/// Draws a frame that re-renders every view. GPUI Fast replays retained
175/// subtrees when nothing was invalidated, so a bare `window.draw` in a test
176/// would skip `render`/`paint` and any side-channel recording they do.
177#[cfg(test)]
178pub(crate) fn test_redraw(window: &mut gpui::Window, cx: &mut gpui::App) {
179    window.refresh();
180    window.draw(cx).clear(cx);
181}