From 8915cd45ef474857d08c5d177dc6f802d07f1a38 Mon Sep 17 00:00:00 2001 From: Chandler Underwood Date: Mon, 20 Sep 2021 14:37:28 -0700 Subject: [PATCH] feat(rsg): Add boundingrect function to node (#665) Implemented boundingRect function for roSGNode with zero-defaulted values https://developer.roku.com/docs/references/brightscript/interfaces/ifsgnodeboundingrect.md --- src/brsTypes/components/RoSGNode.ts | 17 +++++++++++++++++ test/brsTypes/components/RoSGNode.test.js | 16 ++++++++++++++++ test/e2e/RoSGNode.test.js | 4 ++++ .../resources/components/roSGNode/roSGNode.brs | 7 +++++++ 4 files changed, 44 insertions(+) diff --git a/src/brsTypes/components/RoSGNode.ts b/src/brsTypes/components/RoSGNode.ts index 59802fd8..f4833ea8 100644 --- a/src/brsTypes/components/RoSGNode.ts +++ b/src/brsTypes/components/RoSGNode.ts @@ -373,6 +373,7 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable { this.issubtype, this.parentsubtype, ], + ifSGNodeBoundingRect: [this.boundingRect], }); } @@ -1503,6 +1504,22 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable { }, }); + private boundingRect = new Callable("boundingRect", { + signature: { + args: [], + returns: ValueKind.Dynamic, + }, + impl: (interpreter: Interpreter) => { + const zeroValue = new Int32(0); + return new RoAssociativeArray([ + { name: new BrsString("x"), value: zeroValue }, + { name: new BrsString("y"), value: zeroValue }, + { name: new BrsString("height"), value: zeroValue }, + { name: new BrsString("width"), value: zeroValue }, + ]); + }, + }); + /** * Starting with a leaf node, traverses upward through the parents until it reaches * a node without a parent (root node). diff --git a/test/brsTypes/components/RoSGNode.test.js b/test/brsTypes/components/RoSGNode.test.js index bbd0cb9a..24523f7d 100644 --- a/test/brsTypes/components/RoSGNode.test.js +++ b/test/brsTypes/components/RoSGNode.test.js @@ -2516,4 +2516,20 @@ describe("RoSGNode", () => { }); }); }); + + describe("ifSGNodeBoundingRect", () => { + let interpreter, node; + + beforeEach(() => { + interpreter = new Interpreter(); + node = new RoSGNode([{ name: new BrsString("id"), value: new BrsString("root") }]); + }); + + it("should return bounding rect", () => { + let boundingRectCall = node.getMethod("boundingRect"); + expect(boundingRectCall).toBeTruthy(); + let result = boundingRectCall.call(interpreter); + expect(result).toBeTruthy(); + }); + }); }); diff --git a/test/e2e/RoSGNode.test.js b/test/e2e/RoSGNode.test.js index e5330c07..bdc35420 100644 --- a/test/e2e/RoSGNode.test.js +++ b/test/e2e/RoSGNode.test.js @@ -209,6 +209,10 @@ describe("components/roSGNode", () => { "invalid", "33", "37", + "0", + "0", + "0", + "0", ]); }); }); diff --git a/test/e2e/resources/components/roSGNode/roSGNode.brs b/test/e2e/resources/components/roSGNode/roSGNode.brs index e6e49263..f490522b 100644 --- a/test/e2e/resources/components/roSGNode/roSGNode.brs +++ b/test/e2e/resources/components/roSGNode/roSGNode.brs @@ -213,6 +213,13 @@ sub init() ?node.FrameRate node.ClipStart = 37 ?node.ClipStart + + ' ifSGNodeBoundingRect + rect = node.boundingRect() + print rect.x ' => 0 + print rect.y ' => 0 + print rect.height ' => 0 + print rect.width ' => 0 end sub sub onCB1Called()