mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Move all network metadata to the node network
This commit is contained in:
@@ -1590,7 +1590,7 @@ impl Ports {
|
||||
}
|
||||
|
||||
/// This is the same as Option, but more clear in the context of having cached metadata either being loaded or unloaded
|
||||
#[derive(Debug, Default, Clone, PartialEq, serde::Deserialize, Hash)]
|
||||
#[derive(Debug, Default, Clone, PartialEq, Hash)]
|
||||
pub enum TransientMetadata<T> {
|
||||
Loaded(T),
|
||||
#[default]
|
||||
@@ -1612,6 +1612,16 @@ impl<T> Serialize for TransientMetadata<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, T> Deserialize<'de> for TransientMetadata<T> {
|
||||
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
// Always deserialize to Unloaded
|
||||
Ok(TransientMetadata::Unloaded)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TransientMetadata<T> {
|
||||
/// Set the current transient metadata to unloaded
|
||||
pub fn unload(&mut self) {
|
||||
@@ -1730,6 +1740,40 @@ pub struct NodePersistentMetadata {
|
||||
pub position: NodePosition,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, DynAny)]
|
||||
pub struct DocumentNodeClickTargets {
|
||||
/// In order to keep the displayed position of the node in sync with the click target, the displayed position of a node is derived from the top left of the click target
|
||||
/// Ensure node_click_target is kept in sync when modifying a node property that changes its size. Currently this is alias, inputs, is_layer, and metadata
|
||||
pub node_click_target: ClickTarget,
|
||||
/// Stores all port click targets in node graph space.
|
||||
pub port_click_targets: Ports,
|
||||
// Click targets that are specific to either nodes or layers, which are chosen states for displaying as a left-to-right node or bottom-to-top layer.
|
||||
pub node_type_click_targets: NodeTypeClickTargets,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum NodeTypeClickTargets {
|
||||
Layer(LayerClickTargets),
|
||||
Node, // No transient click targets are stored exclusively for nodes
|
||||
}
|
||||
|
||||
/// All fields in TransientLayerMetadata should automatically be updated by using the network interface API
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct LayerClickTargets {
|
||||
/// Cache for all visibility buttons. Should be automatically updated when update_click_target is called
|
||||
pub visibility_click_target: ClickTarget,
|
||||
/// Cache for the grip icon, which is next to the visibility button.
|
||||
pub grip_click_target: ClickTarget,
|
||||
// TODO: Store click target for the preview button, which will appear when the node is a selected/(hovered?) layer node
|
||||
// preview_click_target: ClickTarget,
|
||||
}
|
||||
|
||||
pub enum LayerClickTargetTypes {
|
||||
Visibility,
|
||||
Grip,
|
||||
// Preview,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
@@ -193,6 +193,8 @@ tagged_value! {
|
||||
OptionalString(Option<String>),
|
||||
VecString(Vec<String>),
|
||||
NodeTypeMetadata(crate::document::NodeTypePersistentMetadata),
|
||||
// Transient Node Metadata
|
||||
ClickTargets(TransientMetadata<crate::document::DocumentNodeClickTargets>),
|
||||
}
|
||||
|
||||
impl TaggedValue {
|
||||
@@ -271,7 +273,7 @@ trait FakeHash {
|
||||
mod fake_hash {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::document::{InputConnector, OutputConnector, Ports, TransientMetadata};
|
||||
use crate::document::{DocumentNodeClickTargets, InputConnector, OutputConnector, Ports, TransientMetadata};
|
||||
|
||||
use super::*;
|
||||
impl FakeHash for f64 {
|
||||
@@ -416,4 +418,24 @@ mod fake_hash {
|
||||
});
|
||||
}
|
||||
}
|
||||
impl FakeHash for DocumentNodeClickTargets {
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
self.node_click_target.subpath().hash(state);
|
||||
self.node_click_target.stroke_width().hash(state);
|
||||
self.node_click_target.bounding_box().hash(state);
|
||||
self.port_click_targets.hash(state);
|
||||
match &self.node_type_click_targets {
|
||||
crate::document::NodeTypeClickTargets::Layer(layer_click_target) => {
|
||||
1.hash(state);
|
||||
layer_click_target.visibility_click_target.subpath().hash(state);
|
||||
layer_click_target.visibility_click_target.stroke_width().hash(state);
|
||||
layer_click_target.visibility_click_target.bounding_box().hash(state);
|
||||
layer_click_target.grip_click_target.subpath().hash(state);
|
||||
layer_click_target.grip_click_target.stroke_width().hash(state);
|
||||
layer_click_target.grip_click_target.bounding_box().hash(state);
|
||||
}
|
||||
crate::document::NodeTypeClickTargets::Node => 0.hash(state),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user