-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
50 lines (43 loc) · 1.49 KB
/
list.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
package main
import (
"log/slog"
"reflect"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/MatusOllah/gecfg-editor/assets"
)
func makeList(w fyne.Window) fyne.CanvasObject {
l = widget.NewListWithData(
items,
func() fyne.CanvasObject {
return NewIconLabel("", theme.ErrorIcon())
},
func(i binding.DataItem, co fyne.CanvasObject) {
item := NewListItemFromDataItem(i)
co.(*IconLabel).Label.SetText(item.Key)
switch item.Type.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.Uintptr:
co.(*IconLabel).Icon.Resource = theme.NewThemedResource(assets.NumberSVG)
case reflect.String:
co.(*IconLabel).Icon.Resource = theme.NewThemedResource(assets.StringSVG)
case reflect.Bool:
co.(*IconLabel).Icon.Resource = theme.NewThemedResource(assets.BinarySVG)
case reflect.Array, reflect.Slice:
co.(*IconLabel).Icon.Resource = theme.ListIcon()
case reflect.Invalid:
co.(*IconLabel).Icon.Resource = theme.ErrorIcon()
default:
co.(*IconLabel).Icon.Resource = theme.QuestionIcon()
}
co.(*IconLabel).Icon.Refresh()
},
)
l.OnSelected = func(id widget.ListItemID) {
theItems, _ := items.Get()
slog.Info("selected item", "id", id, "item", theItems[id])
curItemBinding.Set(theItems[id])
}
return l
}