This repository has been archived by the owner on Jan 14, 2024. It is now read-only.
forked from fyne-io/fyne
/
theme.go
72 lines (63 loc) · 1.59 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
68
69
70
71
72
package tutorials
import (
"image/color"
"github.com/Anwert/fyne/v2"
"github.com/Anwert/fyne/v2/theme"
)
var (
purple = &color.NRGBA{R: 128, G: 0, B: 128, A: 255}
orange = &color.NRGBA{R: 198, G: 123, B: 0, A: 255}
grey = &color.Gray{Y: 123}
)
// customTheme is a simple demonstration of a bespoke theme loaded by a Fyne app.
type customTheme struct {
}
func (customTheme) Color(c fyne.ThemeColorName, _ fyne.ThemeVariant) color.Color {
switch c {
case theme.ColorNameBackground:
return purple
case theme.ColorNameButton, theme.ColorNameDisabled:
return color.Black
case theme.ColorNamePlaceHolder, theme.ColorNameScrollBar:
return grey
case theme.ColorNamePrimary, theme.ColorNameHover, theme.ColorNameFocus:
return orange
case theme.ColorNameShadow:
return &color.RGBA{R: 0xcc, G: 0xcc, B: 0xcc, A: 0xcc}
default:
return color.White
}
}
func (customTheme) Font(style fyne.TextStyle) fyne.Resource {
return theme.DarkTheme().Font(style)
}
func (customTheme) Icon(n fyne.ThemeIconName) fyne.Resource {
return theme.DefaultTheme().Icon(n)
}
func (customTheme) Size(s fyne.ThemeSizeName) float32 {
switch s {
case theme.SizeNamePadding:
return 8
case theme.SizeNameInlineIcon:
return 20
case theme.SizeNameScrollBar:
return 10
case theme.SizeNameScrollBarSmall:
return 5
case theme.SizeNameText:
return 18
case theme.SizeNameHeadingText:
return 30
case theme.SizeNameSubHeadingText:
return 25
case theme.SizeNameCaptionText:
return 15
case theme.SizeNameInputBorder:
return 1
default:
return 0
}
}
func newCustomTheme() fyne.Theme {
return &customTheme{}
}