pub mod bind_ext;
pub mod widgets;
pub use widgets::*;
use crate::bind;
#[derive(Default)]
pub struct EguiAsyncPlugin;
impl egui::Plugin for EguiAsyncPlugin {
fn debug_name(&self) -> &'static str {
"egui_async"
}
fn on_begin_pass(&mut self, ui: &mut egui::Ui) {
bind::CTX.get_or_init(|| ui.ctx().clone());
let is_suspended = ui.input(|i| {
let info = i.viewport();
info.minimized.unwrap_or(false)
|| info.occluded.unwrap_or(false)
|| !info.visible().unwrap_or(true)
});
if is_suspended {
return;
}
let time = ui.input(|i| i.time);
let curr_time = bind::CURR_FRAME.load(std::sync::atomic::Ordering::Relaxed);
#[allow(clippy::float_cmp)]
if curr_time != time {
let last_frame = bind::CURR_FRAME.swap(time, std::sync::atomic::Ordering::Relaxed);
bind::LAST_FRAME.store(last_frame, std::sync::atomic::Ordering::Relaxed);
}
}
}