You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Emil Ernerfeldt 7641807665 cargo update 4 years ago
.github better ci job names 4 years ago
docs Fix web blur (#151) 4 years ago
eframe Multiple mouse button support (#135) 4 years ago
egui Improve documentation 4 years ago
egui_demo_app Release 0.8.0 - Grid layout & new visual style 4 years ago
egui_demo_lib [demo] Refactor and minor cleanup 4 years ago
egui_glium Add support for a HTTP body for POST (#139) 4 years ago
egui_web Fix web blur (#151) 4 years ago
emath Improve documentation 4 years ago
epaint Add ui.set_enabled(false) to disable all widgets in a Ui 4 years ago
epi Add support for a HTTP body for POST (#139) 4 years ago
media Release 0.8.0 - Grid layout & new visual style 4 years ago
.gitignore Combine demo_glium and demo_web into one egui_demo crate 4 years ago
CHANGELOG.md Add Ui functions for doing manual layout ("put this widget here") 4 years ago
CONTRIBUTING.md Rename Egui to egui 4 years ago
Cargo.lock cargo update 4 years ago
Cargo.toml Break out mod paint into new crate epaint 4 years ago
LICENSE-APACHE [license] licence under MIT or Apache-2.0 5 years ago
LICENSE-MIT Fix license copy-paste mistake 4 years ago
README.md Improve documentation 4 years ago
build_demo_native.sh Build demo app with all features enabled 4 years ago
build_demo_web.sh Build demo app with all features enabled 4 years ago
check.sh Add doc checks to check.sh 4 years ago
setup_web.sh Combine demo_glium and demo_web into one egui_demo crate 4 years ago
start_server.sh Update wasm/web example 5 years ago

README.md

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

Latest version Documentation unsafe forbidden Build Status MIT Apache dependencies: rusttype atomic_refcell ahash

egui 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 (or will soon).

egui aims to be the easiest-to-use Rust GUI libary, 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.

Sections:

Quick start

If you just want to write a GUI application in Rust (for the web or for native), go to https://github.com/emilk/egui_template/ and follow the instructions there!

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

If you have questions, use Discussions. 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).

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

The native backend is currently using glium (though there are plans to change that) and should work out-of-the-box on Mac and Windows, but on Linux you need to first run:

sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev

NOTE: egui itself is completely platform agnostic.

Example

ui.heading("My egui Application");
ui.horizontal(|ui| {
    ui.label("Your name: ");
    ui.text_edit_singleline(&mut name);
});
ui.add(egui::Slider::u32(&mut age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
    age += 1;
}
ui.label(format!("Hello '{}', age {}", name, age));

Goals

  • The easiest to use GUI libary
  • 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).
  • No callbacks
  • Pure immediate mode
  • 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: rusttype, atomic_refcell and ahash.

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 libary
  • Native looking interface
  • Advanced and flexible layouts (that's fundamentally incompatible with immediate mode)

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.

egui vs Dear ImGui

The obvious alternative to egui is imgui-rs, the Rust wrapper around the C++ library Dear ImGui. Dear ImGui is a great library, which a lot more features and polish compared to egui. However, egui provides some benefits for Rust users:

  • egui is pure Rust
  • egui is easily compiled to WASM
  • egui lets you use native Rust String types (imgui-rs forces you to use annoying macros and wrappers for zero-terminated strings)
  • Writing your own widgets in egui is simple

egui also tries to improve your experience in other small ways:

  • Windows are automatically sized based on their contents
  • Windows are automatically positioned to not overlap with each other
  • Some subtle animations make egui come alive

So in summary:

  • egui: pure Rust, new, exciting, work in progress
  • Dear ImGui: feature rich, well tested, cumbersome Rust integration

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.

Features

  • Widgets: label, text button, hyperlink, checkbox, radio button, slider, draggable value, text editing, combo box, color picker
  • 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)
  • Rendering: Anti-aliased rendering of lines, circles, text and convex polygons.
  • Tooltips on hover
  • More

How it works

Loop:

  • Gather input (mouse, touches, keyboard, screen size, etc) and give it to egui
  • Run application code (Immediate Mode GUI)
  • Tell egui to tessellate the frame graphics to a triangle mesh
  • Render the triangle mesh with your favorite graphics API (see OpenGL example)

Integrations

egui is build 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. The integration needs to do two things:

  • IO: Supply egui with input (mouse position, keyboard presses, ...) and handle egui output (cursor changes, copy-paste integration, ...).
  • Painting: Render the textured triangles that egui outputs.

Official

I maintain two official egui integrations:

The same code can be compiled to a native app or a web app.

3rd party

Writing your own egui integration

You need to collect egui::RawInput, paint egui::ClippedMesh:es and handle egui::Output. The basic structure is this:

let mut egui_ctx = egui::Context::new();

// Game loop:
loop {
    let raw_input: egui::RawInput = my_integration.gather_input();
    egui_ctx.begin_frame(raw_input);
    my_app.ui(&mut egui_ctx); // add panels, windows and widgets to `egui_ctx` here
    let (output, shapes) = egui_ctx.end_frame();
    let clipped_meshes = egui_ctx.tessellate(shapes); // create triangles to paint
    my_integration.paint(clipped_meshes);
    my_integration.set_cursor_icon(output.cursor_icon);
    // Also see `egui::Output` for more
}

For a reference OpenGL backend, see the egui_glium painter or the egui_web WebGL painter.

Debugging your integration

Things look jagged

  • Turn off backface culling.

My text is blurry

  • Make sure you set the proper pixels_per_point in the input to egui.
  • Make sure the texture sampler is not off by half a pixel. Try nearest-neighbor sampler to check.

My windows are too transparent or too dark

  • egui uses premultiplied alpha, so make sure your blending function is (ONE, ONE_MINUS_SRC_ALPHA).
  • Make sure your texture sampler is clamped (GL_CLAMP_TO_EDGE).
  • Use an sRGBA-aware texture if available (e.g. GL_SRGB8_ALPHA8).
    • Otherwise: remember to decode gamma in the fragment shader.
  • Decode the gamma of the incoming vertex colors in your vertex shader.
  • Turn on sRGBA/linear framebuffer if available (GL_FRAMEBUFFER_SRGB).
    • Otherwise: gamma-encode the colors before you write them again.

Other

Conventions and design choices

All coordinates are in screen space coordinates, with (0, 0) in the top left corner

All coordinates are in locial "points" which may consist of many physical pixels.

All colors have premultiplied alpha.

egui uses the builder pattern for construction widgets. For instance: ui.add(Label::new("Hello").text_color(RED)); I am not a big fan of the builder pattern (it is quite verbose both in implementation and in use) but until Rust has named, default arguments it is the best we can do. To alleviate some of the verbosity there are common-case helper functions, like ui.label("Hello");.

Instead of using matching begin/end style function calls (which can be error prone) egui prefers to use FnOnce closures passed to a wrapping function. Lambdas are a bit ugly though, so I'd like to find a nicer solution to this.

Inspiration

The one and only Dear ImGui is a great Immediate Mode GUI for C++ which works with many backends. That library revolutionized how I think about GUI code and turned GUI programming from something I hated to do to something I now enjoy.

Name

The name of the library and the project is "egui" and pronounced as "e-gooey".

The library was originally called "Emigui", but was renamed to "egui" in 2020.

Credits / Licenses

egui author: Emil Ernerfeldt

egui is under MIT OR Apache-2.0 license.

Fonts: