FTXUI  5.0.0
C++ functional terminal UI.
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
13namespace ftxui {
14namespace {
15
16// Helper class.
17class 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 {
24 requirement_ = children_[0]->requirement();
25 }
26
27 void SetBox(Box box) final {
28 reflected_box_ = box;
30 children_[0]->SetBox(box);
31 }
32
33 void Render(Screen& screen) final {
34 reflected_box_ = Box::Intersection(screen.stencil, reflected_box_);
36 }
37
38 private:
39 Box& reflected_box_;
40};
41} // namespace
42
44 return [&](Element child) -> Element {
45 return std::make_shared<Reflect>(std::move(child), box);
46 };
47}
48
49} // namespace ftxui
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition node.cpp:26
virtual void ComputeRequirement()
Compute how much space an elements needs.
Definition node.cpp:18
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:32
std::function< Element(Element)> Decorator
Definition elements.hpp:24
std::shared_ptr< Node > Element
Definition elements.hpp:22
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
Decorator reflect(Box &box)
Definition reflect.cpp:43
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition node.cpp:47
static auto Intersection(Box a, Box b) -> Box
Definition box.cpp:12