FTXUI  5.0.0
C++ functional terminal UI.
table.hpp
Go to the documentation of this file.
1 // Copyright 2021 Arthur Sonzogni. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be found in
3 // the LICENSE file.
4 #ifndef FTXUI_DOM_TABLE
5 #define FTXUI_DOM_TABLE
6 
7 #include <string> // for string
8 #include <vector> // for vector
9 
10 #include "ftxui/dom/elements.hpp" // for Element, BorderStyle, LIGHT, Decorator
11 
12 namespace ftxui {
13 
14 // Usage:
15 //
16 // Initialization:
17 // ---------------
18 //
19 // auto table = Table({
20 // {"X", "Y"},
21 // {"-1", "1"},
22 // {"+0", "0"},
23 // {"+1", "1"},
24 // });
25 //
26 // table.SelectAll().Border(LIGHT);
27 //
28 // table.SelectRow(1).Border(DOUBLE);
29 // table.SelectRow(1).SeparatorInternal(Light);
30 //
31 // std::move(table).Element();
32 
33 class Table;
34 class TableSelection;
35 
36 class Table {
37  public:
38  Table();
39  explicit Table(std::vector<std::vector<std::string>>);
40  explicit Table(std::vector<std::vector<Element>>);
42  TableSelection SelectCell(int column, int row);
43  TableSelection SelectRow(int row_index);
44  TableSelection SelectRows(int row_min, int row_max);
45  TableSelection SelectColumn(int column_index);
46  TableSelection SelectColumns(int column_min, int column_max);
47  TableSelection SelectRectangle(int column_min,
48  int column_max,
49  int row_min,
50  int row_max);
51  Element Render();
52 
53  private:
54  void Initialize(std::vector<std::vector<Element>>);
55  friend TableSelection;
56  std::vector<std::vector<Element>> elements_;
57  int input_dim_x_ = 0;
58  int input_dim_y_ = 0;
59  int dim_x_ = 0;
60  int dim_y_ = 0;
61 };
62 
64  public:
65  void Decorate(Decorator);
66  void DecorateAlternateRow(Decorator, int modulo = 2, int shift = 0);
67  void DecorateAlternateColumn(Decorator, int modulo = 2, int shift = 0);
68 
70  void DecorateCellsAlternateColumn(Decorator, int modulo = 2, int shift = 0);
71  void DecorateCellsAlternateRow(Decorator, int modulo = 2, int shift = 0);
72 
78 
82 
83  private:
84  friend Table;
85  Table* table_;
86  int x_min_;
87  int x_max_;
88  int y_min_;
89  int y_max_;
90 };
91 
92 } // namespace ftxui
93 
94 #endif /* end of include guard: FTXUI_DOM_TABLE */
void DecorateAlternateColumn(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the lines modulo modulo with a shift of shif...
Definition: table.cpp:269
void SeparatorVertical(BorderStyle border=LIGHT)
Draw some vertical separator lines in the selection.
Definition: table.cpp:380
void DecorateCells(Decorator)
Apply the decorator to the selection.
Definition: table.cpp:251
void BorderLeft(BorderStyle border=LIGHT)
Draw some separator lines to the left side of the selection.
Definition: table.cpp:408
void DecorateCellsAlternateColumn(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the corners modulo modulo with a shift of sh...
Definition: table.cpp:309
void Decorate(Decorator)
Apply the decorator to the selection. This decorate both the cells, the lines and the corners.
Definition: table.cpp:237
void DecorateAlternateRow(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the lines modulo modulo with a shift of shif...
Definition: table.cpp:289
void BorderTop(BorderStyle border=LIGHT)
Draw some separator lines to the top side of the selection.
Definition: table.cpp:428
void Separator(BorderStyle border=LIGHT)
Draw some separator lines in the selection.
Definition: table.cpp:364
void BorderBottom(BorderStyle border=LIGHT)
Draw some separator lines to the bottom side of the selection.
Definition: table.cpp:438
void DecorateCellsAlternateRow(Decorator, int modulo=2, int shift=0)
Apply the decorator to the selection. This decorate only the corners modulo modulo with a shift of sh...
Definition: table.cpp:329
void BorderRight(BorderStyle border=LIGHT)
Draw some separator lines to the right side of the selection.
Definition: table.cpp:418
void Border(BorderStyle border=LIGHT)
Apply a border around the selection.
Definition: table.cpp:345
void SeparatorHorizontal(BorderStyle border=LIGHT)
Draw some horizontal separator lines in the selection.
Definition: table.cpp:394
Element Render()
Render the table.
Definition: table.cpp:206
Table()
Create an empty table.
Definition: table.cpp:46
TableSelection SelectCell(int column, int row)
Select a cell of the table.
Definition: table.cpp:160
TableSelection SelectColumn(int column_index)
Select a column of the table.
Definition: table.cpp:142
TableSelection SelectRow(int row_index)
Select a row of the table.
Definition: table.cpp:125
TableSelection SelectColumns(int column_min, int column_max)
Select a range of columns of the table.
Definition: table.cpp:151
TableSelection SelectRows(int row_min, int row_max)
Select a range of rows of the table.
Definition: table.cpp:134
TableSelection SelectAll()
Select all the table.
Definition: table.cpp:193
TableSelection SelectRectangle(int column_min, int column_max, int row_min, int row_max)
Select a rectangle of the table.
Definition: table.cpp:171
std::function< Element(Element)> Decorator
Definition: elements.hpp:24
std::shared_ptr< Node > Element
Definition: elements.hpp:22
Element border(Element)
Draw a border around the element.
Definition: border.cpp:227
BorderStyle
Definition: elements.hpp:27
@ LIGHT
Definition: elements.hpp:28