Store navigation metadata in network

This commit is contained in:
Adam
2024-09-03 21:13:52 -07:00
parent bc62fd2dea
commit d2d451dd6f
12 changed files with 309 additions and 371 deletions

View File

@@ -42,7 +42,7 @@ impl ClickTarget {
self.bounding_box
}
pub fn bounding_box_with_transform(&self, transform: DAffine2) -> Option<[DVec2; 2]> {
pub fn bounding_box_with_transform(&self, transform: &DAffine2) -> Option<[DVec2; 2]> {
self.bounding_box.map(|[a, b]| [transform.transform_point2(a), transform.transform_point2(b)])
}

View File

@@ -6,7 +6,7 @@ use graphene_core::memo::MemoHashGuard;
pub use graphene_core::uuid::generate_uuid;
use graphene_core::{Cow, MemoHash, ProtoNodeIdentifier, Type};
use glam::{DAffine2, DVec2, IVec2};
use glam::{DVec2, IVec2};
use log::Metadata;
use rustc_hash::FxHashMap;
use std::collections::hash_map::DefaultHasher;
@@ -1460,34 +1460,6 @@ impl OutputConnector {
}
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, DynAny)]
pub struct NavigationMetadata {
/// The current pan, and zoom state of the viewport's view of the node graph.
/// Ensure `DocumentMessage::UpdateDocumentTransform` is called when the pan, zoom, or transform changes.
pub node_graph_ptz: PTZ,
// TODO: Remove and replace with calculate_offset_transform from the node_graph_ptz. This will be difficult since it requires both the navigation message handler and the IPP
/// Transform from node graph space to viewport space.
pub node_graph_to_viewport: DAffine2,
/// The viewport pixel distance distance between the left edge of the node graph and the exports. Rounded to nearest grid space when the panning ends.
#[serde(skip)]
pub exports_to_edge_distance: DVec2,
/// The viewport pixel distance between the left edge of the node graph and the imports. Rounded to nearest grid space when the panning ends.
#[serde(skip)]
pub imports_to_edge_distance: DVec2,
}
impl Default for NavigationMetadata {
fn default() -> NavigationMetadata {
//Default PTZ and transform
NavigationMetadata {
node_graph_ptz: PTZ::default(),
node_graph_to_viewport: DAffine2::IDENTITY,
exports_to_edge_distance: DVec2::ZERO,
imports_to_edge_distance: DVec2::ZERO,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize, DynAny)]
#[serde(default)]
pub struct PTZ {

View File

@@ -179,7 +179,7 @@ tagged_value! {
BooleanOperation(graphene_core::vector::misc::BooleanOperation),
FontCache(Arc<graphene_core::text::FontCache>),
Previewing(crate::document::Previewing),
NavigationMetadata(crate::document::NavigationMetadata)
PTZ(crate::document::PTZ),
}
impl TaggedValue {
@@ -306,12 +306,4 @@ mod fake_hash {
self.zoom.hash(state);
}
}
impl FakeHash for crate::document::NavigationMetadata {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.node_graph_ptz.hash(state);
self.node_graph_to_viewport.hash(state);
self.exports_to_edge_distance.hash(state);
self.imports_to_edge_distance.hash(state);
}
}
}