Introduce xflex and yflex.

This commit is contained in:
ArthurSonzogni 2020-07-17 00:27:39 +02:00 committed by Arthur Sonzogni
parent 13e4f97c35
commit e3ca437a48
4 changed files with 67 additions and 8 deletions

View File

@ -363,7 +363,7 @@ class Tab : public Component {
return vbox({
text(L"FTXUI Demo") | bold | hcenter,
tab_selection.Render() | hcenter,
container.Render(),
container.Render() | flex,
});
}
};

View File

@ -64,6 +64,15 @@ Element hflow(Elements);
Element flex(Element); // Expand/Minimize if possible/needed.
Element flex_grow(Element); // Expand element if possible.
Element flex_shrink(Element); // Minimize element if needed.
Element xflex(Element); // Expand/Minimize if possible/needed.
Element xflex_grow(Element); // Expand element if possible.
Element xflex_shrink(Element); // Minimize element if needed.
Element yflex(Element); // Expand/Minimize if possible/needed.
Element yflex_grow(Element); // Expand element if possible.
Element yflex_shrink(Element); // Minimize element if needed.
Element notflex(Element); // Reset the flex attribute.
Element filler(); // A blank expandable element.

View File

@ -8,11 +8,11 @@
namespace ftxui {
Element hcenter(Element child) {
return hbox(filler(), std::move(child), filler()) | flex_grow;
return hbox(filler(), std::move(child), filler()) | xflex_grow;
}
Element vcenter(Element child) {
return vbox(filler(), std::move(child), filler()) | flex_grow;
return vbox(filler(), std::move(child), filler()) | yflex_grow;
}
Element center(Element child) {

View File

@ -14,11 +14,27 @@ void function_flex_grow(Requirement& r) {
r.flex_grow_y = 1;
}
void function_xflex_grow(Requirement& r) {
r.flex_grow_x = 1;
}
void function_yflex_grow(Requirement& r) {
r.flex_grow_y = 1;
}
void function_flex_shrink(Requirement& r) {
r.flex_shrink_x = 1;
r.flex_shrink_y = 1;
}
void function_xflex_shrink(Requirement& r) {
r.flex_shrink_x = 1;
}
void function_yflex_shrink(Requirement& r) {
r.flex_shrink_y = 1;
}
void function_flex(Requirement& r) {
r.flex_grow_x = 1;
r.flex_grow_y = 1;
@ -26,6 +42,16 @@ void function_flex(Requirement& r) {
r.flex_shrink_y = 1;
}
void function_xflex(Requirement& r) {
r.flex_grow_x = 1;
r.flex_shrink_x = 1;
}
void function_yflex(Requirement& r) {
r.flex_grow_y = 1;
r.flex_shrink_y = 1;
}
void function_not_flex(Requirement& r) {
r.flex_grow_x = 0;
r.flex_grow_y = 0;
@ -65,14 +91,38 @@ Element flex(Element child) {
return std::make_shared<Flex>(function_flex, std::move(child));
}
Element xflex(Element child) {
return std::make_shared<Flex>(function_xflex, std::move(child));
}
Element yflex(Element child) {
return std::make_shared<Flex>(function_yflex, std::move(child));
}
Element flex_grow(Element child) {
return std::make_shared<Flex>(function_flex_grow, std::move(child));
}
Element xflex_grow(Element child) {
return std::make_shared<Flex>(function_xflex_grow, std::move(child));
}
Element yflex_grow(Element child) {
return std::make_shared<Flex>(function_yflex_grow, std::move(child));
}
Element flex_shrink(Element child) {
return std::make_shared<Flex>(function_flex_shrink, std::move(child));
}
Element xflex_shrink(Element child) {
return std::make_shared<Flex>(function_xflex_shrink, std::move(child));
}
Element yflex_shrink(Element child) {
return std::make_shared<Flex>(function_yflex_shrink, std::move(child));
}
Element notflex(Element child) {
return std::make_shared<Flex>(function_not_flex, std::move(child));
}