16class GridBox :
public Node {
18 GridBox(std::vector<Elements> lines) :
Node(), lines_(std::move(lines)) {
19 y_size = lines_.size();
20 for (
const auto& line : lines_)
21 x_size = std::max(x_size, (
int)line.size());
22 for (
auto& line : lines_) {
23 while (line.size() < (
size_t)y_size) {
29 void ComputeRequirement()
override {
37 for (
auto& line : lines_) {
38 for (
auto& cell : line) {
39 cell->ComputeRequirement();
52 for (
int x = 0; x < x_size; ++x) {
54 for (
int y = 0; y < y_size; ++y)
55 min_x = std::max(min_x, lines_[y][x]->
requirement().min_x);
60 for (
int y = 0; y < y_size; ++y) {
62 for (
int x = 0; x < x_size; ++x)
63 min_y = std::max(min_y, lines_[y][x]->
requirement().min_y);
68 void SetBox(Box box)
override {
71 box_helper::Element init;
73 init.flex_grow = 1024;
74 init.flex_shrink = 1024;
75 std::vector<box_helper::Element> elements_x(x_size, init);
76 std::vector<box_helper::Element> elements_y(y_size, init);
78 for (
int y = 0; y < y_size; ++y) {
79 for (
int x = 0; x < x_size; ++x) {
80 const auto& cell = lines_[y][x];
82 auto& e_x = elements_x[x];
83 auto& e_y = elements_y[y];
93 int target_size_x = box.x_max - box.x_min + 1;
94 int target_size_y = box.y_max - box.y_min + 1;
100 for (
int iy = 0; iy < y_size; ++iy) {
102 y += elements_y[iy].size;
107 for (
int ix = 0; ix < x_size; ++ix) {
109 x += elements_x[ix].size;
111 lines_[iy][ix]->SetBox(box_x);
116 void Render(Screen& screen)
override {
117 for (
auto& line : lines_) {
118 for (
auto& cell : line)
119 cell->Render(screen);
125 std::vector<Elements> lines_;
155 return std::make_shared<GridBox>(std::move(lines));
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Requirement requirement()
void Compute(std::vector< Element > *elements, int target_size)
std::shared_ptr< Node > Element
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Element filler()
An element that will take expand proportionnally to the space left in a container.