Giter VIP home page Giter VIP logo

ggegui's Introduction

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 show how to use this implementation.

ggegui's People

Contributors

aleokdev avatar alimulap avatar alter-kaker avatar atomicbeef avatar bowarc avatar crumblingstatue avatar dallenng avatar dependabot[bot] avatar github-actions[bot] avatar ionutparau avatar ks0777 avatar m-r-hunt avatar nemuisen avatar originals1n avatar remiczn avatar starvingmarvin avatar tylian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ggegui's Issues

Focus/Cursor position is changing too fast

Steps to reproduce:

  • copy the minimal example from readme
  • add multiple buttons
  • run project
  • by pressing Tab key, change focus between buttons

or

  • copy the minimal example from readme
  • add singleline edit
  • run project
  • type some text into edit
  • press left or right arrow key

Is almost imposible to move focus to first button or move cursor one position to the left or right.

ComboBox's selectable_value cannot be selected using left click

Hey, im sorry to bother you but i found more bugs X)

I'll still take example/basic_template as a base

Replace the State declaration and impl with :

struct State {
	gui: Gui,
	fst: ggez::conf::FullscreenType,
}

impl State {
	pub fn new(ctx: &mut Context) -> Self {
		let mut gui = Gui::new(ctx);
		gui.input.set_scale_factor(2_f32, ctx.gfx.size());

		Self {
			gui,
			fst: ggez::conf::FullscreenType::Windowed,
		}
	}
}

it's just to keep track of a value after the update function is done and to set the scale factor to see text a bit better (not required)

replace the ggez::event::EventHandler::update function with:

fn update(&mut self, ctx: &mut Context) -> GameResult {
    let gui_ctx = self.gui.ctx();

    const WINDOW_SIZE: (f32, f32) = (300., 130.);

    egui::Window::new("UI")
        .fixed_size(WINDOW_SIZE)
        .show(&gui_ctx, |ui| {
            egui::ComboBox::from_label(
                "Fullcreen type (you need to right click to select for some unknown reason)",
            )
            .selected_text(format!("{:?}", self.fst))
            .show_ui(ui, |ui| {
                for screen_type in [
                    ggez::conf::FullscreenType::Windowed,
                    ggez::conf::FullscreenType::True,
                    ggez::conf::FullscreenType::Desktop,
                ] {
                    ui.selectable_value(&mut self.fst, screen_type, format!("{screen_type:?}"));
                }
            });
        });
    self.gui.update(ctx);
    Ok(())
}

and you can only select the True or Desktop option by right clicking (left clicking only closes the ComboBox)

Delta pos

Hey! Thanks for the awesome work on this. Lately i've been maintaining/working my own fork of this I just added partial updates and am working on fixing some key repeat issues i may make a pr eventually but if i don't get around to it figured i could at least mention it here so you or somebody else could possibly take what i've done and transfer it to this repo.
https://github.com/Vixeliz/ggegui

Semi-automatic dependency update with dependabot

Hello, would you like a PR that setup dependabot for your repo ?
I also notice that you don't build the code in CI, I could add that as well if you want ?

Context

Dependabot is a tool provided by Github to automatically create PR with dependency update. It can update Rust and Github Actions dependencies. That way you will be notified when an update is available.

Dependabot can run daily, weekly or monthly. I think weekly is great for this project to keep up with ggez and egui without running it too frequently.

What do you think ?

Scale seems to not be working

Hey, it's me again !
I think i found another bug (or i didn't understood something)

Settings the scale with gui.input.set_scale_factor(5.5, ctx.gfx.size());
(I used the example/basic_template.rs and modified only the following: )

struct State {
	gui: Gui,
}

impl State {
	pub fn new(ctx: &mut Context) -> Self {
		let mut gui = Gui::new(ctx);
		gui.input.set_scale_factor(5.5, ctx.gfx.size());
		Self { gui }
	}
}

seems to have no effect on the size of the egui window

Am i missunderstanding something ?

clic / drag event is based on frames not time.

Hey, im making a game with ggez and i wanted to add a gui crate to make some ui.

but i found a weird bug where when i don't limit my game's fps the egui's button clics are not register'd correctly.
I played a bit with it and i found that when i limit my fps, clics are register'd correctly.

I think the timing window where clics are not held enough to be drag event is based on number of frames between press and release.
that leaves a bug where high fps makes the clic event timing window so short that it's not user friendly

is there a way to fix this without re-writing the egui's code ?

Update to new egui release

Hi, thanks so much for creating this helpful binding. Would you please update the crate to work with the recent egui 0.15.0 release? I'd really appreciate that.

Regards,

Share between threads safely

Hello,

I would like to integrate egui to my ggez game. But, some computing in my game are done in threads, and compilation errors happens when I try to integrate ggez-egui :

error[E0277]: `Rc<RefCell<std::string::String>>` cannot be shared between threads safely
   --> src/engine/soldier.rs:43:27
    |
43  |                 .flat_map(|i| self.decrease_feeling(SoldierIndex(i)))
    |                  -------- ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                  |        |
    |                  |        `Rc<RefCell<std::string::String>>` cannot be shared between threads safely
    |                  |        within this `[closure@src/engine/soldier.rs:43:27: 43:30]`
    |                  required by a bound introduced by this call
    |
    = help: within `[closure@src/engine/soldier.rs:43:27: 43:30]`, the trait `Sync` is not implemented for `Rc<RefCell<std::string::String>>`
    = note: required because it appears within the type `Input`
    = note: required because it appears within the type `EguiBackend`
note: required because it appears within the type `Engine`
   --> src/engine/mod.rs:41:12
    |
41  | pub struct Engine {
    |            ^^^^^^
    = note: required because it appears within the type `&Engine`
note: required because it's used within this closure
   --> src/engine/soldier.rs:43:27
    |
43  |                 .flat_map(|i| self.decrease_feeling(SoldierIndex(i)))
    |                           ^^^
note: required by a bound in `rayon::iter::ParallelIterator::flat_map`
   --> /home/bastiensevajol/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-1.6.1/src/iter/mod.rs:850:35
    |
850 |         F: Fn(Self::Item) -> PI + Sync + Send,
    |                                   ^^^^ required by this bound in `rayon::iter::ParallelIterator::flat_map`

Examples don't render

I'm not really sure why but the examples as given don't actually render anything on my screen.

When I run $ cargo run --example basic_template after a fresh clone of the repository all I see is a black screen:

image

This happens even with the other example.

Some environment information if it helps:

  • Windows 11 21H2
  • stable-x86_64-pc-windows-msvc toolchain
  • rustc 1.69.0 (84c898d65 2023-04-16)
  • ggez v0.8.1
  • egui v0.20.1

Note that checking out the commit at 36b3ed1 works but 9ba2d93 does not, which leads me to believe that something about the update path breaks it for me. I'm unsure how to debug this further, sorry.

Right clicking a button spams it rly fast

I'll still take example/basic_template as a base

Replace the ggez::event::EventHandler::update with:

fn update(&mut self, ctx: &mut Context) -> GameResult {
    let gui_ctx = self.gui.ctx();

    const WINDOW_SIZE: (f32, f32) = (300., 130.);

    egui::Window::new("UI")
        .fixed_size(WINDOW_SIZE)
        .show(&gui_ctx, |ui| {
            if ui.button("Click me").clicked() {
                println!("Hello world");
            }
        });
    self.gui.update(ctx);
    Ok(())
}}

sorry again for spamming issues haha im trying to learn this cool crate, so i test a lot of things

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.