45FlexboxConfig
Normalize(FlexboxConfig config) {
53class Flexbox :
public Node {
59 requirement_.flex_grow_x = 1;
60 requirement_.flex_grow_y = 0;
63 std::swap(requirement_.flex_grow_x, requirement_.flex_grow_y);
74 global.blocks.reserve(children_.size());
75 for (
auto&
child : children_) {
76 flexbox_helper::Block
block;
80 block.flex_grow_x =
child->requirement().flex_grow_x;
81 block.flex_grow_y =
child->requirement().flex_grow_y;
82 block.flex_shrink_x =
child->requirement().flex_shrink_x;
83 block.flex_shrink_y =
child->requirement().flex_shrink_y;
91 void ComputeRequirement()
override {
92 for (
auto&
child : children_) {
93 child->ComputeRequirement();
95 flexbox_helper::Global
global;
96 global.config = config_normalized_;
108 requirement_.selected_box = Box();
109 requirement_.min_x = 0;
110 requirement_.min_y = 0;
112 if (
global.blocks.empty()) {
122 for (
auto& b :
global.blocks) {
123 box.x_min = std::min(
box.x_min, b.x);
124 box.y_min = std::min(
box.y_min, b.y);
125 box.x_max = std::max(
box.x_max, b.x + b.dim_x);
126 box.y_max = std::max(
box.y_max, b.y + b.dim_y);
128 requirement_.min_x =
box.x_max -
box.x_min;
129 requirement_.min_y =
box.y_max -
box.y_min;
132 for (
size_t i = 0; i < children_.size(); ++i) {
133 if (requirement_.selection >= children_[i]->requirement().selection) {
136 requirement_.selection = children_[i]->requirement().selection;
137 Box selected_box = children_[i]->requirement().selected_box;
140 auto& b =
global.blocks[i];
141 selected_box.x_min += b.x;
142 selected_box.y_min += b.y;
143 selected_box.x_max += b.x;
144 selected_box.y_max += b.y;
149 void SetBox(Box
box)
override {
154 :
box.x_max -
box.x_min + 1);
157 flexbox_helper::Global
global;
163 for (
size_t i = 0; i < children_.size(); ++i) {
164 auto&
child = children_[i];
165 auto& b =
global.blocks[i];
180 void Check(Status*
status)
override {
181 for (
auto&
child : children_) {
185 if (
status->iteration == 0) {
187 need_iteration_ =
true;
190 status->need_iteration |= need_iteration_;
194 bool need_iteration_ =
true;
195 const FlexboxConfig config_;
196 const FlexboxConfig config_normalized_;
222 return std::make_shared<Flexbox>(std::move(
children), config);
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
void Compute(Global &global)
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
std::shared_ptr< Node > Element
std::shared_ptr< T > Make(Args &&... args)
std::vector< Element > Elements
static auto Intersection(Box a, Box b) -> Box
@ FlexStart
items are placed at the start of the cross axis.
@ Column
Flex items are laid out in a column.
@ Row
Flex items are laid out in a row.
@ RowInversed
Flex items are laid out in a row, but in reverse order.
@ Wrap
Flex items will wrap onto multiple lines.
@ FlexStart
Items are aligned to the start of flexbox's direction.