From ff95f675a64f13a2602f2ad719cbbd4c7b60b2ec Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 29 Jun 2024 21:46:44 +0100 Subject: [PATCH] Document the requirement to refresh if adding items --- container/theme.go | 3 +++ container/theme_test.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/container/theme.go b/container/theme.go index cd4e29c3d7..838c74ff2c 100644 --- a/container/theme.go +++ b/container/theme.go @@ -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)} diff --git a/container/theme_test.go b/container/theme_test.go index 36ae8fcecf..36423fc06f 100644 --- a/container/theme_test.go +++ b/container/theme_test.go @@ -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())