-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplates.go
73 lines (58 loc) · 1.88 KB
/
templates.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
package main
const bundleTpl = `// auto-generated
// Code generated by 'fynematic'. DO NOT EDIT.
package {{.Package}}
import "fyne.io/fyne/v2"
var {{.VarName}}IconThemed = NewThemedResource({{.VarName}}IconDarkRes, {{.VarName}}IconLightRes)
var {{.VarName}}IconDarkRes = &fyne.StaticResource{
StaticName: "{{.Name}}_{{.Style}}_dark.svg",
StaticContent: []byte({{.IconDark}}),
}
var {{.VarName}}IconLightRes = &fyne.StaticResource{
StaticName: "{{.Name}}_{{.Style}}_light.svg",
StaticContent: []byte({{.IconLight}}),
}
`
const themedResourceTpl = `// auto-generated
// Code generated by 'fynematic'. DO NOT EDIT.
// Copyright (C) 2018 Fyne.io developers (see AUTHORS)
// All rights reserved.
//
// Use of the source code in this file is governed by a BSD 3-Clause License
// license that can be found at
// https://github.com/fyne-io/fyne/blob/v2.0.2/LICENSE
//
// Original: https://github.com/fyne-io/fyne/blob/v2.0.2/cmd/fyne_demo/data/icons.go
package {{.Package}}
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
// ThemedResource is a resource wrapper that will return an appropriate resource
// for the currently selected theme.
type ThemedResource struct {
dark, light fyne.Resource
}
func isLight() bool {
r, g, b, _ := theme.ForegroundColor().RGBA()
return r < 0xaaaa && g < 0xaaaa && b < 0xaaaa
}
// Name returns the underlying resource name (used for caching)
func (res *ThemedResource) Name() string {
if isLight() {
return res.light.Name()
}
return res.dark.Name()
}
// Content returns the underlying content of the correct resource for the current theme
func (res *ThemedResource) Content() []byte {
if isLight() {
return res.light.Content()
}
return res.dark.Content()
}
// NewThemedResource creates a resource that adapts to the current theme setting.
func NewThemedResource(dark, light fyne.Resource) *ThemedResource {
return &ThemedResource{dark, light}
}
`