Popups (overwrite regions)
Ratatui renders text in the order that the application writes to the buffer. This means that earlier instructions will be overwritten by later ones. However, it’s important to note that widgets do not always clear every cell in the area that they are rendering to. This may cause symbols and styles that were previously rendered to the buffer to “bleed” through into the cells that are rendered on top of those cells.
The following code exhibits this problem:
Notice that the background color (black in this case), the italics, and the lorem ipsum background text show through the popup.
This problem is easy to prevent by rendering a Clear
widget prior to rendering the main popup.
Here is an example of how to use this technique to create a Popup
widget:
We can use the new Popup
widget with the following code:
Which results in the following:
Notice that the background is set to the default background and there are no italics or symbols from the background text.
Full source for this article is available at https://github.com/ratatui/ratatui-website/tree/main/code/how-to-overwrite-regions