FTXUI
6.1.9
C++ functional terminal UI.
Toggle main menu visibility
Loading...
Searching...
No Matches
examples/dom/canvas.cpp
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <stdio.h>
// for getchar
#include <cmath>
// for cos
#include <
ftxui/dom/elements.hpp
>
// for Fit, canvas, operator|, border, Element
#include <
ftxui/screen/screen.hpp
>
// for Pixel, Screen
#include <vector>
// for vector, allocator
#include "
ftxui/dom/canvas.hpp
"
// for Canvas
#include "
ftxui/dom/node.hpp
"
// for Render
#include "
ftxui/screen/color.hpp
"
// for Color, Color::Red, Color::Blue, Color::Green, ftxui
int
main() {
using namespace
ftxui
;
auto
c =
Canvas
(100, 100);
c.DrawText(0, 0,
"This is a canvas"
, [](
Pixel
& p) {
p.
foreground_color
=
Color::Red
;
p.
underlined
=
true
;
});
// Triangle:
c.DrawPointLine(10, 10, 80, 10,
Color::Red
);
c.DrawPointLine(80, 10, 80, 40,
Color::Blue
);
c.DrawPointLine(80, 40, 10, 10,
Color::Green
);
// Circle, not filled and filled:
c.DrawPointCircle(30, 50, 20);
c.DrawPointCircleFilled(40, 40, 10);
// Plot a function:
std::vector<int> ys(100);
for
(
int
x = 0; x < 100; x++)
ys[x] =
int
(80 + 20 * cos(x * 0.2));
for
(
int
x = 0; x < 99; x++)
c.DrawPointLine(x, ys[x], x + 1, ys[x + 1],
Color::Red
);
auto
document =
canvas
(&c) |
border
;
auto
screen =
Screen::Create
(
Dimension::Fit
(document));
Render
(screen, document);
screen.Print();
getchar();
return
0;
}
canvas.hpp
ftxui::Color::Green
@ Green
Definition
color.hpp:54
ftxui::Color::Red
@ Red
Definition
color.hpp:53
ftxui::Color::Blue
@ Blue
Definition
color.hpp:56
ftxui::Screen::Create
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
Definition
screen.cpp:394
color.hpp
elements.hpp
ftxui::Dimension::Fit
Dimensions Fit(Element &, bool extend_beyond_screen=false)
Definition
util.cpp:93
ftxui
Definition
animation.hpp:10
ftxui::canvas
Element canvas(ConstRef< Canvas >)
Produce an element from a Canvas, or a reference to a Canvas.
Definition
canvas.cpp:891
ftxui::Render
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition
node.cpp:88
ftxui::border
Element border(Element)
Draw a border around the element.
Definition
border.cpp:227
node.hpp
screen.hpp
ftxui::Canvas
Definition
canvas.hpp:23
ftxui::Pixel
A Unicode character and its associated style.
Definition
pixel.hpp:15
ftxui::Pixel::foreground_color
Color foreground_color
Definition
pixel.hpp:49
ftxui::Pixel::underlined
bool underlined
Definition
pixel.hpp:33