blue_engine_egui

Crates.ioblue_engine_egui
lib.rsblue_engine_egui
version0.5.2
sourcesrc
created_at2022-10-10 20:58:56.843759
updated_at2024-01-16 21:02:45.734758
descriptionegui library for Blue Engine
homepage
repositoryhttps://github.com/AryanpurTech/BlueEngineEGUI
max_upload_size
id684891
size98,754
Elham Aryanpur (ElhamAryanpur)

documentation

README

Blue Engine egui plugin

This is a plugin that adds egui support to the Blue Engine.

Getting started

To get started, initialize the plugin:

let gui_context = blue_engine_egui::EGUI::new(&engine.event_loop, &mut engine.renderer, &engine.window);

This will essentially initializes the egui and create things required to run the plugin. The engine will then run it twice, once before everything else to fetch all inputs and events, and then during render, so that it displays the GUI. And all that's left, is to add the plugin to the engine and use it:

engine.plugins.push(Box::new(gui_context));

During the update_loop, you can get the plugin back and use it. We'll assume only one plugin is added:

// -- update loop start
    // change the plugin_index from 0 to the index of the plugin when added
    let egui_plugin = let egui_plugin = plugins[0]
                // downcast it to obtain the plugin
                .downcast_mut::<blue_engine_egui::EGUI>()
                .expect("Plugin not found");
// -- rest of update loop code

Finally you can use it to add GUI code:

// -- rest of update loop code

// start the GUI addition
egui_plugin.ui(
    // get the context
    |ctx| {
        // create the window
        gui::Window::new("title").show(ctx, |ui| {
            // add components
            ui.horizontal(|ui| {
                ui.label("Hello World!");
            });
        });
    },
    &window,
);

// -- rest of update loop code

Congrats now you have a working GUI!

Style Block

The guide will come soon, it's cool I promise!

Examples

Check the examples folder for potential UIs and as template for your new projects.

Dependency justification

  • blue_engine: Used obiously for exporting some components and struct declrations required to design the API
  • egui-wgpu: Used to assist in applying egui to wgpu graphics backend. Which is same graphics backend used in Blue Engine.
  • egui-winit: Support for Winit windowing. Which is same windowing system used in Blue Engine.
  • egui: The egui itself, required to obtain components and declrations for api design.
Commit count: 20

cargo fmt