Crate egui_backend

source ·
Expand description

egui_backend crate primarily provides traits to abstract away Window and Rendering parts of egui backends. this allows us to use any window backend with any gfx backend crate.

egui is an immediate mode gui library. The lifecycle of egui in every frame goes like this:

  1. takes input from the window backend. eg: mouse position, keyboard events, resize..
  2. constructs gui objects like windows / panels / buttons etc.. and deals with any input interactions.
  3. outputs those gui objects as gpu friendly data to be drawn by a gfx backend.

So, we need a WindowBackend to provide input to egui and a GfxBackend to draw egui’s output. egui already provides an official backends for wgpu, winit and glow, along with a higher level wrapper crate called eframe eframe uses winit on desktop, custom backend on web and wgpu/glow for rendering. If that serves your usecase, then it is recommended to keep using that.

egui_backend crate instead tries to enable separation of window + gfx concerns using traits.

this crate provides 3 traits:

  1. WindowBackend: implemented by window backends like winit, glfw, sdl2 etc..
  2. GfxBackend: implemented by rendering backends like wgpu, glow, three-d,
  3. UserApp: implemented by end user’s struct which holds the app data as well as egui context and the renderer.

This crate will also try to provide functions or structs which are useful across all backends.

  1. BackendConfig: has some configuration which needs to be provided at startup.

look at the docs of the relevant trait to learn more.

Re-exports

Modules

  • Some nice util functions commonly used by egui backends.

Structs

  • Intended to provide a common struct which all window backends accept as their configuration. To set size/position/title etc.. just use the windowbackend trait functions after you created the window. This struct is primarily intended for settings which are to be specified before creating a window like opengl or transparency etc..

Traits

  • Trait for Gfx backends. these could be Gfx APIs like opengl or vulkan or wgpu etc.. or higher level renderers like three-d or rend3 or custom renderers etc..
  • This is the trait most users care about. Just have a struct with WindowBackend, GfxBackend and egui context as fields. and implmenet the get_all and gui_run fn for a simple app. or you can overload the run fn for more advanced stuff like filtering input events etc..
  • Implement this trait for your windowing backend. the main responsibility of a Windowing Backend is to