/
DropDownBox.go
75 lines (57 loc) · 1.47 KB
/
DropDownBox.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
package walkwrap
import (
"github.com/lxn/walk"
)
type DropDownBox struct {
*walk.ComboBox
model *DropDownBoxModel
}
func NewDropDownBox(parent walk.Container, text string, width, height, x, y int) *DropDownBox {
b := new(DropDownBox)
b.ComboBox, _ = walk.NewDropDownBox(parent)
b.SetWidth(width)
b.SetHeight(height)
b.SetY(y)
b.SetX(x)
b.model = NewDropDownBoxModel()
b.SetModel(b.model)
return b
}
func (this *DropDownBox) AddItem(name string) {
this.model.Add(name)
}
type DropDownBoxModel struct {
walk.ListModelBase
data []string
}
/*
// ListModel is the interface that a model must implement to support widgets
// like ComboBox.
type ListModel interface {
// ItemCount returns the number of items in the model.
ItemCount() int
// Value returns the value that should be displayed for the given index.
Value(index int) interface{}
// ItemsReset returns the event that the model should publish when the
// number of its items changes.
ItemsReset() *Event
// ItemChanged returns the event that the model should publish when an item
// was changed.
ItemChanged() *IntEvent
}
*/
func NewDropDownBoxModel() *DropDownBoxModel {
d := new(DropDownBoxModel)
d.data = make([]string, 0)
return d
}
func (this *DropDownBoxModel) Value(index int) interface{} {
return this.data[index]
}
func (this *DropDownBoxModel) ItemCount() int {
return len(this.data)
}
func (this *DropDownBoxModel) Add(v string) {
this.data = append(this.data, v)
this.PublishItemsReset()
}