Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
geometry.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <algorithm>
6#include <cctype>
7#include <cmath>
8#include <optional>
9#include <string>
10#include <vector>
11
12namespace pulp::view {
13
19
20struct Point {
21 float x = 0, y = 0;
22
23 Point operator+(const Point& p) const { return {x + p.x, y + p.y}; }
24 Point operator-(const Point& p) const { return {x - p.x, y - p.y}; }
25 bool operator==(const Point& p) const { return x == p.x && y == p.y; }
26};
27
28struct Size {
29 float width = 0, height = 0;
30
31 bool operator==(const Size& s) const { return width == s.width && height == s.height; }
32 bool is_empty() const { return width <= 0 || height <= 0; }
33};
34
35struct IntRect; // below
36
52struct Rect {
53 float x = 0, y = 0, width = 0, height = 0;
54
55 constexpr float right() const { return x + width; }
56 constexpr float bottom() const { return y + height; }
57 Point origin() const { return {x, y}; }
58 Size size() const { return {width, height}; }
59 Point center() const { return {x + width * 0.5f, y + height * 0.5f}; }
60
62 constexpr float center_x() const { return x + width * 0.5f; }
63 constexpr float center_y() const { return y + height * 0.5f; }
64
65 bool contains(Point p) const {
66 return p.x >= x && p.x < right() && p.y >= y && p.y < bottom();
67 }
68 constexpr bool contains(float px, float py) const {
69 return px >= x && px < right() && py >= y && py < bottom();
70 }
71
79 constexpr bool encloses(const Rect& r) const {
80 return r.x >= x && r.y >= y && r.right() <= right() && r.bottom() <= bottom();
81 }
82
83 constexpr bool is_empty() const { return width <= 0 || height <= 0; }
84
85 Rect inset(float amount) const {
86 return {x + amount, y + amount,
87 std::max(0.0f, width - 2 * amount),
88 std::max(0.0f, height - 2 * amount)};
89 }
90
91 Rect inset(float h, float v) const {
92 return {x + h, y + v,
93 std::max(0.0f, width - 2 * h),
94 std::max(0.0f, height - 2 * v)};
95 }
96
97 // ── Non-mutating derivations ─────────────────────────────────────────
99 Rect reduced(float d) const { return inset(d); }
100 Rect reduced(float dx, float dy) const { return inset(dx, dy); }
102 Rect expanded(float d) const { return inset(-d); }
103 Rect expanded(float dx, float dy) const { return inset(-dx, -dy); }
104
105 constexpr Rect translated(float dx, float dy) const {
106 return {x + dx, y + dy, width, height};
107 }
108
109 constexpr Rect with_x(float v) const { return {v, y, width, height}; }
110 constexpr Rect with_y(float v) const { return {x, v, width, height}; }
111 constexpr Rect with_width(float v) const { return {x, y, v, height}; }
112 constexpr Rect with_height(float v) const { return {x, y, width, v}; }
113 constexpr Rect with_size(float w, float h) const { return {x, y, w, h}; }
114 constexpr Rect with_position(float nx, float ny) const {
115 return {nx, ny, width, height};
116 }
117
119 constexpr Rect with_size_keeping_center(float w, float h) const {
120 return {x + (width - w) * 0.5f, y + (height - h) * 0.5f, w, h};
121 }
122
123 // ── The slicing idiom ────────────────────────────────────────────────
124 // `remove_from_*` MUTATES this rect and returns the slice taken off. It is
125 // the standard way to lay a row of controls out of a bounds rect:
126 //
127 // auto header = bounds.remove_from_top(24);
128 // auto footer = bounds.remove_from_bottom(24);
129 // // `bounds` is now just the middle.
130 //
131 // Asking for more than exists takes everything and leaves an empty rect.
132 // Asking for a NEGATIVE amount takes nothing and changes nothing — a
133 // deliberate choice: the alternative (a negative-height slice, which is
134 // what naive arithmetic produces) is never what a caller wants and turns a
135 // simple sign bug into an invisible, badly-clipped widget.
136 Rect remove_from_top(float amount) {
137 if (amount <= 0) return {x, y, width, 0};
138 const float take = std::min(amount, height);
139 const Rect taken{x, y, width, take};
140 y += take;
141 height -= take;
142 return taken;
143 }
144 Rect remove_from_bottom(float amount) {
145 if (amount <= 0) return {x, bottom(), width, 0};
146 const float take = std::min(amount, height);
147 height -= take;
148 return {x, y + height, width, take};
149 }
150 Rect remove_from_left(float amount) {
151 if (amount <= 0) return {x, y, 0, height};
152 const float take = std::min(amount, width);
153 const Rect taken{x, y, take, height};
154 x += take;
155 width -= take;
156 return taken;
157 }
158 Rect remove_from_right(float amount) {
159 if (amount <= 0) return {right(), y, 0, height};
160 const float take = std::min(amount, width);
161 width -= take;
162 return {x + width, y, take, height};
163 }
164
165 // ── Set operations ───────────────────────────────────────────────────
166 constexpr bool intersects(const Rect& o) const {
167 if (is_empty() || o.is_empty()) return false;
168 return x < o.right() && right() > o.x && y < o.bottom() && bottom() > o.y;
169 }
170
172 Rect intersection(const Rect& o) const {
173 const float ix = std::max(x, o.x);
174 const float iy = std::max(y, o.y);
175 const float ir = std::min(right(), o.right());
176 const float ib = std::min(bottom(), o.bottom());
177 if (ir <= ix || ib <= iy) return {};
178 return {ix, iy, ir - ix, ib - iy};
179 }
180
184 Rect union_with(const Rect& o) const {
185 if (is_empty()) return o;
186 if (o.is_empty()) return *this;
187 const float ux = std::min(x, o.x);
188 const float uy = std::min(y, o.y);
189 const float ur = std::max(right(), o.right());
190 const float ub = std::max(bottom(), o.bottom());
191 return {ux, uy, ur - ux, ub - uy};
192 }
193
194 // ── Conversion ───────────────────────────────────────────────────────
198 IntRect to_nearest_int() const;
199
202
203 bool operator==(const Rect& r) const {
204 return x == r.x && y == r.y && width == r.width && height == r.height;
205 }
206 bool operator!=(const Rect& r) const { return !(*this == r); }
207};
208
213struct IntRect {
214 int x = 0, y = 0, width = 0, height = 0;
215
216 constexpr int right() const { return x + width; }
217 constexpr int bottom() const { return y + height; }
218
221 constexpr int center_x() const { return x + width / 2; }
222 constexpr int center_y() const { return y + height / 2; }
223
224 constexpr bool is_empty() const { return width <= 0 || height <= 0; }
225
226 constexpr bool contains(int px, int py) const {
227 return px >= x && px < right() && py >= y && py < bottom();
228 }
229 constexpr bool contains(const IntRect& r) const {
230 return r.x >= x && r.y >= y && r.right() <= right() && r.bottom() <= bottom();
231 }
232
233 IntRect reduced(int d) const {
234 return {x + d, y + d, std::max(0, width - 2 * d), std::max(0, height - 2 * d)};
235 }
236 IntRect reduced(int dx, int dy) const {
237 return {x + dx, y + dy, std::max(0, width - 2 * dx), std::max(0, height - 2 * dy)};
238 }
239 IntRect expanded(int d) const { return reduced(-d); }
240 IntRect expanded(int dx, int dy) const { return reduced(-dx, -dy); }
241
242 constexpr IntRect translated(int dx, int dy) const {
243 return {x + dx, y + dy, width, height};
244 }
245
246 constexpr IntRect with_x(int v) const { return {v, y, width, height}; }
247 constexpr IntRect with_y(int v) const { return {x, v, width, height}; }
248 constexpr IntRect with_width(int v) const { return {x, y, v, height}; }
249 constexpr IntRect with_height(int v) const { return {x, y, width, v}; }
250 constexpr IntRect with_size(int w, int h) const { return {x, y, w, h}; }
251 constexpr IntRect with_position(int nx, int ny) const {
252 return {nx, ny, width, height};
253 }
254
258 constexpr IntRect with_size_keeping_center(int w, int h) const {
259 return {x + (width - w) / 2, y + (height - h) / 2, w, h};
260 }
261
262 // ── The slicing idiom (integer) ──────────────────────────────────────
263 // Same contract as the float version, including the negative-amount guard.
265 if (amount <= 0) return {x, y, width, 0};
266 const int take = std::min(amount, height);
267 const IntRect taken{x, y, width, take};
268 y += take;
269 height -= take;
270 return taken;
271 }
273 if (amount <= 0) return {x, bottom(), width, 0};
274 const int take = std::min(amount, height);
275 height -= take;
276 return {x, y + height, width, take};
277 }
279 if (amount <= 0) return {x, y, 0, height};
280 const int take = std::min(amount, width);
281 const IntRect taken{x, y, take, height};
282 x += take;
283 width -= take;
284 return taken;
285 }
287 if (amount <= 0) return {right(), y, 0, height};
288 const int take = std::min(amount, width);
289 width -= take;
290 return {x + width, y, take, height};
291 }
292
293 constexpr bool intersects(const IntRect& o) const {
294 if (is_empty() || o.is_empty()) return false;
295 return x < o.right() && right() > o.x && y < o.bottom() && bottom() > o.y;
296 }
297
299 const int ix = std::max(x, o.x);
300 const int iy = std::max(y, o.y);
301 const int ir = std::min(right(), o.right());
302 const int ib = std::min(bottom(), o.bottom());
303 if (ir <= ix || ib <= iy) return {};
304 return {ix, iy, ir - ix, ib - iy};
305 }
306
307 IntRect union_with(const IntRect& o) const {
308 if (is_empty()) return o;
309 if (o.is_empty()) return *this;
310 const int ux = std::min(x, o.x);
311 const int uy = std::min(y, o.y);
312 const int ur = std::max(right(), o.right());
313 const int ub = std::max(bottom(), o.bottom());
314 return {ux, uy, ur - ux, ub - uy};
315 }
316
318 constexpr Rect to_float() const {
319 return {static_cast<float>(x), static_cast<float>(y),
320 static_cast<float>(width), static_cast<float>(height)};
321 }
322
323 constexpr bool operator==(const IntRect& r) const {
324 return x == r.x && y == r.y && width == r.width && height == r.height;
325 }
326 constexpr bool operator!=(const IntRect& r) const { return !(*this == r); }
327};
328
330 // Round the EDGES, then derive the extent — so a rect spanning [0.6, 2.4]
331 // becomes [1, 2] (width 1), not "width round(1.8) = 2" starting at 1.
332 const int l = static_cast<int>(std::lround(x));
333 const int t = static_cast<int>(std::lround(y));
334 const int r = static_cast<int>(std::lround(right()));
335 const int b = static_cast<int>(std::lround(bottom()));
336 return {l, t, r - l, b - t};
337}
338
340 const int l = static_cast<int>(std::floor(x));
341 const int t = static_cast<int>(std::floor(y));
342 const int r = static_cast<int>(std::ceil(right()));
343 const int b = static_cast<int>(std::ceil(bottom()));
344 return {l, t, r - l, b - t};
345}
346
347// Layout mode
348enum class LayoutMode { flex, grid };
349
350// Flex layout direction. row_reverse / column_reverse route
351// `flexDirection: 'row-reverse' | 'column-reverse'` to
352// YGFlexDirectionRowReverse / ColumnReverse.
354
359
367
368// Flex alignment (auto_ = inherit from parent's align_items).
369// `baseline` maps to YGAlignBaseline.
371
381
389
390// ── Viewport-Relative Dimension Units ───────────────────────────────────────
391
401
402struct Dimension {
403 float value = 0.0f;
405
406 float resolve(float parent_size, float viewport_w, float viewport_h,
407 float dpi_scale = 1.0f) const {
408 switch (unit) {
409 case DimensionUnit::px: return value * dpi_scale;
410 case DimensionUnit::percent: return value / 100.0f * parent_size;
411 case DimensionUnit::vw: return value / 100.0f * viewport_w;
412 case DimensionUnit::vh: return value / 100.0f * viewport_h;
413 case DimensionUnit::vmin: return value / 100.0f * std::min(viewport_w, viewport_h);
414 case DimensionUnit::vmax: return value / 100.0f * std::max(viewport_w, viewport_h);
415 case DimensionUnit::auto_: return 0.0f;
416 }
417 return value;
418 }
419
420 static Dimension parse(const std::string& str) {
421 auto trim = [](std::string s) {
422 while (!s.empty() && std::isspace(static_cast<unsigned char>(s.front()))) s.erase(0, 1);
423 while (!s.empty() && std::isspace(static_cast<unsigned char>(s.back()))) s.pop_back();
424 return s;
425 };
426
427 const auto input = trim(str);
428 if (input == "auto") return {0, DimensionUnit::auto_};
429 Dimension d;
430 size_t pos = 0;
431 try { d.value = std::stof(input, &pos); } catch (...) { return d; }
432 auto suffix = trim(input.substr(pos));
433 if (suffix == "vw") d.unit = DimensionUnit::vw;
434 else if (suffix == "vh") d.unit = DimensionUnit::vh;
435 else if (suffix == "vmin") d.unit = DimensionUnit::vmin;
436 else if (suffix == "vmax") d.unit = DimensionUnit::vmax;
437 else if (suffix == "%") d.unit = DimensionUnit::percent;
438 else if (suffix.empty() || suffix == "px") d.unit = DimensionUnit::px;
439 else return {};
440 return d;
441 }
442};
443
444// Flex layout properties for a view
445struct FlexStyle {
449
468
470
471 float gap = 0;
472 float row_gap = -1;
473 float column_gap = -1;
474
475 float padding = 0;
476 float padding_top = -1;
477 float padding_right = -1;
478 float padding_bottom = -1;
479 float padding_left = -1;
480
481 float margin = 0;
482 float margin_top = -1;
483 float margin_right = -1;
484 float margin_bottom = -1;
485 float margin_left = -1;
486
487 float flex_grow = 0;
488 float flex_shrink = 1;
489 float flex_basis = -1;
490
491 float min_width = 0;
492 float min_height = 0;
495 float max_width = 0;
496 float max_height = 0;
497
514
529
550
559 enum class WritingDirection { inherit, ltr, rtl };
561
564 void resolve_dimensions(float parent_w, float parent_h,
565 float viewport_w, float viewport_h, float dpi = 1.0f) {
566 if (dim_width.unit != DimensionUnit::px || dim_width.value != 0)
567 preferred_width = dim_width.resolve(parent_w, viewport_w, viewport_h, dpi);
568 if (dim_height.unit != DimensionUnit::px || dim_height.value != 0)
569 preferred_height = dim_height.resolve(parent_h, viewport_w, viewport_h, dpi);
570 if (dim_min_width.unit != DimensionUnit::px || dim_min_width.value != 0)
571 min_width = dim_min_width.resolve(parent_w, viewport_w, viewport_h, dpi);
572 if (dim_min_height.unit != DimensionUnit::px || dim_min_height.value != 0)
573 min_height = dim_min_height.resolve(parent_h, viewport_w, viewport_h, dpi);
574 }
575
588 int order = 0;
589
599 std::optional<float> aspect_ratio;
600
601 // Helper: resolve per-side margin
602 float margin_t() const { return margin_top >= 0 ? margin_top : margin; }
603 float margin_r() const { return margin_right >= 0 ? margin_right : margin; }
604 float margin_b() const { return margin_bottom >= 0 ? margin_bottom : margin; }
605 float margin_l() const { return margin_left >= 0 ? margin_left : margin; }
606
607 // Helper: resolve directional gap. row_reverse counts as a row-axis
608 // container; the visual reversal doesn't change which gap edge
609 // (column-gap) sits between siblings.
610 float effective_gap(FlexDirection dir) const {
612 return column_gap >= 0 ? column_gap : gap;
613 return row_gap >= 0 ? row_gap : gap;
614 }
615
616 // Helper: resolve flex_basis or preferred size
617 float basis_or_preferred(bool is_row) const {
618 if (flex_basis >= 0) return flex_basis;
619 return is_row ? preferred_width : preferred_height;
620 }
621};
622
624struct GridTrack {
625 enum class Type { fixed, fr, auto_ };
627 float value = 1.0f;
628
629 static GridTrack fixed_px(float px) { return {Type::fixed, px}; }
630 static GridTrack fractional(float fr) { return {Type::fr, fr}; }
631 static GridTrack auto_size() { return {Type::auto_, 0}; }
632};
633
642struct GridStyle {
643 std::vector<GridTrack> template_columns;
644 std::vector<GridTrack> template_rows;
645
651
660
661 float column_gap = 0;
662 float row_gap = 0;
663
670 struct NamedArea {
671 std::string name;
672 int col_start = 1;
673 int col_end = 1;
674 int row_start = 1;
675 int row_end = 1;
676 };
677 std::vector<NamedArea> template_areas;
678
679 // Per-child grid placement
687 std::string grid_area_name;
688
691 static std::vector<GridTrack> parse_template(const std::string& tmpl, int depth = 0);
692
699 static std::vector<NamedArea> parse_template_areas(const std::string& css);
700
702 static AutoFlow parse_auto_flow(const std::string& s) {
703 if (s == "column") return AutoFlow::column;
704 if (s == "dense" || s == "row dense") return AutoFlow::row_dense;
705 if (s == "column dense") return AutoFlow::column_dense;
706 return AutoFlow::row;
707 }
708};
709
710} // namespace pulp::view
Definition affine_transform.hpp:48
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
FlexJustify
Justify content modes (main axis space distribution).
Definition geometry.hpp:373
@ space_evenly
Equal space between items AND at edges.
Definition geometry.hpp:379
@ end_
Pack items to end.
Definition geometry.hpp:376
@ start
Pack items to start (default).
Definition geometry.hpp:374
FlexDirection
Definition geometry.hpp:353
@ column
Definition geometry.hpp:353
@ column_reverse
Definition geometry.hpp:353
@ row_reverse
Definition geometry.hpp:353
@ row
Definition geometry.hpp:353
LayoutMode
Definition geometry.hpp:348
@ flex
Definition geometry.hpp:348
@ grid
Definition geometry.hpp:348
FlexWrap
Flex-wrap tri-state.
Definition geometry.hpp:358
@ no_wrap
Definition geometry.hpp:358
@ wrap_reverse
Definition geometry.hpp:358
@ wrap
Definition geometry.hpp:358
pulp::canvas::AffineTransform AffineTransform
The 2D affine transform value type.
Definition geometry.hpp:18
DimensionUnit
Definition geometry.hpp:392
@ vh
Percentage of viewport height.
Definition geometry.hpp:396
@ px
Absolute pixels.
Definition geometry.hpp:393
@ percent
Percentage of parent dimension.
Definition geometry.hpp:394
@ vw
Percentage of viewport width.
Definition geometry.hpp:395
@ vmin
Percentage of min(viewport width, height).
Definition geometry.hpp:397
@ vmax
Percentage of max(viewport width, height).
Definition geometry.hpp:398
@ auto_
Auto-sized (let layout decide).
Definition geometry.hpp:399
FlexOverflow
Overflow behavior.
Definition geometry.hpp:383
@ scroll
Content clipped, scrollbar shown when needed.
Definition geometry.hpp:386
@ visible
Content renders beyond bounds (default for views).
Definition geometry.hpp:384
@ hidden
Content clipped to bounds.
Definition geometry.hpp:385
@ s
Definition input_events.hpp:41
@ h
Definition input_events.hpp:39
@ l
Definition input_events.hpp:40
@ r
Definition input_events.hpp:41
@ d
Definition input_events.hpp:39
@ p
Definition input_events.hpp:40
@ b
Definition input_events.hpp:39
@ v
Definition input_events.hpp:41
@ o
Definition input_events.hpp:40
@ t
Definition input_events.hpp:41
@ w
Definition input_events.hpp:41
@ column
Definition design_ir.hpp:53
@ row
Definition design_ir.hpp:53
FlexAlign
Definition geometry.hpp:370
@ stretch
Definition geometry.hpp:370
@ end
Definition geometry.hpp:370
@ auto_
Definition geometry.hpp:370
@ baseline
Definition geometry.hpp:370
@ start
Definition geometry.hpp:370
BoxSizing
CSS box-sizing.
Definition geometry.hpp:366
@ border_box
Definition geometry.hpp:366
@ content_box
Definition geometry.hpp:366
@ stretch
Definition design_ir.hpp:57
@ space_around
Definition design_ir.hpp:57
@ center
Definition design_ir.hpp:57
@ space_between
Definition design_ir.hpp:57
Definition geometry.hpp:402
float resolve(float parent_size, float viewport_w, float viewport_h, float dpi_scale=1.0f) const
Definition geometry.hpp:406
DimensionUnit unit
Definition geometry.hpp:404
static Dimension parse(const std::string &str)
Definition geometry.hpp:420
float value
Definition geometry.hpp:403
Definition geometry.hpp:445
float flex_grow
0 = fixed size, >0 = share remaining space
Definition geometry.hpp:487
float preferred_width
Definition geometry.hpp:493
Dimension dim_padding_right
Definition geometry.hpp:526
Dimension dim_padding_start
Definition geometry.hpp:546
Dimension dim_margin_right
Definition geometry.hpp:522
float padding_top
Per-side padding (-1 = use uniform padding).
Definition geometry.hpp:476
Dimension dim_width
Viewport-relative dimension overrides.
Definition geometry.hpp:507
WritingDirection
Node writing direction.
Definition geometry.hpp:559
@ rtl
Definition geometry.hpp:559
@ inherit
Definition geometry.hpp:559
@ ltr
Definition geometry.hpp:559
Dimension dim_height
Definition geometry.hpp:508
FlexAlign align_content
align-content is the CSS / Yoga multi-line flex cross-axis distribution control.
Definition geometry.hpp:459
float row_gap
Gap between rows (-1 = use gap).
Definition geometry.hpp:472
float margin
Uniform margin around this view.
Definition geometry.hpp:481
Dimension dim_margin_top
Per-edge margin / padding accept percent strings (and auto for margin only).
Definition geometry.hpp:521
FlexJustify justify_content
Definition geometry.hpp:469
AlignContentSpace
True when align_content was set to one of the space-* values (space-between / space-around / space-ev...
Definition geometry.hpp:466
@ none
Definition geometry.hpp:466
@ space_evenly
Definition geometry.hpp:466
@ space_around
Definition geometry.hpp:466
@ space_between
Definition geometry.hpp:466
float preferred_height
Definition geometry.hpp:494
FlexAlign align_items
Definition geometry.hpp:447
Dimension dim_padding_top
Definition geometry.hpp:525
Dimension dim_end
Definition geometry.hpp:549
float margin_r() const
Definition geometry.hpp:603
float min_width
Definition geometry.hpp:491
Dimension dim_margin_bottom
Definition geometry.hpp:523
FlexDirection direction
Definition geometry.hpp:446
float basis_or_preferred(bool is_row) const
Definition geometry.hpp:617
Dimension dim_min_width
Definition geometry.hpp:509
FlexAlign align_self
Override parent's align_items for this child.
Definition geometry.hpp:448
float margin_b() const
Definition geometry.hpp:604
float padding
Definition geometry.hpp:475
BoxSizing box_sizing
CSS box-sizing.
Definition geometry.hpp:587
std::optional< float > aspect_ratio
Aspect ratio (width / height).
Definition geometry.hpp:599
float gap
Shorthand for both row_gap and column_gap.
Definition geometry.hpp:471
Dimension dim_max_width
Definition geometry.hpp:511
AlignContentSpace align_content_space
Definition geometry.hpp:467
float margin_left
Definition geometry.hpp:485
float padding_left
Definition geometry.hpp:479
float column_gap
Gap between columns (-1 = use gap).
Definition geometry.hpp:473
float margin_l() const
Definition geometry.hpp:605
Dimension dim_padding_bottom
Definition geometry.hpp:527
Dimension dim_max_height
Definition geometry.hpp:512
float padding_bottom
Definition geometry.hpp:478
float flex_basis
Initial main size before grow/shrink (-1 = use preferred).
Definition geometry.hpp:489
Dimension dim_margin_start
Yoga logical-edge fan-out.
Definition geometry.hpp:544
FlexWrap flex_wrap
Tri-state wrap.
Definition geometry.hpp:581
Dimension dim_start
Definition geometry.hpp:548
Dimension dim_margin_left
Definition geometry.hpp:524
float margin_bottom
Definition geometry.hpp:484
int order
Layout order (lower values first, default 0).
Definition geometry.hpp:588
float flex_shrink
1 = shrink proportionally if overflow
Definition geometry.hpp:488
float min_height
Definition geometry.hpp:492
void resolve_dimensions(float parent_w, float parent_h, float viewport_w, float viewport_h, float dpi=1.0f)
Resolve viewport-relative dimensions and apply to float fields.
Definition geometry.hpp:564
WritingDirection writing_direction
Definition geometry.hpp:560
float margin_top
Per-side margin (-1 = use uniform margin).
Definition geometry.hpp:482
Dimension dim_padding_left
Definition geometry.hpp:528
float effective_gap(FlexDirection dir) const
Definition geometry.hpp:610
float max_height
0 = no maximum
Definition geometry.hpp:496
float max_width
0 = no maximum
Definition geometry.hpp:495
Dimension dim_flex_basis
Definition geometry.hpp:513
Dimension dim_margin_end
Definition geometry.hpp:545
float padding_right
Definition geometry.hpp:477
float margin_t() const
Definition geometry.hpp:602
Dimension dim_padding_end
Definition geometry.hpp:547
Dimension dim_min_height
Definition geometry.hpp:510
float margin_right
Definition geometry.hpp:483
Named-area grid.
Definition geometry.hpp:670
std::string name
Definition geometry.hpp:671
int col_end
Definition geometry.hpp:673
int row_end
Definition geometry.hpp:675
int row_start
Definition geometry.hpp:674
int col_start
Definition geometry.hpp:672
Grid layout properties (CSS Grid Level 1 subset).
Definition geometry.hpp:642
std::vector< NamedArea > template_areas
Definition geometry.hpp:677
std::string grid_area_name
grid-area: header references the parent's NamedArea by name.
Definition geometry.hpp:687
std::vector< GridTrack > template_rows
grid-template-rows
Definition geometry.hpp:644
AutoFlow auto_flow
Definition geometry.hpp:659
int grid_row_start
Definition geometry.hpp:682
static std::vector< GridTrack > parse_template(const std::string &tmpl, int depth=0)
Parse "1fr 2fr auto 100px" into track list.
std::vector< GridTrack > template_columns
grid-template-columns
Definition geometry.hpp:643
static AutoFlow parse_auto_flow(const std::string &s)
Parse the auto-flow keyword string. Unrecognized → row.
Definition geometry.hpp:702
float column_gap
grid-column-gap
Definition geometry.hpp:661
GridTrack auto_columns
Implicit-track sizing for auto-placed items that overflow the explicit grid.
Definition geometry.hpp:649
int grid_column_end
0 = span 1
Definition geometry.hpp:681
int grid_column_start
0 = auto placement
Definition geometry.hpp:680
int grid_row_end
Definition geometry.hpp:683
AutoFlow
Auto-flow direction.
Definition geometry.hpp:653
@ column
fill columns top-to-bottom then wrap
Definition geometry.hpp:655
@ column_dense
column + dense-packing
Definition geometry.hpp:657
@ row_dense
row + dense-packing (fill earlier holes)
Definition geometry.hpp:656
@ row
default; fill rows left-to-right then wrap
Definition geometry.hpp:654
GridTrack auto_rows
Definition geometry.hpp:650
static std::vector< NamedArea > parse_template_areas(const std::string &css)
Parse the CSS named-area grid string (e.g.
float row_gap
grid-row-gap
Definition geometry.hpp:662
Grid track size: fixed px, fractional (fr), or auto.
Definition geometry.hpp:624
static GridTrack auto_size()
Definition geometry.hpp:631
Type type
Definition geometry.hpp:626
static GridTrack fixed_px(float px)
Definition geometry.hpp:629
Type
Definition geometry.hpp:625
@ fr
Definition geometry.hpp:625
@ fixed
Definition geometry.hpp:625
@ auto_
Definition geometry.hpp:625
float value
px for fixed, fraction for fr, ignored for auto
Definition geometry.hpp:627
static GridTrack fractional(float fr)
Definition geometry.hpp:630
Axis-aligned rectangle in DISCRETE (integer) coordinates.
Definition geometry.hpp:213
constexpr IntRect with_size(int w, int h) const
Definition geometry.hpp:250
constexpr bool operator!=(const IntRect &r) const
Definition geometry.hpp:326
constexpr IntRect with_y(int v) const
Definition geometry.hpp:247
int height
Definition geometry.hpp:214
IntRect remove_from_top(int amount)
Definition geometry.hpp:264
int y
Definition geometry.hpp:214
IntRect remove_from_bottom(int amount)
Definition geometry.hpp:272
IntRect expanded(int dx, int dy) const
Definition geometry.hpp:240
int x
Definition geometry.hpp:214
constexpr IntRect translated(int dx, int dy) const
Definition geometry.hpp:242
constexpr bool contains(int px, int py) const
Definition geometry.hpp:226
constexpr int center_y() const
Definition geometry.hpp:222
constexpr bool intersects(const IntRect &o) const
Definition geometry.hpp:293
int width
Definition geometry.hpp:214
IntRect reduced(int d) const
Definition geometry.hpp:233
constexpr IntRect with_height(int v) const
Definition geometry.hpp:249
IntRect expanded(int d) const
Definition geometry.hpp:239
constexpr Rect to_float() const
Widening conversion — always exact.
Definition geometry.hpp:318
IntRect remove_from_right(int amount)
Definition geometry.hpp:286
constexpr int bottom() const
Definition geometry.hpp:217
IntRect intersection(const IntRect &o) const
Definition geometry.hpp:298
constexpr int center_x() const
Integer center.
Definition geometry.hpp:221
constexpr int right() const
Definition geometry.hpp:216
constexpr IntRect with_size_keeping_center(int w, int h) const
Resize about the center, in integer arithmetic.
Definition geometry.hpp:258
IntRect reduced(int dx, int dy) const
Definition geometry.hpp:236
constexpr bool is_empty() const
Definition geometry.hpp:224
constexpr bool operator==(const IntRect &r) const
Definition geometry.hpp:323
constexpr IntRect with_width(int v) const
Definition geometry.hpp:248
constexpr IntRect with_x(int v) const
Definition geometry.hpp:246
IntRect remove_from_left(int amount)
Definition geometry.hpp:278
constexpr bool contains(const IntRect &r) const
Definition geometry.hpp:229
constexpr IntRect with_position(int nx, int ny) const
Definition geometry.hpp:251
IntRect union_with(const IntRect &o) const
Definition geometry.hpp:307
Definition geometry.hpp:20
Point operator+(const Point &p) const
Definition geometry.hpp:23
float x
Definition geometry.hpp:21
bool operator==(const Point &p) const
Definition geometry.hpp:25
Point operator-(const Point &p) const
Definition geometry.hpp:24
float y
Definition geometry.hpp:21
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52
constexpr Rect with_height(float v) const
Definition geometry.hpp:112
Point origin() const
Definition geometry.hpp:57
Rect expanded(float d) const
Grow by d on every side.
Definition geometry.hpp:102
constexpr bool is_empty() const
Definition geometry.hpp:83
IntRect to_nearest_int() const
Round each edge to the nearest integer.
Definition geometry.hpp:329
Rect reduced(float dx, float dy) const
Definition geometry.hpp:100
constexpr Rect with_position(float nx, float ny) const
Definition geometry.hpp:114
Rect inset(float h, float v) const
Definition geometry.hpp:91
Size size() const
Definition geometry.hpp:58
float x
Definition geometry.hpp:53
constexpr Rect with_size(float w, float h) const
Definition geometry.hpp:113
Rect remove_from_left(float amount)
Definition geometry.hpp:150
constexpr bool intersects(const Rect &o) const
Definition geometry.hpp:166
Rect remove_from_right(float amount)
Definition geometry.hpp:158
constexpr Rect with_size_keeping_center(float w, float h) const
Resize about the center — the center stays put and the edges move.
Definition geometry.hpp:119
constexpr bool encloses(const Rect &r) const
Whole-rect containment: does this rect fully enclose r?
Definition geometry.hpp:79
constexpr float right() const
Definition geometry.hpp:55
bool operator==(const Rect &r) const
Definition geometry.hpp:203
Rect remove_from_top(float amount)
Definition geometry.hpp:136
constexpr Rect with_y(float v) const
Definition geometry.hpp:110
bool contains(Point p) const
Definition geometry.hpp:65
constexpr Rect with_width(float v) const
Definition geometry.hpp:111
constexpr float center_y() const
Definition geometry.hpp:63
Rect reduced(float d) const
Shrink by d on every side (the common "padding" idiom).
Definition geometry.hpp:99
Point center() const
Definition geometry.hpp:59
float height
Definition geometry.hpp:53
constexpr Rect translated(float dx, float dy) const
Definition geometry.hpp:105
IntRect to_enclosing_int() const
Smallest integer rect that fully CONTAINS this one.
Definition geometry.hpp:339
constexpr bool contains(float px, float py) const
Definition geometry.hpp:68
float width
Definition geometry.hpp:53
constexpr Rect with_x(float v) const
Definition geometry.hpp:109
bool operator!=(const Rect &r) const
Definition geometry.hpp:206
Rect union_with(const Rect &o) const
Smallest rect enclosing both.
Definition geometry.hpp:184
Rect expanded(float dx, float dy) const
Definition geometry.hpp:103
constexpr float center_x() const
True center in continuous coordinates — exact halves, no truncation.
Definition geometry.hpp:62
float y
Definition geometry.hpp:53
constexpr float bottom() const
Definition geometry.hpp:56
Rect remove_from_bottom(float amount)
Definition geometry.hpp:144
Rect intersection(const Rect &o) const
The overlap, or an empty rect when they do not overlap.
Definition geometry.hpp:172
Rect inset(float amount) const
Definition geometry.hpp:85
Definition geometry.hpp:28
bool operator==(const Size &s) const
Definition geometry.hpp:31
float height
Definition geometry.hpp:29
float width
Definition geometry.hpp:29
bool is_empty() const
Definition geometry.hpp:32