2020-04-20 03:00:37 +08:00
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
#include "ftxui/dom/elements.hpp"
|
2020-03-23 05:32:44 +08:00
|
|
|
#include "ftxui/dom/node.hpp"
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2019-01-12 22:00:08 +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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-05 09:03:49 +08:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2020-02-12 04:44:55 +08:00
|
|
|
} // namespace ftxui
|