17class DBox :
public Node {
19 explicit DBox(
Elements children) : Node(std::move(children)) {}
21 void ComputeRequirement()
override {
22 requirement_.min_x = 0;
23 requirement_.min_y = 0;
24 requirement_.flex_grow_x = 0;
25 requirement_.flex_grow_y = 0;
26 requirement_.flex_shrink_x = 0;
27 requirement_.flex_shrink_y = 0;
29 for (
auto& child : children_) {
30 child->ComputeRequirement();
32 std::max(requirement_.min_x, child->requirement().min_x);
34 std::max(requirement_.min_y, child->requirement().min_y);
36 if (requirement_.selection < child->requirement().selection) {
37 requirement_.selection = child->requirement().selection;
38 requirement_.selected_box = child->requirement().selected_box;
43 void SetBox(Box box)
override {
46 for (
auto& child : children_) {
51 void Render(Screen& screen)
override {
52 if (children_.size() <= 1) {
56 const int width = box_.x_max - box_.x_min + 1;
57 const int height = box_.y_max - box_.y_min + 1;
58 std::vector<Pixel> pixels(width * height);
60 for (
auto& child : children_) {
61 child->Render(screen);
64 Pixel* acc = pixels.data();
65 for (
int x = 0; x < width; ++x) {
66 for (
int y = 0; y < height; ++y) {
67 auto& pixel = screen.PixelAt(x + box_.x_min, y + box_.y_min);
68 acc->background_color =
69 Color::Blend(acc->background_color, pixel.background_color);
70 acc->automerge = pixel.automerge;
71 if (pixel.character ==
" ") {
72 acc->foreground_color =
73 Color::Blend(acc->foreground_color, pixel.background_color);
75 acc->blink = pixel.blink;
76 acc->bold = pixel.bold;
78 acc->inverted = pixel.inverted;
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.
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.