use super::{DrawCacheBuilder, DrawCommand, Modifier, Size};
use crate::modifier_nodes::DrawCommandElement;
use cranpose_ui_graphics::{DrawScope, DrawScopeDefault};
use std::rc::Rc;
impl Modifier {
pub fn draw_with_content(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self {
let func = Rc::new(move |size: Size| {
let mut scope = DrawScopeDefault::new(size);
f(&mut scope);
scope.into_primitives()
});
let modifier = Self::with_element(DrawCommandElement::new(DrawCommand::WithContent(
func.clone(),
)));
self.then(modifier)
}
pub fn draw_behind(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self {
let func = Rc::new(move |size: Size| {
let mut scope = DrawScopeDefault::new(size);
f(&mut scope);
scope.into_primitives()
});
let modifier =
Self::with_element(DrawCommandElement::new(DrawCommand::Behind(func.clone())));
self.then(modifier)
}
pub fn draw_with_cache(self, build: impl FnOnce(&mut DrawCacheBuilder)) -> Self {
let mut builder = DrawCacheBuilder::default();
build(&mut builder);
let commands = builder.finish();
let modifier = Self::with_element(DrawCommandElement::from_commands(commands));
self.then(modifier)
}
}