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