Skip to content

Commit

Permalink
Adding listenerOptions for created button PressListeners, see phetsim…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jun 3, 2019
1 parent 800e2ef commit 7f26ea5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 5 additions & 1 deletion js/buttons/NodesPushButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ define( function( require ) {
listener: null, // {function}
xAlign: 'center', // {string} how the nodes are horizontally aligned: center, left, right
yAlign: 'center', // {string} how the nodes are vertically aligned: center, top, bottom
listenerOptions: null,
tandem: Tandem.required
}, options );
options.listenerOptions = _.extend( {
tandem: options.tandem.createTandem( 'pressListener' )
}, options.listenerOptions );
options.children = [ idleNode, overNode, pressedNode, disabledNode ];

Node.call( this );
Expand All @@ -46,7 +50,7 @@ define( function( require ) {
this.buttonModel = new PushButtonModel( options ); // @private

// @private {PressListener}
this.pressListener = this.buttonModel.createListener( { tandem: options.tandem.createTandem( 'pressListener' ) } );
this.pressListener = this.buttonModel.createListener( options.listenerOptions );
this.addInputListener( this.pressListener );

// Button interactions
Expand Down
13 changes: 9 additions & 4 deletions js/buttons/RectangularButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ define( function( require ) {
// version(s) defined in this file.
contentAppearanceStrategy: RectangularButtonView.FadeContentWhenDisabled,

// Options that will be passed through to the main input listener (PressListener)
listenerOptions: null,

// a11y
tagName: 'button',

Expand All @@ -105,6 +108,11 @@ define( function( require ) {
assert && assert( _.includes( X_ALIGN_VALUES, options.xAlign ), 'invalid xAlign: ' + options.xAlign );
assert && assert( _.includes( Y_ALIGN_VALUES, options.yAlign ), 'invalid yAlign: ' + options.yAlign );

options.listenerOptions = _.extend( {
tandem: options.tandem.createTandem( 'pressListener' ),
accessibleClick: options.accessibleClick
}, options.listenerOptions );

this.buttonModel = buttonModel; // @protected

Node.call( this );
Expand All @@ -113,10 +121,7 @@ define( function( require ) {

// Hook up the input listener
// @private (a11y) {PressListener}
this._pressListener = buttonModel.createListener( {
tandem: options.tandem.createTandem( 'pressListener' ),
accessibleClick: options.accessibleClick
} );
this._pressListener = buttonModel.createListener( options.listenerOptions );
this.addInputListener( this._pressListener );

// @private - make the base color into a property so that the appearance strategy can update itself if changes occur.
Expand Down
9 changes: 8 additions & 1 deletion js/buttons/RoundButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ define( function( require ) {
// version(s) defined in this file.
contentAppearanceStrategy: RoundButtonView.FadeContentWhenDisabled,

// Options that will be passed through to the main input listener (PressListener)
listenerOptions: null,

// phet-io
tandem: Tandem.optional, // This duplicates the parent option and works around https://github.com/phetsims/tandem/issues/50
phetioComponentOptions: { visibleProperty: { phetioFeatured: true } },
Expand All @@ -91,6 +94,10 @@ define( function( require ) {
focusHighlightDilation: 5 // radius dilation for circular highlight
}, options );

options.listenerOptions = _.extend( {
tandem: options.tandem.createTandem( 'pressListener' )
}, options.listenerOptions );

Node.call( this );
var content = options.content; // convenience variable
var upCenter = new Vector2( options.xContentOffset, options.yContentOffset );
Expand All @@ -104,7 +111,7 @@ define( function( require ) {
this.baseColorProperty = new PaintColorProperty( options.baseColor ); // @private

// @private {PressListener}
var pressListener = pushButtonModel.createListener( { tandem: options.tandem.createTandem( 'pressListener' ) } );
var pressListener = pushButtonModel.createListener( options.listenerOptions );
this.addInputListener( pressListener );

// Use the user-specified radius if present, otherwise calculate the
Expand Down

0 comments on commit 7f26ea5

Please sign in to comment.