-
Notifications
You must be signed in to change notification settings - Fork 0
/
fontvalueview.go
80 lines (69 loc) · 2.07 KB
/
fontvalueview.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
// 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"
"github.com/goki/gi/gi"
"github.com/goki/gi/units"
"github.com/goki/ki/ki"
"github.com/goki/ki/kit"
)
////////////////////////////////////////////////////////////////////////////////////////
// FontValueView
// FontValueView presents an action for displaying a FontName and selecting
// fonts from FontChooserDialog
type FontValueView struct {
ValueViewBase
}
var KiT_FontValueView = kit.Types.AddType(&FontValueView{}, nil)
func (vv *FontValueView) WidgetType() reflect.Type {
vv.WidgetTyp = gi.KiT_Action
return vv.WidgetTyp
}
func (vv *FontValueView) UpdateWidget() {
if vv.Widget == nil {
return
}
ac := vv.Widget.(*gi.Action)
txt := kit.ToString(vv.Value.Interface())
ac.SetProp("font-family", txt)
ac.SetText(txt)
}
func (vv *FontValueView) ConfigWidget(widg gi.Node2D) {
vv.Widget = widg
vv.StdConfigWidget(widg)
ac := vv.Widget.(*gi.Action)
ac.SetProp("border-radius", units.NewPx(4))
ac.ActionSig.ConnectOnly(vv.This(), func(recv, send ki.Ki, sig int64, data interface{}) {
vvv, _ := recv.Embed(KiT_FontValueView).(*FontValueView)
ac := vvv.Widget.(*gi.Action)
vvv.Activate(ac.ViewportSafe(), nil, nil)
})
vv.UpdateWidget()
}
func (vv *FontValueView) HasAction() bool {
return true
}
func (vv *FontValueView) Activate(vp *gi.Viewport2D, dlgRecv ki.Ki, dlgFunc ki.RecvFunc) {
if vv.IsInactive() {
return
}
// cur := gi.FontName(kit.ToString(vvv.Value.Interface()))
desc, _ := vv.Tag("desc")
FontChooserDialog(vp, DlgOpts{Title: "Select a Font", 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 := TableViewSelectDialogValue(ddlg)
if si >= 0 {
fi := gi.FontLibrary.FontInfo[si]
vv.SetValue(fi.Name)
vv.UpdateWidget()
}
}
if dlgRecv != nil && dlgFunc != nil {
dlgFunc(dlgRecv, send, sig, data)
}
})
}