22int Integrate(std::vector<int>& elements) {
24 for (
auto& i : elements) {
25 const int old_accu = accu;
33class GridBox :
public Node {
35 explicit GridBox(std::vector<Elements> lines) : lines_(std::move(lines)) {
36 y_size = (int)lines_.size();
37 for (
const auto& line : lines_) {
38 x_size = std::max(x_size, (
int)line.size());
40 for (
auto& line : lines_) {
41 while (line.size() < (
size_t)x_size) {
47 void ComputeRequirement()
override {
55 for (
auto& line : lines_) {
56 for (
auto& cell : line) {
57 cell->ComputeRequirement();
62 std::vector<int> size_x(x_size, 0);
63 std::vector<int> size_y(y_size, 0);
64 for (
int x = 0; x < x_size; ++x) {
65 for (
int y = 0; y < y_size; ++y) {
66 size_x[x] = std::max(size_x[x], lines_[y][x]->
requirement().min_x);
67 size_y[y] = std::max(size_y[y], lines_[y][x]->
requirement().min_y);
76 for (
int x = 0; x < x_size; ++x) {
77 for (
int y = 0; y < y_size; ++y) {
91 void SetBox(Box box)
override {
94 box_helper::Element init;
96 init.flex_grow = 1024;
97 init.flex_shrink = 1024;
98 std::vector<box_helper::Element> elements_x(x_size, init);
99 std::vector<box_helper::Element> elements_y(y_size, init);
101 for (
int y = 0; y < y_size; ++y) {
102 for (
int x = 0; x < x_size; ++x) {
103 const auto& cell = lines_[y][x];
105 auto& e_x = elements_x[x];
106 auto& e_y = elements_y[y];
116 const int target_size_x = box.x_max - box.x_min + 1;
117 const int target_size_y = box.y_max - box.y_min + 1;
123 for (
int iy = 0; iy < y_size; ++iy) {
125 y += elements_y[iy].size;
130 for (
int ix = 0; ix < x_size; ++ix) {
132 x += elements_x[ix].size;
134 lines_[iy][ix]->SetBox(box_x);
139 void Render(Screen& screen)
override {
140 for (
auto& line : lines_) {
141 for (
auto& cell : line) {
142 cell->Render(screen);
149 std::vector<Elements> lines_;
179 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.