mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
Add size(width, height) decorator.
This commit is contained in:
parent
7efe8a6385
commit
ccb437f4da
@ -44,10 +44,7 @@ int main(int argc, const char *argv[])
|
||||
int nb_done = 0;
|
||||
|
||||
auto to_text = [](int number) {
|
||||
std::wstring t = to_wstring(number);
|
||||
while(t.size() < 3)
|
||||
t = L" " + t;
|
||||
return text(t);
|
||||
return text(to_wstring(number)) | size(3,1);
|
||||
};
|
||||
|
||||
auto renderTask = [&](const Task& task) {
|
||||
|
@ -37,6 +37,7 @@ add_library(dom
|
||||
src/ftxui/dom/node.cpp
|
||||
src/ftxui/dom/node_decorator.cpp
|
||||
src/ftxui/dom/separator.cpp
|
||||
src/ftxui/dom/size.cpp
|
||||
src/ftxui/dom/text.cpp
|
||||
src/ftxui/dom/underlined.cpp
|
||||
src/ftxui/dom/util.cpp
|
||||
|
@ -18,8 +18,11 @@ using Color = ftxui::screen::Color;
|
||||
Element vbox(Children);
|
||||
Element hbox(Children);
|
||||
Element dbox(Children);
|
||||
|
||||
// -- Flexibility --
|
||||
Element filler();
|
||||
Element flex(Element);
|
||||
Decorator size(size_t width, size_t height);
|
||||
|
||||
// --- Widget --
|
||||
Element text(std::wstring text);
|
||||
|
35
ftxui/src/ftxui/dom/size.cpp
Normal file
35
ftxui/src/ftxui/dom/size.cpp
Normal 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
|
Loading…
Reference in New Issue
Block a user