func (n *TreeToListNode) ToggleExpanded() bool {
	if n.IsExpanded() {
		return n.Collapse()
	} else {
		return n.Expand()
	}
}
ToggleExpanded attempts to toggles the expanded state of the node, returning
true if the state changed.
package mixins
import (
	"fmt"
	"github.com/google/gxui"
)
type treeToListNodeParent interface {
	adjustDescendants(delta int)
}
type TreeToListNode struct {
	item        gxui.AdapterItem        
	container   gxui.TreeNodeContainer  
	descendants int                     
	children    []*TreeToListNode       
	parent      treeToListNodeParent    
	depth       int                     
	onChange    gxui.Event              
}
func (n *TreeToListNode) adjustDescendants(delta int) {
	n.descendants += delta
	n.parent.adjustDescendants(delta)
}
func (n *TreeToListNode) update(nAsParent treeToListNodeParent) {
	if n.IsExpanded() {
		m := make(map[gxui.AdapterItem]*TreeToListNode, len(n.children))
		for _, c := range n.children {
			m[c.item] = c
		}
		depth := n.depth + 1
		n.descendants = 0
		n.children = make([]*TreeToListNode, n.container.Count())
		for i := range n.children {
			node := n.container.NodeAt(i)
			item := node.Item()
			if p, ok := m[item]; ok {
				p.container = node
				p.update(p)
				n.children[i] = p
				n.descendants += p.descendants + 1
			} else {
				n.children[i] = &TreeToListNode{container: node, item: item, parent: nAsParent, depth: depth}
				n.descendants++
			}
		}
	}
	if n.onChange != nil {
		n.onChange.Fire()
	}
}
func (n *TreeToListNode) Item() gxui.AdapterItem {
	return n.item
}
func (n *TreeToListNode) Depth() int {
	return n.depth
}
func (n *TreeToListNode) IsExpanded() bool {
	return n.children != nil
}
func (n *TreeToListNode) IsLeaf() bool {
	return n.container == nil || n.container.Count() == 0
}
func (n *TreeToListNode) Expand() bool {
	if n.parent == nil {
		panic("Expand cannot be called for root nodes")
	}
	if n.IsExpanded() || n.IsLeaf() {
		return false
	}
	depth := n.depth + 1
	n.descendants = n.container.Count()
	n.children = make([]*TreeToListNode, n.descendants)
	for i := range n.children {
		node := n.container.NodeAt(i)
		item := node.Item()
		n.children[i] = &TreeToListNode{container: node, item: item, parent: n, depth: depth}
	}
	n.parent.adjustDescendants(n.descendants)
	if n.onChange != nil {
		n.onChange.Fire()
	}
	return true
}
func (n *TreeToListNode) Collapse() bool {
	if n.parent == nil {
		panic("Collapse cannot be called for root nodes")
	}
	if !n.IsExpanded() || n.IsLeaf() {
		return false
	}
	n.parent.adjustDescendants(-n.descendants)
	n.descendants = 0
	n.children = nil
	if n.onChange != nil {
		n.onChange.Fire()
	}
	return true
}