/
main.go
83 lines (74 loc) · 1.63 KB
/
main.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
package main
import (
"fmt"
"log"
"github.com/mjl-/duit"
"9fans.net/go/draw"
)
func check(err error, msg string) {
if err != nil {
log.Fatalf("%s: %s\n", msg, err)
}
}
func main() {
dui, err := duit.NewDUI("ex/gridlist", nil)
check(err, "new dui")
var rows []*duit.Gridrow
for i := 0; i < 30; i++ {
values := []string{
fmt.Sprintf("cell 0,%d", i),
fmt.Sprintf("cell 1,%d", i),
fmt.Sprintf("cell 2,%d", i),
}
row := &duit.Gridrow{
Selected: i%10 == 0,
Values: values,
}
rows = append(rows, row)
}
rows = append([]*duit.Gridrow{{
Values: []string{
"and this is the longest of them all! and this is the longest of them all! and this is the longest of them all!",
"this is quite a long line",
"but this is is even longer",
},
}}, rows...)
dui.Top.UI = duit.NewScroll(
&duit.Gridlist{
Header: &duit.Gridrow{Values: []string{"col1", "col2", "col3"}},
Rows: rows,
Multiple: true,
Striped: true,
Padding: duit.SpaceXY(10, 2),
Halign: []duit.Halign{
duit.HalignMiddle,
duit.HalignRight,
duit.HalignLeft,
},
Changed: func(index int) (e duit.Event) {
log.Printf("gridlist, index %d changed\n", index)
return
},
Click: func(index int, m draw.Mouse) (e duit.Event) {
log.Printf("gridlist, click, index %d, m %d\n", index, m)
return
},
Keys: func(k rune, m draw.Mouse) (e duit.Event) {
log.Printf("gridlist, key %c, mouse %v\n", k, m)
return
},
},
)
dui.Render()
for {
select {
case e := <-dui.Inputs:
dui.Input(e)
case err, ok := <-dui.Error:
if !ok {
return
}
log.Printf("duit: %s\n", err)
}
}
}