19class DBox :
public Node {
21 explicit DBox(
Elements children) : Node(std::move(children)) {}
23 void ComputeRequirement()
override {
24 requirement_ = Requirement{};
25 for (
auto& child : children_) {
26 child->ComputeRequirement();
29 if (requirement_.focused.Prefer(child->requirement().focused)) {
30 requirement_.focused = child->requirement().focused;
35 std::max(requirement_.min_x, child->requirement().min_x);
37 std::max(requirement_.min_y, child->requirement().min_y);
41 void SetBox(Box box)
override {
44 for (
auto& child : children_) {
49 void Render(Screen& screen)
override {
50 if (children_.size() <= 1) {
55 const int width = box_.x_max - box_.x_min + 1;
56 const int height = box_.y_max - box_.y_min + 1;
57 std::vector<Pixel> pixels(std::size_t(width * height));
59 for (
auto& child : children_) {
60 child->Render(screen);
63 Pixel* acc = pixels.data();
64 for (
int x = 0; x < width; ++x) {
65 for (
int y = 0; y < height; ++y) {
66 auto& pixel = screen.PixelAt(x + box_.x_min, y + box_.y_min);
67 acc->background_color =
68 Color::Blend(acc->background_color, pixel.background_color);
69 acc->automerge = pixel.automerge || acc->automerge;
70 if (pixel.character.empty()) {
71 acc->foreground_color =
72 Color::Blend(acc->foreground_color, pixel.background_color);
74 acc->blink = pixel.blink;
75 acc->bold = pixel.bold;
77 acc->inverted = pixel.inverted;
78 acc->italic = pixel.italic;
79 acc->underlined = pixel.underlined;
80 acc->underlined_double = pixel.underlined_double;
81 acc->strikethrough = pixel.strikethrough;
82 acc->hyperlink = pixel.hyperlink;
83 acc->character = pixel.character;
84 acc->foreground_color = pixel.foreground_color;
94 Pixel* acc = pixels.data();
95 for (
int x = 0; x < width; ++x) {
96 for (
int y = 0; y < height; ++y) {
97 screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++;
109 return std::make_shared<DBox>(std::move(children_));
static Color Blend(const Color &lhs, const Color &rhs)
Blend two colors together using the alpha channel.
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
friend void Render(Screen &screen, Node *node, Selection &selection)
std::shared_ptr< Node > Element
std::vector< Element > Elements
Element dbox(Elements)
Stack several element on top of each other.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.