egui

repository·main·Indexed 12 days ago

https://github.com/emilk/egui

An immediate mode GUI library for Rust. Includes eframe for building native (Linux, Mac, Windows, Android) and web (Wasm) applications, egui_glow for cross-platform rendering, and egui_extras for image loading. Provides tools for UI testing via egui_kittest and external application observation through egui_inspection.

Tokens
91.5K
Snippets
340
Records
435
Agent score
99%

What's inside egui

  1. Overview of the ecolor library

    main

    ecolor is a simple color storage and conversion library designed specifically for the needs of the egui framework. It provides basic color handling capabilities but is not intended to be a comprehensive color science library.

    Note: If you require a robust, feature-rich color library, the author recommends using the color crate instead.

  2. Overview of the emath library

    main
    emath is a bare-bones 2D math library designed specifically for GUI building. It provides types and functions that are highly useful when working with egui. The library is designed with safety in mind and forbids the use of unsafe code.
  3. Use egui_glow for cross-platform rendering

    main

    The egui_glow crate provides bindings between egui and glow. It allows you to render egui using glow on both native and web platforms.

    Key capabilities:

    • Render egui using glow on native and web.
    • Write cross-platform native egui applications by enabling the winit feature.

    For web applications using glow, it is recommended to use eframe, which utilizes egui_glow internally for rendering.

  4. Explore egui and eframe examples

    main

    The examples/ directory contains various demonstrations of egui and eframe. Most examples use eframe to set up the application window, but many egui patterns shown are applicable to any integration (such as egui-wgpu or egui-glow).

    For a more comprehensive list of examples, including source code links, visit the official website at https://www.egui.rs.

  5. Integrate egui with winit using egui-winit

    main

    The egui-winit crate provides the necessary bindings to connect the egui immediate-mode GUI framework with the winit windowing library. It acts as an event translator, converting winit events into a format egui can understand.

    Key responsibilities of egui-winit include:

    • Translating winit events to egui events.
    • Handling copy/paste operations.
    • Updating the cursor position.
    • Managing interactions like opening links clicked within the egui interface.
  6. Use egui-wgpu for egui and wgpu bindings

    main
    The egui-wgpu crate provides the necessary bindings to integrate the egui immediate mode GUI framework with the wgpu graphics API. Use this crate when you are building a custom rendering backend for egui using wgpu instead of using the high-level eframe wrapper.
  7. Understand the egui crate ecosystem

    main

    The egui ecosystem is composed of several specialized crates that work together to provide a complete GUI experience.

    • egui: The core GUI library containing the main logic and widget implementations.
    • emath: A minimal 2D math library used by almost all other crates.
    • epaint: Handles 2D shapes and text rendering by converting them into textured triangles. It depends on emath and optionally epaint_default_fonts.
    • epaint_default_fonts: Provides embedded font files for epaint.
    • egui_extras: Provides additional high-level features and widgets on top of the core egui library.
    • eframe: The official framework for running egui applications. It is designed to allow the same application code to be compiled for both web (WASM) and native platforms.
    • egui_demo_lib & egui_demo_app: Example implementations showing how to structure UI code (egui_demo_lib) and how to wrap it for web or native deployment (egui_demo_app).
  8. Use `epaint_default_fonts` for egui and epaint

    main
    epaint_default_fonts provides the default fonts used by epaint and egui. This crate is specifically designed to be used as a dependency for egui or epaint applications to ensure consistent default typography. It is not intended to be used as a standalone library.
  9. What is egui_inspection and what can it do?

    main

    egui_inspection provides a wire protocol and an egui::Plugin (InspectionPlugin) that allows external tools to observe and drive an egui application. It is designed for tools like egui_mcp (an MCP server for AI agents) or planned visual debuggers and test inspection tools.

    Supported capabilities include:

    • AccessKit tree reading (GetTree): Inspect the widget tree.
    • Input event injection (HandleEvents): Simulate clicks, typing, and scrolling.
    • Screenshot capture (Screenshot): Capture the current frame (requires the window to be visible/foregrounded).
    • Window resizing (Resize): Change the application window size.

    The protocol follows a strict request-response pattern, making it compatible with TCP sockets or unary RPC transports.

  10. How egui handles platform integration and rendering

    main

    To run an egui application, you need integration crates that bridge the gap between the GUI logic and the operating system/graphics API:

    Windowing and Events

    • egui-winit: Provides bindings between egui and the winit crate. It translates winit events into egui events, manages copy/paste, updates the cursor, and handles opening links clicked within the UI.

    Graphics Rendering

    • egui_glow: Renders egui triangles using the glow (GL on Whatever) library for native desktop windows.
    • egui-wgpu: Renders egui triangles using the wgpu graphics API.

    Framework

    • eframe: Acts as the high-level host that orchestrates these components, allowing you to write code once and deploy to web or native.
  11. Understand the egui core architecture

    main

    The egui crate is a platform-independent GUI implementation. It does not include a backend for rendering or input handling. Instead, it operates on a frame-by-frame basis:

    1. Input: You provide the library with input data (such as mouse position, keyboard events, etc.) for the current frame.
    2. Output: The library produces a triangle mesh that you are responsible for painting using your chosen graphics backend.