MCPcopy Index your code
hub / github.com/emilk/egui

github.com/emilk/egui @0.35.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.35.0 ↗ · + Follow
5,433 symbols 20,014 edges 372 files 1,463 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🖌 egui: an easy-to-use GUI in pure Rust

github Latest version Documentation unsafe forbidden Build Status MIT Apache Discord

👉 Click to run the web demo 👈

egui (pronounced "e-gooey") is a simple, fast, and highly portable immediate mode GUI library for Rust. egui runs on the web, natively, and in your favorite game engine.

egui aims to be the easiest-to-use Rust GUI library, and the simplest way to make a web app in Rust.

egui can be used anywhere you can draw textured triangles, which means you can easily integrate it into your game engine of choice.

eframe is the official egui framework, which supports writing apps for Web, Linux, Mac, Windows, and Android.

Example

ui.heading("My egui Application");
ui.horizontal(|ui| {
    ui.label("Your name: ");
    ui.text_edit_singleline(&mut name);
});
ui.add(egui::Slider::new(&mut age, 0..=120).text("age"));
if ui.button("Increment").clicked() {
    age += 1;
}
ui.label(format!("Hello '{name}', age {age}"));
ui.image(egui::include_image!("ferris.png"));

Dark mode     Light mode

Sections:

(egui 的中文翻译文档 / chinese translation)

Quick start

There are simple examples in the examples/ folder. If you want to write a web app, then go to https://github.com/emilk/eframe_template/ and follow the instructions. The official docs are at https://docs.rs/egui. For inspiration and more examples, check out the the egui web demo and follow the links in it to its source code.

If you want to integrate egui into an existing engine, go to the Integrations section.

If you have questions, use GitHub Discussions. There is also an egui discord server. If you want to contribute to egui, please read the Contributing Guidelines.

Demo

Click to run egui web demo (works in any browser with Wasm and WebGL support). Uses eframe.

To test the demo app locally, run cargo run --release -p egui_demo_app.

The native backend is egui-wgpu (using wgpu) and should work out-of-the-box on Mac and Windows, but on Linux you need to first run:

sudo apt-get install -y libclang-dev libgtk-3-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev

On Fedora Rawhide you need to run:

dnf install clang clang-devel clang-tools-extra libxkbcommon-devel pkg-config openssl-devel libxcb-devel gtk3-devel atk fontconfig-devel

NOTE: This is just for the demo app - egui itself is completely platform agnostic!

Goals

  • The easiest to use GUI library
  • Responsive: target 60 Hz in debug build
  • Friendly: difficult to make mistakes, and shouldn't panic
  • Portable: the same code works on the web and as a native app
  • Easy to integrate into any environment
  • A simple 2D graphics API for custom painting (epaint).
  • Pure immediate mode: no callbacks
  • Extensible: easy to write your own widgets for egui
  • Modular: You should be able to use small parts of egui and combine them in new ways
  • Safe: there is no unsafe code in egui
  • Minimal dependencies

egui is not a framework. egui is a library you call into, not an environment you program for.

NOTE: egui does not claim to have reached all these goals yet! egui is still work in progress.

Non-goals

  • Become the most powerful GUI library
  • Native looking interface

State

egui is in active development. It works well for what it does, but it lacks many features and the interfaces are still in flux. New releases will have breaking changes.

Still, egui can be used to create professional looking applications, like the Rerun Viewer.

Features

  • Widgets: label, text button, hyperlink, checkbox, radio button, slider, draggable value, text editing, color picker, spinner
  • Images
  • Layouts: horizontal, vertical, columns, automatic wrapping
  • Text editing: multiline, copy/paste, undo, emoji supports
  • Windows: move, resize, name, minimize and close. Automatically sized and positioned.
  • Regions: resizing, vertical scrolling, collapsing headers (sections), panels
  • Rendering: Anti-aliased rendering of lines, circles, text and convex polygons.
  • Tooltips on hover
  • Accessibility via AccessKit
  • Label text selection
  • And more!

