diff options
| author | Birk Tjelmeland <web-github@birktj.no> | 2023-04-01 16:04:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-01 16:04:38 +0200 |
| commit | ed79ecbb44a3132f23e3bd4d797009b5c3282fe3 (patch) | |
| tree | 23a3ed7dbe18b3abb7a73112ba9038bb0264a411 /library/src | |
| parent | b2ba061fbb62478017c0a2e9ceced48710cdd291 (diff) | |
Add support for cliping content in `block` and `box` (#431)
Diffstat (limited to 'library/src')
| -rw-r--r-- | library/src/layout/container.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/src/layout/container.rs b/library/src/layout/container.rs index bac0cb7f..0f81a1df 100644 --- a/library/src/layout/container.rs +++ b/library/src/layout/container.rs @@ -88,6 +88,10 @@ pub struct BoxElem { #[fold] pub outset: Sides<Option<Rel<Length>>>, + /// Whether to clip the content inside the box. + #[default(false)] + pub clip: bool, + /// The contents of the box. #[positional] pub body: Option<Content>, @@ -133,6 +137,11 @@ impl Layout for BoxElem { frame.set_baseline(frame.baseline() - shift); } + // Clip the contents + if self.clip(styles) { + frame.clip(); + } + // Prepare fill and stroke. let fill = self.fill(styles); let stroke = self.stroke(styles).map(|s| s.map(PartialStroke::unwrap_or_default)); @@ -296,6 +305,10 @@ pub struct BlockElem { #[default(VElem::block_spacing(Em::new(1.2).into()))] pub below: VElem, + /// Whether to clip the content inside the block. + #[default(false)] + pub clip: bool, + /// The contents of the block. #[positional] pub body: Option<Content>, @@ -369,6 +382,13 @@ impl Layout for BlockElem { body.layout(vt, styles, pod)?.into_frames() }; + // Clip the contents + if self.clip(styles) { + for frame in frames.iter_mut() { + frame.clip(); + } + } + // Prepare fill and stroke. let fill = self.fill(styles); let stroke = self.stroke(styles).map(|s| s.map(PartialStroke::unwrap_or_default)); |
