About egui

egui is an immediate mode GUI library written in Rust. It's designed to be easy to use, portable, and fast. Unlike traditional retained-mode GUI frameworks where you create and manage widget objects, egui uses an immediate mode approach where your GUI code runs every frame.

What is Immediate Mode?

In immediate mode GUIs, you don't create widgets that persist between frames. Instead, you describe what your UI should look like right now, every frame. This might sound inefficient, but it comes with several advantages:

Key Benefits

  1. Simple State Management: No need to synchronize widget state with your application state
  2. Easy to Reason About: The UI code directly reflects what you see
  3. No Memory Leaks: Widgets don't accumulate over time
  4. Dynamic UIs: Easy to create interfaces that change based on conditions

How It Works

Here's a simple example that demonstrates the immediate mode concept:

// This code runs 60+ times per second
if ui.button("Click me").clicked() {
    println!("Button was clicked!");
}

Each frame, egui:

  1. Lays out the text "Click me" to determine button size
  2. Positions the button on screen
  3. Checks if the mouse is hovering or clicking the button area
  4. Chooses appropriate colors based on interaction state
  5. Adds drawing instructions for the button
  6. Returns a Response indicating if it was clicked

There's no button object being stored anywhere - just drawing instructions and interaction feedback.