Browse Source

Restored Control layout properties you undo a parenting of a Control to a Container

(cherry picked from commit 5614e6d61ca5de6c75af2adf5c55e70f4bcd5ec5)
Sofox 1 year ago
parent
commit
21a510b5ea
1 changed files with 6 additions and 1 deletions
  1. 6 1
      editor/scene_tree_dock.cpp

+ 6 - 1
editor/scene_tree_dock.cpp

@@ -2179,6 +2179,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
 		}
 		}
 
 
 		int child_pos = node->get_index(false);
 		int child_pos = node->get_index(false);
+		bool reparented_to_container = Object::cast_to<Container>(new_parent) && Object::cast_to<Control>(node);
 
 
 		undo_redo->add_undo_method(node->get_parent(), "add_child", node, true);
 		undo_redo->add_undo_method(node->get_parent(), "add_child", node, true);
 		undo_redo->add_undo_method(node->get_parent(), "move_child", node, child_pos);
 		undo_redo->add_undo_method(node->get_parent(), "move_child", node, child_pos);
@@ -2194,10 +2195,14 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
 			if (Object::cast_to<Node3D>(node)) {
 			if (Object::cast_to<Node3D>(node)) {
 				undo_redo->add_undo_method(node, "set_transform", Object::cast_to<Node3D>(node)->get_transform());
 				undo_redo->add_undo_method(node, "set_transform", Object::cast_to<Node3D>(node)->get_transform());
 			}
 			}
-			if (Object::cast_to<Control>(node)) {
+			if (!reparented_to_container && Object::cast_to<Control>(node)) {
 				undo_redo->add_undo_method(node, "set_position", Object::cast_to<Control>(node)->get_position());
 				undo_redo->add_undo_method(node, "set_position", Object::cast_to<Control>(node)->get_position());
 			}
 			}
 		}
 		}
+
+		if (reparented_to_container) {
+			undo_redo->add_undo_method(node, "_edit_set_state", Object::cast_to<Control>(node)->_edit_get_state());
+		}
 	}
 	}
 
 
 	perform_node_renames(nullptr, &path_renames);
 	perform_node_renames(nullptr, &path_renames);