Tree
A tree is a widget that allows you to display a nested tree structure. Users can use context menus and drag-and-drop to add, remove, and move tree nodes (core.Tree).
For filesystem trees, use a file tree instead. For a struct, use a form. For a non-nested slice, use a list. For a map, use a keyed list.
Properties
You can make a tree and add tree child nodes directly to it:
tr := core.NewTree(b).SetText("Root")
core.NewTree(tr)
c2 := core.NewTree(tr)
core.NewTree(c2)You can make a tree represent another tree.Node tree:
n := tree.NewNodeBase()
tree.NewNodeBase(n)
c2 := tree.NewNodeBase(n)
tree.NewNodeBase(c2)
core.NewTree(b).SyncTree(n)You can prevent users from changing a tree:
n := tree.NewNodeBase()
tree.NewNodeBase(n)
c2 := tree.NewNodeBase(n)
tree.NewNodeBase(c2)
core.NewTree(b).SyncTree(n).SetReadOnly(true)Events
You can detect when a user changes the value of a tree:
n := tree.NewNodeBase()
tree.NewNodeBase(n)
c2 := tree.NewNodeBase(n)
tree.NewNodeBase(c2)
core.NewTree(b).SyncTree(n).OnChange(func(e events.Event) {
core.MessageSnackbar(b, "Tree changed")
})You can add an initialization function that is called automatically with each tree node (this example adds a context menu):
n := tree.NewNodeBase()
tree.NewNodeBase(n)
c2 := tree.NewNodeBase(n)
tree.NewNodeBase(c2)
tr := core.NewTree(b)
tr.SetTreeInit(func(tr *core.Tree) {
tr.AddContextMenu(func(m *core.Scene, pos image.Point) {
core.NewButton(m).SetText("My button")
})
})
tr.SyncTree(n)Styles
You can change the font size of a tree:
tr := core.NewTree(b).SetText("Root")
tr.Styler(func(s *styles.Style) {
s.Font.Size.Dp(25)
})
core.NewTree(tr)
c2 := core.NewTree(tr)
core.NewTree(c2)You can change the icon size of a tree:
tr := core.NewTree(b).SetText("Root")
tr.Styler(func(s *styles.Style) {
s.IconSize.Set(units.Dp(15))
})
core.NewTree(tr)
c2 := core.NewTree(tr)
core.NewTree(c2)Tree button
You can make a button that opens an interactive inspector of a tree:
n := tree.NewNodeBase()
tree.NewNodeBase(n)
c2 := tree.NewNodeBase(n)
tree.NewNodeBase(c2)
core.NewTreeButton(b).SetTree(n)