diff --git a/src/config.go b/src/config.go index 5b479b6..00e2b6f 100644 --- a/src/config.go +++ b/src/config.go @@ -274,6 +274,7 @@ func (config *Config) ToggleDebugging() { func (config *Config) SwitchTheme(theme string) { config.ThemeManager.SetCurrentTheme(theme) + config.RestartCache = true } func (config *Config) ToggleGridlines() { diff --git a/src/options.go b/src/options.go index 556c939..969f57c 100644 --- a/src/options.go +++ b/src/options.go @@ -113,8 +113,15 @@ func (scene *SceneOptions) Init() { scene.Config.ToggleWrap() }) + themenames := make([]string, len(THEMES)) + i := 0 + for name := range THEMES { + themenames[i] = name + i++ + } + themes := NewCombobox( - []string{"dark", "light"}, + themenames, scene.Config.Theme, func(args *widget.ListComboButtonEntrySelectedEventArgs) { scene.Config.SwitchTheme(args.Entry.(ListEntry).Name) diff --git a/src/theme.go b/src/theme.go index 20ba9f9..d13a1e1 100644 --- a/src/theme.go +++ b/src/theme.go @@ -30,20 +30,56 @@ type Theme struct { Name string } +type ThemeDef struct { + life, dead, grid, old, age1, age2, age3, age4 string +} + +var THEMES = map[string]ThemeDef{ + "standard": { + life: "e15f0b", + dead: "5a5a5a", + grid: "e13c0b", + old: "7b5e4b", + age1: "735f52", + age2: "6c6059", + age3: "635d59", + age4: "808080", + }, + "dark": { + life: "c8c8c8", + dead: "000000", + grid: "ff1e1e", + old: "522600", + age1: "422300", + age2: "2b1b00", + age3: "191100", + age4: "808080", + }, + "light": { + life: "000000", + dead: "c8c8c8", + grid: "ff1e1e", + old: "ffc361", + age1: "ffd38c", + age2: "ffe3b5", + age3: "fff0e0", + age4: "808080", + }, +} + // create a new theme -func NewTheme(life, dead, old, age1, age2, age3, age4, grid string, - cellsize int, name string) Theme { +func NewTheme(def ThemeDef, cellsize int, name string) Theme { theme := Theme{ Name: name, Colors: map[int]color.RGBA{ - ColLife: HexColor2RGBA(life), - ColDead: HexColor2RGBA(dead), - ColGrid: HexColor2RGBA(grid), - ColAge1: HexColor2RGBA(age1), - ColAge2: HexColor2RGBA(age2), - ColAge3: HexColor2RGBA(age3), - ColAge4: HexColor2RGBA(age4), - ColOld: HexColor2RGBA(old), + ColLife: HexColor2RGBA(def.life), + ColDead: HexColor2RGBA(def.dead), + ColGrid: HexColor2RGBA(def.grid), + ColAge1: HexColor2RGBA(def.age1), + ColAge2: HexColor2RGBA(def.age2), + ColAge3: HexColor2RGBA(def.age3), + ColAge4: HexColor2RGBA(def.age4), + ColOld: HexColor2RGBA(def.old), }, } @@ -75,54 +111,16 @@ type ThemeManager struct { // Manager is used to easily switch themes from cli or menu func NewThemeManager(initial string, cellsize int) ThemeManager { - light := NewTheme( - "000000", // life - "c8c8c8", // dead - "ff1e1e", // old - "ffc361", // age 1..4 - "ffd38c", - "ffe3b5", - "fff0e0", - "808080", // grid - cellsize, - "light", - ) - - dark := NewTheme( - "c8c8c8", // life - "000000", // dead - "ff1e1e", // old - "522600", // age 1..4 - "422300", - "2b1b00", - "191100", - "808080", // grid - cellsize, - "dark", - ) - - standard := NewTheme( - "e15f0b", // life - "5a5a5a", // dead - "e13c0b", // old - "7b5e4b", // age 1..4 - "735f52", - "6c6059", - "635d59", - "808080", // grid - cellsize, - "dark", - ) - manager := ThemeManager{ - Themes: map[string]Theme{ - "dark": dark, - "light": light, - "standard": standard, - }, Theme: initial, } + manager.Themes = make(map[string]Theme, len(THEMES)) + + for name, def := range THEMES { + manager.Themes[name] = NewTheme(def, cellsize, name) + } + return manager } diff --git a/src/widgets.go b/src/widgets.go index eb6114e..e27a4c8 100644 --- a/src/widgets.go +++ b/src/widgets.go @@ -129,7 +129,9 @@ func NewCombobox(items []string, selected string, ), widget.ListComboButtonOpts.ListOpts( //Set how wide the dropdown list should be - widget.ListOpts.ContainerOpts(widget.ContainerOpts.WidgetOpts(widget.WidgetOpts.MinSize(50, 0))), + widget.ListOpts.ContainerOpts( + widget.ContainerOpts.WidgetOpts(widget.WidgetOpts.MinSize(50, 0)), + ), //Set the entries in the list widget.ListOpts.Entries(entries), widget.ListOpts.ScrollContainerOpts( @@ -152,16 +154,15 @@ func NewCombobox(items []string, selected string, //Set the font for the list options widget.ListOpts.EntryFontFace(*FontRenderer.FontSmall), //Set the colors for the list - // FIXME: Change to our own color set widget.ListOpts.EntryColor(&widget.ListEntryColor{ - Selected: color.NRGBA{254, 255, 255, 255}, //Foreground color for the unfocused selected entry - Unselected: color.NRGBA{254, 255, 255, 255}, //Foreground color for the unfocused unselected entry - SelectedBackground: color.NRGBA{R: 130, G: 130, B: 200, A: 255}, //Background color for the unfocused selected entry - SelectedFocusedBackground: color.NRGBA{R: 130, G: 130, B: 170, A: 255}, //Background color for the focused selected entry - FocusedBackground: color.NRGBA{R: 170, G: 170, B: 180, A: 255}, //Background color for the focused unselected entry - DisabledUnselected: color.NRGBA{100, 100, 100, 255}, //Foreground color for the disabled unselected entry - DisabledSelected: color.NRGBA{100, 100, 100, 255}, //Foreground color for the disabled selected entry - DisabledSelectedBackground: color.NRGBA{100, 100, 100, 255}, //Background color for the disabled selected entry + Selected: color.NRGBA{254, 255, 255, 255}, + Unselected: color.NRGBA{254, 255, 255, 255}, + SelectedBackground: HexColor2RGBA(THEMES["standard"].life), + SelectedFocusedBackground: HexColor2RGBA(THEMES["standard"].old), + FocusedBackground: HexColor2RGBA(THEMES["standard"].old), + DisabledUnselected: HexColor2RGBA(THEMES["standard"].grid), + DisabledSelected: HexColor2RGBA(THEMES["standard"].grid), + DisabledSelectedBackground: HexColor2RGBA(THEMES["standard"].grid), }), //Padding for each entry widget.ListOpts.EntryTextPadding(widget.NewInsetsSimple(5)),