Sure, go ahead if you like.
Also, introduce a Rect type, maybe something like:
type Rect struct {
Left, Top, Bottom, Right int
}
func NewRect(x, y int, w, h int) Rect {
return Rect{x,y,x+w,y+h }
}
func (r Rect) Inset(pad Rect) Rect {
r.Left += p.Left
r.Top += p.Top
r.Right -= p.Right
r.Bottom -= p.Bottom
}
func (r Rect) Outset(margin Rect) Rect {
r.Left -= p.Left
r.Top -= p.Top
r.Right += p.Right
r.Bottom += p.Bottom
}
type Block struct {
Rect Rect
Padding Rect
inner Rect
Border labeledBorder
IsDisplay bool
HasBorder bool
BgColor Attribute
}
Alternatively:
type Rect struct {
X, Y int
W, H int
}
type Padding struct {
Left, Top, Right, Bottom int
}
It should make some of the code nicer.
PS. regarding the theme, you may want to also try out several other designs, e.g.
"": Attributes{ "bg": Attribute{}, "fg": Attribute{}, "line": Attribute{}}
"border": Attributes{ "bg": Attribute{}, "fg": Attribute{}}
"sparkline": Attributes{ "bg": Attribute{}, "fg": Attribute{}, "line": Attribute{}}
"sparkline.title": Attributes{ "bg": Attribute{}, "fg": Attribute{}}
I don't like the "remove the token before the last item", it isn't simple mechanic... maybe explicitly defining the widget and attributes for that widget is better?
Then you would have:
func (t Theme) Lookup(widget, attr string) Attribute {}
e.g.
Lookup("sparkline.title", "bg")
Lookup("sparkline", "bg")
Lookup("", "bg")
And would remove tokens only in the widget name,