Skip to content

Commit 3be7505

Browse files
authored
Automatically place layers into the artboard they're drawn inside of (#2110)
* place new layer from basic tools within an artboard bounds Signed-off-by: James Ryans <james.ryans2012@gmail.com> * add for Text Tool Signed-off-by: James Ryans <james.ryans2012@gmail.com> * use click_xray function Signed-off-by: James Ryans <james.ryans2012@gmail.com> * support for freehand tool Signed-off-by: James Ryans <james.ryans2012@gmail.com> * support spline tool Signed-off-by: James Ryans <james.ryans2012@gmail.com> --------- Signed-off-by: James Ryans <james.ryans2012@gmail.com>
1 parent 337b8ba commit 3be7505

File tree

9 files changed

+16
-8
lines changed

9 files changed

+16
-8
lines changed

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,14 @@ impl DocumentMessageHandler {
16521652
}
16531653
}
16541654

1655+
/// Finds the artboard that bounds the point in viewport space and be the container of any newly added layers.
1656+
pub fn new_layer_bounding_artboard(&self, ipp: &InputPreprocessorMessageHandler) -> LayerNodeIdentifier {
1657+
self.click_xray(ipp)
1658+
.filter(|layer| self.network_interface.is_artboard(&layer.to_node(), &[]))
1659+
.next()
1660+
.unwrap_or(LayerNodeIdentifier::ROOT_PARENT)
1661+
}
1662+
16551663
/// Finds the parent folder which, based on the current selections, should be the container of any newly added layers.
16561664
pub fn new_layer_parent(&self, include_self: bool) -> LayerNodeIdentifier {
16571665
self.network_interface

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl Fsm for EllipseToolFsmState {
205205
let node = node_type.node_template_input_override([None, Some(NodeInput::value(TaggedValue::F64(0.5), false)), Some(NodeInput::value(TaggedValue::F64(0.5), false))]);
206206
let nodes = vec![(NodeId(0), node)];
207207

208-
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(true), responses);
208+
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
209209
responses.add(Message::StartBuffer);
210210
responses.add(GraphOperationMessage::TransformSet {
211211
layer,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl Fsm for FreehandToolFsmState {
238238

239239
responses.add(DocumentMessage::DeselectAllLayers);
240240

241-
let parent = document.new_layer_parent(true);
241+
let parent = document.new_layer_bounding_artboard(input);
242242

243243
let node_type = resolve_document_node_type("Path").expect("Path node does not exist");
244244
let node = node_type.default_node_template();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl Fsm for LineToolFsmState {
186186
]);
187187
let nodes = vec![(NodeId(0), node)];
188188

189-
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(false), responses);
189+
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
190190
responses.add(Message::StartBuffer);
191191
responses.add(GraphOperationMessage::TransformSet {
192192
layer,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl PenToolData {
492492
let node_type = resolve_document_node_type("Path").expect("Path node does not exist");
493493
let nodes = vec![(NodeId(0), node_type.default_node_template())];
494494

495-
let parent = document.new_layer_parent(true);
495+
let parent = document.new_layer_bounding_artboard(input);
496496
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, parent, responses);
497497
tool_options.fill.apply_fill(layer, responses);
498498
tool_options.stroke.apply_stroke(tool_options.line_weight, layer, responses);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Fsm for PolygonToolFsmState {
264264

265265
let nodes = vec![(NodeId(0), node)];
266266

267-
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(false), responses);
267+
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
268268
responses.add(Message::StartBuffer);
269269
responses.add(GraphOperationMessage::TransformSet {
270270
layer,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl Fsm for RectangleToolFsmState {
211211
let node = node_type.node_template_input_override([None, Some(NodeInput::value(TaggedValue::F64(1.), false)), Some(NodeInput::value(TaggedValue::F64(1.), false))]);
212212
let nodes = vec![(NodeId(0), node)];
213213

214-
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(true), responses);
214+
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
215215
responses.add(Message::StartBuffer);
216216
responses.add(GraphOperationMessage::TransformSet {
217217
layer,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl Fsm for SplineToolFsmState {
203203
responses.add(DocumentMessage::StartTransaction);
204204
responses.add(DocumentMessage::DeselectAllLayers);
205205

206-
let parent = document.new_layer_parent(true);
206+
let parent = document.new_layer_bounding_artboard(input);
207207

208208
tool_data.weight = tool_options.line_weight;
209209

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl TextToolData {
328328
size: editing_text.font_size,
329329
line_height_ratio: editing_text.line_height_ratio,
330330
character_spacing: editing_text.character_spacing,
331-
parent: document.new_layer_parent(true),
331+
parent: document.new_layer_bounding_artboard(input),
332332
insert_index: 0,
333333
});
334334
responses.add(Message::StartBuffer);

0 commit comments

Comments
 (0)