-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
track the fact that a canvas is provided so we don't overwrite its size #1322
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
Conversation
src/core/scene/a-scene.js
Outdated
|
|
||
| // Update canvas. | ||
| if (!isMobile) { | ||
| if (!isMobile && !canvas.provided) { |
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.
this assumes that those providing their own canvas are handling resizing themselves - which is probably a fair assumption
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.
yes, my personal use case is that i'd like to be able to dedicate some subset of the page to my aframe scene and have other html surrounding it. I would be assuming control over how much of the page my canvas occupies.
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.
You have canvas.a-canvas class available
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.
Though that is not specific, enough we could set <canvas data-aframe-provided> on the provided canvas
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.
yeah, it should be a data attribute IMO. I've seen non-browser properties get unset; tbh I don't know how browsers always handle those.
src/components/scene/canvas.js
Outdated
| canvas.style.width = data.width + '%'; | ||
| scene.appendChild(canvas); | ||
| } else { | ||
| canvas.dataset.aframeProvided = true; |
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.
this shouldn't be in the else
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.
i didn't fully understand the architecture. is everything that happens in this component the result of a provided canvas?
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.
You should move it up to the if statement where the provided canvas is created.
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.
Ah, I think the confusion is we're thinking "provided by A-Frame", and you're thinking "provided by user"
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.
ooo, I'll switch it to that then.
|
I've also created a boilerplate-canvas demo which is a simple adaptation of the boilerplate-helloworld demoing a user provided canvas. would you like me to include that? |
src/core/scene/a-scene.js
Outdated
|
|
||
| // Update canvas. | ||
| if (!isMobile) { | ||
| if (!isMobile && canvas.dataset.aframeProvided) { |
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.
I'd update the comment Update canvas if canvas was provided by A-Frame.
|
Yeah, maybe let's include that as a start for embedded/inline scenes? That's one of our goals: like: |
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Hello, World! • A-Frame</title> |
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.
perhaps change title to mention Embedded?
| </head> | ||
| <body> | ||
| <p>Through the looking glass.</p> | ||
| <canvas id="mycanvas"></canvas> |
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.
Maybe move the canvas into the scene element?
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.
I think it's fine to show that that's not necessary
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.
I'd encourage it to wrap everything up nicely.
|
btw I left the canvas element outside of the scene (with a comment) because to me that's one of the main motivations of this feature. I want to be able to declare my scene decoupled from where it's laid out in the page. |
src/components/scene/canvas.js
Outdated
| canvas.style.height = data.height + '%'; | ||
| canvas.style.width = data.width + '%'; | ||
| // Mark canvas as provided/injected by A-Frame. | ||
| canvas.dataset.aframeProvided = true; |
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.
In the light and camera systems we mark the default elements like this:
ambientLight.setAttribute('data-aframe-default-light', '');
cameraWrapperEl.setAttribute('data-aframe-default-camera', '');I think we should either change this or change the camera and light systems to follow this convention. @ngokevin what do you think?
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.
I would say we also add the aframeProvided data attribute to the lights/camera (#798), but need to keep the default-light/default-camera so they can be removed individually
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.
it's not clear to me if I should make a change here.
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.
No action required.
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.
Can we just changed the name to aframeDefault? We can merge after that
|
|
||
| <script> | ||
| var scene = document.querySelector('a-scene'); | ||
| function check () { |
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.
don't want you want to call check on resize of window?
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.
I'm adding it, just to confirm that aframe's resize logic doesn't overwrite the user provided canvas dimensions.
|
@enjalot this is almost ready - let us know when you've made the minor changes above. thanks! 😄 |
|
@cvan i think i've addressed all the concerns. let me know what else i can do |
|
Patch looks good. Still a bit of work to go for better support for embedded scenes, but this is a big step: @dmarcos look good? |
|
@enjalot Thanks! |
|
woot! |
|
nice! @dmarcos for future, you can use the github squash merge, the green button has a dropdown now |
|
@ngokevin I know the button but I don't always check that there's a single commit on the PR. |

Description:
This attempts to fix #1289 by keeping track of whether a canvas element was provided, and if so don't override it's width and height styles during resize.
Changes proposed:
I've made a new example including these changes in a aframe.min.js dist (ran
npm run diston my branch) which shows it seems to work:http://blockbuilder.org/enjalot/dfb4b1220ba76b63b8fa2ed2c5d517c3