A plugin for Egui integration into Bevy

Overview

bevy_egui

Crates.io Documentation License Downloads Rust

This crate provides a Egui integration for the Bevy game engine.

Features:

bevy_egui can be compiled with using only bevy and egui as dependencies: manage_clipboard and open_url features, that require additional crates, can be disabled.

bevy_egui

Trying out

An example WASM project is live at mvlabat.github.io/bevy_egui_web_showcase [source].

Note that in order to use bevy_eguiin WASM you need bevy_webgl2 of at least 0.4.1 version.

Usage

Here's a minimal usage example:

# Cargo.toml
[dependencies]
bevy = "0.4"
bevy_egui = "0.3"
use bevy::prelude::*;
use bevy_egui::{egui, EguiContext, EguiPlugin};

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_plugin(EguiPlugin)
        .add_system(ui_example.system())
        .run();
}

fn ui_example(mut egui_context: ResMut<EguiContext>) {
    let ctx = &mut egui_context.ctx;
    egui::Window::new("Hello").show(ctx, |ui| {
        ui.label("world");
    });
}

For a more advanced example, see examples/ui.rs.

cargo run --example ui --features="bevy/x11 bevy/png bevy/bevy_wgpu"

See also

Comments
  • update to bevy 0.5

    update to bevy 0.5

    This shouldn't be merged yet, I'm just putting this up as a draft PR so that anyone who wants to update to bevy main can see that the work is already done.

    includes #3

    opened by jakobhellermann 14
  • gfx_backend_vulkan error

    gfx_backend_vulkan error

    I have just added env_logger::init(); to the simple.rs example and I'm getting the following message every frame:

    [2021-10-04T09:17:50Z ERROR gfx_backend_vulkan]
        VALIDATION [UNASSIGNED-CoreValidation-DrawState-QueueForwardProgress (-400166253)] : Validation Error: [ UNASSIGNED-CoreValidation-DrawState-QueueForwardProgress ] Object 0: handle = 0xea7170000000031, type = VK_OBJECT_TYPE_SEMAPHORE; Object 1: handle = 0x1e5f980a668, type = VK_OBJECT_TYPE_QUEUE; Object 2: handle = 0x1e5f980a668, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0xe825f293 | vkQueueSubmit(): pSubmits[0].pSignalSemaphores[0] is signaling VkQueue 0x1e5f980a668[] (VkSemaphore 0xea7170000000031[]) that was previously signaled by VkQueue 0x1e5f980a668[] but has not since been waited on by any queue.
        object info: (type: SEMAPHORE, hndl: 1055837926409109553), (type: QUEUE, hndl: 2087245096552), (type: QUEUE, hndl: 2087245096552)
    

    Here's my setup. Dependencies:

    bevy = "0.5.0"
    bevy_egui = "0.7.0"
    env_logger = "0.9.0"
    

    compiler: rustc 1.57.0-nightly (9dbb26efe 2021-10-03) OS: Windows 10 GPU: GeForce GTX 1050 Ti GPU driver: NVIDIA 472.12

    Let me know if I can provide any further information to help reproduce.

    opened by ghost 10
  • Egui crashes with

    Egui crashes with "no entry found for key"

    Today I tried updating both bevy and bevy_egui to their latest versions. Suddenly, in my UI system, I can no longer get the context for the primary window. The code looks like this:

    pub fn ui(
        egui_ctx: ResMut<EguiContext>,
        // other stuff...
    ) {
        let ctx = egui_ctx.ctx(); // crashes
        
        // other stuff...
    }
    

    Oddly enough the example code seems to work just fine. I have no idea which interactions within the code might be causing the crash. I can upload the full code if it helps.

    opened by vihdzp 9
  • calling `EguiContext::ctx` from a startup system

    calling `EguiContext::ctx` from a startup system

    I would like to globally modify some egui visuals, I tried using this

    fn ui_setup(egui_context: ResMut<EguiContext>) {
        egui_context.ctx().set_visuals(egui::Visuals {
            window_shadow: Default::default(),
            ..Default::default()
        });
    }
    

    as a startup system. (Just added this to the simple.rs example.) Unfortunately, this results in a panic:

    thread 'main' panicked at '`EguiContext::ctx()` called before the ctx has been initialized. Consider moving your UI system to `CoreStage::Update` or run you system after `EguiSystem::BeginFrame`.'
    

    The message here seems to be relevant to regular systems, but not to startup systems. How do I ensure that my startup system runs after the context has been initialized?

    opened by ghost 7
  • Example for a panel side-by-side with bevy main camera

    Example for a panel side-by-side with bevy main camera

    I would like to build an editor-style application with an egui-rendered panel next to a view of my in-game world. Right now, the closest example I could find to that is two_windows.rs which spawns a window on top of a bevy camera. I don't really want to use a window, I just a panel docked to one (ideally, both) sides of the screen with a bevy camera drawing the middle.

    Is this even possible with egui? Do I need to install a Frame, maybe? If you can point me towards the right solution - and if I get it working - I'll contribute back an example.

    question 
    opened by masonk 7
  • Provide ability to use GIT egui

    Provide ability to use GIT egui

    I have a situation where I would like to use a Table widget. This is not built into the released version of egui right now, but seems as though a recent merge to master has provided some basic functionality. Is there a way (without forking bevy_egui) that I can get bevy_egui to use the GIT version of egui? Right now it seems as though it is hard coded.

    See discussion at https://github.com/emilk/egui/issues/296 and https://github.com/emilk/egui/pull/963 for more details.

    Possibly adding a feature flag for a specific git branch of egui would be nice.

    opened by justacec 6
  • Keys now trigger actions on hold, not press

    Keys now trigger actions on hold, not press

    Hey, not sure if this is on bevy_egui's end or if I'll have to chase it through egui. I updated https://github.com/ndarilek/bevy_egui_a11y to work on Bevy 0.6. Formerly, pressing tab moved focus once. Now it seems to move focus rapidly.

    It seems like some of these events are being triggered on hold rather than just on press. Focus should only move once when I press tab.

    Thanks!

    opened by ndarilek 6
  • Can a `Res<EguiContext>` be used in two parallel systems?

    Can a `Res` be used in two parallel systems?

    This is more of a question than an issue. In my application, I currently have various parallel systems showing different windows. Most times they work just fine, but they occasionally provoke a startup crash, so I wonder if this is a limitation or a bug.

    The first few lines of the startup crash error message:

    thread 'main' panicked at 'already mutably borrowed', C:\Users\vi\.cargo\registry\src\github.com-1ecc6299db9ec823\atomic_refcell-0.1.7\src\lib.rs:151:23
    stack backtrace:
       0: std::panicking::begin_panic_handler
                 at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\std\src\panicking.rs:493
       1: core::panicking::panic_fmt
                 at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53\/library\core\src\panicking.rs:92
       2: core::panicking::panic_str
                 at C:\Users\vi\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\panicking.rs:57
       3: atomic_refcell::AtomicRefCell<egui::memory::Memory>::borrow_mut<egui::memory::Memory>
                 at C:\Users\vi\.cargo\registry\src\github.com-1ecc6299db9ec823\atomic_refcell-0.1.7\src\lib.rs:151
       4: epaint::mutex::Mutex<egui::memory::Memory>::lock
                 at C:\Users\vi\.cargo\git\checkouts\egui-5e4507fa4153be06\effd3c7\epaint\src\mutex.rs:144
       5: egui::context::Context::memory
                 at C:\Users\vi\.cargo\git\checkouts\egui-5e4507fa4153be06\effd3c7\egui\src\context.rs:378
       6: egui::context::Context::style
                 at C:\Users\vi\.cargo\git\checkouts\egui-5e4507fa4153be06\effd3c7\egui\src\context.rs:443
       7: egui::containers::window::{{impl}}::show_impl::{{closure}}
                 at C:\Users\vi\.cargo\git\checkouts\egui-5e4507fa4153be06\effd3c7\egui\src\containers\window.rs:255
       8: core::option::Option<egui::containers::frame::Frame>::unwrap_or_else<egui::containers::frame::Frame,closure-0>
                 at C:\Users\vi\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\option.rs:427
       9: egui::containers::window::Window::show_impl
                 at C:\Users\vi\.cargo\git\checkouts\egui-5e4507fa4153be06\effd3c7\egui\src\containers\window.rs:255
      10: egui::containers::window::Window::show<closure-0>
                 at C:\Users\vi\.cargo\git\checkouts\egui-5e4507fa4153be06\effd3c7\egui\src\containers\window.rs:236
    
    opened by vihdzp 6
  • Directly use EventReader

    Directly use EventReader

    Use EventReader directly, which was made possible by https://github.com/bevyengine/bevy/pull/1244.

    This should not be merged before the release of Bevy 0.5, as it needs at least commit https://github.com/bevyengine/bevy/commit/a880b5450829411b0248e47cc066915234371d86 to work.

    One test is failing, but i am not sure if it has something to do with my changes. I tested this in one of my project and it works just fine.

    running 2 tests
    test src\lib.rs - EguiSettings::scale_factor (line 100) ... ok
    test src\lib.rs - (line 23) ... FAILED
    
    failures:
    
    ---- src\lib.rs - (line 23) stdout ----
    Test executable failed (exit code 101).
    
    stderr:
    thread 'Compute Task Pool (2)' panicked at 'assertion failed: pixels_per_point > 0.0', C:\Users\...\.cargo\registry\src\github.com-1ecc6299db9ec823\epaint-0.8.0\src\text\font.rs:76:9
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    thread 'main' panicked at 'task has failed', C:\Users\...\.cargo\registry\src\github.com-1ecc6299db9ec823\async-task-4.0.3\src\task.rs:368:45
    
    
    
    failures:
        src\lib.rs - (line 23)
    
    test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.15s
    
    opened by Weasy666 6
  • Window is open and checkbox is checked added to ui.rs example

    Window is open and checkbox is checked added to ui.rs example

    Added demonstration how to use egui::Window::open(self, &'open mut bool). Since I am a newcomer to rust I have been struggling with passing a mutable bool. Should be useful for other newcomers as well since closing or opening a window is such a common use case.

    Hope that helps.

    opened by tomuxmon 5
  • Provide Description on How to Adjust Scene Render Window

    Provide Description on How to Adjust Scene Render Window

    I currently have an app with an egui::SidePanel on the left and an egui::TopBottomPanel on the bottom. This is working great. Now if I go to Bevy and add an obj file and render it, I can see that the panels are simply drawn on top of the scene rendering context. What I would like is for the the rendering scene to fill the space that is not covered by the panels. So, shifted to the upper right area of the window, in this way, the world point (0, 0, 0) would be at the center of the un-paneled space. (does this make sense)

    I am not sure how to make this adjustment, I have been going though the Bevy docs but did not see anything there. Thought it might be in one of the bevy_egui examples but it does not seem so.

    Can this be done? If so, can you add some documentation to point peeps in the right direction? :).

    opened by justacec 5
  • Fix panic due to missing swapchain texture.

    Fix panic due to missing swapchain texture.

    Fixes #136.

    Because of some driver quirks, Bevy will ignore swapchain timeouts on some devices, as mentioned in bevyengine/bevy#5957. When this occurs, extracted_window.swap_chain_texture will be None.

    Bevy handles this by bailing out of the render node early (see here), and this fix is implemented in the same way.

    opened by connerebbinghaus 0
  • example/ui.rs ui_state.value have the same name with ResMut.value, causing lint reporting error.

    example/ui.rs ui_state.value have the same name with ResMut.value, causing lint reporting error.

    bevy_egui = "0.17.1"

    Though it's able to be compiled, ui.rs at line 124, Clippy report: mismatched types [E0308] expected RangeInclusive<&mut UiState>, found RangeInclusive<f64>.

    This is probably because UiState.value has the same name as ResMut.value. Change UiState.value to UiState.value_1 solves the error.

    opened by iamabigartist 0
  • Encountered a panic

    Encountered a panic

    I've ran into a panic on linux/gnu running cargo run --release:

    thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_egui-0.17.1/src/egui_node.rs:332:79
    

    The UI Code is pretty minimal in a fresh project:

    fn ui_example(mut egui_context: ResMut<EguiContext>) {
        let gitlab_store = GitlabStore::fetch_updated();
        egui::Window::new("Event Counter")
            .resizable(true)
            .show(egui_context.ctx_mut(), |ui| {
                ui.label(format!("Builds: {}", gitlab_store.builds.len()));
                ui.label(format!("Deployments: {}", gitlab_store.deployments.len()));
                ui.label(format!("FeatureFlags: {}", gitlab_store.feature_flags.len()));
                ui.label(format!("Issues: {}", gitlab_store.issues.len()));
                ui.label(format!("MergeRequests: {}", gitlab_store.merge_requests.len()));
                ui.label(format!("Notes: {}", gitlab_store.notes.len()));
                ui.label(format!("Pipelines: {}", gitlab_store.pipelines.len()));
                ui.label(format!("Pushs: {}", gitlab_store.pushs.len()));
                ui.label(format!("Releases: {}", gitlab_store.releases.len()));
                ui.label(format!("WikiPages: {}", gitlab_store.wiki_pages.len()));
            });
    }
    

    The bevy version is "0.9" and bevy_egui is "0.17.1".

    The crash happened after letting the application run for a few minutes and leaving it unattended.

    opened by remissio 6
  • Clicks not recogniced on Android

    Clicks not recogniced on Android

    The following "on update system" works well on desktop. Unfortunately, on mobile I cannot get it working properly. It seems like clicks/taps are not recognized so even I create other elements such as sliders, dropdowns, ... and try to tap them, nothing happens.

    fn update_menu(mut egui_context: ResMut<EguiContext>) {
        egui::containers::Area::new("main_container").show(egui_context.ctx_mut(), |ui| {
        ui.button("click me");
    ...
    

    These are my dependencies

    [dependencies.bevy]
    version = "0.9.0"
    default-features = false
    features = [
      "render",
      "bevy_asset",
      "png",
      "x11"
    ]
    
    [dependencies.bevy_egui]
    version = "0.17.1"
    default-features = false
    features = [
      "default_fonts"
    ]
    

    As far as I have seen in https://github.com/rust-windowing/android-ndk-rs, egui should work on android so what am I missing here? (I'm using cargo apk to build the android package)

    opened by michaelrampl 3
  • Bug: clicked() is not working for ui:label()

    Bug: clicked() is not working for ui:label()

    Hi guys, the code snippet below is not working, what should I do to make it work?

    egui::Window::new("Hello").show(egui_context.ctx_mut(), |ui| {
        let response = ui.label("world");
        let response = response.interact(egui::Sense::click());
        if response.clicked() {
          println!("Click!");
        }
    });
    
    opened by Nickan 0
Releases(v0.18.0)
  • v0.18.0(Dec 11, 2022)

  • v0.17.1(Nov 13, 2022)

  • v0.17.0(Nov 13, 2022)

  • v0.16.1(Sep 18, 2022)

  • v0.16.0(Aug 24, 2022)

  • v0.15.1(Aug 13, 2022)

  • v0.15.0(Jul 30, 2022)

  • v0.14.0(May 1, 2022)

    Added

    • Add new_tab support for open_url (#96 by @Azorlogh).
      • EguiSettings has also got the default_open_url_target parameter to make the default behaviour on left mouse click configurable.
    • Update Egui to 0.18 (#99).

    Changed

    • The multi_threaded feature was renamed to immutable_ctx.

    Fixed

    • Improve wgsl readability and introduce minor optimisations (#95 by @lain-dono).
    • Remove duplicate EguiPipeline resource initialization (#98 by @lain-dono).
    • Fix color blending for user textures (#100).
    Source code(tar.gz)
    Source code(zip)
  • v0.13.0(Apr 16, 2022)

    Added

    • Upgrade Bevy to 0.7 (#79 by @aevyrie and @forbjok).

    Changed

    • Return egui::TextureId on removal (#81 by @Shatur).
    • Add must_use attributes to methods (#82).

    Fixed

    • Remove unnecessary image clone allocation (#84 by @frewsxcv).
    • Avoid allocations by utilizing HashMap::iter_mut (#83 by @frewsxcv).
    • Remove unnecessary swap texture clone (#85 by @frewsxcv).
    Source code(tar.gz)
    Source code(zip)
  • v0.12.1(Mar 13, 2022)

  • v0.12.0(Mar 12, 2022)

    Added

    • Upgrade Egui to 0.17 (#78 by @emilk).
    • Add side panel example (#73).

    Changed

    • User texture ids are now tracked internally (#71).
      • Instead of using set_egui_texture, you can now use add_image which returns a texture id itself (see the updated ui example).
    • Switch to arboard for managing clipboard (#72).

    Full Changelog: https://github.com/mvlabat/bevy_egui/compare/v0.11.0...v0.12.0

    Source code(tar.gz)
    Source code(zip)
  • v0.11.1(Feb 26, 2022)

    Hi everyone, my name is Vlad, I'm a maintainer of bevy_egui. I'm currently staying in Kyiv, Ukraine. Our country is being invaded by the Russian army, and our citizens are being killed. This night I was staying in a shelter, this same night 33 civilians in Kyiv were wounded (2 of them are children) and russians hit a civilian building with a rocket destroying 3 floors.

    I ask everyone to support the Ukrainian army if you can:

    That would mean a lot for us.

    Apologies for exploiting GitHub releases for this matter.

    Source code(tar.gz)
    Source code(zip)
Owner
Vladyslav Batyrenko
Rustacean, gamedev hobbyist, author of Grumpy Visitors. Love self-isolation on regular basis, psychedelic rock, and dogs (but have a 🐈)
Vladyslav Batyrenko
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Sélène Amanita 11 May 28, 2023
2d collision test for game-development in rust (with optional integration and example for bevy)

impacted 2d collision test for game-development in rust (with optional integration and example for bevy) This provides a low-level "narrow-phase" coll

Jonathan Cornaz 17 Nov 5, 2022
Integration layer between Bevy, puffin and tracing libraries

bevy_puffin This crate integrates the puffin library into Bevy. It provides PuffinTracePlugin to use as a replacement for the Bevy's default LogPlugin

Vladyslav Batyrenko 12 Jul 15, 2022
A real-time raytracing engine, with extra Bevy integration

strolle Strolle (from strålspårning) is a real-time raytracing engine written entirely in Rust, running on CPU & GPU: It comes integrated with Bevy, b

Patryk Wychowaniec 72 Jan 1, 2023
A Bevy plugin for loading the LDtk 2D tile map format.

bevy_ldtk ( Tileset from "Cavernas" by Adam Saltsman ) A Bevy plugin for loading LDtk tile maps. Usage use bevy::prelude::*; use bevy_ldtk::*; fn mai

Katharos Technology 23 Jul 4, 2022
Inspector plugin for the bevy game engine

bevy-inspector-egui This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a debug interface using egui where

Jakob Hellermann 517 Dec 31, 2022
Crossterm plugin for the bevy game engine

What is bevy_crossterm? bevy_crossterm is a Bevy plugin that uses crossterm as a renderer. It provides custom components and events which allow users

null 79 Nov 2, 2022
A Bevy plugin to use Kira for game audio

Bevy Kira audio This bevy plugin is intended to try integrating Kira into Bevy. The end goal would be to replace or update bevy_audio, if Kira turns o

Niklas Eicker 172 Jan 5, 2023
A prototype plugin providing a simple line drawing api for bevy.

bevy_debug_lines A prototype plugin providing a simple line drawing api for bevy. See docs.rs for documentation. Expect breakage on master. Click on t

Michael Palmos 92 Dec 31, 2022
Bevy plugin helping with asset loading and organisation

Bevy asset loader This Bevy plugin reduces boilerplate when loading game assets. The crate offers the AssetCollection trait and can automatically load

Niklas Eicker 205 Jan 2, 2023
A sprite-sheet animation plugin for bevy

Benimator A sprite sheet animation plugin for bevy Features A SpriteSheetAnimation component to automatically update the indices of the TextureAtlasSp

Jonathan Cornaz 140 Dec 27, 2022
A Bevy Engine plugin for making 2D paths, smooth animations with Bezier curves

bevy_pen_tool A Bevy Engine plugin for making 2D paths and smooth animations with Bezier curves TODO: Mesh-making functionality for building 2D shapes

Eli 36 Dec 22, 2022
A procedural sky plugin for bevy

bevy_atmosphere A procedural sky plugin for bevy Example use bevy::prelude::*; use bevy_atmosphere::*; fn main() { App::build() .insert_re

Jonah Henriksson 137 Dec 23, 2022
Generic cellular automaton plugin for bevy.

Bevy Cellular Automaton bevy_life is a generic plugin for cellular automaton. From the classic 2D Conway's game of life to WireWorld and 3D rules, the

Félix Lescaudey de Maneville 34 Nov 23, 2022
Verlet physics plugin for bevy.

bevy_verlet Simple Verlet points and sticks implementation for bevy. Features You can simply add a VerletPoint component on any entity with a Transfor

Félix Lescaudey de Maneville 34 Dec 9, 2022
Bevy plugin for an AssetServer that can load embedded resources, or use other AssetServers based on the path.

Bevy-Embasset Embed your asset folder inside your binary. bevy-embasset adds support for loading assets embedded into the binary. Furthermore, it can

Johnny Tidemand Vestergaard 9 Aug 4, 2022
Hanabi — a particle system plugin for the Bevy game engine.

Hanabi — a particle system plugin for the Bevy game engine

Jerome Humbert 256 Dec 30, 2022
A plugin to use the kajiya renderer with bevy

??️ ?? bevy-kajiya A plugin that enables use of the kajiya renderer in bevy WARNING: This plugin is barebones and supports a limited set of features.

Sebastian Hamel 79 Jan 5, 2023
Tweening animation plugin for the Bevy game engine.

?? Bevy Tweening Tweening animation plugin for the Bevy game engine. Features Animate any field of any component or asset, including custom ones. Run

Jerome Humbert 135 Dec 23, 2022