From 68cb1fc719a93b91c6e2770e151514d7b4de5b37 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Fri, 3 Nov 2023 17:40:53 -0700 Subject: [PATCH] update theme and themefile syntax now that HyperlinkColor exists in Fyne --- res/bundled.go | 2 +- res/themes/default.toml | 4 ++-- ui/theme/theme.go | 7 ++++++- ui/theme/themefile.go | 17 ++++++++++++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/res/bundled.go b/res/bundled.go index 0cd5803..d8f79e0 100644 --- a/res/bundled.go +++ b/res/bundled.go @@ -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", diff --git a/res/themes/default.toml b/res/themes/default.toml index a7c0dc7..a126d3a 100644 --- a/res/themes/default.toml +++ b/res/themes/default.toml @@ -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" \ No newline at end of file +Hyperlink = "#3737FB" \ No newline at end of file diff --git a/ui/theme/theme.go b/ui/theme/theme.go index 889edd9..bd5594d 100644 --- a/ui/theme/theme.go +++ b/ui/theme/theme.go @@ -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: diff --git a/ui/theme/themefile.go b/ui/theme/themefile.go index 6cf2112..fab4a65 100644 --- a/ui/theme/themefile.go +++ b/ui/theme/themefile.go @@ -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 + } +}