Skip to content

Commit

Permalink
Fix issue where toolbar would not completely refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jan 16, 2021
1 parent 969392b commit 263fec8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 3 additions & 5 deletions widget/toolbar.go
Expand Up @@ -137,11 +137,9 @@ func (r *toolbarRenderer) Refresh() {
}

func (r *toolbarRenderer) resetObjects() {
if len(r.items) != len(r.toolbar.Items) {
r.items = make([]fyne.CanvasObject, 0, len(r.toolbar.Items))
for _, item := range r.toolbar.Items {
r.items = append(r.items, item.ToolbarObject())
}
r.items = make([]fyne.CanvasObject, 0, len(r.toolbar.Items))
for _, item := range r.toolbar.Items {
r.items = append(r.items, item.ToolbarObject())
}
r.SetObjects(append([]fyne.CanvasObject{r.background}, r.items...))
}
12 changes: 12 additions & 0 deletions widget/toolbar_test.go
Expand Up @@ -35,6 +35,18 @@ func TestToolbar_Prepend(t *testing.T) {
assert.Equal(t, prepend, toolbar.Items[0])
}

func TestToolbar_Replace(t *testing.T) {
icon := theme.ContentCutIcon()
toolbar := NewToolbar(NewToolbarAction(icon, func() {}))
assert.Equal(t, 1, len(toolbar.Items))
render := test.WidgetRenderer(toolbar)
assert.Equal(t, icon, render.Objects()[1].(*Button).Icon)

toolbar.Items[0] = NewToolbarAction(theme.HelpIcon(), func() {})
toolbar.Refresh()
assert.NotEqual(t, icon, render.Objects()[1].(*Button).Icon)
}

func TestToolbar_ItemPositioning(t *testing.T) {
toolbar := &Toolbar{
Items: []ToolbarItem{
Expand Down

0 comments on commit 263fec8

Please sign in to comment.