Go back to wrapping inline nodes

This commit is contained in:
Laurenz 2021-11-29 13:12:50 +01:00
parent e36b8ed374
commit cae60ea0cc
12 changed files with 14 additions and 16 deletions

View File

@ -151,7 +151,7 @@ impl Template {
/// Pack the template into a layout node. /// Pack the template into a layout node.
pub fn pack(&self, style: &Style) -> PackedNode { pub fn pack(&self, style: &Style) -> PackedNode {
if let [TemplateNode::Block(f) | TemplateNode::Inline(f)] = self.0.as_slice() { if let [TemplateNode::Block(f)] = self.0.as_slice() {
f(style) f(style)
} else { } else {
let mut builder = Builder::new(style, false); let mut builder = Builder::new(style, false);

View File

@ -15,7 +15,7 @@ pub fn pad(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
bottom.or(all).unwrap_or_default(), bottom.or(all).unwrap_or_default(),
); );
Ok(Value::Template(Template::from_inline(move |style| { Ok(Value::Template(Template::from_block(move |style| {
body.pack(style).padded(padding) body.pack(style).padded(padding)
}))) })))
} }

View File

@ -10,13 +10,11 @@ pub fn box_(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
}))) })))
} }
/// `block`: Size content and place it into the flow. /// `block`: Place content into the flow.
pub fn block(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> { pub fn block(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
let width = args.named("width")?;
let height = args.named("height")?;
let body: Template = args.find().unwrap_or_default(); let body: Template = args.find().unwrap_or_default();
Ok(Value::Template(Template::from_block(move |style| { Ok(Value::Template(Template::from_block(move |style| {
body.pack(style).sized(Spec::new(width, height)) body.pack(style)
}))) })))
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -7,8 +7,8 @@
--- ---
Rect in ellipse in fixed rect. \ Rect in ellipse in fixed rect. \
#rect(width: 3cm, height: 2cm, fill: rgb("2a631a"), #rect(width: 3cm, height: 2cm, fill: rgb("2a631a"),
ellipse(fill: forest, ellipse(fill: forest, width: 100%, height: 100%,
rect(fill: conifer, rect(fill: conifer, width: 100%, height: 100%,
align(center + horizon)[ align(center + horizon)[
Stuff inside an ellipse! Stuff inside an ellipse!
] ]

View File

@ -27,12 +27,12 @@
// Test all three fit modes. // Test all three fit modes.
#page(height: 50pt, margins: 0pt) #page(height: 50pt, margins: 0pt)
#grid( #grid(
columns: 3, columns: (1fr, 1fr, 1fr),
rows: 100%, rows: 100%,
gutter: 3pt, gutter: 3pt,
image("../../res/tiger.jpg", fit: "contain"), image("../../res/tiger.jpg", width: 100%, height: 100%, fit: "contain"),
image("../../res/tiger.jpg", fit: "cover"), image("../../res/tiger.jpg", width: 100%, height: 100%, fit: "cover"),
image("../../res/tiger.jpg", fit: "stretch"), image("../../res/tiger.jpg", width: 100%, height: 100%, fit: "stretch"),
) )
--- ---

View File

@ -10,7 +10,7 @@
#align(center + horizon, rect(fill: eastern, height: 10pt)) #align(center + horizon, rect(fill: eastern, height: 10pt))
#align(bottom, stack( #align(bottom, stack(
align(center, rect(fill: conifer, height: 10pt)), align(center, rect(fill: conifer, height: 10pt)),
rect(fill: forest, height: 10pt), rect(fill: forest, height: 10pt, width: 100%),
)) ))
--- ---

View File

@ -11,7 +11,7 @@
) )
) )
Hi #pad(left: 10pt)[A] there Hi #box(pad(left: 10pt)[A]) there
--- ---
// Pad can grow. // Pad can grow.

View File

@ -9,10 +9,10 @@ Unfortunately, \
the line breaks still had to be inserted manually. the line breaks still had to be inserted manually.
#stack( #stack(
rect(fill: eastern, height: 10pt), rect(fill: eastern, height: 10pt, width: 100%),
place(right, dy: 1.5pt)[ABC], place(right, dy: 1.5pt)[ABC],
rect(fill: conifer, height: 10pt, width: 80%), rect(fill: conifer, height: 10pt, width: 80%),
rect(fill: forest, height: 10pt), rect(fill: forest, height: 10pt, width: 100%),
) )
#block[ #block[