diff --git a/examples/component/gallery.cpp b/examples/component/gallery.cpp index 360938c8..eff8e20e 100644 --- a/examples/component/gallery.cpp +++ b/examples/component/gallery.cpp @@ -57,27 +57,28 @@ class MyComponent : public Component { container.Add(&input); } - // clang-format off Element Render(std::wstring name, Component& component) { - return - hbox( + return hbox({ text(name) | size(WIDTH, EQUAL, 8), separator(), - component.Render() - ); + component.Render(), + }); } Element Render() override { - return - vbox( - Render(L"menu", menu), separator(), - Render(L"toggle", toggle), separator(), - Render(L"checkbox", checkbox_container), separator(), - Render(L"radiobox", radiobox), separator(), - Render(L"input", input) | size(WIDTH, LESS_THAN, 30) - ) | border; + return vbox({ + Render(L"menu", menu), + separator(), + Render(L"toggle", toggle), + separator(), + Render(L"checkbox", checkbox_container), + separator(), + Render(L"radiobox", radiobox), + separator(), + Render(L"input", input) | size(WIDTH, LESS_THAN, 30), + }) | + border; } - // clang-format on }; int main(int argc, const char* argv[]) { diff --git a/examples/component/homescreen.cpp b/examples/component/homescreen.cpp index b92856ed..66358428 100644 --- a/examples/component/homescreen.cpp +++ b/examples/component/homescreen.cpp @@ -41,49 +41,60 @@ class HTopComponent : public Component { HTopComponent() {} ~HTopComponent() override {} - // clang-format off Element Render() override { - return - hbox( - vbox( - // --- Frequency --- - text(L"Frequency [Mhz]") | hcenter, - hbox( - vbox( - text(L"2400 "), filler(), - text(L"1200 "), filler(), - text(L"0% ") - ), - graph(std::ref(my_graph)) - ) | flex, - separator(), - // --- Utilization --- - text(L"Utilization [%]") | hcenter, - hbox( - vbox( - text(L"100 "), filler(), - text(L"50 "), filler(), - text(L"0 ") - ), - graph(std::ref(my_graph)) | color(Color::RedLight) - ) | flex - ) | flex, - separator(), - // --- Ram --- - vbox( - text(L"Ram [Mo]") | hcenter, - hbox( - vbox( - text(L"8192"), filler(), - text(L"4096 "), filler(), - text(L"0 ") - ), - graph(std::ref(my_graph)) | color(Color::BlueLight) - ) | flex - ) | flex - ) | flex | border; + auto frequency = vbox({ + text(L"Frequency [Mhz]") | hcenter, + hbox({ + vbox({ + text(L"2400 "), + filler(), + text(L"1200 "), + filler(), + text(L"0% "), + }), + graph(std::ref(my_graph)) | flex, + }) | flex, + }); + + auto utilization = vbox({ + text(L"Utilization [%]") | hcenter, + hbox({ + vbox({ + text(L"100 "), + filler(), + text(L"50 "), + filler(), + text(L"0 "), + }), + graph(std::ref(my_graph)) | color(Color::RedLight), + }) | flex, + }); + + auto ram = vbox({ + text(L"Ram [Mo]") | hcenter, + hbox({ + vbox({ + text(L"8192"), + filler(), + text(L"4096 "), + filler(), + text(L"0 "), + }), + graph(std::ref(my_graph)) | color(Color::BlueLight), + }) | flex, + }); + + return hbox({ + vbox({ + frequency | flex, + separator(), + utilization | flex, + }) | flex, + separator(), + ram | flex, + }) | + flex | border; } - // clang-format on }; class CompilerComponent : public Component { @@ -173,37 +184,38 @@ class CompilerComponent : public Component { input_container.Add(&input); } - // clang-format off Element Render() override { - return - vbox( - hbox( - window(text(L"Compiler"), - compiler.Render() | frame | size(HEIGHT, LESS_THAN, 6) - ), - window(text(L"Flags"), flag.Render()), - vbox( - window(text(L"Executable:"), executable.Render()) - | size(WIDTH, EQUAL, 20), - window(text(L"Input"), - hbox( - vbox( - hbox(text(L"Add: "), input_add.Render()) - | size(WIDTH, EQUAL, 20) - | size(HEIGHT, EQUAL, 1), - filler() - ), - separator(), - input.Render() | frame | size(HEIGHT, EQUAL, 3) | flex - ) - ) | size(WIDTH, EQUAL, 60) - ), - filler() - ), - hflow(RenderCommandLine()) - ) | border; + auto compiler_win = window(text(L"Compiler"), compiler.Render() | frame); + auto flags_win = window(text(L"Flags"), flag.Render()); + auto executable_win = window(text(L"Executable:"), executable.Render()); + auto input_win = + window(text(L"Input"), + hbox({ + vbox({ + hbox({ + text(L"Add: "), + input_add.Render(), + }) | size(WIDTH, EQUAL, 20) | + size(HEIGHT, EQUAL, 1), + filler(), + }), + separator(), + input.Render() | frame | size(HEIGHT, EQUAL, 3) | flex, + })); + return vbox({ + hbox({ + compiler_win | size(HEIGHT, LESS_THAN, 6), + flags_win, + vbox({ + executable_win | size(WIDTH, EQUAL, 20), + input_win | size(WIDTH, EQUAL, 60), + }), + filler(), + }), + hflow(RenderCommandLine()), + }) | + border; } - // clang-format on Elements RenderCommandLine() { Elements line; @@ -230,100 +242,94 @@ class CompilerComponent : public Component { }; class SpinnerComponent : public Component { - // clang-format off Element Render() override { Elements entries; - for(int i = 0; i<22; ++i) { + for (int i = 0; i < 22; ++i) { if (i != 0) - entries.push_back( - spinner(i, shift/2) - | bold - | size(WIDTH, GREATER_THAN, 2) - | border - ); + entries.push_back(spinner(i, shift / 2) | bold | + size(WIDTH, GREATER_THAN, 2) | border); } return hflow(std::move(entries)) | border; } - // clang-format on }; class ColorComponent : public Component { - // clang-format off Element Render() override { - return - hbox( - vbox( - color(Color::Default, text(L"Default")), - color(Color::Black, text(L"Black")), - color(Color::GrayDark, text(L"GrayDark")), - color(Color::GrayLight, text(L"GrayLight")), - color(Color::White, text(L"White")), - color(Color::Blue, text(L"Blue")), - color(Color::BlueLight, text(L"BlueLight")), - color(Color::Cyan, text(L"Cyan")), - color(Color::CyanLight, text(L"CyanLight")), - color(Color::Green, text(L"Green")), - color(Color::GreenLight, text(L"GreenLight")), - color(Color::Magenta, text(L"Magenta")), - color(Color::MagentaLight, text(L"MagentaLight")), - color(Color::Red, text(L"Red")), - color(Color::RedLight, text(L"RedLight")), - color(Color::Yellow, text(L"Yellow")), - color(Color::YellowLight, text(L"YellowLight")) - ), - vbox( - bgcolor(Color::Default, text(L"Default")), - bgcolor(Color::Black, text(L"Black")), - bgcolor(Color::GrayDark, text(L"GrayDark")), - bgcolor(Color::GrayLight, text(L"GrayLight")), - bgcolor(Color::White, text(L"White")), - bgcolor(Color::Blue, text(L"Blue")), - bgcolor(Color::BlueLight, text(L"BlueLight")), - bgcolor(Color::Cyan, text(L"Cyan")), - bgcolor(Color::CyanLight, text(L"CyanLight")), - bgcolor(Color::Green, text(L"Green")), - bgcolor(Color::GreenLight, text(L"GreenLight")), - bgcolor(Color::Magenta, text(L"Magenta")), - bgcolor(Color::MagentaLight, text(L"MagentaLight")), - bgcolor(Color::Red, text(L"Red")), - bgcolor(Color::RedLight, text(L"RedLight")), - bgcolor(Color::Yellow, text(L"Yellow")), - bgcolor(Color::YellowLight, text(L"YellowLight")) - ) - ) | hcenter | border; - // clang-format on + return hbox({ + vbox({ + color(Color::Default, text(L"Default")), + color(Color::Black, text(L"Black")), + color(Color::GrayDark, text(L"GrayDark")), + color(Color::GrayLight, text(L"GrayLight")), + color(Color::White, text(L"White")), + color(Color::Blue, text(L"Blue")), + color(Color::BlueLight, text(L"BlueLight")), + color(Color::Cyan, text(L"Cyan")), + color(Color::CyanLight, text(L"CyanLight")), + color(Color::Green, text(L"Green")), + color(Color::GreenLight, text(L"GreenLight")), + color(Color::Magenta, text(L"Magenta")), + color(Color::MagentaLight, text(L"MagentaLight")), + color(Color::Red, text(L"Red")), + color(Color::RedLight, text(L"RedLight")), + color(Color::Yellow, text(L"Yellow")), + color(Color::YellowLight, text(L"YellowLight")), + }), + vbox({ + bgcolor(Color::Default, text(L"Default")), + bgcolor(Color::Black, text(L"Black")), + bgcolor(Color::GrayDark, text(L"GrayDark")), + bgcolor(Color::GrayLight, text(L"GrayLight")), + bgcolor(Color::White, text(L"White")), + bgcolor(Color::Blue, text(L"Blue")), + bgcolor(Color::BlueLight, text(L"BlueLight")), + bgcolor(Color::Cyan, text(L"Cyan")), + bgcolor(Color::CyanLight, text(L"CyanLight")), + bgcolor(Color::Green, text(L"Green")), + bgcolor(Color::GreenLight, text(L"GreenLight")), + bgcolor(Color::Magenta, text(L"Magenta")), + bgcolor(Color::MagentaLight, text(L"MagentaLight")), + bgcolor(Color::Red, text(L"Red")), + bgcolor(Color::RedLight, text(L"RedLight")), + bgcolor(Color::Yellow, text(L"Yellow")), + bgcolor(Color::YellowLight, text(L"YellowLight")), + }), + }) | + hcenter | border; } }; class GaugeComponent : public Component { - // clang-format off Element RenderGauge(int delta) { float progress = (shift + delta) % 1000 / 1000.f; - return hbox(text(std::to_wstring(int(progress * 100)) + L"% ") | size(WIDTH, EQUAL, 5), - gauge(progress)); + return hbox({ + text(std::to_wstring(int(progress * 100)) + L"% ") | + size(WIDTH, EQUAL, 5), + gauge(progress), + }); } Element Render() override { - return - vbox( - RenderGauge(0) | color(Color::Black), - RenderGauge(100) | color(Color::GrayDark), - RenderGauge(50) | color(Color::GrayLight), - RenderGauge(6894) | color(Color::White), separator(), - RenderGauge(6841) | color(Color::Blue), - RenderGauge(9813) | color(Color::BlueLight), - RenderGauge(98765) | color(Color::Cyan), - RenderGauge(98) | color(Color::CyanLight), - RenderGauge(9846) | color(Color::Green), - RenderGauge(1122) | color(Color::GreenLight), - RenderGauge(84) | color(Color::Magenta), - RenderGauge(645) | color(Color::MagentaLight), - RenderGauge(568) | color(Color::Red), - RenderGauge(2222) | color(Color::RedLight), - RenderGauge(220) | color(Color::Yellow), - RenderGauge(348) | color(Color::YellowLight) - ) | border; + return vbox({ + RenderGauge(0) | color(Color::Black), + RenderGauge(100) | color(Color::GrayDark), + RenderGauge(50) | color(Color::GrayLight), + RenderGauge(6894) | color(Color::White), + separator(), + RenderGauge(6841) | color(Color::Blue), + RenderGauge(9813) | color(Color::BlueLight), + RenderGauge(98765) | color(Color::Cyan), + RenderGauge(98) | color(Color::CyanLight), + RenderGauge(9846) | color(Color::Green), + RenderGauge(1122) | color(Color::GreenLight), + RenderGauge(84) | color(Color::Magenta), + RenderGauge(645) | color(Color::MagentaLight), + RenderGauge(568) | color(Color::Red), + RenderGauge(2222) | color(Color::RedLight), + RenderGauge(220) | color(Color::Yellow), + RenderGauge(348) | color(Color::YellowLight), + }) | + border; }; - // clang-format on }; class Tab : public Component { @@ -354,8 +360,11 @@ class Tab : public Component { } Element Render() override { - return vbox(text(L"FTXUI Demo") | bold | hcenter, - tab_selection.Render() | hcenter, container.Render()); + return vbox({ + text(L"FTXUI Demo") | bold | hcenter, + tab_selection.Render() | hcenter, + container.Render(), + }); } }; diff --git a/examples/component/input.cpp b/examples/component/input.cpp index 269fc1bf..a28afd7b 100644 --- a/examples/component/input.cpp +++ b/examples/component/input.cpp @@ -33,18 +33,13 @@ class MyComponent : public Component { Input input_2; Input input_3; - // clang-format off Element Render() override { - return - border( - vbox( - hbox(text(L" input_1 : "), input_1.Render()), - hbox(text(L" input_2 : "), input_2.Render()), - hbox(text(L" input_3 : "), input_3.Render()) - ) - ); + return border(vbox({ + hbox({text(L" input_1 : "), input_1.Render()}), + hbox({text(L" input_2 : "), input_2.Render()}), + hbox({text(L" input_3 : "), input_3.Render()}), + })); } - // clang-format on }; int main(int argc, const char* argv[]) { diff --git a/examples/component/menu2.cpp b/examples/component/menu2.cpp index daf32035..82f4a68b 100644 --- a/examples/component/menu2.cpp +++ b/examples/component/menu2.cpp @@ -40,38 +40,39 @@ class MyComponent : public Component { Menu left_menu; Menu right_menu; - // clang-format off - Element Render() override { - int sum = left_menu.selected * 10 + right_menu.selected; - return - border( - vbox( - // -------- Top panel -------------- - hbox( - // -------- Left Menu -------------- - vbox( - hcenter(bold(text(L"Percentage by 10%"))), - separator(), - left_menu.Render() - ) | flex, - // -------- Right Menu -------------- - vbox( - hcenter(bold(text(L"Percentage by 1%"))), - separator(), - right_menu.Render() - ) | flex, - filler() - ), - separator(), - // -------- Bottom panel -------------- - vbox( - hbox(text(L" gauge : "), gauge(sum/100.0)), - hbox(text(L" text : "), text(to_wstring(std::to_string(sum) + " %"))) - ) | flex - ) - ); - } - // clang-format on + Element Render() override { + int sum = left_menu.selected * 10 + right_menu.selected; + return border(vbox({ + // -------- Top panel -------------- + hbox({ + // -------- Left Menu -------------- + vbox({ + hcenter(bold(text(L"Percentage by 10%"))), + separator(), + left_menu.Render(), + }) | flex, + // -------- Right Menu -------------- + vbox({ + hcenter(bold(text(L"Percentage by 1%"))), + separator(), + right_menu.Render(), + }) | flex, + filler(), + }), + separator(), + // -------- Bottom panel -------------- + vbox({ + hbox({ + text(L" gauge : "), + gauge(sum / 100.0), + }), + hbox({ + text(L" text : "), + text(to_wstring(std::to_string(sum) + " %")), + }), + }) | flex, + })); + } }; int main(int argc, const char* argv[]) { diff --git a/examples/component/menu_style.cpp b/examples/component/menu_style.cpp index 433c2349..ba72bf22 100644 --- a/examples/component/menu_style.cpp +++ b/examples/component/menu_style.cpp @@ -57,14 +57,14 @@ class MyComponent : public Component { // clang-format off Element Render() override { return - hbox( + hbox({ menu_1.Render() | flex, separator(), menu_2.Render() | flex, separator(), menu_3.Render() | flex, separator(), menu_4.Render() | flex, separator(), menu_5.Render() | flex, separator(), - menu_6.Render() | flex - ) | border; + menu_6.Render() | flex, + }) | border; } // clang-format on }; diff --git a/examples/component/toggle.cpp b/examples/component/toggle.cpp index 3844a596..c21289d3 100644 --- a/examples/component/toggle.cpp +++ b/examples/component/toggle.cpp @@ -38,19 +38,24 @@ class MyComponent : public Component { Toggle toggle_3_; Toggle toggle_4_; - // clang-format off Element Render() override { - return - vbox( + return vbox({ text(L"Choose your options:"), text(L""), hbox(text(L" * Poweroff on startup : "), toggle_1_.Render()), hbox(text(L" * Out of process : "), toggle_2_.Render()), hbox(text(L" * Price of the information : "), toggle_3_.Render()), - hbox(text(L" * Number of elements : "), toggle_4_.Render()) - ); + hbox(text(L" * Number of elements : "), toggle_4_.Render()), + }); + } + + bool OnEvent(Event event) { + if (event == Event::Return) { + on_enter(); + return true; + } + return Component::OnEvent(event); } - // clang-format on }; int main(int argc, const char* argv[]) { diff --git a/examples/dom/border.cpp b/examples/dom/border.cpp index 837f2196..77b0f819 100644 --- a/examples/dom/border.cpp +++ b/examples/dom/border.cpp @@ -11,41 +11,33 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - hbox( + auto document = hbox({ window(text(L" main frame ") | hcenter, - vbox( - text(L"Line 1"), - text(L"Line 2"), - text(L"Line 3"), - vbox( - text(L"Line 4"), - text(L"Line 5"), - text(L"Line 6") - ) | border, - 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() - ); - // clang-format on + vbox({ + text(L"Line 1"), + text(L"Line 2"), + text(L"Line 3"), + vbox({ + text(L"Line 4"), + text(L"Line 5"), + text(L"Line 6"), + }) | border, + 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 = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); std::cout << screen.ToString() << std::endl; diff --git a/examples/dom/dbox.cpp b/examples/dom/dbox.cpp index 742c58ac..8e917ff8 100644 --- a/examples/dom/dbox.cpp +++ b/examples/dom/dbox.cpp @@ -9,19 +9,16 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - dbox( - vbox( - text(L"line_1"), - text(L"line_2"), - text(L"line_3"), - text(L"line_4"), - text(L"line_5") - ) | border, - text(L"overlay") | border | center - ); - // clang-format on + auto document = dbox({ + vbox({ + text(L"line_1"), + text(L"line_2"), + text(L"line_3"), + text(L"line_4"), + text(L"line_5"), + }) | border, + text(L"overlay") | border | center, + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/gauge.cpp b/examples/dom/gauge.cpp index 71684e67..3d36bd34 100644 --- a/examples/dom/gauge.cpp +++ b/examples/dom/gauge.cpp @@ -17,14 +17,11 @@ int main(int argc, const char* argv[]) { for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) { std::wstring data_downloaded = std::to_wstring(int(percentage * 5000)) + L"/5000"; - // clang-format off - auto document = - hbox( - text(L"downloading:"), - gauge(percentage) | flex, - text(L" " + data_downloaded) - ); - // clang-format on + auto document = hbox({ + text(L"downloading:"), + gauge(percentage) | flex, + text(L" " + data_downloaded), + }); auto screen = Screen(100, 1); Render(screen, document.get()); std::cout << reset_position << screen.ToString() << std::flush; diff --git a/examples/dom/graph.cpp b/examples/dom/graph.cpp index d59f9f61..cae49ac4 100644 --- a/examples/dom/graph.cpp +++ b/examples/dom/graph.cpp @@ -45,23 +45,23 @@ int main(int argc, const char* argv[]) { std::string reset_position; for (int i = 0;; ++i) { - // clang-format off auto document = - hbox( - vbox( - graph(std::ref(my_graph)), separator(), - graph(triangle) | inverted - ) | flex, - separator(), - vbox( - graph(std::ref(my_graph)) | color(Color::BlueLight), separator(), - graph(std::ref(my_graph)) | color(Color::RedLight), separator(), - graph(std::ref(my_graph)) | color(Color::YellowLight) - ) | flex - ) - | border - | size(HEIGHT, GREATER_THAN, 40); - // clang-format on + hbox({ + vbox({ + graph(std::ref(my_graph)), + separator(), + graph(triangle) | inverted, + }) | flex, + separator(), + vbox({ + graph(std::ref(my_graph)) | color(Color::BlueLight), + separator(), + graph(std::ref(my_graph)) | color(Color::RedLight), + separator(), + graph(std::ref(my_graph)) | color(Color::YellowLight), + }) | flex, + }) | + border | size(HEIGHT, GREATER_THAN, 40); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/hflow.cpp b/examples/dom/hflow.cpp index cc2fd070..6adecbe2 100644 --- a/examples/dom/hflow.cpp +++ b/examples/dom/hflow.cpp @@ -12,25 +12,35 @@ int main(int argc, const char* argv[]) { using namespace ftxui; auto make_box = [](size_t dimx, size_t dimy) { std::wstring title = to_wstring(dimx) + L"x" + to_wstring(dimy); - // clang-format off return window(text(title) | hcenter | bold, text(L"content") | hcenter | dim) | size(WIDTH, EQUAL, dimx) | size(HEIGHT, EQUAL, dimy); - // clang-format on }; - // clang-format off - auto document = - hflow(make_box(7, 7), make_box(7, 5), make_box(5, 7), make_box(10, 4), - make_box(10, 4), make_box(10, 4), make_box(10, 4), make_box(11, 4), - make_box(11, 4), make_box(11, 4), make_box(11, 4), make_box(12, 4), - make_box(12, 5), make_box(12, 4), make_box(13, 4), make_box(13, 3), - make_box(13, 3), make_box(10, 3)) - | size(WIDTH, GREATER_THAN, 20) - | border - | size(HEIGHT, GREATER_THAN, 30) - | size(WIDTH, LESS_THAN, 50); - // clang-format on + auto style = size(WIDTH, GREATER_THAN, 20) | border | + size(HEIGHT, GREATER_THAN, 30) | size(WIDTH, LESS_THAN, 50); + + auto document = hflow({ + make_box(7, 7), + make_box(7, 5), + make_box(5, 7), + make_box(10, 4), + make_box(10, 4), + make_box(10, 4), + make_box(10, 4), + make_box(11, 4), + make_box(11, 4), + make_box(11, 4), + make_box(11, 4), + make_box(12, 4), + make_box(12, 5), + make_box(12, 4), + make_box(13, 4), + make_box(13, 3), + make_box(13, 3), + make_box(10, 3), + }) | + style; auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/html_like.cpp b/examples/dom/html_like.cpp index 8b52a57f..1c855bbd 100644 --- a/examples/dom/html_like.cpp +++ b/examples/dom/html_like.cpp @@ -15,11 +15,11 @@ int main(int argc, const char* argv[]) { using namespace std::chrono_literals; auto img1 = []() { return text(L"img") | border; }; - auto img2 = []() { return vbox(text(L"big"), text(L"image")) | border; }; + auto img2 = []() { return vbox({text(L"big"), text(L"image")}) | border; }; std::string reset_position; for (int i = 0;; ++i) { - auto document = + auto document = // hflow( paragraph(L"Hello world! Here is an image:"), img1(), paragraph(L" Here is a text "), text(L"underlined ") | underlined, diff --git a/examples/dom/package_manager.cpp b/examples/dom/package_manager.cpp index fb6719fd..dc8aceef 100644 --- a/examples/dom/package_manager.cpp +++ b/examples/dom/package_manager.cpp @@ -49,49 +49,54 @@ int main(int argc, const char* argv[]) { return text(to_wstring(number)) | size(WIDTH, EQUAL, 3); }; - // clang-format off auto renderTask = [&](const Task& task) { auto style = (task.downloaded == task.size) ? dim : bold; - return - hbox( + return hbox({ text(task.name) | style, separator(), to_text(task.downloaded), text(L"/"), to_text(task.size), separator(), - gauge(task.downloaded / float(task.size)) - ); + gauge(task.downloaded / float(task.size)), + }); }; auto renderSummary = [&]() { - return - window(text(L" Summary "), - vbox( - hbox(text(L"- done: "), to_text(nb_done) | bold) | color(Color::Green), - hbox(text(L"- active: "), to_text(nb_active) | bold ) | color(Color::RedLight), - hbox(text(L"- queue: "), to_text(nb_queued) | bold) | color(Color::Red) - ) - ); + auto summary = vbox({ + hbox({ + text(L"- done: "), + to_text(nb_done) | bold, + }) | color(Color::Green), + hbox({ + text(L"- active: "), + to_text(nb_active) | bold, + }) | color(Color::RedLight), + hbox({ + text(L"- queue: "), + to_text(nb_queued) | bold, + }) | color(Color::Red), + }); + + return window(text(L" Summary "), summary); }; - auto render = [&](){ + auto render = [&]() { std::vector entries; - for(auto& task : displayed_task) + for (auto& task : displayed_task) entries.push_back(renderTask(task)); - return - vbox( + return vbox({ // List of tasks. - window(text(L" Task "), - vbox(std::move(entries)) - ), + window(text(L" Task "), vbox(std::move(entries))), // Summary. - hbox(renderSummary(), filler()) - ); + hbox({ + renderSummary(), + filler(), + }), + }); }; - // clang-format on auto updateModel = [&]() { for (auto& task : displayed_task) { diff --git a/examples/dom/paragraph.cpp b/examples/dom/paragraph.cpp index 8b2da83e..0e1b7f1a 100644 --- a/examples/dom/paragraph.cpp +++ b/examples/dom/paragraph.cpp @@ -13,25 +13,22 @@ int main(int argc, const char* argv[]) { std::wstring p = LR"(In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule) describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For example, if cancer is related to age, then, using Bayes' theorem, a person's age can be used to more accurately assess the probability that they have cancer, compared to the assessment of the probability of cancer made without knowledge of the person's age. One of the many applications of Bayes' theorem is Bayesian inference, a particular approach to statistical inference. When applied, the probabilities involved in Bayes' theorem may have different probability interpretations. With the Bayesian probability interpretation the theorem expresses how a subjective degree of belief should rationally change to account for availability of related evidence. Bayesian inference is fundamental to Bayesian statistics.)"; - // clang-format off - auto document = - vbox( - hbox( - hflow(paragraph(p)) | border, - hflow(paragraph(p)) | border, - hflow(paragraph(p)) | border - ) | flex, - hbox( - hflow(paragraph(p)) | border, - hflow(paragraph(p)) | border - ) | flex, - hbox( - hflow(paragraph(p)) | border - ) | flex - ); - // clang-format on + auto document = vbox({ + hbox({ + hflow(paragraph(p)) | border, + hflow(paragraph(p)) | border, + hflow(paragraph(p)) | border, + }) | flex, + hbox({ + hflow(paragraph(p)) | border, + hflow(paragraph(p)) | border, + }) | flex, + hbox({ + hflow(paragraph(p)) | border, + }) | flex, + }); - auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); + auto screen = Screen::Create(Dimension::Full(), Dimension::Full()); Render(screen, document.get()); std::cout << screen.ToString(); getchar(); diff --git a/examples/dom/separator.cpp b/examples/dom/separator.cpp index 16f10f48..71b495f3 100644 --- a/examples/dom/separator.cpp +++ b/examples/dom/separator.cpp @@ -9,20 +9,18 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - hbox( - text(L"left-column"), - separator(), - vbox( - center(text(L"right-top")) | flex, - separator(), - center(text(L"bottom-bottom")) - ) | flex, - separator(), - text(L"right-column") - ) | border; - // clang-format on + auto document = hbox({ + text(L"left-column"), + separator(), + vbox({ + center(text(L"right-top")) | flex, + separator(), + center(text(L"bottom-bottom")), + }) | flex, + separator(), + text(L"right-column"), + }) | + border; auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/size.cpp b/examples/dom/size.cpp index 3cb9da6d..d0e93010 100644 --- a/examples/dom/size.cpp +++ b/examples/dom/size.cpp @@ -10,7 +10,6 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off auto make_box = [](const std::wstring title) { return window( @@ -26,7 +25,7 @@ int main(int argc, const char* argv[]) { | size(WIDTH, EQUAL, x) ); } - // clang-format on + auto document = hbox(std::move(content)); auto screen = Screen::Create(Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/spinner.cpp b/examples/dom/spinner.cpp index 70c73db8..4a2333ac 100644 --- a/examples/dom/spinner.cpp +++ b/examples/dom/spinner.cpp @@ -20,17 +20,17 @@ int main(int argc, const char* argv[]) { for (int i = 0; i < 22; ++i) { if (i != 0) entries.push_back(separator()); - // clang-format off - entries.push_back( - hbox( - text(to_wstring(i)) | size(WIDTH, EQUAL, 2), - separator(), - spinner(i, index) | bold - ) - ); - // clang-format on + entries.push_back( // + hbox({ + text(to_wstring(i)) | size(WIDTH, EQUAL, 2), + separator(), + spinner(i, index) | bold, + })); } - auto document = hbox(vbox(std::move(entries)) | border, filler()); + auto document = hbox({ + vbox(std::move(entries)) | border, + filler(), + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); std::cout << reset_position << screen.ToString() << std::flush; diff --git a/examples/dom/style_blink.cpp b/examples/dom/style_blink.cpp index 5db769ad..e2b6bbcb 100644 --- a/examples/dom/style_blink.cpp +++ b/examples/dom/style_blink.cpp @@ -9,14 +9,12 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - hbox( - text(L"This text is "), - text(L"blink") | blink, - text(L". Do you like it?") - ); - // clang-format on + auto document = // + hbox({ + text(L"This text is "), + text(L"blink") | blink, + text(L". Do you like it?"), + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/style_bold.cpp b/examples/dom/style_bold.cpp index bc33097f..7fa3216e 100644 --- a/examples/dom/style_bold.cpp +++ b/examples/dom/style_bold.cpp @@ -9,14 +9,12 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - hbox( - text(L"This text is "), - text(L"bold") | bold, - text(L". Do you like it?") - ); - // clang-format on + auto document = // + hbox({ + text(L"This text is "), + text(L"bold") | bold, + text(L". Do you like it?"), + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/style_dim.cpp b/examples/dom/style_dim.cpp index 38e88a06..e95d8762 100644 --- a/examples/dom/style_dim.cpp +++ b/examples/dom/style_dim.cpp @@ -9,14 +9,12 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - hbox( - text(L"This text is "), - text(L"dim") | dim, - text(L". Do you like it?") - ); - // clang-format on + auto document = // + hbox({ + text(L"This text is "), + text(L"dim") | dim, + text(L". Do you like it?"), + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/style_gallery.cpp b/examples/dom/style_gallery.cpp index c67a7fe4..ff858e9a 100644 --- a/examples/dom/style_gallery.cpp +++ b/examples/dom/style_gallery.cpp @@ -11,7 +11,7 @@ int main(int argc, const char* argv[]) { using namespace ftxui; // clang-format off auto document = - hbox( + hbox({ text(L"normal") , text(L" ") , text(L"bold") | bold , text(L" ") , text(L"dim") | dim , text(L" ") , @@ -19,8 +19,8 @@ int main(int argc, const char* argv[]) { text(L"underlined")| underlined , text(L" ") , text(L"blink") | blink , text(L" ") , text(L"color") | color(Color::Blue) , text(L" ") , - text(L"bgcolor") | bgcolor(Color::Blue) - ); + text(L"bgcolor") | bgcolor(Color::Blue), + }); // clang-format on auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/style_inverted.cpp b/examples/dom/style_inverted.cpp index 1395100b..bf9a7bee 100644 --- a/examples/dom/style_inverted.cpp +++ b/examples/dom/style_inverted.cpp @@ -9,14 +9,11 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - hbox( + auto document = hbox({ text(L"This text is "), text(L"inverted") | inverted, - text(L". Do you like it?") - ); - // clang-format on + text(L". Do you like it?"), + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/style_underlined.cpp b/examples/dom/style_underlined.cpp index 0f018410..7335409e 100644 --- a/examples/dom/style_underlined.cpp +++ b/examples/dom/style_underlined.cpp @@ -9,14 +9,12 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - hbox( - text(L"This text is "), - text(L"underlined") | underlined, - text(L". Do you like it?") - ); - // clang-format on + auto document = // + hbox({ + text(L"This text is "), + text(L"underlined") | underlined, + text(L". Do you like it?"), + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); Render(screen, document.get()); diff --git a/examples/dom/vbox_hbox.cpp b/examples/dom/vbox_hbox.cpp index 45adfc5c..265b270b 100644 --- a/examples/dom/vbox_hbox.cpp +++ b/examples/dom/vbox_hbox.cpp @@ -9,34 +9,31 @@ int main(int argc, const char* argv[]) { using namespace ftxui; - // clang-format off - auto document = - vbox( - hbox( - text(L"north-west"), - filler(), - text(L"north-east") - ), - filler(), - hbox( - hbox( + auto document = // + vbox({ + hbox({ + text(L"north-west"), + filler(), + text(L"north-east"), + }), filler(), - text(L"center"), - filler() - ) - ), - filler(), - hbox( - text(L"south-west"), - filler(), - text(L"south-east") - ) - ); - // clang-format on + hbox({ + filler(), + text(L"center"), + filler(), + }), + filler(), + hbox({ + text(L"south-west"), + filler(), + text(L"south-east"), + }), + }); auto screen = Screen::Create(Dimension::Full()); Render(screen, document.get()); std::cout << screen.ToString(); + getchar(); return 0; } diff --git a/include/ftxui/dom/elements.hpp b/include/ftxui/dom/elements.hpp index 82d534cb..ca2c6639 100644 --- a/include/ftxui/dom/elements.hpp +++ b/include/ftxui/dom/elements.hpp @@ -6,20 +6,22 @@ #define FTXUI_DOM_ELEMENTS_HPP #include +#include #include "ftxui/dom/node.hpp" #include "ftxui/screen/color.hpp" +#include "ftxui/screen/screen.hpp" namespace ftxui { - -using Element = std::unique_ptr; +class Node; +using Element = std::shared_ptr; using Elements = std::vector; using Decorator = std::function; using GraphFunction = std::function(int, int)>; // --- Widget --- Element text(std::wstring text); -Element separator(); +Element separator(void); Element separator(Pixel); Element gauge(float ratio); Element border(Element); diff --git a/include/ftxui/dom/node.hpp b/include/ftxui/dom/node.hpp index 2b8e34d0..4cd55771 100644 --- a/include/ftxui/dom/node.hpp +++ b/include/ftxui/dom/node.hpp @@ -14,10 +14,13 @@ namespace ftxui { +using Element = std::shared_ptr; +using Elements = std::vector>; + class Node { public: Node(); - Node(std::vector> children); + Node(Elements children); virtual ~Node(); // Step 1: Compute layout requirement. Tell parent what dimensions this @@ -33,7 +36,7 @@ class Node { // Step 3: Draw this element. virtual void Render(Screen& screen); - std::vector> children; + std::vector children; protected: Requirement requirement_; diff --git a/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp index a5cacef6..50a88a6d 100644 --- a/include/ftxui/screen/screen.hpp +++ b/include/ftxui/screen/screen.hpp @@ -31,7 +31,7 @@ struct Pixel { struct Dimension { static Dimension Fixed(int); - static Dimension Fit(std::unique_ptr&); + static Dimension Fit(std::shared_ptr&); static Dimension Full(); int dimx; diff --git a/src/ftxui/dom/blink.cpp b/src/ftxui/dom/blink.cpp index 4fa58e6a..dd21e87a 100644 --- a/src/ftxui/dom/blink.cpp +++ b/src/ftxui/dom/blink.cpp @@ -22,8 +22,8 @@ class Blink : public NodeDecorator { } }; -std::unique_ptr blink(Element child) { - return std::make_unique(unpack(std::move(child))); +Element blink(Element child) { + return std::make_shared(unpack(std::move(child))); } } // namespace ftxui diff --git a/src/ftxui/dom/bold.cpp b/src/ftxui/dom/bold.cpp index ae40c4e0..4b25e332 100644 --- a/src/ftxui/dom/bold.cpp +++ b/src/ftxui/dom/bold.cpp @@ -22,8 +22,8 @@ class Bold : public NodeDecorator { } }; -std::unique_ptr bold(Element child) { - return std::make_unique(unpack(std::move(child))); +Element bold(Element child) { + return std::make_shared(unpack(std::move(child))); } } // namespace ftxui diff --git a/src/ftxui/dom/border.cpp b/src/ftxui/dom/border.cpp index 2ce26306..173da770 100644 --- a/src/ftxui/dom/border.cpp +++ b/src/ftxui/dom/border.cpp @@ -105,17 +105,17 @@ class Border : public Node { } }; -std::unique_ptr border(Element child) { - return std::make_unique(unpack(std::move(child))); +Element border(Element child) { + return std::make_shared(unpack(std::move(child))); } -std::unique_ptr window(Element title, Element content) { - return std::make_unique(unpack(std::move(content), std::move(title))); +Element window(Element title, Element content) { + return std::make_shared(unpack(std::move(content), std::move(title))); } Decorator borderWith(Pixel pixel) { return [pixel](Element child) { - return std::make_unique(unpack(std::move(child)), pixel); + return std::make_shared(unpack(std::move(child)), pixel); }; } diff --git a/src/ftxui/dom/color.cpp b/src/ftxui/dom/color.cpp index dc2ced28..9800505d 100644 --- a/src/ftxui/dom/color.cpp +++ b/src/ftxui/dom/color.cpp @@ -42,12 +42,12 @@ class FgColor : public NodeDecorator { Color color_; }; -std::unique_ptr color(Color c, Element child) { - return std::make_unique(unpack(std::move(child)), c); +Element color(Color c, Element child) { + return std::make_shared(unpack(std::move(child)), c); } -std::unique_ptr bgcolor(Color c, Element child) { - return std::make_unique(unpack(std::move(child)), c); +Element bgcolor(Color c, Element child) { + return std::make_shared(unpack(std::move(child)), c); } Decorator color(Color c) { diff --git a/src/ftxui/dom/composite_decorator.cpp b/src/ftxui/dom/composite_decorator.cpp index 5479fcee..3088bb59 100644 --- a/src/ftxui/dom/composite_decorator.cpp +++ b/src/ftxui/dom/composite_decorator.cpp @@ -7,19 +7,19 @@ namespace ftxui { -std::unique_ptr hcenter(Element child) { +Element hcenter(Element child) { return hbox(filler(), std::move(child), filler()); } -std::unique_ptr vcenter(Element child) { +Element vcenter(Element child) { return vbox(filler(), std::move(child), filler()); } -std::unique_ptr center(Element child) { +Element center(Element child) { return hcenter(vcenter(std::move(child))); } -std::unique_ptr align_right(Element child) { +Element align_right(Element child) { return hbox(filler(), std::move(child)); } diff --git a/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp index abd7847a..8dfda725 100644 --- a/src/ftxui/dom/dbox.cpp +++ b/src/ftxui/dom/dbox.cpp @@ -41,8 +41,8 @@ class DBox : public Node { } }; -std::unique_ptr dbox(Elements children) { - return std::make_unique(std::move(children)); +Element dbox(Elements children) { + return std::make_shared(std::move(children)); } } // namespace ftxui diff --git a/src/ftxui/dom/dim.cpp b/src/ftxui/dom/dim.cpp index ce1c51be..2e7e51b2 100644 --- a/src/ftxui/dom/dim.cpp +++ b/src/ftxui/dom/dim.cpp @@ -24,8 +24,8 @@ class Dim : public NodeDecorator { } }; -std::unique_ptr dim(Element child) { - return std::make_unique(unpack(std::move(child))); +Element dim(Element child) { + return std::make_shared(unpack(std::move(child))); } } // namespace ftxui diff --git a/src/ftxui/dom/flex.cpp b/src/ftxui/dom/flex.cpp index b6bd879f..22910b00 100644 --- a/src/ftxui/dom/flex.cpp +++ b/src/ftxui/dom/flex.cpp @@ -47,16 +47,16 @@ class NotFlex : public Flex { } }; -std::unique_ptr filler() { - return std::make_unique(); +Element filler() { + return std::make_shared(); } -std::unique_ptr flex(Element child) { - return std::make_unique(std::move(child)); +Element flex(Element child) { + return std::make_shared(std::move(child)); } -std::unique_ptr notflex(Element child) { - return std::make_unique(std::move(child)); +Element notflex(Element child) { + return std::make_shared(std::move(child)); } } // namespace ftxui diff --git a/src/ftxui/dom/frame.cpp b/src/ftxui/dom/frame.cpp index 5ea53ab9..36233035 100644 --- a/src/ftxui/dom/frame.cpp +++ b/src/ftxui/dom/frame.cpp @@ -14,7 +14,7 @@ namespace ftxui { class Select : public Node { public: - Select(std::vector> children) + Select(std::vector> children) : Node(std::move(children)) {} void ComputeRequirement() override { @@ -34,15 +34,15 @@ class Select : public Node { } }; -std::unique_ptr select(Element child) { - return std::make_unique(unpack(std::move(child))); } // ----------------------------------------------------------------------------- class Focus : public Select { public: - Focus(std::vector> children) + Focus(std::vector children) : Select(std::move(children)) {} void ComputeRequirement() override { @@ -56,15 +56,15 @@ class Focus : public Select { } }; -std::unique_ptr focus(Element child) { - return std::make_unique(unpack(std::move(child))); +Element focus(Element child) { + return std::make_shared(unpack(std::move(child))); } // ----------------------------------------------------------------------------- class Frame : public Node { public: - Frame(std::vector> children) + Frame(std::vector children) : Node(std::move(children)) {} void ComputeRequirement() override { @@ -123,8 +123,8 @@ class Frame : public Node { } }; -std::unique_ptr frame(Element child) { - return std::make_unique(unpack(std::move(child))); +Element frame(Element child) { + return std::make_shared(unpack(std::move(child))); } } // namespace ftxui diff --git a/src/ftxui/dom/gauge.cpp b/src/ftxui/dom/gauge.cpp index 494c2271..b16edf24 100644 --- a/src/ftxui/dom/gauge.cpp +++ b/src/ftxui/dom/gauge.cpp @@ -35,8 +35,8 @@ class Gauge : public Node { float progress_; }; -std::unique_ptr gauge(float progress) { - return std::make_unique(progress); +Element gauge(float progress) { + return std::make_shared(progress); } } // namespace ftxui diff --git a/src/ftxui/dom/graph.cpp b/src/ftxui/dom/graph.cpp index e466ac80..b8035e61 100644 --- a/src/ftxui/dom/graph.cpp +++ b/src/ftxui/dom/graph.cpp @@ -42,8 +42,8 @@ class Graph : public Node { GraphFunction graph_function_; }; -std::unique_ptr graph(GraphFunction graph_function) { - return std::make_unique(graph_function); +Element graph(GraphFunction graph_function) { + return std::make_shared(graph_function); } } // namespace ftxui diff --git a/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp index 1065b2ea..6004e8a0 100644 --- a/src/ftxui/dom/hbox.cpp +++ b/src/ftxui/dom/hbox.cpp @@ -68,8 +68,8 @@ class HBox : public Node { } }; -std::unique_ptr hbox(Elements children) { - return std::make_unique(std::move(children)); +Element hbox(Elements children) { + return std::make_shared(std::move(children)); } } // namespace ftxui diff --git a/src/ftxui/dom/hflow.cpp b/src/ftxui/dom/hflow.cpp index 7bb068c8..94987efd 100644 --- a/src/ftxui/dom/hflow.cpp +++ b/src/ftxui/dom/hflow.cpp @@ -58,8 +58,8 @@ class HFlow : public Node { } }; -std::unique_ptr hflow(Elements children) { - return std::make_unique(std::move(children)); +Element hflow(Elements children) { + return std::make_shared(std::move(children)); } } // namespace ftxui diff --git a/src/ftxui/dom/inverted.cpp b/src/ftxui/dom/inverted.cpp index f3149d58..76badb82 100644 --- a/src/ftxui/dom/inverted.cpp +++ b/src/ftxui/dom/inverted.cpp @@ -24,8 +24,8 @@ class Inverted : public NodeDecorator { } }; -std::unique_ptr inverted(Element child) { - return std::make_unique(unpack(std::move(child))); +Element inverted(Element child) { + return std::make_shared(unpack(std::move(child))); } } // namespace ftxui diff --git a/src/ftxui/dom/node.cpp b/src/ftxui/dom/node.cpp index c9da8647..984ec873 100644 --- a/src/ftxui/dom/node.cpp +++ b/src/ftxui/dom/node.cpp @@ -9,8 +9,7 @@ namespace ftxui { using ftxui::Screen; Node::Node() {} -Node::Node(std::vector> children) - : children(std::move(children)) {} +Node::Node(Elements children) : children(std::move(children)) {} Node::~Node() {} void Node::ComputeRequirement() { diff --git a/src/ftxui/dom/node_decorator.hpp b/src/ftxui/dom/node_decorator.hpp index 83679ac6..d26c5984 100644 --- a/src/ftxui/dom/node_decorator.hpp +++ b/src/ftxui/dom/node_decorator.hpp @@ -5,7 +5,6 @@ #ifndef FTXUI_DOM_NODE_DECORATOR_H_ #define FTXUI_DOM_NODE_DECORATOR_H_ -#include "ftxui/dom/elements.hpp" #include "ftxui/dom/node.hpp" namespace ftxui { diff --git a/src/ftxui/dom/separator.cpp b/src/ftxui/dom/separator.cpp index 5c9f48b1..cc9286ac 100644 --- a/src/ftxui/dom/separator.cpp +++ b/src/ftxui/dom/separator.cpp @@ -49,12 +49,12 @@ class SeparatorWithPixel : public Separator { Pixel p; }; -std::unique_ptr separator() { - return std::make_unique(); +Element separator() { + return std::make_shared(); } -std::unique_ptr separator(Pixel pixel) { - return std::make_unique(pixel); +Element separator(Pixel pixel) { + return std::make_shared(pixel); } } // namespace ftxui diff --git a/src/ftxui/dom/size.cpp b/src/ftxui/dom/size.cpp index b0af3123..d6fa7676 100644 --- a/src/ftxui/dom/size.cpp +++ b/src/ftxui/dom/size.cpp @@ -76,7 +76,7 @@ class Size : public Node { Decorator size(Direction direction, Constraint constraint, int value) { return [=](Element e) { - return std::make_unique(std::move(e), direction, constraint, value); + return std::make_shared(std::move(e), direction, constraint, value); }; } diff --git a/src/ftxui/dom/spinner.cpp b/src/ftxui/dom/spinner.cpp index d90577e3..c9b8c2af 100644 --- a/src/ftxui/dom/spinner.cpp +++ b/src/ftxui/dom/spinner.cpp @@ -245,7 +245,7 @@ static const std::vector>> elements = { L" LOLLOL ", }}}; -std::unique_ptr spinner(int c, size_t index) { +Element spinner(int c, size_t index) { if (c == 0) { index %= 40; if (index > 20) diff --git a/src/ftxui/dom/text.cpp b/src/ftxui/dom/text.cpp index 7b797d12..ba810102 100644 --- a/src/ftxui/dom/text.cpp +++ b/src/ftxui/dom/text.cpp @@ -36,8 +36,8 @@ class Text : public Node { std::wstring text_; }; -std::unique_ptr text(std::wstring text) { - return std::make_unique(text); +Element text(std::wstring text) { + return std::make_shared(text); } } // namespace ftxui diff --git a/src/ftxui/dom/underlined.cpp b/src/ftxui/dom/underlined.cpp index edded6a1..6b5835f2 100644 --- a/src/ftxui/dom/underlined.cpp +++ b/src/ftxui/dom/underlined.cpp @@ -24,8 +24,8 @@ class Underlined : public NodeDecorator { } }; -std::unique_ptr underlined(Element child) { - return std::make_unique(unpack(std::move(child))); +Element underlined(Element child) { + return std::make_shared(unpack(std::move(child))); } } // namespace ftxui diff --git a/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp index 411ab46a..a7ec7ef2 100644 --- a/src/ftxui/dom/vbox.cpp +++ b/src/ftxui/dom/vbox.cpp @@ -69,8 +69,8 @@ class VBox : public Node { } }; -std::unique_ptr vbox(Elements children) { - return std::make_unique(std::move(children)); +Element vbox(Elements children) { + return std::make_shared(std::move(children)); } } // namespace ftxui diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index 17450226..a3105246 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -52,7 +52,7 @@ Dimension Dimension::Fixed(int v) { return Dimension{v, v}; } -Dimension Dimension::Fit(std::unique_ptr& e) { +Dimension Dimension::Fit(std::shared_ptr& e) { e->ComputeRequirement(); Terminal::Dimensions size = Terminal::Size(); return Dimension{std::min(e->requirement().min.x, size.dimx), diff --git a/tutorial/build-with-cmake.md b/tutorial/build-with-cmake.md index 91cf753a..5c83fa72 100644 --- a/tutorial/build-with-cmake.md +++ b/tutorial/build-with-cmake.md @@ -18,13 +18,13 @@ main.cpp int main(int argc, const char *argv[]) { using namespace ftxui; auto document = - hbox( + hbox({ text(L"left") | bold | border, text(L"middle") | flex | border, - text(L"right") | border - ); + text(L"right") | border, + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); - Render(screen, document.get()); + Render(screen, document); std::cout << screen.ToString(); diff --git a/tutorial/build-with-nxxm.md b/tutorial/build-with-nxxm.md index 47c07ea4..bfa06ff8 100644 --- a/tutorial/build-with-nxxm.md +++ b/tutorial/build-with-nxxm.md @@ -18,13 +18,13 @@ main.cpp int main(int argc, const char *argv[]) { using namespace ftxui; auto document = - hbox( + hbox({ text(L"left") | bold | border, text(L"middle") | flex | border, - text(L"right") | border - ); + text(L"right") | border, + }); auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); - Render(screen, document.get()); + Render(screen, document); std::cout << screen.ToString(); diff --git a/tutorial/tutorial.md b/tutorial/tutorial.md index 64629f68..f8e44473 100644 --- a/tutorial/tutorial.md +++ b/tutorial/tutorial.md @@ -132,17 +132,19 @@ Display a vertical or horizontal line to visually split the content of a container in two. ~~~cpp -border(hbox( - vbox( - text(L"left top"), - text(L"left bottom") - ), - separator(), - vbox( - text(L"right top"), - text(L"right bottom") - ) -)); +border( + hbox({ + vbox({ + text(L"left top"), + text(L"left bottom"), + }), + separator(), + vbox({ + text(L"right top"), + text(L"right bottom"), + }), + }) +); ~~~ ~~~bash @@ -213,11 +215,11 @@ An horizontal flow layout is implemented by: #### Examples ~~~cpp - hbox( + hbox({ text(L"left") | border , text(L"middle") | border | flex, - text(L"right") | border - ); + text(L"right") | border, + }); ~~~ ~~~bash ┌────┐┌─────────────────────────────────────────────────────────────────┐┌─────┐ @@ -226,11 +228,11 @@ An horizontal flow layout is implemented by: ~~~ ~~~cpp - hbox( + hbox({ text(L"left") | border , text(L"middle") | border | flex, - text(L"right") | border | flex - ); + text(L"right") | border | flex, + }); ~~~ ~~~bash ┌────┐┌───────────────────────────────────┐┌───────────────────────────────────┐