1mod event;
2mod global_state;
3mod icon;
4mod index_path;
5#[cfg(any(feature = "inspector", debug_assertions))]
6mod inspector;
7mod kbd;
8mod root;
9mod styled;
10mod time;
11mod title_bar;
12mod tree;
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 menu;
44pub mod modal;
45pub mod notification;
46pub mod plot;
47pub mod popover;
48pub mod progress;
49pub mod radio;
50pub mod resizable;
51pub mod scroll;
52pub mod sidebar;
53pub mod skeleton;
54pub mod slider;
55pub mod switch;
56pub mod tab;
57pub mod table;
58pub mod tag;
59pub mod text;
60pub mod theme;
61pub mod tooltip;
62
63#[cfg(feature = "webview")]
64pub mod webview;
65
66use gpui::{App, SharedString};
67#[cfg(feature = "webview")]
69pub use wry;
70
71pub use crate::Disableable;
72pub use event::InteractiveElementExt;
73pub use index_path::IndexPath;
74pub use input::{Rope, RopeExt, RopeLines};
75#[cfg(any(feature = "inspector", debug_assertions))]
76pub use inspector::*;
77pub use list::*;
78pub use menu::{context_menu, popup_menu};
79pub use root::{ContextModal, Root};
80pub use styled::*;
81pub use time::*;
82pub use title_bar::*;
83pub use tree::*;
84pub use virtual_list::{h_virtual_list, v_virtual_list, VirtualList, VirtualListScrollHandle};
85pub use window_border::{window_border, window_paddings, WindowBorder};
86
87pub use icon::*;
88pub use kbd::*;
89pub use theme::*;
90
91use std::ops::Deref;
92
93rust_i18n::i18n!("locales", fallback = "en");
94
95pub fn init(cx: &mut App) {
99 theme::init(cx);
100 global_state::init(cx);
101 #[cfg(any(feature = "inspector", debug_assertions))]
102 inspector::init(cx);
103 root::init(cx);
104 date_picker::init(cx);
105 color_picker::init(cx);
106 dock::init(cx);
107 drawer::init(cx);
108 dropdown::init(cx);
109 input::init(cx);
110 list::init(cx);
111 modal::init(cx);
112 popover::init(cx);
113 menu::init(cx);
114 table::init(cx);
115 text::init(cx);
116 tree::init(cx);
117}
118
119#[inline]
120pub fn locale() -> impl Deref<Target = str> {
121 rust_i18n::locale()
122}
123
124#[inline]
125pub fn set_locale(locale: &str) {
126 rust_i18n::set_locale(locale)
127}
128
129#[inline]
130pub(crate) fn measure_enable() -> bool {
131 std::env::var("ZED_MEASUREMENTS").is_ok() || std::env::var("GPUI_MEASUREMENTS").is_ok()
132}
133
134#[inline]
138#[track_caller]
139pub fn measure_if(name: impl Into<SharedString>, if_: bool, f: impl FnOnce()) {
140 if if_ && measure_enable() {
141 let measure = Measure::new(name);
142 f();
143 measure.end();
144 } else {
145 f();
146 }
147}
148
149#[inline]
151#[track_caller]
152pub fn measure(name: impl Into<SharedString>, f: impl FnOnce()) {
153 measure_if(name, true, f);
154}
155
156pub struct Measure {
157 name: SharedString,
158 start: std::time::Instant,
159}
160
161impl Measure {
162 #[track_caller]
163 pub fn new(name: impl Into<SharedString>) -> Self {
164 Self {
165 name: name.into(),
166 start: std::time::Instant::now(),
167 }
168 }
169
170 #[track_caller]
171 pub fn end(self) {
172 let duration = self.start.elapsed();
173 tracing::trace!("{} in {:?}", self.name, duration);
174 }
175}