mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-03 21:16:53 +00:00
test gui
This commit is contained in:
14
gui/fyne_demo/data/bundled-scene.go
Normal file
14
gui/fyne_demo/data/bundled-scene.go
Normal file
File diff suppressed because one or more lines are too long
BIN
gui/fyne_demo/data/fyne_scene_dark.png
Normal file
BIN
gui/fyne_demo/data/fyne_scene_dark.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
BIN
gui/fyne_demo/data/fyne_scene_light.png
Normal file
BIN
gui/fyne_demo/data/fyne_scene_light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
57
gui/fyne_demo/data/gen.go
Normal file
57
gui/fyne_demo/data/gen.go
Normal 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()
|
||||
}
|
40
gui/fyne_demo/data/icons.go
Normal file
40
gui/fyne_demo/data/icons.go
Normal 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)
|
Reference in New Issue
Block a user