mirror of
https://github.com/typst/typst
synced 2025-05-21 04:25:28 +08:00
feat: record label position
This commit is contained in:
parent
83f9399915
commit
8a7a4d154d
@ -62,7 +62,7 @@ fn eval_markup<'a>(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
*elem = std::mem::take(elem).labelled(label);
|
*elem = std::mem::take(elem).labelled(label, expr.span());
|
||||||
} else {
|
} else {
|
||||||
vm.engine.sink.warn(warning!(
|
vm.engine.sink.warn(warning!(
|
||||||
expr.span(),
|
expr.span(),
|
||||||
|
@ -82,6 +82,8 @@ pub struct Content {
|
|||||||
struct Inner<T: ?Sized + 'static> {
|
struct Inner<T: ?Sized + 'static> {
|
||||||
/// An optional label attached to the element.
|
/// An optional label attached to the element.
|
||||||
label: Option<Label>,
|
label: Option<Label>,
|
||||||
|
/// The span where the label is attached.
|
||||||
|
labelled_at: Span,
|
||||||
/// The element's location which identifies it in the layouted output.
|
/// The element's location which identifies it in the layouted output.
|
||||||
location: Option<Location>,
|
location: Option<Location>,
|
||||||
/// Manages the element during realization.
|
/// Manages the element during realization.
|
||||||
@ -101,6 +103,7 @@ impl Content {
|
|||||||
label: None,
|
label: None,
|
||||||
location: None,
|
location: None,
|
||||||
lifecycle: SmallBitSet::new(),
|
lifecycle: SmallBitSet::new(),
|
||||||
|
labelled_at: Span::detached(),
|
||||||
elem: elem.into(),
|
elem: elem.into(),
|
||||||
}),
|
}),
|
||||||
span: Span::detached(),
|
span: Span::detached(),
|
||||||
@ -135,9 +138,16 @@ impl Content {
|
|||||||
self.inner.label
|
self.inner.label
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attach a label to the content.
|
/// Get the span where the label is attached.
|
||||||
pub fn labelled(mut self, label: Label) -> Self {
|
pub fn labelled_at(&self) -> Span {
|
||||||
self.set_label(label);
|
self.inner.labelled_at
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the label of the content.
|
||||||
|
pub fn labelled(mut self, label: Label, labelled_at: Span) -> Self {
|
||||||
|
let m = self.make_mut();
|
||||||
|
m.label = Some(label);
|
||||||
|
m.labelled_at = labelled_at;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -742,6 +752,7 @@ impl<T: NativeElement> Bounds for T {
|
|||||||
location: inner.location,
|
location: inner.location,
|
||||||
lifecycle: inner.lifecycle.clone(),
|
lifecycle: inner.lifecycle.clone(),
|
||||||
elem: LazyHash::reuse(self.clone(), &inner.elem),
|
elem: LazyHash::reuse(self.clone(), &inner.elem),
|
||||||
|
labelled_at: inner.labelled_at,
|
||||||
}),
|
}),
|
||||||
span,
|
span,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user