-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconvalueview.go
93 lines (82 loc) · 2.28 KB
/
iconvalueview.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
91
92
93
// 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 giv
import (
"reflect"
"strings"
"github.com/goki/gi/gi"
"github.com/goki/gi/units"
"github.com/goki/ki/ki"
"github.com/goki/ki/kit"
)
////////////////////////////////////////////////////////////////////////////////////////
// IconValueView
// IconValueView presents an action for displaying an IconName and selecting
// icons from IconChooserDialog
type IconValueView struct {
ValueViewBase
}
var KiT_IconValueView = kit.Types.AddType(&IconValueView{}, nil)
func (vv *IconValueView) WidgetType() reflect.Type {
vv.WidgetTyp = gi.KiT_Action
return vv.WidgetTyp
}
func (vv *IconValueView) UpdateWidget() {
if vv.Widget == nil {
return
}
ac := vv.Widget.(*gi.Action)
txt := kit.ToString(vv.Value.Interface())
if gi.IconName(txt).IsNil() {
ac.SetIcon("blank")
} else {
ac.SetIcon(txt)
}
if sntag, ok := vv.Tag("view"); ok {
if strings.Contains(sntag, "show-name") {
if txt == "" {
txt = "none"
}
ac.SetText(txt)
}
}
}
func (vv *IconValueView) ConfigWidget(widg gi.Node2D) {
vv.Widget = widg
ac := vv.Widget.(*gi.Action)
ac.SetProp("border-radius", units.NewValue(4, units.Px))
ac.SetProp("padding", 0)
ac.SetProp("margin", 0)
ac.ActionSig.ConnectOnly(vv.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
vvv, _ := recv.Embed(KiT_IconValueView).(*IconValueView)
ac := vvv.Widget.(*gi.Action)
vvv.Activate(ac.Viewport, nil, nil)
})
vv.UpdateWidget()
}
func (vv *IconValueView) HasAction() bool {
return true
}
func (vv *IconValueView) Activate(vp *gi.Viewport2D, dlgRecv ki.Ki, dlgFunc ki.RecvFunc) {
if vv.IsInactive() {
return
}
cur := gi.IconName(kit.ToString(vv.Value.Interface()))
desc, _ := vv.Tag("desc")
IconChooserDialog(vp, cur, DlgOpts{Title: "Select an Icon", Prompt: desc},
vv.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
if sig == int64(gi.DialogAccepted) {
ddlg := send.Embed(gi.KiT_Dialog).(*gi.Dialog)
si := SliceViewSelectDialogValue(ddlg)
if si >= 0 {
ic := gi.CurIconList[si]
vv.SetValue(ic)
vv.UpdateWidget()
}
}
if dlgRecv != nil && dlgFunc != nil {
dlgFunc(dlgRecv, send, sig, data)
}
})
}