Skip to content

Commit

Permalink
feat(rsg): Add boundingrect function to node (#665)
Browse files Browse the repository at this point in the history
Implemented boundingRect function for roSGNode with zero-defaulted
values

https://developer.roku.com/docs/references/brightscript/interfaces/ifsgnodeboundingrect.md
  • Loading branch information
underwoo16 committed Sep 20, 2021
1 parent 3ceb55a commit 8915cd4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/brsTypes/components/RoSGNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable {
this.issubtype,
this.parentsubtype,
],
ifSGNodeBoundingRect: [this.boundingRect],
});
}

Expand Down Expand Up @@ -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).
Expand Down
16 changes: 16 additions & 0 deletions test/brsTypes/components/RoSGNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
4 changes: 4 additions & 0 deletions test/e2e/RoSGNode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ describe("components/roSGNode", () => {
"invalid",
"33",
"37",
"0",
"0",
"0",
"0",
]);
});
});
7 changes: 7 additions & 0 deletions test/e2e/resources/components/roSGNode/roSGNode.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8915cd4

Please sign in to comment.