Refactored the menu system

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:54 +01:00
1 parent 4ae7655cd8
commit 86aad51e37
12 files changed
+474 -344

No files matched your search

+23 -10
View File
@@ -40,7 +40,7 @@ var (
}
defaultGrayObjectStyle = ObjectStyle{
Background: image.Black,
BackgroundImage: image.Black,
BackgroundColor: color.Black,
ForegroundColor: color.White,
BorderColor: color.Gray{Y: 0xBF},
@@ -87,7 +87,7 @@ type Styles struct {
Graph ObjectStyle
}
func StylesFor(ctx Context) *Styles {
func StylesFor(model color.Model) *Styles {
theme := UserTheme
if theme == nil {
// Use the default theme.
@@ -105,7 +105,6 @@ func StylesFor(ctx Context) *Styles {
}
}
model := ctx.Display().ColorModel()
switch model {
case pixel.MonoModel:
return theme.Mono
@@ -118,11 +117,11 @@ func StylesFor(ctx Context) *Styles {
type ObjectStyle struct {
// Background image or color.
Background image.Image
BackgroundImage image.Image
BackgroundColor color.Color
// Foreground image (mask) or color.
Foreground image.Image
ForegroundImage image.Image
ForegroundColor color.Color
// Margin around the object.
@@ -139,10 +138,24 @@ type ObjectStyle struct {
Stroke int
}
func (s ObjectStyle) Background() image.Image {
if s.BackgroundImage == nil {
return image.NewUniform(s.BackgroundColor)
}
return s.BackgroundImage
}
func (s ObjectStyle) Foreground() image.Image {
if s.ForegroundImage == nil {
return image.NewUniform(s.ForegroundColor)
}
return s.ForegroundImage
}
func (s ObjectStyle) WithBackgroundColor(c color.Color) ObjectStyle {
i := new(ObjectStyle)
*i = s
i.Background = nil
i.BackgroundImage = nil
i.BackgroundColor = c
return *i
}
@@ -150,7 +163,7 @@ func (s ObjectStyle) WithBackgroundColor(c color.Color) ObjectStyle {
func (s ObjectStyle) WithForegroundColor(c color.Color) ObjectStyle {
i := new(ObjectStyle)
*i = s
i.Foreground = nil
i.ForegroundImage = nil
i.ForegroundColor = c
return *i
}
@@ -158,7 +171,7 @@ func (s ObjectStyle) WithForegroundColor(c color.Color) ObjectStyle {
func (s ObjectStyle) Inverse() ObjectStyle {
i := new(ObjectStyle)
*i = s
i.Background, i.Foreground = i.Foreground, i.Background
i.BackgroundImage, i.ForegroundImage = i.ForegroundImage, i.BackgroundImage
i.BackgroundColor, i.ForegroundColor = i.ForegroundColor, i.BackgroundColor
return *i
}
@@ -270,7 +283,7 @@ type TextStyle struct {
func (s TextStyle) WithBackgroundColor(c color.Color) TextStyle {
i := new(TextStyle)
*i = s
i.Background = nil
i.BackgroundImage = nil
i.BackgroundColor = c
return *i
}
@@ -278,7 +291,7 @@ func (s TextStyle) WithBackgroundColor(c color.Color) TextStyle {
func (s TextStyle) WithForegroundColor(c color.Color) TextStyle {
i := new(TextStyle)
*i = s
i.Foreground = nil
i.ForegroundImage = nil
i.ForegroundColor = c
return *i
}