Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c785fb461c | |||
| 487471d7a9 |
@@ -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]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user