Skip to content

Commit 606be8a

Browse files
pratikagrPratik Agrawal0HyperCube
authored
Make the Artboard tool shift its contents if resizing from the top/left so artwork is stationary (#2166)
* added fetch child layerfunction * Simplify --------- Co-authored-by: Pratik Agrawal <[email protected]> Co-authored-by: hypercube <[email protected]>
1 parent 54926d5 commit 606be8a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

editor/src/messages/tool/tool_messages/artboard_tool.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::tool_prelude::*;
2+
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
23
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
34
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
45
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
@@ -111,6 +112,7 @@ struct ArtboardToolData {
111112
drag_current: DVec2,
112113
auto_panning: AutoPanning,
113114
snap_candidates: Vec<SnapCandidatePoint>,
115+
dragging_current_artboad_location: IVec2,
114116
}
115117

116118
impl ArtboardToolData {
@@ -138,6 +140,7 @@ impl ArtboardToolData {
138140
fn start_resizing(&mut self, _selected_edges: (bool, bool, bool, bool), _document: &DocumentMessageHandler, _input: &InputPreprocessorMessageHandler) {
139141
if let Some(bounds) = &mut self.bounding_box_manager {
140142
bounds.center_of_transformation = bounds.transform.transform_point2((bounds.bounds[0] + bounds.bounds[1]) / 2.);
143+
self.dragging_current_artboad_location = bounds.bounds[0].round().as_ivec2();
141144
}
142145
}
143146

@@ -197,18 +200,17 @@ impl ArtboardToolData {
197200
dimensions: size.round().as_ivec2(),
198201
});
199202

200-
// TODO: Resize artboard children when resizing left/top edges so that they stay in the same viewport space
201-
// let old_top_left = bounds.bounds[0].round().as_ivec2();
202-
// let new_top_left = position.round().as_ivec2();
203-
// let top_left_delta = new_top_left - old_top_left;
204-
// if top_left_delta != IVec2::ZERO {
205-
// responses.add(GraphOperationMessage::TransformChange {
206-
// layer: self.selected_artboard.unwrap(),
207-
// transform: DAffine2::from_translation((-top_left_delta).into()),
208-
// transform_in: TransformIn::Local,
209-
// skip_rerender: false,
210-
// });
211-
// }
203+
let translation = position.round().as_ivec2() - self.dragging_current_artboad_location;
204+
self.dragging_current_artboad_location = position.round().as_ivec2();
205+
for child in self.selected_artboard.unwrap().children(&document.metadata()) {
206+
let local_translation = document.metadata().downstream_transform_to_document(child).inverse().transform_vector2(-translation.as_dvec2());
207+
responses.add(GraphOperationMessage::TransformChange {
208+
layer: child,
209+
transform: DAffine2::from_translation(local_translation),
210+
transform_in: TransformIn::Local,
211+
skip_rerender: false,
212+
});
213+
}
212214
}
213215
}
214216

0 commit comments

Comments
 (0)