Skip to main content

wgpui_component/
lib.rs

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