summaryrefslogtreecommitdiff
path: root/src/library/hide.rs
blob: cfef8f73038ea6afe736f55b082c5200813e92cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//! Hiding of nodes without affecting layout.

use super::prelude::*;

/// Hide a node without affecting layout.
#[derive(Debug, Hash)]
pub struct HideNode(pub PackedNode);

#[class]
impl HideNode {
    fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Template> {
        Ok(Template::inline(Self(args.expect("body")?)))
    }
}

impl Layout for HideNode {
    fn layout(
        &self,
        ctx: &mut LayoutContext,
        regions: &Regions,
        styles: StyleChain,
    ) -> Vec<Constrained<Arc<Frame>>> {
        let mut frames = self.0.layout(ctx, regions, styles);

        // Clear the frames.
        for Constrained { item: frame, .. } in &mut frames {
            *frame = Arc::new(Frame { elements: vec![], ..**frame });
        }

        frames
    }
}