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