15using FlexFunction = void (*)(Requirement&);
17void function_flex_grow(Requirement& r) {
22void function_xflex_grow(Requirement& r) {
26void function_yflex_grow(Requirement& r) {
30void function_flex_shrink(Requirement& r) {
35void function_xflex_shrink(Requirement& r) {
39void function_yflex_shrink(Requirement& r) {
43void function_flex(Requirement& r) {
50void function_xflex(Requirement& r) {
55void function_yflex(Requirement& r) {
60void function_not_flex(Requirement& r) {
67class Flex :
public Node {
69 explicit Flex(FlexFunction f) :
f_(f) {}
70 Flex(FlexFunction f,
Element child) : Node(unpack(std::move(child))),
f_(f) {}
71 void ComputeRequirement()
override {
72 requirement_.min_x = 0;
73 requirement_.min_y = 0;
74 if (!children_.empty()) {
75 children_[0]->ComputeRequirement();
76 requirement_ = children_[0]->requirement();
81 void SetBox(Box box)
override {
83 if (children_.empty()) {
86 children_[0]->SetBox(box);
97 return std::make_shared<Flex>(function_flex);
121 return std::make_shared<Flex>(function_flex, std::move(child));
127 return std::make_shared<Flex>(function_xflex, std::move(child));
133 return std::make_shared<Flex>(function_yflex, std::move(child));
139 return std::make_shared<Flex>(function_flex_grow, std::move(child));
145 return std::make_shared<Flex>(function_xflex_grow, std::move(child));
151 return std::make_shared<Flex>(function_yflex_grow, std::move(child));
157 return std::make_shared<Flex>(function_flex_shrink, std::move(child));
163 return std::make_shared<Flex>(function_xflex_shrink, std::move(child));
169 return std::make_shared<Flex>(function_yflex_shrink, std::move(child));
175 return std::make_shared<Flex>(function_not_flex, std::move(child));
virtual void SetBox(Box box)
为绘图元素分配位置和尺寸。
Element xflex(Element)
在 X 轴上尽可能地扩展/收缩。
Element xflex_grow(Element)
如果可能,在 X 轴上进行扩展。
Element flex(Element)
使子元素按比例扩展以填充容器中剩余的空间。
Element yflex(Element)
在 Y 轴上尽可能地扩展/收缩。
Element flex_shrink(Element)
如果需要,进行收缩。
Element yflex_grow(Element)
如果可能,在 Y 轴上进行扩展。
Element flex_grow(Element)
如果可能,进行扩展。
Element notflex(Element)
使元素不可伸缩。
Element xflex_shrink(Element)
如果需要,在 X 轴上进行收缩。
Element filler()
一个元素,它将按比例扩展以填充容器中剩余的空间。
Element yflex_shrink(Element)
如果需要,在 Y 轴上进行收缩。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::shared_ptr< Node > Element