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// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#include <stdio.h> // for getchar
5#include <cmath> // for cos
6#include <ftxui/dom/elements.hpp> // for Fit, canvas, operator|, border, Element
7#include <ftxui/screen/screen.hpp> // for Pixel, Screen
8#include <vector> // for vector, allocator
9
10#include "ftxui/dom/canvas.hpp" // for Canvas
11#include "ftxui/dom/node.hpp" // for Render
12#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
13
14 int main() {
15 using namespace ftxui;
16
17 auto c = Canvas(100, 100);
18
19 c.DrawText(0, 0, "This is a canvas", [](Pixel& p) {
20 p.foreground_color = Color::Red;
21 p.underlined = true;
22 });
23
24 // Triangle:
25 c.DrawPointLine(10, 10, 80, 10, Color::Red);
26 c.DrawPointLine(80, 10, 80, 40, Color::Blue);
27 c.DrawPointLine(80, 40, 10, 10, Color::Green);
28
29 // Circle, not filled and filled:
30 c.DrawPointCircle(30, 50, 20);
31 c.DrawPointCircleFilled(40, 40, 10);
32
33 // Plot a function:
34 std::vector<int> ys(100);
35 for (int x = 0; x < 100; x++)
36 ys[x] = int(80 + 20 * cos(x * 0.2));
37 for (int x = 0; x < 99; x++)
38 c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
39
40 auto document = canvas(&c) | border;
41
42 auto screen = Screen::Create(Dimension::Fit(document));
43 Render(screen, document);
44 screen.Print();
45 getchar();
46
47 return 0;
48}
canvas.hpp
color.hpp
elements.hpp
main
int main()
Definition examples/dom/canvas.cpp:14
ftxui::Canvas
Canvas is a drawable buffer associated with drawing operations.
Definition canvas.hpp:38
ftxui::Pixel::foreground_color
Color foreground_color
Definition pixel.hpp:49
ftxui::Pixel::underlined
bool underlined
Definition pixel.hpp:33
ftxui::Pixel
A Unicode character and its associated style.
Definition pixel.hpp:15
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
node.hpp
screen.hpp