@@ -35,12 +35,26 @@ var themeColors = map[fyne.ThemeColorName][]color.Color{
3535 },
3636}
3737
38- type myTheme struct {
39- mode settings.ColorTheme
38+ // customTheme represents a custom Fyne theme.
39+ // It adds colors to the default theme
40+ // and allows setting a fixed theme variant.
41+ type customTheme struct {
42+ defaultTheme fyne.Theme
43+ mode settings.ColorTheme
4044}
4145
42- func (ct myTheme ) Color (c fyne.ThemeColorName , v fyne.ThemeVariant ) color.Color {
43- switch ct .mode {
46+ // newCustomTheme returns a new custom theme.
47+ // Must be called after the app has started.
48+ func newCustomTheme (mode settings.ColorTheme ) * customTheme {
49+ th := & customTheme {
50+ defaultTheme : fyne .CurrentApp ().Settings ().Theme (),
51+ mode : mode ,
52+ }
53+ return th
54+ }
55+
56+ func (th customTheme ) Color (c fyne.ThemeColorName , v fyne.ThemeVariant ) color.Color {
57+ switch th .mode {
4458 case settings .Dark :
4559 v = theme .VariantDark
4660 case settings .Light :
@@ -50,18 +64,18 @@ func (ct myTheme) Color(c fyne.ThemeColorName, v fyne.ThemeVariant) color.Color
5064 case colorNameInfo , colorNameCreative , colorNameSystem , colorNameAttention :
5165 return themeColors [c ][v ]
5266 default :
53- return theme . DefaultTheme () .Color (c , v )
67+ return th . defaultTheme .Color (c , v )
5468 }
5569}
5670
57- func (myTheme ) Font (style fyne.TextStyle ) fyne.Resource {
58- return theme . DefaultTheme () .Font (style )
71+ func (th customTheme ) Font (style fyne.TextStyle ) fyne.Resource {
72+ return th . defaultTheme .Font (style )
5973}
6074
61- func (myTheme ) Icon (n fyne.ThemeIconName ) fyne.Resource {
62- return theme . DefaultTheme () .Icon (n )
75+ func (th customTheme ) Icon (n fyne.ThemeIconName ) fyne.Resource {
76+ return th . defaultTheme .Icon (n )
6377}
6478
65- func (myTheme ) Size (s fyne.ThemeSizeName ) float32 {
66- return theme . DefaultTheme () .Size (s )
79+ func (th customTheme ) Size (s fyne.ThemeSizeName ) float32 {
80+ return th . defaultTheme .Size (s )
6781}
0 commit comments