1use crate::{
3 platform::{ActiveApplicationApi, ApplicationApi, Wrapper},
4 platform_impl::{ActiveApplicationImpl, ApplicationImpl, ContextImpl},
5 Error,
6 EventHandler,
7 Icon,
8 Menu,
9};
10
11#[derive(Debug, Clone)]
13pub struct Context(ContextImpl);
14
15impl Context {
16 pub(crate) fn new(ctx: ContextImpl) -> Self { Self(ctx) }
17}
18
19impl Wrapper<ContextImpl> for Context {
20 #[inline]
21 fn get_impl(&self) -> &ContextImpl { &self.0 }
22
23 #[inline]
24 fn get_impl_mut(&mut self) -> &mut ContextImpl { &mut self.0 }
25}
26
27pub trait ContextOwner {
29 fn context(&self) -> &Context;
31}
32
33#[derive(Debug)]
35pub struct ActiveApplication(ActiveApplicationImpl);
36
37impl ActiveApplication {
38 pub(crate) fn new(app_impl: ActiveApplicationImpl) -> Self { Self(app_impl) }
39
40 pub fn set_icon(&mut self, icon: Option<&Icon>) { self.0.set_icon(icon); }
45
46 pub fn set_menu(&mut self, menu: Option<&Menu>) { self.0.set_menu(menu); }
51
52 pub fn stop(&mut self) { self.0.stop(); }
54}
55
56impl Wrapper<ActiveApplicationImpl> for ActiveApplication {
57 #[inline]
58 fn get_impl(&self) -> &ActiveApplicationImpl { &self.0 }
59
60 #[inline]
61 fn get_impl_mut(&mut self) -> &mut ActiveApplicationImpl { &mut self.0 }
62}
63
64impl ContextOwner for ActiveApplication {
65 fn context(&self) -> &Context { self.0.context() }
66}
67
68unsafe impl Sync for ActiveApplication {}
69
70#[derive(Debug)]
75pub struct Application(ApplicationImpl);
76
77impl Application {
78 pub fn new() -> Result<Self, Error> { Ok(Self(ApplicationImpl::new()?)) }
88
89 pub fn run(mut self, handler: impl EventHandler + 'static) { self.0.run(handler); }
94}
95
96impl Wrapper<ApplicationImpl> for Application {
97 #[inline]
98 fn get_impl(&self) -> &ApplicationImpl { &self.0 }
99
100 #[inline]
101 fn get_impl_mut(&mut self) -> &mut ApplicationImpl { &mut self.0 }
102}
103
104impl ContextOwner for Application {
105 fn context(&self) -> &Context { self.0.context() }
106}