use crate::{AppConfig, AppExit};
use oxiui_core::UiError;
pub type ContentFn = Box<dyn FnMut(&mut dyn oxiui_core::UiCtx) + Send>;
#[derive(Default)]
pub struct LifecycleConfig {
pub on_close: Option<Box<dyn FnMut() + Send>>,
pub on_resize: Option<Box<dyn FnMut(f32, f32) + Send>>,
pub on_focus: Option<Box<dyn FnMut(bool) + Send>>,
}
pub trait BackendRunner: Send + 'static {
fn run(
self: Box<Self>,
config: AppConfig,
content: ContentFn,
lifecycle: LifecycleConfig,
) -> Result<AppExit, UiError>;
}
#[cfg(feature = "egui")]
pub struct EguiRunner;
#[cfg(feature = "egui")]
impl BackendRunner for EguiRunner {
fn run(
self: Box<Self>,
config: AppConfig,
content: ContentFn,
_lifecycle: LifecycleConfig,
) -> Result<AppExit, UiError> {
let _ = (config, content);
Ok(AppExit::RequestedByUser)
}
}
#[cfg(feature = "iced")]
pub struct IcedRunner;
#[cfg(feature = "iced")]
impl BackendRunner for IcedRunner {
fn run(
self: Box<Self>,
config: AppConfig,
content: ContentFn,
_lifecycle: LifecycleConfig,
) -> Result<AppExit, UiError> {
let _ = (config, content);
Ok(AppExit::RequestedByUser)
}
}