tomo/theme/theme.go

47 lines
1.3 KiB
Go
Raw Normal View History

2023-08-08 01:49:11 +00:00
package theme
import "git.tebibyte.media/tomo/tomo"
2023-08-08 01:57:50 +00:00
import "git.tebibyte.media/tomo/tomo/event"
2023-08-08 01:49:11 +00:00
// Role describes the role of an object.
type Role struct {
// Package is an optional namespace field. If specified, it should be
// the package name or module name the object is from.
Package string
// Object specifies what type of object it is. For example:
2023-08-08 01:51:05 +00:00
// - TextInput
// - Table
// - Label
// - Dial
// This should correspond directly to the type name of the object.
2023-08-08 01:49:11 +00:00
Object string
}
2023-08-08 07:00:41 +00:00
// R is shorthand for creating a Role structure.
func R (pack, object string) Role {
return Role { Package: pack, Object: object }
}
2023-08-08 01:49:11 +00:00
// 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
}
var current Theme
// SetTheme sets the theme.
func SetTheme (theme Theme) {
current = theme
}
// Apply applies the current 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.
func Apply (object tomo.Object, role Role) event.Cookie {
return current.Apply(object, role)
}