tree_node.go 861 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package ultraviolet
  2. import (
  3. "sync"
  4. )
  5. type NodeList []*Node
  6. type NodeMap map[string]*Node
  7. type NodeIds map[string]int
  8. type Node struct {
  9. mutex sync.Mutex
  10. Component Component
  11. Children NodeList
  12. }
  13. func (this *Node) Build(node *Node) {
  14. this.mutex.Lock()
  15. defer this.mutex.Unlock()
  16. this.Component.Clean()
  17. this.Children = NodeList{node}
  18. for _, child := range this.Children {
  19. child.update(this.Component, true)
  20. }
  21. }
  22. func (this *Node) Update() {
  23. this.mutex.Lock()
  24. defer this.mutex.Unlock()
  25. this.update(nil, false)
  26. }
  27. func (this *Node) update(parent Component, force bool) {
  28. if this.Component.Invalidate() || force {
  29. this.Component.Build(parent)
  30. force = true
  31. }
  32. for _, child := range this.Children {
  33. child.update(this.Component, force)
  34. }
  35. }
  36. func NodeListBuild(list NodeList, nodes ...*Node) NodeList {
  37. return append(list, nodes...)
  38. }