| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package ultraviolet
- import (
- "sync"
- )
- type NodeList []*Node
- type NodeMap map[string]*Node
- type NodeIds map[string]int
- type Node struct {
- mutex sync.Mutex
- Component Component
- Children NodeList
- }
- func NewNode(component Component) *Node {
- return &Node{
- Children: NodeList{},
- Component: component,
- }
- }
- func (this *Node) Build(node *Node) {
- this.mutex.Lock()
- defer this.mutex.Unlock()
- this.Component.Clean()
- this.Children = NodeList{node}
- for _, child := range this.Children {
- child.update(this.Component, true)
- }
- }
- func (this *Node) Update() {
- this.mutex.Lock()
- defer this.mutex.Unlock()
- this.update(nil, false)
- }
- func (this *Node) update(parent Component, force bool) {
- if this.Component.Invalidate() || force {
- this.Component.Build(parent)
- force = true
- }
- for _, item := range this.Children {
- item.update(this.Component, force)
- }
- }
|