2022-06-04 12:57:45 +02:00

35 lines
818 B
Rust

use crate::library::prelude::*;
/// Hide a node without affecting layout.
#[derive(Debug, Hash)]
pub struct HideNode(pub LayoutNode);
#[node]
impl HideNode {
fn construct(_: &mut Machine, args: &mut Args) -> TypResult<Content> {
Ok(Content::inline(Self(args.expect("body")?)))
}
}
impl Layout for HideNode {
fn layout(
&self,
ctx: &mut Context,
regions: &Regions,
styles: StyleChain,
) -> TypResult<Vec<Arc<Frame>>> {
let mut frames = self.0.layout(ctx, regions, styles)?;
// Clear the frames.
for frame in &mut frames {
*frame = Arc::new({
let mut empty = Frame::new(frame.size);
empty.baseline = frame.baseline;
empty
});
}
Ok(frames)
}
}