FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/dom/canvas.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスに準拠しています。
3#include <stdio.h> // for getchar
4#include <cmath> // for cos
5#include <ftxui/dom/elements.hpp> // for Fit, canvas, operator|, border, Element
6#include <ftxui/screen/screen.hpp> // for Pixel, Screen
7#include <vector> // for vector, allocator
8
9#include "ftxui/dom/canvas.hpp" // for Canvas
10#include "ftxui/dom/node.hpp" // for Render
11#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
12
13int main() {
14 using namespace ftxui;
15
16 auto c = Canvas(100, 100);
17
18 c.DrawText(0, 0, "This is a canvas", [](Pixel& p) {
19 p.foreground_color = Color::Red;
20 p.underlined = true;
21 });
22
23 // 三角形:
24 c.DrawPointLine(10, 10, 80, 10, Color::Red);
25 c.DrawPointLine(80, 10, 80, 40, Color::Blue);
26 c.DrawPointLine(80, 40, 10, 10, Color::Green);
27
28 // 円(塗りつぶしなしと塗りつぶしあり):
29 c.DrawPointCircle(30, 50, 20);
30 c.DrawPointCircleFilled(40, 40, 10);
31
32 // 関数をプロット:
33 std::vector<int> ys(100);
34 for (int x = 0; x < 100; x++) {
35 ys[x] = int(80 + 20 * cos(x * 0.2));
36 }
37 for (int x = 0; x < 99; x++) {
38 c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
39 }
40
41 auto document = canvas(&c) | border;
42
43 auto screen = Screen::Create(Dimension::Fit(document));
44 Render(screen, document);
45 screen.Print();
46 getchar();
47
48 return 0;
49}
Element border(Element child)
要素の周囲にボーダーを描画します。
Canvasは、描画操作に関連付けられた描画可能なバッファです。
Definition canvas.hpp:36
Color foreground_color
Definition pixel.hpp:48
bool underlined
Definition pixel.hpp:32
Unicode文字とそれに関連付けられたスタイル。
Definition pixel.hpp:14
FTXUI ftxui:: 名前空間
Definition animation.hpp:9