-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapselect.go
43 lines (35 loc) · 840 Bytes
/
mapselect.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
package mapselect
import (
"fyne.io/fyne/v2/widget"
"github.com/daichi-m/go18ds/maps/linkedhashmap"
)
type MapSelect struct {
options *linkedhashmap.Map[string, interface{}]
widget.Select
}
func NewMapSelect(onChanged func(string)) *MapSelect {
sel := &MapSelect{
options: linkedhashmap.New[string, interface{}](),
}
sel.ExtendBaseWidget(sel)
sel.OnChanged = onChanged
return sel
}
func (m *MapSelect) SetChanged(onChanged func(string)) {
m.OnChanged = onChanged
}
func (m *MapSelect) Add(key string, value interface{}) {
m.options.Put(key, value)
m.Options = append(m.Options, key)
}
func (m *MapSelect) Key() interface{} {
key, _ := m.options.Get(m.Selected)
return key
}
func (m *MapSelect) Clear() {
m.options.Clear()
m.Options = []string{}
}
func (m *MapSelect) Empty() bool {
return m.options.Size() == 0
}