1 个不稳定发布

0.1.0 2022年8月10日

#221 in #egui

MIT 协议

1KB

项目已放弃

最近我对即时模式GUI并不感兴趣,所以我将不得不停止在这个项目上投入时间。如果你想要,可以将其分叉。

checkmate

Egui Toolkit

egui的依赖库

Egui是一个小的UI库,你可以将其嵌入到你的App中。它需要App提供鼠标/键盘等输入。一旦它处理了输入,egui就会提供你需要在显示上绘制的所需数据。

egui_backend是一个库,它将输入需求抽象为一个WindowBackend特质,并将输出绘制内容作为GfxBackend。这允许你为winit、glfw、wgpu、vulkan等特定库实现这些特质。任何用户都可以轻松地重用这些后端。

大多数App开发者只需要关注实现UserApp特质,并选择他们想要使用的后端。如果你不使用高级功能,那么你可以用几行代码就可以交换后端。

// 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,
        &egui::Context,
    ) {
        (
            &mut self.glfw_backend,
            &mut self.glow_backend,
            &self.egui_context,
        )
    }
    // 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(),
    glow_backend,
    glfw_backend,
    };
    // 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);
}

无运行时依赖