Skip to main content

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.92.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 [`Panel`] 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//! ### Quick start
47//!
48//! ```
49//! # egui::__run_test_ui(|ui| {
50//! # let mut my_string = String::new();
51//! # let mut my_boolean = true;
52//! # let mut my_f32 = 42.0;
53//! ui.label("This is a label");
54//! ui.hyperlink("https://github.com/emilk/egui");
55//! ui.text_edit_singleline(&mut my_string);
56//! if ui.button("Click me").clicked() { }
57//! ui.add(egui::Slider::new(&mut my_f32, 0.0..=100.0));
58//! ui.add(egui::DragValue::new(&mut my_f32));
59//!
60//! ui.checkbox(&mut my_boolean, "Checkbox");
61//!
62//! #[derive(PartialEq)]
63//! enum Enum { First, Second, Third }
64//! # let mut my_enum = Enum::First;
65//! ui.horizontal(|ui| {
66//!     ui.radio_value(&mut my_enum, Enum::First, "First");
67//!     ui.radio_value(&mut my_enum, Enum::Second, "Second");
68//!     ui.radio_value(&mut my_enum, Enum::Third, "Third");
69//! });
70//!
71//! ui.separator();
72//!
73//! # let my_image = egui::TextureId::default();
74//! ui.image((my_image, egui::Vec2::new(640.0, 480.0)));
75//!
76//! ui.collapsing("Click to see what is hidden!", |ui| {
77//!     ui.label("Not much, as it turns out");
78//! });
79//! # });
80//! ```
81//!
82//! ## Viewports
83//! Some egui backends support multiple _viewports_, which is what egui calls the native OS windows it resides in.
84//! See [`crate::viewport`] for more information.
85//!
86//! ## Coordinate system
87//! The left-top corner of the screen is `(0.0, 0.0)`,
88//! with X increasing to the right and Y increasing downwards.
89//!
90//! `egui` uses logical _points_ as its coordinate system.
91//! Those related to physical _pixels_ by the `pixels_per_point` scale factor.
92//! For example, a high-dpi screen can have `pixels_per_point = 2.0`,
93//! meaning there are two physical screen pixels for each logical point.
94//!
95//! Angles are in radians, and are measured clockwise from the X-axis, which has angle=0.
96//!
97//! # Integrating with egui
98//!
99//! Most likely you are using an existing `egui` backend/integration such as [`eframe`](https://docs.rs/eframe), [`bevy_egui`](https://docs.rs/bevy_egui),
100//! or [`egui-miniquad`](https://github.com/not-fl3/egui-miniquad),
101//! but if you want to integrate `egui` into a new game engine or graphics backend, this is the section for you.
102//!
103//! You need to collect [`RawInput`] and handle [`FullOutput`]. The basic structure is this:
104//!
105//! ``` no_run
106//! # fn handle_platform_output(_: egui::PlatformOutput) {}
107//! # fn gather_input() -> egui::RawInput { egui::RawInput::default() }
108//! # fn paint(textures_delta: egui::TexturesDelta, _: Vec<egui::ClippedPrimitive>) {}
109//! let mut ctx = egui::Context::default();
110//!
111//! // Game loop:
112//! loop {
113//!     let raw_input: egui::RawInput = gather_input();
114//!
115//!     let full_output = ctx.run_ui(raw_input, |ui| {
116//!         egui::CentralPanel::default().show(ui, |ui| {
117//!             ui.label("Hello world!");
118//!             if ui.button("Click me").clicked() {
119//!                 // take some action here
120//!             }
121//!         });
122//!     });
123//!     handle_platform_output(full_output.platform_output);
124//!     let clipped_primitives = ctx.tessellate(full_output.shapes, full_output.pixels_per_point);
125//!     paint(full_output.textures_delta, clipped_primitives);
126//! }
127//! ```
128//!
129//! For a reference OpenGL renderer, see [the `egui_glow` painter](https://github.com/emilk/egui/blob/main/crates/egui_glow/src/painter.rs).
130//!
131//!
132//! ### Debugging your renderer
133//!
134//! #### Things look jagged
135//!
136//! * Turn off backface culling.
137//!
138//! #### My text is blurry
139//!
140//! * Make sure you set the proper `pixels_per_point` in the input to egui.
141//! * Make sure the texture sampler is not off by half a pixel. Try nearest-neighbor sampler to check.
142//!
143//! #### My windows are too transparent or too dark
144//!
145//! * egui uses premultiplied alpha, so make sure your blending function is `(ONE, ONE_MINUS_SRC_ALPHA)`.
146//! * Make sure your texture sampler is clamped (`GL_CLAMP_TO_EDGE`).
147//! * egui prefers gamma color spaces for all blending so:
148//!   * Do NOT use an sRGBA-aware texture (NOT `GL_SRGB8_ALPHA8`).
149//!   * Multiply texture and vertex colors in gamma space
150//!   * Turn OFF sRGBA/gamma framebuffer (NO `GL_FRAMEBUFFER_SRGB`).
151//!
152//!
153//! # Understanding immediate mode
154//!
155//! `egui` is an immediate mode GUI library.
156//!
157//! Immediate mode has its roots in gaming, where everything on the screen is painted at the
158//! display refresh rate, i.e. at 60+ frames per second.
159//! In immediate mode GUIs, the entire interface is laid out and painted at the same high rate.
160//! This makes immediate mode GUIs especially well suited for highly interactive applications.
161//!
162//! It is useful to fully grok what "immediate mode" implies.
163//!
164//! Here is an example to illustrate it:
165//!
166//! ```
167//! # egui::__run_test_ui(|ui| {
168//! if ui.button("click me").clicked() {
169//!     take_action()
170//! }
171//! # });
172//! # fn take_action() {}
173//! ```
174//!
175//! This code is being executed each frame at maybe 60 frames per second.
176//! Each frame egui does these things:
177//!
178//! * lays out the letters `click me` in order to figure out the size of the button
179//! * decides where on screen to place the button
180//! * check if the mouse is hovering or clicking that location
181//! * choose button colors based on if it is being hovered or clicked
182//! * add a [`Shape::Rect`] and [`Shape::Text`] to the list of shapes to be painted later this frame
183//! * return a [`Response`] with the [`clicked`](`Response::clicked`) member so the user can check for interactions
184//!
185//! There is no button being created and stored somewhere.
186//! The only output of this call is some colored shapes, and a [`Response`].
187//!
188//! Similarly, consider this code:
189//!
190//! ```
191//! # egui::__run_test_ui(|ui| {
192//! # let mut value: f32 = 0.0;
193//! ui.add(egui::Slider::new(&mut value, 0.0..=100.0).text("My value"));
194//! # });
195//! ```
196//!
197//! 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`.
198//! Note that `egui` does not store the slider value for you - it only displays the current value, and changes it
199//! by how much the slider has been dragged in the previous few milliseconds.
200//! This means it is responsibility of the egui user to store the state (`value`) so that it persists between frames.
201//!
202//! It can be useful to read the code for the toggle switch example widget to get a better understanding
203//! of how egui works: <https://github.com/emilk/egui/blob/main/crates/egui_demo_lib/src/demo/toggle_switch.rs>.
204//!
205//! Read more about the pros and cons of immediate mode at <https://github.com/emilk/egui#why-immediate-mode>.
206//!
207//! ## Multi-pass immediate mode
208//! By default, egui usually only does one pass for each rendered frame.
209//! However, egui supports multi-pass immediate mode.
210//! Another pass can be requested with [`Context::request_discard`].
211//!
212//! This is used by some widgets to cover up "first-frame jitters".
213//! For instance, the [`Grid`] needs to know the width of all columns before it can properly place the widgets.
214//! But it cannot know the width of widgets to come.
215//! So it stores the max widths of previous frames and uses that.
216//! This means the first time a `Grid` is shown it will _guess_ the widths of the columns, and will usually guess wrong.
217//! This means the contents of the grid will be wrong for one frame, before settling to the correct places.
218//! Therefore `Grid` calls [`Context::request_discard`] when it is first shown, so the wrong placement is never
219//! visible to the end user.
220//!
221//! This is an example of a form of multi-pass immediate mode, where earlier passes are used for sizing,
222//! and later passes for layout.
223//!
224//! See [`Context::request_discard`] and [`Options::max_passes`] for more.
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 clicking 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`], [`Panel::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//! ## Instrumentation
374//! This crate supports using the [profiling](https://crates.io/crates/profiling) crate for instrumentation.
375//! You can enable features on the profiling crates in your application to add instrumentation for all
376//! crates that support it, including egui. See the profiling crate docs for more information.
377//! ```toml
378//! [dependencies]
379//! profiling = "1.0"
380//! [features]
381//! profile-with-puffin = ["profiling/profile-with-puffin"]
382//! ```
383//!
384//! ## Custom allocator
385//! egui apps can run significantly (~20%) faster by using a custom allocator, like [mimalloc](https://crates.io/crates/mimalloc) or [talc](https://crates.io/crates/talc).
386//!
387
388#![expect(clippy::float_cmp)]
389#![expect(clippy::manual_range_contains)]
390
391mod animation_manager;
392mod atomics;
393pub mod cache;
394pub mod containers;
395mod context;
396mod data;
397pub mod debug_text;
398mod drag_and_drop;
399pub(crate) mod grid;
400pub mod gui_zoom;
401mod hit_test;
402mod id;
403mod id_salt;
404mod input_state;
405mod interaction;
406pub mod introspection;
407pub mod layers;
408mod layout;
409pub mod load;
410mod memory;
411pub mod os;
412mod painter;
413mod pass_state;
414pub(crate) mod placer;
415pub mod plugin;
416pub mod response;
417mod sense;
418pub mod style;
419pub mod text_selection;
420mod ui;
421mod ui_builder;
422mod ui_stack;
423pub mod util;
424pub mod viewport;
425mod widget_rect;
426pub mod widget_style;
427pub mod widget_text;
428pub mod widgets;
429
430#[cfg(feature = "callstack")]
431#[cfg(debug_assertions)]
432mod callstack;
433
434pub use accesskit;
435
436pub use epaint;
437pub use epaint::ecolor;
438pub use epaint::emath;
439
440#[cfg(feature = "color-hex")]
441pub use ecolor::hex_color;
442pub use ecolor::{Color32, Rgba};
443pub use emath::{
444    Align, Align2, NumExt, Pos2, Rangef, Rect, RectAlign, Vec2, Vec2b, lerp, pos2, remap,
445    remap_clamp, vec2,
446};
447pub use epaint::{
448    ClippedPrimitive, ColorImage, CornerRadius, Direction, ImageData, Margin, Mesh, PaintCallback,
449    PaintCallbackInfo, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId, mutex,
450    text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
451    textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
452};
453
454pub mod text {
455    pub use crate::text_selection::CCursorRange;
456    pub use epaint::text::{
457        ByteIndex, ByteRange, CharIndex, CharRange, FontData, FontDefinitions, FontFamily, Fonts,
458        Galley, LayoutJob, LayoutSection, TextFormat, TextWrapping, cursor::CCursor,
459    };
460}
461
462pub use self::{
463    atomics::*,
464    containers::{menu::MenuBar, *},
465    context::{Context, RepaintCause, RequestRepaintInfo},
466    data::{
467        Key, UserData,
468        input::*,
469        output::{
470            self, CursorIcon, CustomCursorImage, FullOutput, OpenUrl, OutputCommand,
471            PlatformOutput, UserAttentionType, WidgetInfo,
472        },
473    },
474    drag_and_drop::DragAndDrop,
475    epaint::text::TextWrapMode,
476    grid::Grid,
477    id::{AsId, Id, IdMap, IdSet},
478    id_salt::{AsIdSalt, IdSalt},
479    input_state::{InputOptions, InputState, MultiTouchInfo, PointerState, SurrenderFocusOn},
480    layers::{LayerId, Order},
481    layout::*,
482    load::SizeHint,
483    memory::{FocusDirection, Memory, Options, Theme, ThemePreference},
484    painter::Painter,
485    plugin::Plugin,
486    response::{InnerResponse, Response},
487    sense::Sense,
488    style::{FontSelection, Spacing, Style, TextStyle, Visuals},
489    text::{Galley, TextFormat},
490    ui::Ui,
491    ui_builder::{IdSource, UiBuilder},
492    ui_stack::*,
493    viewport::*,
494    widget_rect::{InteractOptions, WidgetRect, WidgetRects},
495    widget_text::{RichText, WidgetText},
496    widgets::*,
497};
498
499// ----------------------------------------------------------------------------
500
501/// Helper function that adds a label when compiling with debug assertions enabled.
502pub fn warn_if_debug_build(ui: &mut crate::Ui) {
503    if cfg!(debug_assertions) {
504        ui.label(
505            RichText::new("⚠ Debug build ⚠")
506                .small()
507                .color(ui.visuals().warn_fg_color),
508        )
509        .on_hover_text("egui was compiled with debug assertions enabled.");
510    }
511}
512
513// ----------------------------------------------------------------------------
514
515/// Include an image in the binary.
516///
517/// This is a wrapper over `include_bytes!`, and behaves in the same way.
518///
519/// It produces an [`ImageSource`] which can be used directly in [`Ui::image`] or [`Image::new`]:
520///
521/// ```
522/// # egui::__run_test_ui(|ui| {
523/// ui.image(egui::include_image!("../assets/ferris.png"));
524/// ui.add(
525///     egui::Image::new(egui::include_image!("../assets/ferris.png"))
526///         .max_width(200.0)
527///         .corner_radius(10),
528/// );
529///
530/// let image_source: egui::ImageSource = egui::include_image!("../assets/ferris.png");
531/// assert_eq!(image_source.uri(), Some("bytes://../assets/ferris.png"));
532/// # });
533/// ```
534#[macro_export]
535macro_rules! include_image {
536    ($path:expr $(,)?) => {
537        $crate::ImageSource::Bytes {
538            uri: ::std::borrow::Cow::Borrowed(concat!("bytes://", $path)),
539            bytes: $crate::load::Bytes::Static(include_bytes!($path)),
540        }
541    };
542}
543
544/// Create a [`Hyperlink`] to the current [`file!()`] (and line) on Github
545///
546/// ```
547/// # egui::__run_test_ui(|ui| {
548/// ui.add(egui::github_link_file_line!("https://github.com/YOUR/PROJECT/blob/main/", "(source code)"));
549/// # });
550/// ```
551#[macro_export]
552macro_rules! github_link_file_line {
553    ($github_url: expr, $label: expr) => {{
554        let url = format!("{}{}#L{}", $github_url, file!(), line!());
555        $crate::Hyperlink::from_label_and_url($label, url)
556    }};
557}
558
559/// Create a [`Hyperlink`] to the current [`file!()`] on github.
560///
561/// ```
562/// # egui::__run_test_ui(|ui| {
563/// ui.add(egui::github_link_file!("https://github.com/YOUR/PROJECT/blob/main/", "(source code)"));
564/// # });
565/// ```
566#[macro_export]
567macro_rules! github_link_file {
568    ($github_url: expr, $label: expr) => {{
569        let url = format!("{}{}", $github_url, file!());
570        $crate::Hyperlink::from_label_and_url($label, url)
571    }};
572}
573
574// ----------------------------------------------------------------------------
575
576/// The minus character: <https://www.compart.com/en/unicode/U+2212>
577pub(crate) const MINUS_CHAR_STR: &str = "−";
578
579/// The default egui fonts supports around 1216 emojis in total.
580/// Here are some of the most useful:
581/// ∞⊗⎗⎘⎙⏏⏴⏵⏶⏷
582/// ⏩⏪⏭⏮⏸⏹⏺■▶📾🔀🔁🔃
583/// ☀☁★☆☐☑☜☝☞☟⛃⛶✔
584/// ↺↻⟲⟳⬅➡⬆⬇⬈⬉⬊⬋⬌⬍⮨⮩⮪⮫
585/// ♡
586/// 📅📆
587/// 📈📉📊
588/// 📋📌📎📤📥🔆
589/// 🔈🔉🔊🔍🔎🔗🔘
590/// 🕓🖧🖩🖮🖱🖴🖵🖼🗀🗁🗋🗐🗑🗙🚫❓
591///
592/// NOTE: In egui all emojis are monochrome!
593///
594/// You can explore them all in the Font Book in [the online demo](https://www.egui.rs/#demo).
595///
596/// In addition, egui supports a few special emojis that are not part of the unicode standard.
597/// This module contains some of them:
598pub mod special_emojis {
599    /// Tux, the Linux penguin.
600    pub const OS_LINUX: char = '🐧';
601
602    /// The Windows logo.
603    pub const OS_WINDOWS: char = '';
604
605    /// The Android logo.
606    pub const OS_ANDROID: char = '';
607
608    /// The Apple logo.
609    pub const OS_APPLE: char = '';
610
611    /// The Github logo.
612    pub const GITHUB: char = '';
613
614    /// The word `git`.
615    pub const GIT: char = '';
616
617    // I really would like to have ferris here.
618}
619
620/// The different types of built-in widgets in egui
621#[derive(Clone, Copy, Debug, PartialEq, Eq)]
622#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
623pub enum WidgetType {
624    Label, // TODO(emilk): emit Label events
625
626    /// e.g. a hyperlink
627    Link,
628
629    TextEdit,
630
631    Button,
632
633    Checkbox,
634
635    RadioButton,
636
637    /// A group of radio buttons.
638    RadioGroup,
639
640    SelectableLabel,
641
642    ComboBox,
643
644    Slider,
645
646    DragValue,
647
648    ColorButton,
649
650    Image,
651
652    CollapsingHeader,
653
654    Panel,
655
656    ProgressIndicator,
657
658    Window,
659
660    ResizeHandle,
661
662    ScrollBar,
663
664    /// If you cannot fit any of the above slots.
665    ///
666    /// If this is something you think should be added, file an issue.
667    Other,
668}
669
670// ----------------------------------------------------------------------------
671
672/// For use in tests; especially doctests.
673pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
674    let ctx = Context::default();
675    ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
676    let _ = ctx.run_ui(Default::default(), |ui| {
677        run_ui(ui.ctx());
678    });
679}
680
681/// For use in tests; especially doctests.
682pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
683    let ctx = Context::default();
684    ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
685    let _ = ctx.run_ui(Default::default(), |ui| {
686        add_contents(ui);
687    });
688}
689
690pub fn accesskit_root_id() -> Id {
691    Id::new("accesskit_root")
692}