From a8728be9b03f6f19df6adf1ea26a4713562dc0ae Mon Sep 17 00:00:00 2001 From: Pg Biel <9021226+PgBiel@users.noreply.github.com> Date: Fri, 12 May 2023 06:00:55 -0300 Subject: Initial support for breakable figures (#1121) --- library/src/meta/figure.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'library/src') diff --git a/library/src/meta/figure.rs b/library/src/meta/figure.rs index 548233c4..2082701b 100644 --- a/library/src/meta/figure.rs +++ b/library/src/meta/figure.rs @@ -70,9 +70,14 @@ use crate::visualize::ImageElem; /// ) /// ``` /// +/// If your figure is too large and its contents are breakable across pages +/// (e.g. if it contains a large table), then you can make the figure breakable +/// across pages as well by using `#show figure: set block(breakable: true)` +/// (see the [block]($func/block) documentation for more information). +/// /// Display: Figure /// Category: meta -#[element(Locatable, Synthesize, Count, Show, Refable)] +#[element(Locatable, Synthesize, Count, Show, Finalize, Refable)] pub struct FigureElem { /// The content of the figure. Often, an [image]($func/image). #[required] @@ -254,12 +259,18 @@ impl Show for FigureElem { // We wrap the contents in a block. Ok(BlockElem::new() .with_body(Some(realized)) - .with_breakable(false) .pack() .aligned(Axes::with_x(Some(Align::Center.into())))) } } +impl Finalize for FigureElem { + fn finalize(&self, realized: Content, _: StyleChain) -> Content { + // Allow breakable figures with `show figure: set block(breakable: true)`. + realized.styled(BlockElem::set_breakable(false)) + } +} + impl Count for FigureElem { fn update(&self) -> Option { // If the figure is numbered, step the counter by one. -- cgit v1.2.3