12bool IsCell(
int x,
int y) {
13 return x % 2 == 1 && y % 2 == 1;
16static std::string charset[6][6] = {
17 {
"┌",
"┐",
"└",
"┘",
"─",
"│"},
18 {
"┏",
"┓",
"┗",
"┛",
"━",
"┃"},
19 {
"╔",
"╗",
"╚",
"╝",
"═",
"║"},
20 {
"╭",
"╮",
"╰",
"╯",
"─",
"│"},
21 {
" ",
" ",
" ",
" ",
" ",
" "},
24int Wrap(
int input,
int modulo) {
31void Order(
int& a,
int& b) {
39 input_dim_y_ = input.size();
41 for (
auto& row : input)
42 input_dim_x_ = std::max(input_dim_x_, (
int)row.size());
44 dim_y_ = 2 * input_dim_y_ + 1;
45 dim_x_ = 2 * input_dim_x_ + 1;
48 elements_.resize(dim_y_);
49 for (
int y = 0; y < dim_y_; ++y)
50 elements_[y].resize(dim_x_);
55 for (
auto& row : input) {
57 for (
auto& cell : row) {
58 elements_[y][x] =
text(cell);
66 for (
int y = 0; y < dim_y_; ++y) {
67 for (
int x = 0; x < dim_x_; ++x) {
68 auto& element = elements_[y][x];
105 column_min = Wrap(column_min, input_dim_x_);
106 column_max = Wrap(column_max, input_dim_x_);
107 Order(column_min, column_max);
108 row_min = Wrap(row_min, input_dim_y_);
109 row_max = Wrap(row_max, input_dim_y_);
110 Order(row_min, row_max);
113 output.table_ =
this;
114 output.x_min_ = 2 * column_min;
115 output.x_max_ = 2 * column_max + 2;
116 output.y_min_ = 2 * row_min;
117 output.y_max_ = 2 * row_max + 2;
123 output.table_ =
this;
125 output.x_max_ = dim_x_ - 1;
127 output.y_max_ = dim_y_ - 1;
132 for (
int y = 0; y < dim_y_; ++y) {
133 for (
int x = 0; x < dim_x_; ++x) {
134 auto& it = elements_[y][x];
137 if ((x + y) % 2 == 1) {
138 it = std::move(it) |
flex;
143 if ((x % 2) == 1 && (y % 2) == 1) {
152 return gridbox(std::move(elements_));
156 for (
int y = y_min_; y <= y_max_; ++y) {
157 for (
int x = x_min_; x <= x_max_; ++x) {
158 Element& e = table_->elements_[y][x];
159 e = std::move(e) | decorator;
165 for (
int y = y_min_; y <= y_max_; ++y) {
166 for (
int x = x_min_; x <= x_max_; ++x) {
167 if (y % 2 && x % 2) {
168 Element& e = table_->elements_[y][x];
169 e = std::move(e) | decorator;
178 for (
int y = y_min_; y <= y_max_; ++y) {
179 for (
int x = x_min_; x <= x_max_; ++x) {
180 if (y % 2 && (x / 2) % modulo == shift) {
181 Element& e = table_->elements_[y][x];
182 e = std::move(e) | decorator;
191 for (
int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
192 for (
int x = x_min_; x <= x_max_; ++x) {
193 if (y % 2 && (y / 2) % modulo == shift) {
194 Element& e = table_->elements_[y][x];
195 e = std::move(e) | decorator;
204 for (
int y = y_min_; y <= y_max_; ++y) {
205 for (
int x = x_min_; x <= x_max_; ++x) {
206 if (y % 2 && x % 2 && ((x / 2) % modulo == shift)) {
207 Element& e = table_->elements_[y][x];
208 e = std::move(e) | decorator;
217 for (
int y = y_min_; y <= y_max_; ++y) {
218 for (
int x = x_min_; x <= x_max_; ++x) {
219 if (y % 2 && x % 2 && ((y / 2) % modulo == shift)) {
220 Element& e = table_->elements_[y][x];
221 e = std::move(e) | decorator;
233 table_->elements_[y_min_][x_min_] =
text(charset[style][0]);
234 table_->elements_[y_min_][x_max_] =
text(charset[style][1]);
235 table_->elements_[y_max_][x_min_] =
text(charset[style][2]);
236 table_->elements_[y_max_][x_max_] =
text(charset[style][3]);
240 for (
int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
241 for (
int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
242 if (y % 2 == 0 || x % 2 == 0) {
243 Element& e = table_->elements_[y][x];
252 for (
int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
253 for (
int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
255 table_->elements_[y][x] =
text(charset[style][5]);
262 for (
int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
263 for (
int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
265 table_->elements_[y][x] =
text(charset[style][4]);
272 for (
int y = y_min_; y <= y_max_; y++)
277 for (
int y = y_min_; y <= y_max_; y++)
282 for (
int x = x_min_; x <= x_max_; x++)
287 for (
int x = x_min_; x <= x_max_; x++)
void DecorateAlternateColumn(Decorator, int modulo=2, int shift=0)
void SeparatorVertical(BorderStyle border=LIGHT)
void DecorateCells(Decorator)
void BorderLeft(BorderStyle border=LIGHT)
void DecorateCellsAlternateColumn(Decorator, int modulo=2, int shift=0)
void DecorateAlternateRow(Decorator, int modulo=2, int shift=0)
void BorderTop(BorderStyle border=LIGHT)
void Separator(BorderStyle border=LIGHT)
void BorderBottom(BorderStyle border=LIGHT)
void DecorateCellsAlternateRow(Decorator, int modulo=2, int shift=0)
void BorderRight(BorderStyle border=LIGHT)
void Border(BorderStyle border=LIGHT)
void SeparatorHorizontal(BorderStyle border=LIGHT)
Table(std::vector< std::vector< std::string > >)
TableSelection SelectCell(int column, int row)
TableSelection SelectColumn(int column_index)
TableSelection SelectRow(int row_index)
TableSelection SelectColumns(int column_min, int column_max)
TableSelection SelectRows(int row_min, int row_max)
TableSelection SelectAll()
TableSelection SelectRectangle(int column_min, int column_max, int row_min, int row_max)
std::function< Element(Element)> Decorator
Element flex(Element)
Make a child element to expand proportionnally to the space left in a container.
std::shared_ptr< Node > Element
Element flex_shrink(Element)
Minimize if needed.
Element text(std::wstring text)
Display a piece of unicode text.
Element separatorCharacter(std::string)
Draw a vertical or horizontal separation in between two other elements.
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Decorator size(Direction, Constraint, int value)
Apply a constraint on the size of an element.