♻️ refactor: extract `refresh_label` for GUI

main
Trisha 2022-03-25 16:17:09 -05:00
parent fb9b0c67f5
commit 365c878a90
1 changed files with 16 additions and 6 deletions

View File

@ -112,6 +112,8 @@ struct Gui {
input_relay_url: Input,
input_file_server_root: Input,
input_api_key: SecretInput,
server_is_running: bool,
}
#[derive (Default, serde::Deserialize)]
@ -176,16 +178,15 @@ impl Gui {
input_relay_url,
input_file_server_root,
input_api_key,
server_is_running: false,
}
}
fn set_server_running (&mut self, b: bool) {
self.frame.set_label (if b {
"Running"
}
else {
"Stopped"
});
self.server_is_running = b;
self.refresh_label ();
set_active (&mut self.but_run, ! b);
set_active (&mut self.but_stop, b);
@ -197,6 +198,15 @@ impl Gui {
set_active (&mut self.input_file_server_root, ! b);
set_active (&mut self.input_api_key, ! b);
}
fn refresh_label (&mut self) {
self.frame.set_label (if self.server_is_running {
"Running"
}
else {
"Stopped"
});
}
}
fn set_active <W: WidgetExt> (w: &mut W, b: bool) {