Check out the 3rd party egui crates wiki for even more widgets and features, maintained by the community.

Light Theme:

Dependencies

egui has a minimal set of default dependencies. Heavier dependencies are kept out of egui, even as opt-in. All code in egui is Wasm-friendly (even outside a browser).

To load images into egui you can use the official egui_extras crate.

eframe on the other hand has a lot of dependencies, including winit, image, graphics crates, clipboard crates, etc,

Who is egui for?

egui aims to be the best choice when you want a simple way to create a GUI, or you want to add a GUI to a game engine.

If you are not using Rust, egui is not for you. If you want a GUI that looks native, egui is not for you. If you want something that doesn't break when you upgrade it, egui isn't for you (yet).

But if you are writing something interactive in Rust that needs a simple GUI, egui may be for you.

Integrations

egui is built to be easy to integrate into any existing game engine or platform you are working on. egui itself doesn't know or care on what OS it is running or how to render things to the screen - that is the job of the egui integration.

An integration needs to do the following each frame:

  • Input: Gather input (mouse, touches, keyboard, screen size, etc) and give it to egui
  • Call into the application GUI code
  • Output: Handle egui output (cursor changes, paste, texture allocations, …)
  • Painting: Render the triangle mesh egui produces (see OpenGL example)

Official integrations

These are the official egui integrations:

  • eframe for compiling the same app to web/wasm and desktop/native. Uses egui-winit and egui_glow or egui-wgpu
  • egui_glow for rendering egui with glow on native and web, and for making native apps
  • egui-wgpu for wgpu (WebGPU API)
  • egui-winit for integrating with winit

3rd party integrations

Check the wiki to find 3rd party integrations and egui crates.

Writing your own egui integration

Missing an integration for the thing you're working on? Create one, it's easy! See https://docs.rs/egui/latest/egui/#integrating-with-egui.

Why immediate mode

egui is an immediate mode GUI library, as opposed to a retained mode GUI library. The difference between retained mode and immediate mode is best illustrated with the example of a button: In a retained GUI you create a button, add it to some UI and install some on-click handler (callback). The button is retained in the UI, and to change the text on it you need to store some sort of reference to it. By contrast, in immediate mode you show the button and interact with it immediately, and you do so every frame (e.g. 60 times per second). This means there is no need for any on-click handler, nor to store any reference to it. In egui this looks like this: if ui.button("Save file").clicked() { save(file); }.

A more detailed description of immediate mode can be found in the egui docs.

There are advantages and disadvantages to both systems.

The short of it is this: immediate mode GUI libraries are easier to use, but less powerful.

Advantages of immediate mode

Usability

The main advantage of immediate mode is that the application code becomes vastly simpler:

  • You never need to have any on-click handlers and callbacks that disrupts your code flow.
  • You don't have to worry about a lingering callback calling something that is gone.
  • Your GUI code can easily live in a simple function (no need for an object just for the UI).
  • You don't have to worry about app state and GUI state being out-of-sync (i.e. the GUI showing something outdated), because the GUI isn't storing any state - it is showing the latest state immediately.

In other words, a whole lot of code, complexity and bugs are gone, and you can focus your time on something more interesting than writing GUI code.

Disadvantages of immediate mode

Layout

The main disadvantage of immediate mode is it makes layout more difficult. Say you want to show a small dialog window in the center of the screen. To position the window correctly the GUI library must first know the size of it. To know the size of the window the GUI library must first layout the contents of the window. In retained mode this is easy: the GUI library does the window layout, positions the window, then checks for interaction ("was the OK button clicked?").

In immediate mode you run into a paradox: to know the size of the window, we must do the layout, but the layout code also checks for interaction ("was the OK button clicked?") and so it needs to know the window position before showing the window contents. This means we must decide where to show the window before we know its size!

