@@ -37,6 +37,14 @@ namespace ui
37
37
return (Align)align;
38
38
}
39
39
40
+ Spacing toSpacing (u8 spacing)
41
+ {
42
+ if (spacing >= (u8)Spacing::MAX_SPACING) {
43
+ return Spacing::AFTER;
44
+ }
45
+ return (Spacing)spacing;
46
+ }
47
+
40
48
void Layer::reset ()
41
49
{
42
50
image = Texture ();
@@ -92,6 +100,13 @@ namespace ui
92
100
margin = rf32 (0 .0f , 0 .0f , 0 .0f , 0 .0f );
93
101
padding = rf32 (0 .0f , 0 .0f , 0 .0f , 0 .0f );
94
102
103
+ gap = v2f32 (0 .0f , 0 .0f );
104
+ weight = 0 .0f ;
105
+ span = v2s32 (1 , 1 );
106
+
107
+ hspacing = Spacing::AFTER;
108
+ vspacing = Spacing::AFTER;
109
+
95
110
bg.reset ();
96
111
fg.reset ();
97
112
@@ -130,6 +145,19 @@ namespace ui
130
145
padding.LowerRightCorner = readV2F32 (is);
131
146
}
132
147
148
+ if (testShift (set_mask))
149
+ gap = clamp_vec (readV2F32 (is));
150
+ if (testShift (set_mask))
151
+ weight = std::max (readF32 (is), 0 .0f );
152
+ if (testShift (set_mask)) {
153
+ span = clamp_vec (readV2S32 (is), v2s32 (1 , 1 ));
154
+ }
155
+
156
+ if (testShift (set_mask))
157
+ hspacing = toSpacing (readU8 (is));
158
+ if (testShift (set_mask))
159
+ vspacing = toSpacing (readU8 (is));
160
+
133
161
if (testShift (set_mask))
134
162
bg.read (is);
135
163
if (testShift (set_mask))
@@ -188,7 +216,7 @@ namespace ui
188
216
}
189
217
}
190
218
191
- void Box::layout (const rf32 &parent_rect, const rf32 &parent_clip)
219
+ void Box::layout (const rf32 &parent_rect, const rf32 &parent_clip, bool sizer )
192
220
{
193
221
// Before we layout the box, we need to recompute the style so we have
194
222
// fully updated style properties.
@@ -197,20 +225,37 @@ namespace ui
197
225
// First, calculate the size of the element in absolute coordinates
198
226
// based on the normalized size.
199
227
d2f32 origin_size (
200
- (m_style.rel_size .Width * parent_rect.getWidth ()) + m_style. size . Width ,
201
- (m_style.rel_size .Height * parent_rect.getHeight ()) + m_style. size . Height
228
+ (m_style.rel_size .Width * parent_rect.getWidth ()),
229
+ (m_style.rel_size .Height * parent_rect.getHeight ())
202
230
);
203
231
232
+ if (!sizer) {
233
+ // If this box is not in a sizer, then the "pos" and "size"
234
+ // attributes are absolute pixel amounts to offset the rect by.
235
+ origin_size.Width += m_style.size .Width ;
236
+ origin_size.Height += m_style.size .Height ;
237
+ } else {
238
+ // Otherwise, the "size" attribute is the minimum size of the box
239
+ // and the "pos" attribute is reserved for the sizer's use.
240
+ origin_size.Width = std::max (origin_size.Width , m_style.size .Width );
241
+ origin_size.Height = std::max (origin_size.Height , m_style.size .Height );
242
+ }
243
+
204
244
// Then, create the rect of the element relative to the origin by
205
245
// converting the normalized position absolute coordinates, while
206
246
// accounting for the anchor based on the previously calculated size.
207
247
v2f32 origin_pos (
208
- (m_style.rel_pos .X * parent_rect.getWidth ()) + m_style. pos . X -
248
+ (m_style.rel_pos .X * parent_rect.getWidth ()) -
209
249
(m_style.rel_anchor .X * origin_size.Width ),
210
- (m_style.rel_pos .Y * parent_rect.getHeight ()) + m_style. pos . Y -
250
+ (m_style.rel_pos .Y * parent_rect.getHeight ()) -
211
251
(m_style.rel_anchor .Y * origin_size.Height )
212
252
);
213
253
254
+ if (!sizer) {
255
+ origin_pos.X += m_style.pos .X ;
256
+ origin_pos.Y += m_style.pos .Y ;
257
+ }
258
+
214
259
rf32 origin_rect (origin_pos, origin_size);
215
260
216
261
// The absolute rect of the element is made by shifting the origin to
0 commit comments