mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
Remove explicit default destructors (#157)
From CppCoreGuidelines: Rule of Zero: C.20: If you can avoid defining default operations, do. C.52: Use inheriting constructors to import constructors into a derived class that does not need further explicit initialization. DRY forward and using declarations. Miscellaneous: Fix format.sh to output examples with normalised paths in sorted order. Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
parent
b3a333b417
commit
21d746e858
@ -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
|
||||
|
@ -6,7 +6,7 @@
|
||||
namespace ftxui {
|
||||
class CapturedMouseInterface {
|
||||
public:
|
||||
virtual ~CapturedMouseInterface() {}
|
||||
virtual ~CapturedMouseInterface() = default;
|
||||
};
|
||||
using CapturedMouse = std::unique_ptr<CapturedMouseInterface>;
|
||||
} // namespace ftxui
|
||||
|
@ -2,29 +2,24 @@
|
||||
#define FTXUI_COMPONENT_HPP
|
||||
|
||||
#include <functional> // for function
|
||||
#include <memory> // for shared_ptr, make_shared
|
||||
#include <memory> // for make_shared, shared_ptr
|
||||
#include <string> // for wstring
|
||||
#include <vector> // 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<ComponentBase>;
|
||||
using Components = std::vector<Component>;
|
||||
|
||||
template <class T, class... Args>
|
||||
std::shared_ptr<T> Make(Args&&... args) {
|
||||
return std::make_shared<T>(args...);
|
||||
|
@ -22,8 +22,7 @@ using Components = std::vector<Component>;
|
||||
/// @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<ComponentBase>;
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_BASE_HPP */
|
||||
|
@ -8,14 +8,14 @@
|
||||
#include <string> // 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<ComponentBase>;
|
||||
struct Event;
|
||||
|
||||
class ScreenInteractive : public Screen {
|
||||
public:
|
||||
|
@ -14,7 +14,7 @@ class Node;
|
||||
class Screen;
|
||||
|
||||
using Element = std::shared_ptr<Node>;
|
||||
using Elements = std::vector<std::shared_ptr<Node>>;
|
||||
using Elements = std::vector<Element>;
|
||||
|
||||
class Node {
|
||||
public:
|
||||
|
@ -10,9 +10,6 @@
|
||||
|
||||
namespace ftxui {
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace ftxui {
|
||||
using Element = std::shared_ptr<Node>;
|
||||
|
||||
/// @brief A unicode character and its associated style.
|
||||
|
@ -23,8 +23,6 @@ class ButtonBase : public ComponentBase {
|
||||
Ref<ButtonOption> option)
|
||||
: label_(label), on_click_(on_click), option_(std::move(option)) {}
|
||||
|
||||
~ButtonBase() override = default;
|
||||
|
||||
// Component implementation:
|
||||
Element Render() override {
|
||||
auto style = Focused() ? inverted : nothing;
|
||||
|
@ -13,7 +13,6 @@ class CatchEventBase : public ComponentBase {
|
||||
// Constructor.
|
||||
CatchEventBase(std::function<bool(Event)> on_event)
|
||||
: on_event_(std::move(on_event)) {}
|
||||
~CatchEventBase() override = default;
|
||||
|
||||
// Component implementation.
|
||||
bool OnEvent(Event event) override {
|
||||
|
@ -29,8 +29,6 @@ class CheckboxBase : public ComponentBase {
|
||||
#endif
|
||||
}
|
||||
|
||||
~CheckboxBase() override = default;
|
||||
|
||||
private:
|
||||
// Component implementation.
|
||||
Element Render() override {
|
||||
|
@ -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<CaptureMouseImpl>();
|
||||
return event.screen_->CaptureMouse();
|
||||
if (event.screen_)
|
||||
return event.screen_->CaptureMouse();
|
||||
return std::make_unique<CaptureMouseImpl>();
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@ -53,8 +53,6 @@ class ContainerBase : public ComponentBase {
|
||||
return container;
|
||||
}
|
||||
|
||||
~ContainerBase() override = default;
|
||||
|
||||
// Component override.
|
||||
bool OnEvent(Event event) override {
|
||||
if (event.is_mouse())
|
||||
|
@ -24,7 +24,6 @@ class InputBase : public ComponentBase {
|
||||
ConstStringRef placeholder,
|
||||
Ref<InputOption> option)
|
||||
: content_(content), placeholder_(placeholder), option_(option) {}
|
||||
~InputBase() override = default;
|
||||
|
||||
int& cursor_position() { return *(option_->cursor_position); }
|
||||
|
||||
|
@ -38,7 +38,6 @@ class RadioboxBase : public ComponentBase {
|
||||
option_->style_unchecked = L"( )";
|
||||
#endif
|
||||
}
|
||||
~RadioboxBase() override = default;
|
||||
|
||||
private:
|
||||
Element Render() override {
|
||||
|
@ -18,7 +18,6 @@ class RendererBase : public ComponentBase {
|
||||
|
||||
// Constructor.
|
||||
RendererBase(std::function<Element()> render) : render_(std::move(render)) {}
|
||||
~RendererBase() override = default;
|
||||
|
||||
// Component implementation.
|
||||
Element Render() override { return render_(); }
|
||||
|
@ -29,8 +29,6 @@ class ToggleBase : public ComponentBase {
|
||||
Ref<ToggleOption> option)
|
||||
: entries_(entries), selected_(selected), option_(std::move(option)) {}
|
||||
|
||||
~ToggleBase() override = default;
|
||||
|
||||
private:
|
||||
Element Render() override {
|
||||
Elements children;
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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<Pixel> charset_pixel;
|
||||
std::vector<wchar_t> charset;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -5,8 +5,6 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
using ftxui::Screen;
|
||||
|
||||
Node::Node() {}
|
||||
Node::Node(Elements children) : children_(std::move(children)) {}
|
||||
Node::~Node() {}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
@ -19,8 +19,6 @@ class Size : public Node {
|
||||
constraint_(constraint),
|
||||
value_(value) {}
|
||||
|
||||
~Size() override {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
Node::ComputeRequirement();
|
||||
requirement_ = children_[0]->requirement();
|
||||
|
@ -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_;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user