From 925a7578d4fdff7f65fc7b29da38378ad0a5ad60 Mon Sep 17 00:00:00 2001 From: Arthur Sonzogni Date: Sun, 12 Jun 2022 17:08:22 +0200 Subject: [PATCH] Feature: the `Modal` component. (#418) --- CHANGELOG.md | 3 + CMakeLists.txt | 1 + cmake/ftxui_test.cmake | 1 + examples/component/CMakeLists.txt | 1 + examples/component/modal_dialog.cpp | 147 ++++++++---------- examples/component/modal_dialog_custom.cpp | 94 +++++++++++ include/ftxui/component/component.hpp | 9 +- src/ftxui/component/animation.cpp | 2 +- src/ftxui/component/component_options.cpp | 1 + src/ftxui/component/maybe.cpp | 6 +- src/ftxui/component/modal.cpp | 66 ++++++++ src/ftxui/component/modal_test.cpp | 47 ++++++ src/ftxui/component/screen_interactive.cpp | 8 +- .../component/screen_interactive_test.cpp | 1 + src/ftxui/component/terminal_input_parser.cpp | 8 +- .../component/terminal_input_parser_test.cpp | 10 +- src/ftxui/dom/blink_test.cpp | 4 +- src/ftxui/dom/bold_test.cpp | 4 +- src/ftxui/dom/canvas.cpp | 15 +- src/ftxui/dom/dim_test.cpp | 4 +- src/ftxui/dom/flexbox_helper.cpp | 9 +- src/ftxui/dom/flexbox_helper_test.cpp | 3 +- src/ftxui/dom/flexbox_test.cpp | 26 ++-- src/ftxui/dom/gridbox.cpp | 2 +- src/ftxui/dom/gridbox_test.cpp | 5 +- src/ftxui/dom/node.cpp | 3 +- src/ftxui/dom/node_decorator.cpp | 5 +- src/ftxui/dom/underlined_test.cpp | 4 +- 28 files changed, 354 insertions(+), 135 deletions(-) create mode 100644 examples/component/modal_dialog_custom.cpp create mode 100644 src/ftxui/component/modal.cpp create mode 100644 src/ftxui/component/modal_test.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f2bbf5..c4ce571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ current (development) - Bugfix: Forward the selected/focused area from the child in gridbox. - Bugfix: Fix incorrect Canvas computed dimensions. +### Component: +- Feature: Add the `Modal` component. + ### Screen - Feature: add `Box::Union(a,b) -> Box` diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d2d1c3..b48bdec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,7 @@ add_library(component src/ftxui/component/event.cpp src/ftxui/component/input.cpp src/ftxui/component/maybe.cpp + src/ftxui/component/modal.cpp src/ftxui/component/menu.cpp src/ftxui/component/radiobox.cpp src/ftxui/component/radiobox.cpp diff --git a/cmake/ftxui_test.cmake b/cmake/ftxui_test.cmake index b2fb59a..7f4e237 100644 --- a/cmake/ftxui_test.cmake +++ b/cmake/ftxui_test.cmake @@ -31,6 +31,7 @@ add_executable(tests src/ftxui/component/container_test.cpp src/ftxui/component/input_test.cpp src/ftxui/component/menu_test.cpp + src/ftxui/component/modal_test.cpp src/ftxui/component/radiobox_test.cpp src/ftxui/component/receiver_test.cpp src/ftxui/component/resizable_split_test.cpp diff --git a/examples/component/CMakeLists.txt b/examples/component/CMakeLists.txt index f030781..3a5ef70 100644 --- a/examples/component/CMakeLists.txt +++ b/examples/component/CMakeLists.txt @@ -25,6 +25,7 @@ example(menu_multiple) example(menu_style) example(menu_underline_animated_gallery) example(modal_dialog) +example(modal_dialog_custom) example(nested_screen) example(print_key_press) example(radiobox) diff --git a/examples/component/modal_dialog.cpp b/examples/component/modal_dialog.cpp index 8095274..aa58b41 100644 --- a/examples/component/modal_dialog.cpp +++ b/examples/component/modal_dialog.cpp @@ -1,94 +1,83 @@ -#include // for allocator, shared_ptr, __shared_ptr_access -#include // for string, basic_string, char_traits, operator+ -#include // for vector +#include // for ButtonOption +#include // for function +#include // for allocator, shared_ptr #include "ftxui/component/captured_mouse.hpp" // for ftxui -#include "ftxui/component/component.hpp" // for Button, Renderer, Horizontal, Tab -#include "ftxui/component/component_base.hpp" // for ComponentBase -#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive -#include "ftxui/dom/elements.hpp" // for operator|, Element, filler, text, hbox, separator, center, vbox, bold, border, clear_under, dbox, size, GREATER_THAN, HEIGHT +#include "ftxui/component/component.hpp" // for Button, operator|=, Renderer, Vertical, Modal +#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive, Component +#include "ftxui/dom/elements.hpp" // for operator|, separator, text, size, Element, vbox, border, GREATER_THAN, WIDTH, center, HEIGHT + +using namespace ftxui; + +auto button_style = ButtonOption::Animated(); + +// Definition of the main component. The details are not important. +Component MainComponent(std::function show_modal, + std::function exit) { + auto component = Container::Vertical({ + Button("Show modal", show_modal, button_style), + Button("Quit", exit, button_style), + }); + // Polish how the two buttons are rendered: + component |= Renderer([&](Element inner) { + return vbox({ + text("Main component"), + separator(), + inner, + }) // + | size(WIDTH, GREATER_THAN, 15) // + | size(HEIGHT, GREATER_THAN, 15) // + | border // + | center; // + }); + return component; +} + +// Definition of the modal component. The details are not important. +Component ModalComponent(std::function do_nothing, + std::function hide_modal) { + auto component = Container::Vertical({ + Button("Do nothing", do_nothing, button_style), + Button("Quit modal", hide_modal, button_style), + }); + // Polish how the two buttons are rendered: + component |= Renderer([&](Element inner) { + return vbox({ + text("Modal component "), + separator(), + inner, + }) // + | size(WIDTH, GREATER_THAN, 30) // + | border; // + }); + return component; +} int main(int argc, const char* argv[]) { - using namespace ftxui; auto screen = ScreenInteractive::TerminalOutput(); - // There are two layers. One at depth = 0 and the modal window at depth = 1; - int depth = 0; + // State of the application: + bool modal_shown = false; - // The current rating of FTXUI. - std::string rating = "3/5 stars"; + // Some actions modifying the state: + auto show_modal = [&] { modal_shown = true; }; + auto hide_modal = [&] { modal_shown = false; }; + auto exit = screen.ExitLoopClosure(); + auto do_nothing = [&] {}; - // At depth=0, two buttons. One for rating FTXUI and one for quitting. - auto button_rate_ftxui = Button("Rate FTXUI", [&] { depth = 1; }); - auto button_quit = Button("Quit", screen.ExitLoopClosure()); + // Instanciate the main and modal components: + auto main_component = MainComponent(show_modal, exit); + auto modal_component = ModalComponent(do_nothing, hide_modal); - auto depth_0_container = Container::Horizontal({ - button_rate_ftxui, - button_quit, - }); - auto depth_0_renderer = Renderer(depth_0_container, [&] { - return vbox({ - text("Modal dialog example"), - separator(), - text("☆☆☆ FTXUI:" + rating + " ☆☆☆") | bold, - filler(), - hbox({ - button_rate_ftxui->Render(), - filler(), - button_quit->Render(), - }), - }) | - border | size(HEIGHT, GREATER_THAN, 18) | center; - }); + // Use the `Modal` function to use together the main component and its modal + // window. The |modal_shown| boolean controls whether the modal is shown or + // not. + main_component |= Modal(modal_component, &modal_shown); - // At depth=1, The "modal" window. - std::vector rating_labels = { - "1/5 stars", "2/5 stars", "3/5 stars", "4/5 stars", "5/5 stars", - }; - auto on_rating = [&](std::string new_rating) { - rating = new_rating; - depth = 0; - }; - auto depth_1_container = Container::Horizontal({ - Button(&rating_labels[0], [&] { on_rating(rating_labels[0]); }), - Button(&rating_labels[1], [&] { on_rating(rating_labels[1]); }), - Button(&rating_labels[2], [&] { on_rating(rating_labels[2]); }), - Button(&rating_labels[3], [&] { on_rating(rating_labels[3]); }), - Button(&rating_labels[4], [&] { on_rating(rating_labels[4]); }), - }); - - auto depth_1_renderer = Renderer(depth_1_container, [&] { - return vbox({ - text("Do you like FTXUI?"), - separator(), - hbox(depth_1_container->Render()), - }) | - border; - }); - - auto main_container = Container::Tab( - { - depth_0_renderer, - depth_1_renderer, - }, - &depth); - - auto main_renderer = Renderer(main_container, [&] { - Element document = depth_0_renderer->Render(); - - if (depth == 1) { - document = dbox({ - document, - depth_1_renderer->Render() | clear_under | center, - }); - } - return document; - }); - - screen.Loop(main_renderer); + screen.Loop(main_component); return 0; } -// Copyright 2020 Arthur Sonzogni. All rights reserved. +// Copyright 2022 Arthur Sonzogni. All rights reserved. // Use of this source code is governed by the MIT license that can be found in // the LICENSE file. diff --git a/examples/component/modal_dialog_custom.cpp b/examples/component/modal_dialog_custom.cpp new file mode 100644 index 0000000..8095274 --- /dev/null +++ b/examples/component/modal_dialog_custom.cpp @@ -0,0 +1,94 @@ +#include // for allocator, shared_ptr, __shared_ptr_access +#include // for string, basic_string, char_traits, operator+ +#include // for vector + +#include "ftxui/component/captured_mouse.hpp" // for ftxui +#include "ftxui/component/component.hpp" // for Button, Renderer, Horizontal, Tab +#include "ftxui/component/component_base.hpp" // for ComponentBase +#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive +#include "ftxui/dom/elements.hpp" // for operator|, Element, filler, text, hbox, separator, center, vbox, bold, border, clear_under, dbox, size, GREATER_THAN, HEIGHT + +int main(int argc, const char* argv[]) { + using namespace ftxui; + auto screen = ScreenInteractive::TerminalOutput(); + + // There are two layers. One at depth = 0 and the modal window at depth = 1; + int depth = 0; + + // The current rating of FTXUI. + std::string rating = "3/5 stars"; + + // At depth=0, two buttons. One for rating FTXUI and one for quitting. + auto button_rate_ftxui = Button("Rate FTXUI", [&] { depth = 1; }); + auto button_quit = Button("Quit", screen.ExitLoopClosure()); + + auto depth_0_container = Container::Horizontal({ + button_rate_ftxui, + button_quit, + }); + auto depth_0_renderer = Renderer(depth_0_container, [&] { + return vbox({ + text("Modal dialog example"), + separator(), + text("☆☆☆ FTXUI:" + rating + " ☆☆☆") | bold, + filler(), + hbox({ + button_rate_ftxui->Render(), + filler(), + button_quit->Render(), + }), + }) | + border | size(HEIGHT, GREATER_THAN, 18) | center; + }); + + // At depth=1, The "modal" window. + std::vector rating_labels = { + "1/5 stars", "2/5 stars", "3/5 stars", "4/5 stars", "5/5 stars", + }; + auto on_rating = [&](std::string new_rating) { + rating = new_rating; + depth = 0; + }; + auto depth_1_container = Container::Horizontal({ + Button(&rating_labels[0], [&] { on_rating(rating_labels[0]); }), + Button(&rating_labels[1], [&] { on_rating(rating_labels[1]); }), + Button(&rating_labels[2], [&] { on_rating(rating_labels[2]); }), + Button(&rating_labels[3], [&] { on_rating(rating_labels[3]); }), + Button(&rating_labels[4], [&] { on_rating(rating_labels[4]); }), + }); + + auto depth_1_renderer = Renderer(depth_1_container, [&] { + return vbox({ + text("Do you like FTXUI?"), + separator(), + hbox(depth_1_container->Render()), + }) | + border; + }); + + auto main_container = Container::Tab( + { + depth_0_renderer, + depth_1_renderer, + }, + &depth); + + auto main_renderer = Renderer(main_container, [&] { + Element document = depth_0_renderer->Render(); + + if (depth == 1) { + document = dbox({ + document, + depth_1_renderer->Render() | clear_under | center, + }); + } + return document; + }); + + screen.Loop(main_renderer); + 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. diff --git a/include/ftxui/component/component.hpp b/include/ftxui/component/component.hpp index 5f81ace..6e04cb0 100644 --- a/include/ftxui/component/component.hpp +++ b/include/ftxui/component/component.hpp @@ -7,9 +7,9 @@ #include // for forward #include // for vector -#include "ftxui/component/component_base.hpp" // for Component, Components -#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, InputOption (ptr only), MenuEntryOption (ptr only), MenuOption, RadioboxOption (ptr only) -#include "ftxui/dom/elements.hpp" // for Element +#include "ftxui/component/component_base.hpp" // for Component, Components +#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption +#include "ftxui/dom/elements.hpp" // for Element #include "ftxui/util/ref.hpp" // for Ref, ConstStringRef, ConstStringListRef, StringRef namespace ftxui { @@ -88,6 +88,9 @@ Component Maybe(Component, std::function); ComponentDecorator Maybe(const bool* show); ComponentDecorator Maybe(std::function); +Component Modal(Component main, Component modal, const bool* show_modal); +ComponentDecorator Modal(Component modal, const bool* show_modal); + Component Collapsible(ConstStringRef label, Component child, Ref show = false); diff --git a/src/ftxui/component/animation.cpp b/src/ftxui/component/animation.cpp index ce8b415..bba5783 100644 --- a/src/ftxui/component/animation.cpp +++ b/src/ftxui/component/animation.cpp @@ -1,4 +1,4 @@ -#include +#include // IWYU pragma: keep #include // for ratio #include // for move diff --git a/src/ftxui/component/component_options.cpp b/src/ftxui/component/component_options.cpp index 508ebdf..5e29d4b 100644 --- a/src/ftxui/component/component_options.cpp +++ b/src/ftxui/component/component_options.cpp @@ -1,5 +1,6 @@ #include "ftxui/component/component_options.hpp" +#include // for Color, Color::Black, Color::White, Color::GrayDark, Color::GrayLight #include // for shared_ptr #include // for move diff --git a/src/ftxui/component/maybe.cpp b/src/ftxui/component/maybe.cpp index f85c25d..ac7dc6e 100644 --- a/src/ftxui/component/maybe.cpp +++ b/src/ftxui/component/maybe.cpp @@ -43,7 +43,7 @@ Component Maybe(Component child, std::function show) { /// ### Example /// /// ```cpp -/// auto component = Renderer([]{ return "Hello World!"; }); +/// auto component = Renderer([]{ return text("Hello World!"); }); /// auto maybe_component = component | Maybe([&]{ return counter == 42; }); /// ``` ComponentDecorator Maybe(std::function show) { @@ -60,7 +60,7 @@ ComponentDecorator Maybe(std::function show) { /// ### Example /// /// ```cpp -/// auto component = Renderer([]{ return "Hello World!"; }); +/// auto component = Renderer([]{ return text("Hello World!"); }); /// auto maybe_component = Maybe(component, &show); /// ``` Component Maybe(Component child, const bool* show) { @@ -74,7 +74,7 @@ Component Maybe(Component child, const bool* show) { /// ### Example /// /// ```cpp -/// auto component = Renderer([]{ return "Hello World!"; }); +/// auto component = Renderer([]{ return text("Hello World!"); }); /// auto maybe_component = component | Maybe(&show); /// ``` ComponentDecorator Maybe(const bool* show) { diff --git a/src/ftxui/component/modal.cpp b/src/ftxui/component/modal.cpp new file mode 100644 index 0000000..509a6bd --- /dev/null +++ b/src/ftxui/component/modal.cpp @@ -0,0 +1,66 @@ +#include // for Event +#include // for operator|, Element, center, clear_under, dbox +#include // for __shared_ptr_access, shared_ptr +#include // for move + +#include "ftxui/component/component.hpp" // for Make, Tab, ComponentDecorator, Modal +#include "ftxui/component/component_base.hpp" // for Component, ComponentBase + +namespace ftxui { + +// Add a |modal| window on top of the |main| component. It is shown one on the +// top of the other when |show_modal| is true. +/// @ingroup component +// NOLINTNEXTLINE +Component Modal(Component main, Component modal, const bool* show_modal) { + class Impl : public ComponentBase { + public: + explicit Impl(Component main, Component modal, const bool* show_modal) + : main_(std::move(main)), + modal_(std::move(modal)), + show_modal_(show_modal) { + selector_ = *show_modal_; + Add(Container::Tab({main_, modal_}, &selector_)); + } + + private: + Element Render() override { + selector_ = *show_modal_; + auto document = main_->Render(); + if (*show_modal_) { + document = dbox({ + document, + modal_->Render() | clear_under | center, + }); + } + return document; + } + + bool OnEvent(Event event) override { + selector_ = *show_modal_; + return ComponentBase::OnEvent(event); + } + + Component main_; + Component modal_; + const bool* show_modal_; + int selector_ = 0; + }; + return Make(main, modal, show_modal); +} + +// Decorate a component. Add a |modal| window on top of it. It is shown one on +// the top of the other when |show_modal| is true. +/// @ingroup component +// NOLINTNEXTLINE +ComponentDecorator Modal(Component modal, const bool* show_modal) { + return [modal, show_modal](Component main) { + return Modal(std::move(main), modal, show_modal); + }; +} + +} // namespace ftxui + +// Copyright 2022 Arthur Sonzogni. All rights reserved. +// Use of this source code is governed by the MIT license that can be found in +// the LICENSE file. diff --git a/src/ftxui/component/modal_test.cpp b/src/ftxui/component/modal_test.cpp new file mode 100644 index 0000000..92320bc --- /dev/null +++ b/src/ftxui/component/modal_test.cpp @@ -0,0 +1,47 @@ +#include // for Message +#include // for SuiteApiResolver, TestPartResult, TestFactoryImpl +#include // for Element, operator|, text, border +#include // for shared_ptr, allocator, __shared_ptr_access + +#include "ftxui/component/component.hpp" // for Renderer, Modal +#include "ftxui/component/component_base.hpp" // for ComponentBase +#include "ftxui/dom/node.hpp" // for Render +#include "ftxui/screen/screen.hpp" // for Screen +#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST + +namespace ftxui { + +TEST(ModalTest, Basic) { + auto main = Renderer([] { return text("main") | border; }); + auto modal = Renderer([] { return text("modal") | border; }); + bool show_modal = false; + auto component = Modal(main, modal, &show_modal); + + Screen screen(10, 7); + Render(screen, component->Render()); + EXPECT_EQ(screen.ToString(), + "╭────────╮\r\n" + "│main │\r\n" + "│ │\r\n" + "│ │\r\n" + "│ │\r\n" + "│ │\r\n" + "╰────────╯"); + + show_modal = true; + Render(screen, component->Render()); + EXPECT_EQ(screen.ToString(), + "╭────────╮\r\n" + "│main │\r\n" + "│╭─────╮ │\r\n" + "││modal│ │\r\n" + "│╰─────╯ │\r\n" + "│ │\r\n" + "╰────────╯"); +} + +} // namespace ftxui + +// Copyright 2022 Arthur Sonzogni. All rights reserved. +// Use of this source code is governed by the MIT license that can be found in +// the LICENSE file. diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 88609b2..a0353e3 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -3,8 +3,10 @@ #include // for operator-, milliseconds, duration, operator>=, time_point, common_type<>::type #include // for signal, raise, SIGTSTP, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, SIGWINCH #include // for fileno, size_t, stdin -#include // for function -#include // for initializer_list +#include // for Task, Closure, AnimationTask +#include // for Pixel, Screen::Cursor, Screen +#include // for function +#include // for initializer_list #include // for cout, ostream, basic_ostream, operator<<, endl, flush #include // for stack #include // for thread, sleep_for @@ -17,7 +19,7 @@ #include "ftxui/component/captured_mouse.hpp" // for CapturedMouse, CapturedMouseInterface #include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/event.hpp" // for Event -#include "ftxui/component/receiver.hpp" // for ReceiverImpl, Sender, MakeReceiver, SenderImpl, Receiver +#include "ftxui/component/receiver.hpp" // for Sender, ReceiverImpl, MakeReceiver, SenderImpl, Receiver #include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/terminal_input_parser.hpp" // for TerminalInputParser #include "ftxui/dom/node.hpp" // for Node, Render diff --git a/src/ftxui/component/screen_interactive_test.cpp b/src/ftxui/component/screen_interactive_test.cpp index 957e98b..63b1aee 100644 --- a/src/ftxui/component/screen_interactive_test.cpp +++ b/src/ftxui/component/screen_interactive_test.cpp @@ -1,6 +1,7 @@ #include // for Message #include // for SuiteApiResolver, TestFactoryImpl, TestPartResult #include // for raise, SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM +#include // for Event, Event::Custom #include "ftxui/component/component.hpp" // for Renderer #include "ftxui/component/screen_interactive.hpp" diff --git a/src/ftxui/component/terminal_input_parser.cpp b/src/ftxui/component/terminal_input_parser.cpp index 7d9f74b..0f0a036 100644 --- a/src/ftxui/component/terminal_input_parser.cpp +++ b/src/ftxui/component/terminal_input_parser.cpp @@ -1,8 +1,10 @@ #include "ftxui/component/terminal_input_parser.hpp" -#include // for uint32_t -#include // for unique_ptr -#include // for move +#include // for uint32_t +#include // for Mouse, Mouse::Button, Mouse::Motion +#include // for SenderImpl, Sender +#include // for unique_ptr, allocator +#include // for move #include "ftxui/component/event.hpp" // for Event #include "ftxui/component/task.hpp" // for Task diff --git a/src/ftxui/component/terminal_input_parser_test.cpp b/src/ftxui/component/terminal_input_parser_test.cpp index 0abb28d..679962c 100644 --- a/src/ftxui/component/terminal_input_parser_test.cpp +++ b/src/ftxui/component/terminal_input_parser_test.cpp @@ -1,11 +1,13 @@ #include // for Message #include // for TestPartResult, SuiteApiResolver, TestFactoryImpl #include // for max -#include // for initializer_list -#include // for unique_ptr, allocator -#include // for get +#include // for Mouse, Mouse::Left, Mouse::Middle, Mouse::Pressed, Mouse::Released, Mouse::Right +#include // for Task +#include // for initializer_list +#include // for allocator, unique_ptr +#include // for get -#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::ArrowLeft, Event::ArrowRight, Event::ArrowUp, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::Escape, Event::F10, Event::F11, Event::F12, Event::F5, Event::F6, Event::F7, Event::F8, Event::F9, Event::Home, Event::PageDown, Event::PageUp, Event::Tab, Event::TabReverse +#include "ftxui/component/event.hpp" // for Event, Event::Return, Event::ArrowDown, Event::ArrowLeft, Event::ArrowRight, Event::ArrowUp, Event::Backspace, Event::Custom, Event::Delete, Event::End, Event::F10, Event::F11, Event::F12, Event::F5, Event::F6, Event::F7, Event::F8, Event::F9, Event::Home, Event::PageDown, Event::PageUp, Event::Tab, Event::TabReverse, Event::Escape #include "ftxui/component/receiver.hpp" // for MakeReceiver, ReceiverImpl #include "ftxui/component/terminal_input_parser.hpp" #include "gtest/gtest_pred_impl.h" // for AssertionResult, Test, EXPECT_EQ, EXPECT_TRUE, TEST, EXPECT_FALSE diff --git a/src/ftxui/dom/blink_test.cpp b/src/ftxui/dom/blink_test.cpp index f6f8de6..8bbe423 100644 --- a/src/ftxui/dom/blink_test.cpp +++ b/src/ftxui/dom/blink_test.cpp @@ -1,11 +1,11 @@ #include // for Message #include // for SuiteApiResolver, TestFactoryImpl, TestPartResult -#include // for allocator +#include // for Test, AssertionResult, TestInfo (ptr only), EXPECT_TRUE, TEST +#include // for allocator #include "ftxui/dom/elements.hpp" // for operator|, text, blink, Element #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel -#include "gtest/gtest_pred_impl.h" // for Test, AssertionResult, EXPECT_TRUE, TEST namespace ftxui { diff --git a/src/ftxui/dom/bold_test.cpp b/src/ftxui/dom/bold_test.cpp index 83989c9..fac4431 100644 --- a/src/ftxui/dom/bold_test.cpp +++ b/src/ftxui/dom/bold_test.cpp @@ -1,11 +1,11 @@ #include // for Message #include // for SuiteApiResolver, TestFactoryImpl, TestPartResult -#include // for allocator +#include // for Test, AssertionResult, TestInfo (ptr only), EXPECT_TRUE, TEST +#include // for allocator #include "ftxui/dom/elements.hpp" // for operator|, text, bold, Element #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel -#include "gtest/gtest_pred_impl.h" // for Test, AssertionResult, EXPECT_TRUE, TEST namespace ftxui { diff --git a/src/ftxui/dom/canvas.cpp b/src/ftxui/dom/canvas.cpp index 5621f02..3179885 100644 --- a/src/ftxui/dom/canvas.cpp +++ b/src/ftxui/dom/canvas.cpp @@ -1,12 +1,13 @@ #include "ftxui/dom/canvas.hpp" -#include // for max, min -#include // for uint8_t -#include // for abs -#include // for allocator, map -#include // for make_shared -#include // for move, pair -#include // for vector +#include // for max, min +#include // for uint8_t +#include // for abs +#include // for Color +#include // for map +#include // for make_shared +#include // for move, pair +#include // for vector #include "ftxui/dom/elements.hpp" // for Element, canvas #include "ftxui/dom/node.hpp" // for Node diff --git a/src/ftxui/dom/dim_test.cpp b/src/ftxui/dom/dim_test.cpp index 75dadd6..312c1fe 100644 --- a/src/ftxui/dom/dim_test.cpp +++ b/src/ftxui/dom/dim_test.cpp @@ -1,11 +1,11 @@ #include // for Message #include // for SuiteApiResolver, TestFactoryImpl, TestPartResult -#include // for allocator +#include // for Test, AssertionResult, TestInfo (ptr only), EXPECT_TRUE, TEST +#include // for allocator #include "ftxui/dom/elements.hpp" // for operator|, text, dim, Element #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel -#include "gtest/gtest_pred_impl.h" // for Test, AssertionResult, EXPECT_TRUE, TEST namespace ftxui { diff --git a/src/ftxui/dom/flexbox_helper.cpp b/src/ftxui/dom/flexbox_helper.cpp index 56e19f6..db1daf4 100644 --- a/src/ftxui/dom/flexbox_helper.cpp +++ b/src/ftxui/dom/flexbox_helper.cpp @@ -1,9 +1,10 @@ #include "ftxui/dom/flexbox_helper.hpp" -#include // for min, max -#include // for size_t -#include // for allocator_traits<>::value_type -#include // for swap, move +#include // for max, min +#include // for size_t +#include // for FlexboxConfig, FlexboxConfig::Direction, FlexboxConfig::AlignContent, FlexboxConfig::JustifyContent, FlexboxConfig::Wrap, FlexboxConfig::Direction::RowInversed, FlexboxConfig::AlignItems, FlexboxConfig::Direction::Row, FlexboxConfig::Direction::Column, FlexboxConfig::Direction::ColumnInversed, FlexboxConfig::Wrap::WrapInversed, FlexboxConfig::AlignContent::Stretch, FlexboxConfig::JustifyContent::Stretch, FlexboxConfig::Wrap::Wrap, FlexboxConfig::AlignContent::Center, FlexboxConfig::AlignContent::FlexEnd, FlexboxConfig::AlignContent::FlexStart, FlexboxConfig::AlignContent::SpaceAround, FlexboxConfig::AlignContent::SpaceBetween, FlexboxConfig::AlignContent::SpaceEvenly, FlexboxConfig::AlignItems::Center, FlexboxConfig::AlignItems::FlexEnd, FlexboxConfig::AlignItems::FlexStart, FlexboxConfig::AlignItems::Stretch, FlexboxConfig::JustifyContent::Center, FlexboxConfig::JustifyContent::FlexEnd, FlexboxConfig::JustifyContent::FlexStart, FlexboxConfig::JustifyContent::SpaceAround, FlexboxConfig::JustifyContent::SpaceBetween, FlexboxConfig::JustifyContent::SpaceEvenly, FlexboxConfig::Wrap::NoWrap +#include // for allocator_traits<>::value_type +#include // for swap, move #include "ftxui/dom/box_helper.hpp" // for Element, Compute diff --git a/src/ftxui/dom/flexbox_helper_test.cpp b/src/ftxui/dom/flexbox_helper_test.cpp index 09d5b20..5f74562 100644 --- a/src/ftxui/dom/flexbox_helper_test.cpp +++ b/src/ftxui/dom/flexbox_helper_test.cpp @@ -1,6 +1,7 @@ #include // for Message #include // for TestPartResult, SuiteApiResolver, TestFactoryImpl -#include // for allocator_traits<>::value_type +#include // for FlexboxConfig, FlexboxConfig::Direction, FlexboxConfig::Direction::Column, FlexboxConfig::Direction::ColumnInversed, FlexboxConfig::Direction::Row, FlexboxConfig::Direction::RowInversed +#include // for allocator_traits<>::value_type #include "ftxui/dom/flexbox_helper.hpp" #include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, TEST diff --git a/src/ftxui/dom/flexbox_test.cpp b/src/ftxui/dom/flexbox_test.cpp index dca5913..5925211 100644 --- a/src/ftxui/dom/flexbox_test.cpp +++ b/src/ftxui/dom/flexbox_test.cpp @@ -434,25 +434,25 @@ TEST(FlexboxTest, GapY) { TEST(FlexboxTest, Focus) { auto document = vbox({ - paragraph("0 -"), - paragraph("1 -"), - paragraph("2 -"), - paragraph("3 -"), - paragraph("4 -"), - paragraph("5 -"), - paragraph("6 -"), - paragraph("7 -") | focus, - paragraph("8 -"), - paragraph("9 -"), - }) | yframe | flex; + paragraph("0 -"), + paragraph("1 -"), + paragraph("2 -"), + paragraph("3 -"), + paragraph("4 -"), + paragraph("5 -"), + paragraph("6 -"), + paragraph("7 -") | focus, + paragraph("8 -"), + paragraph("9 -"), + }) | + yframe | flex; Screen screen(1, 3); Render(screen, document); EXPECT_EQ(screen.ToString(), "-\r\n" "7\r\n" - "-" - ); + "-"); } } // namespace ftxui diff --git a/src/ftxui/dom/gridbox.cpp b/src/ftxui/dom/gridbox.cpp index abc12d2..66f69d5 100644 --- a/src/ftxui/dom/gridbox.cpp +++ b/src/ftxui/dom/gridbox.cpp @@ -28,7 +28,7 @@ int Integrate(std::vector& elements) { } return accu; } -} +} // namespace class GridBox : public Node { public: diff --git a/src/ftxui/dom/gridbox_test.cpp b/src/ftxui/dom/gridbox_test.cpp index f358d4f..3e67c25 100644 --- a/src/ftxui/dom/gridbox_test.cpp +++ b/src/ftxui/dom/gridbox_test.cpp @@ -2,10 +2,11 @@ #include // for SuiteApiResolver, TestFactoryImpl, TestPartResult #include // for size_t #include // for remove -#include // for string, allocator, basic_string +#include // for shared_ptr +#include // for allocator, basic_string, string #include // for vector -#include "ftxui/dom/elements.hpp" // for text, operator|, Elements, gridbox, Element, flex, flex_grow, flex_shrink, vtext, vbox, border +#include "ftxui/dom/elements.hpp" // for text, operator|, Element, flex, Elements, flex_grow, flex_shrink, vtext, gridbox, vbox, focus, operator|=, border, frame #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen #include "gtest/gtest_pred_impl.h" // for Test, TEST, EXPECT_EQ diff --git a/src/ftxui/dom/node.cpp b/src/ftxui/dom/node.cpp index 9de54c1..6be453f 100644 --- a/src/ftxui/dom/node.cpp +++ b/src/ftxui/dom/node.cpp @@ -1,4 +1,5 @@ -#include // for move +#include // for Box +#include // for move #include "ftxui/dom/node.hpp" #include "ftxui/screen/screen.hpp" // for Screen diff --git a/src/ftxui/dom/node_decorator.cpp b/src/ftxui/dom/node_decorator.cpp index 6b80989..37a7e2d 100644 --- a/src/ftxui/dom/node_decorator.cpp +++ b/src/ftxui/dom/node_decorator.cpp @@ -1,5 +1,6 @@ -#include // for __shared_ptr_access -#include // for __alloc_traits<>::value_type +#include // for Node, Elements +#include // for __shared_ptr_access +#include // for __alloc_traits<>::value_type #include "ftxui/dom/node_decorator.hpp" #include "ftxui/dom/requirement.hpp" // for Requirement diff --git a/src/ftxui/dom/underlined_test.cpp b/src/ftxui/dom/underlined_test.cpp index 4026f3c..0c71341 100644 --- a/src/ftxui/dom/underlined_test.cpp +++ b/src/ftxui/dom/underlined_test.cpp @@ -1,11 +1,11 @@ #include // for Message #include // for SuiteApiResolver, TestFactoryImpl, TestPartResult -#include // for allocator +#include // for Test, AssertionResult, TestInfo (ptr only), EXPECT_TRUE, TEST +#include // for allocator #include "ftxui/dom/elements.hpp" // for operator|, text, underlined, Element #include "ftxui/dom/node.hpp" // for Render #include "ftxui/screen/screen.hpp" // for Screen, Pixel -#include "gtest/gtest_pred_impl.h" // for Test, AssertionResult, EXPECT_TRUE, TEST namespace ftxui {