FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
reflect.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni。保留所有权利。
2// 本源代码的使用受 MIT 许可证的约束,该许可证可在
3// LICENSE 文件中找到。
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// 辅助类。
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;
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
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)
为绘图元素分配位置和尺寸。
virtual void ComputeRequirement()
计算元素所需的空间。
friend void Render(Screen &screen, Node *node, Selection &selection)
void Render(Screen &screen, const Element &element)
在 ftxui::Screen 上显示元素。
static auto Intersection(Box a, Box b) -> Box
定义 box.cpp:11
Box是一个表示2D空间中矩形区域的结构体。
定义 box.hpp:15
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::function< Element(Element)> Decorator
std::shared_ptr< Node > Element
Decorator reflect(Box &box)