FTXUI/src/ftxui/dom/flex.cpp

63 lines
1.4 KiB
C++
Raw Normal View History

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.
#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
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;
}
};
Element filler() {
return std::make_shared<Flex>();
2018-09-18 14:48:40 +08:00
}
Element flex(Element child) {
return std::make_shared<Flex>(std::move(child));
2018-09-20 03:52:25 +08:00
}
Element notflex(Element child) {
return std::make_shared<NotFlex>(std::move(child));
2019-01-27 09:33:06 +08:00
}
2020-02-12 04:44:55 +08:00
} // namespace ftxui