Merge pull request #91495 from TokageItLab/fix-control-saving

Avoid incorrect computing anchor of Control node when reset on save with `saving` flag
This commit is contained in:
Rémi Verschelde 2024-05-06 15:15:04 +02:00
commit 94b8a1d808
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 29 additions and 0 deletions

View file

@ -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;

View file

@ -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,