summaryrefslogtreecommitdiff
path: root/src/library/hide.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-02-02 10:40:26 +0100
committerLaurenz <laurmaedje@gmail.com>2022-02-02 10:40:26 +0100
commita3f151df82f832668a6c71e6ac47117f3c6bacce (patch)
tree462a41c9d7cc383bddc9422e1c189bcbaa0fdf41 /src/library/hide.rs
parentfe70db1f4ce078f7b41c163a1c0ead31fd04850a (diff)
Fix filename
Diffstat (limited to 'src/library/hide.rs')
-rw-r--r--src/library/hide.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/library/hide.rs b/src/library/hide.rs
new file mode 100644
index 00000000..5025fefb
--- /dev/null
+++ b/src/library/hide.rs
@@ -0,0 +1,32 @@
+//! Hiding of nodes without affecting layout.
+
+use super::prelude::*;
+
+/// A node that hides its child without affecting layout.
+#[derive(Debug, Hash)]
+pub struct HideNode(pub PackedNode);
+
+#[class]
+impl HideNode {
+ fn construct(_: &mut EvalContext, args: &mut Args) -> TypResult<Node> {
+ Ok(Node::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
+ }
+}