diff --git a/crates/typst-library/src/layout/container.rs b/crates/typst-library/src/layout/container.rs index 6eaa59ff9..64d025804 100644 --- a/crates/typst-library/src/layout/container.rs +++ b/crates/typst-library/src/layout/container.rs @@ -1,9 +1,7 @@ -use ecow::EcoString; - use crate::diag::{bail, SourceResult}; use crate::engine::Engine; use crate::foundations::{ - cast, elem, Args, AutoValue, Construct, Content, NativeElement, Packed, Repr, Smart, + cast, elem, Args, AutoValue, Cast, Construct, Content, NativeElement, Packed, Smart, StyleChain, Value, }; use crate::introspection::Locator; @@ -182,7 +180,7 @@ pub enum InlineItem { } /// Defines how a block sticks to adjacent content. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Cast, Copy, Clone, Eq, PartialEq, Hash)] pub enum Sticky { /// Block sticks to the content below it. Below, @@ -192,27 +190,6 @@ pub enum Sticky { Both, } -impl Repr for Sticky { - fn repr(&self) -> EcoString { - match self { - Self::Below => "below".into(), - Self::Above => "above".into(), - Self::Both => "both".into(), - } - } -} - -cast! { - Sticky, - self => self.repr().into_value(), - s: EcoString => match s.as_str() { - "below" => Self::Below, - "above" => Self::Above, - "both" => Self::Both, - _ => bail!("invalid sticky value"), - }, -} - impl Sticky { pub fn is_sticky_above(self) -> bool { matches!(self, Self::Above | Self::Both) diff --git a/tests/suite/layout/container.typ b/tests/suite/layout/container.typ index 973c5d917..f3135b809 100644 --- a/tests/suite/layout/container.typ +++ b/tests/suite/layout/container.typ @@ -165,14 +165,14 @@ F --- block-sticky-many --- #set page(height: 80pt) -#set block(sticky: "below") -#block(breakable: false)[A] -#block(breakable: false)[B] -#block(breakable: false)[C] -#block(breakable: false)[D] +#set block(breakable: false, sticky: "below") +#block[A] +#block[B] +#block[C] +#block[D] E -#block(breakable: false)[F] -#block(breakable: false)[G] +#block[F] +#block[G] --- block-sticky-colbreak --- A