17class Size :
public Node {
21 direction_(direction),
25 void ComputeRequirement()
override {
27 requirement_ = children_[0]->requirement();
29 auto& value = direction_ ==
WIDTH ? requirement_.min_x : requirement_.min_y;
31 switch (constraint_) {
33 value = std::min(value, value_);
39 value = std::max(value, value_);
43 if (direction_ ==
WIDTH) {
44 requirement_.flex_grow_x = 0;
45 requirement_.flex_shrink_x = 0;
47 requirement_.flex_grow_y = 0;
48 requirement_.flex_shrink_y = 0;
52 void SetBox(Box
box)
override {
55 if (direction_ ==
WIDTH) {
56 switch (constraint_) {
59 box.x_max = std::min(
box.x_min + value_ + 1,
box.x_max);
65 switch (constraint_) {
68 box.y_max = std::min(
box.y_min + value_ + 1,
box.y_max);
74 children_[0]->SetBox(
box);
92 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
Component Slider(SliderOption< T > options)
A slider in any direction.