FTXUI/src/ftxui/dom/flex.cpp

59 lines
1.3 KiB
C++
Raw Normal View History

#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
2018-09-18 14:48:40 +08:00
namespace ftxui {
2018-09-18 14:48:40 +08:00
class Flex : public Node {
public:
Flex() {}
2018-09-20 03:52:25 +08:00
Flex(Element child) : Node(unpack(std::move(child))) {}
2018-09-18 14:48:40 +08:00
~Flex() override {}
2019-01-27 09:33:06 +08:00
void ComputeRequirement() override {
2018-09-18 14:48:40 +08:00
requirement_.min.x = 0;
requirement_.min.y = 0;
2018-09-20 03:52:25 +08:00
if (!children.empty()) {
children[0]->ComputeRequirement();
requirement_ = children[0]->requirement();
}
2018-09-18 14:48:40 +08:00
requirement_.flex.x = 1;
requirement_.flex.y = 1;
}
2018-09-20 03:52:25 +08:00
void SetBox(Box box) override {
if (children.empty())
return;
children[0]->SetBox(box);
}
2018-09-18 14:48:40 +08:00
};
2019-01-27 09:33:06 +08:00
class NotFlex : public Flex {
public:
NotFlex() {}
NotFlex(Element child) : Flex(std::move(child)) {}
~NotFlex() override {}
void ComputeRequirement() override {
requirement_.min.x = 0;
requirement_.min.y = 0;
if (!children.empty()) {
children[0]->ComputeRequirement();
requirement_ = children[0]->requirement();
}
requirement_.flex.x = 0;
requirement_.flex.y = 0;
}
};
std::unique_ptr<Node> filler() {
2018-09-18 14:48:40 +08:00
return std::make_unique<Flex>();
}
2018-09-20 03:52:25 +08:00
std::unique_ptr<Node> flex(Element child) {
return std::make_unique<Flex>(std::move(child));
}
2019-01-27 09:33:06 +08:00
std::unique_ptr<Node> notflex(Element child) {
return std::make_unique<NotFlex>(std::move(child));
}
}; // namespace ftxui