-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.go
103 lines (95 loc) · 2.09 KB
/
ui.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
94
95
96
97
98
99
100
101
102
103
package faithtop
import (
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)
type IView interface {
getBaseView() *FBaseView
}
func setupWidget(w *gtk.Widget) {
w.SetHAlign(gtk.ALIGN_START)
w.SetVAlign(gtk.ALIGN_START)
w.SetHExpand(false)
w.SetVExpand(false)
}
type FBaseView struct {
view gtk.IWidget
widget *gtk.Widget
gravity int // default:0 , 1,2,3, 4,5,6, 7,8,9
afterAppend func()
alreadyAdded bool
}
func init() {
gtk.Init(nil)
}
var (
idMap = make(map[string]interface{})
)
func RunOnUIThread(f func()) {
glib.IdleAdd(f)
}
func parseSize(iv IView, widget *gtk.Widget, width, height int) {
v := iv.getBaseView()
align := v.gravity % 3
if width < 0 {
if width == -1 {
widget.SetHExpand(false)
if align == 2 {
widget.SetHAlign(gtk.ALIGN_END)
} else if align == 1 {
widget.SetHAlign(gtk.ALIGN_CENTER)
} else {
widget.SetHAlign(gtk.ALIGN_START)
}
} else if width == -2 {
widget.SetHExpand(true)
widget.SetHAlign(gtk.ALIGN_FILL)
}
width = 0
}
if height < 0 {
if height == -1 {
widget.SetVExpand(false)
if align == 2 {
widget.SetVAlign(gtk.ALIGN_END)
} else if align == 1 {
widget.SetVAlign(gtk.ALIGN_CENTER)
} else {
widget.SetVAlign(gtk.ALIGN_START)
}
} else if height == -2 {
widget.SetVExpand(true)
widget.SetVAlign(gtk.ALIGN_FILL)
}
height = 0
}
widget.SetSizeRequest(width, height)
}
func (v *FBaseView) GravityStart() {
v.gravity = 3
v.widget.SetHAlign(gtk.ALIGN_START)
v.widget.SetVAlign(gtk.ALIGN_START)
}
func (v *FBaseView) GravityCenter() {
v.gravity = 4
v.widget.SetHAlign(gtk.ALIGN_CENTER)
v.widget.SetVAlign(gtk.ALIGN_CENTER)
}
func (v *FBaseView) GravityEnd() {
v.gravity = 5
v.widget.SetHAlign(gtk.ALIGN_END)
v.widget.SetVAlign(gtk.ALIGN_END)
}
func (v *FBaseView) IsEnabled() bool {
return v.widget.GetSensitive()
}
func (v *FBaseView) IsVisible() bool {
return v.widget.GetVisible()
}
func (v *FBaseView) GetWidth() int {
al := v.widget.GetAllocation()
return al.GetWidth()
}
func (v *FBaseView) GetHeight() int {
return v.widget.GetAllocation().GetHeight()
}