use std::cell::RefCell;
use super::{Theme, Window};
use crate::config::{Config, WindowConfig};
use crate::draw::{DrawIface, DrawSharedImpl, color};
use crate::event::EventState;
use crate::theme::ThemeDraw;
pub trait ThemeDst<DS: DrawSharedImpl> {
fn init(&mut self, config: &RefCell<Config>);
fn new_window(&mut self, config: &WindowConfig) -> Box<dyn Window>;
fn update_window(&mut self, window: &mut dyn Window, config: &WindowConfig) -> bool;
fn draw<'a>(
&'a self,
draw: DrawIface<'a, DS>,
ev: &'a mut EventState,
window: &'a mut dyn Window,
) -> Box<dyn ThemeDraw + 'a>;
fn clear_color(&self) -> color::Rgba;
}
impl<DS: DrawSharedImpl, T: Theme<DS>> ThemeDst<DS> for T {
fn init(&mut self, config: &RefCell<Config>) {
self.init(config);
}
fn new_window(&mut self, config: &WindowConfig) -> Box<dyn Window> {
let window = <T as Theme<DS>>::new_window(self, config);
Box::new(window)
}
fn update_window(&mut self, window: &mut dyn Window, config: &WindowConfig) -> bool {
let window = window.as_any_mut().downcast_mut().unwrap();
self.update_window(window, config)
}
fn draw<'b>(
&'b self,
draw: DrawIface<'b, DS>,
ev: &'b mut EventState,
window: &'b mut dyn Window,
) -> Box<dyn ThemeDraw + 'b> {
let window = window.as_any_mut().downcast_mut().unwrap();
Box::new(<T as Theme<DS>>::draw(self, draw, ev, window))
}
fn clear_color(&self) -> color::Rgba {
self.clear_color()
}
}