-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Theme API 2
We want to support adding items to app themes without breaking API compatibility. Also to allow people to easily load variations on the standard theme, such as setting primary colour etc.
The current theme consists of a fyne.Theme
interface that any theme must implement, and the theme
package which has many functions that mirror these features for accessing the current theme.
My proposal is that we completely change the theme interface and push developers to utilise the theme package functions in their app. A new theme API would be "future proof" by using extensible lookups instead of simple methods that return single values. For example:
type Variant uint
type ColorName string
type SizeName string
const (
DarkTheme Variant = iota
LightTheme
// potential for adding theme types such as high visibility or monochrome...
BackgroundColor ColorName = "background"
TextColor ColorName = "text"
// etc etc
PaddingSize SizeName = "padding"
TextSize SizeName = "text"
)
type Theme interface {
Color(ColorName, Variant) color.Color
Size(SizeName) int
Font(TextStyle) fyne.Resource
}
An approach like this would allow us to use something like a JSON store or other mapping to store the values. A loaded theme could provide all the values, or delegate to a builtin fallback. Certain APIs such as "ThemeFromJSON" would load from a JSON string or "ThemeFromTheme" could create a new theme in code that overloads the values from the default theme...