use crate::{
platform::{ActiveApplicationApi, ApplicationApi, Wrapper},
platform_impl::{ActiveApplicationImpl, ApplicationImpl, ContextImpl},
Error,
EventHandler,
Icon,
Menu,
};
#[derive(Debug, Clone)]
pub struct Context(ContextImpl);
impl Context {
pub(crate) fn new(ctx: ContextImpl) -> Self { Self(ctx) }
}
impl Wrapper<ContextImpl> for Context {
#[inline]
fn get_impl(&self) -> &ContextImpl { &self.0 }
#[inline]
fn get_impl_mut(&mut self) -> &mut ContextImpl { &mut self.0 }
}
pub trait ContextOwner {
fn context(&self) -> &Context;
}
#[derive(Debug)]
pub struct ActiveApplication(ActiveApplicationImpl);
impl ActiveApplication {
pub(crate) fn new(app_impl: ActiveApplicationImpl) -> Self { Self(app_impl) }
pub fn set_icon(&mut self, icon: Option<&Icon>) { self.0.set_icon(icon); }
pub fn set_menu(&mut self, menu: Option<&Menu>) { self.0.set_menu(menu); }
pub fn stop(&mut self) { self.0.stop(); }
}
impl Wrapper<ActiveApplicationImpl> for ActiveApplication {
#[inline]
fn get_impl(&self) -> &ActiveApplicationImpl { &self.0 }
#[inline]
fn get_impl_mut(&mut self) -> &mut ActiveApplicationImpl { &mut self.0 }
}
impl ContextOwner for ActiveApplication {
fn context(&self) -> &Context { self.0.context() }
}
unsafe impl Sync for ActiveApplication {}
#[derive(Debug)]
pub struct Application(ApplicationImpl);
impl Application {
pub fn new() -> Result<Self, Error> { Ok(Self(ApplicationImpl::new()?)) }
pub fn run(mut self, handler: impl EventHandler + 'static) { self.0.run(handler); }
}
impl Wrapper<ApplicationImpl> for Application {
#[inline]
fn get_impl(&self) -> &ApplicationImpl { &self.0 }
#[inline]
fn get_impl_mut(&mut self) -> &mut ApplicationImpl { &mut self.0 }
}
impl ContextOwner for Application {
fn context(&self) -> &Context { self.0.context() }
}