mirror of
https://github.com/typst/typst
synced 2025-05-21 12:35:29 +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::diag::{bail, SourceResult};
|
||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
use crate::foundations::{
|
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,
|
StyleChain, Value,
|
||||||
};
|
};
|
||||||
use crate::introspection::Locator;
|
use crate::introspection::Locator;
|
||||||
@ -182,7 +180,7 @@ pub enum InlineItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Defines how a block sticks to adjacent content.
|
/// 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 {
|
pub enum Sticky {
|
||||||
/// Block sticks to the content below it.
|
/// Block sticks to the content below it.
|
||||||
Below,
|
Below,
|
||||||
@ -192,27 +190,6 @@ pub enum Sticky {
|
|||||||
Both,
|
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 {
|
impl Sticky {
|
||||||
pub fn is_sticky_above(self) -> bool {
|
pub fn is_sticky_above(self) -> bool {
|
||||||
matches!(self, Self::Above | Self::Both)
|
matches!(self, Self::Above | Self::Both)
|
||||||
|
@ -165,14 +165,14 @@ F
|
|||||||
|
|
||||||
--- block-sticky-many ---
|
--- block-sticky-many ---
|
||||||
#set page(height: 80pt)
|
#set page(height: 80pt)
|
||||||
#set block(sticky: "below")
|
#set block(breakable: false, sticky: "below")
|
||||||
#block(breakable: false)[A]
|
#block[A]
|
||||||
#block(breakable: false)[B]
|
#block[B]
|
||||||
#block(breakable: false)[C]
|
#block[C]
|
||||||
#block(breakable: false)[D]
|
#block[D]
|
||||||
E
|
E
|
||||||
#block(breakable: false)[F]
|
#block[F]
|
||||||
#block(breakable: false)[G]
|
#block[G]
|
||||||
|
|
||||||
--- block-sticky-colbreak ---
|
--- block-sticky-colbreak ---
|
||||||
A
|
A
|
||||||
|
Loading…
x
Reference in New Issue
Block a user