47FlexboxConfig
Normalize(FlexboxConfig config) {
55class Flexbox :
public Node {
61 requirement_.flex_grow_x = 1;
62 requirement_.flex_grow_y = 0;
65 std::swap(requirement_.flex_grow_x, requirement_.flex_grow_y);
76 global.blocks.reserve(children_.size());
77 for (
auto&
child : children_) {
78 flexbox_helper::Block
block;
82 block.flex_grow_x =
child->requirement().flex_grow_x;
83 block.flex_grow_y =
child->requirement().flex_grow_y;
84 block.flex_shrink_x =
child->requirement().flex_shrink_x;
85 block.flex_shrink_y =
child->requirement().flex_shrink_y;
93 void ComputeRequirement()
override {
94 requirement_ = Requirement{};
95 for (
auto&
child : children_) {
96 child->ComputeRequirement();
98 global_ = flexbox_helper::Global();
99 global_.config = config_normalized_;
101 global_.size_x = 100000;
102 global_.size_y = asked_;
104 global_.size_x = asked_;
105 global_.size_y = 100000;
109 if (global_.blocks.empty()) {
115 box.x_min = global_.blocks[0].x;
116 box.y_min = global_.blocks[0].y;
117 box.x_max = global_.blocks[0].x + global_.blocks[0].dim_x;
118 box.y_max = global_.blocks[0].y + global_.blocks[0].dim_y;
119 for (
auto& b : global_.blocks) {
120 box.x_min = std::min(box.x_min, b.x);
121 box.y_min = std::min(box.y_min, b.y);
122 box.x_max = std::max(box.x_max, b.x + b.dim_x);
123 box.y_max = std::max(box.y_max, b.y + b.dim_y);
125 requirement_.min_x = box.x_max - box.x_min;
126 requirement_.min_y = box.y_max - box.y_min;
129 for (
size_t i = 0; i < children_.size(); ++i) {
130 if (requirement_.focused.Prefer(children_[i]->requirement().focused)) {
131 requirement_.focused = children_[i]->requirement().focused;
133 auto& b = global_.blocks[i];
134 requirement_.focused.box.Shift(b.x, b.y);
135 requirement_.focused.box =
141 void SetBox(Box box)
override {
146 : box.x_max - box.x_min + 1);
149 flexbox_helper::Global
global;
151 global.size_x = box.x_max - box.x_min + 1;
152 global.size_y = box.y_max - box.y_min + 1;
155 for (
size_t i = 0; i < children_.size(); ++i) {
156 auto&
child = children_[i];
157 auto& b =
global.blocks[i];
172 void Select(Selection&
selection)
override {
184 for (
auto& line : global_.lines) {
186 box.x_min = box_.x_min + line.x;
187 box.x_max = box_.x_min + line.x + line.dim_x - 1;
188 box.y_min = box_.y_min + line.y;
189 box.y_max = box_.y_min + line.y + line.dim_y - 1;
201 for (
auto&
block : line.blocks) {
209 void Check(Status*
status)
override {
210 for (
auto&
child : children_) {
214 if (
status->iteration == 0) {
216 need_iteration_ =
true;
219 status->need_iteration |= need_iteration_;
223 bool need_iteration_ =
true;
224 const FlexboxConfig config_;
225 const FlexboxConfig config_normalized_;
226 flexbox_helper::Global global_;
252 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.