diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-18 09:53:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-18 09:53:25 +0200 |
commit | d61d1af64d8f69cf0c9f46d32291e8b7313a0e52 (patch) | |
tree | e28df63c82dca77c0366d584b892a56e14bbee3d | |
parent | 3caed76edaead682e247fa6927676223779f4c7c (diff) | |
parent | df0a69bbaca690e1954d5048cc238acc8adeddb8 (diff) |
Merge pull request #29489 from groud/fixes_nan
Fixes NaN errors with anchors mode
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 9 | ||||
-rw-r--r-- | scene/gui/control.cpp | 3 |
2 files changed, 8 insertions, 4 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index fbf01a9405..3c24fd19b6 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -731,6 +731,8 @@ Vector2 CanvasItemEditor::_position_to_anchor(const Control *p_control, Vector2 ERR_FAIL_COND_V(!p_control, Vector2()); Rect2 parent_rect = p_control->get_parent_anchorable_rect(); + ERR_FAIL_COND_V(parent_rect.size.x == 0, Vector2()); + ERR_FAIL_COND_V(parent_rect.size.y == 0, Vector2()); return (p_control->get_transform().xform(position) - parent_rect.position) / parent_rect.size; } @@ -3348,9 +3350,6 @@ void CanvasItemEditor::_notification(int p_what) { presets_menu->set_visible(true); anchor_mode_button->set_visible(true); - // Set the pressed state of the node - anchor_mode_button->set_pressed(anchors_mode); - // Disable if the selected node is child of a container if (has_container_parents) { presets_menu->set_disabled(true); @@ -3521,6 +3520,7 @@ void CanvasItemEditor::_selection_changed() { } } anchors_mode = (nbValidControls == nbAnchorsMode); + anchor_mode_button->set_pressed(anchors_mode); } void CanvasItemEditor::edit(CanvasItem *p_canvas_item) { @@ -3742,6 +3742,7 @@ void CanvasItemEditor::_set_anchors_and_margins_preset(Control::LayoutPreset p_p undo_redo->commit_action(); anchors_mode = false; + anchor_mode_button->set_pressed(anchors_mode); } void CanvasItemEditor::_set_anchors_and_margins_to_keep_ratio() { @@ -3766,6 +3767,7 @@ void CanvasItemEditor::_set_anchors_and_margins_to_keep_ratio() { undo_redo->add_undo_method(control, "set_meta", "_edit_use_anchors_", use_anchors); anchors_mode = true; + anchor_mode_button->set_pressed(anchors_mode); } } @@ -3912,7 +3914,6 @@ void CanvasItemEditor::_button_toggle_anchor_mode(bool p_status) { } anchors_mode = p_status; - viewport->update(); } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 9d7c08d3f3..0845b56828 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1749,6 +1749,9 @@ Rect2 Control::_compute_child_rect(const float p_anchors[4], const float p_margi void Control::_compute_anchors(Rect2 p_rect, const float p_margins[4], float (&r_anchors)[4]) { Size2 parent_rect_size = get_parent_anchorable_rect().size; + ERR_FAIL_COND(parent_rect_size.x == 0.0); + ERR_FAIL_COND(parent_rect_size.y == 0.0); + r_anchors[0] = (p_rect.position.x - p_margins[0]) / parent_rect_size.x; r_anchors[1] = (p_rect.position.y - p_margins[1]) / parent_rect_size.y; r_anchors[2] = (p_rect.position.x + p_rect.size.x - p_margins[2]) / parent_rect_size.x; |