summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-01-29 22:32:01 +0100
committerLaurenz <laurmaedje@gmail.com>2022-01-29 22:32:01 +0100
commit44ebefbec23114d6ed7a96e7e3cb9078441aff31 (patch)
tree104b51725e2741a7bea774128475c824cc2e60bf /src
parent24d513d8917de0a8c23916837e5ea7fbb550db8b (diff)
Add `hide` class
Diffstat (limited to 'src')
-rw-r--r--src/library/hidden.rs32
-rw-r--r--src/library/mod.rs3
2 files changed, 35 insertions, 0 deletions
diff --git a/src/library/hidden.rs b/src/library/hidden.rs
new file mode 100644
index 00000000..7287bf3d
--- /dev/null
+++ b/src/library/hidden.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<Rc<Frame>>> {
+ let mut frames = self.0.layout(ctx, regions, styles);
+
+ // Clear the frames.
+ for Constrained { item: frame, .. } in &mut frames {
+ *frame = Rc::new(Frame { elements: vec![], ..**frame });
+ }
+
+ frames
+ }
+}
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 51d57c3e..81c8fcdc 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -10,6 +10,7 @@ pub mod deco;
pub mod flow;
pub mod grid;
pub mod heading;
+pub mod hidden;
pub mod image;
pub mod link;
pub mod list;
@@ -33,6 +34,7 @@ pub use deco::*;
pub use flow::*;
pub use grid::*;
pub use heading::*;
+pub use hidden::*;
pub use link::*;
pub use list::*;
pub use pad::*;
@@ -116,6 +118,7 @@ pub fn new() -> Scope {
std.def_class::<TransformNode<Move>>("move");
std.def_class::<TransformNode<Scale>>("scale");
std.def_class::<TransformNode<Rotate>>("rotate");
+ std.def_class::<HideNode>("hide");
std.def_class::<StackNode>("stack");
std.def_class::<GridNode>("grid");
std.def_class::<ColumnsNode>("columns");