update theme and themefile syntax now that HyperlinkColor exists in Fyne
This commit is contained in:
+1
-1
@@ -153,7 +153,7 @@ var ResRepeatoneSvg = &fyne.StaticResource{
|
||||
var ResDefaultToml = &fyne.StaticResource{
|
||||
StaticName: "default.toml",
|
||||
StaticContent: []byte(
|
||||
"[SupersonicTheme]\nName = \"Default\"\nVersion = \"0.1\"\nSupportsDark = true\nSupportsLight = true\n\n[DarkColors]\nPageBackground = \"#0F0F0F\"\nListHeader = \"#232323\"\nBackground = \"#232323\"\nScrollBar = \"#F3F3F3\"\nButton = \"#14141432\"\nInputBackground = \"#14141432\"\n\n[LightColors]\nPageBackground = \"#FAFAFA\"\nListHeader = \"#E1DFE1\"\nBackground = \"#E1DFE1\"\nScrollBar = \"#565656\"\nButton = \"#C8C8C8F0\"\nDisabledButton = \"#CDCDCDF0\"\nForeground = \"#0A0A0A\"\nPrimary = \"#1919FA\""),
|
||||
"[SupersonicTheme]\nName = \"Default\"\nVersion = \"0.2\"\nSupportsDark = true\nSupportsLight = true\n\n[DarkColors]\nPageBackground = \"#0F0F0F\"\nListHeader = \"#232323\"\nBackground = \"#232323\"\nScrollBar = \"#F3F3F3\"\nButton = \"#14141432\"\nInputBackground = \"#14141432\"\n\n[LightColors]\nPageBackground = \"#FAFAFA\"\nListHeader = \"#E1DFE1\"\nBackground = \"#E1DFE1\"\nScrollBar = \"#565656\"\nButton = \"#C8C8C8F0\"\nDisabledButton = \"#CDCDCDF0\"\nForeground = \"#0A0A0A\"\nHyperlink = \"#3737FB\""),
|
||||
}
|
||||
var ResLICENSE = &fyne.StaticResource{
|
||||
StaticName: "LICENSE",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[SupersonicTheme]
|
||||
Name = "Default"
|
||||
Version = "0.1"
|
||||
Version = "0.2"
|
||||
SupportsDark = true
|
||||
SupportsLight = true
|
||||
|
||||
@@ -20,4 +20,4 @@ ScrollBar = "#565656"
|
||||
Button = "#C8C8C8F0"
|
||||
DisabledButton = "#CDCDCDF0"
|
||||
Foreground = "#0A0A0A"
|
||||
Primary = "#1919FA"
|
||||
Hyperlink = "#3737FB"
|
||||
+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