ggez-egui

Crates.ioggez-egui
lib.rsggez-egui
version0.3.1
sourcesrc
created_at2021-07-27 18:50:59.020597
updated_at2022-12-20 04:09:52.915039
descriptionA simple implementation of egui for ggez
homepage
repositoryhttps://github.com/NemuiSen/ggez-egui
max_upload_size
id428061
size97,396
Neloj (NemuiSen)

documentation

README

latest version

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.

Commit count: 82

cargo fmt