10 releases
0.3.1 | Dec 20, 2022 |
---|---|
0.2.1 | May 29, 2022 |
0.1.7 | Mar 2, 2022 |
0.1.6 | Feb 18, 2022 |
0.1.0 | Jul 27, 2021 |
#1353 in Game dev
46 downloads per month
26KB
340 lines
ggez_egui
An egui implementation for the ggez game framework
First steps
To make use of this implementation you must first add the "EguiBackend" inside your game structure and initialize it. Ej:
struct MyGame {
egui_backend: EguiBackend,
...
}
...
let game = MyGame {
egui_backend: EguiBackend::default(), //or EguiBackend::new(ctx)
...
}
later, in the part of the "EventHandler", inside the "update" we will add the structure and logic of the ui, inside the "draw" we will send to draw the ui, and at the end we will detect the user input. Ej:
impl EventHandler<GameResult> for MyGame {
fn update(&mut self, ctx: &mut Context) -> GameResult {
let egui_ctx = self.egui_backend.ctx();
egui::Window::new("egui-window").show(&egui_ctx, |ui| {
ui.label("a very nice gui :3");
if ui.button("print \"hello world\"").clicked() {
println!("hello world");
}
if ui.button("quit").clicked() {
quit(ctx);
}
});
self.egui_backend.update(ctx); // Update the input with the data from the context with exceptions (scale_factor, resize, mouse_wheel, and text_input)
Ok(())
}
fn draw(&mut self, ctx: &mut Context) -> GameResult {
clear(ctx, Color::BLACK);
draw(ctx, &self.egui_backend, ([0.0, 0.0],))?;
present(ctx)
}
}
In this case we only handle the mouse input so we only use those three functions (mouse_button_down_event, mouse_button_up_event, mouse_motion_event), it is not very necessary to explain them because their names are already very descriptive. If we need to manage other things in the window such as the keyboard, the size, or even the scale factor, there are also respective functions for that, check out the Input Documentation.
there are a few examples to know how to use this implementation.
Dependencies
~28–44MB
~599K SLoC