-
Notifications
You must be signed in to change notification settings - Fork 486
Conversation
pub fn clean(mut self, clean: bool) -> Block<'a> { | ||
self.clean = clean; | ||
self | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn clean(mut self, clean: bool) -> Block<'a> { | |
self.clean = clean; | |
self | |
} | |
pub fn clean(mut sel) -> Block<'a> { | |
self.clean = true; | |
self | |
} |
Maybe this is better?
I just stumbled on the same challenge. I for now took a different route: pub struct Clear<T: Widget>(T);
impl<T: Widget> Clear<T> {
pub fn new(w: T) -> Self {
Self(w)
}
}
impl<T: Widget> Widget for Clear<T> {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
if area.width < 2 || area.height < 2 {
return;
}
for x in area.left()..area.right() {
for y in area.top()..area.bottom() {
buf.get_mut(x, y).reset();
}
}
self.0.draw(area, buf);
}
} this see example use: Clear::new(
Paragraph::new(txt.iter())
.block(Block::default().title("Popup").borders(Borders::ALL))
.alignment(Alignment::Center),
)
.render(f, Rect::new(20, 30, 100, 10)); But yea I think it shows how necessary a official solution is! |
I think that @extrawurst solution might be preferable because it works with all widgets. To make it behave as any other widget we might want to have it render to the same area instead of wrapping a widget instance. let area = Rect::new(20, 30, 100, 10);
let popup = Paragraph::new(txt.iter())
.block(Block::default().title("Popup").borders(Borders::ALL))
.alignment(Alignment::Center);
f.render_widget(Clear, area);
f.render_widget(popup, area); What do you think ? |
So do I! @extrawurst can you make a PR ? |
Sure I can do that! |
Closed in favor of #251 |
This works pretty good, but can you help me with, rendering it on the top, like |
Related to: #211
I find the need to make a pop-up dialog in my program, but drawing widgets over drawn buffer will not clean all the underlying cells. Thus I add a
reset_area
function tobuffer.rs
to reset cells in a certainRect
. This will make it possible to implement a dialog.I also adds a
clean
option toBlock
to clean the cells first before rendering. Other widgets are untouched.Here is a minimal-example to create a dialog: