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:
commit
94b8a1d808
@ -1383,6 +1383,15 @@ void Control::_set_position(const Point2 &p_point) {
|
|||||||
|
|
||||||
void Control::set_position(const Point2 &p_point, bool p_keep_offsets) {
|
void Control::set_position(const Point2 &p_point, bool p_keep_offsets) {
|
||||||
ERR_MAIN_THREAD_GUARD;
|
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) {
|
if (p_keep_offsets) {
|
||||||
_compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor);
|
_compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor);
|
||||||
} else {
|
} else {
|
||||||
@ -1441,6 +1450,14 @@ void Control::set_size(const Size2 &p_size, bool p_keep_offsets) {
|
|||||||
new_size.y = min.y;
|
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) {
|
if (p_keep_offsets) {
|
||||||
_compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor);
|
_compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor);
|
||||||
} else {
|
} else {
|
||||||
@ -3140,6 +3157,14 @@ Control *Control::make_custom_tooltip(const String &p_text) const {
|
|||||||
void Control::_notification(int p_notification) {
|
void Control::_notification(int p_notification) {
|
||||||
ERR_MAIN_THREAD_GUARD;
|
ERR_MAIN_THREAD_GUARD;
|
||||||
switch (p_notification) {
|
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: {
|
case NOTIFICATION_POSTINITIALIZE: {
|
||||||
data.initialized = true;
|
data.initialized = true;
|
||||||
|
|
||||||
|
@ -47,6 +47,10 @@ class ThemeContext;
|
|||||||
class Control : public CanvasItem {
|
class Control : public CanvasItem {
|
||||||
GDCLASS(Control, CanvasItem);
|
GDCLASS(Control, CanvasItem);
|
||||||
|
|
||||||
|
#ifdef TOOLS_ENABLED
|
||||||
|
bool saving = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Anchor {
|
enum Anchor {
|
||||||
ANCHOR_BEGIN = 0,
|
ANCHOR_BEGIN = 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user