This is a fundamental shortcoming of immediate mode GUIs, and any attempt to resolve it comes with its own downsides.

One workaround is to store the size and use it the next frame. This produces a frame-delay for the correct layout, producing occasional flickering the first frame something shows up. egui does this for some things such as windows and grid layouts.

The "first-frame jitter" can be covered up with an extra pass, which egui supports via Context::request_discard. The downside of this is the added CPU cost of a second pass, so egui only does this in very rare circumstances (the majority of frames are single-pass).

For "atomic" widgets (e.g. a button) egui knows the size before showing it, so centering buttons, labels etc is possible in egui without any special workarounds.

See this issue for more.

CPU usage

Since an immediate mode GUI does a full layout each frame, the layout code needs to be quick. If you have a very complex GUI this can tax the CPU. In particular, having a very large UI in a scroll area (with very long scrollback) can be slow, as the content needs to be laid out each frame.

If you design the GUI with this in mind and refrain from huge scroll areas (or only lay out the part that is in view) then the performance hit is generally pretty small. For most cases you can expect egui to take up 1-2 ms per frame, but egui still has a lot of room for optimization (it's not something I've focused on yet). egui only repaints when there is interaction (e.g. mouse movement) or an animation, so if your app is idle, no CPU is wasted.

If your GUI

Extension points exported contracts — how you extend this code

App (Interface)
Implement this trait to write apps that can be compiled for both web/wasm and desktop/native using [`eframe`](https://gi [26 …
crates/eframe/src/epi.rs
View (Interface)
Something to view in the demo windows [40 implementers]
crates/egui_demo_lib/src/demo/mod.rs
DemoApp (Interface)
Trait that wraps different parts of the demo app. [8 implementers]
crates/egui_demo_app/src/lib.rs
IntoTag (Interface)
Helper trait for all types that can be parsed as a [`font_types::Tag`]. [5 implementers]
crates/epaint/src/text/text_layout_types.rs
HasClasses (Interface)
Any widgets supporting [`Classes`] must implement this trait [5 implementers]
crates/egui/src/widget_style.rs
GuiRounding (Interface)
Trait for rounding coordinates and sizes to align with either . See [`GuiRounding::round_ui`] for more information. [5 …
crates/emath/src/gui_rounding.rs
CallbackTrait (Interface)
A callback trait that can be used to compose an [`epaint::PaintCallback`] via [`Callback`] for custom WGPU rendering. C [1 …
crates/egui-wgpu/src/renderer.rs
TestRenderer (Interface)
(no doc) [2 implementers]
crates/egui_kittest/src/renderer.rs

Core symbols most depended-on inside this repo

label
called by 755
crates/egui/src/ui.rs
vec2
called by 435
crates/emath/src/vec2.rs
push
called by 311
crates/epaint/src/text/text_layout_types.rs
pos2
called by 290
crates/emath/src/pos2.rs
iter
called by 247
crates/egui/src/ui_stack.rs
end_row
called by 224
crates/egui/src/ui.rs
clicked
called by 194
crates/egui/src/response.rs
button
called by 169
crates/egui/src/ui.rs

Shape

Method 3,759
Function 916
Class 591
Enum 128
Interface 39

Languages

Rust100%
Python1%

Modules by API surface

crates/egui/src/context.rs201 symbols
crates/egui/src/ui.rs179 symbols
crates/emath/src/rect.rs93 symbols
crates/egui/src/input_state/mod.rs85 symbols
crates/egui/src/memory/mod.rs82 symbols
crates/egui/src/response.rs74 symbols
crates/epaint/src/text/text_layout_types.rs70 symbols
crates/egui/src/util/id_type_map.rs67 symbols
crates/egui/src/style.rs67 symbols
crates/epaint/src/text/fonts.rs64 symbols
crates/egui/src/containers/window.rs64 symbols
crates/egui_extras/src/table.rs62 symbols

For agents

$ claude mcp add egui \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact