FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/dom/table.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. 版權所有。
2// 本原始碼的使用受 MIT 授權約束,該授權可在 LICENSE 檔案中找到。
3#include <ftxui/dom/elements.hpp> // for color, Fit, LIGHT, align_right, bold, DOUBLE
4#include <ftxui/dom/table.hpp> // for Table, TableSelection
5#include <ftxui/screen/screen.hpp> // for Screen
6#include <iostream> // for endl, cout, ostream
7#include <string> // for basic_string, allocator, string
8#include <vector> // for vector
9
10#include "ftxui/dom/node.hpp" // for Render
11#include "ftxui/screen/color.hpp" // for Color, Color::Blue, Color::Cyan, Color::White, ftxui
12
13int main() {
14 using namespace ftxui;
15
16 auto table = Table({
17 {"Version", "Marketing name", "Release date", "API level", "Runtime"},
18 {"2.3", "Gingerbread", "February 9 2011", "10", "Dalvik 1.4.0"},
19 {"4.0", "Ice Cream Sandwich", "October 19 2011", "15", "Dalvik"},
20 {"4.1", "Jelly Bean", "July 9 2012", "16", "Dalvik"},
21 {"4.2", "Jelly Bean", "November 13 2012", "17", "Dalvik"},
22 {"4.3", "Jelly Bean", "July 24 2013", "18", "Dalvik"},
23 {"4.4", "KitKat", "October 31 2013", "19", "Dalvik and ART"},
24 {"5.0", "Lollipop", "November 3 2014", "21", "ART"},
25 {"5.1", "Lollipop", "March 9 2015", "22", "ART"},
26 {"6.0", "Marshmallow", "October 5 2015", "23", "ART"},
27 {"7.0", "Nougat", "August 22 2016", "24", "ART"},
28 {"7.1", "Nougat", "October 4 2016", "25", "ART"},
29 {"8.0", "Oreo", "August 21 2017", "26", "ART"},
30 {"8.1", "Oreo", "December 5 2017", "27", "ART"},
31 {"9", "Pie", "August 6 2018", "28", "ART"},
32 {"10", "10", "September 3 2019", "29", "ART"},
33 {"11", "11", "September 8 2020", "30", "ART"},
34 });
35
36 table.SelectAll().Border(LIGHT);
37
38 // 在第一列周圍添加邊框。
39 table.SelectColumn(0).Border(LIGHT);
40
41 // 使第一行加粗並帶有雙邊框。
42 table.SelectRow(0).Decorate(bold);
43 table.SelectRow(0).SeparatorVertical(LIGHT);
44 table.SelectRow(0).Border(DOUBLE);
45
46 // 將“發布日期”列向右對齊。
47 table.SelectColumn(2).DecorateCells(align_right);
48
49 // 選擇從第二行到最後一行。
50 auto content = table.SelectRows(1, -1);
51 // 在 3 種顏色之間交替。
52 content.DecorateCellsAlternateRow(color(Color::Blue), 3, 0);
53 content.DecorateCellsAlternateRow(color(Color::Cyan), 3, 1);
54 content.DecorateCellsAlternateRow(color(Color::White), 3, 2);
55
56 auto document = table.Render();
57 auto screen =
58 Screen::Create(Dimension::Fit(document, /*extend_beyond_screen=*/true));
59 Render(screen, document);
60 screen.Print();
61 std::cout << std::endl;
62
63 return 0;
64}
void Border(BorderStyle border=LIGHT)
在選取範圍周圍應用 border。
TableSelection SelectAll()
選取整個表格。
Table 是一個用於繪製表格的工具。
Definition table.hpp:35
void Render(Screen &screen, const Element &element)
在 ftxui::Screen 上顯示元素。
Definition node.cpp:82
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10