Skip to content
rustbasicPublic

About

A small integration between egui and Bevy.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

87 Commits

Folders and files

Repository files navigation

egui-bevy

A small integration between egui and Bevy.

Live Demo

Open the WebGPU demo

Screenshot of the Windows 3D overlay example

Showcase

IQPush is a Sokoban-style game built with egui-bevy. Play the live demo | GitHub project.

Dependencies

egui-bevy egui Bevy
0.4.0 0.38.0 ^0.20.0 or later
0.3.2 and earlier 0.37.0 ^0.20.0 or later

Motivation

I started this library because CJK text input worked for me in egui directly, but I couldn't get it working with bevy_egui. This project explores a separate integration path for using egui with Bevy.

I haven't yet evaluated the relative advantages and disadvantages of bevy_egui and egui_bevy, so this project does not claim that one is better than the other.

Current status

The library provides EguiBevyPlugin for displaying egui over Core2d or Core3d output in each Bevy window. Add it after Bevy's renderer plugins and provide a callback that builds each egui frame:

The graphics backend is configured when Bevy's RenderPlugin is initialized, before adding EguiBevyPlugin; this integration plugin does not change an already initialized renderer. Use DefaultPlugins.set(egui_bevy::render_plugin_with_backend(egui_bevy::RenderBackend::Default)) for platform defaults: WGPU_BACKEND is honored when set, otherwise Windows uses DX12, Apple platforms use Metal, and other native platforms use Vulkan. Explicit RenderBackend variants override WGPU_BACKEND. The existing default_render_plugin() helper remains available to prefer DX12 on Windows Native while retaining Bevy defaults elsewhere. Enable the corresponding Bevy render features; native GL may require bevy_render/gles and a compatible ANGLE setup.

app.add_plugins(EguiBevyPlugin::new(|ctx| {
    egui::Window::new("Hello").show(ctx, |ui| ui.label("Hello from egui"));
}));

By default, each Bevy window gets an independent egui context and UI frame. The callback runs on Bevy's main thread. The plugin forwards window-specific pointer, keyboard, DPI, and IME input, as well as clipboard copy, cut, and paste, then composites egui over the window's Core2d or Core3d view. Shared egui state across windows is also available through shared deferred viewports, described below. Each Bevy window supports one egui overlay; multiple camera views in one window are not supported. On WebAssembly, browser DOM text input is connected to the primary window only. The integration has been tested on Windows and WebAssembly; other platforms have not yet been tested.

Shared egui viewports

Enable with_shared_viewports() to use one egui context for the root window and its deferred child viewports. To render a child viewport in an existing secondary Bevy window, add EguiViewport with the same unique ViewportId used by show_viewport_deferred, as shown below. On native platforms, an unmapped deferred viewport gets a Bevy window and camera created by the plugin; on WebAssembly, deferred viewports remain embedded in the root viewport:

let inspector = egui::ViewportId::from_hash_of("inspector");

app.add_plugins(
    EguiBevyPlugin::new(move |ctx| {
        ctx.show_viewport_deferred(
            inspector,
            egui::ViewportBuilder::default().with_title("Inspector"),
            |ui, _class| {
                egui::CentralPanel::default().show(ui, |ui| {
                    ui.label("Inspector contents");
                });
            },
        );
    })
    .with_shared_viewports(),
);

// Spawn this as an existing secondary Bevy window:
commands.spawn((Window::default(), EguiViewport(inspector)));

The primary window is the root viewport. Existing secondary Bevy windows are associated with deferred child viewports only when marked with EguiViewport; on native platforms, the plugin creates a Bevy window and camera for each unmapped deferred viewport.

examples/windows-overlay demonstrates a 2D scene with egui. examples/multi-window demonstrates independent egui contexts in multiple native Bevy windows (the browser version uses one canvas). examples/multi-viewport demonstrates shared deferred viewports: a mapped Inspector window and an automatically created native Preview window; both viewports are embedded in the root viewport in a browser. examples/split-screen compares one rotating 3D scene through two adjustable camera viewports in one Bevy window. Its left and right camera-control windows can be moved freely and are not confined to their corresponding viewports. Both windows share a single egui context and input; they are not independent camera-specific UIs. examples/windows-3d-overlay demonstrates a rotating 3D cube with interactive egui controls on Windows. examples/wasm-3d-overlay is the WebGPU-only browser version. It is intended for GitHub Pages and requires a browser with WebGPU support; it does not include a WebGL2 fallback.

Development

This project is developed with the assistance of AI.

Contributions are welcome! Feel free to open an issue or submit a pull request.

About

A small integration between egui and Bevy.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages