mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Add hide
class
This commit is contained in:
parent
24d513d891
commit
44ebefbec2
32
src/library/hidden.rs
Normal file
32
src/library/hidden.rs
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ pub mod deco;
|
|||||||
pub mod flow;
|
pub mod flow;
|
||||||
pub mod grid;
|
pub mod grid;
|
||||||
pub mod heading;
|
pub mod heading;
|
||||||
|
pub mod hidden;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
pub mod link;
|
pub mod link;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
@ -33,6 +34,7 @@ pub use deco::*;
|
|||||||
pub use flow::*;
|
pub use flow::*;
|
||||||
pub use grid::*;
|
pub use grid::*;
|
||||||
pub use heading::*;
|
pub use heading::*;
|
||||||
|
pub use hidden::*;
|
||||||
pub use link::*;
|
pub use link::*;
|
||||||
pub use list::*;
|
pub use list::*;
|
||||||
pub use pad::*;
|
pub use pad::*;
|
||||||
@ -116,6 +118,7 @@ pub fn new() -> Scope {
|
|||||||
std.def_class::<TransformNode<Move>>("move");
|
std.def_class::<TransformNode<Move>>("move");
|
||||||
std.def_class::<TransformNode<Scale>>("scale");
|
std.def_class::<TransformNode<Scale>>("scale");
|
||||||
std.def_class::<TransformNode<Rotate>>("rotate");
|
std.def_class::<TransformNode<Rotate>>("rotate");
|
||||||
|
std.def_class::<HideNode>("hide");
|
||||||
std.def_class::<StackNode>("stack");
|
std.def_class::<StackNode>("stack");
|
||||||
std.def_class::<GridNode>("grid");
|
std.def_class::<GridNode>("grid");
|
||||||
std.def_class::<ColumnsNode>("columns");
|
std.def_class::<ColumnsNode>("columns");
|
||||||
|
BIN
tests/ref/layout/hide.png
Normal file
BIN
tests/ref/layout/hide.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 936 B |
5
tests/typ/layout/hide.typ
Normal file
5
tests/typ/layout/hide.typ
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Test the `hide` function.
|
||||||
|
|
||||||
|
---
|
||||||
|
AB #h(1fr) CD \
|
||||||
|
#hide[A]B #h(1fr) C#hide[D]
|
Loading…
x
Reference in New Issue
Block a user