some refinement
This commit is contained in:
17
common/elements/v1/core/config.go
Normal file
17
common/elements/v1/core/config.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package core
|
||||
|
||||
import "git.vezzani.net/ben/games/common/elements/v1"
|
||||
|
||||
type OptFunc func(*Element)
|
||||
|
||||
func Children(children ...elements.Element) OptFunc {
|
||||
return func(c *Element) {
|
||||
c.children = children
|
||||
}
|
||||
}
|
||||
|
||||
func Name(name string) OptFunc {
|
||||
return func(s *Element) {
|
||||
s.name = name
|
||||
}
|
||||
}
|
||||
32
common/elements/v1/core/core.go
Normal file
32
common/elements/v1/core/core.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"git.vezzani.net/ben/games/common/elements/v1"
|
||||
"git.vezzani.net/ben/games/common/elements/v1/mouse"
|
||||
"git.vezzani.net/ben/games/common/geo"
|
||||
)
|
||||
|
||||
type Element struct {
|
||||
mouse.NopHandler
|
||||
|
||||
anchor geo.Point
|
||||
children []elements.Element
|
||||
|
||||
name string // For debugging
|
||||
}
|
||||
|
||||
func (c *Element) Anchor() geo.Point {
|
||||
return c.anchor
|
||||
}
|
||||
|
||||
func (c *Element) SetAnchor(a geo.Point) {
|
||||
d := c.Anchor().Delta(a)
|
||||
for _, ch := range c.Children() {
|
||||
ch.SetAnchor(ch.Anchor().Add(d))
|
||||
}
|
||||
c.anchor = a
|
||||
}
|
||||
|
||||
func (c *Element) Children() []elements.Element {
|
||||
return c.children
|
||||
}
|
||||
Reference in New Issue
Block a user