use crate::element::Element;
use crate::proxy::Proxy;
use crate::theme::Theme;
#[derive(Debug, Clone)]
pub struct WindowDesc<Msg> {
pub key: String,
pub title: String,
pub size: (f64, f64),
pub on_close: Msg,
}
impl<Msg> WindowDesc<Msg> {
pub fn new(
key: impl Into<String>,
title: impl Into<String>,
size: (f64, f64),
on_close: Msg,
) -> Self {
Self {
key: key.into(),
title: title.into(),
size,
on_close,
}
}
}
pub trait App {
type Msg: Clone + 'static;
fn init(&mut self, proxy: Proxy<Self::Msg>) {
let _ = proxy;
}
fn update(&mut self, msg: Self::Msg);
fn view(&self) -> Element<Self::Msg>;
fn theme(&self) -> Theme {
Theme::light()
}
fn windows(&self) -> Vec<WindowDesc<Self::Msg>> {
Vec::new()
}
fn view_for(&self, key: &str) -> Element<Self::Msg> {
let _ = key;
self.view()
}
fn theme_for(&self, key: &str) -> Theme {
let _ = key;
self.theme()
}
}
impl<A: App> App for &mut A {
type Msg = A::Msg;
fn init(&mut self, proxy: Proxy<Self::Msg>) {
(**self).init(proxy);
}
fn update(&mut self, msg: Self::Msg) {
(**self).update(msg);
}
fn view(&self) -> Element<Self::Msg> {
(**self).view()
}
fn theme(&self) -> Theme {
(**self).theme()
}
fn windows(&self) -> Vec<WindowDesc<Self::Msg>> {
(**self).windows()
}
fn view_for(&self, key: &str) -> Element<Self::Msg> {
(**self).view_for(key)
}
fn theme_for(&self, key: &str) -> Theme {
(**self).theme_for(key)
}
}
pub const MAIN_WINDOW: &str = "main";