FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
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
12namespace ftxui {
13
14class Table;
15class TableSelection;
16
17/// @brief Table is a utility to draw tables.
18///
19/// **example**
20/// ```cpp
21/// auto table = Table({
22/// {"X", "Y"},
23/// {"-1", "1"},
24/// {"+0", "0"},
25/// {"+1", "1"},
26/// });
27///
28/// table.SelectAll().Border(LIGHT);
29/// table.SelectRow(1).Border(DOUBLE);
30/// table.SelectRow(1).SeparatorInternal(LIGHT);
31///
32/// std::move(table).Render();
33/// ```
34///
35/// @ingroup dom
36class Table {
37 public:
38 Table();
39 explicit Table(const std::vector<std::vector<std::string>>&);
40 explicit Table(std::vector<std::vector<Element>>);
41 Table(std::initializer_list<std::vector<std::string>> init);
43 TableSelection SelectCell(int column, int row);
44 TableSelection SelectRow(int row_index);
45 TableSelection SelectRows(int row_min, int row_max);
46 TableSelection SelectColumn(int column_index);
47 TableSelection SelectColumns(int column_min, int column_max);
48 TableSelection SelectRectangle(int column_min,
49 int column_max,
50 int row_min,
51 int row_max);
53
54 private:
55 void Initialize(std::vector<std::vector<Element>>);
56 friend TableSelection;
57 std::vector<std::vector<Element>> elements_;
58 int input_dim_x_ = 0;
59 int input_dim_y_ = 0;
60 int dim_x_ = 0;
61 int dim_y_ = 0;
62};
63
65 public:
66 // Decorate the whole selection with a decorator.
67 void Decorate(const Decorator&);
68 void DecorateAlternateRow(const Decorator&, int modulo = 2, int shift = 0);
69 void DecorateAlternateColumn(const Decorator&, int modulo = 2, int shift = 0);
70
71 // Decorate only the cells of the selection with a decorator.
72 void DecorateCells(const Decorator&);
74 int modulo = 2,
75 int shift = 0);
77 int modulo = 2,
78 int shift = 0);
79
80 // Decorate only the border of the selection with a decorator.
81 void DecorateBorder(const Decorator&);
82 void DecorateBorderLeft(const Decorator&);
83 void DecorateBorderRight(const Decorator&);
84 void DecorateBorderTop(const Decorator&);
86
87 // Decorate only the separator of the selection with a decorator.
88 void DecorateSeparator(const Decorator&);
91
92 // Decorate the border of the selection with a border style and a decorator.
93 void Border(BorderStyle border = LIGHT);
94 void Border(BorderStyle, const Decorator&);
95 void BorderLeft(BorderStyle border = LIGHT);
96 void BorderLeft(BorderStyle, const Decorator&);
97 void BorderRight(BorderStyle border = LIGHT);
98 void BorderRight(BorderStyle, const Decorator&);
99 void BorderTop(BorderStyle border = LIGHT);
100 void BorderTop(BorderStyle, const Decorator&);
101 void BorderBottom(BorderStyle border = LIGHT);
102 void BorderBottom(BorderStyle, const Decorator&);
103
104 // Decorate the separator of the selection with a border style and a
105 // decorator.
106 void Separator(BorderStyle border = LIGHT);
107 void Separator(BorderStyle, const Decorator&);
108 void SeparatorVertical(BorderStyle border = LIGHT);
112
113 private:
114 friend Table;
115 Table* table_;
116 int x_min_;
117 int x_max_;
118 int y_min_;
119 int y_max_;
120};
121
122} // namespace ftxui
123
124#endif /* end of include guard: FTXUI_DOM_TABLE */
void DecorateBorderRight(const Decorator &)
Apply the decorator to the right border of the selection.
void DecorateBorder(const Decorator &)
Apply the decorator to the border of the selection.
void DecorateAlternateRow(const 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...
void DecorateSeparatorHorizontal(const Decorator &)
Apply the decorator to the horizontal separators of the selection.
void DecorateCellsAlternateRow(const 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...
void DecorateCellsAlternateColumn(const 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...
void SeparatorVertical(BorderStyle border=LIGHT)
Draw some vertical separator lines in the selection.
void Decorate(const Decorator &)
Apply the decorator to the selection. This decorate both the cells, the lines and the corners.
void DecorateBorderBottom(const Decorator &)
Apply the decorator to the bottom border of the selection.
void BorderLeft(BorderStyle border=LIGHT)
Draw some separator lines to the left side of the selection.
void DecorateCells(const Decorator &)
Apply the decorator to the selection.
void DecorateAlternateColumn(const 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...
void DecorateSeparatorVertical(const Decorator &)
Apply the decorator to the vertical separators of the selection.
void DecorateBorderLeft(const Decorator &)
Apply the decorator to the left border of the selection.
void BorderTop(BorderStyle border=LIGHT)
Draw some separator lines to the top side of the selection.
void Separator(BorderStyle border=LIGHT)
Draw some separator lines in the selection.
void BorderBottom(BorderStyle border=LIGHT)
Draw some separator lines to the bottom side of the selection.
void DecorateSeparator(const Decorator &)
Apply the decorator to the separators of the selection.
void DecorateBorderTop(const Decorator &)
Apply the decorator to the top border of the selection.
void BorderRight(BorderStyle border=LIGHT)
Draw some separator lines to the right side of the selection.
void Border(BorderStyle border=LIGHT)
Apply a border around the selection.
void SeparatorHorizontal(BorderStyle border=LIGHT)
Draw some horizontal separator lines in the selection.
Element Render()
Render the table.
Table()
Create an empty table.
TableSelection SelectCell(int column, int row)
Select a cell of the table.
TableSelection SelectColumn(int column_index)
Select a column of the table.
TableSelection SelectRow(int row_index)
Select a row of the table.
TableSelection SelectColumns(int column_min, int column_max)
Select a range of columns of the table.
TableSelection SelectRows(int row_min, int row_max)
Select a range of rows of the table.
TableSelection SelectAll()
Select all the table.
TableSelection SelectRectangle(int column_min, int column_max, int row_min, int row_max)
Select a rectangle of the table.
Table is a utility to draw tables.
Definition table.hpp:36
BorderStyle
BorderStyle is an enumeration that represents the different styles of borders that can be applied to ...
Definition elements.hpp:36
@ LIGHT
Definition elements.hpp:37
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
std::function< Element(Element)> Decorator
Definition elements.hpp:25
std::shared_ptr< Node > Element
Definition elements.hpp:23