on master help sign in
Replace the Clear widget with buffer.clear/clear_with.
ff4c1d0Blaž Hrastnik
helix-term/src/ui/completion.rs+1−8
@@ -202,14 +202,7 @@ impl Component for Completion {
202
202
203 // clear area
203 // clear area
204 let background = cx.editor.theme.get("ui.popup");
204 let background = cx.editor.theme.get("ui.popup");
205− for y in area.top()..area.bottom() {
205+ surface.clear_with(area, background);
206− for x in area.left()..area.right() {
207− let cell = surface.get_mut(x, y);
208− cell.reset();
209− // cell.symbol.clear();
210− cell.set_style(background);
211− }
212− }
213 doc.render(area, surface, cx);
206 doc.render(area, surface, cx);
214 }
207 }
215 None => (),
208 None => (),
helix-term/src/ui/picker.rs+1−8
@@ -205,14 +205,7 @@ impl<T: 'static> Component for Picker<T> {
205
205
206 // clear area
206 // clear area
207 let background = cx.editor.theme.get("ui.background");
207 let background = cx.editor.theme.get("ui.background");
208− for y in area.top()..area.bottom() {
208+ surface.clear_with(area, background);
209− for x in area.left()..area.right() {
210− let cell = surface.get_mut(x, y);
211− cell.reset();
212− // cell.symbol.clear();
213− cell.set_style(background);
214− }
215− }
216
209
217 use tui::widgets::Widget;
210 use tui::widgets::Widget;
218 // don't like this but the lifetime sucks
211 // don't like this but the lifetime sucks
helix-term/src/ui/popup.rs+1−8
@@ -148,14 +148,7 @@ impl<T: Component> Component for Popup<T> {
148
148
149 // clear area
149 // clear area
150 let background = cx.editor.theme.get("ui.popup");
150 let background = cx.editor.theme.get("ui.popup");
151− for y in area.top()..area.bottom() {
151+ surface.clear_with(area, background);
152− for x in area.left()..area.right() {
153− let cell = surface.get_mut(x, y);
154− cell.reset();
155− // cell.symbol.clear();
156− cell.set_style(background);
157− }
158− }
159
152
160 self.contents.render(area, surface, cx);
153 self.contents.render(area, surface, cx);
161 }
154 }
helix-term/src/ui/prompt.rs+2−14
@@ -126,13 +126,7 @@ impl Prompt {
126 let area = completion_area;
126 let area = completion_area;
127 let background = theme.get("ui.statusline");
127 let background = theme.get("ui.statusline");
128
128
129− for y in area.top()..area.bottom() {
129+ surface.clear_with(area, background);
130− for x in area.left()..area.right() {
131− let cell = surface.get_mut(x, y);
132− cell.reset();
133− cell.set_style(background);
134− }
135− }
136
130
137 let mut row = 0;
131 let mut row = 0;
138 let mut col = 0;
132 let mut col = 0;
@@ -172,13 +166,7 @@ impl Prompt {
172 );
166 );
173
167
174 let background = theme.get("ui.window");
168 let background = theme.get("ui.window");
175− for y in area.top()..area.bottom() {
169+ surface.clear_with(area, background);
176− for x in area.left()..area.right() {
177− let cell = surface.get_mut(x, y);
178− cell.reset();
179− cell.set_style(background);
180− }
181− }
182
170
183 use tui::layout::Margin;
171 use tui::layout::Margin;
184 text.render(
172 text.render(
helix-tui/src/buffer.rs+20
@@ -379,6 +379,26 @@ impl Buffer {
379 }
379 }
380 }
380 }
381
381
382+ /// Clear an area in the buffer
383+ pub fn clear(&mut self, area: Rect) {
384+ for x in area.left()..area.right() {
385+ for y in area.top()..area.bottom() {
386+ self.get_mut(x, y).reset();
387+ }
388+ }
389+ }
390+
391+ /// Clear an area in the buffer with a default style.
392+ pub fn clear_with(&mut self, area: Rect, style: Style) {
393+ for x in area.left()..area.right() {
394+ for y in area.top()..area.bottom() {
395+ let cell = self.get_mut(x, y);
396+ cell.reset();
397+ cell.set_style(style);
398+ }
399+ }
400+ }
401+
382 /// Merge an other buffer into this one
402 /// Merge an other buffer into this one
383 pub fn merge(&mut self, other: &Buffer) {
403 pub fn merge(&mut self, other: &Buffer) {
384 let area = self.area.union(other.area);
404 let area = self.area.union(other.area);
helix-tui/src/widgets/clear.rsdeleted−36
@@ -1,36 +0,0 @@
1−use crate::buffer::Buffer;
2−use crate::layout::Rect;
3−use crate::widgets::Widget;
4−
5−/// A widget to to clear/reset a certain area to allow overdrawing (e.g. for popups)
6−///
7−/// # Examples
8−///
9−/// ```
10−/// # use helix_tui::widgets::{Clear, Block, Borders};
11−/// # use helix_tui::layout::Rect;
12−/// # use helix_tui::Frame;
13−/// # use helix_tui::backend::Backend;
14−/// fn draw_on_clear<B: Backend>(f: &mut Frame<B>, area: Rect) {
15−/// let block = Block::default().title("Block").borders(Borders::ALL);
16−/// f.render_widget(Clear, area); // <- this will clear/reset the area first
17−/// f.render_widget(block, area); // now render the block widget
18−/// }
19−/// ```
20−///
21−/// # Popup Example
22−///
23−/// For a more complete example how to utilize `Clear` to realize popups see
24−/// the example `examples/popup.rs`
25−#[derive(Debug, Clone)]
26−pub struct Clear;
27−
28−impl Widget for Clear {
29− fn render(self, area: Rect, buf: &mut Buffer) {
30− for x in area.left()..area.right() {
31− for y in area.top()..area.bottom() {
32− buf.get_mut(x, y).reset();
33− }
34− }
35− }
36−}
helix-tui/src/widgets/mod.rs−3
@@ -9,17 +9,14 @@
9//! - [`List`]
9//! - [`List`]
10//! - [`Table`]
10//! - [`Table`]
11//! - [`Paragraph`]
11//! - [`Paragraph`]
12−//! - [`Clear`]
13
12
14mod block;
13mod block;
15−mod clear;
16// mod list;
14// mod list;
17mod paragraph;
15mod paragraph;
18mod reflow;
16mod reflow;
19// mod table;
17// mod table;
20
18
21pub use self::block::{Block, BorderType};
19pub use self::block::{Block, BorderType};
22−pub use self::clear::Clear;
23// pub use self::list::{List, ListItem, ListState};
20// pub use self::list::{List, ListItem, ListState};
24pub use self::paragraph::{Paragraph, Wrap};
21pub use self::paragraph::{Paragraph, Wrap};
25// pub use self::table::{Cell, Row, Table, TableState};
22// pub use self::table::{Cell, Row, Table, TableState};