mirror of
https://codeberg.org/scip/golsky.git
synced 2025-12-16 20:20:57 +01:00
fixed theme selection from menu, centralized theme def to 1 place
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
106
src/theme.go
106
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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)),
|
||||
|
||||
Reference in New Issue
Block a user