Update internal/theme to use new API

This commit is contained in:
Sasha Koshka 2024-05-27 16:02:39 -04:00
parent 1142cb7ab6
commit 9e2d1ecf01
1 changed files with 13 additions and 14 deletions

View File

@ -7,7 +7,6 @@ import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/tomo/theme"
import "git.tebibyte.media/tomo/tomo/canvas"
// this is CSS's bastard child
@ -22,26 +21,26 @@ type Theme struct {
// Rules determines which styles get applied to which Objects.
Rules []Rule
// Colors maps theme.Color values to color.RGBA values.
Colors map[theme.Color] color.Color
// Colors maps tomo.Color values to color.RGBA values.
Colors map[tomo.Color] color.Color
// This type does not handle icons, and as such, a special icon theme
// must be separately specified.
IconTheme
}
// IconTheme implements the part of theme.Theme that handles icons.
// IconTheme implements the part of tomo.Theme that handles icons.
type IconTheme interface {
// 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 (data.Mime, theme.IconSize) canvas.Texture
MimeIcon (data.Mime, tomo.IconSize) canvas.Texture
}
// Rule describes under what circumstances should certain style attributes be
// active.
type Rule struct {
Role theme.Role
Role tomo.Role
Default AttrSet
Hovered AttrSet
Pressed AttrSet
@ -105,7 +104,7 @@ func (this *Theme) execute (object tomo.Object, set AttrSet) {
case AttrColor:
box.SetColor(attr.Color)
case AttrTexture:
box.SetTexture(this.texture(string(attr)))
box.SetTextureTile(this.texture(string(attr)))
case AttrBorder:
box.SetBorder([]tomo.Border(attr)...)
case AttrMinimumSize:
@ -133,7 +132,7 @@ func (this *Theme) execute (object tomo.Object, set AttrSet) {
box.SetAlign(attr.X, attr.Y)
}
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
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 {
// check for a match
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
}
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
hovered := false
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 }
color, ok := this.Colors[c]
if !ok { return 0xFFFF, 0, 0xFFFF, 0xFFFF }
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 {
return this.missingTexture()
} 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 {
return this.missingTexture()
} else {