feat: record label position

This commit is contained in:
Myriad-Dreamin 2024-10-07 11:55:29 +08:00
parent 83f9399915
commit 8a7a4d154d
2 changed files with 15 additions and 4 deletions

View File

@ -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 {
vm.engine.sink.warn(warning!(
expr.span(),

View File

@ -82,6 +82,8 @@ pub struct Content {
struct Inner<T: ?Sized + 'static> {
/// An optional label attached to the element.
label: Option<Label>,
/// The span where the label is attached.
labelled_at: Span,
/// The element's location which identifies it in the layouted output.
location: Option<Location>,
/// Manages the element during realization.
@ -101,6 +103,7 @@ impl Content {
label: None,
location: None,
lifecycle: SmallBitSet::new(),
labelled_at: Span::detached(),
elem: elem.into(),
}),
span: Span::detached(),
@ -135,9 +138,16 @@ impl Content {
self.inner.label
}
/// Attach a label to the content.
pub fn labelled(mut self, label: Label) -> Self {
self.set_label(label);
/// Get the span where the label is attached.
pub fn labelled_at(&self) -> Span {
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
}
@ -742,6 +752,7 @@ impl<T: NativeElement> Bounds for T {
location: inner.location,
lifecycle: inner.lifecycle.clone(),
elem: LazyHash::reuse(self.clone(), &inner.elem),
labelled_at: inner.labelled_at,
}),
span,
}