2#include "TinyMaterialDesign/Core/Bounds.h"
7
8
9
10
11
12
13
14
15
16
17
18
19
20
23 GridLayout(
Bounds container, int32_t cellWidth, int32_t cellHeight, int32_t spacing = 8)
24 : container_(container), cellWidth_(cellWidth), cellHeight_(cellHeight), spacing_(spacing) {
25 const int32_t step = cellWidth_ + spacing_;
26 columns_ = step > 0 ? (container_
.w + spacing_) / step : 1;
27 if (columns_ < 1) columns_ = 1;
32 const int32_t col = index % columns_;
33 const int32_t row = index / columns_;
34 const int32_t x = container_
.x + col * (cellWidth_ + spacing_);
35 const int32_t y = container_
.y + row * (cellHeight_ + spacing_);
43 if (count <= 0)
return 0;
44 const int32_t rows = (count + columns_ - 1) / columns_;
45 return rows * cellHeight_ + (rows - 1) * spacing_;
Computes wrapped grid cell positions for a row of equal-size cards.
Definition: GridLayout.h:21
int columns() const
Definition: GridLayout.h:39
GridLayout(Bounds container, int32_t cellWidth, int32_t cellHeight, int32_t spacing=8)
Definition: GridLayout.h:23
int32_t totalHeight(int count) const
Total height needed to lay out count items.
Definition: GridLayout.h:42
Bounds cellRect(int index) const
Bounds for the index-th cell (0-based, row-major).
Definition: GridLayout.h:31
Definition: AnchorLayout.h:4
Axis-aligned pixel rectangle used for widget bounds and hit-testing.
Definition: Bounds.h:21
int32_t w
Definition: Bounds.h:24
Bounds(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: Bounds.h:28
int32_t y
Definition: Bounds.h:23
int32_t x
Definition: Bounds.h:22