Added dynamic styling
This commit is contained in:
parent
32c3717a2e
commit
472d9fdfde
93
theme.go
93
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: 169, G: 171, B: 168, 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,82 @@ 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) 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