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

Widget tweaks #870

Merged
merged 15 commits into from
Jun 18, 2013
Merged

Widget tweaks #870

merged 15 commits into from
Jun 18, 2013

Conversation

mramato
Copy link
Contributor

@mramato mramato commented Jun 15, 2013

  1. Fixes Firefox Sandcastle resize issue on startup... #608 by forcing a resize every 60 frames.
  2. Add a useDefaultRenderLoop property and constructor option to CesiumWidget and Viewer so that users can turn on/off the default render loop at will.
  3. Have Viewer use the new property to disable the CesiumWidget render loop and use it's own instead.

1. Fixes #608 by adding a render counter and always resizing the window every 60 frames.
2. Add a `useDefaultRenderLoop` property and constructor option to `CesiumWidget` so that users can turn on/off the default render loop at will.
@@ -502,7 +503,8 @@ define([
};

Viewer.prototype._onTick = function(clock) {
if (this._needResize) {
if (this._needResize || this._resizeCounter === 60) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The code that checks _resizeCounter is in CesiumWidget, but this code is in Viewer. Shouldn't all these changes be in CesiumWidget?

1. Use frameNumber instead of a separate counter for determining when we should resize.
2. Have Viewer disable the default render loop and use it's own.
3. Expose `useDefaultRenderLoop` on Viewer as well.
@mramato
Copy link
Contributor Author

mramato commented Jun 17, 2013

@shunter ready for another look.

* Resizes the widget to match the container size.
* This function is called automatically as needed unless
* <code>useDefaultRenderLoop</code> is set to false.
* @memberof CesiumWidget
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong memberof here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was in two places in fact, both fixed.

return;
}

this._lastWidth = container.clientWidth;
Copy link
Contributor

Choose a reason for hiding this comment

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

_lastWidth and _lastHeight should be declared in the constructor like we normally do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also seems slightly more idiomatic to assign to the local var width / height first, then assign those to this_lastWidth / this._lastHeight rather than vice versa.

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 agree, I added these after the fact and it didn't occur to me to switch the order. Fixed.


if (width > 900) {
animationWidth = 169;
animationContainer.style.width = '169px';
Copy link
Contributor

Choose a reason for hiding this comment

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

I checked a JSPerf and there's a significant cost to setting style, even if you're setting it to the same value it already was. Since we call resize all the time now, we should cache these width/heights somewhere, as a number, and check them before setting them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we only set them when the window size has actually changed. So I'm not sure why this would be an issue?

`Animation` and `Timeline` no longer listen to `window.resize`.  Instead the `Viewer` resizes them as needed.  Also added checks to avoid unecessary resizing when the current size and new size are identical.
logoOffset.y = logoBottom;

if (timelineExists) {
this._timeline.container.style.left = animationExists ? animationWidth + 'px' : 0;
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 animationExists must be true here, given animationSizeChanged is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, no. animationSizeChanged is now misnamed. My last commit introduced crashes if the Timeline or Animation widget were turned off. I'm fixing it now.

@mramato
Copy link
Contributor Author

mramato commented Jun 17, 2013

Okay, I think everything is covered. You might want to do some extra testing by turning some widgets on/off in CesiumViewer to make sure you are happy with the behavior.

@@ -228,6 +247,12 @@ define([
fullscreenContainer.className = 'cesium-viewer-fullscreenContainer';
viewerContainer.appendChild(fullscreenContainer);
fullscreenButton = new FullscreenButton(fullscreenContainer, defaultValue(options.fullscreenElement, container));
if (!Fullscreen.isFullscreenEnabled()) {
fullscreenContainer.style.display = 'none';
timeline.container.style.right = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Crashes here if timeline is disabled and Fullscreen is not enabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, recall that the fullscreen button can be disabled separately via the view model. Perhaps it should observe the isFullscreenEnabled property instead?

var animationExists = typeof this._animation !== 'undefined';
var animationContainer;

var resizeWidgets = false || !animationExists;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this false || doing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops.

mramato added 2 commits June 17, 2013 17:21
1. Make Specs issue resize and add specs that combine cases that were causing resize to throw.
2. Observe `fullscreenButton.viewModel.isFullscreenEnabled` so that we can hide/show the button as needed.
3. Replace some hard-coded values with clientHeight/clientWidth;
fullscreenContainer.style.display = 'none';
}
if (typeof timeline !== 'undefined') {
timeline.container.style.right = fullscreenContainer.clientWidth;
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to call timeline.resize(); here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

…ptions generated by the default render loop. Also add code to prevent multiple render loops from being started simulataneously.
@mramato
Copy link
Contributor Author

mramato commented Jun 17, 2013

Well this pull request escalated quickly 😄 I fixed @emackey's concerns about the render loop and also added an event that gets raised if an exception is generated inside the default render loop. These exceptions are uncatchable by user code, so an event allows them to be propagated up. Let me know if that's anything else, otherwise this is ready.

this._lastWidth = 0;
this._lastHeight = 0;
this._useDefaultRenderLoop = undefined;
this._renderLoopShutdown = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to nitpick here, feel free to disregard. I don't like upside-down booleans where true means it's not running and false means it's running. Can we rename to _renderLoopRunning or even _expectingAnimationFrame? Yes I know it's private, but we harp on code readability and maintainability around here, so I thought I'd suggest it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To explain my general thought process here, if you look at the only place it is used (line 525) you'll see if (value && this._renderLoopShutdown) Changing the boolean would mean that the only place we use it needs to negate it to get the value it really wants, that seems more "upside-down" to me than what we have here now. But, since I don't care, and you admit you're bikeshedding, I'll change it just to be a nice guy 😉

@shunter
Copy link
Contributor

shunter commented Jun 18, 2013

I fixed one last final bug when enabling/disabling the fullscreen button. This looks good to me. Merging.

shunter added a commit that referenced this pull request Jun 18, 2013
@shunter shunter merged commit 66ee5a3 into master Jun 18, 2013
@shunter shunter deleted the widgetCleanup branch June 18, 2013 14:33
mramato added a commit that referenced this pull request Jun 18, 2013
1. Properly implement Timeline destroy to make sure everyting cleans up after itself
2. Add a sanity check spec that creates/destroys the Timeline as a stopgap until we write complete specs.
3. Fix a bug introduced in #870 that caused the Timeline to not redraw properly on scroll/zoom.

This change does not attempt to fix the myriad of other issues with the Timeline, so please don't review it with our normal rigor.  I'm hoping to carve out some time soon to finally get around to #754.
@mramato mramato mentioned this pull request Jun 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firefox Sandcastle resize issue on startup...
3 participants