Skip to content

Commit

Permalink
Refresh dialog background on theme change
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 21, 2020
1 parent 3d3694b commit dcb72a1
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
27 changes: 26 additions & 1 deletion dialog/base.go
Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions 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())
}
6 changes: 3 additions & 3 deletions dialog/file_test.go
Expand Up @@ -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"}))

Expand All @@ -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/*"}))

Expand All @@ -228,5 +228,5 @@ func TestFileFilters(t *testing.T) {
count++
}
}
assert.Equal(t, count, 2)
assert.Equal(t, 4, count)
}
Binary file added dialog/testdata/dialog-custom-dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dialog/testdata/dialog-custom-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dcb72a1

Please sign in to comment.