-
Notifications
You must be signed in to change notification settings - Fork 6
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
problems with API for StepBackButton and StepForwardButton #243
Comments
Looking more closely at (1) above... playingProperty actually has inverted semantics. The button is disabled when when true. |
(5) I also see this in both buttons: assert && assert( !options.listener, 'stepFunction replaces options.listener' );
options.listener = stepFunction; Why is this difference necessary? Why can't we just use |
(1) Yes those parameters should be unified. I'm not sure whether we should go with isPlayingProperty, or enabledProperty. I don't know why these diverged. |
I'll assign this to me to clean up, low priority. |
Check list, for what I need to change and test... Sims that use
Sims that use
|
In the above commits, I removed the /**
* @param {Property.<boolean>} enabledProperty
* @param {Object} [options]
* @constructor
*/
function StepBackButton( enabledProperty, options );
/**
* @param {Property.<boolean>} playingProperty - button is disabled when this is true
* @param {Object} [options]
* @constructor
*/
function StepForwardButton( playingProperty, options ); |
(6) The only reason why we currently need separate "forward" and "back" buttons is because of the phetsims/sun#236 (a problem with buttons in general). Working around this problem requires different values for the |
If we fixed phetsims/sun#236, then we really don't need StepForwardButton and StepBackButton. We add a Here's what a typical call site would look like: var playingProperty = new Property( false );
var stepForwardButton = new StepButton( {
direction: 'forward',
listener: function() { .... },
playingProperty: playingProperty
} );
var stepBackButton = new StepButton( {
direction: 'back',
listener: function() { .... },
playingProperty: playingProperty
} ); |
In fact, we could move the content offset into StepButton (checks the direction to determine the offset) even if we don't fix phetsims/sun#236 and then we wouldn't really need StepForwardButton and StepBackButton. But on the other hand, I'm wondering if it is simpler for developer to look for StepForwardButton, or StepButton and know they must supply a direction parameter. There is some precedent for this pattern in HBox, which is a trivial subclass of LayoutBox whose sole purpose is to provide |
And here's an example (similar to neuron) where enabling/disabling the buttons involves more than whether the sim is playing. var playingProperty = new Property( false );
var timeProperty = new Property( 0 );
var recordedTimeRange = new Range( 0, 0 );
var stepBackButton = new StepButton( {
direction: 'forward',
listener: function() { ... }
} );
var stepForwardButton = new StepButton( {
direction: 'back',
listener: function() { ... }
} );
var multilink = new Multilink( [ playingProperty, timeProperty ],
function( playing, time ) {
stepBackButton.enabled = ( playing && time > recordedTimeRange.min );
stepForwardButton.enabled = ( playing && time < recordedTimeRange.max );
} ); |
…tions.playingProperty, phetsims/scenery-phet#243
…tions.playingProperty, phetsims/scenery-phet#243
…tions.playingProperty, phetsims/scenery-phet#243
Add options |
StepBackButton renamed to StepBackwardButton. StepForwardButton and StepBackwardButton added to scenery-phet demo. All work completed here. @samreid would you mind reviewing? |
StepButton.call( this, _.extend( {}, options, { direction: 'backward' } ) ); Why not write as the following, since we already asserted that direction doesn't appear in the options? StepButton.call( this, _.extend( { direction: 'backward' }, options ) );
var BUTTON_RADIUS = ( options && options.radius ) ? options.radius : 20; Would it be better to use this? var BUTTON_RADIUS = options && options.radius || 20; Also in both of these logics, it is impossible to provide a radius of 0 because it is falsy. Perhaps that is a good thing in this case though.
|
I made a few of the recommendations above, will wait to discuss the "These lines read kind of confusingly to me:" part with @pixelzoom |
Here's an implementation that allows 0 radius values: options && typeof options.radius==='number' ? options.radius : 20 I didn't grok the original proposal right away, but really I'm fine with any of the proposed solutions for this (including the original). |
Re the computation of BUTTON_RADIUS in #243 (comment)... This one doesn't do what you think it does. It returns true or false, not a radius value. var BUTTON_RADIUS = options && options.radius || 20; I'm fine with either of these, but prefer the first (the current implementation) since a zero radius is almost certain to cause RoundPushButton to fail. var BUTTON_RADIUS = ( options && options.radius ) ? options.radius : 20;
var BUTTON_RADIUS = ( options && typeof options.radius==='number' ) ? options.radius : 20; |
Got it, thanks for the clarification. Closing. |
…tions.playingProperty, phetsims/scenery-phet#243
Noticed while adding buttons to the scenery-phet demo.
Multiple problems with the API for StepBackButton and StepForwardButton, which have these constructors:
(1) Parameters that do the same thing have different names:
enabledProperty
vsplayingProperty
.(2) StepBackButton and StepForwardButton are subtypes of PushButton, which has its own enabledProperty. Why do these buttons need an extra enabledProperty? All other buttons in scenery-phet require the client to use the enabledProperty provided by the button.
(3) Why is
stepFunction
a required parameter? It's likely that therefunction() {}
is a reasonable default. If that's the case, then it should be an option.(4) Due to 1-3, the API for these buttons looks different than other scenery-phet buttons.
Assigning to @samreid for comment, since I believe he was the original author. (I factored out StepButton recently.)
The text was updated successfully, but these errors were encountered: