Snap VisualScript comment to grid when resizing

This commit is contained in:
Kanabenki 2021-02-06 21:39:35 +01:00
parent fa2f7693bb
commit 07fb7f9888

View File

@ -3689,16 +3689,23 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_
return;
}
Vector2 new_size = p_new_size;
if (graph->is_using_snap()) {
Vector2 snap = Vector2(graph->get_snap(), graph->get_snap());
Vector2 min_size = (gn->get_minimum_size() + (snap * 0.5)).snapped(snap);
new_size = new_size.snapped(snap).max(min_size);
}
updating_graph = true;
graph->set_block_minimum_size_adjust(true); //faster resize
undo_redo->create_action(TTR("Resize Comment"), UndoRedo::MERGE_ENDS);
undo_redo->add_do_method(vsc.ptr(), "set_size", p_new_size / EDSCALE);
undo_redo->add_do_method(vsc.ptr(), "set_size", new_size / EDSCALE);
undo_redo->add_undo_method(vsc.ptr(), "set_size", vsc->get_size());
undo_redo->commit_action();
gn->set_custom_minimum_size(p_new_size);
gn->set_custom_minimum_size(new_size);
gn->set_size(Size2(1, 1));
graph->set_block_minimum_size_adjust(false);
updating_graph = false;