diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-07 11:24:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-07 11:24:06 +0100 |
commit | 5851f0ff3a920dfa9fa811f1b4b47794f50c0543 (patch) | |
tree | 7cefdc652d3dae3a699a73ad8f7d78fad177f1d2 | |
parent | 40d1694e4e915d6bc94c3a2098766954f58dfb1e (diff) | |
parent | 07fb7f9888126d189476ec9a6272447b7c9748ac (diff) |
Merge pull request #45776 from Kanabenki/snap-visualscript-comment
Snap VisualScript comment to grid when resizing
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 78e4a7f113..92b83f3db0 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -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; |