mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Redraw interface only if needed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user