forked from fyne-io/fyne
/
theme.go
368 lines (300 loc) · 10.5 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
// Package theme defines how a Fyne app should look when rendered
package theme // import "fyne.io/fyne/theme"
import (
"image/color"
"os"
"strings"
"fyne.io/fyne"
)
type builtinTheme struct {
background color.Color
button, text, icon, hyperlink, placeholder, primary, hover, scrollBar, shadow color.Color
regular, bold, italic, bolditalic, monospace fyne.Resource
disabledButton, disabledIcon, disabledText color.Color
}
// LightTheme defines the built in light theme colors and sizes
func LightTheme() fyne.Theme {
theme := &builtinTheme{
background: color.NRGBA{0xf5, 0xf5, 0xf5, 0xff},
button: color.NRGBA{0xd9, 0xd9, 0xd9, 0xff},
disabledButton: color.NRGBA{0xe7, 0xe7, 0xe7, 0xff},
text: color.NRGBA{0x21, 0x21, 0x21, 0xff},
disabledText: color.NRGBA{0x80, 0x80, 0x80, 0xff},
icon: color.NRGBA{0x21, 0x21, 0x21, 0xff},
disabledIcon: color.NRGBA{0x80, 0x80, 0x80, 0xff},
hyperlink: color.NRGBA{0x0, 0x0, 0xd9, 0xff},
placeholder: color.NRGBA{0x88, 0x88, 0x88, 0xff},
primary: color.NRGBA{0x9f, 0xa8, 0xda, 0xff},
hover: color.NRGBA{0xe7, 0xe7, 0xe7, 0xff},
scrollBar: color.NRGBA{0x0, 0x0, 0x0, 0x99},
shadow: color.NRGBA{0x0, 0x0, 0x0, 0x33},
}
theme.initFonts()
return theme
}
// DarkTheme defines the built in dark theme colors and sizes
func DarkTheme() fyne.Theme {
theme := &builtinTheme{
background: color.NRGBA{0x42, 0x42, 0x42, 0xff},
button: color.NRGBA{0x21, 0x21, 0x21, 0xff},
disabledButton: color.NRGBA{0x31, 0x31, 0x31, 0xff},
text: color.NRGBA{0xff, 0xff, 0xff, 0xff},
disabledText: color.NRGBA{0x60, 0x60, 0x60, 0xff},
icon: color.NRGBA{0xff, 0xff, 0xff, 0xff},
disabledIcon: color.NRGBA{0x60, 0x60, 0x60, 0xff},
hyperlink: color.NRGBA{0x99, 0x99, 0xff, 0xff},
placeholder: color.NRGBA{0xb2, 0xb2, 0xb2, 0xff},
primary: color.NRGBA{0x1a, 0x23, 0x7e, 0xff},
hover: color.NRGBA{0x31, 0x31, 0x31, 0xff},
scrollBar: color.NRGBA{0x0, 0x0, 0x0, 0x99},
shadow: color.NRGBA{0x0, 0x0, 0x0, 0x66},
}
theme.initFonts()
return theme
}
func (t *builtinTheme) BackgroundColor() color.Color {
return t.background
}
// ButtonColor returns the theme's standard button color
func (t *builtinTheme) ButtonColor() color.Color {
return t.button
}
// DisabledButtonColor returns the theme's disabled button color
func (t *builtinTheme) DisabledButtonColor() color.Color {
return t.disabledButton
}
// HyperlinkColor returns the theme's standard hyperlink color
func (t *builtinTheme) HyperlinkColor() color.Color {
return t.hyperlink
}
// TextColor returns the theme's standard text color
func (t *builtinTheme) TextColor() color.Color {
return t.text
}
// DisabledIconColor returns the color for a disabledIcon UI element
func (t *builtinTheme) DisabledTextColor() color.Color {
return t.disabledText
}
// IconColor returns the theme's standard text color
func (t *builtinTheme) IconColor() color.Color {
return t.icon
}
// DisabledIconColor returns the color for a disabledIcon UI element
func (t *builtinTheme) DisabledIconColor() color.Color {
return t.disabledIcon
}
// PlaceHolderColor returns the theme's placeholder text color
func (t *builtinTheme) PlaceHolderColor() color.Color {
return t.placeholder
}
// PrimaryColor returns the color used to highlight primary features
func (t *builtinTheme) PrimaryColor() color.Color {
return t.primary
}
// HoverColor returns the color used to highlight interactive elements currently under a cursor
func (t *builtinTheme) HoverColor() color.Color {
return t.hover
}
// FocusColor returns the color used to highlight a focused widget
func (t *builtinTheme) FocusColor() color.Color {
return t.primary
}
// ScrollBarColor returns the color (and translucency) for a scrollBar
func (t *builtinTheme) ScrollBarColor() color.Color {
return t.scrollBar
}
// ShadowColor returns the color (and translucency) for shadows used for indicating elevation
func (t *builtinTheme) ShadowColor() color.Color {
return t.shadow
}
// TextSize returns the standard text size
func (t *builtinTheme) TextSize() int {
return 14
}
func loadCustomFont(env, variant string, fallback fyne.Resource) fyne.Resource {
variantPath := strings.Replace(env, "Regular", variant, -1)
res, err := fyne.LoadResourceFromPath(variantPath)
if err != nil {
fyne.LogError("Error loading specified font", err)
return fallback
}
return res
}
func (t *builtinTheme) initFonts() {
t.regular = regular
t.bold = bold
t.italic = italic
t.bolditalic = bolditalic
t.monospace = monospace
font := os.Getenv("FYNE_FONT")
if font != "" {
t.regular = loadCustomFont(font, "Regular", regular)
t.bold = loadCustomFont(font, "Bold", bold)
t.italic = loadCustomFont(font, "Italic", italic)
t.bolditalic = loadCustomFont(font, "BoldItalic", bolditalic)
}
font = os.Getenv("FYNE_FONT_MONOSPACE")
if font != "" {
t.monospace = loadCustomFont(font, "Regular", monospace)
}
}
// TextFont returns the font resource for the regular font style
func (t *builtinTheme) TextFont() fyne.Resource {
return t.regular
}
// TextBoldFont retutns the font resource for the bold font style
func (t *builtinTheme) TextBoldFont() fyne.Resource {
return t.bold
}
// TextItalicFont returns the font resource for the italic font style
func (t *builtinTheme) TextItalicFont() fyne.Resource {
return t.italic
}
// TextBoldItalicFont returns the font resource for the bold and italic font style
func (t *builtinTheme) TextBoldItalicFont() fyne.Resource {
return t.bolditalic
}
// TextMonospaceFont retutns the font resource for the monospace font face
func (t *builtinTheme) TextMonospaceFont() fyne.Resource {
return t.monospace
}
// Padding is the standard gap between elements and the border around interface
// elements
func (t *builtinTheme) Padding() int {
return 4
}
// IconInlineSize is the standard size of icons which appear within buttons, labels etc.
func (t *builtinTheme) IconInlineSize() int {
return 20
}
// ScrollBarSize is the width (or height) of the bars on a ScrollContainer
func (t *builtinTheme) ScrollBarSize() int {
return 16
}
// ScrollBarSmallSize is the width (or height) of the minimized bars on a ScrollContainer
func (t *builtinTheme) ScrollBarSmallSize() int {
return 3
}
func current() fyne.Theme {
if fyne.CurrentApp() == nil || fyne.CurrentApp().Settings().Theme() == nil {
return DarkTheme()
}
return fyne.CurrentApp().Settings().Theme()
}
// BackgroundColor returns the theme's background color
func BackgroundColor() color.Color {
return current().BackgroundColor()
}
// ButtonColor returns the theme's standard button color
func ButtonColor() color.Color {
return current().ButtonColor()
}
// DisabledButtonColor returns the theme's disabled button color
func DisabledButtonColor() color.Color {
return current().DisabledButtonColor()
}
// HyperlinkColor returns the theme's standard hyperlink color
func HyperlinkColor() color.Color {
return current().HyperlinkColor()
}
// TextColor returns the theme's standard text color
func TextColor() color.Color {
return current().TextColor()
}
// DisabledTextColor returns the color for a disabledIcon UI element
func DisabledTextColor() color.Color {
return current().DisabledTextColor()
}
// IconColor returns the theme's standard text color
func IconColor() color.Color {
return current().IconColor()
}
// DisabledIconColor returns the color for a disabledIcon UI element
func DisabledIconColor() color.Color {
return current().DisabledIconColor()
}
// PlaceHolderColor returns the theme's standard text color
func PlaceHolderColor() color.Color {
return current().PlaceHolderColor()
}
// PrimaryColor returns the color used to highlight primary features
func PrimaryColor() color.Color {
return current().PrimaryColor()
}
// HoverColor returns the color used to highlight interactive elements currently under a cursor
func HoverColor() color.Color {
return current().HoverColor()
}
// FocusColor returns the color used to highlight a focussed widget
func FocusColor() color.Color {
return current().FocusColor()
}
// ScrollBarColor returns the color (and translucency) for a scrollBar
func ScrollBarColor() color.Color {
return current().ScrollBarColor()
}
// ShadowColor returns the color (and translucency) for shadows used for indicating elevation
func ShadowColor() color.Color {
return current().ShadowColor()
}
// TextSize returns the standard text size
func TextSize() int {
return current().TextSize()
}
// TextFont returns the font resource for the regular font style
func TextFont() fyne.Resource {
return current().TextFont()
}
// TextBoldFont retutns the font resource for the bold font style
func TextBoldFont() fyne.Resource {
return current().TextBoldFont()
}
// TextItalicFont returns the font resource for the italic font style
func TextItalicFont() fyne.Resource {
return current().TextItalicFont()
}
// TextBoldItalicFont returns the font resource for the bold and italic font style
func TextBoldItalicFont() fyne.Resource {
return current().TextBoldItalicFont()
}
// TextMonospaceFont retutns the font resource for the monospace font face
func TextMonospaceFont() fyne.Resource {
return current().TextMonospaceFont()
}
// Padding is the standard gap between elements and the border around interface
// elements
func Padding() int {
return current().Padding()
}
// IconInlineSize is the standard size of icons which appear within buttons, labels etc.
func IconInlineSize() int {
return current().IconInlineSize()
}
// ScrollBarSize is the width (or height) of the bars on a ScrollContainer
func ScrollBarSize() int {
return current().ScrollBarSize()
}
// ScrollBarSmallSize is the width (or height) of the minimized bars on a ScrollContainer
func ScrollBarSmallSize() int {
return current().ScrollBarSmallSize()
}
// DefaultTextFont returns the font resource for the built-in regular font style
func DefaultTextFont() fyne.Resource {
return regular
}
// DefaultTextBoldFont retutns the font resource for the built-in bold font style
func DefaultTextBoldFont() fyne.Resource {
return bold
}
// DefaultTextItalicFont returns the font resource for the built-in italic font style
func DefaultTextItalicFont() fyne.Resource {
return italic
}
// DefaultTextBoldItalicFont returns the font resource for the built-in bold and italic font style
func DefaultTextBoldItalicFont() fyne.Resource {
return bolditalic
}
// DefaultTextMonospaceFont retutns the font resource for the built-in monospace font face
func DefaultTextMonospaceFont() fyne.Resource {
return monospace
}