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{
|
var ResDefaultToml = &fyne.StaticResource{
|
||||||
StaticName: "default.toml",
|
StaticName: "default.toml",
|
||||||
StaticContent: []byte(
|
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{
|
var ResLICENSE = &fyne.StaticResource{
|
||||||
StaticName: "LICENSE",
|
StaticName: "LICENSE",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[SupersonicTheme]
|
[SupersonicTheme]
|
||||||
Name = "Default"
|
Name = "Default"
|
||||||
Version = "0.1"
|
Version = "0.2"
|
||||||
SupportsDark = true
|
SupportsDark = true
|
||||||
SupportsLight = true
|
SupportsLight = true
|
||||||
|
|
||||||
@@ -20,4 +20,4 @@ ScrollBar = "#565656"
|
|||||||
Button = "#C8C8C8F0"
|
Button = "#C8C8C8F0"
|
||||||
DisabledButton = "#CDCDCDF0"
|
DisabledButton = "#CDCDCDF0"
|
||||||
Foreground = "#0A0A0A"
|
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 {
|
func NewMyTheme(config *backend.ThemeConfig, themeFileDir string) *MyTheme {
|
||||||
m := &MyTheme{config: config, themeFileDir: themeFileDir}
|
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()
|
m.createThemeIcons()
|
||||||
return m
|
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)
|
return colorOrDefault(colors.Foreground, defColors.Foreground, name, variant)
|
||||||
case theme.ColorNameHover:
|
case theme.ColorNameHover:
|
||||||
return colorOrDefault(colors.Hover, defColors.Hover, name, variant)
|
return colorOrDefault(colors.Hover, defColors.Hover, name, variant)
|
||||||
|
case theme.ColorNameHyperlink:
|
||||||
|
return colorOrDefault(colors.Hyperlink, defColors.Hyperlink, name, variant)
|
||||||
case theme.ColorNameInputBackground:
|
case theme.ColorNameInputBackground:
|
||||||
return colorOrDefault(colors.InputBackground, defColors.InputBackground, name, variant)
|
return colorOrDefault(colors.InputBackground, defColors.InputBackground, name, variant)
|
||||||
case theme.ColorNameInputBorder:
|
case theme.ColorNameInputBorder:
|
||||||
|
|||||||
+16
-1
@@ -15,6 +15,8 @@ import (
|
|||||||
"github.com/pelletier/go-toml/v2"
|
"github.com/pelletier/go-toml/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var validThemeVersions = []string{"0.1", "0.2"}
|
||||||
|
|
||||||
type ThemeFileHeader struct {
|
type ThemeFileHeader struct {
|
||||||
Name string
|
Name string
|
||||||
Version string
|
Version string
|
||||||
@@ -54,6 +56,9 @@ type ThemeColors struct {
|
|||||||
|
|
||||||
Hover string
|
Hover string
|
||||||
|
|
||||||
|
// since Supersonic theme file version 0.2 (Fyne version 2.4)
|
||||||
|
Hyperlink string
|
||||||
|
|
||||||
InputBackground string
|
InputBackground string
|
||||||
|
|
||||||
InputBorder string
|
InputBorder string
|
||||||
@@ -97,12 +102,13 @@ func DecodeThemeFile(reader io.Reader) (*ThemeFile, error) {
|
|||||||
return nil, err
|
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")
|
return nil, errors.New("invalid theme file name or version")
|
||||||
}
|
}
|
||||||
if !(theme.SupersonicTheme.SupportsDark || theme.SupersonicTheme.SupportsLight) {
|
if !(theme.SupersonicTheme.SupportsDark || theme.SupersonicTheme.SupportsLight) {
|
||||||
return nil, errors.New("invalid theme file: must support one or both of light/dark")
|
return nil, errors.New("invalid theme file: must support one or both of light/dark")
|
||||||
}
|
}
|
||||||
|
updateThemeToLatestVersion(theme)
|
||||||
|
|
||||||
return theme, nil
|
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
|
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