summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/model/outline.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-library/src/model/outline.rs')
-rw-r--r--crates/typst-library/src/model/outline.rs36
1 files changed, 18 insertions, 18 deletions
diff --git a/crates/typst-library/src/model/outline.rs b/crates/typst-library/src/model/outline.rs
index 16a11614..bb061fb7 100644
--- a/crates/typst-library/src/model/outline.rs
+++ b/crates/typst-library/src/model/outline.rs
@@ -183,8 +183,7 @@ pub struct OutlineElem {
/// caption: [Experiment results],
/// )
/// ```
- #[default(LocatableSelector(HeadingElem::elem().select()))]
- #[borrowed]
+ #[default(LocatableSelector(HeadingElem::ELEM.select()))]
pub target: LocatableSelector,
/// The maximum level up to which elements are included in the outline. When
@@ -257,7 +256,7 @@ impl Show for Packed<OutlineElem> {
// Build the outline title.
let mut seq = vec![];
- if let Some(title) = self.title(styles).unwrap_or_else(|| {
+ if let Some(title) = self.title.get_cloned(styles).unwrap_or_else(|| {
Some(TextElem::packed(Self::local_name_in(styles)).spanned(span))
}) {
seq.push(
@@ -268,8 +267,8 @@ impl Show for Packed<OutlineElem> {
);
}
- let elems = engine.introspector.query(&self.target(styles).0);
- let depth = self.depth(styles).unwrap_or(NonZeroUsize::MAX);
+ let elems = engine.introspector.query(&self.target.get_ref(styles).0);
+ let depth = self.depth.get(styles).unwrap_or(NonZeroUsize::MAX);
// Build the outline entries.
for elem in elems {
@@ -291,13 +290,13 @@ impl Show for Packed<OutlineElem> {
impl ShowSet for Packed<OutlineElem> {
fn show_set(&self, styles: StyleChain) -> Styles {
let mut out = Styles::new();
- out.set(HeadingElem::set_outlined(false));
- out.set(HeadingElem::set_numbering(None));
- out.set(ParElem::set_justify(false));
- out.set(BlockElem::set_above(Smart::Custom(ParElem::leading_in(styles).into())));
+ out.set(HeadingElem::outlined, false);
+ out.set(HeadingElem::numbering, None);
+ out.set(ParElem::justify, false);
+ out.set(BlockElem::above, Smart::Custom(styles.get(ParElem::leading).into()));
// Makes the outline itself available to its entries. Should be
// superseded by a proper ancestry mechanism in the future.
- out.set(OutlineEntry::set_parent(Some(self.clone())));
+ out.set(OutlineEntry::parent, Some(self.clone()));
out
}
}
@@ -395,7 +394,6 @@ pub struct OutlineEntry {
///
/// = A New Beginning
/// ```
- #[borrowed]
#[default(Some(
RepeatElem::new(TextElem::packed("."))
.with_gap(Em::new(0.15).into())
@@ -472,7 +470,9 @@ impl OutlineEntry {
gap: Length,
) -> SourceResult<Content> {
let styles = context.styles().at(span)?;
- let outline = Self::parent_in(styles)
+ let outline = styles
+ .get_ref(Self::parent)
+ .as_ref()
.ok_or("must be called within the context of an outline")
.at(span)?;
let outline_loc = outline.location().unwrap();
@@ -483,7 +483,7 @@ impl OutlineEntry {
.transpose()?;
let prefix_inset = prefix_width.map(|w| w + gap.resolve(styles));
- let indent = outline.indent(styles);
+ let indent = outline.indent.get_ref(styles);
let (base_indent, hanging_indent) = match &indent {
Smart::Auto => compute_auto_indents(
engine.introspector,
@@ -527,7 +527,7 @@ impl OutlineEntry {
};
let inset = Sides::default().with(
- TextElem::dir_in(styles).start(),
+ styles.resolve(TextElem::dir).start(),
Some(base_indent + Rel::from(hanging_indent.unwrap_or_default())),
);
@@ -582,7 +582,7 @@ impl OutlineEntry {
// See also:
// - https://github.com/typst/typst/issues/4476
// - https://github.com/typst/typst/issues/5176
- let rtl = TextElem::dir_in(styles) == Dir::RTL;
+ let rtl = styles.resolve(TextElem::dir) == Dir::RTL;
if rtl {
// "Right-to-Left Embedding"
seq.push(TextElem::packed("\u{202B}"));
@@ -596,11 +596,11 @@ impl OutlineEntry {
}
// Add the filler between the section name and page number.
- if let Some(filler) = self.fill(styles) {
+ if let Some(filler) = self.fill.get_cloned(styles) {
seq.push(SpaceElem::shared().clone());
seq.push(
BoxElem::new()
- .with_body(Some(filler.clone()))
+ .with_body(Some(filler))
.with_width(Fr::one().into())
.pack()
.spanned(span),
@@ -717,7 +717,7 @@ fn query_prefix_widths(
outline_loc: Location,
) -> SmallVec<[Option<Abs>; 4]> {
let mut widths = SmallVec::<[Option<Abs>; 4]>::new();
- let elems = introspector.query(&select_where!(PrefixInfo, Key => outline_loc));
+ let elems = introspector.query(&select_where!(PrefixInfo, key => outline_loc));
for elem in &elems {
let info = elem.to_packed::<PrefixInfo>().unwrap();
let level = info.level.get();