From 5ed971cad969cfe828bdccbd311ac35c42c7371a Mon Sep 17 00:00:00 2001 From: gucio321 Date: Sun, 8 Oct 2023 10:50:26 +0200 Subject: [PATCH] image with rgba: fix bug when changing input RGBA didn't change displayed image --- ImageWidgets.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ImageWidgets.go b/ImageWidgets.go index 92398fcf..d0086ad0 100644 --- a/ImageWidgets.go +++ b/ImageWidgets.go @@ -6,6 +6,7 @@ import ( "image" "image/color" "net/http" + "reflect" "time" imgui "github.com/AllenDang/cimgui-go" @@ -108,6 +109,7 @@ type imageState struct { failure bool cancel ctx.CancelFunc texture *Texture + img *image.RGBA } // Dispose cleans imageState (implements Disposable interface). @@ -127,7 +129,7 @@ var _ Widget = &ImageWithRgbaWidget{} // display it in giu. type ImageWithRgbaWidget struct { id string - rgba image.Image + rgba *image.RGBA img *ImageWidget } @@ -135,7 +137,7 @@ type ImageWithRgbaWidget struct { func ImageWithRgba(rgba image.Image) *ImageWithRgbaWidget { return &ImageWithRgbaWidget{ id: GenAutoID("ImageWithRgba"), - rgba: rgba, + rgba: ImageToRgba(rgba), img: Image(nil), } } @@ -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)