Skip to content

Commit

Permalink
reset ideal width and height on serialization (#16084)
Browse files Browse the repository at this point in the history
* reset ideal width and height on serialization

* stay safe
  • Loading branch information
RaananW authored Jan 17, 2025
1 parent a0f9ab8 commit 05b606e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/dev/gui/src/2D/controls/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,6 @@ export class Control implements IAnimatable, IFocusableControl {
public clone(host?: AdvancedDynamicTexture): Control {
const serialization: any = {};
this.serialize(serialization, true);

const controlType = Tools.Instantiate("BABYLON.GUI." + serialization.className);
const cloned = new controlType();
cloned.parse(serialization, host);
Expand Down Expand Up @@ -2634,6 +2633,16 @@ export class Control implements IAnimatable, IFocusableControl {
if (!this.isSerializable && !force) {
return;
}
let idealWidth = 0;
let idealHeight = 0;
// the host's ideal width and height are influencing the serialization, as they are used in getValue() of ValueAndUnit.
// for a proper serialization, we need to temporarily set them to 0 and re-set them back afterwards.
if (this.host) {
idealHeight = this.host.idealHeight;
idealWidth = this.host.idealWidth;
this.host.idealWidth = 0;
this.host.idealHeight = 0;
}
SerializationHelper.Serialize(this, serializationObject);
serializationObject.name = this.name;
serializationObject.className = this.getClassName();
Expand Down Expand Up @@ -2662,6 +2671,11 @@ export class Control implements IAnimatable, IFocusableControl {

// Animations
SerializationHelper.AppendSerializedAnimations(this, serializationObject);
// re-set the ideal width and height
if (this.host) {
this.host.idealWidth = idealWidth;
this.host.idealHeight = idealHeight;
}
}

/**
Expand Down

0 comments on commit 05b606e

Please sign in to comment.