Restructure internal theme

This commit is contained in:
Sasha Koshka 2024-06-12 00:19:12 -04:00
parent 86fb87c7f6
commit 03ca852475
19 changed files with 257 additions and 287 deletions

View File

Before

Width:  |  Height:  |  Size: 8.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -7,7 +7,6 @@ import _ "image/png"
import "git.tebibyte.media/tomo/tomo" 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/canvas" import "git.tebibyte.media/tomo/tomo/canvas"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme"
//go:embed assets/icons-small.png //go:embed assets/icons-small.png
var atlasSmallBytes []byte var atlasSmallBytes []byte
@ -418,7 +417,7 @@ type iconTheme struct {
} }
// New creates a new fallback icon theme. // New creates a new fallback icon theme.
func New () dataTheme.IconTheme { func New () tomo.Icons {
return new(iconTheme) return new(iconTheme)
} }

View File

@ -11,17 +11,16 @@ import "git.tebibyte.media/tomo/tomo"
import xdgIconTheme "git.tebibyte.media/tomo/xdg/icon-theme" import xdgIconTheme "git.tebibyte.media/tomo/xdg/icon-theme"
import "git.tebibyte.media/tomo/tomo/data" import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/canvas" import "git.tebibyte.media/tomo/tomo/canvas"
import "git.tebibyte.media/tomo/nasin/internal/theme"
type iconTheme struct { type iconTheme struct {
xdg xdgIconTheme.Theme xdg xdgIconTheme.Theme
fallback theme.IconTheme fallback tomo.Icons
texturesSmall map[tomo.Icon] canvas.Texture texturesSmall map[tomo.Icon] canvas.Texture
texturesMedium map[tomo.Icon] canvas.Texture texturesMedium map[tomo.Icon] canvas.Texture
texturesLarge map[tomo.Icon] canvas.Texture texturesLarge map[tomo.Icon] canvas.Texture
} }
func FindThemeWarn (name string, fallback theme.IconTheme, path ...string) (theme.IconTheme, error) { func FindThemeWarn (name string, fallback tomo.Icons, path ...string) (tomo.Icons, error) {
this := &iconTheme { this := &iconTheme {
fallback: fallback, fallback: fallback,
texturesLarge: make(map[tomo.Icon] canvas.Texture), texturesLarge: make(map[tomo.Icon] canvas.Texture),

View File

@ -3,36 +3,37 @@ package registrar
import "os" import "os"
import "log" import "log"
import "git.tebibyte.media/tomo/backend/x"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme" import "git.tebibyte.media/tomo/backend/x"
import "git.tebibyte.media/tomo/nasin/internal/theme/icons/xdg" import "git.tebibyte.media/tomo/nasin/internal/style"
import "git.tebibyte.media/tomo/nasin/internal/theme/icons/fallback" import "git.tebibyte.media/tomo/nasin/internal/icons/xdg"
import "git.tebibyte.media/tomo/nasin/internal/theme/style/fallback" import "git.tebibyte.media/tomo/nasin/internal/icons/fallback"
import "git.tebibyte.media/tomo/nasin/internal/theme/style/aluminum" import "git.tebibyte.media/tomo/nasin/internal/style/fallback"
import "git.tebibyte.media/tomo/nasin/internal/style/aluminum"
func Init () error { func Init () error {
var theme *dataTheme.Theme var styl *style.Style
// TODO eventually get rid of this when we make a file format for // TODO eventually get rid of this when we make a file format for
// storing visual styles // storing visual styles
if os.Getenv("TOMO_USE_ALUMINUM_STYLE") != "" { if os.Getenv("TOMO_USE_ALUMINUM_STYLE") != "" {
theme = aluminumStyle.New() styl = aluminumStyle.New()
} else { } else {
theme = fallbackStyle.New() styl = fallbackStyle.New()
} }
theme.IconTheme = fallbackIcons.New() icons := fallbackIcons.New()
iconThemeName := os.Getenv("TOMO_XDG_ICON_THEME") iconThemeName := os.Getenv("TOMO_XDG_ICON_THEME")
if iconThemeName != "" { if iconThemeName != "" {
iconTheme, err := xdgIcons.FindThemeWarn(iconThemeName, theme.IconTheme) xdgIconTheme, err := xdgIcons.FindThemeWarn(iconThemeName, icons)
if err == nil { if err == nil {
theme.IconTheme = iconTheme icons = xdgIconTheme
} else { } else {
log.Printf("nasin: could not load icon theme '%s': %v", iconThemeName, err) log.Printf("nasin: could not load icon theme '%s': %v", iconThemeName, err)
} }
} }
tomo.SetTheme(theme) tomo.SetStyle(styl)
tomo.SetIcons(icons)
tomo.Register(1, x.New) tomo.Register(1, x.New)
return nil return nil
} }

View File

@ -2,11 +2,11 @@ package aluminumStyle
import "image/color" import "image/color"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme" import "git.tebibyte.media/tomo/nasin/internal/style"
// New returns Aluminum, a futuristic, bluish-white style. // New returns Aluminum, a futuristic, bluish-white style.
func New () *dataTheme.Theme { func New () *style.Style {
return &dataTheme.Theme { return &style.Style {
Colors: map[tomo.Color] color.Color { Colors: map[tomo.Color] color.Color {
tomo.ColorBackground: colorBackground, tomo.ColorBackground: colorBackground,
tomo.ColorForeground: colorForeground, tomo.ColorForeground: colorForeground,

View File

@ -3,7 +3,7 @@ package aluminumStyle
import "image/color" import "image/color"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import "golang.org/x/image/font/basicfont" import "golang.org/x/image/font/basicfont"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme" import "git.tebibyte.media/tomo/nasin/internal/style"
func hex (color uint32) (c color.RGBA) { func hex (color uint32) (c color.RGBA) {
c.A = uint8(color) c.A = uint8(color)
@ -62,66 +62,66 @@ var borderTearPadFocused = border(0x7391c080, 0x7391c080, 0x7391c080, 0x7391c080
var borderInnerShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 1, 0, 0, 1) var borderInnerShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 1, 0, 0, 1)
var borderOuterShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 0, 1, 1, 0) var borderOuterShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 0, 1, 1, 0)
var rules = []dataTheme.Rule { var rules = []style.Rule {
// *.*[*] // *.*[*]
dataTheme.Rule { style.Rule {
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrFace { Face: basicfont.Face7x13 }, style.AttrFace { Face: basicfont.Face7x13 },
dataTheme.AttrTextColor { Color: tomo.ColorForeground }, style.AttrTextColor { Color: tomo.ColorForeground },
dataTheme.AttrDotColor { Color: colorDot }, style.AttrDotColor { Color: colorDot },
dataTheme.AttrGap { X: 8, Y: 8 }, style.AttrGap { X: 8, Y: 8 },
), ),
}, },
// *.Button[*] // *.Button[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Button", ""), Role: tomo.R("", "Button", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderLifted, borderLifted,
}, },
dataTheme.AttrPadding(tomo.I(4, 8)), style.AttrPadding(tomo.I(4, 8)),
dataTheme.AttrColor { Color: tomo.ColorRaised }, style.AttrColor { Color: tomo.ColorRaised },
), ),
Pressed: dataTheme.AS ( Pressed: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderInnerShadow, borderInnerShadow,
}, },
dataTheme.AttrPadding(tomo.I(5, 8, 4, 9)), style.AttrPadding(tomo.I(5, 8, 4, 9)),
dataTheme.AttrColor { Color: colorRaisedPressed }, style.AttrColor { Color: colorRaisedPressed },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderLiftedFocused, borderLiftedFocused,
}, },
dataTheme.AttrPadding(tomo.I(4, 8)), style.AttrPadding(tomo.I(4, 8)),
dataTheme.AttrColor { Color: colorRaisedFocused }, style.AttrColor { Color: colorRaisedFocused },
), ),
Hovered: dataTheme.AS ( Hovered: style.AS (
dataTheme.AttrColor { Color: colorRaisedHovered }, style.AttrColor { Color: colorRaisedHovered },
), ),
}, },
// *.TextInput[*] // *.TextInput[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "TextInput", ""), Role: tomo.R("", "TextInput", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderInnerShadow, borderInnerShadow,
}, },
dataTheme.AttrColor { Color: tomo.ColorSunken }, style.AttrColor { Color: tomo.ColorSunken },
dataTheme.AttrPadding(tomo.I(5, 4, 4, 5)), style.AttrPadding(tomo.I(5, 4, 4, 5)),
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderFocused, borderFocused,
borderInnerShadow, borderInnerShadow,
@ -130,206 +130,206 @@ var rules = []dataTheme.Rule {
}, },
// *.TextView[*] // *.TextView[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "TextView", ""), Role: tomo.R("", "TextView", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderInnerShadow, borderInnerShadow,
}, },
dataTheme.AttrColor { Color: tomo.ColorSunken }, style.AttrColor { Color: tomo.ColorSunken },
dataTheme.AttrPadding(tomo.I(8)), style.AttrPadding(tomo.I(8)),
), ),
}, },
// *.NumberInput[*] // *.NumberInput[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "NumberInput", ""), Role: tomo.R("", "NumberInput", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrGap { }, style.AttrGap { },
), ),
}, },
// *.Container[sunken] // *.Container[sunken]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Container", "sunken"), Role: tomo.R("", "Container", "sunken"),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderInnerShadow, borderInnerShadow,
}, },
dataTheme.AttrColor { Color: tomo.ColorSunken }, style.AttrColor { Color: tomo.ColorSunken },
dataTheme.AttrPadding(tomo.I(8)), style.AttrPadding(tomo.I(8)),
), ),
}, },
// *.Container[outer] // *.Container[outer]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Container", "outer"), Role: tomo.R("", "Container", "outer"),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrColor { Color: tomo.ColorBackground }, style.AttrColor { Color: tomo.ColorBackground },
dataTheme.AttrPadding(tomo.I(8)), style.AttrPadding(tomo.I(8)),
), ),
}, },
// *.Container[menu] // *.Container[menu]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Container", "menu"), Role: tomo.R("", "Container", "menu"),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderGap, borderGap,
borderLifted, borderLifted,
}, },
dataTheme.AttrColor { Color: tomo.ColorBackground }, style.AttrColor { Color: tomo.ColorBackground },
dataTheme.AttrGap { }, style.AttrGap { },
), ),
}, },
// *.Heading[*] // *.Heading[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Heading", ""), Role: tomo.R("", "Heading", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrAlign { X: tomo.AlignMiddle, Y: tomo.AlignMiddle }, style.AttrAlign { X: tomo.AlignMiddle, Y: tomo.AlignMiddle },
), ),
}, },
// *.Separator[*] // *.Separator[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Separator", ""), Role: tomo.R("", "Separator", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
}, },
), ),
}, },
// *.Slider[*] // *.Slider[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Slider", ""), Role: tomo.R("", "Slider", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderInnerShadow, borderInnerShadow,
}, },
dataTheme.AttrColor { Color: colorGutter }, style.AttrColor { Color: colorGutter },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderFocused, borderFocused,
borderInnerShadow, borderInnerShadow,
}, },
), ),
Hovered: dataTheme.AS ( Hovered: style.AS (
dataTheme.AttrColor { Color: colorGutterHovered }, style.AttrColor { Color: colorGutterHovered },
), ),
}, },
// *.Slider[horizontal] // *.Slider[horizontal]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Slider", "horizontal"), Role: tomo.R("", "Slider", "horizontal"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { X: 48 }), Default: style.AS(style.AttrMinimumSize { X: 48 }),
}, },
// *.Slider[vertical] // *.Slider[vertical]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Slider", "vertical"), Role: tomo.R("", "Slider", "vertical"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { Y: 48 }), Default: style.AS(style.AttrMinimumSize { Y: 48 }),
}, },
// *.SliderHandle[*] // *.SliderHandle[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "SliderHandle", ""), Role: tomo.R("", "SliderHandle", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderOuterShadow, borderOuterShadow,
borderGap, borderGap,
borderLifted, borderLifted,
}, },
dataTheme.AttrColor { Color: tomo.ColorRaised }, style.AttrColor { Color: tomo.ColorRaised },
dataTheme.AttrMinimumSize { X: 12, Y: 12, }, style.AttrMinimumSize { X: 12, Y: 12, },
), ),
}, },
// *.Checkbox[*] // *.Checkbox[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Checkbox", ""), Role: tomo.R("", "Checkbox", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderGap, borderGap,
borderInnerShadow, borderInnerShadow,
}, },
dataTheme.AttrColor { Color: tomo.ColorSunken }, style.AttrColor { Color: tomo.ColorSunken },
dataTheme.AttrPadding(tomo.I(0, 1, 1, 0)), style.AttrPadding(tomo.I(0, 1, 1, 0)),
dataTheme.AttrMinimumSize { X: 19, Y: 19 }, style.AttrMinimumSize { X: 19, Y: 19 },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderEngraved, borderEngraved,
borderFocused, borderFocused,
borderInnerShadow, borderInnerShadow,
}, },
dataTheme.AttrPadding(tomo.I(0)), style.AttrPadding(tomo.I(0)),
dataTheme.AttrColor { Color: colorSunkenFocused }, style.AttrColor { Color: colorSunkenFocused },
), ),
}, },
// *.LabelCheckbox[*] // *.LabelCheckbox[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "LabelCheckbox", ""), Role: tomo.R("", "LabelCheckbox", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrGap { X: 8, Y: 8 }, style.AttrGap { X: 8, Y: 8 },
), ),
}, },
// *.MenuItem[*] // *.MenuItem[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "MenuItem", ""), Role: tomo.R("", "MenuItem", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrPadding(tomo.I(4)), style.AttrPadding(tomo.I(4)),
dataTheme.AttrGap { X: 4, Y: 4 }, style.AttrGap { X: 4, Y: 4 },
dataTheme.AttrColor { Color: color.Transparent }, style.AttrColor { Color: color.Transparent },
), ),
Hovered: dataTheme.AS ( Hovered: style.AS (
dataTheme.AttrColor { Color: colorDot }, style.AttrColor { Color: colorDot },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrColor { Color: colorDot }, style.AttrColor { Color: colorDot },
), ),
}, },
// *.File[*] // *.File[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "File", ""), Role: tomo.R("", "File", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrColor { Color: color.Transparent }, style.AttrColor { Color: color.Transparent },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrColor { Color: colorDot }, style.AttrColor { Color: colorDot },
), ),
}, },
// *.TearLine[*] // *.TearLine[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "TearLine", ""), Role: tomo.R("", "TearLine", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderTearPad, borderTearPad,
borderTear, borderTear,
}, },
), ),
Hovered: dataTheme.AS ( Hovered: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderTearPadFocused, borderTearPadFocused,
borderTearFocused, borderTearFocused,
}, },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
borderTearPadFocused, borderTearPadFocused,
borderTearFocused, borderTearFocused,
}, },

