FTXUI 6.1.9
C++ functional terminal UI.
Chargement...
Recherche...
Aucune correspondance
examples/dom/canvas.cpp
Aller à la documentation de ce fichier.
1// Copyright 2020 Arthur Sonzogni. Tous droits réservés.
2// L'utilisation de ce code source est régie par la licence MIT que l'on peut trouver dans
3// le fichier LICENSE.
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
14int 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 // Cercle, non rempli et rempli :
30 c.DrawPointCircle(30, 50, 20);
31 c.DrawPointCircleFilled(40, 40, 10);
32
33 // Tracer une fonction :
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 }
38 for (int x = 0; x < 99; x++) {
39 c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red);
40 }
41
42 auto document = canvas(&c) | border;
43
44 auto screen = Screen::Create(Dimension::Fit(document));
45 Render(screen, document);
46 screen.Print();
47 getchar();
48
49 return 0;
50}
auto screen
void Render(Screen &screen, const Element &element)
Affiche un élément sur un ftxui::Screen.
Definition node.cpp:83
Canvas est un tampon dessinable associé aux opérations de dessin.
Definition canvas.hpp:38
Color foreground_color
Definition pixel.hpp:49
bool underlined
Definition pixel.hpp:33
Un caractère Unicode et son style associé.
Definition pixel.hpp:15
L'espace de noms FTXUI ftxui::
Definition animation.hpp:10