Skip to content

Commit

Permalink
Merge pull request #924 from gucio321/image-button-id
Browse files Browse the repository at this point in the history
Clickable widget: push auto ids
  • Loading branch information
gucio321 authored Dec 3, 2024
2 parents 4536adc + 6b92c1a commit c97a822
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 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,24 @@ func ImageButton(texture *Texture) *ImageButtonWidget {
bgColor: colornames.Black,
tintColor: colornames.White,
onClick: nil,
id: GenAutoID("ImageButton"),
}
}

// ID allows to manually set widget's id.
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,
Expand All @@ -239,6 +249,8 @@ func (b *ImageButtonWidget) Build() {
) && b.onClick != nil {
b.onClick()
}

imgui.PopID()
}

// Size sets BUTTONS size.
Expand Down

0 comments on commit c97a822

Please sign in to comment.