View File

@ -1,4 +1,4 @@
package theme package style
import "image" import "image"
import "image/color" import "image/color"

View File

@ -3,7 +3,7 @@ package fallbackStyle
import "image/color" import "image/color"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import "golang.org/x/image/font/basicfont" import "golang.org/x/image/font/basicfont"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme" import "git.tebibyte.media/tomo/nasin/internal/style"
var colorFocus = color.RGBA { R: 61, G: 128, B: 143, A: 255 } var colorFocus = color.RGBA { R: 61, G: 128, B: 143, A: 255 }
var colorInput = color.RGBA { R: 208, G: 203, B: 150, A: 255 } var colorInput = color.RGBA { R: 208, G: 203, B: 150, A: 255 }
@ -32,70 +32,70 @@ var borderColorLifted = [4]color.Color { colorHighlight, colorShadow, col
var borderColorInput = [4]color.Color { colorInputShadow, colorInput, colorInput, colorInputShadow } var borderColorInput = [4]color.Color { colorInputShadow, colorInput, colorInput, colorInputShadow }
var borderColorFocused = [4]color.Color { colorFocus, colorFocus, colorFocus, colorFocus } var borderColorFocused = [4]color.Color { colorFocus, colorFocus, colorFocus, colorFocus }
var rules = []dataTheme.Rule { var rules = []style.Rule {
// *.*[*] // *.*[*]
dataTheme.Rule { style.Rule {
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrFace { Face: basicfont.Face7x13 }, style.AttrFace { Face: basicfont.Face7x13 },
dataTheme.AttrTextColor { Color: tomo.ColorForeground }, style.AttrTextColor { Color: tomo.ColorForeground },
dataTheme.AttrDotColor { Color: tomo.ColorAccent }, style.AttrDotColor { Color: tomo.ColorAccent },
dataTheme.AttrGap { X: 8, Y: 8 }, style.AttrGap { X: 8, Y: 8 },
), ),
}, },
// *.Button[*] // *.Button[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Button", ""), Role: tomo.R("", "Button", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorLifted, Color: borderColorLifted,
}, },
}, },
dataTheme.AttrPadding(tomo.I(4, 8)), style.AttrPadding(tomo.I(4, 8)),
dataTheme.AttrColor { Color: tomo.ColorRaised }, style.AttrColor { Color: tomo.ColorRaised },
), ),
Pressed: dataTheme.AS ( Pressed: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1, 0, 0, 1), Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved, Color: borderColorEngraved,
}, },
}, },
dataTheme.AttrPadding(tomo.I(5, 8, 4, 9)), style.AttrPadding(tomo.I(5, 8, 4, 9)),
dataTheme.AttrColor { Color: colorCarvedPressed }, style.AttrColor { Color: colorCarvedPressed },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorFocused, Color: borderColorFocused,
}, },
}, },
dataTheme.AttrPadding(tomo.I(4, 8)), style.AttrPadding(tomo.I(4, 8)),
), ),
}, },
// *.TextInput[*] // *.TextInput[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "TextInput", ""), Role: tomo.R("", "TextInput", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorInput, Color: borderColorInput,
}, },
}, },
dataTheme.AttrColor { Color: colorInput }, style.AttrColor { Color: colorInput },
dataTheme.AttrPadding(tomo.I(5, 4, 4, 5)), style.AttrPadding(tomo.I(5, 4, 4, 5)),
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
@ -106,83 +106,83 @@ var rules = []dataTheme.Rule {
}, },
// *.TextView[*] // *.TextView[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "TextView", ""), Role: tomo.R("", "TextView", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1, 0, 0, 1), Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved, Color: borderColorEngraved,
}, },
}, },
dataTheme.AttrColor { Color: tomo.ColorSunken }, style.AttrColor { Color: tomo.ColorSunken },
dataTheme.AttrPadding(tomo.I(8)), style.AttrPadding(tomo.I(8)),
), ),
}, },
// *.NumberInput[*] // *.NumberInput[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "NumberInput", ""), Role: tomo.R("", "NumberInput", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrGap { }, style.AttrGap { },
), ),
}, },
// *.Container[sunken] // *.Container[sunken]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Container", "sunken"), Role: tomo.R("", "Container", "sunken"),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1, 0, 0, 1), Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved, Color: borderColorEngraved,
}, },
}, },
dataTheme.AttrColor { Color: tomo.ColorSunken }, style.AttrColor { Color: tomo.ColorSunken },
dataTheme.AttrPadding(tomo.I(8)), style.AttrPadding(tomo.I(8)),
), ),
}, },
// *.Container[outer] // *.Container[outer]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Container", "outer"), Role: tomo.R("", "Container", "outer"),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrColor { Color: tomo.ColorBackground }, style.AttrColor { Color: tomo.ColorBackground },
dataTheme.AttrPadding(tomo.I(8)), style.AttrPadding(tomo.I(8)),
), ),
}, },
// *.Container[menu] // *.Container[menu]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Container", "menu"), Role: tomo.R("", "Container", "menu"),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorLifted, Color: borderColorLifted,
}, },
}, },
dataTheme.AttrColor { Color: tomo.ColorBackground }, style.AttrColor { Color: tomo.ColorBackground },
dataTheme.AttrGap { }, style.AttrGap { },
), ),
}, },
// *.Heading[*] // *.Heading[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Heading", ""), Role: tomo.R("", "Heading", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrAlign { X: tomo.AlignMiddle, Y: tomo.AlignMiddle }, style.AttrAlign { X: tomo.AlignMiddle, Y: tomo.AlignMiddle },
), ),
}, },
// *.Separator[*] // *.Separator[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Separator", ""), Role: tomo.R("", "Separator", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorEngraved, Color: borderColorEngraved,
@ -192,126 +192,126 @@ var rules = []dataTheme.Rule {
}, },
// *.Slider[*] // *.Slider[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Slider", ""), Role: tomo.R("", "Slider", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1, 0, 0, 1), Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved, Color: borderColorEngraved,
}, },
}, },
dataTheme.AttrColor { Color: colorGutter }, style.AttrColor { Color: colorGutter },
dataTheme.AttrPadding(tomo.I(0, 1, 1, 0)), style.AttrPadding(tomo.I(0, 1, 1, 0)),
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorFocused, Color: borderColorFocused,
}, },
}, },
dataTheme.AttrPadding(tomo.I(0)), style.AttrPadding(tomo.I(0)),
), ),
}, },
// *.Slider[horizontal] // *.Slider[horizontal]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Slider", "horizontal"), Role: tomo.R("", "Slider", "horizontal"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { X: 48 }), Default: style.AS(style.AttrMinimumSize { X: 48 }),
}, },
// *.Slider[vertical] // *.Slider[vertical]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Slider", "vertical"), Role: tomo.R("", "Slider", "vertical"),
Default: dataTheme.AS(dataTheme.AttrMinimumSize { Y: 48 }), Default: style.AS(style.AttrMinimumSize { Y: 48 }),
}, },
// *.SliderHandle[*] // *.SliderHandle[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "SliderHandle", ""), Role: tomo.R("", "SliderHandle", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorLifted, Color: borderColorLifted,
}, },
}, },
dataTheme.AttrColor { Color: tomo.ColorRaised }, style.AttrColor { Color: tomo.ColorRaised },
dataTheme.AttrMinimumSize { X: 12, Y: 12, }, style.AttrMinimumSize { X: 12, Y: 12, },
), ),
}, },
// *.Checkbox[*] // *.Checkbox[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "Checkbox", ""), Role: tomo.R("", "Checkbox", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1, 0, 0, 1), Width: tomo.I(1, 0, 0, 1),
Color: borderColorEngraved, Color: borderColorEngraved,
}, },
}, },
dataTheme.AttrColor { Color: tomo.ColorSunken }, style.AttrColor { Color: tomo.ColorSunken },
dataTheme.AttrPadding(tomo.I(0, 1, 1, 0)), style.AttrPadding(tomo.I(0, 1, 1, 0)),
dataTheme.AttrMinimumSize { X: 19, Y: 19 }, style.AttrMinimumSize { X: 19, Y: 19 },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
outline, outline,
tomo.Border { tomo.Border {
Width: tomo.I(1), Width: tomo.I(1),
Color: borderColorFocused, Color: borderColorFocused,
}, },
}, },
dataTheme.AttrPadding(tomo.I(0)), style.AttrPadding(tomo.I(0)),
), ),
}, },
// *.LabelCheckbox[*] // *.LabelCheckbox[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "LabelCheckbox", ""), Role: tomo.R("", "LabelCheckbox", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrGap { X: 8, Y: 8 }, style.AttrGap { X: 8, Y: 8 },
), ),
}, },
// *.MenuItem[*] // *.MenuItem[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "MenuItem", ""), Role: tomo.R("", "MenuItem", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrPadding(tomo.I(4)), style.AttrPadding(tomo.I(4)),
dataTheme.AttrGap { X: 4, Y: 4 }, style.AttrGap { X: 4, Y: 4 },
dataTheme.AttrColor { Color: color.Transparent }, style.AttrColor { Color: color.Transparent },
), ),
Hovered: dataTheme.AS ( Hovered: style.AS (
dataTheme.AttrColor { Color: tomo.ColorAccent }, style.AttrColor { Color: tomo.ColorAccent },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrColor { Color: tomo.ColorAccent }, style.AttrColor { Color: tomo.ColorAccent },
), ),
}, },
// *.File[*] // *.File[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "File", ""), Role: tomo.R("", "File", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrColor { Color: color.Transparent }, style.AttrColor { Color: color.Transparent },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrColor { Color: tomo.ColorAccent }, style.AttrColor { Color: tomo.ColorAccent },
), ),
}, },
// *.TearLine[*] // *.TearLine[*]
dataTheme.Rule { style.Rule {
Role: tomo.R("", "TearLine", ""), Role: tomo.R("", "TearLine", ""),
Default: dataTheme.AS ( Default: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
tomo.Border { tomo.Border {
Width: tomo.I(3), Width: tomo.I(3),
Color: [4]color.Color { Color: [4]color.Color {
@ -322,19 +322,19 @@ var rules = []dataTheme.Rule {
}, },
}, },
}, },
dataTheme.AttrColor { Color: tomo.ColorForeground }, style.AttrColor { Color: tomo.ColorForeground },
dataTheme.AttrPadding(tomo.I(1, 0, 0, 1)), style.AttrPadding(tomo.I(1, 0, 0, 1)),
), ),
Hovered: dataTheme.AS ( Hovered: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
tomo.Border { tomo.Border {
Width: tomo.I(3), Width: tomo.I(3),
Color: borderColorFocused, Color: borderColorFocused,
}, },
}, },
), ),
Focused: dataTheme.AS ( Focused: style.AS (
dataTheme.AttrBorder { style.AttrBorder {
tomo.Border { tomo.Border {
Width: tomo.I(3), Width: tomo.I(3),
Color: borderColorFocused, Color: borderColorFocused,

View File

@ -2,12 +2,12 @@ package fallbackStyle
import "image/color" import "image/color"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import dataTheme "git.tebibyte.media/tomo/nasin/internal/theme" import "git.tebibyte.media/tomo/nasin/internal/style"
// New returns Wintergreen, the default Tomo tomo. It is neutral-gray with green // New returns Wintergreen, the default Tomo style. It is neutral-gray with
// and turquoise accents. // green and turquoise accents.
func New () *dataTheme.Theme { func New () *style.Style {
return &dataTheme.Theme { return &style.Style {
Colors: map[tomo.Color] color.Color { Colors: map[tomo.Color] color.Color {
tomo.ColorBackground: colorBackground, tomo.ColorBackground: colorBackground,
tomo.ColorForeground: colorForeground, tomo.ColorForeground: colorForeground,

View File

@ -1,4 +1,4 @@
package theme package style
import "image" import "image"
import "image/color" import "image/color"

View File

@ -1,18 +1,17 @@
// Package theme provides a data-driven theme implementation. // Package style provides a data-driven style implementation.
package theme package style
import "image" import "image"
import "image/color" import "image/color"
import "git.tebibyte.media/tomo/tomo" 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/event"
import "git.tebibyte.media/tomo/tomo/input" import "git.tebibyte.media/tomo/tomo/input"
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
// Theme allows the use of data to define a visual style. // Style allows the use of data to define a visual style.
type Theme struct { type Style struct {
// Textures maps texture names to image textures. // Textures maps texture names to image textures.
Textures map[string] image.Image Textures map[string] image.Image
textures map[string] canvas.TextureCloser // private texture cache textures map[string] canvas.TextureCloser // private texture cache
@ -23,18 +22,6 @@ type Theme struct {
// Colors maps tomo.Color values to color.RGBA values. // Colors maps tomo.Color values to color.RGBA values.
Colors map[tomo.Color] color.Color 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 tomo.Theme that handles icons.
type IconTheme interface {
// Icon returns a texture of the corresponding icon ID.
Icon (tomo.Icon, tomo.IconSize) canvas.Texture
// MimeIcon returns an icon corresponding to a MIME type.
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
@ -96,7 +83,7 @@ func (this *AttrSet) ensure () {
if this.set == nil { this.set = make(map[int] Attr) } if this.set == nil { this.set = make(map[int] Attr) }
} }
func (this *Theme) execute (object tomo.Object, set AttrSet) { func (this *Style) execute (object tomo.Object, set AttrSet) {
box := object.GetBox() box := object.GetBox()
for _, attr := range set.set { for _, attr := range set.set {
@ -137,7 +124,7 @@ func (this *Theme) execute (object tomo.Object, set AttrSet) {
} }
} }
func (this *Theme) texture (name string) canvas.Texture { func (this *Style) texture (name string) canvas.Texture {
this.ensureTextureCache() this.ensureTextureCache()
if texture, ok := this.textures[name]; ok { if texture, ok := this.textures[name]; ok {
return texture return texture
@ -152,19 +139,19 @@ func (this *Theme) texture (name string) canvas.Texture {
return this.missingTexture() return this.missingTexture()
} }
func (this *Theme) missingTexture () canvas.Texture { func (this *Style) missingTexture () canvas.Texture {
if this.missing == nil { if this.missing == nil {
this.missing = tomo.NewTexture(missingTexture(16)) this.missing = tomo.NewTexture(missingTexture(16))
} }
return this.missing return this.missing
} }
func (this *Theme) ensureTextureCache () { func (this *Style) ensureTextureCache () {
if this.textures == nil { this.textures = make(map[string] canvas.TextureCloser) } if this.textures == nil { this.textures = make(map[string] canvas.TextureCloser) }
} }
// 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 tomo.Role) (defaul, hovered, pressed, focused AttrSet) { func (this *Style) 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 == ""
@ -186,7 +173,7 @@ func (this *Theme) setsFor (role tomo.Role) (defaul, hovered, pressed, focused A
return defaul, hovered, pressed, focused return defaul, hovered, pressed, focused
} }
func (this *Theme) Apply (object tomo.Object) event.Cookie { func (this *Style) Apply (object tomo.Object) event.Cookie {
pressed := false pressed := false
hovered := false hovered := false
box := object.GetBox() box := object.GetBox()
@ -232,32 +219,16 @@ func (this *Theme) Apply (object tomo.Object) event.Cookie {
} }
func (this *Theme) RGBA (c tomo.Color) (r, g, b, a uint32) { func (this *Style) 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 tomo.Icon, size tomo.IconSize) canvas.Texture { // Close closes all cached textures this style has open. Do not call this while
if this.IconTheme == nil { // the style is in use.
return this.missingTexture() func (this *Style) Close () error {
} else {
return this.IconTheme.Icon(icon, size)
}
}
func (this *Theme) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
if this.IconTheme == nil {
return this.missingTexture()
} else {
return this.IconTheme.MimeIcon(mime, size)
}
}
// Close closes all cached textures this theme has open. Do not call this while
// the theme is in use.
func (this *Theme) Close () error {
this.missing.Close() this.missing.Close()
this.missing = nil this.missing = nil
for _, texture := range this.textures { for _, texture := range this.textures {