Compare commits

...

2 Commits

Author SHA1 Message Date
c785fb461c Colors now operate more sensibly 2023-08-09 15:13:19 -04:00
487471d7a9 Add colors 2023-08-09 12:08:17 -04:00
2 changed files with 24 additions and 0 deletions

View File

@@ -45,6 +45,10 @@ func (broadcaster *Broadcaster[L]) ensure () {
}
}
// NoCookie is a cookie that does nothing when closed.
type NoCookie struct { }
func (NoCookie) Close () { }
type cookie[L any] struct {
id int
broadcaster *Broadcaster[L]

View File

@@ -23,12 +23,30 @@ func R (pack, object string) Role {
return Role { Package: pack, Object: object }
}
// Color represents a color ID.
type Color int; const (
ColorBackground Color = iota
ColorForeground
ColorRaised
ColorSunken
ColorAccent
)
// RGBA satisfies the color.Color interface.
func (id Color) RGBA () (r, g, b, a uint32) {
if current == nil { return }
return current.RGBA(id)
}
// Theme is an object that can apply a visual style to different objects.
type Theme interface {
// Apply applies the theme to the given object, according to the given
// role. This may register event listeners with the given object;
// closing the returned cookie will remove them.
Apply (tomo.Object, Role) event.Cookie
// RGBA returns the RGBA values of the corresponding color ID.
RGBA (Color) (r, g, b, a uint32)
}
var current Theme
@@ -42,5 +60,7 @@ func SetTheme (theme Theme) {
// role. This may register event listeners with the given object; closing the
// returned cookie will remove them.
func Apply (object tomo.Object, role Role) event.Cookie {
if current == nil { return event.NoCookie { } }
return current.Apply(object, role)
}