Skip to content

Commit

Permalink
image with rgba: fix bug when changing input RGBA didn't change displ…
Browse files Browse the repository at this point in the history
…ayed image
  • Loading branch information
gucio321 committed Oct 8, 2023
1 parent 65bce2a commit 5ed971c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ImageWidgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"image"
"image/color"
"net/http"
"reflect"
"time"

imgui "github.com/AllenDang/cimgui-go"
Expand Down Expand Up @@ -108,6 +109,7 @@ type imageState struct {
failure bool
cancel ctx.CancelFunc
texture *Texture
img *image.RGBA
}

// Dispose cleans imageState (implements Disposable interface).
Expand All @@ -127,15 +129,15 @@ var _ Widget = &ImageWithRgbaWidget{}
// display it in giu.
type ImageWithRgbaWidget struct {
id string
rgba image.Image
rgba *image.RGBA
img *ImageWidget
}

// ImageWithRgba creates ImageWithRgbaWidget.
func ImageWithRgba(rgba image.Image) *ImageWithRgbaWidget {
return &ImageWithRgbaWidget{
id: GenAutoID("ImageWithRgba"),
rgba: rgba,
rgba: ImageToRgba(rgba),
img: Image(nil),
}
}
Expand All @@ -162,7 +164,7 @@ func (i *ImageWithRgbaWidget) OnClick(cb func()) *ImageWithRgbaWidget {
func (i *ImageWithRgbaWidget) Build() {
if i.rgba != nil {
var imgState *imageState
if imgState = GetState[imageState](Context, i.id); imgState == nil {
if imgState = GetState[imageState](Context, i.id); imgState == nil || !reflect.DeepEqual(i.rgba, imgState.img) {
imgState = &imageState{}
SetState(Context, i.id, imgState)

Expand Down

0 comments on commit 5ed971c

Please sign in to comment.