Not underline-ing empty spaces / NodeDecorator not part of the API #346
-
Hi! I was a bit annoyed that the Also is there maybe a way to achieve what I want more elegantly? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I try to expose as little as possible and mostly function, because it is easy to keep supporting API with function. It is harder with classes. NodeDecorator does not much, outside of wrapping another Node and passing/copying data about its size. With the provided API, you should be able to achieve what you want. Element underline2(Element child) {
class Impl : public Node {
public:
Impl(Element child) : Node(unpack(std::move(child))) {}
void ComputeRequirement() override {
Node::ComputeRequirement();
requirement_ = children_[0]->requirement();
}
void NodeDecorator::SetBox(Box box) override {
Node::SetBox(box);
children_[0]->SetBox(box);
}
void Render(Screen& screen) override {
Node::Render(screen);
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
auto& cell = screen.PixelAt(x,y);
if (cell.character != " ")
cell.underlined = true;
}
}
}
};
return std::make_shared<Impl>(std::move(child));
}
|
Beta Was this translation helpful? Give feedback.
I try to expose as little as possible and mostly function, because it is easy to keep supporting API with function. It is harder with classes.
NodeDecorator does not much, outside of wrapping another Node and passing/copying data about its size.
With the provided API, you should be able to achieve what you want.