20 static std::string charset[] =
21 #if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
24 {
" ",
" ",
"█",
" ",
"█",
"█",
"█",
"█",
"█"};
26 {
" ",
"▗",
"▐",
"▖",
"▄",
"▟",
"▌",
"▙",
"█"};
29 class Graph :
public Node {
32 : graph_function_(std::move(graph_function)) {}
34 void ComputeRequirement()
override {
35 requirement_.flex_grow_x = 1;
36 requirement_.flex_grow_y = 1;
37 requirement_.flex_shrink_x = 1;
38 requirement_.flex_shrink_y = 1;
39 requirement_.min_x = 3;
40 requirement_.min_y = 3;
43 void Render(Screen& screen)
override {
44 const int width = (box_.x_max - box_.x_min + 1) * 2;
45 const int height = (box_.y_max - box_.y_min + 1) * 2;
46 if (width <= 0 || height <= 0) {
49 auto data = graph_function_(width, height);
51 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
52 const int height_1 = 2 * box_.y_max - data[i++];
53 const int height_2 = 2 * box_.y_max - data[i++];
54 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
56 int i_1 = yy < height_1 ? 0 : yy == height_1 ? 3 : 6;
57 int i_2 = yy < height_2 ? 0 : yy == height_2 ? 1 : 2;
58 screen.at(x, y) = charset[i_1 + i_2];
72 return std::make_shared<Graph>(std::move(graph_function));
std::shared_ptr< Node > Element
std::function< std::vector< int >(int, int)> GraphFunction
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element graph(GraphFunction)
Draw a graph using a GraphFunction.