Update internal/theme to use new API
This commit is contained in:
parent
1142cb7ab6
commit
9e2d1ecf01
@ -7,7 +7,6 @@ import "git.tebibyte.media/tomo/tomo"
|
|||||||
import "git.tebibyte.media/tomo/tomo/data"
|
import "git.tebibyte.media/tomo/tomo/data"
|
||||||
import "git.tebibyte.media/tomo/tomo/event"
|
import "git.tebibyte.media/tomo/tomo/event"
|
||||||
import "git.tebibyte.media/tomo/tomo/input"
|
import "git.tebibyte.media/tomo/tomo/input"
|
||||||
import "git.tebibyte.media/tomo/tomo/theme"
|
|
||||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||||
|
|
||||||
// this is CSS's bastard child
|
// this is CSS's bastard child
|
||||||
@ -22,26 +21,26 @@ type Theme struct {
|
|||||||
// Rules determines which styles get applied to which Objects.
|
// Rules determines which styles get applied to which Objects.
|
||||||
Rules []Rule
|
Rules []Rule
|
||||||
|
|
||||||
// Colors maps theme.Color values to color.RGBA values.
|
// Colors maps tomo.Color values to color.RGBA values.
|
||||||
Colors map[theme.Color] color.Color
|
Colors map[tomo.Color] color.Color
|
||||||
|
|
||||||
// This type does not handle icons, and as such, a special icon theme
|
// This type does not handle icons, and as such, a special icon theme
|
||||||
// must be separately specified.
|
// must be separately specified.
|
||||||
IconTheme
|
IconTheme
|
||||||
}
|
}
|
||||||
|
|
||||||
// IconTheme implements the part of theme.Theme that handles icons.
|
// IconTheme implements the part of tomo.Theme that handles icons.
|
||||||
type IconTheme interface {
|
type IconTheme interface {
|
||||||
// Icon returns a texture of the corresponding icon ID.
|
// Icon returns a texture of the corresponding icon ID.
|
||||||
Icon (theme.Icon, theme.IconSize) canvas.Texture
|
Icon (tomo.Icon, tomo.IconSize) canvas.Texture
|
||||||
// MimeIcon returns an icon corresponding to a MIME type.
|
// MimeIcon returns an icon corresponding to a MIME type.
|
||||||
MimeIcon (data.Mime, theme.IconSize) canvas.Texture
|
MimeIcon (data.Mime, tomo.IconSize) canvas.Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rule describes under what circumstances should certain style attributes be
|
// Rule describes under what circumstances should certain style attributes be
|
||||||
// active.
|
// active.
|
||||||
type Rule struct {
|
type Rule struct {
|
||||||
Role theme.Role
|
Role tomo.Role
|
||||||
Default AttrSet
|
Default AttrSet
|
||||||
Hovered AttrSet
|
Hovered AttrSet
|
||||||
Pressed AttrSet
|
Pressed AttrSet
|
||||||
@ -105,7 +104,7 @@ func (this *Theme) execute (object tomo.Object, set AttrSet) {
|
|||||||
case AttrColor:
|
case AttrColor:
|
||||||
box.SetColor(attr.Color)
|
box.SetColor(attr.Color)
|
||||||
case AttrTexture:
|
case AttrTexture:
|
||||||
box.SetTexture(this.texture(string(attr)))
|
box.SetTextureTile(this.texture(string(attr)))
|
||||||
case AttrBorder:
|
case AttrBorder:
|
||||||
box.SetBorder([]tomo.Border(attr)...)
|
box.SetBorder([]tomo.Border(attr)...)
|
||||||
case AttrMinimumSize:
|
case AttrMinimumSize:
|
||||||
@ -133,7 +132,7 @@ func (this *Theme) execute (object tomo.Object, set AttrSet) {
|
|||||||
box.SetAlign(attr.X, attr.Y)
|
box.SetAlign(attr.X, attr.Y)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
panic("bug: nasin/internal/theme.Theme: unexpected attribute")
|
panic("bug: nasin/internal/tomo.Theme: unexpected attribute")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,7 +164,7 @@ func (this *Theme) ensureTextureCache () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setsFor builds flattened attr sets for a specific role based on the rules list
|
// setsFor builds flattened attr sets for a specific role based on the rules list
|
||||||
func (this *Theme) setsFor (role theme.Role) (defaul, hovered, pressed, focused AttrSet) {
|
func (this *Theme) setsFor (role tomo.Role) (defaul, hovered, pressed, focused AttrSet) {
|
||||||
for _, current := range this.Rules {
|
for _, current := range this.Rules {
|
||||||
// check for a match
|
// check for a match
|
||||||
packageMatch := current.Role.Package == role.Package || current.Role.Package == ""
|
packageMatch := current.Role.Package == role.Package || current.Role.Package == ""
|
||||||
@ -187,7 +186,7 @@ func (this *Theme) setsFor (role theme.Role) (defaul, hovered, pressed, focused
|
|||||||
return defaul, hovered, pressed, focused
|
return defaul, hovered, pressed, focused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Theme) Apply (object tomo.Object, role theme.Role) event.Cookie {
|
func (this *Theme) Apply (object tomo.Object, role tomo.Role) event.Cookie {
|
||||||
pressed := false
|
pressed := false
|
||||||
hovered := false
|
hovered := false
|
||||||
box := object.GetBox()
|
box := object.GetBox()
|
||||||
@ -232,14 +231,14 @@ func (this *Theme) Apply (object tomo.Object, role theme.Role) event.Cookie {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Theme) RGBA (c theme.Color) (r, g, b, a uint32) {
|
func (this *Theme) RGBA (c tomo.Color) (r, g, b, a uint32) {
|
||||||
if this.Colors == nil { return 0xFFFF, 0, 0xFFFF, 0xFFFF }
|
if this.Colors == nil { return 0xFFFF, 0, 0xFFFF, 0xFFFF }
|
||||||
color, ok := this.Colors[c]
|
color, ok := this.Colors[c]
|
||||||
if !ok { return 0xFFFF, 0, 0xFFFF, 0xFFFF }
|
if !ok { return 0xFFFF, 0, 0xFFFF, 0xFFFF }
|
||||||
return color.RGBA()
|
return color.RGBA()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Theme) Icon (icon theme.Icon, size theme.IconSize) canvas.Texture {
|
func (this *Theme) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
|
||||||
if this.IconTheme == nil {
|
if this.IconTheme == nil {
|
||||||
return this.missingTexture()
|
return this.missingTexture()
|
||||||
} else {
|
} else {
|
||||||
@ -247,7 +246,7 @@ func (this *Theme) Icon (icon theme.Icon, size theme.IconSize) canvas.Texture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Theme) MimeIcon (mime data.Mime, size theme.IconSize) canvas.Texture {
|
func (this *Theme) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
|
||||||
if this.IconTheme == nil {
|
if this.IconTheme == nil {
|
||||||
return this.missingTexture()
|
return this.missingTexture()
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user