Skip to content

Commit 6e3e881

Browse files
committed
Use GraphIdentifier instead of option
1 parent ef6fcb3 commit 6e3e881

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub use self::document_node_types::*;
22
use crate::messages::input_mapper::utility_types::macros::action_keys;
33
use crate::messages::layout::utility_types::widget_prelude::*;
44
use crate::messages::prelude::*;
5-
use crate::node_graph_executor::NodeGraphExecutor;
5+
use crate::node_graph_executor::{GraphIdentifier, NodeGraphExecutor};
66

77
use document_legacy::document::Document;
88
use document_legacy::LayerId;
@@ -347,7 +347,8 @@ impl NodeGraphMessageHandler {
347347
})
348348
.collect();
349349

350-
let thumbnail_svg = executor.thumbnails.get(&layer_id).and_then(|thumbnails| thumbnails.get(id)).map(|svg| svg.to_string());
350+
let graph_identifier = GraphIdentifier::new(layer_id);
351+
let thumbnail_svg = executor.thumbnails.get(&graph_identifier).and_then(|thumbnails| thumbnails.get(id)).map(|svg| svg.to_string());
351352

352353
nodes.push(FrontendNode {
353354
id: *id,

editor/src/node_graph_executor.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,30 @@ use std::rc::Rc;
2929
use std::sync::mpsc::{Receiver, Sender};
3030
use std::sync::Arc;
3131

32+
/// Identifies a node graph, either the document graph or a node graph associated with a legacy layer.
33+
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
34+
pub enum GraphIdentifier {
35+
DocumentGraph,
36+
LayerGraph(LayerId),
37+
}
38+
39+
impl GraphIdentifier {
40+
pub const fn new(layer_id: Option<LayerId>) -> Self {
41+
match layer_id {
42+
Some(layer_id) => Self::LayerGraph(layer_id),
43+
None => Self::DocumentGraph,
44+
}
45+
}
46+
}
47+
3248
pub struct NodeRuntime {
3349
pub(crate) executor: DynamicExecutor,
3450
font_cache: FontCache,
3551
receiver: Receiver<NodeRuntimeMessage>,
3652
sender: InternalNodeGraphUpdateSender,
3753
wasm_io: Option<WasmApplicationIo>,
3854
imaginate_preferences: ImaginatePreferences,
39-
pub(crate) thumbnails: HashMap<Option<LayerId>, HashMap<NodeId, SvgSegmentList>>,
55+
pub(crate) thumbnails: HashMap<GraphIdentifier, HashMap<NodeId, SvgSegmentList>>,
4056
canvas_cache: HashMap<Vec<LayerId>, SurfaceId>,
4157
}
4258

@@ -57,7 +73,7 @@ pub(crate) struct GenerationResponse {
5773
generation_id: u64,
5874
result: Result<TaggedValue, String>,
5975
updates: VecDeque<Message>,
60-
new_thumbnails: HashMap<Option<LayerId>, HashMap<NodeId, SvgSegmentList>>,
76+
new_thumbnails: HashMap<GraphIdentifier, HashMap<NodeId, SvgSegmentList>>,
6177
}
6278

6379
enum NodeGraphUpdate {
@@ -209,7 +225,8 @@ impl NodeRuntime {
209225
debug!("SVG {}", render.svg);
210226

211227
if let Some(node_id) = node_path.get(node_path.len() - 2).copied() {
212-
let old_thumbnail = self.thumbnails.entry(layer_path.last().copied()).or_default().entry(node_id).or_default();
228+
let graph_identifier = GraphIdentifier::new(layer_path.last().copied());
229+
let old_thumbnail = self.thumbnails.entry(graph_identifier).or_default().entry(node_id).or_default();
213230
if *old_thumbnail != render.svg {
214231
*old_thumbnail = render.svg;
215232
thumbnails_changed = true;
@@ -263,7 +280,7 @@ pub struct NodeGraphExecutor {
263280
receiver: Receiver<NodeGraphUpdate>,
264281
// TODO: This is a memory leak since layers are never removed
265282
pub(crate) last_output_type: HashMap<Vec<LayerId>, Option<Type>>,
266-
pub(crate) thumbnails: HashMap<Option<LayerId>, HashMap<NodeId, SvgSegmentList>>,
283+
pub(crate) thumbnails: HashMap<GraphIdentifier, HashMap<NodeId, SvgSegmentList>>,
267284
futures: HashMap<u64, ExecutionContext>,
268285
}
269286

@@ -516,7 +533,7 @@ impl NodeGraphExecutor {
516533

517534
/// When a blob url for a thumbnail is loaded, update the state and the UI.
518535
pub fn insert_thumbnail_blob_url(&mut self, blob_url: String, layer_id: Option<LayerId>, node_id: NodeId, responses: &mut VecDeque<Message>) {
519-
if let Some(layer) = self.thumbnails.get_mut(&layer_id) {
536+
if let Some(layer) = self.thumbnails.get_mut(&GraphIdentifier::new(layer_id)) {
520537
if let Some(segment) = layer.values_mut().flat_map(|segments| segments.iter_mut()).find(|segment| **segment == SvgSegment::BlobUrl(node_id)) {
521538
*segment = SvgSegment::String(blob_url);
522539
responses.add(NodeGraphMessage::SendGraph { should_rerender: false });

0 commit comments

Comments
 (0)