include/flex.h

filter: Statementstmt 0.0% 0 / 222 Branchbran 0.0% 0 / 142 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 364 SCAR 0
CC
0
Cov
0%
CRAP 0
« Flex.xs ↑ Summary blib/lib/Layout/Flex.pm »
1 /*
2 * flex.h — CSS Flexible Box layout engine (single + multi-line)
3 *
4 * Supports flex-wrap, align-content, gap (main_gap/cross_gap),
5 * and per-item margins (margin_main_start/end, margin_cross_start/end).
6 * Zero dependencies beyond <stdlib.h> and <float.h>.
7 */
8  
9 #ifndef LAYOUT_FLEX_H
10 #define LAYOUT_FLEX_H
11  
12 #include <stdlib.h>
13 #include <float.h>
14  
15 /* ── direction ──────────────────────────────────────────────────── */
16 #define LF_DIR_ROW 0
17 #define LF_DIR_COLUMN 1
18  
19 /* ── justify-content ────────────────────────────────────────────── */
20 #define LF_JUST_START 0
21 #define LF_JUST_END 1
22 #define LF_JUST_CENTER 2
23 #define LF_JUST_SPACE_BETWEEN 3
24 #define LF_JUST_SPACE_AROUND 4
25 #define LF_JUST_SPACE_EVENLY 5
26  
27 /* ── align-items / align-self ───────────────────────────────────── */
28 #define LF_ALIGN_STRETCH 0
29 #define LF_ALIGN_START 1
30 #define LF_ALIGN_END 2
31 #define LF_ALIGN_CENTER 3
32  
33 /* ── flex-wrap ──────────────────────────────────────────────────── */
34 #define LF_WRAP_NOWRAP 0
35 #define LF_WRAP_WRAP 1
36 #define LF_WRAP_REVERSE 2
37  
38 /* ── align-content ──────────────────────────────────────────────── */
39 #define LF_ACONT_STRETCH 0
40 #define LF_ACONT_START 1
41 #define LF_ACONT_END 2
42 #define LF_ACONT_CENTER 3
43 #define LF_ACONT_SPACE_BETWEEN 4
44 #define LF_ACONT_SPACE_AROUND 5
45 #define LF_ACONT_SPACE_EVENLY 6
46  
47 /* ── item descriptor ─────────────────────────────────────────────── */
48  
49 typedef struct {
50 float basis;
51 float grow;
52 float shrink;
53 float min_main;
54 float max_main; /* 0 = unconstrained */
55 float min_cross;
56 float max_cross; /* 0 = unconstrained */
57 float cross; /* natural cross size (non-stretch align) */
58 int align_self; /* LF_ALIGN_* or -1 to inherit */
59 float margin_main_start; /* margin before item on main axis */
60 float margin_main_end; /* margin after item on main axis */
61 float margin_cross_start; /* margin before item on cross axis */
62 float margin_cross_end; /* margin after item on cross axis */
63 } lf_item_t;
64  
65 /* ── container context ───────────────────────────────────────────── */
66  
67 typedef struct {
68 float main_size;
69 float cross_size;
70 int direction; /* LF_DIR_* */
71 int justify; /* LF_JUST_* */
72 int align_items; /* LF_ALIGN_* */
73 int wrap; /* LF_WRAP_* */
74 int align_content; /* LF_ACONT_* */
75 float main_gap; /* fixed gap between items on main axis */
76 float cross_gap; /* fixed gap between lines on cross axis */
77 lf_item_t *items;
78 int n_items;
79 } lf_ctx_t;
80  
81 /* ── output rectangle ────────────────────────────────────────────── */
82  
83 typedef struct { float x, y, w, h; } lf_rect_t;
84  
85 /* ── internal: per-line descriptor ──────────────────────────────── */
86  
87 typedef struct {
88 int start;
89 int count;
90 float cross_size;
91 float cross_pos;
92 } lf__line_t;
93  
94 /* ── internal helpers ─────────────────────────────────────────────── */
95  
96 0 ▶static float lf__fmax(float a, float b) { return a > b ? a : b; }
Branch: 1 branch
BranchTrueFalseTotal
static float lf__fmax(float a, float b) { return a > b ? a : b; } 0 0 0
97 0 ▶static float lf__fmin(float a, float b) { return a < b ? a : b; }
Branch: 1 branch
BranchTrueFalseTotal
static float lf__fmin(float a, float b) { return a < b ? a : b; } 0 0 0
98 0 static float lf__clamp(float v, float lo, float hi) {
99 0 ▶ return v < lo ? lo : (v > hi ? hi : v);
Branch: 2 branches
BranchTrueFalseTotal
return v < lo ? lo : (v > hi ? hi : v); 0 0 0
return v < lo ? lo : (v > hi ? hi : v); 0 0 0
100 }
101  
102 /* outer main-axis size of one item (content size + margins) */
103 0 static float lf__outer_main(const lf_item_t *it, float size) {
104 0 return size + it->margin_main_start + it->margin_main_end;
105 }
106  
107 /* outer cross-axis size for line-cross contribution */
108 0 static float lf__outer_cross(const lf_item_t *it, float ic) {
109 0 return ic + it->margin_cross_start + it->margin_cross_end;
110 }
111  
112 /* ── grow/shrink violation-freezing loop for one line ──────────── */
113  
114 0 static void lf__flex_line(const lf_item_t *items, int start, int count,
115 float main_size, float main_gap, float *sizes) {
116 0 int i, end = start + count;
117 float *proposed;
118 int *frozen;
119 float free_space;
120 float gaps;
121  
122 0 ▶ if (count <= 0) return;
Branch: 1 branch
BranchTrueFalseTotal
if (count <= 0) return; 0 0 0
123  
124 0 proposed = (float *)calloc((size_t)count, sizeof(float));
125 0 frozen = (int *)calloc((size_t)count, sizeof(int));
126  
127 0 ▶ gaps = main_gap * (count > 1 ? count - 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
gaps = main_gap * (count > 1 ? count - 1 : 0); 0 0 0
128  
129 /* free space = main_size - gaps - sum(outer sizes) */
130 0 free_space = main_size - gaps;
131 0 ▶ for (i = start; i < end; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) 0 0 0
132 0 free_space -= lf__outer_main(&items[i], sizes[i]);
133  
134 0 ▶ if (free_space > 0.0f) {
Branch: 1 branch
BranchTrueFalseTotal
if (free_space > 0.0f) { 0 0 0
135 0 for (;;) {
136 0 float remaining, tg = 0.0f;
137 0 int viol = 0, j;
138 0 remaining = main_size - gaps;
139 0 ▶ for (i = start; i < end; i++) remaining -= lf__outer_main(&items[i], sizes[i]);
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) remaining -= lf__outer_main(&items[i], sizes[i]); 0 0 0
140 0 ▶ for (i = start; i < end; i++) { j = i-start; if (!frozen[j]) tg += items[i].grow; }
Branch: 2 branches
BranchTrueFalseTotal
for (i = start; i < end; i++) { j = i-start; if (!frozen[j]) tg += items[i].grow; } 0 0 0
for (i = start; i < end; i++) { j = i-start; if (!frozen[j]) tg += items[i].grow; } 0 0 0
141 0 ▶ if (tg <= 0.0f) break;
Branch: 1 branch
BranchTrueFalseTotal
if (tg <= 0.0f) break; 0 0 0
142 0 ▶ for (i = start; i < end; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) { 0 0 0
143 0 j = i - start;
144 0 ▶ if (frozen[j]) { proposed[j] = sizes[i]; continue; }
Branch: 1 branch
BranchTrueFalseTotal
if (frozen[j]) { proposed[j] = sizes[i]; continue; } 0 0 0
145 0 proposed[j] = sizes[i] + remaining * (items[i].grow / tg);
146 }
147 0 ▶ for (i = start; i < end; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) { 0 0 0
148 float mn, mx, c;
149 0 j = i - start;
150 0 ▶ if (frozen[j]) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (frozen[j]) continue; 0 0 0
151 0 mn = items[i].min_main;
152 0 ▶ mx = items[i].max_main > 0.0f ? items[i].max_main : FLT_MAX;
Branch: 1 branch
BranchTrueFalseTotal
mx = items[i].max_main > 0.0f ? items[i].max_main : FLT_MAX; 0 0 0
153 0 c = lf__clamp(proposed[j], mn, mx);
154 0 ▶ if (c != proposed[j]) { sizes[i] = c; frozen[j] = 1; viol = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (c != proposed[j]) { sizes[i] = c; frozen[j] = 1; viol = 1; } 0 0 0
155 0 else sizes[i] = proposed[j];
156 }
157 0 ▶ if (!viol) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!viol) break; 0 0 0
158 }
159 0 ▶ } else if (free_space < 0.0f) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (free_space < 0.0f) { 0 0 0
160 0 for (;;) {
161 0 float remaining, ts = 0.0f;
162 0 int viol = 0, j;
163 0 remaining = main_size - gaps;
164 0 ▶ for (i = start; i < end; i++) remaining -= lf__outer_main(&items[i], sizes[i]);
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) remaining -= lf__outer_main(&items[i], sizes[i]); 0 0 0
165 0 ▶ for (i = start; i < end; i++) { j = i-start; if (!frozen[j]) ts += items[i].shrink * sizes[i]; }
Branch: 2 branches
BranchTrueFalseTotal
for (i = start; i < end; i++) { j = i-start; if (!frozen[j]) ts += items[i].shrink * sizes[i]; } 0 0 0
for (i = start; i < end; i++) { j = i-start; if (!frozen[j]) ts += items[i].shrink * sizes[i]; } 0 0 0
166 0 ▶ if (ts <= 0.0f) break;
Branch: 1 branch
BranchTrueFalseTotal
if (ts <= 0.0f) break; 0 0 0
167 0 ▶ for (i = start; i < end; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) { 0 0 0
168 0 j = i - start;
169 0 ▶ if (frozen[j]) { proposed[j] = sizes[i]; continue; }
Branch: 1 branch
BranchTrueFalseTotal
if (frozen[j]) { proposed[j] = sizes[i]; continue; } 0 0 0
170 0 proposed[j] = sizes[i] + remaining * (items[i].shrink * sizes[i] / ts);
171 }
172 0 ▶ for (i = start; i < end; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) { 0 0 0
173 float mn, mx, c;
174 0 j = i - start;
175 0 ▶ if (frozen[j]) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (frozen[j]) continue; 0 0 0
176 0 mn = items[i].min_main;
177 0 ▶ mx = items[i].max_main > 0.0f ? items[i].max_main : FLT_MAX;
Branch: 1 branch
BranchTrueFalseTotal
mx = items[i].max_main > 0.0f ? items[i].max_main : FLT_MAX; 0 0 0
178 0 c = lf__clamp(proposed[j], mn, mx);
179 0 ▶ if (c != proposed[j]) { sizes[i] = c; frozen[j] = 1; viol = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (c != proposed[j]) { sizes[i] = c; frozen[j] = 1; viol = 1; } 0 0 0
180 0 else sizes[i] = proposed[j];
181 }
182 0 ▶ if (!viol) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!viol) break; 0 0 0
183 }
184 }
185  
186 0 free(proposed);
187 0 free(frozen);
188 }
189  
190 /* ── justify spacing for one line ────────────────────────────────── */
191 /*
192 * gap_before — offset before the first item's margin
193 * gap_between — space between consecutive items' outer edges (includes main_gap)
194 */
195 0 static void lf__justify(int justify, float main_size, float main_gap,
196 const lf_item_t *items, float *sizes,
197 int start, int count,
198 float *gap_before, float *gap_between) {
199 0 int i, end = start + count;
200 0 ▶ float ff = main_size - main_gap * (count > 1 ? count - 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
float ff = main_size - main_gap * (count > 1 ? count - 1 : 0); 0 0 0
201 0 ▶ for (i = start; i < end; i++) ff -= lf__outer_main(&items[i], sizes[i]);
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) ff -= lf__outer_main(&items[i], sizes[i]); 0 0 0
202 0 ff = lf__fmax(ff, 0.0f);
203  
204 0 *gap_before = 0.0f;
205 0 *gap_between = main_gap; /* base is the fixed gap */
206  
207 0 switch (justify) {
208 0 case LF_JUST_START: break;
209 0 case LF_JUST_END: *gap_before = ff; break;
210 0 case LF_JUST_CENTER: *gap_before = ff / 2.0f; break;
211 0 case LF_JUST_SPACE_BETWEEN:
212 0 ▶ *gap_between += (count > 1) ? ff / (float)(count - 1) : 0.0f; break;
Branch: 1 branch
BranchTrueFalseTotal
*gap_between += (count > 1) ? ff / (float)(count - 1) : 0.0f; break; 0 0 0
213 0 case LF_JUST_SPACE_AROUND: {
214 0 ▶ float g = (count > 0) ? ff / (float)count : 0.0f;
Branch: 1 branch
BranchTrueFalseTotal
float g = (count > 0) ? ff / (float)count : 0.0f; 0 0 0
215 0 *gap_between += g; *gap_before = g / 2.0f;
216 0 } break;
217 0 case LF_JUST_SPACE_EVENLY: {
218 0 ▶ float g = (count > 0) ? ff / (float)(count + 1) : 0.0f;
Branch: 1 branch
BranchTrueFalseTotal
float g = (count > 0) ? ff / (float)(count + 1) : 0.0f; 0 0 0
219 0 *gap_between += g; *gap_before = g;
220 0 } break;
221 }
222 0 }
223  
224 /* ── main algorithm ──────────────────────────────────────────────── */
225  
226 0 static void lf_compute(const lf_ctx_t *ctx, lf_rect_t *out) {
227 0 int n = ctx->n_items;
228 int i, li;
229 float *sizes;
230 lf__line_t *lines;
231 0 int n_lines = 0;
232  
233 0 ▶ if (n <= 0) return;
Branch: 1 branch
BranchTrueFalseTotal
if (n <= 0) return; 0 0 0
234  
235 0 sizes = (float *)calloc((size_t)n, sizeof(float));
236 0 lines = (lf__line_t *)calloc((size_t)n, sizeof(lf__line_t));
237  
238 /* ── 1. hypothetical main sizes ─────────────────────────────── */
239 0 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 0 0 0
240 0 float mn = ctx->items[i].min_main;
241 0 ▶ float mx = ctx->items[i].max_main > 0.0f ? ctx->items[i].max_main : FLT_MAX;
Branch: 1 branch
BranchTrueFalseTotal
float mx = ctx->items[i].max_main > 0.0f ? ctx->items[i].max_main : FLT_MAX; 0 0 0
242 0 sizes[i] = lf__clamp(ctx->items[i].basis, mn, mx);
243 }
244  
245 /* ── 2. line breaking ────────────────────────────────────────── */
246 0 ▶ if (ctx->wrap == LF_WRAP_NOWRAP) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->wrap == LF_WRAP_NOWRAP) { 0 0 0
247 0 lines[0].start = 0;
248 0 lines[0].count = n;
249 0 n_lines = 1;
250 } else {
251 0 int ls = 0;
252 0 float lsz = 0.0f;
253 0 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 0 0 0
254 0 float outer_i = lf__outer_main(&ctx->items[i], sizes[i]);
255 0 ▶ float gap_i = (i > ls) ? ctx->main_gap : 0.0f;
Branch: 1 branch
BranchTrueFalseTotal
float gap_i = (i > ls) ? ctx->main_gap : 0.0f; 0 0 0
256 0 ▶ if (i > ls && lsz + gap_i + outer_i > ctx->main_size) {
Branch: 2 branches
BranchTrueFalseTotal
if (i > ls && lsz + gap_i + outer_i > ctx->main_size) { 0 0 0
if (i > ls && lsz + gap_i + outer_i > ctx->main_size) { 0 0 0
257 0 lines[n_lines].start = ls;
258 0 lines[n_lines].count = i - ls;
259 0 n_lines++;
260 0 ls = i;
261 0 lsz = outer_i;
262 } else {
263 0 lsz += gap_i + outer_i;
264 }
265 }
266 0 lines[n_lines].start = ls;
267 0 lines[n_lines].count = n - ls;
268 0 n_lines++;
269 }
270  
271 /* ── 3. grow / shrink per line ───────────────────────────────── */
272 0 ▶ for (li = 0; li < n_lines; li++)
Branch: 1 branch
BranchTrueFalseTotal
for (li = 0; li < n_lines; li++) 0 0 0
273 0 lf__flex_line(ctx->items, lines[li].start, lines[li].count,
274 0 ctx->main_size, ctx->main_gap, sizes);
275  
276 /* ── 4. line cross sizes ─────────────────────────────────────── */
277 0 ▶ if (n_lines == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (n_lines == 1) { 0 0 0
278 0 lines[0].cross_size = ctx->cross_size;
279 0 lines[0].cross_pos = 0.0f;
280 } else {
281 0 float total_cs = 0.0f;
282 float ff;
283  
284 0 ▶ for (li = 0; li < n_lines; li++) {
Branch: 1 branch
BranchTrueFalseTotal
for (li = 0; li < n_lines; li++) { 0 0 0
285 0 int start = lines[li].start;
286 0 int end = start + lines[li].count;
287 0 float lcs = 0.0f;
288 0 ▶ for (i = start; i < end; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) { 0 0 0
289 0 int al = (ctx->items[i].align_self >= 0)
290 0 ▶ ? ctx->items[i].align_self : ctx->align_items;
Branch: 1 branch
BranchTrueFalseTotal
? ctx->items[i].align_self : ctx->align_items; 0 0 0
291 0 float ic = (al == LF_ALIGN_STRETCH)
292 0 ? ctx->items[i].min_cross
293 0 ▶ : lf__fmax(ctx->items[i].cross, ctx->items[i].min_cross);
Branch: 1 branch
BranchTrueFalseTotal
: lf__fmax(ctx->items[i].cross, ctx->items[i].min_cross); 0 0 0
294 0 lcs = lf__fmax(lcs, lf__outer_cross(&ctx->items[i], ic));
295 }
296 0 lines[li].cross_size = lcs;
297 0 total_cs += lcs;
298 }
299  
300 0 ff = ctx->cross_size
301 0 - total_cs
302 0 ▶ - ctx->cross_gap * (n_lines > 1 ? n_lines - 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
- ctx->cross_gap * (n_lines > 1 ? n_lines - 1 : 0); 0 0 0
303  
304 /* stretch distributes remaining cross space equally among lines */
305 0 ▶ if (ctx->align_content == LF_ACONT_STRETCH && ff > 0.0f) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->align_content == LF_ACONT_STRETCH && ff > 0.0f) { 0 0 0
if (ctx->align_content == LF_ACONT_STRETCH && ff > 0.0f) { 0 0 0
306 0 float add = ff / (float)n_lines;
307 0 ▶ for (li = 0; li < n_lines; li++) lines[li].cross_size += add;
Branch: 1 branch
BranchTrueFalseTotal
for (li = 0; li < n_lines; li++) lines[li].cross_size += add; 0 0 0
308 0 ff = 0.0f;
309 }
310  
311 /* ── 5. align-content → line cross positions ─────────────── */
312 {
313 0 float gb = 0.0f;
314 0 float gbw = ctx->cross_gap;
315 float pos;
316 0 float pff = lf__fmax(ff, 0.0f);
317  
318 0 switch (ctx->align_content) {
319 0 case LF_ACONT_STRETCH:
320 0 case LF_ACONT_START: break;
321 0 case LF_ACONT_END: gb = pff; break;
322 0 case LF_ACONT_CENTER: gb = pff / 2.0f; break;
323 0 case LF_ACONT_SPACE_BETWEEN:
324 0 ▶ gbw += (n_lines > 1) ? pff / (float)(n_lines - 1) : 0.0f; break;
Branch: 1 branch
BranchTrueFalseTotal
gbw += (n_lines > 1) ? pff / (float)(n_lines - 1) : 0.0f; break; 0 0 0
325 0 case LF_ACONT_SPACE_AROUND: {
326 0 ▶ float g = (n_lines > 0) ? pff / (float)n_lines : 0.0f;
Branch: 1 branch
BranchTrueFalseTotal
float g = (n_lines > 0) ? pff / (float)n_lines : 0.0f; 0 0 0
327 0 gbw += g; gb = g / 2.0f;
328 0 } break;
329 0 case LF_ACONT_SPACE_EVENLY: {
330 0 ▶ float g = (n_lines > 0) ? pff / (float)(n_lines + 1) : 0.0f;
Branch: 1 branch
BranchTrueFalseTotal
float g = (n_lines > 0) ? pff / (float)(n_lines + 1) : 0.0f; 0 0 0
331 0 gbw += g; gb = g;
332 0 } break;
333 }
334  
335 0 ▶ if (ctx->wrap == LF_WRAP_REVERSE) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->wrap == LF_WRAP_REVERSE) { 0 0 0
336 0 pos = gb;
337 0 ▶ for (li = n_lines - 1; li >= 0; li--) {
Branch: 1 branch
BranchTrueFalseTotal
for (li = n_lines - 1; li >= 0; li--) { 0 0 0
338 0 lines[li].cross_pos = pos;
339 0 pos += lines[li].cross_size;
340 0 ▶ if (li > 0) pos += gbw;
Branch: 1 branch
BranchTrueFalseTotal
if (li > 0) pos += gbw; 0 0 0
341 }
342 } else {
343 0 pos = gb;
344 0 ▶ for (li = 0; li < n_lines; li++) {
Branch: 1 branch
BranchTrueFalseTotal
for (li = 0; li < n_lines; li++) { 0 0 0
345 0 lines[li].cross_pos = pos;
346 0 pos += lines[li].cross_size;
347 0 ▶ if (li < n_lines - 1) pos += gbw;
Branch: 1 branch
BranchTrueFalseTotal
if (li < n_lines - 1) pos += gbw; 0 0 0
348 }
349 }
350 }
351 }
352  
353 /* ── 6. place items ─────────────────────────────────────────── */
354 0 ▶ for (li = 0; li < n_lines; li++) {
Branch: 1 branch
BranchTrueFalseTotal
for (li = 0; li < n_lines; li++) { 0 0 0
355 0 int start = lines[li].start;
356 0 int count = lines[li].count;
357 0 int end = start + count;
358 0 float lcs = lines[li].cross_size;
359 0 float cross_origin = lines[li].cross_pos;
360 float gb, gbw, main_pos;
361  
362 0 lf__justify(ctx->justify, ctx->main_size, ctx->main_gap,
363 0 ctx->items, sizes, start, count, &gb, &gbw);
364 0 main_pos = gb;
365  
366 0 ▶ for (i = start; i < end; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = start; i < end; i++) { 0 0 0
367 0 const lf_item_t *it = &ctx->items[i];
368 0 ▶ int al = (it->align_self >= 0) ? it->align_self : ctx->align_items;
Branch: 1 branch
BranchTrueFalseTotal
int al = (it->align_self >= 0) ? it->align_self : ctx->align_items; 0 0 0
369 0 float mn_c = it->min_cross;
370 0 ▶ float mx_c = it->max_cross > 0.0f ? it->max_cross : FLT_MAX;
Branch: 1 branch
BranchTrueFalseTotal
float mx_c = it->max_cross > 0.0f ? it->max_cross : FLT_MAX; 0 0 0
371 0 float nat = it->cross;
372 0 float mcs = it->margin_cross_start;
373 0 float mce = it->margin_cross_end;
374 0 float avail = lcs - mcs - mce; /* cross space inside margins */
375 float ic, cp;
376  
377 0 switch (al) {
378 0 case LF_ALIGN_STRETCH:
379 0 ic = lf__clamp(avail, mn_c, mx_c);
380 0 cp = mcs;
381 0 break;
382 0 case LF_ALIGN_START:
383 0 ic = (nat > 0.0f) ? lf__clamp(nat, mn_c, lf__fmin(mx_c, avail))
384 0 ▶ : lf__clamp(avail, mn_c, mx_c);
Branch: 1 branch
BranchTrueFalseTotal
: lf__clamp(avail, mn_c, mx_c); 0 0 0
385 0 cp = mcs;
386 0 break;
387 0 case LF_ALIGN_END:
388 0 ic = (nat > 0.0f) ? lf__clamp(nat, mn_c, lf__fmin(mx_c, avail))
389 0 ▶ : lf__clamp(avail, mn_c, mx_c);
Branch: 1 branch
BranchTrueFalseTotal
: lf__clamp(avail, mn_c, mx_c); 0 0 0
390 0 cp = lcs - ic - mce;
391 0 break;
392 0 case LF_ALIGN_CENTER:
393 0 ic = (nat > 0.0f) ? lf__clamp(nat, mn_c, lf__fmin(mx_c, avail))
394 0 ▶ : lf__clamp(avail, mn_c, mx_c);
Branch: 1 branch
BranchTrueFalseTotal
: lf__clamp(avail, mn_c, mx_c); 0 0 0
395 0 cp = mcs + (avail - ic) / 2.0f;
396 0 break;
397 0 default:
398 0 ic = avail; cp = mcs;
399 }
400  
401 /* place content box after margin_main_start */
402 0 main_pos += it->margin_main_start;
403  
404 0 ▶ if (ctx->direction == LF_DIR_ROW) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->direction == LF_DIR_ROW) { 0 0 0
405 0 out[i].x = main_pos;
406 0 out[i].y = cross_origin + cp;
407 0 out[i].w = sizes[i];
408 0 out[i].h = ic;
409 } else {
410 0 out[i].x = cross_origin + cp;
411 0 out[i].y = main_pos;
412 0 out[i].w = ic;
413 0 out[i].h = sizes[i];
414 }
415  
416 0 main_pos += sizes[i] + it->margin_main_end;
417 0 ▶ if (i < end - 1) main_pos += gbw;
Branch: 1 branch
BranchTrueFalseTotal
if (i < end - 1) main_pos += gbw; 0 0 0
418 }
419 }
420  
421 0 free(sizes);
422 0 free(lines);
423 }
424  
425 #endif /* LAYOUT_FLEX_H */
« Flex.xs ↑ Summary blib/lib/Layout/Flex.pm »