Skip to content

Conversation

@enjalot
Copy link
Contributor

@enjalot enjalot commented Apr 1, 2016

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:

  • adds a boolean to the canvas element that the scene will check for in the resize function.

I've made a new example including these changes in a aframe.min.js dist (ran npm run dist on my branch) which shows it seems to work:
http://blockbuilder.org/enjalot/dfb4b1220ba76b63b8fa2ed2c5d517c3


// Update canvas.
if (!isMobile) {
if (!isMobile && !canvas.provided) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor

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.

@enjalot
Copy link
Contributor Author

enjalot commented Apr 1, 2016

@cvan @ngokevin i've updated the code to use data attributes, is this what you had in mind?

canvas.style.width = data.width + '%';
scene.appendChild(canvas);
} else {
canvas.dataset.aframeProvided = true;
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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"

Copy link
Contributor Author

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.

@enjalot
Copy link
Contributor Author

enjalot commented Apr 1, 2016

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?


// Update canvas.
if (!isMobile) {
if (!isMobile && canvas.dataset.aframeProvided) {
Copy link
Member

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.

@ngokevin
Copy link
Member

ngokevin commented Apr 1, 2016

Yeah, maybe let's include that as a start for embedded/inline scenes? That's one of our goals:

like: boilerplate-embedded-scenes

<html>
<head>
<meta charset="utf-8">
<title>Hello, World! • A-Frame</title>
Copy link
Contributor

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?

@cvan cvan changed the title track the fact that a canvas is provided so we don't overwrite it's size Apr 1, 2016
</head>
<body>
<p>Through the looking glass.</p>
<canvas id="mycanvas"></canvas>
Copy link
Member

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?

Copy link
Contributor

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

Copy link
Member

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.

@enjalot
Copy link
Contributor Author

enjalot commented Apr 2, 2016

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.

canvas.style.height = data.height + '%';
canvas.style.width = data.width + '%';
// Mark canvas as provided/injected by A-Frame.
canvas.dataset.aframeProvided = true;
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No action required.

Copy link
Member

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 () {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@cvan
Copy link
Contributor

cvan commented Apr 12, 2016

@enjalot this is almost ready - let us know when you've made the minor changes above. thanks! 😄

@enjalot
Copy link
Contributor Author

enjalot commented Apr 15, 2016

@cvan i think i've addressed all the concerns. let me know what else i can do

@ngokevin
Copy link
Member

Patch looks good. Still a bit of work to go for better support for embedded scenes, but this is a big step:

screen shot 2016-04-15 at 12 18 57 pm

@dmarcos look good?

@dmarcos
Copy link
Member

dmarcos commented Apr 19, 2016

@enjalot Thanks!

@dmarcos dmarcos merged commit 48691d3 into aframevr:master Apr 19, 2016
@enjalot
Copy link
Contributor Author

enjalot commented Apr 19, 2016

woot!

@ngokevin
Copy link
Member

nice!

@dmarcos for future, you can use the github squash merge, the green button has a dropdown now

@dmarcos
Copy link
Member

dmarcos commented Apr 19, 2016

@ngokevin I know the button but I don't always check that there's a single commit on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants