Allow deleting artboards (#533)

This commit is contained in:
0HyperCube 2022-02-10 20:03:14 +00:00 committed by Keavon Chambers
parent 77dc125095
commit 011f32395e
4 changed files with 26 additions and 6 deletions

View File

@ -18,9 +18,12 @@ pub enum ArtboardMessage {
position: (f64, f64),
size: (f64, f64),
},
DeleteArtboard {
artboard: LayerId,
},
RenderArtboards,
ResizeArtboard {
artboard: Vec<LayerId>,
artboard: LayerId,
position: (f64, f64),
size: (f64, f64),
},

View File

@ -55,6 +55,13 @@ impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
responses.push_back(DocumentMessage::RenderDocument.into());
}
DeleteArtboard { artboard } => {
self.artboard_ids.retain(|&id| id != artboard);
responses.push_back(ArtboardMessage::DispatchOperation(Box::new(DocumentOperation::DeleteLayer { path: vec![artboard] })).into());
responses.push_back(DocumentMessage::RenderDocument.into());
}
RenderArtboards => {
// Render an infinite canvas if there are no artboards
if self.artboard_ids.is_empty() {
@ -76,7 +83,7 @@ impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
ResizeArtboard { artboard, position, size } => {
responses.push_back(
ArtboardMessage::DispatchOperation(Box::new(DocumentOperation::SetLayerTransform {
path: artboard,
path: vec![artboard],
transform: DAffine2::from_scale_angle_translation(size.into(), 0., position.into()).to_cols_array(),
}))
.into(),

View File

@ -53,6 +53,8 @@ impl Default for Mapping {
entry! {action=CropMessage::PointerDown, key_down=Lmb},
entry! {action=CropMessage::PointerMove { constrain_axis_or_aspect: KeyShift, center: KeyAlt }, message=InputMapperMessage::PointerMove},
entry! {action=CropMessage::PointerUp, key_up=Lmb},
entry! {action=CropMessage::DeleteSelected, key_down=KeyDelete},
entry! {action=CropMessage::DeleteSelected, key_down=KeyBackspace},
// Navigate
entry! {action=NavigateMessage::ClickZoom { zoom_in: false }, key_up=Lmb, modifiers=[KeyShift]},
entry! {action=NavigateMessage::ClickZoom { zoom_in: true }, key_up=Lmb},

View File

@ -33,6 +33,7 @@ pub enum CropMessage {
DocumentIsDirty,
// Tool-specific messages
DeleteSelected,
PointerDown,
PointerMove {
constrain_axis_or_aspect: Key,
@ -61,7 +62,7 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Crop {
}
}
advertise_actions!(CropMessageDiscriminant; PointerDown, PointerUp, PointerMove, Abort);
advertise_actions!(CropMessageDiscriminant; PointerDown, PointerUp, PointerMove, DeleteSelected, Abort);
}
impl PropertyHolder for Crop {}
@ -201,7 +202,7 @@ impl Fsm for CropToolFsmState {
responses.push_back(
ArtboardMessage::ResizeArtboard {
artboard: vec![data.selected_board.unwrap()],
artboard: data.selected_board.unwrap(),
position: position.round().into(),
size: size.round().into(),
}
@ -229,7 +230,7 @@ impl Fsm for CropToolFsmState {
responses.push_back(
ArtboardMessage::ResizeArtboard {
artboard: vec![data.selected_board.unwrap()],
artboard: data.selected_board.unwrap(),
position: position.round().into(),
size: size.round().into(),
}
@ -265,7 +266,7 @@ impl Fsm for CropToolFsmState {
responses.push_back(
ArtboardMessage::ResizeArtboard {
artboard: vec![data.selected_board.unwrap()],
artboard: data.selected_board.unwrap(),
position: start.round().into(),
size: size.round().into(),
}
@ -315,6 +316,13 @@ impl Fsm for CropToolFsmState {
CropToolFsmState::Ready
}
(_, CropMessage::DeleteSelected) => {
if let Some(artboard) = data.selected_board.take() {
responses.push_back(ArtboardMessage::DeleteArtboard { artboard }.into());
responses.push_back(ToolMessage::DocumentIsDirty.into());
}
CropToolFsmState::Ready
}
(_, CropMessage::Abort) => {
if let Some(bounding_box_overlays) = data.bounding_box_overlays.take() {
bounding_box_overlays.delete(responses);