use crate::{Font, Result, Settings, window};
use taim_view::{AnyView, Scope};
use std::borrow::Cow;
pub fn launch<V>(title: &str, build: impl FnOnce(&mut Scope) -> V + 'static) -> Result
where
V: Into<AnyView>,
{
app(title, build).run()
}
pub fn app<V>(title: &str, build: impl FnOnce(&mut Scope) -> V + 'static) -> App
where
V: Into<AnyView>,
{
App {
title: title.to_owned(),
settings: Settings::default(),
window: window::Settings::default(),
build: Box::new(move |cx| build(cx).into()),
}
}
pub struct App {
title: String,
settings: Settings,
window: window::Settings,
build: Box<dyn FnOnce(&mut Scope) -> AnyView>,
}
impl App {
pub fn size(mut self, width: f32, height: f32) -> Self {
self.window.size = crate::Size::new(width, height);
self
}
pub fn window(mut self, settings: window::Settings) -> Self {
self.window = settings;
self
}
pub fn settings(mut self, settings: Settings) -> Self {
self.settings = settings;
self
}
pub fn font(mut self, bytes: impl Into<Cow<'static, [u8]>>) -> Self {
self.settings.fonts.push(bytes.into());
self
}
pub fn default_font(mut self, font: Font) -> Self {
self.settings.default_font = font;
self
}
#[cfg(target_os = "android")]
pub fn run_android(self, activity: crate::android::AndroidApp) -> Result {
taim_winit::run_android(
taim_winit::App {
title: self.title,
settings: self.settings,
window: self.window,
build: self.build,
},
activity,
)
.map_err(Into::into)
}
pub fn run(self) -> Result {
taim_winit::run(taim_winit::App {
title: self.title,
settings: self.settings,
window: self.window,
build: self.build,
})
.map_err(Into::into)
}
}
impl std::fmt::Debug for App {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("App")
.field("title", &self.title)
.finish_non_exhaustive()
}
}
pub mod prelude {
pub use taim_view::prelude::*;
}