13
13
14
14
Layout* = ref object of Uiobj
15
15
orientation* : Property[LayoutOrientation]
16
- spacing* , wrapSpacing* : Property[float32 ]
17
- fillWithSpaces* , wrapFillWithSpaces* : Property[bool ]
18
- hugContent* : Property[bool ]
16
+
17
+ hugContent* : Property[bool ] = true .property
19
18
wrapHugContent* : Property[bool ] = true .property
20
- alignment* , wrapAlignment* : Property[LayoutAlignment]
19
+
20
+ align* : Property[LayoutAlignment]
21
+ fillContainer* : Property[bool ]
22
+
23
+ alignContent* , wrapAlignContent* : Property[LayoutAlignment]
24
+
25
+ gap* , wrapGap* : Property[float32 ]
26
+ fillWithSpaces* , wrapFillWithSpaces* : Property[bool ]
21
27
consistentSpacing* : Property[bool ]
22
28
23
29
wrap* : Property[bool ]
28
34
inRepositionProcess: bool
29
35
30
36
InLayout* = ref object of Uiobj
31
- alignment * : Property[LayoutAlignment]
37
+ align * : Property[LayoutAlignment]
32
38
fillContainer* : Property[bool ]
33
39
34
40
isChangingW, isChangingH: bool
@@ -69,8 +75,8 @@ proc reposition(this: Layout) =
69
75
for child in this.childs:
70
76
if child.visibility == collapsed: continue
71
77
if x != 0 :
72
- x += this.spacing []
73
- rows[^ 1 ].freeSpace -= this.spacing []
78
+ x += this.gap []
79
+ rows[^ 1 ].freeSpace -= this.gap []
74
80
x += child.get_w
75
81
inc i
76
82
@@ -81,7 +87,7 @@ proc reposition(this: Layout) =
81
87
(this.lengthBeforeWrap[] > 0 and x > this.lengthBeforeWrap[])
82
88
)
83
89
):
84
- rows[^ 1 ].freeSpace += this.spacing []
90
+ rows[^ 1 ].freeSpace += this.gap []
85
91
rows[^ 1 ].h = h
86
92
i = 1
87
93
x = child.get_w
@@ -104,13 +110,13 @@ proc reposition(this: Layout) =
104
110
105
111
block :
106
112
let freeYSpace =
107
- if this.wrapFillWithSpaces[]: rows.mapit(it.h).foldl(a + this.wrapSpacing [] + b)
113
+ if this.wrapFillWithSpaces[]: rows.mapit(it.h).foldl(a + this.wrapGap [] + b)
108
114
else : 0 'f32
109
115
110
116
var y =
111
117
if this.wrapfillWithSpaces[]: 0 'f32
112
118
else :
113
- case this.wrapAlignment []
119
+ case this.wrapAlignContent []
114
120
of start: 0 'f32
115
121
of center: freeYSpace / 2
116
122
of `end`: freeYSpace
@@ -120,7 +126,7 @@ proc reposition(this: Layout) =
120
126
x =
121
127
if this.fillWithSpaces[]: 0 'f32
122
128
else :
123
- case this.alignment []
129
+ case this.alignContent []
124
130
of start: 0 'f32
125
131
of center: freeSpace / 2
126
132
of `end`: freeSpace
@@ -132,39 +138,57 @@ proc reposition(this: Layout) =
132
138
for child in row:
133
139
child.set_x(x)
134
140
135
- if child of InLayout:
136
- if child.InLayout.fillContainer[]:
141
+ let fillContainer =
142
+ if child of InLayout: child.InLayout.fillContainer[]
143
+ else : this.fillWithSpaces[]
144
+
145
+ let align =
146
+ if child of InLayout: child.InLayout.align[]
147
+ else : this.align[]
148
+
149
+ if fillContainer:
150
+ if child of InLayout:
137
151
for child in child.childs:
138
152
child.set_h(this.get_h)
139
- child.set_y(0 )
140
153
else :
141
- case child.InLayout.alignment[]
142
- of start:
143
- child.set_y(y)
144
- of center:
145
- child.set_y(y + h / 2 - child.get_h / 2 )
146
- of `end`:
147
- child.set_y(y + h - child.get_h)
148
-
154
+ child.set_h(this.get_h)
155
+
156
+ child.set_y(0 )
157
+
149
158
else :
150
- child.set_y(y)
159
+ case align
160
+ of start:
161
+ child.set_y(y)
162
+ of center:
163
+ child.set_y(y + h / 2 - child.get_h / 2 )
164
+ of `end`:
165
+ child.set_y(y + h - child.get_h)
151
166
152
- x += child.get_w + this.spacing [] + spaceBetween
167
+ x += child.get_w + this.gap [] + spaceBetween
153
168
154
- y += h + this.wrapSpacing [] + (if rows.len > 1 : freeYSpace / (rows.len.float32 - 1 ) else : 0 )
169
+ y += h + this.wrapGap [] + (if rows.len > 1 : freeYSpace / (rows.len.float32 - 1 ) else : 0 )
155
170
156
171
if this.hugContent[]:
157
172
if this.childs.len > 0 :
158
173
this.set_w(rows.mapit(it.childs[^ 1 ].get_x + it.childs[^ 1 ].get_w).foldl(max(a, b), 0 'f32))
159
174
else :
160
175
this.set_w(0 )
176
+
161
177
if this.wrapHugContent[]:
162
178
if this.childs.len > 0 :
163
179
this.set_h(rows[^ 1 ].childs.mapit(it.get_y + it.get_h).foldl(max(a, b), 0 'f32))
164
180
else :
165
181
this.set_w(0 )
166
182
167
183
184
+ template spacing* (this: Layout): Property[float32 ] = this.gap
185
+ template wrapSpacing* (this: Layout): Property[float32 ] = this.wrapGap
186
+ template alignment* (this: Layout): Property[float32 ] = this.alignContent
187
+ template wrapAlignment* (this: Layout): Property[float32 ] = this.wrapAlignContent
188
+
189
+ template alignment* (this: InLayout): Property[float32 ] = this.align
190
+
191
+
168
192
method addChild* (this: Layout, child: Uiobj) =
169
193
if this.newChildsObject != nil :
170
194
this.newChildsObject.addChild(child)
@@ -177,7 +201,7 @@ method addChild*(this: Layout, child: Uiobj) =
177
201
# todo : disconnect if child is no loger child
178
202
179
203
if child of InLayout:
180
- child.InLayout.alignment .changed.connectTo this: reposition(this)
204
+ child.InLayout.align .changed.connectTo this: reposition(this)
181
205
child.InLayout.fillContainer.changed.connectTo this: reposition(this)
182
206
183
207
reposition(this)
@@ -214,15 +238,22 @@ method init*(this: Layout) =
214
238
215
239
doRepositionWhenChanged w
216
240
doRepositionWhenChanged h
217
- doRepositionWhenChanged spacing
218
- doRepositionWhenChanged wrapSpacing
219
- doRepositionWhenChanged fillWithSpaces
220
- doRepositionWhenChanged wrapFillWithSpaces
241
+
221
242
doRepositionWhenChanged hugContent
222
243
doRepositionWhenChanged wrapHugContent
223
- doRepositionWhenChanged alignment
224
- doRepositionWhenChanged wrapAlignment
244
+
245
+ doRepositionWhenChanged align
246
+ doRepositionWhenChanged fillContainer
247
+
248
+ doRepositionWhenChanged alignContent
249
+ doRepositionWhenChanged wrapAlignContent
250
+
251
+ doRepositionWhenChanged gap
252
+ doRepositionWhenChanged wrapGap
253
+ doRepositionWhenChanged fillWithSpaces
254
+ doRepositionWhenChanged wrapFillWithSpaces
225
255
doRepositionWhenChanged consistentSpacing
256
+
226
257
doRepositionWhenChanged wrap
227
258
doRepositionWhenChanged elementsBeforeWrap
228
259
doRepositionWhenChanged lengthBeforeWrap
0 commit comments