FTXUI  5.0.0
C++ functional terminal UI.
dbox.cpp
Go to the documentation of this file.
1 // Copyright 2020 Arthur Sonzogni. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be found in
3 // the LICENSE file.
4 #include <algorithm> // for max
5 #include <memory> // for __shared_ptr_access, shared_ptr, make_shared
6 #include <utility> // for move
7 #include <vector> // for vector
8 
9 #include "ftxui/dom/elements.hpp" // for Element, Elements, dbox
10 #include "ftxui/dom/node.hpp" // for Node, Elements
11 #include "ftxui/dom/requirement.hpp" // for Requirement
12 #include "ftxui/screen/box.hpp" // for Box
13 
14 namespace ftxui {
15 
16 namespace {
17 class DBox : public Node {
18  public:
19  explicit DBox(Elements children) : Node(std::move(children)) {}
20 
21  void ComputeRequirement() override {
22  requirement_.min_x = 0;
23  requirement_.min_y = 0;
24  requirement_.flex_grow_x = 0;
25  requirement_.flex_grow_y = 0;
26  requirement_.flex_shrink_x = 0;
27  requirement_.flex_shrink_y = 0;
28  requirement_.selection = Requirement::NORMAL;
29  for (auto& child : children_) {
30  child->ComputeRequirement();
31  requirement_.min_x =
32  std::max(requirement_.min_x, child->requirement().min_x);
33  requirement_.min_y =
34  std::max(requirement_.min_y, child->requirement().min_y);
35 
36  if (requirement_.selection < child->requirement().selection) {
37  requirement_.selection = child->requirement().selection;
38  requirement_.selected_box = child->requirement().selected_box;
39  }
40  }
41  }
42 
43  void SetBox(Box box) override {
44  Node::SetBox(box);
45 
46  for (auto& child : children_) {
47  child->SetBox(box);
48  }
49  }
50 };
51 } // namespace
52 
53 /// @brief Stack several element on top of each other.
54 /// @param children_ The input element.
55 /// @return The right aligned element.
56 /// @ingroup dom
57 Element dbox(Elements children_) {
58  return std::make_shared<DBox>(std::move(children_));
59 }
60 
61 } // namespace ftxui
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition: node.cpp:26
std::shared_ptr< Node > Element
Definition: elements.hpp:23
std::vector< Element > Elements
Definition: elements.hpp:24
Element dbox(Elements)
Stack several element on top of each other.
Definition: dbox.cpp:57