Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rsg): Add boundingrect function to node #665

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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