Replies: 2 comments
-
i know this is quite old but for anyone else searching for a solution I think async operation in update isn't recommended which results in the UI hanging lazy_static! {
pub static ref UI_STATE: Mutex<UiState> = Mutex::new(UiState {
is_loading: false,
});
} then used the ui_state in ui code egui::CentralPanel::default().show(ctx, |ui: &mut egui::Ui| {
let ui_state = UI_STATE.lock().unwrap();
self.is_enabled = !ui_state.is_loading;
if ui_state.is_loading {
ui.horizontal(|ui| {
ui.label("Loading... Please wait.");
ui.spinner();
});
}
ui.add_enabled_ui(self.is_enabled, |ui| {
self.show_main_ui(ui);
});
}); and is_enabled used here to disable all UI elements until the request is done |
Beta Was this translation helpful? Give feedback.
-
Another solution is to use the poll-promise crate. Then you can call async functions directly from your update method. Example:
As for the lack of updating, when you have things going on in the background, you can force updates via
|
Beta Was this translation helpful? Give feedback.
-
I have a button click it's connecting the database. I want to show a spinner say on the status bar on the bottom of the window, when the button is clicked and connecting the MongoDB. I have a ui enable component to control the spinner show or hide. Before the API call, I set the variable to true and hoping the spinner will show. After the API call, I set it back to false so the spinner will be hidden. But it's not working. When the API is trying to connect, the UI is not refreshing I guess. How can I do this?
Beta Was this translation helpful? Give feedback.
All reactions