Clear the screen only on window resize and layer removal

Should actually also be done if a layer shrinks.
Luckily, clear can be called anytime, as draw() is the last action
performed in the event loop - so it's safe to clear the screen in any
event callback, or even during layout.
This commit is contained in:
Alexandre Bury 2016-07-09 18:49:37 -07:00
parent 9b2dec2a7f
commit 08ab18608b
2 changed files with 7 additions and 2 deletions

View File

@ -289,10 +289,9 @@ impl Cursive {
while self.running { while self.running {
// Do we need to redraw everytime? // Do we need to redraw everytime?
// Probably, actually. // Probably, actually.
// TODO: Do we actually need to clear everytime?
B::clear();
// TODO: Do we need to re-layout everytime? // TODO: Do we need to re-layout everytime?
self.layout(); self.layout();
// TODO: Do we need to redraw every view every time? // TODO: Do we need to redraw every view every time?
// (Is this getting repetitive? :p) // (Is this getting repetitive? :p)
self.draw(); self.draw();
@ -300,6 +299,10 @@ impl Cursive {
// Wait for next event. // Wait for next event.
// (If set_fps was called, this returns -1 now and then) // (If set_fps was called, this returns -1 now and then)
let event = B::poll_event(); let event = B::poll_event();
if event == Event::Key(event::Key::Resize) {
B::clear();
continue;
}
// Event dispatch order: // Event dispatch order:
// * Focused element: // * Focused element:

View File

@ -1,5 +1,6 @@
use std::any::Any; use std::any::Any;
use backend::Backend;
use vec::Vec2; use vec::Vec2;
use view::{Offset, Position, Selector, ShadowView, View}; use view::{Offset, Position, Selector, ShadowView, View};
use event::{Event, EventResult}; use event::{Event, EventResult};
@ -54,6 +55,7 @@ impl StackView {
/// Remove the top-most layer. /// Remove the top-most layer.
pub fn pop_layer(&mut self) { pub fn pop_layer(&mut self) {
self.layers.pop(); self.layers.pop();
::B::clear();
} }
} }