1use rgpui::{App, SharedString};
2use std::ops::Deref;
3
4mod async_util;
5mod element_ext;
6mod event;
7mod focus_trap;
8mod geometry;
9pub mod global_state;
10mod icon;
11mod index_path;
12#[cfg(any(feature = "inspector", debug_assertions))]
13mod inspector;
14mod root;
15mod styled;
16mod time;
17mod title_bar;
18mod virtual_list;
19mod window_border;
20mod window_ext;
21
22pub mod actions;
23
24pub mod accordion;
25pub mod alert;
26pub mod animation;
27pub mod avatar;
28pub mod badge;
29pub mod breadcrumb;
30pub mod button;
31pub mod chart;
32pub mod checkbox;
33pub mod clipboard;
34pub mod collapsible;
35pub mod color_picker;
36pub mod combobox;
37pub mod description_list;
38pub mod dialog;
39pub mod dock;
40pub mod form;
41pub mod group_box;
42pub mod highlighter;
43pub mod history;
44pub mod hover_card;
45pub mod input;
46pub mod kbd;
47pub mod label;
48pub mod link;
49pub mod list;
50pub mod menu;
51pub mod native_menu;
52pub mod notification;
53pub mod pagination;
54pub mod plot;
55pub mod popover;
56pub mod progress;
57pub mod radio;
58pub mod rating;
59pub mod resizable;
60pub mod scroll;
61pub mod searchable_list;
62pub mod select;
63pub mod separator;
64pub mod setting;
65pub mod sheet;
66pub mod sidebar;
67pub mod skeleton;
68pub mod slider;
69pub mod spinner;
70pub mod status_bar;
71pub mod stepper;
72pub mod switch;
73pub mod tab;
74pub mod table;
75pub mod tag;
76pub mod text;
77pub mod theme;
78pub mod tooltip;
79pub mod tree;
80
81pub use crate::Disableable;
82pub use element_ext::*;
83pub use event::InteractiveElementExt;
84pub use focus_trap::FocusTrapElement;
85pub use geometry::*;
86pub use global_state::GlobalState;
87pub use icon::*;
88pub use index_path::IndexPath;
89pub use input::{Rope, RopeExt, RopeLines};
90#[cfg(any(feature = "inspector", debug_assertions))]
91pub use inspector::*;
92pub use rgpui_component_macros::icon_named;
93pub use root::Root;
94pub use styled::*;
95pub use theme::*;
96pub use time::{calendar, date_picker};
97pub use title_bar::*;
98pub use virtual_list::{VirtualList, VirtualListScrollHandle, h_virtual_list, v_virtual_list};
99pub use window_border::{WindowBorder, window_border, window_paddings};
100pub use window_ext::WindowExt;
101
102rust_i18n::i18n!("locales", fallback = "en");
103
104pub fn init(cx: &mut App) {
108 theme::init(cx);
109 global_state::init(cx);
110 #[cfg(any(feature = "inspector", debug_assertions))]
111 inspector::init(cx);
112 root::init(cx);
113 focus_trap::init(cx);
114 color_picker::init(cx);
115 date_picker::init(cx);
116 dock::init(cx);
117 sheet::init(cx);
118 combobox::init(cx);
119 select::init(cx);
120 input::init(cx);
121 list::init(cx);
122 dialog::init(cx);
123 popover::init(cx);
124 menu::init(cx);
125 table::init(cx);
126 text::init(cx);
127 tree::init(cx);
128 tooltip::init(cx);
129}
130
131#[inline]
132pub fn locale() -> impl Deref<Target = str> {
133 rust_i18n::locale()
134}
135
136#[inline]
137pub fn set_locale(locale: &str) {
138 rust_i18n::set_locale(locale)
139}
140
141#[inline]
142pub(crate) fn measure_enable() -> bool {
143 std::env::var("ZED_MEASUREMENTS").is_ok() || std::env::var("GPUI_MEASUREMENTS").is_ok()
144}
145
146#[inline]
150#[track_caller]
151pub fn measure_if(name: impl Into<SharedString>, if_: bool, f: impl FnOnce()) {
152 if if_ && measure_enable() {
153 let measure = Measure::new(name);
154 f();
155 measure.end();
156 } else {
157 f();
158 }
159}
160
161#[inline]
163#[track_caller]
164pub fn measure(name: impl Into<SharedString>, f: impl FnOnce()) {
165 measure_if(name, true, f);
166}
167
168pub struct Measure {
169 name: SharedString,
170 start: std::time::Instant,
171}
172
173impl Measure {
174 #[track_caller]
175 pub fn new(name: impl Into<SharedString>) -> Self {
176 Self {
177 name: name.into(),
178 start: std::time::Instant::now(),
179 }
180 }
181
182 #[track_caller]
183 pub fn end(self) {
184 let duration = self.start.elapsed();
185 tracing::trace!("{} in {:?}", self.name, duration);
186 }
187}