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#include "ftxui/util/export.hpp"
12
13namespace ftxui {
14
15class Table;
16class TableSelection;
17
18/// @brief Table is a utility to draw tables.
19///
20/// **example**
21/// ```cpp
22/// auto table = Table({
23/// {"X", "Y"},
24/// {"-1", "1"},
25/// {"+0", "0"},
26/// {"+1", "1"},
27/// });
28///
29/// table.SelectAll().Border(LIGHT);
30/// table.SelectRow(1).Border(DOUBLE);
31/// table.SelectRow(1).SeparatorInternal(LIGHT);
32///
33/// std::move(table).Render();
34/// ```
35///
36/// @ingroup dom
37class FTXUI_EXPORT(DOM) Table {
38 public:
39 Table();
40 explicit Table(const std::vector<std::vector<std::string>>&);
41 explicit Table(std::vector<std::vector<Element>>);
42 Table(std::initializer_list<std::vector<std::string>> init);
43 TableSelection SelectAll();
44 TableSelection SelectCell(int column, int row);
45 TableSelection SelectRow(int row_index);
46 TableSelection SelectRows(int row_min, int row_max);
47 TableSelection SelectColumn(int column_index);
48 TableSelection SelectColumns(int column_min, int column_max);
49 TableSelection SelectRectangle(int column_min,
50 int column_max,
51 int row_min,
52 int row_max);
53 Element Render();
54
55 private:
56 void Initialize(std::vector<std::vector<Element>>);
57 friend TableSelection;
58 std::vector<std::vector<Element>> elements_;
59 int input_dim_x_ = 0;
60 int input_dim_y_ = 0;
61 int dim_x_ = 0;
62 int dim_y_ = 0;
63};
64
65class FTXUI_EXPORT(DOM) TableSelection {
66 public:
67 // Decorate the whole selection with a decorator.
68 void Decorate(const Decorator&);
69 void DecorateAlternateRow(const Decorator&, int modulo = 2, int shift = 0);
70 void DecorateAlternateColumn(const Decorator&, int modulo = 2, int shift = 0);
71
72 // Decorate only the cells of the selection with a decorator.
73 void DecorateCells(const Decorator&);
74 void DecorateCellsAlternateColumn(const Decorator&,
75 int modulo = 2,
76 int shift = 0);
77 void DecorateCellsAlternateRow(const Decorator&,
78 int modulo = 2,
79 int shift = 0);
80
81 // Decorate only the border of the selection with a decorator.
82 void DecorateBorder(const Decorator&);
83 void DecorateBorderLeft(const Decorator&);
84 void DecorateBorderRight(const Decorator&);
85 void DecorateBorderTop(const Decorator&);
86 void DecorateBorderBottom(const Decorator&);
87
88 // Decorate only the separator of the selection with a decorator.
89 void DecorateSeparator(const Decorator&);
90 void DecorateSeparatorVertical(const Decorator&);
91 void DecorateSeparatorHorizontal(const Decorator&);
92
93 // Decorate the border of the selection with a border style and a decorator.
94 void Border(BorderStyle border = LIGHT);
95 void Border(BorderStyle, const Decorator&);
96 void BorderLeft(BorderStyle border = LIGHT);
97 void BorderLeft(BorderStyle, const Decorator&);
98 void BorderRight(BorderStyle border = LIGHT);
99 void BorderRight(BorderStyle, const Decorator&);
100 void BorderTop(BorderStyle border = LIGHT);
101 void BorderTop(BorderStyle, const Decorator&);
102 void BorderBottom(BorderStyle border = LIGHT);
103 void BorderBottom(BorderStyle, const Decorator&);
104
105 // Decorate the separator of the selection with a border style and a
106 // decorator.
107 void Separator(BorderStyle border = LIGHT);
108 void Separator(BorderStyle, const Decorator&);
109 void SeparatorVertical(BorderStyle border = LIGHT);
110 void SeparatorVertical(BorderStyle, const Decorator&);
111 void SeparatorHorizontal(BorderStyle border = LIGHT);
112 void SeparatorHorizontal(BorderStyle, const Decorator&);
113
114 private:
115 friend Table;
116 Table* table_;
117 int x_min_;
118 int x_max_;
119 int y_min_;
120 int y_max_;
121};
122
123} // namespace ftxui
124
125#endif /* end of include guard: FTXUI_DOM_TABLE */
The FTXUI ftxui:: namespace.
Definition animation.hpp:11
std::shared_ptr< Node > Element
Definition elements.hpp:24