mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Execute IWYU (#299)
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
#include <stddef.h> // for size_t
|
||||
#include <stdio.h> // for getchar
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, size, Element, text, hcenter, Decorator, Fit, WIDTH, hflow, window, EQUAL, GREATER_THAN, HEIGHT, bold, border, dim, LESS_THAN
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <memory> // for allocator, shared_ptr
|
||||
#include <string> // for operator+, to_string, char_traits, string
|
||||
#include <cmath> // for sin, cos
|
||||
#include <ftxui/dom/elements.hpp> // for canvas, Element, separator, hbox, operator|, border
|
||||
#include <ftxui/screen/screen.hpp> // for Pixel
|
||||
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
||||
#include <string> // for string, basic_string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/screen_interactive.hpp"
|
||||
#include "ftxui/component/component.hpp" // for Renderer, CatchEvent, Horizontal, Menu, Tab
|
||||
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
||||
#include "ftxui/component/event.hpp" // for Event
|
||||
#include "ftxui/component/mouse.hpp" // for Mouse
|
||||
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
||||
#include "ftxui/dom/canvas.hpp" // for Canvas
|
||||
#include "ftxui/screen/color.hpp" // for Color, Color::Red, Color::Blue, Color::Green, ftxui
|
||||
|
||||
#include <cmath>
|
||||
int main(int argc, const char* argv[]) {
|
||||
using namespace ftxui;
|
||||
|
||||
@@ -18,7 +23,7 @@ int main(int argc, const char* argv[]) {
|
||||
// A triangle following the mouse, using braille characters.
|
||||
auto renderer_line_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "Several lines (braille)");
|
||||
c.DrawText(0, 0, "Several lines (braille)");
|
||||
c.DrawPointLine(mouse_x, mouse_y, 80, 10, Color::Red);
|
||||
c.DrawPointLine(80, 10, 80, 40, Color::Blue);
|
||||
c.DrawPointLine(80, 40, mouse_x, mouse_y, Color::Green);
|
||||
@@ -28,7 +33,7 @@ int main(int argc, const char* argv[]) {
|
||||
// A triangle following the mouse, using block characters.
|
||||
auto renderer_line_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "Several lines (block)");
|
||||
c.DrawText(0, 0, "Several lines (block)");
|
||||
c.DrawBlockLine(mouse_x, mouse_y, 80, 10, Color::Red);
|
||||
c.DrawBlockLine(80, 10, 80, 40, Color::Blue);
|
||||
c.DrawBlockLine(80, 40, mouse_x, mouse_y, Color::Green);
|
||||
@@ -38,7 +43,7 @@ int main(int argc, const char* argv[]) {
|
||||
// A circle following the mouse, using braille characters.
|
||||
auto renderer_circle_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "A circle (braille)");
|
||||
c.DrawText(0, 0, "A circle (braille)");
|
||||
c.DrawPointCircle(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
@@ -46,7 +51,7 @@ int main(int argc, const char* argv[]) {
|
||||
// A circle following the mouse, using block characters.
|
||||
auto renderer_circle_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "A circle (block)");
|
||||
c.DrawText(0, 0, "A circle (block)");
|
||||
c.DrawBlockCircle(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
@@ -54,7 +59,7 @@ int main(int argc, const char* argv[]) {
|
||||
// A filled circle following the mouse, using braille characters.
|
||||
auto renderer_circle_filled_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "A circle filled (braille)");
|
||||
c.DrawText(0, 0, "A circle filled (braille)");
|
||||
c.DrawPointCircleFilled(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
@@ -62,7 +67,7 @@ int main(int argc, const char* argv[]) {
|
||||
// A filled circle following the mouse, using block characters.
|
||||
auto renderer_circle_filled_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "A circle filled (block)");
|
||||
c.DrawText(0, 0, "A circle filled (block)");
|
||||
c.DrawBlockCircleFilled(mouse_x, mouse_y, 30);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
@@ -70,7 +75,7 @@ int main(int argc, const char* argv[]) {
|
||||
// An ellipse following the mouse, using braille characters.
|
||||
auto renderer_ellipse_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "An ellipse (braille)");
|
||||
c.DrawText(0, 0, "An ellipse (braille)");
|
||||
c.DrawPointEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
@@ -78,7 +83,7 @@ int main(int argc, const char* argv[]) {
|
||||
// An ellipse following the mouse, using block characters.
|
||||
auto renderer_ellipse_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "An ellipse (block)");
|
||||
c.DrawText(0, 0, "An ellipse (block)");
|
||||
c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
@@ -86,18 +91,18 @@ int main(int argc, const char* argv[]) {
|
||||
// An ellipse following the mouse filled, using braille characters.
|
||||
auto renderer_ellipse_filled_braille = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "A filled ellipse (braille)");
|
||||
c.DrawText(0, 0, "A filled ellipse (braille)");
|
||||
c.DrawPointEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2,
|
||||
mouse_y / 2);
|
||||
mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
// An ellipse following the mouse filled, using block characters.
|
||||
auto renderer_ellipse_filled_block = Renderer([&] {
|
||||
auto c = Canvas(100, 100);
|
||||
c.DrawText(0,0, "A filled ellipse (block)");
|
||||
c.DrawText(0, 0, "A filled ellipse (block)");
|
||||
c.DrawBlockEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2,
|
||||
mouse_y / 2);
|
||||
mouse_y / 2);
|
||||
c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
@@ -136,13 +141,13 @@ int main(int argc, const char* argv[]) {
|
||||
c.DrawText(0, 0, "A symmetrical graph filled");
|
||||
std::vector<int> ys(100);
|
||||
for (int x = 0; x < 100; x++) {
|
||||
ys[x] = 30 + //
|
||||
10 * cos(x * 0.2 - mouse_x * 0.05) + //
|
||||
5 * sin(x * 0.4) + //
|
||||
5 * sin(x * 0.3 - mouse_y * 0.05); //
|
||||
ys[x] = 30 + //
|
||||
10 * cos(x * 0.2 - mouse_x * 0.05) + //
|
||||
5 * sin(x * 0.4) + //
|
||||
5 * sin(x * 0.3 - mouse_y * 0.05); //
|
||||
}
|
||||
for (int x = 0; x < 100; x++) {
|
||||
c.DrawPointLine(x, 50+ys[x], x, 50-ys[x], Color::Red);
|
||||
c.DrawPointLine(x, 50 + ys[x], x, 50 - ys[x], Color::Red);
|
||||
}
|
||||
|
||||
return canvas(std::move(c));
|
||||
@@ -153,16 +158,16 @@ int main(int argc, const char* argv[]) {
|
||||
c.DrawText(0, 0, "A 2D gaussian plot");
|
||||
int size = 15;
|
||||
|
||||
// mouse_x = 5mx + 3*my
|
||||
// mouse_x = 5mx + 3*my
|
||||
// mouse_y = 0mx + -5my + 90
|
||||
float my = (mouse_y - 90) / -5.f;
|
||||
float mx = (mouse_x - 3 * my) / 5.f;
|
||||
std::vector<std::vector<float>> ys(size, std::vector<float>(size));
|
||||
for (int y = 0; y < size; y++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
float dx = x-mx;
|
||||
float dy = y-my;
|
||||
ys[y][x] = -1.5 + 3.0 * std::exp(-0.2f * (dx*dx+dy*dy));
|
||||
float dx = x - mx;
|
||||
float dy = y - my;
|
||||
ys[y][x] = -1.5 + 3.0 * std::exp(-0.2f * (dx * dx + dy * dy));
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < size; y++) {
|
||||
@@ -183,26 +188,27 @@ int main(int argc, const char* argv[]) {
|
||||
return canvas(std::move(c));
|
||||
});
|
||||
|
||||
|
||||
int selected_tab = 12;
|
||||
auto tab = Container::Tab({
|
||||
renderer_line_braille,
|
||||
renderer_line_block,
|
||||
renderer_circle_braille,
|
||||
renderer_circle_block,
|
||||
renderer_circle_filled_braille,
|
||||
renderer_circle_filled_block,
|
||||
renderer_ellipse_braille,
|
||||
renderer_ellipse_block,
|
||||
renderer_ellipse_filled_braille,
|
||||
renderer_ellipse_filled_block,
|
||||
auto tab = Container::Tab(
|
||||
{
|
||||
renderer_line_braille,
|
||||
renderer_line_block,
|
||||
renderer_circle_braille,
|
||||
renderer_circle_block,
|
||||
renderer_circle_filled_braille,
|
||||
renderer_circle_filled_block,
|
||||
renderer_ellipse_braille,
|
||||
renderer_ellipse_block,
|
||||
renderer_ellipse_filled_braille,
|
||||
renderer_ellipse_filled_block,
|
||||
|
||||
renderer_plot_1,
|
||||
renderer_plot_2,
|
||||
renderer_plot_3,
|
||||
renderer_plot_1,
|
||||
renderer_plot_2,
|
||||
renderer_plot_3,
|
||||
|
||||
renderer_text,
|
||||
}, &selected_tab);
|
||||
renderer_text,
|
||||
},
|
||||
&selected_tab);
|
||||
|
||||
// This capture the last mouse position.
|
||||
auto tab_with_mouse = CatchEvent(tab, [&](Event e) {
|
||||
|
Reference in New Issue
Block a user