2 unstable releases

0.2.0 Sep 8, 2022
0.1.0 Aug 25, 2022

#9 in #glfw-window

43 downloads per month

MIT license

542 lines

Project Abandoned

I am not really into immediate mode guis these days, so i will have to stop putting my time into this project. Fork it if you want.


Egui Toolkit

Supporting crates for egui

Egui is a small ui library that you embed into your App. And it requires the App to provide input like mouse/keyboard. Once it processes the input, egui will provide you with a bunch of data which you need to draw on the display.

egui_backend is a crate that abstracts away the input requirements as a WindowBackend trait and output drawing stuff as GfxBackend. This allows you to implement these traits for specific libraries like winit, glfw, wgpu, vulkan etc.. And any user can easily reuse these backends.

Most App devs only need to take care of implementing the UserApp trait and choose the backends they want to use. If you don't use advanced stuff, then you can just swap the backends with barely a couple lines of code.

// This is the user struct where we can store any data we want along with the window and gfx backends.
pub struct App {
    pub frame_count: usize,
    pub egui_context: egui::Context,
    pub glow_backend: GlowBackend,
    pub glfw_backend: GlfwBackend,
// we need to implement this trait for our struct
impl UserApp for App {
    // we can make it generic, but didn't want to complicate the example.
    type UserGfxBackend = GlowBackend;
    type UserWindowBackend = GlfwBackend;
    // The function which is used by some default fn impl of this trait
    // allows us access to window/gfx backends mutably at the same time
    fn get_all(
        &mut self,
    ) -> (
        &mut Self::UserWindowBackend,
        &mut Self::UserGfxBackend,
    ) {
            &mut self.glfw_backend,
            &mut self.glow_backend,
    // here, you put your gui code, which will be run every frame.
    fn gui_run(&mut self) {
        let egui_context = self.egui_context.clone();
        egui::Window::new("egui window").show(&egui_context, |ui| {
            ui.label(format!("frame number: {}", self.frame_count));

pub fn fake_main() {
    // create window backend with default config. here you can set initial flags like transparency or selecting opengl vs vulkan etc..
    let mut glfw_backend = GlfwBackend::new(Default::default(), BackendConfig::default());
    // creating gfx backend. It uses Window backend to load things like fn pointers or window handle for swapchain etc.. behind the scenes.
    let glow_backend = GlowBackend::new(&mut glfw_backend, Default::default());
    // initialize app state
    let app = App {
    frame_count: 0,
    egui_context: Default::default(),
    // enter event loop. Now, the `gui_run` method from trait impl will be called every frame. read docs for more info
    <App as UserApp>::UserWindowBackend::run_event_loop(app);


~120K SLoC