Skip to content
/ ggegui Public
forked from NemuiSen/ggegui

A simple implementation of egui for ggez

Notifications You must be signed in to change notification settings

Vixeliz/ggegui

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crates.io docs.rs

ggegui

An egui implementation for the ggez game framework

Ultra minimal example

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)
	}
}

there are a few examples to know how to use this implementation.

About

A simple implementation of egui for ggez

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%