FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
examples/dom/color_truecolor_RGB.cpp
// 版权所有 2020 Arthur Sonzogni。保留所有权利。
// 本源代码的使用受 MIT 许可证的约束,该许可证可在
// LICENSE 文件中找到。
#include <ftxui/dom/elements.hpp> // for hbox, text, bgcolor, operator|, vbox, Elements, window, Element, Fit
#include <ftxui/screen/screen.hpp> // for Full, Screen
#include <memory> // for allocator
#include <utility> // for move
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/color.hpp" // for Color, ftxui
int main() {
using namespace ftxui;
Elements red_line;
Elements green_line;
Elements blue_line;
Elements cyan_line;
Elements magenta_line;
Elements yellow_line;
for (int value = 0; value < 255; value += 3) {
int v = value * value / 255;
red_line.push_back(text(" ") | bgcolor(Color::RGB(v, 0, 0)));
green_line.push_back(text(" ") | bgcolor(Color::RGB(0, v, 0)));
blue_line.push_back(text(" ") | bgcolor(Color::RGB(0, 0, v)));
cyan_line.push_back(text(" ") | bgcolor(Color::RGB(0, v, v)));
magenta_line.push_back(text(" ") | bgcolor(Color::RGB(v, 0, v)));
yellow_line.push_back(text(" ") | bgcolor(Color::RGB(v, v, 0)));
}
auto document = vbox({
window(text("原色"),
vbox({
hbox({text("红色线条 :"), hbox(std::move(red_line))}),
hbox({text("绿色线条 :"), hbox(std::move(green_line))}),
hbox({text("蓝色线条 :"), hbox(std::move(blue_line))}),
})),
window(text("次生色"),
vbox({
hbox({text("青色线条 :"), hbox(std::move(cyan_line))}),
hbox({text("洋红色线条:"), hbox(std::move(magenta_line))}),
hbox({text("黄色线条 :"), hbox(std::move(yellow_line))}),
})),
});
auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document));
Render(screen, document);
screen.Print();
return 0;
}
Element window(Element title, Element content, BorderStyle border)
绘制带有标题和边框的窗口。
Element bgcolor(const LinearGradient &gradient, Element child)
使用线性渐变效果设置元素的背景色。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::vector< Element > Elements