Skip to content

Commit

Permalink
Merge pull request #713 from gucio321/fix-image-loading
Browse files Browse the repository at this point in the history
image with rgba: fix rgba bug
  • Loading branch information
gucio321 authored Dec 14, 2023
2 parents 31019fa + 5ed971c commit a42c149
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 a42c149

Please sign in to comment.