File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ type Image struct {
70
70
Translucency float64 // Set a translucency value > 0.0 to fade the image
71
71
FillMode ImageFill // Specify how the image should expand to fill or fit the available space
72
72
ScaleMode ImageScale // Specify the type of scaling interpolation applied to the image
73
+
74
+ previousRender bool // did we successfully draw before? if so a nil content will need a reset
73
75
}
74
76
75
77
// Alpha is a convenience function that returns the alpha value for an image
@@ -131,6 +133,11 @@ func (i *Image) Refresh() {
131
133
return
132
134
}
133
135
rc = io .NopCloser (r )
136
+ } else if i .previousRender {
137
+ i .previousRender = false
138
+
139
+ Refresh (i )
140
+ return
134
141
} else {
135
142
return
136
143
}
@@ -165,6 +172,7 @@ func (i *Image) Refresh() {
165
172
}
166
173
}
167
174
175
+ i .previousRender = true
168
176
Refresh (i )
169
177
}
170
178
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ import (
9
9
"strings"
10
10
"testing"
11
11
12
+ "fyne.io/fyne/v2"
12
13
"fyne.io/fyne/v2/canvas"
13
14
"fyne.io/fyne/v2/storage"
14
15
_ "fyne.io/fyne/v2/test"
16
+ "fyne.io/fyne/v2/theme"
15
17
16
18
"github.com/stretchr/testify/assert"
17
19
)
@@ -28,6 +30,22 @@ func TestImage_TranslucencyDefault(t *testing.T) {
28
30
assert .Equal (t , 0.0 , img .Translucency )
29
31
}
30
32
33
+ func TestImage_RefreshBlank (t * testing.T ) {
34
+ img := & canvas.Image {}
35
+ img .Resize (fyne .NewSize (64 , 64 ))
36
+ img .Refresh ()
37
+ assert .Nil (t , img .Image )
38
+
39
+ img .Resource = theme .HomeIcon ()
40
+ img .Refresh ()
41
+ assert .NotNil (t , img .Image )
42
+
43
+ img .Image = nil
44
+ img .Resource = nil
45
+ img .Refresh ()
46
+ assert .Nil (t , img .Image )
47
+ }
48
+
31
49
func TestNewImageFromFile (t * testing.T ) {
32
50
pwd , _ := os .Getwd ()
33
51
path := filepath .Join (filepath .Dir (pwd ), "theme" , "icons" , "fyne.png" )
You can’t perform that action at this time.
0 commit comments