Avoid incorrect computing anchor of Control node when reset on save
This commit is contained in:
parent
7ebc866418
commit
57cd00aee9
|
@ -1383,6 +1383,15 @@ void Control::_set_position(const Point2 &p_point) {
|
|||
|
||||
void Control::set_position(const Point2 &p_point, bool p_keep_offsets) {
|
||||
ERR_MAIN_THREAD_GUARD;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
// Can't compute anchors, set position directly and return immediately.
|
||||
if (saving && !is_inside_tree()) {
|
||||
data.pos_cache = p_point;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p_keep_offsets) {
|
||||
_compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor);
|
||||
} else {
|
||||
|
@ -1441,6 +1450,14 @@ void Control::set_size(const Size2 &p_size, bool p_keep_offsets) {
|
|||
new_size.y = min.y;
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
// Can't compute anchors, set size directly and return immediately.
|
||||
if (saving && !is_inside_tree()) {
|
||||
data.size_cache = new_size;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p_keep_offsets) {
|
||||
_compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor);
|
||||
} else {
|
||||
|
@ -3140,6 +3157,14 @@ Control *Control::make_custom_tooltip(const String &p_text) const {
|
|||
void Control::_notification(int p_notification) {
|
||||
ERR_MAIN_THREAD_GUARD;
|
||||
switch (p_notification) {
|
||||
#ifdef TOOLS_ENABLED
|
||||
case NOTIFICATION_EDITOR_PRE_SAVE: {
|
||||
saving = true;
|
||||
} break;
|
||||
case NOTIFICATION_EDITOR_POST_SAVE: {
|
||||
saving = false;
|
||||
} break;
|
||||
#endif
|
||||
case NOTIFICATION_POSTINITIALIZE: {
|
||||
data.initialized = true;
|
||||
|
||||
|
|
|
@ -47,6 +47,10 @@ class ThemeContext;
|
|||
class Control : public CanvasItem {
|
||||
GDCLASS(Control, CanvasItem);
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
bool saving = false;
|
||||
#endif
|
||||
|
||||
public:
|
||||
enum Anchor {
|
||||
ANCHOR_BEGIN = 0,
|
||||
|
|
Loading…
Reference in New Issue