mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Allow sticky blocks to be breakable (#5161)
This commit is contained in:
parent
7a96c86487
commit
fc5858c982
@ -422,8 +422,6 @@ pub struct BlockElem {
|
|||||||
/// This is, by default, set on heading blocks to prevent orphaned headings
|
/// This is, by default, set on heading blocks to prevent orphaned headings
|
||||||
/// at the bottom of the page.
|
/// at the bottom of the page.
|
||||||
///
|
///
|
||||||
/// Marking a block as sticky makes it unbreakable.
|
|
||||||
///
|
|
||||||
/// ```example
|
/// ```example
|
||||||
/// >>> #set page(height: 140pt)
|
/// >>> #set page(height: 140pt)
|
||||||
/// // Disable stickiness of headings.
|
/// // Disable stickiness of headings.
|
||||||
|
@ -189,7 +189,7 @@ impl<'a> Collector<'a, '_, '_> {
|
|||||||
|
|
||||||
self.output.push(spacing(elem.above(styles)));
|
self.output.push(spacing(elem.above(styles)));
|
||||||
|
|
||||||
if !breakable || sticky || fr.is_some() {
|
if !breakable || fr.is_some() {
|
||||||
self.output.push(Child::Single(self.boxed(SingleChild {
|
self.output.push(Child::Single(self.boxed(SingleChild {
|
||||||
align,
|
align,
|
||||||
sticky,
|
sticky,
|
||||||
@ -203,6 +203,7 @@ impl<'a> Collector<'a, '_, '_> {
|
|||||||
let alone = self.children.len() == 1;
|
let alone = self.children.len() == 1;
|
||||||
self.output.push(Child::Multi(self.boxed(MultiChild {
|
self.output.push(Child::Multi(self.boxed(MultiChild {
|
||||||
align,
|
align,
|
||||||
|
sticky,
|
||||||
alone,
|
alone,
|
||||||
elem,
|
elem,
|
||||||
styles,
|
styles,
|
||||||
@ -375,6 +376,7 @@ fn layout_single_impl(
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MultiChild<'a> {
|
pub struct MultiChild<'a> {
|
||||||
pub align: Axes<FixedAlignment>,
|
pub align: Axes<FixedAlignment>,
|
||||||
|
pub sticky: bool,
|
||||||
alone: bool,
|
alone: bool,
|
||||||
elem: &'a Packed<BlockElem>,
|
elem: &'a Packed<BlockElem>,
|
||||||
styles: StyleChain<'a>,
|
styles: StyleChain<'a>,
|
||||||
|
@ -247,7 +247,7 @@ impl<'a, 'b> Distributor<'a, 'b, '_, '_, '_> {
|
|||||||
|
|
||||||
// Lay out the block.
|
// Lay out the block.
|
||||||
let (frame, spill) = multi.layout(self.composer.engine, self.regions)?;
|
let (frame, spill) = multi.layout(self.composer.engine, self.regions)?;
|
||||||
self.frame(frame, multi.align, false, true)?;
|
self.frame(frame, multi.align, multi.sticky, true)?;
|
||||||
|
|
||||||
// If the block didn't fully fit into the current region, save it into
|
// If the block didn't fully fit into the current region, save it into
|
||||||
// the `spill` and finish the region.
|
// the `spill` and finish the region.
|
||||||
@ -292,9 +292,9 @@ impl<'a, 'b> Distributor<'a, 'b, '_, '_, '_> {
|
|||||||
breakable: bool,
|
breakable: bool,
|
||||||
) -> FlowResult<()> {
|
) -> FlowResult<()> {
|
||||||
if sticky {
|
if sticky {
|
||||||
// If the frame is sticky and we haven't remember a preceding sticky
|
// If the frame is sticky and we haven't remembered a preceding
|
||||||
// element, make a checkpoint which we can restore should we end on
|
// sticky element, make a checkpoint which we can restore should we
|
||||||
// this sticky element.
|
// end on this sticky element.
|
||||||
if self.stickable && self.sticky.is_none() {
|
if self.stickable && self.sticky.is_none() {
|
||||||
self.sticky = Some(self.snapshot());
|
self.sticky = Some(self.snapshot());
|
||||||
}
|
}
|
||||||
|
BIN
tests/ref/block-sticky-breakable.png
Normal file
BIN
tests/ref/block-sticky-breakable.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 405 B |
@ -180,6 +180,12 @@ A
|
|||||||
#colbreak()
|
#colbreak()
|
||||||
C
|
C
|
||||||
|
|
||||||
|
--- block-sticky-breakable ---
|
||||||
|
// Ensure that sticky blocks are still breakable.
|
||||||
|
#set page(height: 60pt)
|
||||||
|
#block(sticky: true, lines(4))
|
||||||
|
E
|
||||||
|
|
||||||
--- box-clip-rect ---
|
--- box-clip-rect ---
|
||||||
// Test box clipping with a rectangle
|
// Test box clipping with a rectangle
|
||||||
Hello #box(width: 1em, height: 1em, clip: false)[#rect(width: 3em, height: 3em, fill: red)]
|
Hello #box(width: 1em, height: 1em, clip: false)[#rect(width: 3em, height: 3em, fill: red)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user