From 4ca9f4d87d0186f308c094503c01ed1b8ade6b0f Mon Sep 17 00:00:00 2001 From: gucio321 Date: Tue, 3 Dec 2024 17:03:12 +0100 Subject: [PATCH 1/3] Clickable widget: push auto ids I've just noticed that 2 ImageButton's with the same texture are conflicting items for imgui. Now ImageButton auto-generates and ID and adds ID method if someone wants to set the ID manually --- ClickableWidgets.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ClickableWidgets.go b/ClickableWidgets.go index 9c992db0..0538feb7 100644 --- a/ClickableWidgets.go +++ b/ClickableWidgets.go @@ -206,6 +206,7 @@ type ImageButtonWidget struct { bgColor color.Color tintColor color.Color onClick func() + id ID } // ImageButton constructs image button widget. @@ -220,15 +221,22 @@ func ImageButton(texture *Texture) *ImageButtonWidget { bgColor: colornames.Black, tintColor: colornames.White, onClick: nil, + id: GenAutoID("ImageButton"), } } +func (b *ImageButtonWidget) ID(id ID) *ImageButtonWidget { + b.id = id + return b +} + // Build implements Widget interface. func (b *ImageButtonWidget) Build() { if b.texture == nil || b.texture.tex == nil { return } + imgui.PushIDStr(b.id.String()) if imgui.ImageButtonV( fmt.Sprintf("%v", b.texture.tex.ID), b.texture.tex.ID, @@ -239,6 +247,8 @@ func (b *ImageButtonWidget) Build() { ) && b.onClick != nil { b.onClick() } + + imgui.PopID() } // Size sets BUTTONS size. From f1d83dddc216663ea79b48755b1d83318ccf8ae9 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Tue, 3 Dec 2024 17:04:58 +0100 Subject: [PATCH 2/3] linting --- ClickableWidgets.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ClickableWidgets.go b/ClickableWidgets.go index 0538feb7..e6e6704d 100644 --- a/ClickableWidgets.go +++ b/ClickableWidgets.go @@ -225,6 +225,7 @@ func ImageButton(texture *Texture) *ImageButtonWidget { } } +// ID allows to manually set widget's id. func (b *ImageButtonWidget) ID(id ID) *ImageButtonWidget { b.id = id return b From 6b92c1a4a5b45e924bcf4cfd65d55b2a4ed113cb Mon Sep 17 00:00:00 2001 From: gucio321 Date: Tue, 3 Dec 2024 17:06:53 +0100 Subject: [PATCH 3/3] linting --- ClickableWidgets.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ClickableWidgets.go b/ClickableWidgets.go index e6e6704d..d7c33bdc 100644 --- a/ClickableWidgets.go +++ b/ClickableWidgets.go @@ -238,6 +238,7 @@ func (b *ImageButtonWidget) Build() { } imgui.PushIDStr(b.id.String()) + if imgui.ImageButtonV( fmt.Sprintf("%v", b.texture.tex.ID), b.texture.tex.ID,