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

View File

@ -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,
} }