use crate::view::{View, ViewWrapper};
pub struct ThemedView<T> {
theme: crate::theme::Theme,
view: T,
}
impl<T> ThemedView<T> {
pub fn new(theme: crate::theme::Theme, view: T) -> Self {
ThemedView { theme, view }
}
pub fn get_theme(&self) -> &crate::theme::Theme {
&self.theme
}
pub fn set_theme(&mut self, theme: crate::theme::Theme) {
self.theme = theme;
}
inner_getters!(self.view: T);
}
impl<T: View> ViewWrapper for ThemedView<T> {
wrap_impl!(self.view: T);
fn wrap_draw(&self, printer: &crate::Printer) {
printer
.theme(&self.theme)
.with_style(crate::style::PaletteStyle::View, |printer| {
self.view.draw(printer);
});
}
}
#[crate::blueprint(ThemedView::new(theme, view))]
struct Blueprint {
view: crate::views::BoxedView,
theme: crate::theme::Theme,
}
crate::manual_blueprint!(with theme, |config, context| {
let theme = context.resolve(config)?;
Ok(move |view| ThemedView::new(theme, view))
});