diff --git a/dialog/base.go b/dialog/base.go index d1e99c68a2..e57fb2c4e8 100644 --- a/dialog/base.go +++ b/dialog/base.go @@ -54,9 +54,34 @@ func (d *dialog) SetOnClosed(closed func()) { } } +// dialogTitle is really just a normal title but we use the Refresh() hook to update the background rectangle. +type dialogTitle struct { + widget.Label + + d *dialog +} + +// Refresh applies the current theme to the whole dialog before refreshing the underlying label. +func (t *dialogTitle) Refresh() { + t.d.applyTheme() + + t.BaseWidget.Refresh() +} + +func newDialogTitle(title string, d *dialog) *dialogTitle { + l := &dialogTitle{} + l.Text = title + l.Alignment = fyne.TextAlignLeading + l.TextStyle.Bold = true + + l.d = d + l.ExtendBaseWidget(l) + return l +} + func (d *dialog) setButtons(buttons fyne.CanvasObject) { d.bg = canvas.NewRectangle(theme.BackgroundColor()) - d.label = widget.NewLabelWithStyle(d.title, fyne.TextAlignLeading, fyne.TextStyle{Bold: true}) + d.label = newDialogTitle(d.title, d) var content fyne.CanvasObject if d.icon == nil { diff --git a/dialog/base_test.go b/dialog/base_test.go new file mode 100644 index 0000000000..e045f60403 --- /dev/null +++ b/dialog/base_test.go @@ -0,0 +1,26 @@ +package dialog + +import ( + "image/color" + "testing" + + "fyne.io/fyne" + "fyne.io/fyne/canvas" + "fyne.io/fyne/test" + "fyne.io/fyne/theme" + "fyne.io/fyne/widget" +) + +func TestShowCustom_ApplyTheme(t *testing.T) { + a := test.NewApp() + a.Settings().SetTheme(theme.DarkTheme()) + w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w.Resize(fyne.NewSize(300, 200)) + d := NewCustom("Title", "OK", widget.NewLabel("Content"), w) + + d.Show() + test.AssertImageMatches(t, "dialog-custom-dark.png", w.Canvas().Capture()) + + a.Settings().SetTheme(theme.LightTheme()) + test.AssertImageMatches(t, "dialog-custom-light.png", w.Canvas().Capture()) +} diff --git a/dialog/file_test.go b/dialog/file_test.go index 1037509d24..889fb0c6cd 100644 --- a/dialog/file_test.go +++ b/dialog/file_test.go @@ -203,7 +203,7 @@ func TestFileFilters(t *testing.T) { count++ } } - assert.Equal(t, count, 1) + assert.Equal(t, 3, count) f.SetFilter(storage.NewMimeTypeFileFilter([]string{"image/jpeg"})) @@ -215,7 +215,7 @@ func TestFileFilters(t *testing.T) { count++ } } - assert.Equal(t, count, 1) + assert.Equal(t, 1, count) f.SetFilter(storage.NewMimeTypeFileFilter([]string{"image/*"})) @@ -228,5 +228,5 @@ func TestFileFilters(t *testing.T) { count++ } } - assert.Equal(t, count, 2) + assert.Equal(t, 4, count) } diff --git a/dialog/testdata/dialog-custom-dark.png b/dialog/testdata/dialog-custom-dark.png new file mode 100644 index 0000000000..857712146c Binary files /dev/null and b/dialog/testdata/dialog-custom-dark.png differ diff --git a/dialog/testdata/dialog-custom-light.png b/dialog/testdata/dialog-custom-light.png new file mode 100644 index 0000000000..200abe1ced Binary files /dev/null and b/dialog/testdata/dialog-custom-light.png differ