mirror of
https://github.com/typst/typst
synced 2025-05-21 04:25:28 +08:00
Make Sticky derive cast and make test case less verbose
This commit is contained in:
parent
96f9187841
commit
23ef479a73
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user