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.81.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//! ## Multi-pass immediate mode
227//! By default, egui usually only does one pass for each rendered frame.
228//! However, egui supports multi-pass immediate mode.
229//! Another pass can be requested with [`Context::request_discard`].
230//!
231//! This is used by some widgets to cover up "first-frame jitters".
232//! For instance, the [`Grid`] needs to know the width of all columns before it can properly place the widgets.
233//! But it cannot know the width of widgets to come.
234//! So it stores the max widths of previous frames and uses that.
235//! This means the first time a `Grid` is shown it will _guess_ the widths of the columns, and will usually guess wrong.
236//! This means the contents of the grid will be wrong for one frame, before settling to the correct places.
237//! Therefore `Grid` calls [`Context::request_discard`] when it is first shown, so the wrong placement is never
238//! visible to the end user.
239//!
240//! This is an example of a form of multi-pass immediate mode, where earlier passes are used for sizing,
241//! and later passes for layout.
242//!
243//! See [`Context::request_discard`] and [`Options::max_passes`] for more.
244//!
245//! # Misc
246//!
247//! ## How widgets works
248//!
249//! ```
250//! # egui::__run_test_ui(|ui| {
251//! if ui.button("click me").clicked() { take_action() }
252//! # });
253//! # fn take_action() {}
254//! ```
255//!
256//! is short for
257//!
258//! ```
259//! # egui::__run_test_ui(|ui| {
260//! let button = egui::Button::new("click me");
261//! if ui.add(button).clicked() { take_action() }
262//! # });
263//! # fn take_action() {}
264//! ```
265//!
266//! which is short for
267//!
268//! ```
269//! # use egui::Widget;
270//! # egui::__run_test_ui(|ui| {
271//! let button = egui::Button::new("click me");
272//! let response = button.ui(ui);
273//! if response.clicked() { take_action() }
274//! # });
275//! # fn take_action() {}
276//! ```
277//!
278//! [`Button`] uses the builder pattern to create the data required to show it. The [`Button`] is then discarded.
279//!
280//! [`Button`] implements `trait` [`Widget`], which looks like this:
281//! ```
282//! # use egui::*;
283//! pub trait Widget {
284//! /// Allocate space, interact, paint, and return a [`Response`].
285//! fn ui(self, ui: &mut Ui) -> Response;
286//! }
287//! ```
288//!
289//!
290//! ## Widget interaction
291//! Each widget has a [`Sense`], which defines whether or not the widget
292//! is sensitive to clicking and/or drags.
293//!
294//! For instance, a [`Button`] only has a [`Sense::click`] (by default).
295//! This means if you drag a button it will not respond with [`Response::dragged`].
296//! Instead, the drag will continue through the button to the first
297//! widget behind it that is sensitive to dragging, which for instance could be
298//! a [`ScrollArea`]. This lets you scroll by dragging a scroll area (important
299//! on touch screens), just as long as you don't drag on a widget that is sensitive
300//! to drags (e.g. a [`Slider`]).
301//!
302//! When widgets overlap it is the last added one
303//! that is considered to be on top and which will get input priority.
304//!
305//! The widget interaction logic is run at the _start_ of each frame,
306//! based on the output from the previous frame.
307//! This means that when a new widget shows up you cannot click it in the same
308//! frame (i.e. in the same fraction of a second), but unless the user
309//! is spider-man, they wouldn't be fast enough to do so anyways.
310//!
311//! By running the interaction code early, egui can actually
312//! tell you if a widget is being interacted with _before_ you add it,
313//! as long as you know its [`Id`] before-hand (e.g. using [`Ui::next_auto_id`]),
314//! by calling [`Context::read_response`].
315//! This can be useful in some circumstances in order to style a widget,
316//! or to respond to interactions before adding the widget
317//! (perhaps on top of other widgets).
318//!
319//!
320//! ## Auto-sizing panels and windows
321//! In egui, all panels and windows auto-shrink to fit the content.
322//! If the window or panel is also resizable, this can lead to a weird behavior
323//! where you can drag the edge of the panel/window to make it larger, and
324//! when you release the panel/window shrinks again.
325//! This is an artifact of immediate mode, and here are some alternatives on how to avoid it:
326//!
327//! 1. Turn off resizing with [`Window::resizable`], [`SidePanel::resizable`], [`TopBottomPanel::resizable`].
328//! 2. Wrap your panel contents in a [`ScrollArea`], or use [`Window::vscroll`] and [`Window::hscroll`].
329//! 3. Use a justified layout:
330//!
331//! ```
332//! # egui::__run_test_ui(|ui| {
333//! ui.with_layout(egui::Layout::top_down_justified(egui::Align::Center), |ui| {
334//! ui.button("I am becoming wider as needed");
335//! });
336//! # });
337//! ```
338//!
339//! 4. Fill in extra space with emptiness:
340//!
341//! ```
342//! # egui::__run_test_ui(|ui| {
343//! ui.allocate_space(ui.available_size()); // put this LAST in your panel/window code
344//! # });
345//! ```
346//!
347//! ## Sizes
348//! You can control the size of widgets using [`Ui::add_sized`].
349//!
350//! ```
351//! # egui::__run_test_ui(|ui| {
352//! # let mut my_value = 0.0_f32;
353//! ui.add_sized([40.0, 20.0], egui::DragValue::new(&mut my_value));
354//! # });
355//! ```
356//!
357//! ## Code snippets
358//!
359//! ```
360//! # use egui::TextWrapMode;
361//! # egui::__run_test_ui(|ui| {
362//! # let mut some_bool = true;
363//! // Miscellaneous tips and tricks
364//!
365//! ui.horizontal_wrapped(|ui| {
366//! ui.spacing_mut().item_spacing.x = 0.0; // remove spacing between widgets
367//! // `radio_value` also works for enums, integers, and more.
368//! ui.radio_value(&mut some_bool, false, "Off");
369//! ui.radio_value(&mut some_bool, true, "On");
370//! });
371//!
372//! ui.group(|ui| {
373//! ui.label("Within a frame");
374//! ui.set_min_height(200.0);
375//! });
376//!
377//! // A `scope` creates a temporary [`Ui`] in which you can change settings:
378//! ui.scope(|ui| {
379//! ui.visuals_mut().override_text_color = Some(egui::Color32::RED);
380//! ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
381//! ui.style_mut().wrap_mode = Some(TextWrapMode::Truncate);
382//!
383//! ui.label("This text will be red, monospace, and won't wrap to a new line");
384//! }); // the temporary settings are reverted here
385//! # });
386//! ```
387//!
388//! ## Installing additional fonts
389//! The default egui fonts only support latin and cryllic characters, and some emojis.
390//! To use egui with e.g. asian characters you need to install your own font (`.ttf` or `.otf`) using [`Context::set_fonts`].
391//!
392//! ## Instrumentation
393//! This crate supports using the [profiling](https://crates.io/crates/profiling) crate for instrumentation.
394//! You can enable features on the profiling crates in your application to add instrumentation for all
395//! crates that support it, including egui. See the profiling crate docs for more information.
396//! ```toml
397//! [dependencies]
398//! profiling = "1.0"
399//! [features]
400//! profile-with-puffin = ["profiling/profile-with-puffin"]
401//! ```
402//!
403
404#![allow(clippy::float_cmp)]
405#![allow(clippy::manual_range_contains)]
406
407mod animation_manager;
408pub mod cache;
409pub mod containers;
410mod context;
411mod data;
412pub mod debug_text;
413mod drag_and_drop;
414pub(crate) mod grid;
415pub mod gui_zoom;
416mod hit_test;
417mod id;
418mod input_state;
419mod interaction;
420pub mod introspection;
421pub mod layers;
422mod layout;
423pub mod load;
424mod memory;
425pub mod menu;
426pub mod os;
427mod painter;
428mod pass_state;
429pub(crate) mod placer;
430pub mod response;
431mod sense;
432pub mod style;
433pub mod text_selection;
434mod ui;
435mod ui_builder;
436mod ui_stack;
437pub mod util;
438pub mod viewport;
439mod widget_rect;
440pub mod widget_text;
441pub mod widgets;
442
443#[cfg(feature = "callstack")]
444#[cfg(debug_assertions)]
445mod callstack;
446
447#[cfg(feature = "accesskit")]
448pub use accesskit;
449
450#[deprecated = "Use the ahash crate directly."]
451pub use ahash;
452
453pub use epaint;
454pub use epaint::ecolor;
455pub use epaint::emath;
456
457#[cfg(feature = "color-hex")]
458pub use ecolor::hex_color;
459pub use ecolor::{Color32, Rgba};
460pub use emath::{
461 lerp, pos2, remap, remap_clamp, vec2, Align, Align2, NumExt, Pos2, Rangef, Rect, Vec2, Vec2b,
462};
463pub use epaint::{
464 mutex,
465 text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
466 textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
467 ClippedPrimitive, ColorImage, CornerRadius, FontImage, ImageData, Margin, Mesh, PaintCallback,
468 PaintCallbackInfo, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,
469};
470
471pub mod text {
472 pub use crate::text_selection::{CCursorRange, CursorRange};
473 pub use epaint::text::{
474 cursor::CCursor, FontData, FontDefinitions, FontFamily, Fonts, Galley, LayoutJob,
475 LayoutSection, TextFormat, TextWrapping, TAB_SIZE,
476 };
477}
478
479pub use self::{
480 containers::*,
481 context::{Context, RepaintCause, RequestRepaintInfo},
482 data::{
483 input::*,
484 output::{
485 self, CursorIcon, FullOutput, OpenUrl, OutputCommand, PlatformOutput,
486 UserAttentionType, WidgetInfo,
487 },
488 Key, UserData,
489 },
490 drag_and_drop::DragAndDrop,
491 epaint::text::TextWrapMode,
492 grid::Grid,
493 id::{Id, IdMap},
494 input_state::{InputState, MultiTouchInfo, PointerState},
495 layers::{LayerId, Order},
496 layout::*,
497 load::SizeHint,
498 memory::{Memory, Options, Theme, ThemePreference},
499 painter::Painter,
500 response::{InnerResponse, Response},
501 sense::Sense,
502 style::{FontSelection, Spacing, Style, TextStyle, Visuals},
503 text::{Galley, TextFormat},
504 ui::Ui,
505 ui_builder::UiBuilder,
506 ui_stack::*,
507 viewport::*,
508 widget_rect::{WidgetRect, WidgetRects},
509 widget_text::{RichText, WidgetText},
510 widgets::*,
511};
512
513#[deprecated = "Renamed to CornerRadius"]
514pub type Rounding = CornerRadius;
515
516// ----------------------------------------------------------------------------
517
518/// Helper function that adds a label when compiling with debug assertions enabled.
519pub fn warn_if_debug_build(ui: &mut crate::Ui) {
520 if cfg!(debug_assertions) {
521 ui.label(
522 RichText::new("⚠ Debug build ⚠")
523 .small()
524 .color(ui.visuals().warn_fg_color),
525 )
526 .on_hover_text("egui was compiled with debug assertions enabled.");
527 }
528}
529
530// ----------------------------------------------------------------------------
531
532/// Include an image in the binary.
533///
534/// This is a wrapper over `include_bytes!`, and behaves in the same way.
535///
536/// It produces an [`ImageSource`] which can be used directly in [`Ui::image`] or [`Image::new`]:
537///
538/// ```
539/// # egui::__run_test_ui(|ui| {
540/// ui.image(egui::include_image!("../assets/ferris.png"));
541/// ui.add(
542/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
543/// .max_width(200.0)
544/// .corner_radius(10),
545/// );
546///
547/// let image_source: egui::ImageSource = egui::include_image!("../assets/ferris.png");
548/// assert_eq!(image_source.uri(), Some("bytes://../assets/ferris.png"));
549/// # });
550/// ```
551#[macro_export]
552macro_rules! include_image {
553 ($path:expr $(,)?) => {
554 $crate::ImageSource::Bytes {
555 uri: ::std::borrow::Cow::Borrowed(concat!("bytes://", $path)),
556 bytes: $crate::load::Bytes::Static(include_bytes!($path)),
557 }
558 };
559}
560
561/// Create a [`Hyperlink`] to the current [`file!()`] (and line) on Github
562///
563/// ```
564/// # egui::__run_test_ui(|ui| {
565/// ui.add(egui::github_link_file_line!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));
566/// # });
567/// ```
568#[macro_export]
569macro_rules! github_link_file_line {
570 ($github_url: expr, $label: expr) => {{
571 let url = format!("{}{}#L{}", $github_url, file!(), line!());
572 $crate::Hyperlink::from_label_and_url($label, url)
573 }};
574}
575
576/// Create a [`Hyperlink`] to the current [`file!()`] on github.
577///
578/// ```
579/// # egui::__run_test_ui(|ui| {
580/// ui.add(egui::github_link_file!("https://github.com/YOUR/PROJECT/blob/master/", "(source code)"));
581/// # });
582/// ```
583#[macro_export]
584macro_rules! github_link_file {
585 ($github_url: expr, $label: expr) => {{
586 let url = format!("{}{}", $github_url, file!());
587 $crate::Hyperlink::from_label_and_url($label, url)
588 }};
589}
590
591// ----------------------------------------------------------------------------
592
593/// The minus character: <https://www.compart.com/en/unicode/U+2212>
594pub(crate) const MINUS_CHAR_STR: &str = "−";
595
596/// The default egui fonts supports around 1216 emojis in total.
597/// Here are some of the most useful:
598/// ∞⊗⎗⎘⎙⏏⏴⏵⏶⏷
599/// ⏩⏪⏭⏮⏸⏹⏺■▶📾🔀🔁🔃
600/// ☀☁★☆☐☑☜☝☞☟⛃⛶✔
601/// ↺↻⟲⟳⬅➡⬆⬇⬈⬉⬊⬋⬌⬍⮨⮩⮪⮫
602/// ♡
603/// 📅📆
604/// 📈📉📊
605/// 📋📌📎📤📥🔆
606/// 🔈🔉🔊🔍🔎🔗🔘
607/// 🕓🖧🖩🖮🖱🖴🖵🖼🗀🗁🗋🗐🗑🗙🚫❓
608///
609/// NOTE: In egui all emojis are monochrome!
610///
611/// You can explore them all in the Font Book in [the online demo](https://www.egui.rs/#demo).
612///
613/// In addition, egui supports a few special emojis that are not part of the unicode standard.
614/// This module contains some of them:
615pub mod special_emojis {
616 /// Tux, the Linux penguin.
617 pub const OS_LINUX: char = '🐧';
618
619 /// The Windows logo.
620 pub const OS_WINDOWS: char = '';
621
622 /// The Android logo.
623 pub const OS_ANDROID: char = '';
624
625 /// The Apple logo.
626 pub const OS_APPLE: char = '';
627
628 /// The Github logo.
629 pub const GITHUB: char = '';
630
631 /// The word `git`.
632 pub const GIT: char = '';
633
634 // I really would like to have ferris here.
635}
636
637/// The different types of built-in widgets in egui
638#[derive(Clone, Copy, Debug, PartialEq, Eq)]
639#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
640pub enum WidgetType {
641 Label, // TODO(emilk): emit Label events
642
643 /// e.g. a hyperlink
644 Link,
645
646 TextEdit,
647
648 Button,
649
650 Checkbox,
651
652 RadioButton,
653
654 /// A group of radio buttons.
655 RadioGroup,
656
657 SelectableLabel,
658
659 ComboBox,
660
661 Slider,
662
663 DragValue,
664
665 ColorButton,
666
667 ImageButton,
668
669 Image,
670
671 CollapsingHeader,
672
673 ProgressIndicator,
674
675 Window,
676
677 /// If you cannot fit any of the above slots.
678 ///
679 /// If this is something you think should be added, file an issue.
680 Other,
681}
682
683// ----------------------------------------------------------------------------
684
685/// For use in tests; especially doctests.
686pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
687 let ctx = Context::default();
688 ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
689 let _ = ctx.run(Default::default(), |ctx| {
690 run_ui(ctx);
691 });
692}
693
694/// For use in tests; especially doctests.
695pub fn __run_test_ui(add_contents: impl Fn(&mut Ui)) {
696 let ctx = Context::default();
697 ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
698 let _ = ctx.run(Default::default(), |ctx| {
699 crate::CentralPanel::default().show(ctx, |ui| {
700 add_contents(ui);
701 });
702 });
703}
704
705#[cfg(feature = "accesskit")]
706pub fn accesskit_root_id() -> Id {
707 Id::new("accesskit_root")
708}