mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 10:38:09 +08:00 
			
		
		
		
	Address felixjulianheitmann suggestions. (#288)
- Remove unused examples/dom/flexbox.cpp - Add canvas(width, height, void(Canvas&)) method
This commit is contained in:
		| @@ -22,7 +22,7 @@ int main(int argc, const char* argv[]) { | ||||
|     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); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // A triangle following the mouse, using block characters. | ||||
| @@ -32,7 +32,7 @@ int main(int argc, const char* argv[]) { | ||||
|     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); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // A circle following the mouse, using braille characters. | ||||
| @@ -40,7 +40,7 @@ int main(int argc, const char* argv[]) { | ||||
|     auto c = Canvas(100, 100); | ||||
|     c.DrawText(0,0, "A circle (braille)"); | ||||
|     c.DrawPointCircle(mouse_x, mouse_y, 30); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // A circle following the mouse, using block characters. | ||||
| @@ -48,7 +48,7 @@ int main(int argc, const char* argv[]) { | ||||
|     auto c = Canvas(100, 100); | ||||
|     c.DrawText(0,0, "A circle (block)"); | ||||
|     c.DrawBlockCircle(mouse_x, mouse_y, 30); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // A filled circle following the mouse, using braille characters. | ||||
| @@ -56,7 +56,7 @@ int main(int argc, const char* argv[]) { | ||||
|     auto c = Canvas(100, 100); | ||||
|     c.DrawText(0,0, "A circle filled (braille)"); | ||||
|     c.DrawPointCircleFilled(mouse_x, mouse_y, 30); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // A filled circle following the mouse, using block characters. | ||||
| @@ -64,7 +64,7 @@ int main(int argc, const char* argv[]) { | ||||
|     auto c = Canvas(100, 100); | ||||
|     c.DrawText(0,0, "A circle filled (block)"); | ||||
|     c.DrawBlockCircleFilled(mouse_x, mouse_y, 30); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // An ellipse following the mouse, using braille characters. | ||||
| @@ -72,7 +72,7 @@ int main(int argc, const char* argv[]) { | ||||
|     auto c = Canvas(100, 100); | ||||
|     c.DrawText(0,0, "An ellipse (braille)"); | ||||
|     c.DrawPointEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // An ellipse following the mouse, using block characters. | ||||
| @@ -80,7 +80,7 @@ int main(int argc, const char* argv[]) { | ||||
|     auto c = Canvas(100, 100); | ||||
|     c.DrawText(0,0, "An ellipse (block)"); | ||||
|     c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // An ellipse following the mouse filled, using braille characters. | ||||
| @@ -89,7 +89,7 @@ int main(int argc, const char* argv[]) { | ||||
|     c.DrawText(0,0, "A filled ellipse (braille)"); | ||||
|     c.DrawPointEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2, | ||||
|                               mouse_y / 2); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // An ellipse following the mouse filled, using block characters. | ||||
| @@ -99,7 +99,7 @@ int main(int argc, const char* argv[]) { | ||||
|     c.DrawBlockEllipseFilled(mouse_x / 2, mouse_y / 2, mouse_x / 2, | ||||
|                               mouse_y / 2); | ||||
|     c.DrawBlockEllipse(mouse_x / 2, mouse_y / 2, mouse_x / 2, mouse_y / 2); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   // A text following the mouse | ||||
| @@ -112,7 +112,7 @@ int main(int argc, const char* argv[]) { | ||||
|                  p.underlined = true; | ||||
|                  p.bold = true; | ||||
|                }); | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   auto renderer_plot_1 = Renderer([&] { | ||||
| @@ -128,7 +128,7 @@ int main(int argc, const char* argv[]) { | ||||
|     for (int x = 1; x < 99; x++) | ||||
|       c.DrawPointLine(x, ys[x], x + 1, ys[x + 1]); | ||||
|  | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   auto renderer_plot_2 = Renderer([&] { | ||||
| @@ -145,7 +145,7 @@ int main(int argc, const char* argv[]) { | ||||
|       c.DrawPointLine(x, 50+ys[x], x, 50-ys[x], Color::Red); | ||||
|     } | ||||
|  | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|   auto renderer_plot_3 = Renderer([&] { | ||||
| @@ -180,7 +180,7 @@ int main(int argc, const char* argv[]) { | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     return ElementFrom(std::move(c)); | ||||
|     return canvas(std::move(c)); | ||||
|   }); | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -12,30 +12,30 @@ | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|  | ||||
|   auto canvas = Canvas(100, 100); | ||||
|   auto c = Canvas(100, 100); | ||||
|  | ||||
|   canvas.DrawText(0, 0, "This is a canvas", [](Pixel& p) -> void { | ||||
|   c.DrawText(0, 0, "This is a canvas", [](Pixel& p) { | ||||
|     p.foreground_color = Color::Red; | ||||
|     p.underlined = true; | ||||
|   }); | ||||
|  | ||||
|   // Triangle: | ||||
|   canvas.DrawPointLine(10, 10, 80, 10, Color::Red); | ||||
|   canvas.DrawPointLine(80, 10, 80, 40, Color::Blue); | ||||
|   canvas.DrawPointLine(80, 40, 10, 10, Color::Green); | ||||
|   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: | ||||
|   canvas.DrawPointCircle(30, 50, 20); | ||||
|   canvas.DrawPointCircleFilled(40, 40, 10); | ||||
|   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] = 80 + 20 * cos(x * 0.2); | ||||
|   for (int x = 0; x < 99; x++)  | ||||
|     canvas.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red); | ||||
|     c.DrawPointLine(x, ys[x], x + 1, ys[x + 1], Color::Red); | ||||
|  | ||||
|   auto document = ElementFrom(&canvas) | border; | ||||
|   auto document = canvas(&c) | border; | ||||
|  | ||||
|   auto screen = Screen::Create(Dimension::Fit(document)); | ||||
|   Render(screen, document); | ||||
|   | ||||
| @@ -1,38 +0,0 @@ | ||||
| #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 "ftxui/dom/flexbox_config.hpp"  // for ftxui | ||||
| #include "ftxui/dom/node.hpp"            // for Render | ||||
|  | ||||
| int main(int argc, const char* argv[]) { | ||||
|   using namespace ftxui; | ||||
|  | ||||
|   auto image = Canvas(100, 100); | ||||
|  | ||||
|   auto document = vbox({ | ||||
|     make_box("header"), | ||||
|     hbox({ | ||||
|       make_box("left side"), | ||||
|       make_box("center") | flex, | ||||
|       make_box("right side"), | ||||
|     }) | flex, | ||||
|     make_box("footer") | ||||
|   }); | ||||
|  | ||||
|   //auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); | ||||
|   //auto screen = Screen::Create(Dimension::Fit(document)); | ||||
|   auto screen = Screen::Create(Dimension::Full()); | ||||
|   Render(screen, document); | ||||
|   screen.Print(); | ||||
|   getchar(); | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| // 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. | ||||
		Reference in New Issue
	
	Block a user
	 Arthur Sonzogni
					Arthur Sonzogni