use std::sync::mpsc;
use dces::prelude::Entity;
use crate::{
shell::{Shell, ShellRequest},
theming::Theme,
widget_base::BuildContext,
};
pub use self::context_provider::*;
pub use self::global::*;
pub use self::overlay::*;
pub use self::window_adapter::*;
mod context_provider;
mod global;
mod overlay;
mod window_adapter;
pub struct Application {
request_sender: mpsc::Sender<ShellRequest<WindowAdapter>>,
shell: Shell<WindowAdapter>,
name: Box<str>,
theme: Theme,
}
impl Default for Application {
fn default() -> Self {
Application::from_name("orbtk_application")
}
}
impl Application {
pub fn new() -> Self {
Self::default()
}
pub fn theme(mut self, theme: Theme) -> Self {
self.theme = theme;
self
}
pub fn from_name(name: impl Into<Box<str>>) -> Self {
let (sender, receiver) = mpsc::channel();
Application {
request_sender: sender,
name: name.into(),
shell: Shell::new(receiver),
theme: crate::theme::dark_theme(),
}
}
pub fn window<F: Fn(&mut BuildContext) -> Entity + 'static>(mut self, create_fn: F) -> Self {
let (adapter, settings, receiver) = create_window(
self.name.clone(),
self.theme.clone(),
self.request_sender.clone(),
create_fn,
);
self.shell
.create_window_from_settings(settings, adapter)
.request_receiver(receiver)
.build();
self
}
pub fn run(mut self) {
self.shell.run();
}
}