16class Size :
public Node {
20 direction_(direction),
24 void ComputeRequirement()
override {
26 requirement_ = children_[0]->requirement();
28 auto& value = direction_ ==
WIDTH ? requirement_.min_x : requirement_.min_y;
30 switch (constraint_) {
32 value = std::min(value, value_);
38 value = std::max(value, value_);
42 if (direction_ ==
WIDTH) {
43 requirement_.flex_grow_x = 0;
44 requirement_.flex_shrink_x = 0;
46 requirement_.flex_grow_y = 0;
47 requirement_.flex_shrink_y = 0;
51 void SetBox(Box
box)
override {
54 if (direction_ ==
WIDTH) {
55 switch (constraint_) {
58 box.x_max = std::min(
box.x_min + value_ + 1,
box.x_max);
64 switch (constraint_) {
67 box.y_max = std::min(
box.y_min + value_ + 1,
box.y_max);
73 children_[0]->SetBox(
box);
91 return std::make_shared<Size>(std::move(e), direction,
constraint, value);
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
virtual void ComputeRequirement()
Compute how much space an elements needs.
Dimensions Size()
Get the terminal size.
std::function< Element(Element)> Decorator
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
std::shared_ptr< Node > Element
std::shared_ptr< T > Make(Args &&... args)