diff --git a/examples/dom/frame.cpp b/examples/dom/frame.cpp index 52ec6df817778a86af96d4bbfa133f7e518ef34c..0cfccbc8130b7b63a5cc3a21e7618b2ddea70c21 100644 --- a/examples/dom/frame.cpp +++ b/examples/dom/frame.cpp @@ -8,41 +8,41 @@ int main(int argc, const char *argv[]) { using namespace ftxui::dom; - auto document = - hbox( - window(hcenter(text(L" main frame ")), - vbox( - text(L"Line 1"), - text(L"Line 2"), - text(L"Line 3"), - frame( - vbox( - text(L"Line 4"), - text(L"Line 5"), - text(L"Line 6") - ) - ), - hbox( - window(text(L"frame 2"), - vbox( - text(L"Line 4"), - text(L"Line 5"), - text(L"Line 6") - ) - ), - window(text(L"frame 3"), - vbox( - text(L"Line 7"), - text(L"Line 8"), - text(L"Line 9") - ) - ) - ), - text(L"footer footer footer footer footer") - ) - ), - filler() - ); + auto document = + hbox( + window(text(L" main frame ") | hcenter, + vbox( + text(L"Line 1"), + text(L"Line 2"), + text(L"Line 3"), + frame( + vbox( + text(L"Line 4"), + text(L"Line 5"), + text(L"Line 6") + ) + ), + hbox( + window(text(L"frame 2"), + vbox( + text(L"Line 4"), + text(L"Line 5"), + text(L"Line 6") + ) + ), + window(text(L"frame 3"), + vbox( + text(L"Line 7"), + text(L"Line 8"), + text(L"Line 9") + ) + ) + ), + text(L"footer footer footer footer footer") + ) + ), + filler() + ); auto screen = ftxui::Screen::TerminalOutput(document); Render(screen, document.get()); std::cout << screen.ToString() << std::endl; diff --git a/examples/dom/package_manager.cpp b/examples/dom/package_manager.cpp index 21c803a6d10f124795fdc84ce4d71b9db1240da3..1987bec6ea598f1df541345bac7776eceeacdfd8 100644 --- a/examples/dom/package_manager.cpp +++ b/examples/dom/package_manager.cpp @@ -44,7 +44,7 @@ int main(int argc, const char *argv[]) int nb_done = 0; auto to_text = [](int number) { - std::wstring t = to_wstring(std::to_string(number)); + std::wstring t = to_wstring(number); while(t.size() < 3) t = L" " + t; return text(t); diff --git a/ftxui/include/ftxui/component/input.hpp b/ftxui/include/ftxui/component/input.hpp index 232d88e6662e6e1876bb9cf2512b598da4fcf5ae..6f8537c57ac02ea8186a40ad563f0df0549d2825 100644 --- a/ftxui/include/ftxui/component/input.hpp +++ b/ftxui/include/ftxui/component/input.hpp @@ -23,7 +23,7 @@ class Input : public Component { // Component implementation. dom::Element Render() override; - bool OnEvent(Event) override; + bool OnEvent(Event) override; private: int cursor_position = 0; diff --git a/ftxui/include/ftxui/component/menu.hpp b/ftxui/include/ftxui/component/menu.hpp index b426c6db2d79883631bd78b4105f6939216d57bb..6b4f045d0da6be06a6707d9b3752300391fa2d4d 100644 --- a/ftxui/include/ftxui/component/menu.hpp +++ b/ftxui/include/ftxui/component/menu.hpp @@ -27,7 +27,7 @@ class Menu : public Component { // Component implementation. dom::Element Render() override; - bool OnEvent(Event) override; + bool OnEvent(Event) override; }; } // namespace component diff --git a/ftxui/include/ftxui/dom/elements.hpp b/ftxui/include/ftxui/dom/elements.hpp index 6609fd7c2f32e093e87c761328d153b6ae0ca62c..67ebe7defea6a2a854e05a78cc1cc91f64862d43 100644 --- a/ftxui/include/ftxui/dom/elements.hpp +++ b/ftxui/include/ftxui/dom/elements.hpp @@ -52,20 +52,8 @@ Element nothing(Element element); Element operator|(Element, Decorator); Decorator operator|(Decorator, Decorator); -// Make container able to take several children. -template <class... Args> -Children unpack(Args... args) { - Children vec; - (vec.push_back(std::forward<Args>(args)), ...); - return vec; -} - -#define TAKE_ANY_ARGS(container) \ - template <class... Args> \ - Element container(Args... children) { \ - return container(unpack(std::forward<Args>(children)...)); \ - } \ - +// Make container able to take any number of children as input. +#include "take_any_args.hpp" TAKE_ANY_ARGS(vbox) TAKE_ANY_ARGS(hbox) TAKE_ANY_ARGS(dbox) diff --git a/ftxui/include/ftxui/requirement.hpp b/ftxui/include/ftxui/requirement.hpp index 2b4e714a22174716fcb06bc6fcdace7d690fb398..f5a960552c55159558686da2164a1d125906efdc 100644 --- a/ftxui/include/ftxui/requirement.hpp +++ b/ftxui/include/ftxui/requirement.hpp @@ -4,23 +4,11 @@ namespace ftxui { struct Requirement { - // Minimal dimensions. - struct { - int x = 0; - int y = 0; - } min; + // The required size to fully draw the element. + struct { int x = 0; int y = 0; } min; - // Maximal dimensions. - struct { - int x = -1; - int y = -1; - } max; - - // Flex. - struct { - int x = 0; - int y = 0; - } flex; + // How much flexibility is given to the component. + struct { int x = 0; int y = 0; } flex; }; }; // namespace ftxui diff --git a/ftxui/include/ftxui/util/string.hpp b/ftxui/include/ftxui/util/string.hpp index d2383e787eb5df27d93d1eb2cf6e4ed4e2615cad..72d0b0515783f3e33a77783fccc2d77a9f02493e 100644 --- a/ftxui/include/ftxui/util/string.hpp +++ b/ftxui/include/ftxui/util/string.hpp @@ -2,3 +2,8 @@ std::string to_string(const std::wstring& s); std::wstring to_wstring(const std::string& s); + +template<typename T> +std::wstring to_wstring(T s) { + return to_wstring(std::to_string(s)); +} diff --git a/ftxui/src/ftxui/dom/gauge_test.cpp b/ftxui/src/ftxui/dom/gauge_test.cpp index c3f88814d216c6a6755023ee08538c26a30ed436..ef78951a91950fee7d9bde779586a40fe52e3d7e 100644 --- a/ftxui/src/ftxui/dom/gauge_test.cpp +++ b/ftxui/src/ftxui/dom/gauge_test.cpp @@ -18,8 +18,8 @@ TEST(GaugeTest, half) { Screen screen(11,1); Render(screen, root.get()); - EXPECT_EQ("█████▏▋ ", screen.ToString()); -//" ▏▎▍▌▊▉█"; + EXPECT_EQ("█████▍ ", screen.ToString()); + //" ▏▎▍▌▊▉█"; } TEST(GaugeTest, one) { diff --git a/ftxui/src/ftxui/dom/vbox_test.cpp b/ftxui/src/ftxui/dom/vbox_test.cpp index 3e1ef4539d3d594cdbfbcc4b091760648e6290c8..6f24fb8b60d380abce318da36ccae3be0ebe634b 100644 --- a/ftxui/src/ftxui/dom/vbox_test.cpp +++ b/ftxui/src/ftxui/dom/vbox_test.cpp @@ -10,7 +10,7 @@ TEST(VBoxTest, ScreenSmaller1) { Screen screen(6, 1); Render(screen, root.get()); - EXPECT_EQ("text_1", screen.ToString()); + EXPECT_EQ("text_2", screen.ToString()); } TEST(VBoxTest, ScreenFit) {