88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
package theme
|
|
|
|
import "git.tebibyte.media/tomo/tomo"
|
|
import "git.tebibyte.media/tomo/tomo/data"
|
|
import "git.tebibyte.media/tomo/tomo/event"
|
|
|
|
// 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:
|
|
// - TextInput
|
|
// - Table
|
|
// - Label
|
|
// - 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, 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)
|
|
|
|
// Icon returns a texture of the corresponding icon ID. This texture
|
|
// should be protected, unless a new copy of it is returned with each
|
|
// subsequent call.
|
|
Icon (Icon, IconSize) tomo.Texture
|
|
|
|
// MimeIcon returns an icon corresponding to a MIME type. This texture
|
|
// should be protected, unless a new copy of it is returned with each
|
|
// subsequent call.
|
|
MimeIcon (data.Mime, IconSize) tomo.Texture
|
|
|
|
// ApplicationIcon returns an icon corresponding to an application. This
|
|
// texture should be protected, unless a new copy of it is returned with
|
|
// each subsequent call.
|
|
ApplicationIcon (ApplicationIcon, IconSize) tomo.Texture
|
|
}
|
|
|
|
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 {
|
|
if current == nil { return event.NoCookie { } }
|
|
return current.Apply(object, role)
|
|
}
|
|
|