FTXUI
6.1.9
C++ functional terminal UI.
Toggle main menu visibility
Loading...
Searching...
No Matches
reflect.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 <memory>
// for make_shared, __shared_ptr_access
5
#include <utility>
// for move
6
7
#include "
ftxui/dom/elements.hpp
"
// for Element, unpack, Decorator, reflect
8
#include "
ftxui/dom/node.hpp
"
// for Node, Elements
9
#include "
ftxui/dom/requirement.hpp
"
// for Requirement
10
#include "
ftxui/screen/box.hpp
"
// for Box
11
#include "
ftxui/screen/screen.hpp
"
// for Screen
12
13
namespace
ftxui
{
14
namespace
{
15
16
// Helper class.
17
class
Reflect :
public
Node
{
18
public
:
19
Reflect(
Element
child, Box& box)
20
: Node(unpack(std::move(child))), reflected_box_(box) {}
21
22
void
ComputeRequirement() final {
23
Node::ComputeRequirement
();
24
requirement_ = children_[0]->requirement();
25
}
26
27
void
SetBox(Box box)
final
{
28
reflected_box_ = box;
29
Node::SetBox
(box);
30
children_[0]->SetBox(box);
31
}
32
33
void
Render
(Screen& screen)
final
{
34
reflected_box_ =
Box::Intersection
(screen.stencil, reflected_box_);
35
Node::Render
(screen);
36
}
37
38
private
:
39
Box& reflected_box_;
40
};
41
}
// namespace
42
43
Decorator
reflect
(
Box
& box) {
44
return
[&](
Element
child) ->
Element
{
45
return
std::make_shared<Reflect>(std::move(child), box);
46
};
47
}
48
49
}
// namespace ftxui
box.hpp
ftxui::Node
Definition
node.hpp:23
ftxui::Node::SetBox
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition
node.cpp:43
ftxui::Node::ComputeRequirement
virtual void ComputeRequirement()
Compute how much space an elements needs.
Definition
node.cpp:21
ftxui::Node::Render
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition
node.cpp:63
elements.hpp
ftxui
Definition
animation.hpp:10
ftxui::Decorator
std::function< Element(Element)> Decorator
Definition
elements.hpp:24
ftxui::Element
std::shared_ptr< Node > Element
Definition
elements.hpp:22
ftxui::reflect
Decorator reflect(Box &box)
Definition
reflect.cpp:43
ftxui::Render
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition
node.cpp:88
node.hpp
requirement.hpp
screen.hpp
ftxui::Box
Definition
box.hpp:9
ftxui::Box::Intersection
static auto Intersection(Box a, Box b) -> Box
Definition
box.cpp:12