-
Notifications
You must be signed in to change notification settings - Fork 20
/
theme.go
67 lines (53 loc) · 1.36 KB
/
theme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"crocgui/internal/croctheme"
"fmt"
"image/color"
"io"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"github.com/ulikunitz/xz"
)
type crocTheme struct {
color fyne.Theme
icon fyne.Theme
fontName string
size fyne.Theme
}
var _ fyne.Theme = (*crocTheme)(nil)
var appTheme = crocTheme{}
func (c crocTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
return c.color.Color(name, variant)
}
func (c crocTheme) Icon(name fyne.ThemeIconName) fyne.Resource {
return c.icon.Icon(name)
}
func (c crocTheme) Font(style fyne.TextStyle) fyne.Resource {
ftype := "Regular"
if style.Bold {
ftype = "Bold"
}
if ttfxz, lerr := fsFonts.Open(fmt.Sprintf("internal/fonts/%s-%s.ttf.xz", c.fontName, ftype)); lerr == nil {
xr, _ := xz.NewReader(ttfxz)
ttf, _ := io.ReadAll(xr)
return fyne.NewStaticResource(fmt.Sprintf("%s-%s.ttf", c.fontName, ftype), ttf)
}
return theme.DefaultTheme().Font(style)
}
func (c crocTheme) Size(name fyne.ThemeSizeName) float32 {
return c.size.Size(name)
}
func setThemeColor(themeName string) {
switch themeName {
case "light":
appTheme.color = theme.LightTheme()
case "grey":
appTheme.color = croctheme.GreyTheme()
case "dark":
appTheme.color = theme.DarkTheme()
case "black":
appTheme.color = croctheme.BlackTheme()
case "system":
appTheme.color = theme.DefaultTheme()
}
}