diff options
author | Gilles Roudiere <gilles.roudiere@gmail.com> | 2018-01-11 23:21:04 +0100 |
---|---|---|
committer | Gilles Roudiere <gilles.roudiere@gmail.com> | 2018-01-11 23:39:49 +0100 |
commit | 00473e08972121cad4d8a2f583620c93c3fa28a5 (patch) | |
tree | 8db4e3f4d88b550e10faed35735c02777a19d530 | |
parent | 9a6282975938106d17ccd49ef1b8c7fc4b11b3d2 (diff) |
Fixes nodes being resized or moved when changing an anchor
-rw-r--r-- | scene/gui/control.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 979a65f455..6503d1fb6d 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1357,24 +1357,32 @@ float Control::_a2s(float p_val, float p_anchor, float p_range) const { } void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bool p_push_opposite_anchor) { - bool pushed = false; + float parent_range = _get_parent_range((p_margin == MARGIN_LEFT || p_margin == MARGIN_RIGHT) ? 0 : 1); + float previous_margin_pos = data.margin[p_margin] + data.anchor[p_margin] * parent_range; + float previous_opposite_margin_pos = data.margin[(p_margin + 2) % 4] + data.anchor[(p_margin + 2) % 4] * parent_range; + data.anchor[p_margin] = CLAMP(p_anchor, 0.0, 1.0); if (((p_margin == MARGIN_LEFT || p_margin == MARGIN_TOP) && data.anchor[p_margin] > data.anchor[(p_margin + 2) % 4]) || ((p_margin == MARGIN_RIGHT || p_margin == MARGIN_BOTTOM) && data.anchor[p_margin] < data.anchor[(p_margin + 2) % 4])) { if (p_push_opposite_anchor) { data.anchor[(p_margin + 2) % 4] = data.anchor[p_margin]; - pushed = true; } else { data.anchor[p_margin] = data.anchor[(p_margin + 2) % 4]; } } - if (is_inside_tree()) { - if (p_keep_margin) { - _size_changed(); + if (!p_keep_margin) { + data.margin[p_margin] = _s2a(previous_margin_pos, data.anchor[p_margin], parent_range); + if (p_push_opposite_anchor) { + data.margin[(p_margin + 2) % 4] = _s2a(previous_opposite_margin_pos, data.anchor[(p_margin + 2) % 4], parent_range); } } + + if (is_inside_tree()) { + _size_changed(); + } + update(); _change_notify(); } |