Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nemuisen/ggegui
A simple implementation of egui for ggez
https://github.com/nemuisen/ggegui
egui ggez rust-lang
Last synced: about 2 months ago
JSON representation
A simple implementation of egui for ggez
- Host: GitHub
- URL: https://github.com/nemuisen/ggegui
- Owner: NemuiSen
- Created: 2021-07-27T18:23:28.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T01:21:39.000Z (9 months ago)
- Last Synced: 2024-05-16T04:15:43.307Z (7 months ago)
- Topics: egui, ggez, rust-lang
- Language: Rust
- Homepage:
- Size: 130 KB
- Stars: 51
- Watchers: 1
- Forks: 29
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
[![crates.io](https://img.shields.io/crates/v/ggegui)](https://crates.io/crates/ggegui)
[![docs.rs](https://img.shields.io/docsrs/ggegui)](https://docs.rs/ggegui/)
# ggegui
An [egui](https://github.com/emilk/egui/) implementation for the [ggez](https://ggez.rs/) game framework## Ultra minimal example
```rust
use ggegui::{egui, Gui};
use ggez::{
ContextBuilder, Context, GameResult, glam,
event::{ self, EventHandler},
graphics::{ self, DrawParam, Color }
};fn main() {
let (mut ctx, event_loop) = ContextBuilder::new("game_id", "author").build().unwrap();
let state = State::new(&mut ctx);
event::run(ctx, event_loop, state);
}struct State {
gui: Gui,
}impl State {
pub fn new(ctx: &mut Context) -> Self {
Self {
gui: Gui::new(ctx),
}
}
}impl EventHandler for State {
fn update(&mut self, ctx: &mut Context) -> GameResult {
let gui_ctx = self.gui.ctx();egui::Window::new("Title").show(&gui_ctx, |ui| {
ui.label("label");
if ui.button("button").clicked() {
println!("button clicked");
}
});
self.gui.update(ctx);
Ok(())
}fn draw(&mut self, ctx: &mut Context) -> GameResult {
let mut canvas = graphics::Canvas::from_frame(ctx, Color::BLACK);
canvas.draw(
&self.gui,
DrawParam::default().dest(glam::Vec2::ZERO),
);
canvas.finish(ctx)
}
}
```
> **__NOTE:__** due to how ggez is made currently there is no way to access the raw events emited by eventloop so instead to get the events using the functions and the context of EventHandler, as shown in the example of adove inside `EventHandler::update` is called `Gui::update` this function extract the information inside the context to send it to egui and draws everything. To make use of text input you must call `Input::text_input_event` inside of `EventHandler::text_input_event` like this `self.gui.input.text_input_event(character)`, this also applies to `Input::mouse_wheel_event` and `Input::resize_event`, you just call then inside of their respective functions exposed by `EventHandler`.there are a few [examples](./examples/) to show how to use this implementation.