mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-18 00:48:09 +08:00
Use shared_ptr instead of unique_ptr for elements.
This allow users to pass it into initializer list. Then clang-format will produce 'acceptable' indentations. This fixes: https://github.com/ArthurSonzogni/FTXUI/issues/18
This commit is contained in:
@@ -22,8 +22,8 @@ class Blink : public NodeDecorator {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> blink(Element child) {
|
||||
return std::make_unique<Blink>(unpack(std::move(child)));
|
||||
Element blink(Element child) {
|
||||
return std::make_shared<Blink>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -22,8 +22,8 @@ class Bold : public NodeDecorator {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> bold(Element child) {
|
||||
return std::make_unique<Bold>(unpack(std::move(child)));
|
||||
Element bold(Element child) {
|
||||
return std::make_shared<Bold>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -105,17 +105,17 @@ class Border : public Node {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> border(Element child) {
|
||||
return std::make_unique<Border>(unpack(std::move(child)));
|
||||
Element border(Element child) {
|
||||
return std::make_shared<Border>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> window(Element title, Element content) {
|
||||
return std::make_unique<Border>(unpack(std::move(content), std::move(title)));
|
||||
Element window(Element title, Element content) {
|
||||
return std::make_shared<Border>(unpack(std::move(content), std::move(title)));
|
||||
}
|
||||
|
||||
Decorator borderWith(Pixel pixel) {
|
||||
return [pixel](Element child) {
|
||||
return std::make_unique<Border>(unpack(std::move(child)), pixel);
|
||||
return std::make_shared<Border>(unpack(std::move(child)), pixel);
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -42,12 +42,12 @@ class FgColor : public NodeDecorator {
|
||||
Color color_;
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> color(Color c, Element child) {
|
||||
return std::make_unique<FgColor>(unpack(std::move(child)), c);
|
||||
Element color(Color c, Element child) {
|
||||
return std::make_shared<FgColor>(unpack(std::move(child)), c);
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> bgcolor(Color c, Element child) {
|
||||
return std::make_unique<BgColor>(unpack(std::move(child)), c);
|
||||
Element bgcolor(Color c, Element child) {
|
||||
return std::make_shared<BgColor>(unpack(std::move(child)), c);
|
||||
}
|
||||
|
||||
Decorator color(Color c) {
|
||||
|
@@ -7,19 +7,19 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
std::unique_ptr<Node> hcenter(Element child) {
|
||||
Element hcenter(Element child) {
|
||||
return hbox(filler(), std::move(child), filler());
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> vcenter(Element child) {
|
||||
Element vcenter(Element child) {
|
||||
return vbox(filler(), std::move(child), filler());
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> center(Element child) {
|
||||
Element center(Element child) {
|
||||
return hcenter(vcenter(std::move(child)));
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> align_right(Element child) {
|
||||
Element align_right(Element child) {
|
||||
return hbox(filler(), std::move(child));
|
||||
}
|
||||
|
||||
|
@@ -41,8 +41,8 @@ class DBox : public Node {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> dbox(Elements children) {
|
||||
return std::make_unique<DBox>(std::move(children));
|
||||
Element dbox(Elements children) {
|
||||
return std::make_shared<DBox>(std::move(children));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -24,8 +24,8 @@ class Dim : public NodeDecorator {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> dim(Element child) {
|
||||
return std::make_unique<Dim>(unpack(std::move(child)));
|
||||
Element dim(Element child) {
|
||||
return std::make_shared<Dim>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -47,16 +47,16 @@ class NotFlex : public Flex {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> filler() {
|
||||
return std::make_unique<Flex>();
|
||||
Element filler() {
|
||||
return std::make_shared<Flex>();
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> flex(Element child) {
|
||||
return std::make_unique<Flex>(std::move(child));
|
||||
Element flex(Element child) {
|
||||
return std::make_shared<Flex>(std::move(child));
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> notflex(Element child) {
|
||||
return std::make_unique<NotFlex>(std::move(child));
|
||||
Element notflex(Element child) {
|
||||
return std::make_shared<NotFlex>(std::move(child));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -14,7 +14,7 @@ namespace ftxui {
|
||||
|
||||
class Select : public Node {
|
||||
public:
|
||||
Select(std::vector<std::unique_ptr<Node>> children)
|
||||
Select(std::vector<std::shared_ptr<Node>> children)
|
||||
: Node(std::move(children)) {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
@@ -34,15 +34,15 @@ class Select : public Node {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> select(Element child) {
|
||||
return std::make_unique<Select>(unpack(std::move(child)));
|
||||
Element select(Element child) {
|
||||
return std::make_shared<Select>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class Focus : public Select {
|
||||
public:
|
||||
Focus(std::vector<std::unique_ptr<Node>> children)
|
||||
Focus(std::vector<Element> children)
|
||||
: Select(std::move(children)) {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
@@ -56,15 +56,15 @@ class Focus : public Select {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> focus(Element child) {
|
||||
return std::make_unique<Focus>(unpack(std::move(child)));
|
||||
Element focus(Element child) {
|
||||
return std::make_shared<Focus>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class Frame : public Node {
|
||||
public:
|
||||
Frame(std::vector<std::unique_ptr<Node>> children)
|
||||
Frame(std::vector<Element> children)
|
||||
: Node(std::move(children)) {}
|
||||
|
||||
void ComputeRequirement() override {
|
||||
@@ -123,8 +123,8 @@ class Frame : public Node {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> frame(Element child) {
|
||||
return std::make_unique<Frame>(unpack(std::move(child)));
|
||||
Element frame(Element child) {
|
||||
return std::make_shared<Frame>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -35,8 +35,8 @@ class Gauge : public Node {
|
||||
float progress_;
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> gauge(float progress) {
|
||||
return std::make_unique<Gauge>(progress);
|
||||
Element gauge(float progress) {
|
||||
return std::make_shared<Gauge>(progress);
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -42,8 +42,8 @@ class Graph : public Node {
|
||||
GraphFunction graph_function_;
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> graph(GraphFunction graph_function) {
|
||||
return std::make_unique<Graph>(graph_function);
|
||||
Element graph(GraphFunction graph_function) {
|
||||
return std::make_shared<Graph>(graph_function);
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -68,8 +68,8 @@ class HBox : public Node {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> hbox(Elements children) {
|
||||
return std::make_unique<HBox>(std::move(children));
|
||||
Element hbox(Elements children) {
|
||||
return std::make_shared<HBox>(std::move(children));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -58,8 +58,8 @@ class HFlow : public Node {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> hflow(Elements children) {
|
||||
return std::make_unique<HFlow>(std::move(children));
|
||||
Element hflow(Elements children) {
|
||||
return std::make_shared<HFlow>(std::move(children));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -24,8 +24,8 @@ class Inverted : public NodeDecorator {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> inverted(Element child) {
|
||||
return std::make_unique<Inverted>(unpack(std::move(child)));
|
||||
Element inverted(Element child) {
|
||||
return std::make_shared<Inverted>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -9,8 +9,7 @@ namespace ftxui {
|
||||
using ftxui::Screen;
|
||||
|
||||
Node::Node() {}
|
||||
Node::Node(std::vector<std::unique_ptr<Node>> children)
|
||||
: children(std::move(children)) {}
|
||||
Node::Node(Elements children) : children(std::move(children)) {}
|
||||
Node::~Node() {}
|
||||
|
||||
void Node::ComputeRequirement() {
|
||||
|
@@ -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 {
|
||||
|
@@ -49,12 +49,12 @@ class SeparatorWithPixel : public Separator {
|
||||
Pixel p;
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> separator() {
|
||||
return std::make_unique<Separator>();
|
||||
Element separator() {
|
||||
return std::make_shared<Separator>();
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> separator(Pixel pixel) {
|
||||
return std::make_unique<SeparatorWithPixel>(pixel);
|
||||
Element separator(Pixel pixel) {
|
||||
return std::make_shared<SeparatorWithPixel>(pixel);
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -76,7 +76,7 @@ class Size : public Node {
|
||||
|
||||
Decorator size(Direction direction, Constraint constraint, int value) {
|
||||
return [=](Element e) {
|
||||
return std::make_unique<Size>(std::move(e), direction, constraint, value);
|
||||
return std::make_shared<Size>(std::move(e), direction, constraint, value);
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -245,7 +245,7 @@ static const std::vector<std::vector<std::vector<std::wstring>>> elements = {
|
||||
L" LOLLOL ",
|
||||
}}};
|
||||
|
||||
std::unique_ptr<Node> spinner(int c, size_t index) {
|
||||
Element spinner(int c, size_t index) {
|
||||
if (c == 0) {
|
||||
index %= 40;
|
||||
if (index > 20)
|
||||
|
@@ -36,8 +36,8 @@ class Text : public Node {
|
||||
std::wstring text_;
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> text(std::wstring text) {
|
||||
return std::make_unique<Text>(text);
|
||||
Element text(std::wstring text) {
|
||||
return std::make_shared<Text>(text);
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -24,8 +24,8 @@ class Underlined : public NodeDecorator {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> underlined(Element child) {
|
||||
return std::make_unique<Underlined>(unpack(std::move(child)));
|
||||
Element underlined(Element child) {
|
||||
return std::make_shared<Underlined>(unpack(std::move(child)));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -69,8 +69,8 @@ class VBox : public Node {
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<Node> vbox(Elements children) {
|
||||
return std::make_unique<VBox>(std::move(children));
|
||||
Element vbox(Elements children) {
|
||||
return std::make_shared<VBox>(std::move(children));
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -52,7 +52,7 @@ Dimension Dimension::Fixed(int v) {
|
||||
return Dimension{v, v};
|
||||
}
|
||||
|
||||
Dimension Dimension::Fit(std::unique_ptr<Node>& e) {
|
||||
Dimension Dimension::Fit(std::shared_ptr<Node>& e) {
|
||||
e->ComputeRequirement();
|
||||
Terminal::Dimensions size = Terminal::Size();
|
||||
return Dimension{std::min(e->requirement().min.x, size.dimx),
|
||||
|
Reference in New Issue
Block a user