Place new layers in tree based on layer selection (#526)

* place new layers based on layer selection
This commit is contained in:
Wuelle 2022-02-09 19:54:38 +01:00 committed by Keavon Chambers
parent cb9a37b638
commit cc66ab06b0
9 changed files with 18 additions and 7 deletions

View file

@ -462,6 +462,16 @@ impl DocumentMessageHandler {
self.artboard_message_handler.artboards_graphene_document.viewport_bounding_box(&[]).ok().flatten()
}
}
/// Calculate the path that new layers should be inserted to.
/// Depends on the selected layers as well as their types (Folder/Non-Folder)
pub fn get_path_for_new_layer(&self) -> Vec<u64> {
// If the selected layers dont actually exist, a new uuid for the
// root folder will be returned
let mut path = self.graphene_document.shallowest_common_folder(self.selected_layers()).map_or(vec![], |v| v.to_vec());
path.push(generate_uuid());
path
}
}
impl PropertyHolder for DocumentMessageHandler {

View file

@ -111,7 +111,7 @@ impl Fsm for EllipseToolFsmState {
(Ready, DragStart) => {
shape_data.start(responses, input.viewport_bounds.size(), document, input.mouse.position);
responses.push_back(DocumentMessage::StartTransaction.into());
shape_data.path = Some(vec![generate_uuid()]);
shape_data.path = Some(document.get_path_for_new_layer());
responses.push_back(DocumentMessage::DeselectAllLayers.into());
responses.push_back(

View file

@ -148,7 +148,7 @@ impl Fsm for FreehandToolFsmState {
(Ready, DragStart) => {
responses.push_back(DocumentMessage::StartTransaction.into());
responses.push_back(DocumentMessage::DeselectAllLayers.into());
data.path = Some(vec![generate_uuid()]);
data.path = Some(document.get_path_for_new_layer());
let pos = transform.inverse().transform_point2(input.mouse.position);

View file

@ -159,7 +159,7 @@ impl Fsm for LineToolFsmState {
data.drag_start = data.snap_handler.snap_position(responses, input.viewport_bounds.size(), document, input.mouse.position);
responses.push_back(DocumentMessage::StartTransaction.into());
data.path = Some(vec![generate_uuid()]);
data.path = Some(document.get_path_for_new_layer());
responses.push_back(DocumentMessage::DeselectAllLayers.into());
data.weight = tool_options.line_weight;

View file

@ -153,7 +153,7 @@ impl Fsm for PenToolFsmState {
(Ready, DragStart) => {
responses.push_back(DocumentMessage::StartTransaction.into());
responses.push_back(DocumentMessage::DeselectAllLayers.into());
data.path = Some(vec![generate_uuid()]);
data.path = Some(document.get_path_for_new_layer());
data.snap_handler.start_snap(document, document.visible_layers(), true, true);
let snapped_position = data.snap_handler.snap_position(responses, input.viewport_bounds.size(), document, input.mouse.position);

View file

@ -110,7 +110,7 @@ impl Fsm for RectangleToolFsmState {
(Ready, DragStart) => {
shape_data.start(responses, input.viewport_bounds.size(), document, input.mouse.position);
responses.push_back(DocumentMessage::StartTransaction.into());
shape_data.path = Some(vec![generate_uuid()]);
shape_data.path = Some(document.get_path_for_new_layer());
responses.push_back(DocumentMessage::DeselectAllLayers.into());
responses.push_back(

View file

@ -151,7 +151,7 @@ impl Fsm for ShapeToolFsmState {
(Ready, DragStart) => {
shape_data.start(responses, input.viewport_bounds.size(), document, input.mouse.position);
responses.push_back(DocumentMessage::StartTransaction.into());
shape_data.path = Some(vec![generate_uuid()]);
shape_data.path = Some(document.get_path_for_new_layer());
responses.push_back(DocumentMessage::DeselectAllLayers.into());
data.sides = tool_options.vertices;

View file

@ -15,6 +15,7 @@ pub struct Resize {
pub path: Option<Vec<LayerId>>,
snap_handler: SnapHandler,
}
impl Resize {
/// Starts a resize, assigning the snap targets and snapping the starting position.
pub fn start(&mut self, responses: &mut VecDeque<Message>, viewport_bounds: DVec2, document: &DocumentMessageHandler, mouse_position: DVec2) {

View file

@ -246,7 +246,7 @@ impl Fsm for TextToolFsmState {
else if state == TextToolFsmState::Ready {
let transform = DAffine2::from_translation(input.mouse.position).to_cols_array();
let font_size = tool_options.font_size;
data.path = vec![generate_uuid()];
data.path = document.get_path_for_new_layer();
responses.push_back(
Operation::AddText {