diff --git a/document-legacy/src/document_metadata.rs b/document-legacy/src/document_metadata.rs index 9e1830cb..b2ab66a0 100644 --- a/document-legacy/src/document_metadata.rs +++ b/document-legacy/src/document_metadata.rs @@ -321,7 +321,7 @@ impl DocumentMetadata { /// Calculates the document bounds in document space pub fn document_bounds_document_space(&self, include_artboards: bool) -> Option<[DVec2; 2]> { self.all_layers() - .filter(|&layer| include_artboards || self.is_artboard(layer)) + .filter(|&layer| include_artboards || !self.is_artboard(layer)) .filter_map(|layer| self.bounding_box_document(layer)) .reduce(Quad::combine_bounds) } @@ -329,7 +329,7 @@ impl DocumentMetadata { /// Calculates the selected layer bounds in document space pub fn selected_bounds_document_space(&self, include_artboards: bool) -> Option<[DVec2; 2]> { self.selected_layers() - .filter(|&layer| include_artboards || self.is_artboard(layer)) + .filter(|&layer| include_artboards || !self.is_artboard(layer)) .filter_map(|layer| self.bounding_box_document(layer)) .reduce(Quad::combine_bounds) } diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index d8558264..aabf04f5 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -296,7 +296,6 @@ impl MessageHandler> for DocumentMessageHand info!("{:#?}\n{:#?}", self.document_legacy, self.layer_metadata); } DeleteLayer { layer_path } => { - responses.add_front(DocumentOperation::DeleteLayer { path: layer_path.clone() }); responses.add(GraphOperationMessage::DeleteLayer { id: layer_path[0] }); responses.add_front(BroadcastEvent::ToolAbort); responses.add(PropertiesPanelMessage::CheckSelectedWasDeleted { path: layer_path }); diff --git a/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs b/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs index 74321752..904b86ca 100644 --- a/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs +++ b/editor/src/messages/portfolio/document/node_graph/graph_operation_message_handler.rs @@ -709,6 +709,7 @@ impl MessageHandler { let mut modify_inputs = ModifyInputsContext::new(document, node_graph, responses); modify_inputs.delete_layer(id); + document.load_network_structure(); } GraphOperationMessage::ClearArtboards => { let mut modify_inputs = ModifyInputsContext::new(document, node_graph, responses); diff --git a/editor/src/messages/tool/common_functionality/resize.rs b/editor/src/messages/tool/common_functionality/resize.rs index 5930456c..f9fb739e 100644 --- a/editor/src/messages/tool/common_functionality/resize.rs +++ b/editor/src/messages/tool/common_functionality/resize.rs @@ -48,6 +48,10 @@ impl Resize { let Some(layer) = self.layer else { return None; }; + if !document.network().nodes.contains_key(&layer.to_node()) { + self.layer.take(); + return None; + } let mut start = self.viewport_drag_start(document); let stop = self.snap_manager.snap_position(responses, document, ipp.mouse.position); diff --git a/node-graph/gcore/src/graphic_element/renderer.rs b/node-graph/gcore/src/graphic_element/renderer.rs index 8cac0f3f..b54d8d44 100644 --- a/node-graph/gcore/src/graphic_element/renderer.rs +++ b/node-graph/gcore/src/graphic_element/renderer.rs @@ -227,6 +227,10 @@ pub trait GraphicElementRendered { root: root_node.clone(), } } + + fn contains_artboard(&self) -> bool { + false + } } impl GraphicElementRendered for GraphicGroup { @@ -265,6 +269,10 @@ impl GraphicElementRendered for GraphicGroup { } root_node } + + fn contains_artboard(&self) -> bool { + self.iter().any(|element| element.contains_artboard()) + } } impl GraphicElementRendered for VectorData { @@ -427,6 +435,10 @@ impl GraphicElementRendered for Artboard { let subpath = Subpath::new_rect(DVec2::ZERO, self.dimensions.as_dvec2()); click_targets.push(ClickTarget { stroke_width: 0., subpath }); } + + fn contains_artboard(&self) -> bool { + true + } } impl GraphicElementRendered for ImageFrame { @@ -546,6 +558,16 @@ impl GraphicElementRendered for GraphicElement { GraphicElement::Artboard(artboard) => artboard.to_usvg_node(), } } + + fn contains_artboard(&self) -> bool { + match self { + GraphicElement::VectorData(vector_data) => vector_data.contains_artboard(), + GraphicElement::ImageFrame(image_frame) => image_frame.contains_artboard(), + GraphicElement::Text(text) => text.contains_artboard(), + GraphicElement::GraphicGroup(graphic_group) => graphic_group.contains_artboard(), + GraphicElement::Artboard(artboard) => artboard.contains_artboard(), + } + } } /// Used to stop rust complaining about upstream traits adding display implementations to `Option`. This would not be an issue as we control that crate. diff --git a/node-graph/gstd/src/wasm_application_io.rs b/node-graph/gstd/src/wasm_application_io.rs index 82941427..b24acf8d 100644 --- a/node-graph/gstd/src/wasm_application_io.rs +++ b/node-graph/gstd/src/wasm_application_io.rs @@ -4,7 +4,7 @@ use core::future::Future; use dyn_any::StaticType; use graphene_core::application_io::{ApplicationError, ApplicationIo, ExportFormat, RenderConfig, ResourceFuture, SurfaceHandle, SurfaceHandleFrame, SurfaceId}; use graphene_core::raster::Image; -use graphene_core::renderer::{GraphicElementRendered, ImageRenderMode, RenderParams, SvgRender}; +use graphene_core::renderer::{format_transform_matrix, GraphicElementRendered, ImageRenderMode, RenderParams, SvgRender}; use graphene_core::transform::Footprint; use graphene_core::Color; use graphene_core::{ @@ -291,8 +291,21 @@ pub struct RenderNode { } fn render_svg(data: impl GraphicElementRendered, mut render: SvgRender, render_params: RenderParams, footprint: Footprint) -> RenderOutput { + if !data.contains_artboard() && !render_params.hide_artboards { + render.leaf_tag("rect", |attributes| { + attributes.push("x", "0"); + attributes.push("x", "0"); + attributes.push("y", "0"); + attributes.push("width", footprint.resolution.x.to_string()); + attributes.push("height", footprint.resolution.y.to_string()); + attributes.push("transform", format_transform_matrix(footprint.transform.inverse())); + attributes.push("fill", "white"); + }); + } + data.render_svg(&mut render, &render_params); render.wrap_with_transform(footprint.transform, Some(footprint.resolution.as_dvec2())); + RenderOutput::Svg(render.svg.to_string()) }