From 4ca9f4d87d0186f308c094503c01ed1b8ade6b0f Mon Sep 17 00:00:00 2001 From: gucio321 Date: Tue, 3 Dec 2024 17:03:12 +0100 Subject: [PATCH] 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.