19static std::string charset[] =
20#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
23 {
" ",
" ",
"█",
" ",
"█",
"█",
"█",
"█",
"█"};
25 {
" ",
"▗",
"▐",
"▖",
"▄",
"▟",
"▌",
"▙",
"█"};
28class Graph :
public Node {
31 : graph_function_(std::move(graph_function)) {}
33 void ComputeRequirement()
override {
34 requirement_.flex_grow_x = 1;
35 requirement_.flex_grow_y = 1;
36 requirement_.flex_shrink_x = 1;
37 requirement_.flex_shrink_y = 1;
38 requirement_.min_x = 3;
39 requirement_.min_y = 3;
42 void Render(Screen& screen)
override {
43 const int width = (box_.x_max - box_.x_min + 1) * 2;
44 const int height = (box_.y_max - box_.y_min + 1) * 2;
45 if (width <= 0 || height <= 0) {
48 auto data = graph_function_(width, height);
50 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
51 const int height_1 = 2 * box_.y_max - data[i++];
52 const int height_2 = 2 * box_.y_max - data[i++];
53 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
55 int i_1 = yy < height_1 ? 0 : yy == height_1 ? 3 : 6;
56 int i_2 = yy < height_2 ? 0 : yy == height_2 ? 1 : 2;
57 screen.at(x, y) = charset[i_1 + i_2];
71 return std::make_shared<Graph>(std::move(graph_function));
void Render(Screen &screen, const Element &element)
要素をftxui::Screenに表示します。
std::shared_ptr< Node > Element
std::function< std::vector< int >(int, int)> GraphFunction
Element graph(GraphFunction)
GraphFunctionを使用してグラフを描画します。