kas_core/theme/
theme_dst.rs1use std::cell::RefCell;
9
10use super::{Theme, Window};
11use crate::config::{Config, WindowConfig};
12use crate::draw::{DrawIface, DrawSharedImpl, color};
13use crate::event::EventState;
14use crate::theme::ThemeDraw;
15
16pub trait ThemeDst<DS: DrawSharedImpl> {
22 fn init(&mut self, config: &RefCell<Config>);
26
27 fn new_window(&mut self, config: &WindowConfig) -> Box<dyn Window>;
31
32 fn update_window(&mut self, window: &mut dyn Window, config: &WindowConfig) -> bool;
38
39 fn draw<'a>(
40 &'a self,
41 draw: DrawIface<'a, DS>,
42 ev: &'a mut EventState,
43 window: &'a mut dyn Window,
44 ) -> Box<dyn ThemeDraw + 'a>;
45
46 fn clear_color(&self) -> color::Rgba;
50}
51
52impl<DS: DrawSharedImpl, T: Theme<DS>> ThemeDst<DS> for T {
53 fn init(&mut self, config: &RefCell<Config>) {
54 self.init(config);
55 }
56
57 fn new_window(&mut self, config: &WindowConfig) -> Box<dyn Window> {
58 let window = <T as Theme<DS>>::new_window(self, config);
59 Box::new(window)
60 }
61
62 fn update_window(&mut self, window: &mut dyn Window, config: &WindowConfig) -> bool {
63 let window = window.as_any_mut().downcast_mut().unwrap();
64 self.update_window(window, config)
65 }
66
67 fn draw<'b>(
68 &'b self,
69 draw: DrawIface<'b, DS>,
70 ev: &'b mut EventState,
71 window: &'b mut dyn Window,
72 ) -> Box<dyn ThemeDraw + 'b> {
73 let window = window.as_any_mut().downcast_mut().unwrap();
74 Box::new(<T as Theme<DS>>::draw(self, draw, ev, window))
75 }
76
77 fn clear_color(&self) -> color::Rgba {
78 self.clear_color()
79 }
80}