egui/lib.rs
1//! `egui`: an easy-to-use GUI in pure Rust!
2//!
3//! Try the live web demo: <https://www.egui.rs/#demo>. Read more about egui at <https://github.com/emilk/egui>.
4//!
5//! `egui` is in heavy development, with each new version having breaking changes.
6//! You need to have rust 1.76.0 or later to use `egui`.
7//!
8//! To quickly get started with egui, you can take a look at [`eframe_template`](https://github.com/emilk/eframe_template)
9//! which uses [`eframe`](https://docs.rs/eframe).
10//!
11//! To create a GUI using egui you first need a [`Context`] (by convention referred to by `ctx`).
12//! Then you add a [`Window`] or a [`SidePanel`] to get a [`Ui`], which is what you'll be using to add all the buttons and labels that you need.
13//!
14//!
15//! ## Feature flags
16#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
17//!
18//!
19//! # Using egui
20//!
21//! To see what is possible to build with egui you can check out the online demo at <https://www.egui.rs/#demo>.
22//!
23//! If you like the "learning by doing" approach, clone <https://github.com/emilk/eframe_template> and get started using egui right away.
24//!
25//! ### A simple example
26//!
27//! Here is a simple counter that can be incremented and decremented using two buttons:
28//! ```
29//! fn ui_counter(ui: &mut egui::Ui, counter: &mut i32) {
30//! // Put the buttons and label on the same row:
31//! ui.horizontal(|ui| {
32//! if ui.button("−").clicked() {
33//! *counter -= 1;
34//! }
35//! ui.label(counter.to_string());
36//! if ui.button("+").clicked() {
37//! *counter += 1;
38//! }
39//! });
40//! }
41//! ```
42//!
43//! In some GUI frameworks this would require defining multiple types and functions with callbacks or message handlers,
44//! but thanks to `egui` being immediate mode everything is one self-contained function!
45//!
46//! ### Getting a [`Ui`]
47//!
48//! Use one of [`SidePanel`], [`TopBottomPanel`], [`CentralPanel`], [`Window`] or [`Area`] to
49//! get access to an [`Ui`] where you can put widgets. For example:
50//!
51//! ```
52//! # egui::__run_test_ctx(|ctx| {
53//! egui::CentralPanel::default().show(&ctx, |ui| {
54//! ui.add(egui::Label::new("Hello World!"));
55//! ui.label("A shorter and more convenient way to add a label.");
56//! if ui.button("Click me").clicked() {
57//! // take some action here
58//! }
59//! });
60//! # });
61//! ```
62//!
63//! ### Quick start
64//!
65//! ```
66//! # egui::__run_test_ui(|ui| {
67//! # let mut my_string = String::new();
68//! # let mut my_boolean = true;
69//! # let mut my_f32 = 42.0;
70//! ui.label("This is a label");
71//! ui.hyperlink("https://github.com/emilk/egui");
72//! ui.text_edit_singleline(&mut my_string);
73//! if ui.button("Click me").clicked() { }
74//! ui.add(egui::Slider::new(&mut my_f32, 0.0..=100.0));
75//! ui.add(egui::DragValue::new(&mut my_f32));
76//!
77//! ui.checkbox(&mut my_boolean, "Checkbox");
78//!
79//! #[derive(PartialEq)]
80//! enum Enum { First, Second, Third }
81//! # let mut my_enum = Enum::First;
82//! ui.horizontal(|ui| {
83//! ui.radio_value(&mut my_enum, Enum::First, "First");
84//! ui.radio_value(&mut my_enum, Enum::Second, "Second");
85//! ui.radio_value(&mut my_enum, Enum::Third, "Third");
86//! });
87//!
88//! ui.separator();
89//!
90//! # let my_image = egui::TextureId::default();
91//! ui.image((my_image, egui::Vec2::new(640.0, 480.0)));
92//!
93//! ui.collapsing("Click to see what is hidden!", |ui| {
94//! ui.label("Not much, as it turns out");
95//! });
96//! # });
97//! ```
98//!
99//! ## Viewports
100//! Some egui backends support multiple _viewports_, which is what egui calls the native OS windows it resides in.
101//! See [`crate::viewport`] for more information.
102//!
103//! ## Coordinate system
104//! The left-top corner of the screen is `(0.0, 0.0)`,
105//! with X increasing to the right and Y increasing downwards.
106//!
107//! `egui` uses logical _points_ as its coordinate system.
108//! Those related to physical _pixels_ by the `pixels_per_point` scale factor.
109//! For example, a high-dpi screen can have `pixels_per_point = 2.0`,
110//! meaning there are two physical screen pixels for each logical point.
111//!
112//! Angles are in radians, and are measured clockwise from the X-axis, which has angle=0.
113//!
114//! # Integrating with egui
115//!
116//! Most likely you are using an existing `egui` backend/integration such as [`eframe`](https://docs.rs/eframe), [`bevy_egui`](https://docs.rs/bevy_egui),
117//! or [`egui-miniquad`](https://github.com/not-fl3/egui-miniquad),
118//! but if you want to integrate `egui` into a new game engine or graphics backend, this is the section for you.
119//!
120//! You need to collect [`RawInput`] and handle [`FullOutput`]. The basic structure is this:
121//!
122//! ``` no_run
123//! # fn handle_platform_output(_: egui::PlatformOutput) {}
124//! # fn gather_input() -> egui::RawInput { egui::RawInput::default() }
125//! # fn paint(textures_delta: egui::TexturesDelta, _: Vec<egui::ClippedPrimitive>) {}
126//! let mut ctx = egui::Context::default();
127//!
128//! // Game loop:
129//! loop {
130//! let raw_input: egui::RawInput = gather_input();
131//!
132//! let full_output = ctx.run(raw_input, |ctx| {
133//! egui::CentralPanel::default().show(&ctx, |ui| {
134//! ui.label("Hello world!");
135//! if ui.button("Click me").clicked() {
136//! // take some action here
137//! }
138//! });
139//! });
140//! handle_platform_output(full_output.platform_output);
141//! let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
142//! paint(full_output.textures_delta, clipped_primitives);
143//! }
144//! ```
145//!
146//! For a reference OpenGL renderer, see [the `egui_glow` painter](https://github.com/emilk/egui/blob/master/crates/egui_glow/src/painter.rs).
147//!
148//!
149//! ### Debugging your renderer
150//!
151//! #### Things look jagged
152//!
153//! * Turn off backface culling.
154//!
155//! #### My text is blurry
156//!
157//! * Make sure you set the proper `pixels_per_point` in the input to egui.
158//! * Make sure the texture sampler is not off by half a pixel. Try nearest-neighbor sampler to check.
159//!
160//! #### My windows are too transparent or too dark
161//!
162//! * egui uses premultiplied alpha, so make sure your blending function is `(ONE, ONE_MINUS_SRC_ALPHA)`.
163//! * Make sure your texture sampler is clamped (`GL_CLAMP_TO_EDGE`).
164//! * egui prefers linear color spaces for all blending so:
165//! * Use an sRGBA-aware texture if available (e.g. `GL_SRGB8_ALPHA8`).
166//! * Otherwise: remember to decode gamma in the fragment shader.
167//! * Decode the gamma of the incoming vertex colors in your vertex shader.
168//! * Turn on sRGBA/linear framebuffer if available (`GL_FRAMEBUFFER_SRGB`).
169//! * Otherwise: gamma-encode the colors before you write them again.
170//!
171//!
172//! # Understanding immediate mode
173//!
174//! `egui` is an immediate mode GUI library.
175//!
176//! Immediate mode has its roots in gaming, where everything on the screen is painted at the
177//! display refresh rate, i.e. at 60+ frames per second.
178//! In immediate mode GUIs, the entire interface is laid out and painted at the same high rate.
179//! This makes immediate mode GUIs especially well suited for highly interactive applications.
180//!
181//! It is useful to fully grok what "immediate mode" implies.
182//!
183//! Here is an example to illustrate it:
184//!
185//! ```
186//! # egui::__run_test_ui(|ui| {
187//! if ui.button("click me").clicked() {
188//! take_action()
189//! }
190//! # });
191//! # fn take_action() {}
192//! ```
193//!
194//! This code is being executed each frame at maybe 60 frames per second.
195//! Each frame egui does these things:
196//!
197//! * lays out the letters `click me` in order to figure out the size of the button
198//! * decides where on screen to place the button
199//! * check if the mouse is hovering or clicking that location
200//! * chose button colors based on if it is being hovered or clicked
201//! * add a [`Shape::Rect`] and [`Shape::Text`] to the list of shapes to be painted later this frame
202//! * return a [`Response`] with the [`clicked`](`Response::clicked`) member so the user can check for interactions
203//!
204//! There is no button being created and stored somewhere.
205//! The only output of this call is some colored shapes, and a [`Response`].
206//!
207//! Similarly, consider this code:
208//!
209//! ```
210//! # egui::__run_test_ui(|ui| {
211//! # let mut value: f32 = 0.0;
212//! ui.add(egui::Slider::new(&mut value, 0.0..=100.0).text("My value"));
213//! # });
214//! ```
215//!
216//! Here egui will read `value` (an `f32`) to display the slider, then look if the mouse is dragging the slider and if so change the `value`.
217//! Note that `egui` does not store the slider value for you - it only displays the current value, and changes it
218//! by how much the slider has been dragged in the previous few milliseconds.
219//! This means it is responsibility of the egui user to store the state (`value`) so that it persists between frames.
220//!
221//! It can be useful to read the code for the toggle switch example widget to get a better understanding
222//! of how egui works: <https://github.com/emilk/egui/blob/master/crates/egui_demo_lib/src/demo/toggle_switch.rs>.
223//!
224//! Read more about the pros and cons of immediate mode at <https://github.com/emilk/egui#why-immediate-mode>.
225//!
226//! # Misc
227//!
228//! ## How widgets works
229//!
230//! ```
231//! # egui::__run_test_ui(|ui| {
232//! if ui.button("click me").clicked() { take_action() }
233//! # });
234//! # fn take_action() {}
235//! ```
236//!
237//! is short for
238//!
239//! ```
240//! # egui::__run_test_ui(|ui| {
241//! let button = egui::Button::new("click me");
242//! if ui.add(button).clicked() { take_action() }
243//! # });
244//! # fn take_action() {}
245//! ```
246//!
247//! which is short for
248//!
249//! ```
250//! # use egui::Widget;
251//! # egui::__run_test_ui(|ui| {
252//! let button = egui::Button::new("click me");
253//! let response = button.ui(ui);
254//! if response.clicked() { take_action() }
255//! # });
256//! # fn take_action() {}
257//! ```
258//!
259//! [`Button`] uses the builder pattern to create the data required to show it. The [`Button`] is then discarded.
260//!
261//! [`Button`] implements `trait` [`Widget`], which looks like this:
262//! ```
263//! # use egui::*;
264//! pub trait Widget {
265//! /// Allocate space, interact, paint, and return a [`Response`].
266//! fn ui(self, ui: &mut Ui) -> Response;
267//! }
268//! ```
269//!
270//!
271//! ## Widget interaction
272//! Each widget has a [`Sense`], which defines whether or not the widget
273//! is sensitive to clickicking and/or drags.
274//!
275//! For instance, a [`Button`] only has a [`Sense::click`] (by default).
276//! This means if you drag a button it will not respond with [`Response::dragged`].
277//! Instead, the drag will continue through the button to the first
278//! widget behind it that is sensitive to dragging, which for instance could be
279//! a [`ScrollArea`]. This lets you scroll by dragging a scroll area (important
280//! on touch screens), just as long as you don't drag on a widget that is sensitive
281//! to drags (e.g. a [`Slider`]).
282//!
283//! When widgets overlap it is the last added one
284//! that is considered to be on top and which will get input priority.
285//!
286//! The widget interaction logic is run at the _start_ of each frame,
287//! based on the output from the previous frame.
288//! This means that when a new widget shows up you cannot click it in the same
289//! frame (i.e. in the same fraction of a second), but unless the user
290//! is spider-man, they wouldn't be fast enough to do so anyways.
291//!
292//! By running the interaction code early, egui can actually
293//! tell you if a widget is being interacted with _before_ you add it,
294//! as long as you know its [`Id`] before-hand (e.g. using [`Ui::next_auto_id`]),
295//! by calling [`Context::read_response`].
296//! This can be useful in some circumstances in order to style a widget,
297//! or to respond to interactions before adding the widget
298//! (perhaps on top of other widgets).
299//!
300//!
301//! ## Auto-sizing panels and windows
302//! In egui, all panels and windows auto-shrink to fit the content.
303//! If the window or panel is also resizable, this can lead to a weird behavior
304//! where you can drag the edge of the panel/window to make it larger, and
305//! when you release the panel/window shrinks again.
306//! This is an artifact of immediate mode, and here are some alternatives on how to avoid it:
307//!
308//! 1. Turn off resizing with [`Window::resizable`], [`SidePanel::resizable`], [`TopBottomPanel::resizable`].
309//! 2. Wrap your panel contents in a [`ScrollArea`], or use [`Window::vscroll`] and [`Window::hscroll`].
310//! 3. Use a justified layout:
311//!
312//! ```
313//! # egui::__run_test_ui(|ui| {
314//! ui.with_layout(egui::Layout::top_down_justified(egui::Align::Center), |ui| {
315//! ui.button("I am becoming wider as needed");
316//! });
317//! # });
318//! ```
319//!
320//! 4. Fill in extra space with emptiness:
321//!
322//! ```
323//! # egui::__run_test_ui(|ui| {
324//! ui.allocate_space(ui.available_size()); // put this LAST in your panel/window code
325//! # });
326//! ```
327//!
328//! ## Sizes
329//! You can control the size of widgets using [`Ui::add_sized`].
330//!
331//! ```
332//! # egui::__run_test_ui(|ui| {
333//! # let mut my_value = 0.0_f32;
334//! ui.add_sized([40.0, 20.0], egui::DragValue::new(&mut my_value));
335//! # });
336//! ```
337//!
338//! ## Code snippets
339//!
340//! ```
341//! # use egui::TextWrapMode;
342//! # egui::__run_test_ui(|ui| {
343//! # let mut some_bool = true;
344//! // Miscellaneous tips and tricks
345//!
346//! ui.horizontal_wrapped(|ui| {
347//! ui.spacing_mut().item_spacing.x = 0.0; // remove spacing between widgets
348//! // `radio_value` also works for enums, integers, and more.
349//! ui.radio_value(&mut some_bool, false, "Off");
350//! ui.radio_value(&mut some_bool, true, "On");
351//! });
352//!
353//! ui.group(|ui| {
354//! ui.label("Within a frame");
355//! ui.set_min_height(200.0);
356//! });
357//!
358//! // A `scope` creates a temporary [`Ui`] in which you can change settings:
359//! ui.scope(|ui| {
360//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
361//! ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
362//! ui.style_mut().wrap_mode = Some(TextWrapMode::Truncate);
363//!
364//! ui.label("This text will be red, monospace, and won't wrap to a new line");
365//! }); // the temporary settings are reverted here
366//! # });
367//! ```
368//!
369//! ## Installing additional fonts
370//! The default egui fonts only support latin and cryllic characters, and some emojis.
371//! To use egui with e.g. asian characters you need to install your own font (`.ttf` or `.otf`) using [`Context::set_fonts`].
372
373#![allow(clippy::float_cmp)]
374#![allow(clippy::manual_range_contains)]
375
376mod animation_manager;
377pub mod containers;
378mod context;
379mod data;
380pub mod debug_text;
381mod drag_and_drop;
382mod frame_state;
383pub(crate) mod grid;
384pub mod gui_zoom;
385mod hit_test;
386mod id;
387mod input_state;
388mod interaction;
389pub mod introspection;
390pub mod layers;
391mod layout;
392pub mod load;
393mod memory;
394pub mod menu;
395pub mod os;
396mod painter;
397pub(crate) mod placer;
398mod response;
399mod sense;
400pub mod style;
401pub mod text_selection;
402mod ui;
403mod ui_stack;
404pub mod util;
405pub mod viewport;
406mod widget_rect;
407pub mod widget_text;
408pub mod widgets;
409
410#[cfg(feature = "callstack")]
411#[cfg(debug_assertions)]
412mod callstack;
413
414#[cfg(feature = "accesskit")]
415pub use accesskit;
416
417pub use ahash;
418
419pub use epaint;
420pub use epaint::ecolor;
421pub use epaint::emath;
422
423#[cfg(feature = "color-hex")]
424pub use ecolor::hex_color;
425pub use ecolor::{Color32, Rgba};
426pub use emath::{
427 lerp, pos2, remap, remap_clamp, vec2, Align, Align2, NumExt, Pos2, Rangef, Rect, Vec2, Vec2b,
428};
429pub use epaint::{
430 mutex,
431 text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
432 textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
433 ClippedPrimitive, ColorImage, FontImage, ImageData, Margin, Mesh, PaintCallback,
434 PaintCallbackInfo, Rounding, Shadow, Shape, Stroke, TextureHandle, TextureId,
435};
436
437pub mod text {
438 pub use crate::text_selection::{CCursorRange, CursorRange};
439 pub use epaint::text::{
440 cursor::CCursor, FontData, FontDefinitions, FontFamily, Fonts, Galley, LayoutJob,
441 LayoutSection, TextFormat, TextWrapping, TAB_SIZE,
442 };
443}
444
445pub use {
446 containers::*,
447 context::{Context, RepaintCause, RequestRepaintInfo},
448 data::{
449 input::*,
450 output::{
451 self, CursorIcon, FullOutput, OpenUrl, PlatformOutput, UserAttentionType, WidgetInfo,
452 },
453 Key,
454 },
455 drag_and_drop::DragAndDrop,
456 epaint::text::TextWrapMode,
457 grid::Grid,
458 id::{Id, IdMap},
459 input_state::{InputState, MultiTouchInfo, PointerState},
460 layers::{LayerId, Order},
461 layout::*,
462 load::SizeHint,
463 memory::{Memory, Options},
464 painter::Painter,
465 response::{InnerResponse, Response},
466 sense::Sense,
467 style::{FontSelection, Style, TextStyle, Visuals},
468 text::{Galley, TextFormat},
469 ui::Ui,
470 ui_stack::*,
471 viewport::*,
472 widget_rect::{WidgetRect, WidgetRects},
473 widget_text::{RichText, WidgetText},
474 widgets::*,
475};
476
477// ----------------------------------------------------------------------------
478
479/// Helper function that adds a label when compiling with debug assertions enabled.
480pub fn warn_if_debug_build(ui: &mut crate::Ui) {
481 if cfg!(debug_assertions) {
482 ui.label(
483 RichText::new("⚠ Debug build ⚠")
484 .small()
485 .color(ui.visuals().warn_fg_color),
486 )
487 .on_hover_text("egui was compiled with debug assertions enabled.");
488 }
489}
490
491// ----------------------------------------------------------------------------
492
493/// Include an image in the binary.
494///
495/// This is a wrapper over `include_bytes!`, and behaves in the same way.
496///
497/// It produces an [`ImageSource`] which can be used directly in [`Ui::image`] or [`Image::new`]:
498///
499/// ```
500/// # egui::__run_test_ui(|ui| {
501/// ui.image(egui::include_image!("../assets/ferris.png"));
502/// ui.add(
503/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
504/// .max_width(200.0)
505/// .rounding(10.0),
506/// );
507///
508/// let image_source: egui::ImageSource = egui::include_image!("../assets/ferris.png");
509/// assert_eq!(image_source.uri(), Some("bytes://../assets/ferris.png"));
510/// # });
511/// ```
512#[macro_export]
513macro_rules! include_image {
514 ($path:expr $(,)?) => {
515 $crate::ImageSource::Bytes {
516 uri: ::std::borrow::Cow::Borrowed(concat!("bytes://", $path)),
517 bytes: $crate::load::Bytes::Static(include_bytes!($path)),
518 }
519 };
520}
521
522/// Create a [`Hyperlink`] to the current [`file!()`] (and line) on Github
523///
524/// ```
525/// # egui::__run_test_ui(|ui| {
526/// ui.add(egui::github_link_file_line!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));
527/// # });
528/// ```
529#[macro_export]
530macro_rules! github_link_file_line {
531 ($github_url: expr, $label: expr) => {{
532 let url = format!("{}{}#L{}", $github_url, file!(), line!());
533 $crate::Hyperlink::from_label_and_url($label, url)
534 }};
535}
536
537/// Create a [`Hyperlink`] to the current [`file!()`] on github.
538///
539/// ```
540/// # egui::__run_test_ui(|ui| {
541/// ui.add(egui::github_link_file!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));
542/// # });
543/// ```
544#[macro_export]
545macro_rules! github_link_file {
546 ($github_url: expr, $label: expr) => {{
547 let url = format!("{}{}", $github_url, file!());
548 $crate::Hyperlink::from_label_and_url($label, url)
549 }};
550}
551
552// ----------------------------------------------------------------------------
553
554/// The minus character: <https://www.compart.com/en/unicode/U+2212>
555pub(crate) const MINUS_CHAR_STR: &str = "−";
556
557/// The default egui fonts supports around 1216 emojis in total.
558/// Here are some of the most useful:
559/// ∞⊗⎗⎘⎙⏏⏴⏵⏶⏷
560/// ⏩⏪⏭⏮⏸⏹⏺■▶📾🔀🔁🔃
561/// ☀☁★☆☐☑☜☝☞☟⛃⛶✔
562/// ↺↻⟲⟳⬅➡⬆⬇⬈⬉⬊⬋⬌⬍⮨⮩⮪⮫
563/// ♡
564/// 📅📆
565/// 📈📉📊
566/// 📋📌📎📤📥🔆
567/// 🔈🔉🔊🔍🔎🔗🔘
568/// 🕓🖧🖩🖮🖱🖴🖵🖼🗀🗁🗋🗐🗑🗙🚫❓
569///
570/// NOTE: In egui all emojis are monochrome!
571///
572/// You can explore them all in the Font Book in [the online demo](https://www.egui.rs/#demo).
573///
574/// In addition, egui supports a few special emojis that are not part of the unicode standard.
575/// This module contains some of them:
576pub mod special_emojis {
577 /// Tux, the Linux penguin.
578 pub const OS_LINUX: char = '🐧';
579
580 /// The Windows logo.
581 pub const OS_WINDOWS: char = '';
582
583 /// The Android logo.
584 pub const OS_ANDROID: char = '';
585
586 /// The Apple logo.
587 pub const OS_APPLE: char = '';
588
589 /// The Github logo.
590 pub const GITHUB: char = '';
591
592 /// The Twitter bird.
593 pub const TWITTER: char = '';
594
595 /// The word `git`.
596 pub const GIT: char = '';
597
598 // I really would like to have ferris here.
599}
600
601/// The different types of built-in widgets in egui
602#[derive(Clone, Copy, Debug, PartialEq, Eq)]
603#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
604pub enum WidgetType {
605 Label, // TODO(emilk): emit Label events
606
607 /// e.g. a hyperlink
608 Link,
609
610 TextEdit,
611
612 Button,
613
614 Checkbox,
615
616 RadioButton,
617
618 SelectableLabel,
619
620 ComboBox,
621
622 Slider,
623
624 DragValue,
625
626 ColorButton,
627
628 ImageButton,
629
630 CollapsingHeader,
631
632 ProgressIndicator,
633
634 /// If you cannot fit any of the above slots.
635 ///
636 /// If this is something you think should be added, file an issue.
637 Other,
638}
639
640// ----------------------------------------------------------------------------
641
642/// For use in tests; especially doctests.
643pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
644 let ctx = Context::default();
645 ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
646 let _ = ctx.run(Default::default(), |ctx| {
647 run_ui(ctx);
648 });
649}
650
651/// For use in tests; especially doctests.
652pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
653 let ctx = Context::default();
654 ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
655 let _ = ctx.run(Default::default(), |ctx| {
656 crate::CentralPanel::default().show(ctx, |ui| {
657 add_contents(ui);
658 });
659 });
660}
661
662#[cfg(feature = "accesskit")]
663pub fn accesskit_root_id() -> Id {
664 Id::new("accesskit_root")
665}
666
667// ---------------------------------------------------------------------------
668
669mod profiling_scopes {
670 #![allow(unused_macros)]
671 #![allow(unused_imports)]
672
673 /// Profiling macro for feature "puffin"
674 macro_rules! profile_function {
675 ($($arg: tt)*) => {
676 #[cfg(feature = "puffin")]
677 #[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
678 puffin::profile_function!($($arg)*);
679 };
680 }
681 pub(crate) use profile_function;
682
683 /// Profiling macro for feature "puffin"
684 macro_rules! profile_scope {
685 ($($arg: tt)*) => {
686 #[cfg(feature = "puffin")]
687 #[cfg(not(target_arch = "wasm32"))] // Disabled on web because of the coarse 1ms clock resolution there.
688 puffin::profile_scope!($($arg)*);
689 };
690 }
691 pub(crate) use profile_scope;
692}
693
694#[allow(unused_imports)]
695pub(crate) use profiling_scopes::*;