Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7264cf7d2 | |||
| 472d9fdfde |
4
go.mod
4
go.mod
@@ -2,6 +2,6 @@ module git.tebibyte.media/tomo/wintergreen
|
||||
|
||||
go 1.20
|
||||
|
||||
require git.tebibyte.media/tomo/tomo v0.19.0
|
||||
require git.tebibyte.media/tomo/tomo v0.21.0
|
||||
|
||||
require golang.org/x/image v0.8.0 // indirect
|
||||
require golang.org/x/image v0.8.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,5 +1,5 @@
|
||||
git.tebibyte.media/tomo/tomo v0.19.0 h1:emnkcwMRP+Kpk+NFwYtLfQ21H48EFR2ejfaZPhXKmOA=
|
||||
git.tebibyte.media/tomo/tomo v0.19.0/go.mod h1:lTwjpiHbP4UN/kFw+6FwhG600B+PMKVtMOr7wpd5IUY=
|
||||
git.tebibyte.media/tomo/tomo v0.21.0 h1:qUk2FJ355NMpoMlO1NM7G/lRAAKJs3nnpF0VTWqF1Vs=
|
||||
git.tebibyte.media/tomo/tomo v0.21.0/go.mod h1:lTwjpiHbP4UN/kFw+6FwhG600B+PMKVtMOr7wpd5IUY=
|
||||
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=
|
||||
|
||||
104
theme.go
104
theme.go
@@ -1,15 +1,21 @@
|
||||
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: 169, G: 171, B: 168, A: 255 }
|
||||
var colorBackground = color.RGBA { R: 169, G: 171, B: 168, A: 255 }
|
||||
var colorForeground = color.Black
|
||||
var colorOutline = color.Black
|
||||
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),
|
||||
@@ -21,17 +27,93 @@ var outline = tomo.Border {
|
||||
},
|
||||
}
|
||||
|
||||
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) Apply (object tomo.Object, role theme.Role) {
|
||||
if textBox, ok := object.(tomo.TextBox); ok {
|
||||
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.Box()
|
||||
|
||||
if textBox, ok := box.(tomo.TextBox); ok {
|
||||
textBox.SetDotColor(colorFocus)
|
||||
textBox.SetTextColor(colorForeground)
|
||||
textBox.SetFace(basicfont.Face7x13)
|
||||
}
|
||||
|
||||
switch role.Object {
|
||||
case "Button": object.SetColor(colorCarved)
|
||||
case "Input": object.SetColor(colorInput)
|
||||
default: object.SetColor(colorBackground)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user