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// 本原始碼的使用受 MIT 授權條款約束,該條款可在 LICENSE 檔案中找到。
3#ifndef FTXUI_DOM_TABLE
4#define FTXUI_DOM_TABLE
5
6#include <string> // for string
7#include <vector> // for vector
8
9#include "ftxui/dom/elements.hpp" // for Element, BorderStyle, LIGHT, Decorator
10
11namespace ftxui {
12
13class Table;
14class TableSelection;
15
16/// @brief Table 是一個用於繪製表格的工具。
17///
18/// **範例**
19/// ```cpp
20/// auto table = Table({
21/// {"X", "Y"},
22/// {"-1", "1"},
23/// {"+0", "0"},
24/// {"+1", "1"},
25/// });
26///
27/// table.SelectAll().Border(LIGHT);
28/// table.SelectRow(1).Border(DOUBLE);
29/// table.SelectRow(1).SeparatorInternal(LIGHT);
30///
31/// std::move(table).Render();
32/// ```
33///
34/// @ingroup dom
35class Table {
36 public:
37 Table();
38 explicit Table(std::vector<std::vector<std::string>>);
39 explicit Table(std::vector<std::vector<Element>>);
40 Table(std::initializer_list<std::vector<std::string>> init);
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);
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
73 void Border(BorderStyle border = LIGHT);
74 void BorderLeft(BorderStyle border = LIGHT);
75 void BorderRight(BorderStyle border = LIGHT);
76 void BorderTop(BorderStyle border = LIGHT);
77 void BorderBottom(BorderStyle border = LIGHT);
78
79 void Separator(BorderStyle border = LIGHT);
80 void SeparatorVertical(BorderStyle border = LIGHT);
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)
將 decorator 應用於選取範圍。 這只會裝飾模數為 modulo,偏移量為 shift 的線條。
void SeparatorVertical(BorderStyle border=LIGHT)
在選取範圍內繪製一些垂直分隔線。
void DecorateCells(Decorator)
將 decorator 應用於選取範圍。 這只會裝飾單元格。
void BorderLeft(BorderStyle border=LIGHT)
在選取範圍的左側繪製一些分隔線。
void DecorateCellsAlternateColumn(Decorator, int modulo=2, int shift=0)
將 decorator 應用於選取範圍。 這只會裝飾模數為 modulo,偏移量為 shift 的角落。
void Decorate(Decorator)
將 decorator 應用於選取範圍。 這會裝飾單元格、線條和角落。
void DecorateAlternateRow(Decorator, int modulo=2, int shift=0)
將 decorator 應用於選取範圍。 這只會裝飾模數為 modulo,偏移量為 shift 的線條。
void BorderTop(BorderStyle border=LIGHT)
在選取範圍的頂部繪製一些分隔線。
void Separator(BorderStyle border=LIGHT)
在選取範圍內繪製一些分隔線。
void BorderBottom(BorderStyle border=LIGHT)
在選取範圍的底部繪製一些分隔線。
void DecorateCellsAlternateRow(Decorator, int modulo=2, int shift=0)
將 decorator 應用於選取範圍。 這只會裝飾模數為 modulo,偏移量為 shift 的角落。
void BorderRight(BorderStyle border=LIGHT)
在選取範圍的右側繪製一些分隔線。
void Border(BorderStyle border=LIGHT)
在選取範圍周圍應用 border。
void SeparatorHorizontal(BorderStyle border=LIGHT)
在選取範圍內繪製一些水平分隔線。
Element Render()
渲染表格。
Table()
創建一個空表格。
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)
選取表格的一個矩形區域。
Table 是一個用於繪製表格的工具。
Definition table.hpp:35
BorderStyle
BorderStyle 是一個列舉,表示可以應用於終端機 UI 元素的不同邊框樣式。
Definition elements.hpp:32
@ LIGHT
Definition elements.hpp:33
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::function< Element(Element)> Decorator
Definition elements.hpp:24
std::shared_ptr< Node > Element
Definition elements.hpp:22