fixed theme selection from menu, centralized theme def to 1 place

This commit is contained in:
2024-06-09 18:00:06 +02:00
parent 01cfaf3b78
commit 3a743a65e5
4 changed files with 72 additions and 65 deletions

View File

@@ -274,6 +274,7 @@ func (config *Config) ToggleDebugging() {
func (config *Config) SwitchTheme(theme string) { func (config *Config) SwitchTheme(theme string) {
config.ThemeManager.SetCurrentTheme(theme) config.ThemeManager.SetCurrentTheme(theme)
config.RestartCache = true
} }
func (config *Config) ToggleGridlines() { func (config *Config) ToggleGridlines() {

View File

@@ -113,8 +113,15 @@ func (scene *SceneOptions) Init() {
scene.Config.ToggleWrap() scene.Config.ToggleWrap()
}) })
themenames := make([]string, len(THEMES))
i := 0
for name := range THEMES {
themenames[i] = name
i++
}
themes := NewCombobox( themes := NewCombobox(
[]string{"dark", "light"}, themenames,
scene.Config.Theme, scene.Config.Theme,
func(args *widget.ListComboButtonEntrySelectedEventArgs) { func(args *widget.ListComboButtonEntrySelectedEventArgs) {
scene.Config.SwitchTheme(args.Entry.(ListEntry).Name) scene.Config.SwitchTheme(args.Entry.(ListEntry).Name)

View File

@@ -30,20 +30,56 @@ type Theme struct {
Name string 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 // create a new theme
func NewTheme(life, dead, old, age1, age2, age3, age4, grid string, func NewTheme(def ThemeDef, cellsize int, name string) Theme {
cellsize int, name string) Theme {
theme := Theme{ theme := Theme{
Name: name, Name: name,
Colors: map[int]color.RGBA{ Colors: map[int]color.RGBA{
ColLife: HexColor2RGBA(life), ColLife: HexColor2RGBA(def.life),
ColDead: HexColor2RGBA(dead), ColDead: HexColor2RGBA(def.dead),
ColGrid: HexColor2RGBA(grid), ColGrid: HexColor2RGBA(def.grid),
ColAge1: HexColor2RGBA(age1), ColAge1: HexColor2RGBA(def.age1),
ColAge2: HexColor2RGBA(age2), ColAge2: HexColor2RGBA(def.age2),
ColAge3: HexColor2RGBA(age3), ColAge3: HexColor2RGBA(def.age3),
ColAge4: HexColor2RGBA(age4), ColAge4: HexColor2RGBA(def.age4),
ColOld: HexColor2RGBA(old), ColOld: HexColor2RGBA(def.old),
}, },
} }
@@ -75,54 +111,16 @@ type ThemeManager struct {
// Manager is used to easily switch themes from cli or menu // Manager is used to easily switch themes from cli or menu
func NewThemeManager(initial string, cellsize int) ThemeManager { 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{ manager := ThemeManager{
Themes: map[string]Theme{
"dark": dark,
"light": light,
"standard": standard,
},
Theme: initial, Theme: initial,
} }
manager.Themes = make(map[string]Theme, len(THEMES))
for name, def := range THEMES {
manager.Themes[name] = NewTheme(def, cellsize, name)
}
return manager return manager
} }

View File

@@ -129,7 +129,9 @@ func NewCombobox(items []string, selected string,
), ),
widget.ListComboButtonOpts.ListOpts( widget.ListComboButtonOpts.ListOpts(
//Set how wide the dropdown list should be //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 //Set the entries in the list
widget.ListOpts.Entries(entries), widget.ListOpts.Entries(entries),
widget.ListOpts.ScrollContainerOpts( widget.ListOpts.ScrollContainerOpts(
@@ -152,16 +154,15 @@ func NewCombobox(items []string, selected string,
//Set the font for the list options //Set the font for the list options
widget.ListOpts.EntryFontFace(*FontRenderer.FontSmall), widget.ListOpts.EntryFontFace(*FontRenderer.FontSmall),
//Set the colors for the list //Set the colors for the list
// FIXME: Change to our own color set
widget.ListOpts.EntryColor(&widget.ListEntryColor{ widget.ListOpts.EntryColor(&widget.ListEntryColor{
Selected: color.NRGBA{254, 255, 255, 255}, //Foreground color for the unfocused selected entry Selected: color.NRGBA{254, 255, 255, 255},
Unselected: color.NRGBA{254, 255, 255, 255}, //Foreground color for the unfocused unselected entry Unselected: color.NRGBA{254, 255, 255, 255},
SelectedBackground: color.NRGBA{R: 130, G: 130, B: 200, A: 255}, //Background color for the unfocused selected entry SelectedBackground: HexColor2RGBA(THEMES["standard"].life),
SelectedFocusedBackground: color.NRGBA{R: 130, G: 130, B: 170, A: 255}, //Background color for the focused selected entry SelectedFocusedBackground: HexColor2RGBA(THEMES["standard"].old),
FocusedBackground: color.NRGBA{R: 170, G: 170, B: 180, A: 255}, //Background color for the focused unselected entry FocusedBackground: HexColor2RGBA(THEMES["standard"].old),
DisabledUnselected: color.NRGBA{100, 100, 100, 255}, //Foreground color for the disabled unselected entry DisabledUnselected: HexColor2RGBA(THEMES["standard"].grid),
DisabledSelected: color.NRGBA{100, 100, 100, 255}, //Foreground color for the disabled selected entry DisabledSelected: HexColor2RGBA(THEMES["standard"].grid),
DisabledSelectedBackground: color.NRGBA{100, 100, 100, 255}, //Background color for the disabled selected entry DisabledSelectedBackground: HexColor2RGBA(THEMES["standard"].grid),
}), }),
//Padding for each entry //Padding for each entry
widget.ListOpts.EntryTextPadding(widget.NewInsetsSimple(5)), widget.ListOpts.EntryTextPadding(widget.NewInsetsSimple(5)),