Artboard nodes (#1328)

* Create artboard nodes

* Update node when resizing artboard

* Render clipped artboards

* More stable feature

* Do not render old artboards

* Fix some issues with transforms

* Fix crash when drawing rectangle

* Format

* Allow renaming document from Properties panel

* Adjust artboard label styling

* Fix document graph refresh so artboards show up

* Make "Clear Artboards" coming soon

* Fix displaying an infinite canvas

* Show document name in node graph options bar

* info!() to debug!()

* Fix Properties panel not being cleared when all docs closed

* Remove dead code

* Remove debug logs added in this branch

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2023-07-27 07:35:17 +01:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent ad0dc3276e
commit 08f9be6aaf
26 changed files with 636 additions and 182 deletions
@@ -13,7 +13,7 @@ use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
use document_legacy::intersection::Quad;
use document_legacy::LayerId;
use glam::{DVec2, Vec2Swizzles};
use glam::{DVec2, IVec2, Vec2Swizzles};
use serde::{Deserialize, Serialize};
#[derive(Default)]
@@ -133,10 +133,6 @@ impl Fsm for ArtboardToolFsmState {
tool_data.bounding_box_overlays = Some(bounding_box_overlays);
responses.add(OverlaysMessage::Rerender);
responses.add(PropertiesPanelMessage::SetActiveLayers {
paths: vec![vec![tool_data.selected_artboard.unwrap()]],
document: TargetDocument::Artboard,
});
}
_ => {}
};
@@ -196,11 +192,6 @@ impl Fsm for ArtboardToolFsmState {
.start_snap(document, input, document.bounding_boxes(None, Some(intersection[0]), render_data), true, true);
tool_data.snap_manager.add_all_document_handles(document, input, &[], &[], &[]);
responses.add(PropertiesPanelMessage::SetActiveLayers {
paths: vec![intersection.clone()],
document: TargetDocument::Artboard,
});
ArtboardToolFsmState::Dragging
} else {
tool_data.selected_artboard = None;
@@ -226,6 +217,11 @@ impl Fsm for ArtboardToolFsmState {
position: position.round().into(),
size: size.round().into(),
});
responses.add(GraphOperationMessage::ResizeArtboard {
id: tool_data.selected_artboard.unwrap(),
location: position.round().as_ivec2(),
dimensions: size.round().as_ivec2(),
});
responses.add(BroadcastEvent::DocumentIsDirty);
}
@@ -251,6 +247,11 @@ impl Fsm for ArtboardToolFsmState {
position: position.round().into(),
size: size.round().into(),
});
responses.add(GraphOperationMessage::ResizeArtboard {
id: tool_data.selected_artboard.unwrap(),
location: position.round().as_ivec2(),
dimensions: size.round().as_ivec2(),
});
responses.add(BroadcastEvent::DocumentIsDirty);
@@ -285,6 +286,11 @@ impl Fsm for ArtboardToolFsmState {
position: start.round().into(),
size: size.round().into(),
});
responses.add(GraphOperationMessage::ResizeArtboard {
id: tool_data.selected_artboard.unwrap(),
location: start.round().as_ivec2(),
dimensions: size.round().as_ivec2(),
});
} else {
let id = generate_uuid();
tool_data.selected_artboard = Some(id);
@@ -297,14 +303,20 @@ impl Fsm for ArtboardToolFsmState {
position: start.round().into(),
size: (1., 1.),
});
responses.add(GraphOperationMessage::NewArtboard {
id,
artboard: graphene_core::Artboard {
graphic_group: graphene_core::GraphicGroup::EMPTY,
location: start.round().as_ivec2(),
dimensions: IVec2::splat(1),
background: graphene_core::Color::WHITE,
clip: false,
},
})
}
// Have to put message here instead of when Artboard is created
// This might result in a few more calls but it is not reliant on the order of messages
responses.add(PropertiesPanelMessage::SetActiveLayers {
paths: vec![vec![tool_data.selected_artboard.unwrap()]],
document: TargetDocument::Artboard,
});
responses.add(BroadcastEvent::DocumentIsDirty);
@@ -352,6 +364,8 @@ impl Fsm for ArtboardToolFsmState {
(_, ArtboardToolMessage::DeleteSelected) => {
if let Some(artboard) = tool_data.selected_artboard.take() {
responses.add(ArtboardMessage::DeleteArtboard { artboard });
responses.add(GraphOperationMessage::DeleteArtboard { id: artboard });
responses.add(BroadcastEvent::DocumentIsDirty);
}
ArtboardToolFsmState::Ready
@@ -363,6 +377,11 @@ impl Fsm for ArtboardToolFsmState {
position: (bounds.bounds[0].x + delta_x, bounds.bounds[0].y + delta_y),
size: (bounds.bounds[1] - bounds.bounds[0]).round().into(),
});
responses.add(GraphOperationMessage::ResizeArtboard {
id: tool_data.selected_artboard.unwrap(),
location: DVec2::new(bounds.bounds[0].x + delta_x, bounds.bounds[0].y + delta_y).round().as_ivec2(),
dimensions: (bounds.bounds[1] - bounds.bounds[0]).round().as_ivec2(),
});
}
ArtboardToolFsmState::Ready