Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:41 +01:00
1 parent 85a9ec684c
commit c5d6137fab
160 files changed
+76293 -387

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
package config
import (
"image/color"
"strings"
"github.com/BeatGlow/beatglow/ui"
"github.com/BeatGlow/beatglow/ui/font"
"github.com/mazznoer/csscolorparser"
"github.com/sirupsen/logrus"
)
type Style struct {
Color string `hcl:"color,optional"`
Font string `hcl:"font,optional"`
FontSize float64 `hcl:"font_size,optional"`
Hinting string `hcl:"hinting,optional"`
DPI float64 `hcl:"dpi,optional"`
}
// Apply styles; errors are logged but don't override styles, so we don't break visuals.
func (s Style) Apply(style *ui.Style) {
if s.Color != "" {
c, err := csscolorparser.Parse(s.Color)
if err != nil {
logrus.WithError(err).WithField("color", s.Color).Warn("invalid color name")
} else {
r, g, b, a := c.RGBA255()
style.Foreground = color.RGBA{r, g, b, a}
}
}
if s.Font != "" {
switch s.Font {
case "monteserrat":
style.Font = font.Montserrat
case "monaco":
style.Font = font.Monaco
case "mairy":
style.Font = font.MairyBlackItalic
case "microgrotesk":
style.Font = font.MicroGrotesk
default:
f, err := font.New(s.Font)
if err != nil {
logrus.WithError(err).WithField("font", s.Font).Warn("font failed to load")
} else {
attr := style.Font.Attr()
style.Font = f
style.Font.SetDPI(attr.DPI)
style.Font.SetHinting(attr.Hinting)
style.Font.SetLineSpacing(attr.LineSpacing)
style.Font.SetPointSize(attr.PointSize)
}
}
}
if s.FontSize > 0 {
style.Font.SetPointSize(s.FontSize)
}
if s.DPI > 0 {
style.Font.SetDPI(s.DPI)
}
switch strings.ToLower(s.Hinting) {
case "": // use default
case "none", "no", "false":
style.Font.SetHinting(font.HintingNone)
case "vertical":
style.Font.SetHinting(font.HintingVertical)
case "full", "yes":
style.Font.SetHinting(font.HintingFull)
default:
logrus.WithField("hinting", s.Hinting).Warn("font hinting invalid")
}
}