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