-
Notifications
You must be signed in to change notification settings - Fork 0
/
treeview.go
90 lines (73 loc) · 2.09 KB
/
treeview.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2018, The Goki Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"math/rand"
"goki.dev/gi/v2/gi"
"goki.dev/gi/v2/gimain"
"goki.dev/gi/v2/giv"
"goki.dev/girl/styles"
"goki.dev/goosi/events"
"goki.dev/mat32/v2"
)
func main() { gimain.Run(app) }
func MakeTree(tv *giv.TreeView, iter, maxIter, maxKids int) {
if iter > maxIter {
return
}
n := rand.Intn(maxKids)
if iter == 0 {
n = maxKids
}
iter++
parnm := tv.Name() + "_"
tv.SetNChildren(n, giv.TreeViewType, parnm+"ch")
for j := 0; j < n; j++ {
kt := tv.Child(j).(*giv.TreeView)
MakeTree(kt, iter, maxIter, maxKids)
}
}
func app() {
// turn this on to see a trace of the rendering
// gi.RenderTrace = true
// gi.LayoutTrace = true
b := gi.NewAppBody("treeview").SetTitle("TreeView Test")
b.App().About = `This is a demo of the treeview in the <b>GoGi</b> graphical interface system, within the <b>Goki</b> tree framework. See <a href="https://github.com/goki">Goki on GitHub</a>
<p>Full Drag-and-Drop, Copy / Cut / Paste, and Keyboard Navigation is supported.</p>`
split := gi.NewSplits(b, "split")
split.Dim = mat32.X
tvfr := gi.NewFrame(split, "tvfr")
svfr := gi.NewFrame(split, "svfr")
split.SetSplits(.3, .7)
svfr.Style(func(s *styles.Style) {
s.Direction = styles.Column
// s.Border.Color.Set(colors.Black)
// s.Border.Width.Set(units.Dp(2))
s.Grow.Set(1, 1)
})
tvfr.Style(func(s *styles.Style) {
s.Direction = styles.Column
// s.Border.Color.Set(colors.Black)
// s.Border.Width.Set(units.Dp(2))
s.Overflow.Y = styles.OverflowAuto
})
tv := giv.NewTreeView(tvfr, "tv")
depth := 3 // 1 = small tree for testing
// depth := 10 // big tree
MakeTree(tv, 0, depth, 5)
nleaves := tv.RootSetViewIdx()
fmt.Println("N leaves:", nleaves)
sv := giv.NewStructView(svfr, "sv")
sv.Style(func(s *styles.Style) {
s.Grow.Set(1, 1)
})
sv.SetStruct(tv)
tv.OnSelect(func(e events.Event) {
if len(tv.SelectedNodes) > 0 {
sv.SetStruct(tv.SelectedNodes[0])
}
})
b.NewWindow().Run().Wait()
}