diff --git a/doc/example_list.md b/doc/example_list.md index 92c99da..9405532 100644 --- a/doc/example_list.md +++ b/doc/example_list.md @@ -1,46 +1,46 @@ # Examples -@example ./examples/util/print_key_press.cpp -@example ./examples/dom/color_truecolor_HSV.cpp -@example ./examples/dom/dbox.cpp -@example ./examples/dom/separator.cpp -@example ./examples/dom/style_color.cpp -@example ./examples/dom/color_info_palette256.cpp -@example ./examples/dom/color_truecolor_RGB.cpp -@example ./examples/dom/paragraph.cpp -@example ./examples/dom/style_blink.cpp -@example ./examples/dom/style_dim.cpp -@example ./examples/dom/style_inverted.cpp -@example ./examples/dom/graph.cpp -@example ./examples/dom/package_manager.cpp -@example ./examples/dom/window.cpp -@example ./examples/dom/html_like.cpp -@example ./examples/dom/border.cpp -@example ./examples/dom/style_underlined.cpp -@example ./examples/dom/color_gallery.cpp -@example ./examples/dom/gauge.cpp -@example ./examples/dom/style_bold.cpp -@example ./examples/dom/spinner.cpp -@example ./examples/dom/style_gallery.cpp -@example ./examples/dom/vbox_hbox.cpp -@example ./examples/dom/size.cpp -@example ./examples/dom/hflow.cpp -@example ./examples/component/tab_vertical.cpp -@example ./examples/component/gallery.cpp +@example ./examples/component/button.cpp @example ./examples/component/checkbox.cpp @example ./examples/component/checkbox_in_frame.cpp -@example ./examples/component/menu2.cpp -@example ./examples/component/resizable_split.cpp -@example ./examples/component/tab_horizontal.cpp -@example ./examples/component/slider.cpp -@example ./examples/component/input.cpp -@example ./examples/component/homescreen.cpp -@example ./examples/component/radiobox.cpp -@example ./examples/component/menu_multiple.cpp -@example ./examples/component/slider_rgb.cpp -@example ./examples/component/menu.cpp -@example ./examples/component/menu_style.cpp -@example ./examples/component/radiobox_in_frame.cpp @example ./examples/component/composition.cpp -@example ./examples/component/button.cpp -@example ./examples/component/toggle.cpp +@example ./examples/component/gallery.cpp +@example ./examples/component/homescreen.cpp +@example ./examples/component/input.cpp +@example ./examples/component/menu2.cpp +@example ./examples/component/menu.cpp +@example ./examples/component/menu_multiple.cpp +@example ./examples/component/menu_style.cpp @example ./examples/component/modal_dialog.cpp +@example ./examples/component/radiobox.cpp +@example ./examples/component/radiobox_in_frame.cpp +@example ./examples/component/resizable_split.cpp +@example ./examples/component/slider.cpp +@example ./examples/component/slider_rgb.cpp +@example ./examples/component/tab_horizontal.cpp +@example ./examples/component/tab_vertical.cpp +@example ./examples/component/toggle.cpp +@example ./examples/dom/border.cpp +@example ./examples/dom/color_gallery.cpp +@example ./examples/dom/color_info_palette256.cpp +@example ./examples/dom/color_truecolor_HSV.cpp +@example ./examples/dom/color_truecolor_RGB.cpp +@example ./examples/dom/dbox.cpp +@example ./examples/dom/gauge.cpp +@example ./examples/dom/graph.cpp +@example ./examples/dom/hflow.cpp +@example ./examples/dom/html_like.cpp +@example ./examples/dom/package_manager.cpp +@example ./examples/dom/paragraph.cpp +@example ./examples/dom/separator.cpp +@example ./examples/dom/size.cpp +@example ./examples/dom/spinner.cpp +@example ./examples/dom/style_blink.cpp +@example ./examples/dom/style_bold.cpp +@example ./examples/dom/style_color.cpp +@example ./examples/dom/style_dim.cpp +@example ./examples/dom/style_gallery.cpp +@example ./examples/dom/style_inverted.cpp +@example ./examples/dom/style_underlined.cpp +@example ./examples/dom/vbox_hbox.cpp +@example ./examples/dom/window.cpp +@example ./examples/util/print_key_press.cpp diff --git a/include/ftxui/component/captured_mouse.hpp b/include/ftxui/component/captured_mouse.hpp index 9c69a3a..a59e3ea 100644 --- a/include/ftxui/component/captured_mouse.hpp +++ b/include/ftxui/component/captured_mouse.hpp @@ -6,7 +6,7 @@ namespace ftxui { class CapturedMouseInterface { public: - virtual ~CapturedMouseInterface() {} + virtual ~CapturedMouseInterface() = default; }; using CapturedMouse = std::unique_ptr; } // namespace ftxui diff --git a/include/ftxui/component/component.hpp b/include/ftxui/component/component.hpp index b06fdf8..1bedac6 100644 --- a/include/ftxui/component/component.hpp +++ b/include/ftxui/component/component.hpp @@ -2,29 +2,24 @@ #define FTXUI_COMPONENT_HPP #include // for function -#include // for shared_ptr, make_shared +#include // for make_shared, shared_ptr #include // for wstring #include // for vector -#include "ftxui/component/component_base.hpp" -#include "ftxui/component/component_options.hpp" -#include "ftxui/dom/elements.hpp" // for Element -#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef, StringRef +#include "ftxui/component/component_base.hpp" // for Component, Components +#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, InputOption, MenuOption, RadioboxOption, ToggleOption +#include "ftxui/dom/elements.hpp" // for Element +#include "ftxui/util/ref.hpp" // for Ref, ConstStringRef, StringRef namespace ftxui { - -class ComponentBase; -struct Event; struct ButtonOption; struct CheckboxOption; +struct Event; struct InputOption; struct MenuOption; struct RadioboxOption; struct ToggleOption; -using Component = std::shared_ptr; -using Components = std::vector; - template std::shared_ptr Make(Args&&... args) { return std::make_shared(args...); diff --git a/include/ftxui/component/component_base.hpp b/include/ftxui/component/component_base.hpp index a8b68a5..9f786a8 100644 --- a/include/ftxui/component/component_base.hpp +++ b/include/ftxui/component/component_base.hpp @@ -22,8 +22,7 @@ using Components = std::vector; /// @ingroup component class ComponentBase { public: - // Constructor/Destructor. - ComponentBase() = default; + // virtual Destructor. virtual ~ComponentBase(); // Component hierarchy: @@ -73,8 +72,6 @@ class ComponentBase { ComponentBase* parent_ = nullptr; }; -using Component = std::shared_ptr; - } // namespace ftxui #endif /* end of include guard: FTXUI_COMPONENT_BASE_HPP */ diff --git a/include/ftxui/component/screen_interactive.hpp b/include/ftxui/component/screen_interactive.hpp index 9cb15a1..a6e0b5f 100644 --- a/include/ftxui/component/screen_interactive.hpp +++ b/include/ftxui/component/screen_interactive.hpp @@ -8,14 +8,14 @@ #include // for string #include "ftxui/component/captured_mouse.hpp" // for CapturedMouse -#include "ftxui/component/event.hpp" -#include "ftxui/screen/screen.hpp" // for Screen +#include "ftxui/component/event.hpp" // for Event +#include "ftxui/screen/screen.hpp" // for Screen namespace ftxui { class ComponentBase; +struct Event; using Component = std::shared_ptr; -struct Event; class ScreenInteractive : public Screen { public: diff --git a/include/ftxui/dom/node.hpp b/include/ftxui/dom/node.hpp index 7c66375..f3d03ee 100644 --- a/include/ftxui/dom/node.hpp +++ b/include/ftxui/dom/node.hpp @@ -14,7 +14,7 @@ class Node; class Screen; using Element = std::shared_ptr; -using Elements = std::vector>; +using Elements = std::vector; class Node { public: diff --git a/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp index 4a3d0ca..a76eb2f 100644 --- a/include/ftxui/screen/screen.hpp +++ b/include/ftxui/screen/screen.hpp @@ -10,9 +10,6 @@ namespace ftxui { class Node; -} - -namespace ftxui { using Element = std::shared_ptr; /// @brief A unicode character and its associated style. diff --git a/src/ftxui/component/button.cpp b/src/ftxui/component/button.cpp index 194a354..aa35e25 100644 --- a/src/ftxui/component/button.cpp +++ b/src/ftxui/component/button.cpp @@ -23,8 +23,6 @@ class ButtonBase : public ComponentBase { Ref option) : label_(label), on_click_(on_click), option_(std::move(option)) {} - ~ButtonBase() override = default; - // Component implementation: Element Render() override { auto style = Focused() ? inverted : nothing; diff --git a/src/ftxui/component/catch_event.cpp b/src/ftxui/component/catch_event.cpp index 102f6dd..59ba1aa 100644 --- a/src/ftxui/component/catch_event.cpp +++ b/src/ftxui/component/catch_event.cpp @@ -13,7 +13,6 @@ class CatchEventBase : public ComponentBase { // Constructor. CatchEventBase(std::function on_event) : on_event_(std::move(on_event)) {} - ~CatchEventBase() override = default; // Component implementation. bool OnEvent(Event event) override { diff --git a/src/ftxui/component/checkbox.cpp b/src/ftxui/component/checkbox.cpp index efcecd2..cf242d7 100644 --- a/src/ftxui/component/checkbox.cpp +++ b/src/ftxui/component/checkbox.cpp @@ -29,8 +29,6 @@ class CheckboxBase : public ComponentBase { #endif } - ~CheckboxBase() override = default; - private: // Component implementation. Element Render() override { diff --git a/src/ftxui/component/component.cpp b/src/ftxui/component/component.cpp index bc90775..cd0c6cc 100644 --- a/src/ftxui/component/component.cpp +++ b/src/ftxui/component/component.cpp @@ -14,10 +14,7 @@ namespace ftxui { namespace { -class CaptureMouseImpl : public CapturedMouseInterface { - public: - ~CaptureMouseImpl() override {} -}; +class CaptureMouseImpl : public CapturedMouseInterface {}; } // namespace ComponentBase::~ComponentBase() { @@ -161,9 +158,9 @@ void ComponentBase::TakeFocus() { /// @param event /// @ingroup component CapturedMouse ComponentBase::CaptureMouse(const Event& event) { - if (!event.screen_) - return std::make_unique(); - return event.screen_->CaptureMouse(); + if (event.screen_) + return event.screen_->CaptureMouse(); + return std::make_unique(); } } // namespace ftxui diff --git a/src/ftxui/component/container.cpp b/src/ftxui/component/container.cpp index 3125025..5685fac 100644 --- a/src/ftxui/component/container.cpp +++ b/src/ftxui/component/container.cpp @@ -53,8 +53,6 @@ class ContainerBase : public ComponentBase { return container; } - ~ContainerBase() override = default; - // Component override. bool OnEvent(Event event) override { if (event.is_mouse()) diff --git a/src/ftxui/component/input.cpp b/src/ftxui/component/input.cpp index 527e31a..e62b12c 100644 --- a/src/ftxui/component/input.cpp +++ b/src/ftxui/component/input.cpp @@ -24,7 +24,6 @@ class InputBase : public ComponentBase { ConstStringRef placeholder, Ref option) : content_(content), placeholder_(placeholder), option_(option) {} - ~InputBase() override = default; int& cursor_position() { return *(option_->cursor_position); } diff --git a/src/ftxui/component/radiobox.cpp b/src/ftxui/component/radiobox.cpp index d24a235..5834857 100644 --- a/src/ftxui/component/radiobox.cpp +++ b/src/ftxui/component/radiobox.cpp @@ -38,7 +38,6 @@ class RadioboxBase : public ComponentBase { option_->style_unchecked = L"( )"; #endif } - ~RadioboxBase() override = default; private: Element Render() override { diff --git a/src/ftxui/component/renderer.cpp b/src/ftxui/component/renderer.cpp index 21e17db..9e51630 100644 --- a/src/ftxui/component/renderer.cpp +++ b/src/ftxui/component/renderer.cpp @@ -18,7 +18,6 @@ class RendererBase : public ComponentBase { // Constructor. RendererBase(std::function render) : render_(std::move(render)) {} - ~RendererBase() override = default; // Component implementation. Element Render() override { return render_(); } diff --git a/src/ftxui/component/toggle.cpp b/src/ftxui/component/toggle.cpp index e357686..a82429f 100644 --- a/src/ftxui/component/toggle.cpp +++ b/src/ftxui/component/toggle.cpp @@ -29,8 +29,6 @@ class ToggleBase : public ComponentBase { Ref option) : entries_(entries), selected_(selected), option_(std::move(option)) {} - ~ToggleBase() override = default; - private: Element Render() override { Elements children; diff --git a/src/ftxui/dom/blink.cpp b/src/ftxui/dom/blink.cpp index 3622b1f..0dbdb01 100644 --- a/src/ftxui/dom/blink.cpp +++ b/src/ftxui/dom/blink.cpp @@ -11,8 +11,7 @@ namespace ftxui { class Blink : public NodeDecorator { public: - Blink(Elements children) : NodeDecorator(std::move(children)) {} - ~Blink() override {} + using NodeDecorator::NodeDecorator; void Render(Screen& screen) override { Node::Render(screen); diff --git a/src/ftxui/dom/bold.cpp b/src/ftxui/dom/bold.cpp index 0561860..7e25de5 100644 --- a/src/ftxui/dom/bold.cpp +++ b/src/ftxui/dom/bold.cpp @@ -11,8 +11,7 @@ namespace ftxui { class Bold : public NodeDecorator { public: - Bold(Elements children) : NodeDecorator(std::move(children)) {} - ~Bold() override {} + using NodeDecorator::NodeDecorator; void Render(Screen& screen) override { for (int y = box_.y_min; y <= box_.y_max; ++y) { diff --git a/src/ftxui/dom/border.cpp b/src/ftxui/dom/border.cpp index 9b71cff..5847511 100644 --- a/src/ftxui/dom/border.cpp +++ b/src/ftxui/dom/border.cpp @@ -22,7 +22,6 @@ class Border : public Node { std::end(simple_border_charset)) {} Border(Elements children, Pixel pixel) : Node(std::move(children)), charset_pixel(10, pixel) {} - ~Border() override {} std::vector charset_pixel; std::vector charset; diff --git a/src/ftxui/dom/clear_under.cpp b/src/ftxui/dom/clear_under.cpp index e9ae80c..188b60f 100644 --- a/src/ftxui/dom/clear_under.cpp +++ b/src/ftxui/dom/clear_under.cpp @@ -13,8 +13,7 @@ using ftxui::Screen; class ClearUnder : public NodeDecorator { public: - ClearUnder(Elements children) : NodeDecorator(std::move(children)) {} - ~ClearUnder() override {} + using NodeDecorator::NodeDecorator; void Render(Screen& screen) override { for (int y = box_.y_min; y <= box_.y_max; ++y) { diff --git a/src/ftxui/dom/color.cpp b/src/ftxui/dom/color.cpp index 465ad68..297a0a4 100644 --- a/src/ftxui/dom/color.cpp +++ b/src/ftxui/dom/color.cpp @@ -30,7 +30,6 @@ class FgColor : public NodeDecorator { public: FgColor(Elements children, Color color) : NodeDecorator(std::move(children)), color_(color) {} - ~FgColor() override {} void Render(Screen& screen) override { for (int y = box_.y_min; y <= box_.y_max; ++y) { diff --git a/src/ftxui/dom/dbox.cpp b/src/ftxui/dom/dbox.cpp index 7881941..9694d10 100644 --- a/src/ftxui/dom/dbox.cpp +++ b/src/ftxui/dom/dbox.cpp @@ -13,7 +13,6 @@ namespace ftxui { class DBox : public Node { public: DBox(Elements children) : Node(std::move(children)) {} - ~DBox() {} void ComputeRequirement() override { requirement_.min_x = 0; diff --git a/src/ftxui/dom/dim.cpp b/src/ftxui/dom/dim.cpp index a2e8d85..043305f 100644 --- a/src/ftxui/dom/dim.cpp +++ b/src/ftxui/dom/dim.cpp @@ -9,12 +9,9 @@ namespace ftxui { -using ftxui::Screen; - class Dim : public NodeDecorator { public: - Dim(Elements children) : NodeDecorator(std::move(children)) {} - ~Dim() override {} + using NodeDecorator::NodeDecorator; void Render(Screen& screen) override { Node::Render(screen); diff --git a/src/ftxui/dom/flex.cpp b/src/ftxui/dom/flex.cpp index 2837707..54e05f5 100644 --- a/src/ftxui/dom/flex.cpp +++ b/src/ftxui/dom/flex.cpp @@ -67,9 +67,8 @@ void function_not_flex(Requirement& r) { class Flex : public Node { public: - Flex(FlexFunction f) { f_ = f; } + Flex(FlexFunction f) : f_(f) {} Flex(FlexFunction f, Element child) : Node(unpack(std::move(child))), f_(f) {} - ~Flex() override {} void ComputeRequirement() override { requirement_.min_x = 0; requirement_.min_y = 0; diff --git a/src/ftxui/dom/gauge.cpp b/src/ftxui/dom/gauge.cpp index 3c2888d..b494f6b 100644 --- a/src/ftxui/dom/gauge.cpp +++ b/src/ftxui/dom/gauge.cpp @@ -19,7 +19,6 @@ static wchar_t charset[] = L" ▏▎▍▌▋▊▉█"; class Gauge : public Node { public: Gauge(float progress) : progress_(progress) {} - ~Gauge() override {} void ComputeRequirement() override { requirement_.flex_grow_x = 1; diff --git a/src/ftxui/dom/graph.cpp b/src/ftxui/dom/graph.cpp index a1faa65..64a463c 100644 --- a/src/ftxui/dom/graph.cpp +++ b/src/ftxui/dom/graph.cpp @@ -21,7 +21,6 @@ const wchar_t charset[] = L" ▗▐▖▄▟▌▙█"; class Graph : public Node { public: Graph(GraphFunction graph_function) : graph_function_(graph_function) {} - ~Graph() override {} void ComputeRequirement() override { requirement_.flex_grow_x = 1; diff --git a/src/ftxui/dom/hbox.cpp b/src/ftxui/dom/hbox.cpp index b48e5ec..08e82bf 100644 --- a/src/ftxui/dom/hbox.cpp +++ b/src/ftxui/dom/hbox.cpp @@ -13,7 +13,6 @@ namespace ftxui { class HBox : public Node { public: HBox(Elements children) : Node(std::move(children)) {} - ~HBox() {} void ComputeRequirement() override { requirement_.min_x = 0; diff --git a/src/ftxui/dom/hflow.cpp b/src/ftxui/dom/hflow.cpp index b5976f9..79f8219 100644 --- a/src/ftxui/dom/hflow.cpp +++ b/src/ftxui/dom/hflow.cpp @@ -13,7 +13,6 @@ namespace ftxui { class HFlow : public Node { public: HFlow(Elements children) : Node(std::move(children)) {} - ~HFlow() {} void ComputeRequirement() override { requirement_.min_x = 1; diff --git a/src/ftxui/dom/inverted.cpp b/src/ftxui/dom/inverted.cpp index c562499..3f1b4a8 100644 --- a/src/ftxui/dom/inverted.cpp +++ b/src/ftxui/dom/inverted.cpp @@ -9,12 +9,9 @@ namespace ftxui { -using ftxui::Screen; - class Inverted : public NodeDecorator { public: - Inverted(Elements children) : NodeDecorator(std::move(children)) {} - ~Inverted() override {} + using NodeDecorator::NodeDecorator; void Render(Screen& screen) override { Node::Render(screen); diff --git a/src/ftxui/dom/node.cpp b/src/ftxui/dom/node.cpp index 3e07d9e..6bf0294 100644 --- a/src/ftxui/dom/node.cpp +++ b/src/ftxui/dom/node.cpp @@ -5,8 +5,6 @@ namespace ftxui { -using ftxui::Screen; - Node::Node() {} Node::Node(Elements children) : children_(std::move(children)) {} Node::~Node() {} diff --git a/src/ftxui/dom/node_decorator.hpp b/src/ftxui/dom/node_decorator.hpp index a9f1d4f..a1f5709 100644 --- a/src/ftxui/dom/node_decorator.hpp +++ b/src/ftxui/dom/node_decorator.hpp @@ -12,7 +12,6 @@ struct Box; class NodeDecorator : public Node { public: NodeDecorator(Elements children) : Node(std::move(children)) {} - ~NodeDecorator() override {} void ComputeRequirement() override; void SetBox(Box box) override; }; diff --git a/src/ftxui/dom/reflect.cpp b/src/ftxui/dom/reflect.cpp index a263063..2d4b2a6 100644 --- a/src/ftxui/dom/reflect.cpp +++ b/src/ftxui/dom/reflect.cpp @@ -14,7 +14,6 @@ class Reflect : public Node { public: Reflect(Element child, Box& box) : Node(unpack(std::move(child))), reflected_box_(box) {} - ~Reflect() override {} void ComputeRequirement() final { Node::ComputeRequirement(); diff --git a/src/ftxui/dom/separator.cpp b/src/ftxui/dom/separator.cpp index fa255a8..88d066e 100644 --- a/src/ftxui/dom/separator.cpp +++ b/src/ftxui/dom/separator.cpp @@ -13,8 +13,6 @@ using ftxui::Screen; class Separator : public Node { public: - Separator() {} - ~Separator() override {} void ComputeRequirement() override { requirement_.min_x = 1; requirement_.min_y = 1; @@ -41,7 +39,6 @@ class Separator : public Node { class SeparatorWithPixel : public Separator { public: SeparatorWithPixel(Pixel pixel) : pixel_(pixel) {} - ~SeparatorWithPixel() override {} void Render(Screen& screen) override { for (int y = box_.y_min; y <= box_.y_max; ++y) { for (int x = box_.x_min; x <= box_.x_max; ++x) { diff --git a/src/ftxui/dom/size.cpp b/src/ftxui/dom/size.cpp index 7d5b773..9d66246 100644 --- a/src/ftxui/dom/size.cpp +++ b/src/ftxui/dom/size.cpp @@ -19,8 +19,6 @@ class Size : public Node { constraint_(constraint), value_(value) {} - ~Size() override {} - void ComputeRequirement() override { Node::ComputeRequirement(); requirement_ = children_[0]->requirement(); diff --git a/src/ftxui/dom/text.cpp b/src/ftxui/dom/text.cpp index e8d24f6..2803fd7 100644 --- a/src/ftxui/dom/text.cpp +++ b/src/ftxui/dom/text.cpp @@ -15,8 +15,7 @@ using ftxui::Screen; class Text : public Node { public: - Text(std::wstring text) : Node(), text_(text) {} - ~Text() {} + Text(std::wstring text) : text_(text) {} void ComputeRequirement() override { requirement_.min_x = wstring_width(text_); @@ -47,11 +46,10 @@ class Text : public Node { class VText : public Node { public: - VText(std::wstring text) : Node(), text_(text) { + VText(std::wstring text) : text_(text) { for (auto& c : text_) width_ = std::max(width_, wchar_width(c)); } - ~VText() {} void ComputeRequirement() override { requirement_.min_x = width_; diff --git a/src/ftxui/dom/underlined.cpp b/src/ftxui/dom/underlined.cpp index 09e82f7..d75d315 100644 --- a/src/ftxui/dom/underlined.cpp +++ b/src/ftxui/dom/underlined.cpp @@ -9,12 +9,9 @@ namespace ftxui { -using ftxui::Screen; - class Underlined : public NodeDecorator { public: - Underlined(Elements children) : NodeDecorator(std::move(children)) {} - ~Underlined() override {} + using NodeDecorator::NodeDecorator; void Render(Screen& screen) override { Node::Render(screen); diff --git a/src/ftxui/dom/vbox.cpp b/src/ftxui/dom/vbox.cpp index ef2a1d8..4021cdc 100644 --- a/src/ftxui/dom/vbox.cpp +++ b/src/ftxui/dom/vbox.cpp @@ -13,7 +13,6 @@ namespace ftxui { class VBox : public Node { public: VBox(Elements children) : Node(std::move(children)) {} - ~VBox() {} void ComputeRequirement() override { requirement_.min_x = 0; diff --git a/tools/format.sh b/tools/format.sh index 692edb0..8c46506 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -20,7 +20,7 @@ done exampleList="./doc/example_list.md" echo "# Examples" > $exampleList -files=$(find ./examples/ -iname "*.cpp") +files=$(find ./examples -iname "*.cpp" | sort) for f in $files do echo "@example $f" >> $exampleList