From b0999aecf7fc218ad48b6f5d23c1803e98081418 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Fri, 22 Mar 2024 14:13:53 +0100 Subject: [PATCH] update cimgui-go version --- Canvas.go | 4 ++-- ClickableWidgets.go | 4 ++-- Events.go | 8 ++++---- Flags.go | 3 --- ImageWidgets.go | 2 +- MasterWindow.go | 6 +++++- Plot.go | 5 +++-- Texture.go | 2 +- Widgets.go | 8 +++++++- go.mod | 2 +- go.sum | 4 ++-- 11 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Canvas.go b/Canvas.go index 30322f7c..92b7442f 100644 --- a/Canvas.go +++ b/Canvas.go @@ -158,9 +158,9 @@ func (c *Canvas) AddImage(texture *Texture, pMin, pMax image.Point) { } func (c *Canvas) AddImageQuad(texture *Texture, p1, p2, p3, p4, uv1, uv2, uv3, uv4 image.Point, col color.Color) { - c.DrawList.AddImageQuadV(texture.tex.ID(), ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec2(uv1), ToVec2(uv2), ToVec2(uv3), ToVec2(uv4), ColorToUint(col)) + c.DrawList.AddImageQuadV(texture.tex.ID, ToVec2(p1), ToVec2(p2), ToVec2(p3), ToVec2(p4), ToVec2(uv1), ToVec2(uv2), ToVec2(uv3), ToVec2(uv4), ColorToUint(col)) } func (c *Canvas) AddImageV(texture *Texture, pMin, pMax, uvMin, uvMax image.Point, col color.Color) { - c.DrawList.AddImageV(texture.tex.ID(), ToVec2(pMin), ToVec2(pMax), ToVec2(uvMin), ToVec2(uvMax), ColorToUint(col)) + c.DrawList.AddImageV(texture.tex.ID, ToVec2(pMin), ToVec2(pMax), ToVec2(uvMin), ToVec2(uvMax), ColorToUint(col)) } diff --git a/ClickableWidgets.go b/ClickableWidgets.go index a9805965..287c2837 100644 --- a/ClickableWidgets.go +++ b/ClickableWidgets.go @@ -229,8 +229,8 @@ func (b *ImageButtonWidget) Build() { } if imgui.ImageButtonV( - fmt.Sprintf("%v", b.texture.tex.ID()), - b.texture.tex.ID(), + fmt.Sprintf("%v", b.texture.tex.ID), + b.texture.tex.ID, imgui.Vec2{X: b.width, Y: b.height}, ToVec2(b.uv0), ToVec2(b.uv1), ToVec4Color(b.bgColor), diff --git a/Events.go b/Events.go index 764ca782..a108f86d 100644 --- a/Events.go +++ b/Events.go @@ -30,7 +30,7 @@ func IsItemActive() bool { // IsKeyDown returns true if key `key` is down. func IsKeyDown(key Key) bool { - return imgui.IsKeyDownNil(imgui.Key(key)) + return imgui.IsKeyDown(imgui.Key(key)) } // IsKeyPressed returns true if key `key` is pressed. @@ -40,12 +40,12 @@ func IsKeyPressed(key Key) bool { // IsKeyReleased returns true if key `key` is released. func IsKeyReleased(key Key) bool { - return imgui.IsKeyReleasedNil(imgui.Key(key)) + return imgui.IsKeyReleased(imgui.Key(key)) } // IsMouseDown returns true if mouse button `button` is down. func IsMouseDown(button MouseButton) bool { - return imgui.IsMouseDownNil(imgui.MouseButton(button)) + return imgui.IsMouseDown(imgui.MouseButton(button)) } // IsMouseClicked returns true if mouse button `button` is clicked @@ -56,7 +56,7 @@ func IsMouseClicked(button MouseButton) bool { // IsMouseReleased returns true if mouse button `button` is released. func IsMouseReleased(button MouseButton) bool { - return imgui.IsMouseReleasedNil(imgui.MouseButton(button)) + return imgui.IsMouseReleased(imgui.MouseButton(button)) } // IsMouseDoubleClicked returns true if mouse button `button` is double clicked. diff --git a/Flags.go b/Flags.go index ad1b469b..c372b3e0 100644 --- a/Flags.go +++ b/Flags.go @@ -94,9 +94,6 @@ const ( WindowFlagsAlwaysVerticalScrollbar WindowFlags = WindowFlags(imgui.WindowFlagsAlwaysVerticalScrollbar) // WindowFlagsAlwaysHorizontalScrollbar always shows horizontal scrollbar, even if ContentSize.x < Size.x . WindowFlagsAlwaysHorizontalScrollbar WindowFlags = WindowFlags(imgui.WindowFlagsAlwaysHorizontalScrollbar) - // WindowFlagsAlwaysUseWindowPadding ensures child windows without border uses style.WindowPadding (ignored by - // default for non-bordered child windows, because more convenient). - WindowFlagsAlwaysUseWindowPadding WindowFlags = WindowFlags(imgui.WindowFlagsAlwaysUseWindowPadding) // WindowFlagsNoNavInputs has no gamepad/keyboard navigation within the window. WindowFlagsNoNavInputs WindowFlags = WindowFlags(imgui.WindowFlagsNoNavInputs) // WindowFlagsNoNavFocus has no focusing toward this window with gamepad/keyboard navigation diff --git a/ImageWidgets.go b/ImageWidgets.go index d0086ad0..99c424f0 100644 --- a/ImageWidgets.go +++ b/ImageWidgets.go @@ -101,7 +101,7 @@ func (i *ImageWidget) Build() { } } - imgui.ImageV(i.texture.tex.ID(), size, i.uv0, i.uv1, ToVec4Color(i.tintColor), ToVec4Color(i.borderColor)) + imgui.ImageV(i.texture.tex.ID, size, i.uv0, i.uv1, ToVec4Color(i.tintColor), ToVec4Color(i.borderColor)) } type imageState struct { diff --git a/MasterWindow.go b/MasterWindow.go index d9ec044b..352b5615 100644 --- a/MasterWindow.go +++ b/MasterWindow.go @@ -1,6 +1,7 @@ package giu import ( + "errors" "image" "image/color" "runtime" @@ -85,7 +86,10 @@ func NewMasterWindow(title string, width, height int, flags MasterWindowFlags) * // Disable imgui.ini io.SetIniFilename("") - backend := imgui.CreateBackend(imgui.NewGLFWBackend()) + backend, err := imgui.CreateBackend(imgui.NewGLFWBackend()) + if err != nil && !errors.Is(err, imgui.CExposerError) { + panic(err) + } // Create GIU context Context = CreateContext(backend) diff --git a/Plot.go b/Plot.go index b7b26398..1483bc20 100644 --- a/Plot.go +++ b/Plot.go @@ -1,8 +1,9 @@ package giu import ( - imgui "github.com/AllenDang/cimgui-go" "image" + + imgui "github.com/AllenDang/cimgui-go" ) // PlotWidget is implemented by all the particular plots, which can be used @@ -493,7 +494,7 @@ func (p *PieChartPlot) Angle0(a float64) *PieChartPlot { func (p *PieChartPlot) Plot() { // TODO: p.normalized not used anymore - replace with flags - imgui.PlotPlotPieChartdoublePtrV( + imgui.PlotPlotPieChartdoublePtrStrV( Context.FontAtlas.RegisterStringSlice(p.labels), &p.values, int32(len(p.values)), diff --git a/Texture.go b/Texture.go index 7f4c5371..a98913b3 100644 --- a/Texture.go +++ b/Texture.go @@ -40,7 +40,7 @@ func ToTexture(texture *imgui.Texture) *Texture { func (t *Texture) ID() imgui.TextureID { if t.tex != nil { - return t.tex.ID() + return t.tex.ID } return imgui.TextureID{} diff --git a/Widgets.go b/Widgets.go index 81fe4055..d9126fc4 100644 --- a/Widgets.go +++ b/Widgets.go @@ -72,7 +72,13 @@ type ChildWidget struct { // Build implements Widget interface. func (c *ChildWidget) Build() { - if imgui.BeginChildStrV(c.id, imgui.Vec2{X: c.width, Y: c.height}, c.border, imgui.WindowFlags(c.flags)) { + if imgui.BeginChildStrV(c.id, imgui.Vec2{X: c.width, Y: c.height}, func() imgui.ChildFlags { + if c.border { + return imgui.ChildFlagsBorder + } + + return 0 + }(), imgui.WindowFlags(c.flags)) { c.layout.Build() } diff --git a/go.mod b/go.mod index d1488fe6..ef994119 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/AllenDang/giu go 1.21 require ( - github.com/AllenDang/cimgui-go v0.0.0-20240217115856-389161c9afbe + github.com/AllenDang/cimgui-go v0.0.0-20240321080015-b8f29f999b6d github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 github.com/mazznoer/csscolorparser v0.1.3 diff --git a/go.sum b/go.sum index f07c2d12..d68920be 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/AllenDang/cimgui-go v0.0.0-20240217115856-389161c9afbe h1:hCgPHyxsipQgkSIDoDkFS6/axFK2tDqXgRySwqdYvZc= -github.com/AllenDang/cimgui-go v0.0.0-20240217115856-389161c9afbe/go.mod h1:e6feXR4FrATVY/UrWS3si3KCJOm0wruwbxVI/B85fUM= +github.com/AllenDang/cimgui-go v0.0.0-20240321080015-b8f29f999b6d h1:AUfBQnUrFx3HutYvsJq/NPYjz7wnoY91zRO/AOW8/m8= +github.com/AllenDang/cimgui-go v0.0.0-20240321080015-b8f29f999b6d/go.mod h1:e6feXR4FrATVY/UrWS3si3KCJOm0wruwbxVI/B85fUM= github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 h1:dKZMqib/yUDoCFigmz2agG8geZ/e3iRq304/KJXqKyw= github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8/go.mod h1:b4uuDd0s6KRIPa84cEEchdQ9ICh7K0OryZHbSzMca9k= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=