Skip to content

Commit

Permalink
Fix icon for extending as well
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 23, 2020
1 parent 137542f commit 3e4b30f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -20,7 +20,7 @@ More detailed release notes can be found on the [releases page](https://github.c
### Fixed

* Updating text and calling refresh for widget doesn't work (#607)
* Corrected visual behaviour of extended widgets including Entry, Select, Check and Radio (#615)
* Corrected visual behaviour of extended widgets including Entry, Select, Check, Radio and Icon (#615)
* Entries and Selects that are extended would crash on right click.
* PasswordEntry created from Entry with Password = true has no revealer
* Dialog width not always sufficient for title
Expand Down
5 changes: 3 additions & 2 deletions widget/icon.go
Expand Up @@ -46,7 +46,7 @@ func (i *iconRenderer) Refresh() {
}
i.Layout(i.image.Size())

canvas.Refresh(i.image)
canvas.Refresh(i.image.super())
}

func (i *iconRenderer) Destroy() {
Expand All @@ -62,7 +62,7 @@ type Icon struct {
// SetResource updates the resource rendered in this icon widget
func (i *Icon) SetResource(res fyne.Resource) {
i.Resource = res
i.refresh(i)
i.Refresh()
}

// MinSize returns the size that this widget should not shrink below
Expand All @@ -84,6 +84,7 @@ func (i *Icon) CreateRenderer() fyne.WidgetRenderer {
// NewIcon returns a new icon widget that displays a themed icon resource
func NewIcon(res fyne.Resource) *Icon {
icon := &Icon{}
icon.ExtendBaseWidget(icon)
icon.SetResource(res) // force the image conversion

return icon
Expand Down
29 changes: 29 additions & 0 deletions widget/icon_extend_test.go
@@ -0,0 +1,29 @@
package widget

import (
"testing"

"fyne.io/fyne/canvas"
"fyne.io/fyne/internal/cache"
"fyne.io/fyne/theme"
"github.com/stretchr/testify/assert"
)

type extendedIcon struct {
Icon
}

func newExtendedIcon() *extendedIcon {
icon := &extendedIcon{}
icon.ExtendBaseWidget(icon)
return icon
}

func TestIcon_Extended_SetResource(t *testing.T) {
icon := newExtendedIcon()
icon.SetResource(theme.FyneLogo())

objs := cache.Renderer(icon).Objects()
assert.Equal(t, 1, len(objs))
assert.Equal(t, theme.FyneLogo(), objs[0].(*canvas.Image).Resource)
}
7 changes: 4 additions & 3 deletions widget/icon_test.go
Expand Up @@ -4,13 +4,14 @@ import (
"testing"

"fyne.io/fyne/canvas"
"fyne.io/fyne/internal/cache"
"fyne.io/fyne/theme"
"github.com/stretchr/testify/assert"
)

func TestNewIcon(t *testing.T) {
icon := NewIcon(theme.ConfirmIcon())
render := Renderer(icon)
render := cache.Renderer(icon)

assert.Equal(t, 1, len(render.Objects()))
obj := render.Objects()[0]
Expand All @@ -23,7 +24,7 @@ func TestNewIcon(t *testing.T) {

func TestIcon_Nil(t *testing.T) {
icon := NewIcon(nil)
render := Renderer(icon)
render := cache.Renderer(icon)

assert.Equal(t, 0, len(render.Objects()))
}
Expand All @@ -38,7 +39,7 @@ func TestIcon_MinSize(t *testing.T) {

func TestIconRenderer_ApplyTheme(t *testing.T) {
icon := NewIcon(theme.CancelIcon())
render := Renderer(icon).(*iconRenderer)
render := cache.Renderer(icon).(*iconRenderer)
visible := render.objects[0].Visible()

render.Refresh()
Expand Down

0 comments on commit 3e4b30f

Please sign in to comment.