2023-08-19 19:56:36 +08:00
|
|
|
// 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.
|
2021-05-15 04:00:49 +08:00
|
|
|
#include <memory> // for make_shared, __shared_ptr_access
|
|
|
|
#include <utility> // for move
|
2021-05-10 02:32:27 +08:00
|
|
|
|
|
|
|
#include "ftxui/dom/elements.hpp" // for Element, unpack, Decorator, reflect
|
2021-09-17 02:45:26 +08:00
|
|
|
#include "ftxui/dom/node.hpp" // for Node, Elements
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
|
|
|
#include "ftxui/screen/box.hpp" // for Box
|
2021-09-17 02:45:26 +08:00
|
|
|
#include "ftxui/screen/screen.hpp" // for Screen
|
2021-04-19 04:33:41 +08:00
|
|
|
|
|
|
|
namespace ftxui {
|
2023-08-19 20:56:28 +08:00
|
|
|
namespace {
|
2021-04-19 04:33:41 +08:00
|
|
|
|
|
|
|
// Helper class.
|
|
|
|
class Reflect : public Node {
|
|
|
|
public:
|
|
|
|
Reflect(Element child, Box& box)
|
2021-05-16 23:18:11 +08:00
|
|
|
: Node(unpack(std::move(child))), reflected_box_(box) {}
|
2021-04-19 04:33:41 +08:00
|
|
|
|
|
|
|
void ComputeRequirement() final {
|
|
|
|
Node::ComputeRequirement();
|
2021-05-16 23:18:11 +08:00
|
|
|
requirement_ = children_[0]->requirement();
|
2021-04-19 04:33:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetBox(Box box) final {
|
2021-05-16 23:18:11 +08:00
|
|
|
reflected_box_ = box;
|
2021-09-08 15:36:37 +08:00
|
|
|
Node::SetBox(box);
|
|
|
|
children_[0]->SetBox(box);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Render(Screen& screen) final {
|
|
|
|
reflected_box_ = Box::Intersection(screen.stencil, reflected_box_);
|
2024-08-16 17:19:51 +08:00
|
|
|
Node::Render(screen);
|
2021-04-19 04:33:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-05-16 23:18:11 +08:00
|
|
|
Box& reflected_box_;
|
2021-04-19 04:33:41 +08:00
|
|
|
};
|
2023-08-19 20:56:28 +08:00
|
|
|
} // namespace
|
2021-04-19 04:33:41 +08:00
|
|
|
|
|
|
|
Decorator reflect(Box& box) {
|
|
|
|
return [&](Element child) -> Element {
|
|
|
|
return std::make_shared<Reflect>(std::move(child), box);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ftxui
|