move default theme to ThemeFile system

This commit is contained in:
Drew Weymouth
2023-06-20 18:32:41 -07:00
parent 604396ae17
commit 4a399c51b7
6 changed files with 134 additions and 35 deletions
+15 -1
View File
@@ -5,9 +5,12 @@ import (
"errors"
"fmt"
"image/color"
"io"
"os"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/pelletier/go-toml"
)
@@ -83,8 +86,12 @@ func ReadThemeFile(filePath string) (*ThemeFile, error) {
}
defer f.Close()
return DecodeThemeFile(f)
}
func DecodeThemeFile(reader io.Reader) (*ThemeFile, error) {
theme := &ThemeFile{}
if err := toml.NewDecoder(f).Decode(theme); err != nil {
if err := toml.NewDecoder(reader).Decode(theme); err != nil {
return nil, err
}
@@ -98,6 +105,13 @@ func ReadThemeFile(filePath string) (*ThemeFile, error) {
return theme, nil
}
func (t *ThemeFile) SupportsVariant(v fyne.ThemeVariant) bool {
if v == theme.VariantDark {
return t.SupersonicTheme.SupportsDark
}
return t.SupersonicTheme.SupportsLight
}
// Parses a CSS-style #RRGGBB or #RRGGBBAA string
func ColorStringToColor(colorStr string) (color.Color, error) {
if !strings.HasPrefix(colorStr, "#") || !sharedutil.SliceContains([]int{7, 9}, len(colorStr)) {