Skip to content

Commit

Permalink
Clickable widget: push auto ids
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gucio321 committed Dec 3, 2024
1 parent 4536adc commit 4ca9f4d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ClickableWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ type ImageButtonWidget struct {
bgColor color.Color
tintColor color.Color
onClick func()
id ID
}

// ImageButton constructs image button widget.
Expand All @@ -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 {

Check failure on line 228 in ClickableWidgets.go

View workflow job for this annotation

GitHub Actions / Lint

exported: exported method ImageButtonWidget.ID should have comment or be unexported (revive)
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(

Check failure on line 240 in ClickableWidgets.go

View workflow job for this annotation

GitHub Actions / Lint

if statements should only be cuddled with assignments (wsl)
fmt.Sprintf("%v", b.texture.tex.ID),
b.texture.tex.ID,
Expand All @@ -239,6 +247,8 @@ func (b *ImageButtonWidget) Build() {
) && b.onClick != nil {
b.onClick()
}

imgui.PopID()
}

// Size sets BUTTONS size.
Expand Down

0 comments on commit 4ca9f4d

Please sign in to comment.