19 class DBox :
public Node {
21 explicit DBox(
Elements children) : Node(std::move(children)) {}
23 void ComputeRequirement()
override {
24 requirement_.min_x = 0;
25 requirement_.min_y = 0;
26 requirement_.flex_grow_x = 0;
27 requirement_.flex_grow_y = 0;
28 requirement_.flex_shrink_x = 0;
29 requirement_.flex_shrink_y = 0;
31 for (
auto& child : children_) {
32 child->ComputeRequirement();
34 std::max(requirement_.min_x, child->requirement().min_x);
36 std::max(requirement_.min_y, child->requirement().min_y);
38 if (requirement_.selection < child->requirement().selection) {
39 requirement_.selection = child->requirement().selection;
40 requirement_.selected_box = child->requirement().selected_box;
45 void SetBox(Box box)
override {
48 for (
auto& child : children_) {
53 void Render(Screen& screen)
override {
54 if (children_.size() <= 1) {
59 const int width = box_.x_max - box_.x_min + 1;
60 const int height = box_.y_max - box_.y_min + 1;
61 std::vector<Pixel> pixels(std::size_t(width * height));
63 for (
auto& child : children_) {
64 child->Render(screen);
67 Pixel* acc = pixels.data();
68 for (
int x = 0; x < width; ++x) {
69 for (
int y = 0; y < height; ++y) {
70 auto& pixel = screen.PixelAt(x + box_.x_min, y + box_.y_min);
71 acc->background_color =
72 Color::Blend(acc->background_color, pixel.background_color);
73 acc->automerge = pixel.automerge || acc->automerge;
74 if (pixel.character.empty()) {
75 acc->foreground_color =
76 Color::Blend(acc->foreground_color, pixel.background_color);
78 acc->blink = pixel.blink;
79 acc->bold = pixel.bold;
81 acc->inverted = pixel.inverted;
82 acc->underlined = pixel.underlined;
83 acc->underlined_double = pixel.underlined_double;
84 acc->strikethrough = pixel.strikethrough;
85 acc->hyperlink = pixel.hyperlink;
86 acc->character = pixel.character;
87 acc->foreground_color = pixel.foreground_color;
97 Pixel* acc = pixels.data();
98 for (
int x = 0; x < width; ++x) {
99 for (
int y = 0; y < height; ++y) {
100 screen.PixelAt(x + box_.x_min, y + box_.y_min) = *acc++;
112 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.
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
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.