Add colors
This commit is contained in:
parent
2f5421a5c9
commit
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,24 @@ 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
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// Color returns a color for the corresponding color ID.
|
||||
Color (Color) color.Color
|
||||
}
|
||||
|
||||
var current Theme
|
||||
|
@ -42,5 +54,12 @@ 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)
|
||||
}
|
||||
|
||||
// Color returns a color for the corresponding color ID.
|
||||
func Color (id Color) color.Color {
|
||||
if current == nil { return color.Black }
|
||||
return current.Color(id)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue