Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image with rgba: fix rgba bug #713

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading