cranpose_ui/modifier/
draw_cache.rs1use super::{DrawCacheBuilder, DrawCommand, Modifier};
2use crate::modifier_nodes::DrawCommandElement;
3use cranpose_ui_graphics::{DrawScope, DrawScopeDefault};
4use std::rc::Rc;
5
6impl Modifier {
7 pub fn draw_with_content(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self {
15 let func = Rc::new(move |scope: &mut DrawScopeDefault| f(scope));
16 let modifier = Self::with_element(DrawCommandElement::new(DrawCommand::WithContent(func)));
17 self.then(modifier)
18 }
19
20 pub fn draw_behind(self, f: impl Fn(&mut dyn DrawScope) + 'static) -> Self {
24 let func = Rc::new(move |scope: &mut DrawScopeDefault| f(scope));
25 let modifier = Self::with_element(DrawCommandElement::new(DrawCommand::Behind(func)));
26 self.then(modifier)
27 }
28
29 pub fn draw_with_cache(self, build: impl FnOnce(&mut DrawCacheBuilder)) -> Self {
33 let mut builder = DrawCacheBuilder::default();
34 build(&mut builder);
35 let commands = builder.finish();
36 let modifier = Self::with_element(DrawCommandElement::from_commands(commands));
37 self.then(modifier)
38 }
39}