17using FlexFunction = void (*)(Requirement&);
19void function_flex_grow(Requirement& r) {
24void function_xflex_grow(Requirement& r) {
28void function_yflex_grow(Requirement& r) {
32void function_flex_shrink(Requirement& r) {
37void function_xflex_shrink(Requirement& r) {
41void function_yflex_shrink(Requirement& r) {
45void function_flex(Requirement& r) {
52void function_xflex(Requirement& r) {
57void function_yflex(Requirement& r) {
62void function_not_flex(Requirement& r) {
69class Flex :
public Node {
71 explicit Flex(FlexFunction f) : f_(f) {}
72 Flex(FlexFunction f,
Element child) : Node(unpack(std::move(child))), f_(f) {}
73 void ComputeRequirement()
override {
74 requirement_.min_x = 0;
75 requirement_.min_y = 0;
76 if (!children_.empty()) {
77 children_[0]->ComputeRequirement();
78 requirement_ = children_[0]->requirement();
83 void SetBox(Box box)
override {
84 if (children_.empty()) {
87 children_[0]->SetBox(box);
99 return std::make_shared<Flex>(function_flex);
124 return std::make_shared<Flex>(function_flex, std::move(child));
130 return std::make_shared<Flex>(function_xflex, std::move(child));
136 return std::make_shared<Flex>(function_yflex, std::move(child));
142 return std::make_shared<Flex>(function_flex_grow, std::move(child));
148 return std::make_shared<Flex>(function_xflex_grow, std::move(child));
154 return std::make_shared<Flex>(function_yflex_grow, std::move(child));
160 return std::make_shared<Flex>(function_flex_shrink, std::move(child));
166 return std::make_shared<Flex>(function_xflex_shrink, std::move(child));
172 return std::make_shared<Flex>(function_yflex_shrink, std::move(child));
178 return std::make_shared<Flex>(function_not_flex, std::move(child));
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Element xflex_grow(Element)
Expand if possible on the X axis.
Element flex(Element)
Make a child element to expand proportionnally to the space left in a container.
std::shared_ptr< Node > Element
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Element flex_shrink(Element)
Minimize if needed.
Element yflex_grow(Element)
Expand if possible on the Y axis.
Element flex_grow(Element)
Expand if possible.
Element notflex(Element)
Make the element not flexible.
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Element filler()
An element that will take expand proportionnally to the space left in a container.
Element yflex_shrink(Element)
Minimize if needed on the Y axis.