Fix artboard thumbnails

This commit is contained in:
0hypercube 2023-07-30 12:03:56 +01:00 committed by Keavon Chambers
parent b2397b06c6
commit 5b61a30c2a
3 changed files with 9 additions and 8 deletions

View File

@ -24,6 +24,9 @@ impl MessageHandler<InputPreprocessorMessage, KeyboardPlatformLayout> for InputP
assert_eq!(bounds_of_viewports.len(), 1, "Only one viewport is currently supported"); assert_eq!(bounds_of_viewports.len(), 1, "Only one viewport is currently supported");
for bounds in bounds_of_viewports { for bounds in bounds_of_viewports {
let new_size = bounds.size();
let existing_size = self.viewport_bounds.size();
// TODO: Extend this to multiple viewports instead of setting it to the value of this last loop iteration // TODO: Extend this to multiple viewports instead of setting it to the value of this last loop iteration
self.viewport_bounds = bounds; self.viewport_bounds = bounds;

View File

@ -345,8 +345,7 @@ impl NodeGraphMessageHandler {
}); });
let primary_output = outputs.next(); let primary_output = outputs.next();
let graph_identifier = GraphIdentifier::new(layer_id); let thumbnail_svg = executor.thumbnails.get(&layer_id).and_then(|thumbnails| thumbnails.get(id)).map(|svg| svg.to_string());
let thumbnail_svg = executor.thumbnails.get(&graph_identifier).and_then(|thumbnails| thumbnails.get(id)).map(|svg| svg.to_string());
nodes.push(FrontendNode { nodes.push(FrontendNode {
id: *id, id: *id,

View File

@ -52,7 +52,7 @@ pub struct NodeRuntime {
sender: InternalNodeGraphUpdateSender, sender: InternalNodeGraphUpdateSender,
wasm_io: Option<WasmApplicationIo>, wasm_io: Option<WasmApplicationIo>,
imaginate_preferences: ImaginatePreferences, imaginate_preferences: ImaginatePreferences,
pub(crate) thumbnails: HashMap<GraphIdentifier, HashMap<NodeId, SvgSegmentList>>, pub(crate) thumbnails: HashMap<Option<LayerId>, HashMap<NodeId, SvgSegmentList>>,
canvas_cache: HashMap<Vec<LayerId>, SurfaceId>, canvas_cache: HashMap<Vec<LayerId>, SurfaceId>,
} }
@ -73,7 +73,7 @@ pub(crate) struct GenerationResponse {
generation_id: u64, generation_id: u64,
result: Result<TaggedValue, String>, result: Result<TaggedValue, String>,
updates: VecDeque<Message>, updates: VecDeque<Message>,
new_thumbnails: HashMap<GraphIdentifier, HashMap<NodeId, SvgSegmentList>>, new_thumbnails: HashMap<Option<LayerId>, HashMap<NodeId, SvgSegmentList>>,
} }
enum NodeGraphUpdate { enum NodeGraphUpdate {
@ -224,8 +224,7 @@ impl NodeRuntime {
render.format_svg(min, max); render.format_svg(min, max);
if let Some(node_id) = node_path.get(node_path.len() - 2).copied() { if let Some(node_id) = node_path.get(node_path.len() - 2).copied() {
let graph_identifier = GraphIdentifier::new(layer_path.last().copied()); let old_thumbnail = self.thumbnails.entry(layer_path.last().copied()).or_default().entry(node_id).or_default();
let old_thumbnail = self.thumbnails.entry(graph_identifier).or_default().entry(node_id).or_default();
if *old_thumbnail != render.svg { if *old_thumbnail != render.svg {
*old_thumbnail = render.svg; *old_thumbnail = render.svg;
thumbnails_changed = true; thumbnails_changed = true;
@ -279,7 +278,7 @@ pub struct NodeGraphExecutor {
receiver: Receiver<NodeGraphUpdate>, receiver: Receiver<NodeGraphUpdate>,
// TODO: This is a memory leak since layers are never removed // TODO: This is a memory leak since layers are never removed
pub(crate) last_output_type: HashMap<Vec<LayerId>, Option<Type>>, pub(crate) last_output_type: HashMap<Vec<LayerId>, Option<Type>>,
pub(crate) thumbnails: HashMap<GraphIdentifier, HashMap<NodeId, SvgSegmentList>>, pub(crate) thumbnails: HashMap<Option<LayerId>, HashMap<NodeId, SvgSegmentList>>,
futures: HashMap<u64, ExecutionContext>, futures: HashMap<u64, ExecutionContext>,
} }
@ -529,7 +528,7 @@ impl NodeGraphExecutor {
/// When a blob url for a thumbnail is loaded, update the state and the UI. /// When a blob url for a thumbnail is loaded, update the state and the UI.
pub fn insert_thumbnail_blob_url(&mut self, blob_url: String, layer_id: Option<LayerId>, node_id: NodeId, responses: &mut VecDeque<Message>) { pub fn insert_thumbnail_blob_url(&mut self, blob_url: String, layer_id: Option<LayerId>, node_id: NodeId, responses: &mut VecDeque<Message>) {
if let Some(layer) = self.thumbnails.get_mut(&GraphIdentifier::new(layer_id)) { if let Some(layer) = self.thumbnails.get_mut(&layer_id) {
if let Some(segment) = layer.values_mut().flat_map(|segments| segments.iter_mut()).find(|segment| **segment == SvgSegment::BlobUrl(node_id)) { if let Some(segment) = layer.values_mut().flat_map(|segments| segments.iter_mut()).find(|segment| **segment == SvgSegment::BlobUrl(node_id)) {
*segment = SvgSegment::String(blob_url); *segment = SvgSegment::String(blob_url);
responses.add(NodeGraphMessage::SendGraph { should_rerender: false }); responses.add(NodeGraphMessage::SendGraph { should_rerender: false });