diff --git a/README.md b/README.md index e69de29..298fa60 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +# aluminum diff --git a/aluminum/plugin.go b/aluminum/plugin.go new file mode 100644 index 0000000..d6ce361 --- /dev/null +++ b/aluminum/plugin.go @@ -0,0 +1,17 @@ +// Plugin sapphire provides the Aluminum theme as a plugin. +package main + +import "git.tebibyte.media/tomo/aluminum" +import "git.tebibyte.media/tomo/tomo/theme" + +func init () { + theme.SetTheme(aluminum.Theme { }) +} + +func Name () string { + return "Aluminum" +} + +func Description () string { + return "A shiny blue and metallic theme." +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a0ab2b9 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module git.tebibyte.media/tomo/aluminum + +go 1.20 + +require ( + git.tebibyte.media/tomo/tomo v0.23.0 + golang.org/x/image v0.11.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5e4ffa0 --- /dev/null +++ b/go.sum @@ -0,0 +1,35 @@ +git.tebibyte.media/tomo/tomo v0.23.0 h1:OZwI4oLKMP7JqFc98VxBoRxwjL+W9NyTQZLB/m1BvaA= +git.tebibyte.media/tomo/tomo v0.23.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo= +golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/theme.go b/theme.go new file mode 100644 index 0000000..49c23ed --- /dev/null +++ b/theme.go @@ -0,0 +1,178 @@ +package aluminum + +import "image" +import "image/color" +import "git.tebibyte.media/tomo/tomo" +import "golang.org/x/image/font/basicfont" +import "git.tebibyte.media/tomo/tomo/theme" +import "git.tebibyte.media/tomo/tomo/input" +import "git.tebibyte.media/tomo/tomo/event" + +func hex (color uint32) (c color.RGBA) { + c.A = uint8(color) + c.B = uint8(color >> 8) + c.G = uint8(color >> 16) + c.R = uint8(color >> 24) + return +} + +func border (top, right, bottom, left uint32, width ...int) tomo.Border { + return tomo.Border { + Width: tomo.I(width...), + Color: [4]color.Color { + hex(top), hex(right), + hex(bottom), hex(left), + }, + } +} + +var engravedBorder = border(0xc3c3c5FF, 0xe3e3e3FF, 0xe9e9e9ff, 0xc2c2c2ff, 1) +var gapBorder = border(0x697c7cFF, 0x566767FF, 0x566767ff, 0x697c7cff, 1) +var focusedBorder = border(0x5f8bc4FF, 0x5f8bc4FF, 0x5f8bc4ff, 0x5f8bc4ff, 1) +var buttonBorder = border(0xf9fafcFF, 0xc2c8d3FF, 0xa4afc0ff, 0xf5f6f8ff, 1) +var sunkenShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 1, 0, 0, 1) +var outerShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 0, 1, 1, 0) + +var buttonColor = hex(0xe9eaeaFF) +var buttonColorPressed = hex(0xe3e4e4FF) +var buttonColorFocused = hex(0xe4e6e8FF) +var dotColor = hex(0xa4c0e4FF) +var inputColor = hex(0xe3e4e4FF) +var textColor = hex(0x000000FF) +var backgroundColor = hex(0xd6d6d6FF) +var gutterColor = hex(0xbfc6d1FF) + +type Theme struct { } + +func (Theme) RGBA (id theme.Color) (r, g, b, a uint32) { + switch id { + case theme.ColorBackground: return backgroundColor .RGBA() + case theme.ColorForeground: return textColor .RGBA() + case theme.ColorRaised: return buttonColor .RGBA() + case theme.ColorSunken: return inputColor .RGBA() + case theme.ColorAccent: return hex(0x5f8bc4FF) .RGBA() + default: return color.Transparent.RGBA() + } +} + +func (Theme) Apply (object tomo.Object, role theme.Role) event.Cookie { + box := object.GetBox() + box.SetColor(backgroundColor) + + if textBox, ok := box.(tomo.TextBox); ok { + textBox.SetDotColor(dotColor) + textBox.SetTextColor(textColor) + textBox.SetFace(basicfont.Face7x13) + } + + if containerBox, ok := box.(tomo.ContainerBox); ok { + containerBox.SetGap(image.Pt(8, 8)) + } + + switch role.Object { + case "Button": + mouseDown := false + + updateStyle := func () { + border := []tomo.Border { + engravedBorder, + gapBorder, + buttonBorder, + } + + box.SetColor(buttonColor) + box.SetPadding(tomo.I(4, 8)) + + if box.Focused() { + box.SetColor(buttonColorFocused) + border[1] = focusedBorder + } + if mouseDown { + box.SetColor(buttonColorPressed) + border[2] = sunkenShadow + box.SetPadding(tomo.I(5, 8, 4, 9)) + } + box.SetBorder(border...) + } + updateStyle() + return event.MultiCookie ( + box.OnMouseDown(func (button input.Button) { + if button != input.ButtonLeft { return } + mouseDown = true + updateStyle() + }), + box.OnMouseUp(func (button input.Button) { + if button != input.ButtonLeft { return } + mouseDown = false + updateStyle() + }), + box.OnFocusEnter(updateStyle), + box.OnFocusLeave(updateStyle)) + + case "TextInput", "NumberInput": + box.SetPadding(tomo.I(5, 4, 4, 5)) + updateStyle := func () { + border := []tomo.Border { + engravedBorder, + gapBorder, + sunkenShadow, + } + box.SetColor(inputColor) + + if box.Focused() { + border[1] = focusedBorder + } + + box.SetBorder(border...) + } + updateStyle() + return event.MultiCookie ( + box.OnFocusEnter(updateStyle), + box.OnFocusLeave(updateStyle)) + + case "Container": + if role.Variant == "outer" { + box.SetPadding(tomo.I(8)) + } + + case "Heading": + if textBox, ok := box.(tomo.TextBox); ok { + textBox.SetAlign(tomo.AlignMiddle, tomo.AlignMiddle) + } + + case "Separator": + box.SetBorder(engravedBorder) + box.SetMinimumSize(image.Pt(2, 2)) + + case "Slider": + updateStyle := func () { + border := []tomo.Border { + engravedBorder, + gapBorder, + sunkenShadow, + } + box.SetColor(gutterColor) + + if box.Focused() { + border[1] = focusedBorder + } + + box.SetBorder(border...) + } + updateStyle() + return event.MultiCookie ( + box.OnFocusEnter(updateStyle), + box.OnFocusLeave(updateStyle)) + + case "SliderHandle": + box.SetMinimumSize(image.Pt(12, 12)) + border := []tomo.Border { + outerShadow, + gapBorder, + buttonBorder, + } + box.SetBorder(border...) + box.SetColor(buttonColor) + } + return event.MultiCookie() +}