Loading...
Searching...
No Matches
reflect.cpp
Go to the documentation of this file.
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#include <memory> // for make_shared, __shared_ptr_access
#include <utility> // for move
#include "ftxui/dom/elements.hpp" // for Element, unpack, Decorator, reflect
#include "ftxui/dom/node.hpp" // for Node, Elements
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/screen.hpp" // for Screen
namespace ftxui {
namespace {
// Helper class.
class Reflect : public Node {
public:
Reflect(Element child, Box& box)
: Node(unpack(std::move(child))), reflected_box_(box) {}
void ComputeRequirement() final {
Node::ComputeRequirement();
requirement_ = children_[0]->requirement();
}
void SetBox(Box box) final {
reflected_box_ = box;
Node::SetBox(box);
children_[0]->SetBox(box);
}
void Render(Screen& screen) final {
reflected_box_ = Box::Intersection(screen.stencil, reflected_box_);
Node::Render(screen);
}
private:
Box& reflected_box_;
};
} // namespace
Decorator reflect(Box& box) {
return [&](Element child) -> Element {
return std::make_shared<Reflect>(std::move(child), box);
};
}
} // namespace ftxui
box.hpp
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
friend void Render(Screen &screen, Node *node, Selection &selection)
Definition node.cpp:100
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::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
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