Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e25397a05 | |||
| 2884604fdd | |||
| f99d9e0d2a | |||
| 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]
|
||||
|
||||
2
go.mod
2
go.mod
@@ -2,4 +2,4 @@ module git.tebibyte.media/tomo/tomo
|
||||
|
||||
go 1.20
|
||||
|
||||
require golang.org/x/image v0.8.0
|
||||
require golang.org/x/image v0.11.0
|
||||
|
||||
3
go.sum
3
go.sum
@@ -3,6 +3,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.8.0 h1:agUcRXV/+w6L9ryntYYsF2x9fQTMd4T8fiiYXAVW6Jg=
|
||||
golang.org/x/image v0.8.0/go.mod h1:PwLxp3opCYg4WR2WO9P0L6ESnsD6bLTWcw8zanLMVFM=
|
||||
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
|
||||
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
@@ -26,6 +28,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
|
||||
@@ -104,7 +104,7 @@ type Align int; const (
|
||||
// Object is any obscreen object. Each object must be linked to a box, even if
|
||||
// it is that box.
|
||||
type Object interface {
|
||||
Box () Box
|
||||
GetBox () Box
|
||||
}
|
||||
|
||||
// Box is a basic styled box.
|
||||
|
||||
@@ -16,19 +16,42 @@ type Role struct {
|
||||
// - Dial
|
||||
// This should correspond directly to the type name of the object.
|
||||
Object string
|
||||
|
||||
// Variant is an optional field to be used when an object has one or
|
||||
// more soft variants under one type. For example, an object "Slider"
|
||||
// may have variations "horizontal" and "vertical".
|
||||
Variant string
|
||||
}
|
||||
|
||||
// R is shorthand for creating a Role structure.
|
||||
func R (pack, object string) Role {
|
||||
return Role { Package: pack, Object: object }
|
||||
func R (pack, object, variant string) Role {
|
||||
return Role { Package: pack, Object: object, Variant: variant }
|
||||
}
|
||||
|
||||
// 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 +65,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