From ecb5543985cc0788d9c01e8c2e28d8ca6d8e19b6 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 15 Mar 2023 12:33:38 +0100 Subject: Node links --- src/doc.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/doc.rs') diff --git a/src/doc.rs b/src/doc.rs index ffa056cd..6add64fc 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -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 { + match self { + Self::Dest(dest) => Some(dest.clone()), + Self::Node(id) => introspector().location(*id).map(Destination::Internal), + } + } } /// Host for metadata. -- cgit v1.2.3