Skip to content

Commit

Permalink
Document the requirement to refresh if adding items
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jun 30, 2024
1 parent 7a8bc42 commit ff95f67
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions container/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type ThemeOverride struct {
// Containers will be traversed and all child widgets will reflect the theme in this container.
// This should be used sparingly to avoid a jarring user experience.
//
// If the content `obj` of this theme override is a container and items are later added to the container
// ensure that you call `Refresh()` on this `ThemeOverride` to ensure the new items match the theme.
//
// Since: 2.5
func NewThemeOverride(obj fyne.CanvasObject, th fyne.Theme) *ThemeOverride {
t := &ThemeOverride{Content: obj, Theme: th, holder: NewStack(obj)}
Expand Down
16 changes: 16 additions & 0 deletions container/theme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ import (
"image"
"testing"

"github.com/stretchr/testify/assert"

"fyne.io/fyne/v2/internal/cache"
"fyne.io/fyne/v2/test"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)

func TestThemeOverride_AddChild(t *testing.T) {
b := widget.NewButton("Test", func() {})
group := NewHBox(b)
override := NewThemeOverride(group, test.Theme())

child := widget.NewLabel("Added")
assert.NotEqual(t, cache.WidgetTheme(b), cache.WidgetTheme(child))

group.Add(child)
override.Refresh()
assert.Equal(t, cache.WidgetTheme(b), cache.WidgetTheme(child))
}

func TestThemeOverride_Icons(t *testing.T) {
b := widget.NewButtonWithIcon("", theme.HomeIcon(), func() {})
o := NewThemeOverride(b, test.Theme())
Expand Down

0 comments on commit ff95f67

Please sign in to comment.