21 using namespace ftxui;
27 auto renderer_line_braille = Renderer([&] {
29 c.DrawText(0, 0,
"Several lines (braille)");
30 c.DrawPointLine(mouse_x, mouse_y, 80, 10, Color::Red);
31 c.DrawPointLine(80, 10, 80, 40, Color::Blue);
32 c.DrawPointLine(80, 40, mouse_x, mouse_y, Color::Green);
33 return canvas(std::move(c));
37 auto renderer_line_block = Renderer([&] {
39 c.DrawText(0, 0,
"Several lines (block)");
40 c.DrawBlockLine(mouse_x, mouse_y, 80, 10, Color::Red);
41 c.DrawBlockLine(80, 10, 80, 40, Color::Blue);
42 c.DrawBlockLine(80, 40, mouse_x, mouse_y, Color::Green);
43 return canvas(std::move(c));
47 auto renderer_circle_braille = Renderer([&] {
49 c.DrawText(0, 0,
"A circle (braille)");
50 c.DrawPointCircle(mouse_x, mouse_y, 30);
51 return canvas(std::move(c));
55 auto renderer_circle_block = Renderer([&] {
57 c.DrawText(0, 0,
"A circle (block)");
58 c.DrawBlockCircle(mouse_x, mouse_y, 30);
59 return canvas(std::move(c));
63 auto renderer_circle_filled_braille = Renderer([&] {
65 c.DrawText(0, 0,
"A circle filled (braille)");
66 c.DrawPointCircleFilled(mouse_x, mouse_y, 30);
67 return canvas(std::move(c));
71 auto renderer_circle_filled_block = Renderer([&] {
73 c.DrawText(0, 0,
"A circle filled (block)");
74 c.DrawBlockCircleFilled(mouse_x, mouse_y, 30);
75 return canvas(std::move(c));
79 auto renderer_ellipse_braille = Renderer([&] {
81 c.DrawText(0, 0,
"An ellipse (braille)");
82 c.DrawPointEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
83 return canvas(std::move(c));
87 auto renderer_ellipse_block = Renderer([&] {
89 c.DrawText(0, 0,
"An ellipse (block)");
90 c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
91 return canvas(std::move(c));
95 auto renderer_ellipse_filled_braille = Renderer([&] {
97 c.DrawText(0, 0,
"A filled ellipse (braille)");
98 c.DrawPointEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2,
100 return canvas(std::move(c));
104 auto renderer_ellipse_filled_block = Renderer([&] {
105 auto c =
Canvas(100, 100);
106 c.DrawText(0, 0,
"A filled ellipse (block)");
107 c.DrawBlockEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2,
109 c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2);
110 return canvas(std::move(c));
114 auto renderer_text = Renderer([&] {
115 auto c =
Canvas(100, 100);
116 c.DrawText(0, 0,
"A piece of text");
117 c.DrawText(mouse_x, mouse_y,
"This is a piece of text with effects",
123 return canvas(std::move(c));
126 auto renderer_plot_1 = Renderer([&] {
127 auto c =
Canvas(100, 100);
128 c.DrawText(0, 0,
"A graph");
130 std::vector<int> ys(100);
131 for (
int x = 0; x < 100; x++) {
132 float dx = float(x - mouse_x);
134 ys[x] = int(dy + 20 * cos(dx * 0.14) + 10 * sin(dx * 0.42));
136 for (
int x = 1; x < 99; x++)
137 c.DrawPointLine(x, ys[x], x + 1, ys[x + 1]);
139 return canvas(std::move(c));
142 auto renderer_plot_2 = Renderer([&] {
143 auto c =
Canvas(100, 100);
144 c.DrawText(0, 0,
"A symmetrical graph filled");
145 std::vector<int> ys(100);
146 for (
int x = 0; x < 100; x++) {
148 10 * cos(x * 0.2 - mouse_x * 0.05) +
150 5 * sin(x * 0.3 - mouse_y * 0.05));
152 for (
int x = 0; x < 100; x++) {
153 c.DrawPointLine(x, 50 + ys[x], x, 50 - ys[x], Color::Red);
156 return canvas(std::move(c));
159 auto renderer_plot_3 = Renderer([&] {
160 auto c =
Canvas(100, 100);
161 c.DrawText(0, 0,
"A 2D gaussian plot");
166 float my = (mouse_y - 90) / -5.f;
167 float mx = (mouse_x - 3 * my) / 5.f;
168 std::vector<std::vector<float>> ys(size, std::vector<float>(size));
169 for (
int y = 0; y < size; y++) {
170 for (
int x = 0; x < size; x++) {
173 ys[y][x] = -1.5 + 3.0 * std::exp(-0.2f * (dx * dx + dy * dy));
176 for (
int y = 0; y < size; y++) {
177 for (
int x = 0; x < size; x++) {
180 5 * (x - 1) + 3 * (y - 0), 90 - 5 * (y - 0) - 5 * ys[y][x - 1],
181 5 * (x - 0) + 3 * (y - 0), 90 - 5 * (y - 0) - 5 * ys[y][x]);
185 5 * (x - 0) + 3 * (y - 1), 90 - 5 * (y - 1) - 5 * ys[y - 1][x],
186 5 * (x - 0) + 3 * (y - 0), 90 - 5 * (y - 0) - 5 * ys[y][x]);
191 return canvas(std::move(c));
194 int selected_tab = 12;
195 auto tab = Container::Tab(
197 renderer_line_braille,
199 renderer_circle_braille,
200 renderer_circle_block,
201 renderer_circle_filled_braille,
202 renderer_circle_filled_block,
203 renderer_ellipse_braille,
204 renderer_ellipse_block,
205 renderer_ellipse_filled_braille,
206 renderer_ellipse_filled_block,
217 auto tab_with_mouse = CatchEvent(tab, [&](
Event e) {
219 mouse_x = (e.
mouse().x - 1) * 2;
220 mouse_y = (e.
mouse().y - 1) * 4;
225 std::vector<std::string> tab_titles = {
230 "circle filled (braille)",
231 "circle filled (block)",
234 "ellipse filled (braille)",
235 "ellipse filled (block)",
241 auto tab_toggle = Menu(&tab_titles, &selected_tab);
243 auto component = Container::Horizontal({
249 auto component_renderer = Renderer(component, [&] {
251 tab_with_mouse->Render(),
253 tab_toggle->Render(),
258 auto screen = ScreenInteractive::FitComponent();
259 screen.Loop(component_renderer);