ImGui wrapper
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package imgui
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
cimgui "github.com/AllenDang/cimgui-go/imgui"
|
||||
)
|
||||
|
||||
// ImGui context & IO wrapper
|
||||
type Context struct {
|
||||
ctx *cimgui.Context
|
||||
io *cimgui.IO
|
||||
}
|
||||
|
||||
func New() *Context {
|
||||
ctx := cimgui.CreateContext()
|
||||
cimgui.SetCurrentContext(ctx)
|
||||
io := cimgui.CurrentIO()
|
||||
return &Context{ctx: ctx, io: io}
|
||||
}
|
||||
|
||||
func (c *Context) Destroy() {
|
||||
cimgui.DestroyContext()
|
||||
}
|
||||
|
||||
// Starts new ImGui frame
|
||||
// dt - time since last frame
|
||||
func (c *Context) BeginFrame(dt time.Duration, winW, winH int32) {
|
||||
c.io.SetDeltaTime(float32(dt.Seconds()))
|
||||
c.io.SetDisplaySize(cimgui.Vec2{X: float32(winW), Y: float32(winH)})
|
||||
cimgui.NewFrame()
|
||||
}
|
||||
|
||||
// Ends the frame, renders
|
||||
// and returns data for Vulkan
|
||||
func (c *Context) EndFrame() *cimgui.DrawData {
|
||||
cimgui.EndFrame()
|
||||
cimgui.Render()
|
||||
return cimgui.CurrentDrawData()
|
||||
}
|
||||
|
||||
// expose io to input backend
|
||||
func (c *Context) IO() *cimgui.IO { return c.io }
|
||||
Reference in New Issue
Block a user