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