mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-18 00:48:09 +08:00
Miscellaneous refactoring (#160)
* Reorganize ContainerBase - Reduce Container overloads using default arguments - Extract member function pointers to virtual functions - Separate classes for Vertical, Horizontal and Tab containers * Collect unpack from NodeDecorator subclasses * Reduce redundant expansion for aliases
This commit is contained in:

committed by
GitHub

parent
210e8c5863
commit
09805e5e86
@@ -1,7 +1,7 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack, Elements, blink
|
||||
#include "ftxui/dom/elements.hpp" // for Element, blink
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
@@ -26,7 +26,7 @@ class Blink : public NodeDecorator {
|
||||
/// @brief The text drawn alternates in between visible and hidden.
|
||||
/// @ingroup dom
|
||||
Element blink(Element child) {
|
||||
return std::make_shared<Blink>(unpack(std::move(child)));
|
||||
return std::make_shared<Blink>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack, Elements, bold
|
||||
#include "ftxui/dom/elements.hpp" // for Element, bold
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
@@ -26,7 +26,7 @@ class Bold : public NodeDecorator {
|
||||
/// @brief Use a bold font, for elements with more emphasis.
|
||||
/// @ingroup dom
|
||||
Element bold(Element child) {
|
||||
return std::make_shared<Bold>(unpack(std::move(child)));
|
||||
return std::make_shared<Bold>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack, Elements, clear_under
|
||||
#include "ftxui/dom/elements.hpp" // for Element, clear_under
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
@@ -30,7 +30,7 @@ class ClearUnder : public NodeDecorator {
|
||||
/// @see ftxui::dbox
|
||||
/// @ingroup dom
|
||||
Element clear_under(Element child) {
|
||||
return std::make_shared<ClearUnder>(unpack(std::move(child)));
|
||||
return std::make_shared<ClearUnder>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack, Decorator, Elements, bgcolor, color
|
||||
#include "ftxui/dom/elements.hpp" // for Element, Decorator, bgcolor, color
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
#include "ftxui/screen/color.hpp" // for Color
|
||||
@@ -11,8 +11,8 @@ namespace ftxui {
|
||||
|
||||
class BgColor : public NodeDecorator {
|
||||
public:
|
||||
BgColor(Elements children, Color color)
|
||||
: NodeDecorator(std::move(children)), color_(color) {}
|
||||
BgColor(Element child, Color color)
|
||||
: NodeDecorator(std::move(child)), color_(color) {}
|
||||
|
||||
void Render(Screen& screen) override {
|
||||
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
||||
@@ -28,8 +28,8 @@ class BgColor : public NodeDecorator {
|
||||
|
||||
class FgColor : public NodeDecorator {
|
||||
public:
|
||||
FgColor(Elements children, Color color)
|
||||
: NodeDecorator(std::move(children)), color_(color) {}
|
||||
FgColor(Element child, Color color)
|
||||
: NodeDecorator(std::move(child)), color_(color) {}
|
||||
|
||||
void Render(Screen& screen) override {
|
||||
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
||||
@@ -55,7 +55,7 @@ class FgColor : public NodeDecorator {
|
||||
/// Element document = color(Color::Green, text(L"Success")),
|
||||
/// ```
|
||||
Element color(Color color, Element child) {
|
||||
return std::make_shared<FgColor>(unpack(std::move(child)), color);
|
||||
return std::make_shared<FgColor>(std::move(child), color);
|
||||
}
|
||||
|
||||
/// @brief Set the background color of an element.
|
||||
@@ -70,7 +70,7 @@ Element color(Color color, Element child) {
|
||||
/// Element document = bgcolor(Color::Green, text(L"Success")),
|
||||
/// ```
|
||||
Element bgcolor(Color color, Element child) {
|
||||
return std::make_shared<BgColor>(unpack(std::move(child)), color);
|
||||
return std::make_shared<BgColor>(std::move(child), color);
|
||||
}
|
||||
|
||||
/// @brief Decorate using a foreground color.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack, Elements, dim
|
||||
#include "ftxui/dom/elements.hpp" // for Element, dim
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
@@ -26,7 +26,7 @@ class Dim : public NodeDecorator {
|
||||
/// @brief Use a light font, for elements with less emphasis.
|
||||
/// @ingroup dom
|
||||
Element dim(Element child) {
|
||||
return std::make_shared<Dim>(unpack(std::move(child)));
|
||||
return std::make_shared<Dim>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -16,8 +16,7 @@ namespace ftxui {
|
||||
|
||||
class Select : public Node {
|
||||
public:
|
||||
Select(std::vector<std::shared_ptr<Node>> children)
|
||||
: Node(std::move(children)) {}
|
||||
Select(Elements children) : Node(std::move(children)) {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
Node::ComputeRequirement();
|
||||
@@ -31,7 +30,7 @@ class Select : public Node {
|
||||
};
|
||||
|
||||
void SetBox(Box box) override {
|
||||
box_ = box;
|
||||
Node::SetBox(box);
|
||||
children_[0]->SetBox(box);
|
||||
}
|
||||
};
|
||||
@@ -44,7 +43,7 @@ Element select(Element child) {
|
||||
|
||||
class Focus : public Select {
|
||||
public:
|
||||
Focus(std::vector<Element> children) : Select(std::move(children)) {}
|
||||
using Select::Select;
|
||||
|
||||
void ComputeRequirement() override {
|
||||
Select::ComputeRequirement();
|
||||
@@ -85,7 +84,7 @@ Element focus(Element child) {
|
||||
|
||||
class Frame : public Node {
|
||||
public:
|
||||
Frame(std::vector<Element> children, bool x_frame, bool y_frame)
|
||||
Frame(Elements children, bool x_frame, bool y_frame)
|
||||
: Node(std::move(children)), x_frame_(x_frame), y_frame_(y_frame) {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack, Elements, inverted
|
||||
#include "ftxui/dom/elements.hpp" // for Element, inverted
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
@@ -27,7 +27,7 @@ class Inverted : public NodeDecorator {
|
||||
/// colors.
|
||||
/// @ingroup dom
|
||||
Element inverted(Element child) {
|
||||
return std::make_shared<Inverted>(unpack(std::move(child)));
|
||||
return std::make_shared<Inverted>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -3,7 +3,8 @@
|
||||
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/node.hpp" // for Node, Elements
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
|
||||
namespace ftxui {
|
||||
struct Box;
|
||||
@@ -11,7 +12,7 @@ struct Box;
|
||||
// Helper class.
|
||||
class NodeDecorator : public Node {
|
||||
public:
|
||||
NodeDecorator(Elements children) : Node(std::move(children)) {}
|
||||
NodeDecorator(Element child) : Node(unpack(std::move(child))) {}
|
||||
void ComputeRequirement() override;
|
||||
void SetBox(Box box) override;
|
||||
};
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <memory> // for make_shared
|
||||
#include <utility> // for move
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for Element, unpack, Elements, underlined
|
||||
#include "ftxui/dom/elements.hpp" // for Element, underlined
|
||||
#include "ftxui/dom/node.hpp" // for Node
|
||||
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||
#include "ftxui/screen/box.hpp" // for Box
|
||||
@@ -26,7 +26,7 @@ class Underlined : public NodeDecorator {
|
||||
/// @brief Make the underlined element to be underlined.
|
||||
/// @ingroup dom
|
||||
Element underlined(Element child) {
|
||||
return std::make_shared<Underlined>(unpack(std::move(child)));
|
||||
return std::make_shared<Underlined>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
Reference in New Issue
Block a user