Coder Social home page Coder Social logo

ggez-egui's Introduction

latest version

ggez_egui

An egui implementation for the ggez game framework

basic project template

use ggez::{ContextBuilder, GameError, GameResult, event, graphics::{self, Color}};
use ggez_egui::EguiBackend;

fn main() -> GameResult {
	let (ctx, event_loop) = ContextBuilder::new("game_id", "author")
	.build()?;

	let my_game = MyGame::new();

	event::run(ctx, event_loop, my_game)
}

struct MyGame {
	egui_backend: EguiBackend
}

impl MyGame {
	fn new() -> Self {
		Self {
			egui_backend: EguiBackend::default()
		}
	}
}

impl event::EventHandler<GameError> for MyGame {
	fn update(&mut self, ctx: &mut ggez::Context) -> Result<(), GameError> {
		let egui_ctx = self.egui_backend.get_context();
		egui::Window::new("egui-window").show(&egui_ctx, |ui| {
			ui.label("a very nice gui :3");
			if ui.button("quit").clicked() {
				event::quit(ctx);
			}
		});
		Ok(())
	}

	fn draw(&mut self, ctx: &mut ggez::Context) -> Result<(), GameError> {
		graphics::clear(ctx, Color::BLACK);
		graphics::draw(ctx, &self.egui_backend, ([0.0, 0.0],))?;
		graphics::present(ctx)
	}

	fn mouse_button_down_event(&mut self, _ctx: &mut ggez::Context, button: event::MouseButton, _x: f32, _y: f32) {
		self.egui_backend.input.mouse_button_down_event(button);
	}

	fn mouse_button_up_event(&mut self, _ctx: &mut ggez::Context, button: event::MouseButton, _x: f32, _y: f32) {
		self.egui_backend.input.mouse_button_up_event(button);
	}

	fn mouse_motion_event(&mut self, _ctx: &mut ggez::Context, x: f32, y: f32, _dx: f32, _dy: f32) {
		self.egui_backend.input.mouse_motion_event(x, y);
	}
}

there are a couple of examples to know how to use this implementation.

ggez-egui's People

Contributors

nemuisen avatar pitcer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.