use crate::platform::qt::qt_wrapper::QApplicationAttribute;
use crate::platform::qt::qt_wrapper::{QApplication, QString, QSurfaceFormat};
use crate::platform::ApplicationOptions;
use crate::{Dispatcher, FUISystemError};
pub struct Application {
_qapp: QApplication,
}
impl Application {
pub fn new(options: ApplicationOptions) -> Result<Self, FUISystemError> {
let app_name = QString::from_str(&options.title)?;
QApplication::set_application_display_name(&app_name);
QApplication::set_attribute(
QApplicationAttribute::ShareOpenGLContexts,
options.opengl_share_contexts,
);
QSurfaceFormat::set_default(options.opengl_stencil_bits);
let qapp = QApplication::new()?;
Ok(Self { _qapp: qapp })
}
pub fn get_dispatcher(&self) -> Dispatcher {
Dispatcher::new()
}
pub fn message_loop(&self) -> i32 {
QApplication::exec()
}
pub fn exit(return_code: i32) {
QApplication::exit(return_code);
}
pub fn is_gui_thread() -> bool {
QApplication::is_gui_thread()
}
pub fn post_func<F>(func: F)
where
F: FnOnce() + 'static + Send,
{
QApplication::post_func_any_thread(func);
}
}