16class GridBox :
public Node {
18 explicit GridBox(std::vector<Elements> lines) : lines_(std::move(lines)) {
19 y_size = (int)lines_.size();
20 for (
const auto& line : lines_) {
21 x_size = std::max(x_size, (
int)line.size());
23 for (
auto& line : lines_) {
24 while (line.size() < (
size_t)x_size) {
30 void ComputeRequirement()
override {
38 for (
auto& line : lines_) {
39 for (
auto& cell : line) {
40 cell->ComputeRequirement();
54 for (
int x = 0; x < x_size; ++x) {
56 for (
int y = 0; y < y_size; ++y) {
57 min_x = std::max(min_x, lines_[y][x]->
requirement().min_x);
63 for (
int y = 0; y < y_size; ++y) {
65 for (
int x = 0; x < x_size; ++x) {
66 min_y = std::max(min_y, lines_[y][x]->
requirement().min_y);
72 void SetBox(Box box)
override {
75 box_helper::Element init;
77 init.flex_grow = 1024;
78 init.flex_shrink = 1024;
79 std::vector<box_helper::Element> elements_x(x_size, init);
80 std::vector<box_helper::Element> elements_y(y_size, init);
82 for (
int y = 0; y < y_size; ++y) {
83 for (
int x = 0; x < x_size; ++x) {
84 const auto& cell = lines_[y][x];
86 auto& e_x = elements_x[x];
87 auto& e_y = elements_y[y];
97 int target_size_x = box.x_max - box.x_min + 1;
98 int target_size_y = box.y_max - box.y_min + 1;
104 for (
int iy = 0; iy < y_size; ++iy) {
106 y += elements_y[iy].size;
111 for (
int ix = 0; ix < x_size; ++ix) {
113 x += elements_x[ix].size;
115 lines_[iy][ix]->SetBox(box_x);
120 void Render(Screen& screen)
override {
121 for (
auto& line : lines_) {
122 for (
auto& cell : line) {
123 cell->Render(screen);
130 std::vector<Elements> lines_;
160 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.