FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/dom/canvas.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni。保留所有權利。
2// 本原始碼受 MIT 授權條款約束,詳情請參閱
3// LICENSE 檔案。
4 // 用於 getchar
5 // 用於 cos
6 // 用於 Fit, canvas, operator|, border, Element
7 // 用於 Pixel, Screen
8 // 用於 vector, allocator
9
10#include "ftxui/dom/canvas.hpp" // 用於 Canvas
11#include "ftxui/dom/node.hpp" // 用於 Render
12#include "ftxui/screen/color.hpp" // 用於 Color, Color::Red, Color::Blue, Color::Green, ftxui
13
14int main() {
15 using namespace ftxui;
16
17 auto c = Canvas(100, 100);
18
19 c.DrawText(0, 0, "This is a canvas", [](Pixel& p) {
20 p.foreground_color = Color::Red;
21 p.underlined = true;
22 });
23
24 // 三角形:
25 c.DrawPointLine(10, 10, 80, 10, Color::Red);
26 c.DrawPointLine(80, 10, 80, 40, Color::Blue);
27 c.DrawPointLine(80, 40, 10, 10, Color::Green);
28
29 // 圓形,未填充和已填充:
30 c.DrawPointCircle(30, 50, 20);
31 c.DrawPointCircleFilled(40, 40, 10);
32
33 // 繪製函數:
34 std::vector<int> ys(100);
35 for (int x = 0; x < 100; x++) {
36 ys[x] = int(80 + 20 * cos(x * 0.2));
37 }
38 for (int x = 0; x < 99; x++) {
39 c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
40 }
41
42 auto document = canvas(&c) | border;
43
44 auto screen = Screen::Create(Dimension::Fit(document));
45 Render(screen, document);
46 screen.Print();
47 getchar();
48
49 return 0;
50}
void Render(Screen &screen, const Element &element)
在 ftxui::Screen 上顯示元素。
Definition node.cpp:82
畫布是與繪圖操作相關聯的可繪製緩衝區。
Definition canvas.hpp:35
Color foreground_color
Definition pixel.hpp:48
bool underlined
Definition pixel.hpp:32
一個 Unicode 字元及其相關樣式。
Definition pixel.hpp:14
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
Element canvas(ConstRef< Canvas > canvas)
從 Canvas 或對 Canvas 的參考中產生一個元素。