19class HBox :
public Node {
23 void ComputeRequirement()
override {
24 requirement_.min_x = 0;
25 requirement_.min_y = 0;
26 requirement_.flex_grow_x = 0;
27 requirement_.flex_grow_y = 0;
28 requirement_.flex_shrink_x = 0;
29 requirement_.flex_shrink_y = 0;
31 for (
auto&
child : children_) {
32 child->ComputeRequirement();
33 if (requirement_.selection <
child->requirement().selection) {
34 requirement_.selection =
child->requirement().selection;
35 requirement_.selected_box =
child->requirement().selected_box;
36 requirement_.selected_box.x_min += requirement_.min_x;
37 requirement_.selected_box.x_max += requirement_.min_x;
39 requirement_.min_x +=
child->requirement().min_x;
41 std::max(requirement_.min_y,
child->requirement().min_y);
45 void SetBox(Box
box)
override {
48 std::vector<box_helper::Element>
elements(children_.size());
49 for (
size_t i = 0; i < children_.size(); ++i) {
51 const auto& requirement = children_[i]->requirement();
52 element.min_size = requirement.min_x;
53 element.flex_grow = requirement.flex_grow_x;
54 element.flex_shrink = requirement.flex_shrink_x;
60 for (
size_t i = 0; i < children_.size(); ++i) {
63 children_[i]->SetBox(
box);
84 return std::make_shared<HBox>(std::move(
children));
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
void Compute(std::vector< Element > *elements, int target_size)
std::shared_ptr< Node > Element
std::shared_ptr< T > Make(Args &&... args)
Element hbox(Elements)
A container displaying elements horizontally one by one.
std::vector< Element > Elements