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