diff --git a/examples/component/homescreen.cpp b/examples/component/homescreen.cpp index 834faaf..33c129c 100644 --- a/examples/component/homescreen.cpp +++ b/examples/component/homescreen.cpp @@ -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, }); } }; diff --git a/include/ftxui/dom/elements.hpp b/include/ftxui/dom/elements.hpp index a3c0c91..d80afff 100644 --- a/include/ftxui/dom/elements.hpp +++ b/include/ftxui/dom/elements.hpp @@ -61,11 +61,20 @@ Element hflow(Elements); // -- Flexibility --- // Define how to share the remaining space when not all of it is used inside a // container. -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 notflex(Element); // Reset the flex attribute. -Element filler(); // A blank expandable element. +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. // -- Size override; enum Direction { WIDTH, HEIGHT }; diff --git a/src/ftxui/dom/composite_decorator.cpp b/src/ftxui/dom/composite_decorator.cpp index 23deb58..0333ceb 100644 --- a/src/ftxui/dom/composite_decorator.cpp +++ b/src/ftxui/dom/composite_decorator.cpp @@ -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) { diff --git a/src/ftxui/dom/flex.cpp b/src/ftxui/dom/flex.cpp index 48e1cec..d075d63 100644 --- a/src/ftxui/dom/flex.cpp +++ b/src/ftxui/dom/flex.cpp @@ -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(function_flex, std::move(child)); } +Element xflex(Element child) { + return std::make_shared(function_xflex, std::move(child)); +} + +Element yflex(Element child) { + return std::make_shared(function_yflex, std::move(child)); +} + Element flex_grow(Element child) { return std::make_shared(function_flex_grow, std::move(child)); } +Element xflex_grow(Element child) { + return std::make_shared(function_xflex_grow, std::move(child)); +} + +Element yflex_grow(Element child) { + return std::make_shared(function_yflex_grow, std::move(child)); +} + Element flex_shrink(Element child) { return std::make_shared(function_flex_shrink, std::move(child)); } +Element xflex_shrink(Element child) { + return std::make_shared(function_xflex_shrink, std::move(child)); +} + +Element yflex_shrink(Element child) { + return std::make_shared(function_yflex_shrink, std::move(child)); +} + Element notflex(Element child) { return std::make_shared(function_not_flex, std::move(child)); }