2023-08-08 00:07:01 -06:00
|
|
|
package wintergreen
|
|
|
|
|
2023-08-08 10:08:26 -06:00
|
|
|
import "image/color"
|
2023-08-08 00:07:01 -06:00
|
|
|
import "git.tebibyte.media/tomo/tomo"
|
|
|
|
import "golang.org/x/image/font/basicfont"
|
|
|
|
import "git.tebibyte.media/tomo/tomo/theme"
|
2023-08-08 10:08:26 -06:00
|
|
|
import "git.tebibyte.media/tomo/tomo/input"
|
|
|
|
import "git.tebibyte.media/tomo/tomo/event"
|
2023-08-08 00:07:01 -06:00
|
|
|
|
2023-08-08 10:08:26 -06:00
|
|
|
var colorFocus = color.RGBA { R: 61, G: 128, B: 143, A: 255 }
|
|
|
|
var colorInput = color.RGBA { R: 208, G: 203, B: 150, A: 255 }
|
2023-08-09 13:23:57 -06:00
|
|
|
var colorCarved = color.RGBA { R: 151, G: 160, B: 150, A: 255 }
|
2023-08-08 10:08:26 -06:00
|
|
|
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
|
2023-08-08 00:07:01 -06:00
|
|
|
|
|
|
|
var outline = tomo.Border {
|
|
|
|
Width: tomo.I(1),
|
|
|
|
Color: [4]color.Color {
|
|
|
|
colorOutline,
|
|
|
|
colorOutline,
|
|
|
|
colorOutline,
|
|
|
|
colorOutline,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-08-08 10:08:26 -06:00
|
|
|
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 }
|
|
|
|
|
2023-08-08 00:07:01 -06:00
|
|
|
type Theme struct { }
|
|
|
|
|
2023-08-09 13:23:57 -06:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-08 10:08:26 -06:00
|
|
|
func (Theme) Apply (object tomo.Object, role theme.Role) event.Cookie {
|
2023-08-11 23:00:56 -06:00
|
|
|
box := object.GetBox()
|
2023-08-08 10:08:26 -06:00
|
|
|
|
|
|
|
if textBox, ok := box.(tomo.TextBox); ok {
|
2023-08-08 00:07:01 -06:00
|
|
|
textBox.SetDotColor(colorFocus)
|
|
|
|
textBox.SetTextColor(colorForeground)
|
2023-08-08 10:08:26 -06:00
|
|
|
textBox.SetFace(basicfont.Face7x13)
|
2023-08-08 00:07:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
switch role.Object {
|
2023-08-08 10:08:26 -06:00
|
|
|
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()
|
2023-08-08 00:07:01 -06:00
|
|
|
}
|
|
|
|
}
|