Add size(width, height) decorator.

This commit is contained in:
Arthur Sonzogni 2019-01-06 19:17:27 +01:00
parent 7efe8a6385
commit ccb437f4da
4 changed files with 40 additions and 4 deletions

View File

@ -44,10 +44,7 @@ int main(int argc, const char *argv[])
int nb_done = 0; int nb_done = 0;
auto to_text = [](int number) { auto to_text = [](int number) {
std::wstring t = to_wstring(number); return text(to_wstring(number)) | size(3,1);
while(t.size() < 3)
t = L" " + t;
return text(t);
}; };
auto renderTask = [&](const Task& task) { auto renderTask = [&](const Task& task) {

View File

@ -37,6 +37,7 @@ add_library(dom
src/ftxui/dom/node.cpp src/ftxui/dom/node.cpp
src/ftxui/dom/node_decorator.cpp src/ftxui/dom/node_decorator.cpp
src/ftxui/dom/separator.cpp src/ftxui/dom/separator.cpp
src/ftxui/dom/size.cpp
src/ftxui/dom/text.cpp src/ftxui/dom/text.cpp
src/ftxui/dom/underlined.cpp src/ftxui/dom/underlined.cpp
src/ftxui/dom/util.cpp src/ftxui/dom/util.cpp

View File

@ -18,8 +18,11 @@ using Color = ftxui::screen::Color;
Element vbox(Children); Element vbox(Children);
Element hbox(Children); Element hbox(Children);
Element dbox(Children); Element dbox(Children);
// -- Flexibility --
Element filler(); Element filler();
Element flex(Element); Element flex(Element);
Decorator size(size_t width, size_t height);
// --- Widget -- // --- Widget --
Element text(std::wstring text); Element text(std::wstring text);

View File

@ -0,0 +1,35 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/dom/elements.hpp"
namespace ftxui::dom {
class Size : public Node {
public:
Size(Element child, size_t width, size_t height)
: Node(unpack(std::move(child))), width_(width), height_(height) {}
~Size() override {}
void ComputeRequirement() override {
Node::ComputeRequirement();
requirement_.min.x = width_;
requirement_.min.y = height_;
requirement_.flex.x = 0;
requirement_.flex.y = 0;
}
void SetBox(Box box) override {
Node::SetBox(box);
children[0]->SetBox(box);
}
private:
size_t width_;
size_t height_;
};
Decorator size(size_t width, size_t height) {
return [=](Element e) {
return std::make_unique<Size>(std::move(e), width, height);
};
}
}; // namespace ftxui::dom