ImGui wrapper

This commit is contained in:
Dmitry Sergeev
2026-08-24 23:46:34 +03:00
parent 2b247d0fd6
commit 16692b693a
5 changed files with 287 additions and 0 deletions
+43
View File
@@ -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 }