This commit is contained in:
unknown
2019-12-16 10:43:46 +08:00
parent d930d9f003
commit 90ff08ed98
13 changed files with 877 additions and 0 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

57
gui/fyne_demo/data/gen.go Normal file
View File

@@ -0,0 +1,57 @@
// +build ignore
package main
import (
"fmt"
"os"
"path"
"runtime"
"fyne.io/fyne"
)
func bundleFile(name string, filepath string, f *os.File) {
res, err := fyne.LoadResourceFromPath(filepath)
if err != nil {
fyne.LogError("Unable to load file "+filepath, err)
return
}
_, err = f.WriteString(fmt.Sprintf("var %s = %#v\n", name, res))
if err != nil {
fyne.LogError("Unable to write to bundled file", err)
}
}
func openFile(filename string) *os.File {
os.Remove(filename)
_, dirname, _, _ := runtime.Caller(0)
f, err := os.Create(path.Join(path.Dir(dirname), filename))
if err != nil {
fyne.LogError("Unable to open file "+filename, err)
return nil
}
_, err = f.WriteString("// **** THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT IT **** //\n\npackage data\n\nimport \"fyne.io/fyne\"\n\n")
if err != nil {
fyne.LogError("Unable to write file "+filename, err)
return nil
}
return f
}
func iconDir() string {
_, dirname, _, _ := runtime.Caller(0)
return path.Join(path.Dir(dirname), "icons")
}
func main() {
f := openFile("bundled-scene.go")
bundleFile("fynescenedark", "fyne_scene_dark.png", f)
bundleFile("fynescenelight", "fyne_scene_light.png", f)
f.Close()
}

View File

@@ -0,0 +1,40 @@
package data
import (
"fyne.io/fyne"
)
// 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, _ := fyne.CurrentApp().Settings().Theme().TextColor().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}
}
// FyneScene contains the full fyne logo with background design
var FyneScene = NewThemedResource(fynescenedark, fynescenelight)