update theme and themefile syntax now that HyperlinkColor exists in Fyne
This commit is contained in:
+6
-1
@@ -53,7 +53,10 @@ var _ fyne.Theme = (*MyTheme)(nil)
|
||||
|
||||
func NewMyTheme(config *backend.ThemeConfig, themeFileDir string) *MyTheme {
|
||||
m := &MyTheme{config: config, themeFileDir: themeFileDir}
|
||||
m.defaultThemeFile, _ = DecodeThemeFile(bytes.NewReader(res.ResDefaultToml.StaticContent))
|
||||
var err error
|
||||
if m.defaultThemeFile, err = DecodeThemeFile(bytes.NewReader(res.ResDefaultToml.StaticContent)); err != nil {
|
||||
log.Fatalf("Failed to load builtin theme: %v", err.Error())
|
||||
}
|
||||
m.createThemeIcons()
|
||||
return m
|
||||
}
|
||||
@@ -103,6 +106,8 @@ func (m *MyTheme) Color(name fyne.ThemeColorName, _ fyne.ThemeVariant) color.Col
|
||||
return colorOrDefault(colors.Foreground, defColors.Foreground, name, variant)
|
||||
case theme.ColorNameHover:
|
||||
return colorOrDefault(colors.Hover, defColors.Hover, name, variant)
|
||||
case theme.ColorNameHyperlink:
|
||||
return colorOrDefault(colors.Hyperlink, defColors.Hyperlink, name, variant)
|
||||
case theme.ColorNameInputBackground:
|
||||
return colorOrDefault(colors.InputBackground, defColors.InputBackground, name, variant)
|
||||
case theme.ColorNameInputBorder:
|
||||
|
||||
+16
-1
@@ -15,6 +15,8 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
var validThemeVersions = []string{"0.1", "0.2"}
|
||||
|
||||
type ThemeFileHeader struct {
|
||||
Name string
|
||||
Version string
|
||||
@@ -54,6 +56,9 @@ type ThemeColors struct {
|
||||
|
||||
Hover string
|
||||
|
||||
// since Supersonic theme file version 0.2 (Fyne version 2.4)
|
||||
Hyperlink string
|
||||
|
||||
InputBackground string
|
||||
|
||||
InputBorder string
|
||||
@@ -97,12 +102,13 @@ func DecodeThemeFile(reader io.Reader) (*ThemeFile, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if theme.SupersonicTheme.Name == "" || theme.SupersonicTheme.Version != "0.1" {
|
||||
if theme.SupersonicTheme.Name == "" || !sharedutil.SliceContains(validThemeVersions, theme.SupersonicTheme.Version) {
|
||||
return nil, errors.New("invalid theme file name or version")
|
||||
}
|
||||
if !(theme.SupersonicTheme.SupportsDark || theme.SupersonicTheme.SupportsLight) {
|
||||
return nil, errors.New("invalid theme file: must support one or both of light/dark")
|
||||
}
|
||||
updateThemeToLatestVersion(theme)
|
||||
|
||||
return theme, nil
|
||||
}
|
||||
@@ -129,3 +135,12 @@ func ColorStringToColor(colorStr string) (color.Color, error) {
|
||||
}
|
||||
return color.RGBA{R: colorBytes[0], G: colorBytes[1], B: colorBytes[2], A: colorBytes[3]}, nil
|
||||
}
|
||||
|
||||
func updateThemeToLatestVersion(themeFile *ThemeFile) {
|
||||
switch themeFile.SupersonicTheme.Version {
|
||||
case "0.1":
|
||||
// in version 0.1, hyperlinks were drawn with the Primary color
|
||||
themeFile.DarkColors.Hyperlink = themeFile.DarkColors.Primary
|
||||
themeFile.LightColors.Hyperlink = themeFile.LightColors.Primary
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user