Redraw interface only if needed

This commit is contained in:
ChristianVisintin
2020-11-30 14:38:14 +01:00
parent 015a17d9f7
commit b5c47b9470
2 changed files with 76 additions and 58 deletions

View File

@@ -82,6 +82,7 @@ pub struct AuthActivity {
input_mode: InputMode,
popup_message: Option<String>,
password_placeholder: String,
redraw: bool, // Should ui actually be redrawned?
}
impl AuthActivity {
@@ -102,6 +103,7 @@ impl AuthActivity {
input_mode: InputMode::Text,
popup_message: None,
password_placeholder: String::new(),
redraw: true, // True at startup
}
}
@@ -432,11 +434,16 @@ impl Activity for AuthActivity {
}
// Start catching Input Events
if let Ok(input_events) = self.context.as_ref().unwrap().input_hnd.fetch_events() {
if input_events.len() > 0 {
self.redraw = true; // Set redraw to true if there is at least one event
}
// Iterate over input events
for event in input_events.iter() {
self.handle_input_event(event);
}
}
// Redraw if necessary
if self.redraw {
// Determine input mode
self.input_mode = self.select_input_mode();
// draw interface
@@ -495,6 +502,9 @@ impl Activity for AuthActivity {
});
// Reset ctx
self.context = Some(ctx);
// Set redraw to false
self.redraw = false;
}
}
/// ### on_destroy

View File

@@ -2235,6 +2235,7 @@ impl Activity for FileTransferActivity {
/// `on_draw` is the function which draws the graphical interface.
/// This function must be called at each tick to refresh the interface
fn on_draw(&mut self) {
let mut redraw: bool = false; // Should ui actually be redrawned?
// Context must be something
if self.context.is_none() {
return;
@@ -2254,17 +2255,24 @@ impl Activity for FileTransferActivity {
self.draw();
// Connect to remote
self.connect();
// Redraw
redraw = true;
}
// Handle input events
if let Ok(event) = self.context.as_ref().unwrap().input_hnd.read_event() {
// Iterate over input events
if let Some(event) = event {
// Handle event
self.handle_input_event(&event);
// Set redraw to true
redraw = true;
}
}
// @! draw interface
if redraw {
self.draw();
}
}
/// ### on_destroy
///