-
Notifications
You must be signed in to change notification settings - Fork 24
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
428 dynamic bounds margin #467
Open
Drulokia
wants to merge
5
commits into
main
Choose a base branch
from
428-dynamic-bounds-margin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5a3bcb4
Added boundsMargin to be able to set per node.
Drulokia 31a6a6b
Prevent unnecessary method calls and allow number or array property
Drulokia 98fc173
Cleanup Code
Drulokia fffffc7
Some fixes and tests
Drulokia a243846
Changed so renderBounds updateType propagates to all children. (not o…
Drulokia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2024 Comcast Cable Communications Management, LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { ExampleSettings } from '../common/ExampleSettings.js'; | ||
const TESTPAGES = 11; | ||
|
||
export async function automation(settings: ExampleSettings) { | ||
const testPageArray: number[] = []; | ||
for (let i = 1; i < TESTPAGES; i++) { | ||
testPageArray.push(i); | ||
} | ||
|
||
const page = await test(settings); | ||
// i = 0 | ||
await settings.snapshot(); | ||
|
||
let testIdx = 1; | ||
const testPage = async () => { | ||
console.log('Testing ', testIdx); | ||
page(testIdx); | ||
await settings.snapshot(); | ||
|
||
if (testIdx >= TESTPAGES) { | ||
return true; | ||
} | ||
|
||
testIdx++; | ||
await testPage(); | ||
}; | ||
|
||
// test first page | ||
await testPage(); | ||
} | ||
|
||
export default async function test({ renderer, testRoot }: ExampleSettings) { | ||
renderer.createTextNode({ | ||
text: 'Left/Right Arrow keys to move, Up/Down Arrow keys to change page, enter to reset', | ||
fontSize: 30, | ||
x: 10, | ||
y: 960, | ||
fontFamily: 'Ubuntu-ssdf', | ||
parent: testRoot, | ||
}); | ||
|
||
const boundaryRect1 = renderer.createNode({ | ||
x: 1920 / 2 - (1920 * 0.75) / 2, | ||
y: 1080 / 2 - (1080 * 0.75) / 2, | ||
width: 1440, | ||
height: 810, | ||
color: 0x000000ff, | ||
parent: testRoot, | ||
}); | ||
|
||
const boundaryRect2 = renderer.createNode({ | ||
x: 50, | ||
y: 50, | ||
width: 1440 - 100, | ||
height: 810 - 100, | ||
color: 0x222222ff, | ||
parent: boundaryRect1, | ||
}); | ||
|
||
const redText = renderer.createTextNode({ | ||
x: 500, | ||
y: 305, | ||
alpha: 1, | ||
width: 200, | ||
height: 200, | ||
color: 0xff0000ff, | ||
pivot: 0, | ||
text: 'red', | ||
fontSize: 80, | ||
fontFamily: 'sans-serif', | ||
parent: boundaryRect2, | ||
}); | ||
|
||
const statusText = renderer.createTextNode({ | ||
text: 'Status: Inside viewport', | ||
fontSize: 30, | ||
x: 10, | ||
y: 10, | ||
fontFamily: 'Ubuntu-ssdf', | ||
parent: testRoot, | ||
}); | ||
|
||
const testPage = renderer.createTextNode({ | ||
text: `Test Page: 0`, | ||
fontSize: 30, | ||
x: 10, | ||
y: 50, | ||
parent: testRoot, | ||
}); | ||
|
||
const boundsMarginText = renderer.createTextNode({ | ||
text: 'Text BoundsMargin: ', | ||
fontSize: 30, | ||
x: 800, | ||
y: 10, | ||
parent: testRoot, | ||
}); | ||
|
||
const redPosition = renderer.createTextNode({ | ||
text: `Text X Position: ${redText.x}`, | ||
fontSize: 30, | ||
x: 800, | ||
y: 50, | ||
parent: testRoot, | ||
}); | ||
|
||
redText.on('outOfBounds', () => { | ||
statusText.text = `Status: Out of bounds`; | ||
statusText.color = 0xff0000ff; | ||
boundsMarginText.text = `Text BoundsMargin: ${redText.boundsMargin}`; | ||
}); | ||
|
||
redText.on('inViewport', () => { | ||
statusText.text = `Status: Inside viewport`; | ||
statusText.color = 0x00ff00ff; | ||
boundsMarginText.text = `Text BoundsMargin: ${redText.boundsMargin}`; | ||
}); | ||
|
||
redText.on('inBounds', () => { | ||
statusText.text = 'Status: Inside renderbounds'; | ||
statusText.color = 0xffff00ff; | ||
boundsMarginText.text = `Text BoundsMargin: ${redText.boundsMargin}`; | ||
}); | ||
|
||
const page = (i = 1) => { | ||
console.log('Running test page', i); | ||
testPage.text = `Test Page ${i}`; | ||
switch (i) { | ||
// reset | ||
case 0: | ||
renderer.stage.setBoundsMargin(100); | ||
boundaryRect1.boundsMargin = null; | ||
redText.boundsMargin = null; | ||
redText.x = 500; | ||
testPageIdx = 0; | ||
boundaryRect1.clipping = false; | ||
break; | ||
|
||
// Text inside render bounds | ||
case 1: | ||
redText.x = -500; | ||
break; | ||
|
||
// Text out of bounds | ||
case 2: | ||
redText.x = -600; | ||
break; | ||
|
||
// stage bounds margin increased to 200 should be in bounds | ||
case 3: | ||
renderer.stage.setBoundsMargin(200); | ||
break; | ||
|
||
// Text out of bounds | ||
case 4: | ||
redText.x = -700; | ||
break; | ||
|
||
// first parent text in view | ||
case 5: | ||
boundaryRect1.clipping = true; | ||
redText.x = -100; | ||
boundaryRect1.boundsMargin = 100; | ||
break; | ||
|
||
// first parent text inside render bounds | ||
case 6: | ||
redText.x = -200; | ||
boundaryRect1.boundsMargin = 100; | ||
break; | ||
|
||
// first parent text out of bounds | ||
case 7: | ||
redText.x = -300; | ||
boundaryRect1.boundsMargin = 100; | ||
break; | ||
|
||
// first parent change boundsMargin should be in render bounds | ||
case 8: | ||
boundaryRect1.boundsMargin = 200; | ||
redText.x = -300; | ||
break; | ||
|
||
// boundsmargin on text should be in viewport | ||
case 9: | ||
redText.x = 0; | ||
redText.boundsMargin = 300; | ||
break; | ||
|
||
// boundsmargin on text should be inside render bounds | ||
case 10: | ||
redText.x = -200; | ||
redText.boundsMargin = 300; | ||
break; | ||
|
||
// boundsmargin on text should be out of bounds | ||
case 11: | ||
redText.x = -500; | ||
redText.boundsMargin = 300; | ||
break; | ||
} | ||
redPosition.text = `Text X Position: ${redText.x}`; | ||
}; | ||
const moveModifier = 100; | ||
const numKeys: string[] = []; | ||
for (let i = 0; i < 10; i++) { | ||
numKeys.push(i.toString()); | ||
} | ||
|
||
let testPageIdx = 0; | ||
window.onkeydown = (e) => { | ||
if (numKeys.indexOf(e.key) !== -1) { | ||
page(parseInt(e.key)); | ||
} | ||
|
||
if (e.key === 'ArrowRight') { | ||
redText.x += moveModifier; | ||
redPosition.text = `Text X Position: ${redText.x}`; | ||
} | ||
|
||
if (e.key === 'ArrowLeft') { | ||
redText.x -= moveModifier; | ||
redPosition.text = `Text X Position: ${redText.x}`; | ||
} | ||
|
||
if (e.key === 'ArrowDown') { | ||
if (testPageIdx <= 0) { | ||
testPageIdx = TESTPAGES; | ||
} else { | ||
testPageIdx--; | ||
} | ||
page(testPageIdx); | ||
} | ||
|
||
if (e.key === 'ArrowUp') { | ||
if (testPageIdx >= TESTPAGES) { | ||
testPageIdx = 0; | ||
} else { | ||
testPageIdx++; | ||
} | ||
page(testPageIdx); | ||
} | ||
|
||
if (e.key === 'Enter') { | ||
page(0); | ||
} | ||
}; | ||
|
||
return page; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left over from the new type?