Visualize Your Ideas With Code
fix(2d): clone size correctly (#562)
Jacobcdd3df1bff25
diff --git a/packages/2d/src/components/Layout.ts b/packages/2d/src/components/Layout.tsindex 3c0fd27a..749eda60 100644--- a/packages/2d/src/components/Layout.ts+++ b/packages/2d/src/components/Layout.ts@@ -228,8 +228,67 @@ export class Layout extends Node {this.customY(value);}+ /**+ * Represents the size of this node.+ *+ * @remarks+ * A size is a two-dimensional vector, where `x` represents the `width`, and `y`+ * represents the `height`.+ *+ * The value of both x and y is of type {@link partials.Length} which is+ * either:+ * - `number` - the desired length in pixels+ * - `${number}%` - a string with the desired length in percents, for example+ * `'50%'`+ * - `null` - an automatic length+ *+ * When retrieving the size, all units are converted to pixels, using the+ * current state of the layout. For example, retrieving the width set to+ * `'50%'`, while the parent has a width of `200px` will result in the number+ * `100` being returned.+ *+ * When the node is not part of the layout, setting its size using percents+ * refers to the size of the entire scene.+ *+ * @example+ * Initializing the size:+ * ```tsx+ * // with a possible vector:+ * <Node size={['50%', 200]} />+ * // with individual components:+ * <Node width={'50%'} height={200} />+ * ```+ *+ * Accessing the size:+ * ```tsx+ * // retrieving the vector:+ * const size = node.size();+ * // retrieving an individual component:+ * const width = node.size.x();+ * ```+ *+ * Setting the size:+ * ```tsx+ * // with a possible vector:+ * node.size(['50%', 200]);+ * node.size(() => ['50%', 200]);+ * // with individual components:+ * node.size.x('50%');+ * node.size.x(() => '50%');+ * ```+ */+ @cloneable(false)+ @initial({x: null, y: null})+ @vector2Signal({x: 'width', y: 'height'})+ public declare readonly size: Vector2LengthSignal<this>;+ public get width(): Signal<Length, number, this> {+ return this.size.x;+ }+ public get height(): Signal<Length, number, this> {+ return this.size.y;+ }+@inspectable(false)- @initial(null)@signal()protected declare readonly customWidth: SimpleSignal<DesiredLength, this>;@@ -274,7 +333,6 @@ export class Layout extends Node {}@inspectable(false)- @initial(null)@signal()protected declare readonly customHeight: SimpleSignal<DesiredLength, this>;@@ -319,66 +377,6 @@ export class Layout extends Node {lock && this.releaseSize();}- /**- * Represents the size of this node.- *- * @remarks- * A size is a two-dimensional vector, where `x` represents the `width`, and `y`- * represents the `height`.- *- * The value of both x and y is of type {@link partials.Length} which is- * either:- * - `number` - the desired length in pixels- * - `${number}%` - a string with the desired length in percents, for example- * `'50%'`- * - `null` - an automatic length- *- * When retrieving the size, all units are converted to pixels, using the- * current state of the layout. For example, retrieving the width set to- * `'50%'`, while the parent has a width of `200px` will result in the number- * `100` being returned.- *- * When the node is not part of the layout, setting its size using percents- * refers to the size of the entire scene.- *- * @example- * Initializing the size:- * ```tsx- * // with a possible vector:- * <Node size={['50%', 200]} />- * // with individual components:- * <Node width={'50%'} height={200} />- * ```- *- * Accessing the size:- * ```tsx- * // retrieving the vector:- * const size = node.size();- * // retrieving an individual component:- * const width = node.size.x();- * ```- *- * Setting the size:- * ```tsx- * // with a possible vector:- * node.size(['50%', 200]);- * node.size(() => ['50%', 200]);- * // with individual components:- * node.size.x('50%');- * node.size.x(() => '50%');- * ```- */- @cloneable(false)- @initial({x: null, y: null})- @vector2Signal({x: 'width', y: 'height'})- public declare readonly size: Vector2LengthSignal<this>;- public get width(): Signal<Length, number, this> {- return this.size.x;- }- public get height(): Signal<Length, number, this> {- return this.size.y;- }-/*** Get the desired size of this node.*