Visualize Your Ideas With Code
feat: implement absolute scale setter
aarthificial842079a6547a
diff --git a/lerna.json b/lerna.jsonindex 4e7c2f38..746bd008 100644--- a/lerna.json+++ b/lerna.json@@ -4,10 +4,7 @@"useWorkspaces": true,"private": false,"version": "12.0.0-alpha.2",- "ignoreChanges": [- "**/*.test.ts",- "**/*.md"- ],+ "ignoreChanges": ["**/*.test.ts", "**/*.md"],"message": "ci(release): %v [skip ci]","conventionalCommits": true,"createRelease": "github"diff --git a/packages/2d/src/components/Layout.ts b/packages/2d/src/components/Layout.tsindex 9ce3788a..e9802d28 100644--- a/packages/2d/src/components/Layout.ts+++ b/packages/2d/src/components/Layout.ts@@ -384,7 +384,16 @@ export class Layout extends Node {}protected setAbsoluteScale(value: SignalValue<Vector2>) {- // TODO Implement setter+ if (isReactive(value)) {+ this.scale(() => this.getRelativeScale(value()));+ } else {+ this.scale(this.getRelativeScale(value));+ }+ }++ private getRelativeScale(scale: Vector2): Vector2 {+ const parentScale = this.parentTransform()?.absoluteScale() ?? Vector2.one;+ return scale.div(parentScale);}@compound(['x', 'y'], Vector2)@@ -566,11 +575,11 @@ export class Layout extends Node {this.element.innerText = '';const queue = [...this.children()];while (queue.length) {- const child = queue.shift()!;+ const child = queue.shift();if (child instanceof Layout) {this.element.append(child.element);child.updateLayout();- } else {+ } else if (child) {queue.push(...child.children());}}diff --git a/packages/core/src/types/Vector.ts b/packages/core/src/types/Vector.tsindex 23f1b091..fbf44263 100644--- a/packages/core/src/types/Vector.ts+++ b/packages/core/src/types/Vector.ts@@ -188,6 +188,10 @@ export class Vector2 {return new Vector2(this.x * vector.x, this.y * vector.y);}+ public div(vector: Vector2) {+ return new Vector2(this.x / vector.x, this.y / vector.y);+ }+public add(vector: Vector2) {return new Vector2(this.x + vector.x, this.y + vector.y);}diff --git a/packages/core/src/utils/range.ts b/packages/core/src/utils/range.tsindex 4ac67e9a..b45486d4 100644--- a/packages/core/src/utils/range.ts+++ b/packages/core/src/utils/range.ts@@ -1,13 +1,44 @@/**- * Create an array of given length containing its own indices.+ * Create an array containing a range of numbers.** @example* ```ts* const array = range(3); // [0, 1, 2]* ```*- * @param length+ * @param length - The length of the array.*/-export function range(length: number): number[] {- return [...Array(length).keys()];+export function range(length: number): number[];+/**+ * Create an array containing a range of numbers.+ *+ * @example+ * ```ts+ * const array = range(3, 7); // [3, 4, 5, 6]+ * ```+ *+ * @param from - The start of the range.+ * @param to - The end of the range. `to` itself is not included in the result.+ */+export function range(from: number, to: number): number[];+export function range(first: number, second?: number): number[] {+ let from = 0;+ let to = first;+ if (second !== undefined) {+ from = first;+ to = second;+ }++ const array = [];+ if (from > to) {+ for (let i = from; i > to; i--) {+ array.push(i);+ }+ } else {+ for (let i = from; i < to; i++) {+ array.push(i);+ }+ }++ return array;}