diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-15 12:33:38 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-15 12:33:38 +0100 |
| commit | ecb5543985cc0788d9c01e8c2e28d8ca6d8e19b6 (patch) | |
| tree | fcd6dfaad54d4076ee6d767ceb5f388b3c84225b /src/doc.rs | |
| parent | 85678118086b29b3820813411cf382fa283b39f0 (diff) | |
Node links
Diffstat (limited to 'src/doc.rs')
| -rw-r--r-- | src/doc.rs | 34 |
1 files changed, 29 insertions, 5 deletions
@@ -14,7 +14,7 @@ use crate::geom::{ Numeric, Paint, Point, Rel, RgbaColor, Shape, Sides, Size, Stroke, Transform, }; use crate::image::Image; -use crate::model::{node, Content, Fold, StyleChain}; +use crate::model::{node, Content, Fold, Introspector, StableId, StyleChain}; use crate::syntax::Span; /// A finished document with metadata and page frames. @@ -276,7 +276,7 @@ impl Frame { return; } for meta in MetaNode::data_in(styles) { - if matches!(meta, Meta::Hidden) { + if matches!(meta, Meta::Hide) { self.clear(); break; } @@ -593,13 +593,37 @@ cast_to_value! { /// Meta information that isn't visible or renderable. #[derive(Debug, Clone, Hash)] pub enum Meta { + /// Indicates that the content should be hidden. + Hide, /// An internal or external link. - Link(Destination), + Link(Link), /// An identifiable piece of content that produces something within the /// area this metadata is attached to. Node(Content), - /// Indicates that the content is hidden. - Hidden, +} + +/// A possibly unresolved link. +#[derive(Debug, Clone, Hash)] +pub enum Link { + /// A fully resolved. + Dest(Destination), + /// An unresolved link to a node. + Node(StableId), +} + +impl Link { + /// Resolve a destination. + /// + /// Needs to lazily provide an introspector. + pub fn resolve<'a>( + &self, + introspector: impl FnOnce() -> &'a Introspector, + ) -> Option<Destination> { + match self { + Self::Dest(dest) => Some(dest.clone()), + Self::Node(id) => introspector().location(*id).map(Destination::Internal), + } + } } /// Host for metadata. |
