cleaning up the component system just a bit more...
This commit is contained in:
@@ -13,19 +13,17 @@ import (
|
||||
"golang.org/x/image/font"
|
||||
)
|
||||
|
||||
func New(ops ...OptFunc) elements.InitFunc {
|
||||
return func() elements.Element {
|
||||
b := Button{
|
||||
Block: blocks.Block{},
|
||||
font: ux.FontFace,
|
||||
color: ux.FontColor,
|
||||
}
|
||||
for op := range ops {
|
||||
ops[op](&b)
|
||||
}
|
||||
|
||||
return &b
|
||||
func New(ops ...OptFunc) elements.Element {
|
||||
b := Button{
|
||||
Block: blocks.Block{},
|
||||
font: ux.FontFace,
|
||||
color: ux.FontColor,
|
||||
}
|
||||
for op := range ops {
|
||||
ops[op](&b)
|
||||
}
|
||||
|
||||
return &b
|
||||
}
|
||||
|
||||
type Button struct {
|
||||
@@ -67,7 +65,7 @@ func (b *Button) HandleMouseEvent(ms mouse.State) bool {
|
||||
if !bnd.Contains(ms.Point()) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
switch {
|
||||
case b.onClick != nil && (ms.RightClicked || ms.LeftClicked):
|
||||
b.onClick(ms)
|
||||
|
||||
@@ -3,14 +3,17 @@ package buttons
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"git.vezzani.net/ben/games/common/elements/v1"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/blocks"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/mouse"
|
||||
)
|
||||
|
||||
type OptFunc func(button *Button)
|
||||
|
||||
type Option interface {
|
||||
OptFunc | blocks.OptFunc
|
||||
func Core(f elements.OptFunc) OptFunc {
|
||||
return func(b *Button) {
|
||||
f(&b.Core)
|
||||
}
|
||||
}
|
||||
|
||||
func OnClick(f func(ms mouse.State)) OptFunc {
|
||||
|
||||
Reference in New Issue
Block a user