Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The clear_under cannot clear background color #917

Open
Chessom opened this issue Aug 15, 2024 · 2 comments
Open

The clear_under cannot clear background color #917

Chessom opened this issue Aug 15, 2024 · 2 comments

Comments

@Chessom
Copy link

Chessom commented Aug 15, 2024

Hello!
When I tested the latest ftxui (not release 5.0.0), I found that the performance of "Modal" has changed compared to release 5.0.0, as the "Modal" component does not clear the background color. Later, I discovered that there had been a change in the implementation of "Pixel" and "clear_under" due to the "Color Alpha Support".
I checked the source code and found that the render function of clear_under sets the background color of pixels to Color::Default (i.e. transparent). Due to changes in the implementation of dbox, "clear_under" does not truly clear the background color of pixels below the Node.
The first option, in my opinion, is to change the code to below in order to better match the "clear" of clear_under.

//In src/ftxui/dom/clear_under.cpp
class ClearUnder : public NodeDecorator {
 public:
  using NodeDecorator::NodeDecorator;

  void Render(Screen& screen) override {
    for (int y = box_.y_min; y <= box_.y_max; ++y) {
      for (int x = box_.x_min; x <= box_.x_max; ++x) {
        auto& pixel = screen.PixelAt(x, y);
        pixel = Pixel();
        pixel.character = " ";  // Consider the pixel written.
        pixel.background_color = Color::Opaque; //Some operations to set the background color opaque
      }
    }
    Node::Render(screen);
  }
};

The other option is to provide users with a customized option to set the content and color to be filled after clear_under (including whether background_comlor is transparent).

Element clear_under(Element element, std::string fill_content, Color c) {
  return std::make_shared<ClearUnder>(std::move(element), fill_content, c);
}

Thank you!

@ArthurSonzogni
Copy link
Owner

Hello!

Wouldn't the operation you are describing being equivalent to: x | clear_under | bgcolor(fill_content) ?

This sounds simpler to encourage composing operations instead of adding new options to this Decorator.

@Chessom
Copy link
Author

Chessom commented Aug 18, 2024

Hello!

Wouldn't the operation you are describing being equivalent to: x | clear_under | bgcolor(fill_content) ?

This sounds simpler to encourage composing operations instead of adding new options to this Decorator.

Thank you! You solved the problem that troubled me, I didn't thought of doing it this way. However, I think we should change the examples of the modal because I was confused when trying to run the modal examples, as the performance of the modal (clear_under and dbox) is different from before.
This library is really interesting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants