FTXUI  0.11.1
C++ functional terminal UI.
reflect.cpp
Go to the documentation of this file.
1 #include <memory> // for make_shared, __shared_ptr_access
2 #include <utility> // for move
3 #include <vector> // for __alloc_traits<>::value_type
4 
5 #include "ftxui/dom/elements.hpp" // for Element, unpack, Decorator, reflect
6 #include "ftxui/dom/node.hpp" // for Node, Elements
7 #include "ftxui/dom/requirement.hpp" // for Requirement
8 #include "ftxui/screen/box.hpp" // for Box
9 #include "ftxui/screen/screen.hpp" // for Screen
10 
11 namespace ftxui {
12 
13 // Helper class.
14 class Reflect : public Node {
15  public:
16  Reflect(Element child, Box& box)
17  : Node(unpack(std::move(child))), reflected_box_(box) {}
18 
19  void ComputeRequirement() final {
21  requirement_ = children_[0]->requirement();
22  }
23 
24  void SetBox(Box box) final {
25  reflected_box_ = box;
26  Node::SetBox(box);
27  children_[0]->SetBox(box);
28  }
29 
30  void Render(Screen& screen) final {
31  reflected_box_ = Box::Intersection(screen.stencil, reflected_box_);
32  return Node::Render(screen);
33  }
34 
35  private:
36  Box& reflected_box_;
37 };
38 
40  return [&](Element child) -> Element {
41  return std::make_shared<Reflect>(std::move(child), box);
42  };
43 }
44 
45 } // namespace ftxui
46 
47 // Copyright 2020 Arthur Sonzogni. All rights reserved.
48 // Use of this source code is governed by the MIT license that can be found in
49 // the LICENSE file.
Node()
Definition: node.cpp:8
Elements children_
Definition: node.hpp:48
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
virtual void ComputeRequirement()
Compute how much space an elements needs.
Definition: node.cpp:14
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition: node.cpp:27
std::function< Element(Element)> Decorator
Definition: elements.hpp:18
std::shared_ptr< Node > Element
Definition: elements.hpp:16
Decorator reflect(Box &box)
Definition: reflect.cpp:39
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
Definition: node.cpp:40
static Box Intersection(Box a, Box b)
Definition: box.cpp:9