This repository has been archived on 2024-05-03. You can view files and clone it, but cannot push or open issues or pull requests.
wintergreen/theme.go

120 lines
3.6 KiB
Go

package wintergreen
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"
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 colorCarved = color.RGBA { R: 151, G: 160, B: 150, A: 255 }
var colorShadow = color.RGBA { R: 57, G: 59, B: 57, A: 255 }
var colorInputShadow = color.RGBA { R: 143, G: 146, B: 91, A: 255 }
var colorHighlight = color.RGBA { R: 207, G: 215, B: 210, A: 255 }
var colorBackground = color.RGBA { R: 169, G: 171, B: 168, A: 255 }
var colorForeground = color.Black
var colorOutline = color.Black
var outline = tomo.Border {
Width: tomo.I(1),
Color: [4]color.Color {
colorOutline,
colorOutline,
colorOutline,
colorOutline,
},
}
var borderColorLifted = [4]color.Color { colorShadow, colorHighlight, colorHighlight, colorShadow }
var borderColorEngraved = [4]color.Color { colorHighlight, colorShadow, colorShadow, colorHighlight }
var borderColorInput = [4]color.Color { colorInputShadow, colorInput, colorInput, colorInputShadow }
var borderColorFocused = [4]color.Color { colorFocus, colorFocus, colorFocus, colorFocus }
type Theme struct { }
func (Theme) RGBA (id theme.Color) (r, g, b, a uint32) {
switch id {
case theme.ColorBackground: return colorBackground .RGBA()
case theme.ColorForeground: return colorForeground .RGBA()
case theme.ColorRaised: return colorCarved .RGBA()
case theme.ColorSunken: return colorCarved .RGBA()
case theme.ColorAccent: return colorFocus .RGBA()
default: return color.Transparent.RGBA()
}
}
func (Theme) Apply (object tomo.Object, role theme.Role) event.Cookie {
box := object.GetBox()
if textBox, ok := box.(tomo.TextBox); ok {
textBox.SetDotColor(colorFocus)
textBox.SetTextColor(colorForeground)
textBox.SetFace(basicfont.Face7x13)
}
switch role.Object {
case "Button":
box.SetColor(colorCarved)
mouseDown := false
updateStyle := func () {
border := []tomo.Border { outline, tomo.Border { } }
switch {
case mouseDown:
border[1].Width = tomo.I(1, 0, 0, 1)
border[1].Color = borderColorLifted
box.SetPadding(tomo.I(9, 8, 8, 9))
case box.Focused():
border[1].Width = tomo.I(1)
border[1].Color = borderColorFocused
box.SetPadding(tomo.I(8))
default:
border[1].Width = tomo.I(1)
border[1].Color = borderColorEngraved
box.SetPadding(tomo.I(8))
}
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.SetColor(colorInput)
updateStyle := func () {
border := []tomo.Border { outline, tomo.Border { } }
switch {
case box.Focused():
border[1].Width = tomo.I(1)
border[1].Color = borderColorFocused
box.SetPadding(tomo.I(8))
default:
border[1].Width = tomo.I(1)
border[1].Color = borderColorInput
box.SetPadding(tomo.I(8))
}
box.SetBorder(border...)
}
updateStyle()
return event.MultiCookie (
box.OnFocusEnter(updateStyle),
box.OnFocusLeave(updateStyle))
default:
box.SetColor(colorBackground)
return event.MultiCookie()
}
}