diff options
author | Blaž Hrastnik | 2021-05-09 08:52:55 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-05-09 08:52:55 +0000 |
commit | 35606a3daa7ee273845a12f3e03728e0ae23928e (patch) | |
tree | 643684eaff6627dbebc4156d33fdb541bf87bbd9 /helix-tui/src/widgets/clear.rs | |
parent | 6c705f09e88a4b63c4ed854bc9e956b0539ca8af (diff) |
Inline tui as helix-tui fork.
We only rely on some of the rendering primitives and implement our
Cursive-style compositor on top.
Diffstat (limited to 'helix-tui/src/widgets/clear.rs')
-rw-r--r-- | helix-tui/src/widgets/clear.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/helix-tui/src/widgets/clear.rs b/helix-tui/src/widgets/clear.rs new file mode 100644 index 00000000..d1da40de --- /dev/null +++ b/helix-tui/src/widgets/clear.rs @@ -0,0 +1,36 @@ +use crate::buffer::Buffer; +use crate::layout::Rect; +use crate::widgets::Widget; + +/// A widget to to clear/reset a certain area to allow overdrawing (e.g. for popups) +/// +/// # Examples +/// +/// ``` +/// # use helix_tui::widgets::{Clear, Block, Borders}; +/// # use helix_tui::layout::Rect; +/// # use helix_tui::Frame; +/// # use helix_tui::backend::Backend; +/// fn draw_on_clear<B: Backend>(f: &mut Frame<B>, area: Rect) { +/// let block = Block::default().title("Block").borders(Borders::ALL); +/// f.render_widget(Clear, area); // <- this will clear/reset the area first +/// f.render_widget(block, area); // now render the block widget +/// } +/// ``` +/// +/// # Popup Example +/// +/// For a more complete example how to utilize `Clear` to realize popups see +/// the example `examples/popup.rs` +#[derive(Debug, Clone)] +pub struct Clear; + +impl Widget for Clear { + fn render(self, area: Rect, buf: &mut Buffer) { + for x in area.left()..area.right() { + for y in area.top()..area.bottom() { + buf.get_mut(x, y).reset(); + } + } + } +} |