Code Monkey home page Code Monkey logo

ebiten-imgui's Introduction

Dear ImGui for Ebitengine

A renderer of cimgui-go for Ebitengine!

preview

Usage:

package main

import (
	"fmt"
	"image/color"

	"github.com/gabstv/ebiten-imgui/v3/imcolor"
	ebimgui "github.com/gabstv/ebiten-imgui/v3"
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
	imgui "github.com/gabstv/cimgui-go"
)

func main() {
	gg := &G{
		name:       "Hello, Dear ImGui",
		clearColor: [3]float32{0,0,0},
	}

	ebiten.SetWindowSize(800, 600)
	ebiten.SetWindowTitle(gg.name)

	ebiten.RunGame(gg)
}

type G struct {
	clearColor [3]float32
	floatVal   float32
	counter    int
	name       string
}

func (g *G) Draw(screen *ebiten.Image) {
	screen.Fill(color.RGBA{uint8(g.clearColor[0] * 255), uint8(g.clearColor[1] * 255), uint8(g.clearColor[2] * 255), 255})
	ebitenutil.DebugPrint(screen, fmt.Sprintf("TPS: %.2f", ebiten.CurrentTPS()))
	ebimgui.Draw(screen)
}

func InputText(label string, buf *string) bool {
	return imgui.InputTextWithHint(label, "", buf, 0, nil)
}

func (g *G) Update() error {
	ebimgui.Update(1.0 / 60.0)
	ebimgui.BeginFrame()
	defer ebimgui.EndFrame()

	imgui.Text("ภาษาไทย测试조선말")                        // To display these, you'll need to register a compatible font
	imgui.Text("Hello, world!")                       // Display some text
	imgui.SliderFloat("float", &g.floatVal, 0.0, 1.0) // Edit 1 float using a slider from 0.0f to 1.0f
	imgui.ColorEdit3("clear color", &g.clearColor)     // Edit 3 floats representing a color

	//imgui.Checkbox("Demo Window", &showDemoWindow) // Edit bools storing our window open/close state
	//imgui.Checkbox("Go Demo Window", &showGoDemoWindow)
	//imgui.Checkbox("Another Window", &showAnotherWindow)

	if imgui.Button("Button") { // Buttons return true when clicked (most widgets return true when edited/activated)
		g.counter++
	}
	imgui.SameLine()
	imgui.Text(fmt.Sprintf("counter = %d", g.counter))

	if InputText("Window title", &g.name) {
		ebiten.SetWindowTitle(g.name)
	}

	xcol := imcolor.ToVec4(color.RGBA{
		R: 0xFF,
		G: 0x00,
		B: 0xFF,
		A: 0x99,
	})

	imgui.PushStyleColor_Vec4(imgui.ImGuiCol_Text, xcol)
	imgui.Text(fmt.Sprintf("fps = %f", ebiten.CurrentFPS()))
	imgui.PopStyleColor()
	return nil
}

func (g *G) Layout(outsideWidth, outsideHeight int) (int, int) {
	ebimgui.SetDisplaySize(float32(800), float32(600))
	return 800, 600
}

ebiten-imgui's People

Contributors

csmith avatar divverent avatar eliasdaler avatar gabstv avatar magnuswahlstrand 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  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  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ebiten-imgui's Issues

Docking support?

Hi there,

With the recent updates to the latest cimgui-go, I was attempting to try out the newer docking features. Unfortunately it seems that the current state of cimgui-go relies on having a handle to the main window in order to set docking flags? I'm not entirely sure. I came across this example which I was unable to get working under this repository. Any ideas on how to make it work? AllenDang/cimgui-go#101

Need some example

imgui.Text("ภาษาไทย测试조선말") // To display these, you'll need to register a compatible font

Can you provide an example? thx

支持非英语

go调用 非英语字符串 的其它语言全部不能正常显示 这个应该怎么解决呢

ClipMask how to use?

Hello, I want to paste content in the input box. How should I use this ClipMask? Do you have any ideas?

New version of cimgui is available

Hi there, I was curious if we could get this merged with the upstream repo? The following resolves an issue that is currently causing panic when building font ranges, an issue that I have also been dealing with.

AllenDang/cimgui-go#241

thanks for your consideration!

An example should show how to change the default title "Debug"

After crawling through all the examples and source code for this project and the imgui-go project I finally stumbled upon the secret sauce to get the window to have the text "Menu" instead of "Debug". Can you please consider adding this to one of your examples?

g.mgr.BeginFrame()
imgui.Begin("Menu") // changes menu title from default "Debug"
{
    imgui.Text("Hello, world!")
}
imgui.End()
g.mgr.EndFrame()

imgui.Image() example

Hey, thanks for making this library, it's been extremely useful for me! Just wondering if you had any examples for using imgui.Image with ebiten?

imgui-go is getting discontinued/deprecated

Hello.
See inkyblackness/imgui-go#192

This is pretty important, because imgui-go will stop getting updates. I've already ported ebiten-imgui to cimgui-go, see this branch of my fork. Most of the work is done, however cimgui-go doesn't have some stuff exposed here and there - I'll work on that.

I can make a PR, but some discussion is needed. Obviously, this is a big breaking change, so ebiten-imgui probably will need to go to v2. If this is the case, maybe it might be the time to rethink some of API decisions if we're breaking it anyway.

Any thoughts on this?

P.S. I now see that readme still says that "API might change", so maybe there's no need for v2.

Fatal panic in imgui code when SetDisplaySize not set

If you don't set display size properly, it throws a fatal panic in the imgui code that doesn't really explain much. There needs to be some check to make sure it's initialized correctly, and an error thrown if it's not.

Drawing when TPS and FPS are not in sync / have different rates

Hello
I think that some restructuring of the code/API is needed to make ebiten-imgui support different TPS/FPS rates.

In usual Dear ImGui setup, you call Begin/EndFrame and widget creation functions in "Update", not "Draw". Actual drawing should be just just done in "Draw" function.

So, I think it's the usage should be like this:

func (g *Game) Update() {
    g.mgr.BeginFrame()
    // put stuff like imgui.Button etc. here
    g.mgr.EndFrame() 
}

func (g *Game) Draw(screen *ebiten.Image) {
    g.mgr.Draw(screen) // new function - doesn't call "EndFrame" for us
}

This is much better and allows to have 60 TPS (update calls per second) and 60+ FPS (Draw calls per second) - we just need to render the old frame if Draw has been called more than once for 1 update call. Note that we can call imgui.Render once - it doesn't break anything.

Thoughts? If you agree with this, I can make a PR which implements the changes, though it'll break the API.

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.