Skip to content

Commit 05b606e

Browse files
authored
reset ideal width and height on serialization (#16084)
* reset ideal width and height on serialization * stay safe
1 parent a0f9ab8 commit 05b606e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/dev/gui/src/2D/controls/control.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,6 @@ export class Control implements IAnimatable, IFocusableControl {
25982598
public clone(host?: AdvancedDynamicTexture): Control {
25992599
const serialization: any = {};
26002600
this.serialize(serialization, true);
2601-
26022601
const controlType = Tools.Instantiate("BABYLON.GUI." + serialization.className);
26032602
const cloned = new controlType();
26042603
cloned.parse(serialization, host);
@@ -2634,6 +2633,16 @@ export class Control implements IAnimatable, IFocusableControl {
26342633
if (!this.isSerializable && !force) {
26352634
return;
26362635
}
2636+
let idealWidth = 0;
2637+
let idealHeight = 0;
2638+
// the host's ideal width and height are influencing the serialization, as they are used in getValue() of ValueAndUnit.
2639+
// for a proper serialization, we need to temporarily set them to 0 and re-set them back afterwards.
2640+
if (this.host) {
2641+
idealHeight = this.host.idealHeight;
2642+
idealWidth = this.host.idealWidth;
2643+
this.host.idealWidth = 0;
2644+
this.host.idealHeight = 0;
2645+
}
26372646
SerializationHelper.Serialize(this, serializationObject);
26382647
serializationObject.name = this.name;
26392648
serializationObject.className = this.getClassName();
@@ -2662,6 +2671,11 @@ export class Control implements IAnimatable, IFocusableControl {
26622671

26632672
// Animations
26642673
SerializationHelper.AppendSerializedAnimations(this, serializationObject);
2674+
// re-set the ideal width and height
2675+
if (this.host) {
2676+
this.host.idealWidth = idealWidth;
2677+
this.host.idealHeight = idealHeight;
2678+
}
26652679
}
26662680

26672681
/**

0 commit comments

Comments
 (0)