typst_library/layout/
pad.rs1use crate::diag::SourceResult;
2use crate::engine::Engine;
3use crate::foundations::{elem, Content, NativeElement, Packed, Show, StyleChain};
4use crate::layout::{BlockElem, Length, Rel};
5
6#[elem(title = "Padding", Show)]
20pub struct PadElem {
21 #[parse(
23 let all = args.named("rest")?.or(args.find()?);
24 let x = args.named("x")?.or(all);
25 let y = args.named("y")?.or(all);
26 args.named("left")?.or(x)
27 )]
28 pub left: Rel<Length>,
29
30 #[parse(args.named("top")?.or(y))]
32 pub top: Rel<Length>,
33
34 #[parse(args.named("right")?.or(x))]
36 pub right: Rel<Length>,
37
38 #[parse(args.named("bottom")?.or(y))]
40 pub bottom: Rel<Length>,
41
42 #[external]
44 pub x: Rel<Length>,
45
46 #[external]
48 pub y: Rel<Length>,
49
50 #[external]
52 pub rest: Rel<Length>,
53
54 #[required]
56 pub body: Content,
57}
58
59impl Show for Packed<PadElem> {
60 fn show(&self, engine: &mut Engine, _: StyleChain) -> SourceResult<Content> {
61 Ok(BlockElem::multi_layouter(self.clone(), engine.routines.layout_pad)
62 .pack()
63 .spanned(self.span()))
64 }
65}