Fixes for removing artboards; white infinite canvas background (#1497)
* Fix crash when drawing on a deleted artboard * Fix clear artboards button * White background on no artboards * Re-disable Clear Artboards since it still crashes --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
33845707db
commit
b60736c2c6
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -296,7 +296,6 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> 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 });
|
||||
|
|
|
|||
|
|
@ -709,6 +709,7 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
|
|||
GraphOperationMessage::DeleteLayer { id } => {
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<Color> {
|
||||
|
|
@ -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<Color>`. This would not be an issue as we control that crate.
|
||||
|
|
|
|||
|
|
@ -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<Data, Surface, Parameter> {
|
|||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue