prettyfyne

package module
v0.0.0-...-4f2d209 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2021 License: MIT Imports: 14 Imported by: 3

README

prettyfyne

This is a tool to assist with building, and using themes for fyne, a golang graphical user interface library.

prettyfyne Theme Editor prettyfyne Theme Editor

Included here are:

  • A graphical interface for changing theme settings, with ability to view yaml and Go source representations.
  • Utilities for more easily loading and exchanging themes via yaml files.
  • A few example themes.

This is very early in the development stage, so much is missing like better color pallets, a variety of pre-built themes, unit tests, actually ... testing of any kind.

for examples see the _example folder.

Usage

  1. Import Yaml theme from a saved configuration file
  2. override default values to fine-tune an existing theme
  3. create/edit/load entirely new themes

All three are in _example directory.

Quick example, building a theme from scratch:
package main

import (
	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/theme"
	"fyne.io/fyne/widget"
	"github.com/blockpane/prettyfyne"
	"image/color"
	"time"
)

func main()  {
	a := app.New()
	w := a.NewWindow("Pretty Fyne - PrettyTheme Example")

	myTheme := prettyfyne.PrettyTheme{
		BackgroundColor:        color.RGBA{R: 30, G: 30, B: 30, A: 255},
		ButtonColor:            color.RGBA{R: 20, G: 20, B: 20, A: 255},
		DisabledButtonColor:    color.RGBA{R: 15, G: 15, B: 17, A: 255},
		HyperlinkColor:         color.RGBA{R: 170, G:100, B:20, A: 64},
		TextColor:              color.RGBA{R: 200, G: 200, B: 200, A: 255},
		DisabledTextColor:      color.RGBA{R: 155, G: 155, B: 155, A: 127},
		IconColor:              color.RGBA{R: 150, G: 80, B: 0, A: 255},
		DisabledIconColor:      color.RGBA{R: 155, G: 155, B: 155, A: 127},
		PlaceHolderColor:       color.RGBA{R: 150, G: 80, B: 0, A: 255},
		PrimaryColor:           color.RGBA{R: 110, G: 40, B: 0, A: 127},
		HoverColor:             color.RGBA{R: 110, G: 40, B: 0, A: 127},
		FocusColor:             color.RGBA{R: 99, G: 99, B: 99, A: 255},
		ScrollBarColor:         color.RGBA{R: 35, G: 35, B: 35, A: 8},
		ShadowColor:            color.RGBA{R: 0, G: 0, B: 0, A: 64},
		TextSize:               13,
		TextFont:               theme.DarkTheme().TextFont(),
		TextBoldFont:           theme.DarkTheme().TextBoldFont(),
		TextItalicFont:         theme.DarkTheme().TextItalicFont(),
		TextBoldItalicFont:     theme.DarkTheme().TextBoldItalicFont(),
		TextMonospaceFont:      theme.DarkTheme().TextMonospaceFont(),
		Padding:                4,
		IconInlineSize:         24,
		ScrollBarSize:          10,
		ScrollBarSmallSize:     4,
	}

	hello := widget.NewLabel("Hello Pretty Fyne!")

	w.SetContent(widget.NewVBox(
		hello,
		widget.NewButton("Quit", func() {
			a.Quit()
		}),
	))

	// applying a theme before the window is running will cause a panic, aggressively wait for it to be present
	go func(){
		for {
			time.Sleep(50 * time.Millisecond)
			if hello.Visible() {
				break
			}
		}
		fyne.CurrentApp().Settings().SetTheme(myTheme.ToFyneTheme())
	}()

	w.CenterOnScreen()
	w.ShowAndRun()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExampleCubicleLife = PrettyTheme{
	BackgroundColor:     &color.RGBA{R: 0xd3, G: 0xd3, B: 0xd3, A: 0xff},
	ButtonColor:         &color.RGBA{R: 0xbf, G: 0xbf, B: 0xbf, A: 0xff},
	DisabledButtonColor: &color.RGBA{R: 0x87, G: 0x87, B: 0x87, A: 0xff},
	HyperlinkColor:      &color.RGBA{R: 0x0, G: 0x33, B: 0xff, A: 0xff},
	TextColor:           &color.RGBA{R: 0x0, G: 0x0, B: 0x0, A: 0xff},
	DisabledTextColor:   &color.RGBA{R: 0x1a, G: 0x1a, B: 0x1a, A: 0xff},
	IconColor:           &color.RGBA{R: 0x25, G: 0x25, B: 0x25, A: 0xff},
	DisabledIconColor:   &color.RGBA{R: 0xa9, G: 0xa9, B: 0xa9, A: 0xff},
	PlaceHolderColor:    &color.RGBA{R: 0x94, G: 0x94, B: 0x94, A: 0xff},
	PrimaryColor:        &color.RGBA{R: 0x33, G: 0x66, B: 0xcc, A: 0xf0},
	HoverColor:          &color.RGBA{R: 0x8f, G: 0x8f, B: 0x8f, A: 0xff},
	FocusColor:          &color.RGBA{R: 0xa7, G: 0xbd, B: 0xdf, A: 0xff},
	ScrollBarColor:      &color.RGBA{R: 0x4d, G: 0x4d, B: 0x4d, A: 0xff},
	ShadowColor:         &color.RGBA{R: 0x0, G: 0x0, B: 0x0, A: 0x40},
	TextSize:            15,
	TextFont:            theme.DarkTheme().TextFont(),
	TextBoldFont:        theme.DarkTheme().TextBoldFont(),
	TextItalicFont:      theme.DarkTheme().TextItalicFont(),
	TextBoldItalicFont:  theme.DarkTheme().TextBoldItalicFont(),
	TextMonospaceFont:   theme.DarkTheme().TextMonospaceFont(),
	Padding:             6,
	IconInlineSize:      32,
	ScrollBarSize:       10,
	ScrollBarSmallSize:  4,
}
View Source
var ExampleDracula = PrettyTheme{
	BackgroundColor:     &color.RGBA{R: 0x0, G: 0x0, B: 0x0, A: 0xff},
	ButtonColor:         &color.RGBA{R: 0xf, G: 0xf, B: 0xf, A: 0xff},
	DisabledButtonColor: &color.RGBA{R: 0xf, G: 0xf, B: 0x11, A: 0xff},
	HyperlinkColor:      &color.RGBA{R: 0x0, G: 0x41, B: 0x78, A: 0xff},
	TextColor:           &color.RGBA{R: 0xaf, G: 0xaf, B: 0xaf, A: 0xff},
	DisabledTextColor:   &color.RGBA{R: 0x4e, G: 0x4e, B: 0x4e, A: 0xff},
	IconColor:           &color.RGBA{R: 0x53, G: 0x0, B: 0x0, A: 0xff},
	DisabledIconColor:   &color.RGBA{R: 0x21, G: 0x21, B: 0x21, A: 0xff},
	PlaceHolderColor:    &color.RGBA{R: 0x64, G: 0x14, B: 0x27, A: 0xff},
	PrimaryColor:        &color.RGBA{R: 0x50, G: 0x0, B: 0x13, A: 0xff},
	HoverColor:          &color.RGBA{R: 0x1a, G: 0x12, B: 0xe, A: 0xff},
	FocusColor:          &color.RGBA{R: 0x28, G: 0x0, B: 0x9, A: 0x80},
	ScrollBarColor:      &color.RGBA{R: 0x23, G: 0x23, B: 0x23, A: 0x8},
	ShadowColor:         &color.RGBA{R: 0x12, G: 0x12, B: 0x12, A: 0xff},
	TextSize:            16,
	TextFont:            theme.DarkTheme().TextFont(),
	TextBoldFont:        theme.DarkTheme().TextBoldFont(),
	TextItalicFont:      theme.DarkTheme().TextItalicFont(),
	TextBoldItalicFont:  theme.DarkTheme().TextBoldItalicFont(),
	TextMonospaceFont:   theme.DarkTheme().TextMonospaceFont(),
	Padding:             3,
	IconInlineSize:      23,
	ScrollBarSize:       10,
	ScrollBarSmallSize:  4,
}
View Source
var ExampleEveryDayIsHalloween = PrettyTheme{
	BackgroundColor:     color.RGBA{R: 30, G: 30, B: 30, A: 255},
	ButtonColor:         color.RGBA{R: 20, G: 20, B: 20, A: 255},
	DisabledButtonColor: color.RGBA{R: 15, G: 15, B: 17, A: 255},
	HyperlinkColor:      color.RGBA{R: 0xaa, G: 0x64, B: 0x14, A: 0x40},
	TextColor:           color.RGBA{R: 200, G: 200, B: 200, A: 255},
	DisabledTextColor:   color.RGBA{R: 155, G: 155, B: 155, A: 127},
	IconColor:           color.RGBA{R: 150, G: 80, B: 0, A: 255},
	DisabledIconColor:   color.RGBA{R: 155, G: 155, B: 155, A: 127},
	PlaceHolderColor:    color.RGBA{R: 150, G: 80, B: 0, A: 255},
	PrimaryColor:        color.RGBA{R: 110, G: 40, B: 0, A: 127},
	HoverColor:          color.RGBA{R: 0, G: 0, B: 0, A: 255},
	FocusColor:          color.RGBA{R: 99, G: 99, B: 99, A: 255},
	ScrollBarColor:      color.RGBA{R: 35, G: 35, B: 35, A: 8},
	ShadowColor:         color.RGBA{R: 0, G: 0, B: 0, A: 64},
	TextSize:            13,
	TextFont:            theme.DarkTheme().TextFont(),
	TextBoldFont:        theme.DarkTheme().TextBoldFont(),
	TextItalicFont:      theme.DarkTheme().TextItalicFont(),
	TextBoldItalicFont:  theme.DarkTheme().TextBoldItalicFont(),
	TextMonospaceFont:   theme.DarkTheme().TextMonospaceFont(),
	Padding:             4,
	IconInlineSize:      24,
	ScrollBarSize:       10,
	ScrollBarSmallSize:  4,
}
View Source
var ExampleMaterialLight = PrettyTheme{
	BackgroundColor:     color.RGBA{255, 255, 255, 255},
	ButtonColor:         color.RGBA{0, 0, 0, 10},
	DisabledButtonColor: color.RGBA{0, 0, 0, 30},
	HyperlinkColor:      color.RGBA{100, 181, 246, 253},
	TextColor:           color.RGBA{0, 0, 0, 222},
	DisabledTextColor:   color.RGBA{94, 94, 94, 255},
	IconColor:           color.RGBA{100, 181, 246, 253},
	DisabledIconColor:   color.RGBA{0, 0, 0, 97},
	PlaceHolderColor:    color.RGBA{178, 178, 178, 255},
	PrimaryColor:        color.RGBA{166, 212, 250, 255},
	HoverColor:          color.RGBA{0, 0, 0, 30},
	FocusColor:          color.RGBA{198, 198, 198, 224},
	ScrollBarColor:      color.RGBA{0, 0, 0, 153},
	ShadowColor:         color.RGBA{0, 0, 0, 66},
	TextSize:            13,
	TextFont:            theme.LightTheme().TextFont(),
	TextBoldFont:        theme.LightTheme().TextBoldFont(),
	TextItalicFont:      theme.LightTheme().TextItalicFont(),
	TextBoldItalicFont:  theme.LightTheme().TextBoldItalicFont(),
	TextMonospaceFont:   theme.LightTheme().TextMonospaceFont(),
	Padding:             4,
	IconInlineSize:      24,
	ScrollBarSize:       12,
	ScrollBarSmallSize:  3,
}
View Source
var ExampleTree = PrettyTheme{
	BackgroundColor:     &color.RGBA{R: 0x70, G: 0x78, B: 0x4c, A: 0xf0},
	ButtonColor:         &color.RGBA{R: 0x70, G: 0x78, B: 0x4c, A: 0xd2},
	DisabledButtonColor: &color.RGBA{R: 0x70, G: 0x78, B: 0x4c, A: 0xff},
	HyperlinkColor:      &color.RGBA{R: 0x1, G: 0x24, B: 0x1, A: 0xff},
	TextColor:           &color.RGBA{R: 0x0, G: 0x0, B: 0x0, A: 0xff},
	DisabledTextColor:   &color.RGBA{R: 0x2a, G: 0x32, B: 0x6, A: 0xff},
	IconColor:           &color.RGBA{R: 0x3c, G: 0x34, B: 0xf, A: 0xff},
	DisabledIconColor:   &color.RGBA{R: 0x5c, G: 0x64, B: 0x38, A: 0xff},
	PlaceHolderColor:    &color.RGBA{R: 0x57, G: 0x2c, B: 0x1, A: 0xff},
	PrimaryColor:        &color.RGBA{R: 0x70, G: 0x78, B: 0x4c, A: 0xb4},
	HoverColor:          &color.RGBA{R: 0x70, G: 0x78, B: 0x4c, A: 0xc8},
	FocusColor:          &color.RGBA{R: 0xa0, G: 0x96, B: 0x32, A: 0xff},
	ScrollBarColor:      &color.RGBA{R: 0x23, G: 0x23, B: 0x23, A: 0x8},
	ShadowColor:         &color.RGBA{R: 0x0, G: 0x0, B: 0x0, A: 0x40},
	TextSize:            15,
	TextFont:            theme.DarkTheme().TextFont(),
	TextBoldFont:        theme.DarkTheme().TextBoldFont(),
	TextItalicFont:      theme.DarkTheme().TextItalicFont(),
	TextBoldItalicFont:  theme.DarkTheme().TextBoldItalicFont(),
	TextMonospaceFont:   theme.DarkTheme().TextMonospaceFont(),
	Padding:             4,
	IconInlineSize:      28,
	ScrollBarSize:       10,
	ScrollBarSmallSize:  4,
}
View Source
var MaterialLight = []color.Color{
	color.RGBA{0xa6, 0xd4, 0xfa, 0xff},
	color.RGBA{0xf6, 0xa5, 0xc0, 0xff},
	color.RGBA{0xe5, 0x73, 0x73, 0xff},
	color.RGBA{0xff, 0xb7, 0x4d, 0xff},
	color.RGBA{0x64, 0xb5, 0xf6, 0xff},
	color.RGBA{0x81, 0xc7, 0x84, 0xff},
}
View Source
var MaterialTypographyLight = []color.Color{
	color.RGBA{0, 0, 0, 222},
	color.RGBA{0, 0, 0, 138},
	color.RGBA{0, 0, 0, 66},
	color.RGBA{0xfa, 0xfa, 0xfa, 0xff},
	color.RGBA{0, 0, 0, 30},
	color.RGBA{0, 0, 0, 10},
	color.RGBA{0, 0, 0, 97},
	color.RGBA{0xff, 0xff, 0xff, 0xff},
}

Functions

func GetFonts

func GetFonts() (fonts map[string]string, err error)

GetFonts provides a map containing a list of fonts and their location based on system defaults, TODO: for now only works on MacOS

func LoadFont

func LoadFont(path string, name string, fallbackFont Font) (font fyne.Resource, err error)

LoadFont gives a best-effort attempt at loading a font, and returns the default font if it fails

func PalletMap

func PalletMap() map[string][]color.Color

Types

type Font

type Font string
const (
	FontDefault    Font = "NotoSans-Regular.ttf"
	FontBold       Font = "NotoSans-Bold.ttf"
	FontItalic     Font = "NotoSans-Italic.ttf"
	FontBoldItalic Font = "NotoSans-BoldItalic.ttf"
	FontMono       Font = "NotoMono-Regular.ttf"
)

type PrettyTheme

type PrettyTheme struct {
	BackgroundColor     color.Color
	ButtonColor         color.Color
	DisabledButtonColor color.Color
	HyperlinkColor      color.Color
	TextColor           color.Color
	DisabledTextColor   color.Color
	IconColor           color.Color
	DisabledIconColor   color.Color
	PlaceHolderColor    color.Color
	PrimaryColor        color.Color
	HoverColor          color.Color
	FocusColor          color.Color
	ScrollBarColor      color.Color
	ShadowColor         color.Color
	TextSize            int
	TextFont            fyne.Resource

	TextBoldFont fyne.Resource

	TextItalicFont fyne.Resource

	TextBoldItalicFont fyne.Resource

	TextMonospaceFont fyne.Resource

	Padding            int
	IconInlineSize     int
	ScrollBarSize      int
	ScrollBarSmallSize int
	// contains filtered or unexported fields
}

func DefaultLightTheme

func DefaultLightTheme() *PrettyTheme

DefaultLightTheme returns the default fyne light theme, which provides an easy starting point for customization

func DefaultTheme

func DefaultTheme() *PrettyTheme

DefaultTheme returns the default fyne dark theme, which provides an easy starting point for customization

func UnmarshalYaml

func UnmarshalYaml(y []byte) (pt *PrettyTheme, fontsLoaded bool, err error)

UnmarshalYaml will override the default theme settings with what is stored in a yaml file. All fields are optional and will fall back to the default if not set. It will always return a populated theme, even if it cannot load fonts.

func (PrettyTheme) MarshalYaml

func (pt PrettyTheme) MarshalYaml() ([]byte, error)

func (PrettyTheme) ToConfig

func (pt PrettyTheme) ToConfig() PrettyThemeConfig

func (PrettyTheme) ToFyneTheme

func (pt PrettyTheme) ToFyneTheme() fyne.Theme

ToFyneTheme converts a PrettyTheme to the fyne.Theme interface that can be applied to the app

type PrettyThemeConfig

type PrettyThemeConfig struct {
	BackgroundColor        *color.RGBA `yaml:"background_color,omitempty"`
	ButtonColor            *color.RGBA `yaml:"button_color,omitempty"`
	DisabledButtonColor    *color.RGBA `yaml:"disabled_button_color,omitempty"`
	HyperlinkColor         *color.RGBA `yaml:"hyperlink_color,omitempty"`
	TextColor              *color.RGBA `yaml:"text_color,omitempty"`
	DisabledTextColor      *color.RGBA `yaml:"disabled_text_color,omitempty"`
	IconColor              *color.RGBA `yaml:"icon_color,omitempty"`
	DisabledIconColor      *color.RGBA `yaml:"disabled_icon_color,omitempty"`
	PlaceHolderColor       *color.RGBA `yaml:"place_holder_color,omitempty"`
	PrimaryColor           *color.RGBA `yaml:"primary_color,omitempty"`
	HoverColor             *color.RGBA `yaml:"hover_color,omitempty"`
	FocusColor             *color.RGBA `yaml:"focus_color,omitempty"`
	ScrollBarColor         *color.RGBA `yaml:"scroll_bar_color,omitempty"`
	ShadowColor            *color.RGBA `yaml:"shadow_color,omitempty"`
	TextSize               int         `yaml:"text_size,omitempty"`
	TextFontPath           string      `yaml:"text_font_path,omitempty"`
	TextFont               string      `yaml:"text_font,omitempty"`
	TextBoldFontPath       string      `yaml:"text_bold_font_path,omitempty"`
	TextBoldFont           string      `yaml:"text_bold_font,omitempty"`
	TextItalicFontPath     string      `yaml:"text_italic_font_path,omitempty"`
	TextItalicFont         string      `yaml:"text_italic_font,omitempty"`
	TextBoldItalicFontPath string      `yaml:"text_bold_italic_font_path,omitempty"`
	TextBoldItalicFont     string      `yaml:"text_bold_italic_font,omitempty"`
	TextMonospaceFontPath  string      `yaml:"text_monospace_font_path,omitempty"`
	TextMonospaceFont      string      `yaml:"text_monospace_font,omitempty"`
	Padding                int         `yaml:"padding,omitempty"`
	IconInlineSize         int         `yaml:"icon_inline_size,omitempty"`
	ScrollBarSize          int         `yaml:"scroll_bar_size,omitempty"`
	ScrollBarSmallSize     int         `yaml:"scroll_bar_small_size,omitempty"`
}

PrettyThemeConfig is used for serialization and loading from yaml

Directories

Path Synopsis
_example
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL