FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
examples/dom/canvas.cpp
// 版权所有 2020 Arthur Sonzogni. 保留所有权利。
// 本源代码的使用受 MIT 许可证的约束,该许可证可在
// LICENSE 文件中找到。
#include <stdio.h> // for getchar
#include <cmath> // for cos
#include <ftxui/dom/elements.hpp> // for Fit, canvas, operator|, border, Element
#include <ftxui/screen/screen.hpp> // for Pixel, Screen
#include <vector> // for vector, allocator
#include "ftxui/dom/canvas.hpp" // for Canvas
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
int main() {
using namespace ftxui;
auto c = Canvas(100, 100);
c.DrawText(0, 0, "This is a canvas", [](Pixel& p) {
p.foreground_color = Color::Red;
p.underlined = true;
});
// 三角形:
c.DrawPointLine(10, 10, 80, 10, Color::Red);
c.DrawPointLine(80, 10, 80, 40, Color::Blue);
c.DrawPointLine(80, 40, 10, 10, Color::Green);
// 圆形,未填充和已填充:
c.DrawPointCircle(30, 50, 20);
c.DrawPointCircleFilled(40, 40, 10);
// 绘制函数:
std::vector<int> ys(100);
for (int x = 0; x < 100; x++) {
ys[x] = int(80 + 20 * cos(x * 0.2));
}
for (int x = 0; x < 99; x++) {
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
}
auto document = canvas(&c) | border;
auto screen = Screen::Create(Dimension::Fit(document));
Render(screen, document);
screen.Print();
getchar();
return 0;
}
Element border(Element child)
在元素周围绘制边框。
Canvas 是一个与绘图操作相关的可绘制缓冲区。
Color foreground_color
一个 Unicode 字符及其相关样式。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase