-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Widget tweaks #870
Conversation
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) { |
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.
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.
@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 |
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.
Wrong memberof 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.
This was in two places in fact, both fixed.
return; | ||
} | ||
|
||
this._lastWidth = container.clientWidth; |
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.
_lastWidth
and _lastHeight
should be declared in the constructor like we normally do.
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.
Thanks, fixed.
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.
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.
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 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'; |
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 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.
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.
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; |
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 animationExists
must be true here, given animationSizeChanged
is 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.
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.
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; |
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.
Crashes here if timeline is disabled and Fullscreen is not enabled.
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.
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; |
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.
What's this false ||
doing 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.
whoops.
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; |
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.
Need to call timeline.resize();
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.
Fixed.
…ptions generated by the default render loop. Also add code to prevent multiple render loops from being started simulataneously.
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; |
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 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.
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.
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 😉
I fixed one last final bug when enabling/disabling the fullscreen button. This looks good to me. Merging. |
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.
useDefaultRenderLoop
property and constructor option toCesiumWidget
andViewer
so that users can turn on/off the default render loop at will.Viewer
use the new property to disable theCesiumWidget
render loop and use it's own instead.