From 08ab18608bb402f4d8662936f9d3f68e87e18981 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sat, 9 Jul 2016 18:49:37 -0700 Subject: [PATCH] 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. --- src/lib.rs | 7 +++++-- src/view/stack_view.rs | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cefb363..c352dea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -289,10 +289,9 @@ impl Cursive { while self.running { // Do we need to redraw everytime? // Probably, actually. - // TODO: Do we actually need to clear everytime? - B::clear(); // TODO: Do we need to re-layout everytime? self.layout(); + // TODO: Do we need to redraw every view every time? // (Is this getting repetitive? :p) self.draw(); @@ -300,6 +299,10 @@ impl Cursive { // Wait for next event. // (If set_fps was called, this returns -1 now and then) let event = B::poll_event(); + if event == Event::Key(event::Key::Resize) { + B::clear(); + continue; + } // Event dispatch order: // * Focused element: diff --git a/src/view/stack_view.rs b/src/view/stack_view.rs index 5619ed0..4dd1281 100644 --- a/src/view/stack_view.rs +++ b/src/view/stack_view.rs @@ -1,5 +1,6 @@ use std::any::Any; +use backend::Backend; use vec::Vec2; use view::{Offset, Position, Selector, ShadowView, View}; use event::{Event, EventResult}; @@ -54,6 +55,7 @@ impl StackView { /// Remove the top-most layer. pub fn pop_layer(&mut self) { self.layers.pop(); + ::B::clear(); } }