-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.go
More file actions
166 lines (142 loc) · 4.9 KB
/
widget.go
File metadata and controls
166 lines (142 loc) · 4.9 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package gui
import (
"github.com/maxfish/GoNativeUI-Core/utils"
)
type IWidget interface {
Id() string
SetId(id string)
Parent() IContainer
setParent(container IContainer)
Style() *WidgetStyle
SetStyle(style WidgetStyle)
// Status
Visible() bool
SetVisible(v bool)
Enabled() bool
SetEnabled(e bool)
// Dimensions
Bounds() utils.Rect
InnerBounds() utils.Rect
SetLeft(left int)
SetTop(top int)
SetDimension(width int, height int)
SetWidth(width int)
SetHeight(height int)
AbsolutePosition() utils.Point
// Layout
Flex() int
SetFlex(flex int)
Stretch() int
SetStretch(stretch int)
MinimumWidth() int
SetMinimumWidth(int)
MaximumWidth() int
SetMaximumWidth(int)
MinimumHeight() int
SetMinimumHeight(int)
MaximumHeight() int
SetMaximumHeight(int)
Measure()
Layout()
MeasuredFlex() int
SetMeasuredFlex(measuredFlex int)
MeasuredHeight() int
SetMeasuredHeight(measuredHeight int)
MeasuredWidth() int
SetMeasuredWidth(measuredWidth int)
// Content
ContentWidth() int
ContentHeight() int
}
type Widget struct {
id string
parent IContainer
enabled bool
visible bool
bounds utils.Rect
style WidgetStyle
minimumWidth int
maximumWidth int
minimumHeight int
maximumHeight int
flex int
stretch int
measuredWidth int
measuredHeight int
measuredFlex int
contentWidth int
contentHeight int
}
// Getters / Setters
func (w *Widget) Id() string { return w.id }
func (w *Widget) SetId(id string) { w.id = id }
func (w *Widget) Parent() IContainer { return w.parent }
func (w *Widget) Style() *WidgetStyle { return &w.style }
func (w *Widget) SetStyle(style WidgetStyle) { w.style = style }
func (w *Widget) setParent(container IContainer) { w.parent = container }
func (w *Widget) Enabled() bool { return w.enabled }
func (w *Widget) SetEnabled(e bool) { w.enabled = e }
func (w *Widget) Visible() bool { return w.visible }
func (w *Widget) SetVisible(v bool) { w.visible = v }
func (w *Widget) InnerBounds() utils.Rect { return w.bounds.ShrinkByInsets(w.style.Padding) }
func (w *Widget) ContentWidth() int { return w.contentWidth }
func (w *Widget) ContentHeight() int { return w.contentHeight }
func (w *Widget) Flex() int { return w.flex }
func (w *Widget) SetFlex(flex int) { w.flex = flex }
func (w *Widget) Stretch() int { return w.stretch }
func (w *Widget) SetStretch(stretch int) { w.stretch = stretch }
func (w *Widget) Bounds() utils.Rect { return w.bounds }
func (w *Widget) SetTop(top int) { w.bounds.Y = top }
func (w *Widget) SetLeft(left int) { w.bounds.X = left }
func (w *Widget) MaximumHeight() int { return w.maximumHeight }
func (w *Widget) SetMaximumHeight(maximumHeight int) { w.maximumHeight = maximumHeight }
func (w *Widget) MinimumHeight() int { return w.minimumHeight }
func (w *Widget) SetMinimumHeight(minimumHeight int) { w.minimumHeight = minimumHeight }
func (w *Widget) MinimumWidth() int { return w.minimumWidth }
func (w *Widget) SetMinimumWidth(minimumWidth int) { w.minimumWidth = minimumWidth }
func (w *Widget) MaximumWidth() int { return w.maximumWidth }
func (w *Widget) SetMaximumWidth(maximumWidth int) { w.maximumWidth = maximumWidth }
func (w *Widget) MeasuredFlex() int { return w.measuredFlex }
func (w *Widget) SetMeasuredFlex(measuredFlex int) { w.measuredFlex = measuredFlex }
func (w *Widget) MeasuredHeight() int { return w.measuredHeight }
func (w *Widget) SetMeasuredHeight(measuredHeight int) { w.measuredHeight = measuredHeight }
func (w *Widget) MeasuredWidth() int { return w.measuredWidth }
func (w *Widget) SetMeasuredWidth(measuredWidth int) { w.measuredWidth = measuredWidth }
func (w *Widget) AbsolutePosition() utils.Point {
p := utils.Point{w.bounds.X, w.bounds.Y}
if w.parent != nil {
p = p.Add(w.parent.AbsolutePosition())
}
return p
}
func (w *Widget) SetWidth(width int) {
if width < w.minimumWidth {
w.bounds.W = w.minimumWidth
} else if w.maximumWidth > 0 && width > w.maximumWidth {
w.bounds.W = w.maximumWidth
} else {
w.bounds.W = width
}
}
func (w *Widget) SetHeight(height int) {
if height < w.minimumHeight {
w.bounds.H = w.minimumHeight
} else if w.maximumHeight > 0 && height > w.maximumHeight {
w.bounds.H = w.maximumHeight
} else {
w.bounds.H = height
}
}
func (w *Widget) SetDimension(width int, height int) {
w.SetWidth(width)
w.SetHeight(height)
}
// Methods which need to be implemented by the widgets
func (w *Widget) Layout() { /* NOP */ }
func (w *Widget) Measure() {
w.measuredFlex = w.flex
}
func widgetInit(w IWidget) {
w.SetEnabled(true)
w.SetVisible(true)
}