Skip to content

Commit

Permalink
Set clearButton enabledProperty to a derivedProperty, see: #459
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas authored and samreid committed Oct 5, 2022
1 parent 9d09041 commit 47e8e5d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions js/common/view/TimeCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @author Aaron Davis (PhET Interactive Simulations)
*/

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import TProperty from '../../../../axon/js/TProperty.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import merge from '../../../../phet-core/js/merge.js';
Expand Down Expand Up @@ -45,18 +46,16 @@ class TimeCounter extends Node {
maxWidth: 200
} );

const isTimeNonZeroProperty = new DerivedProperty( [ clock.timeProperty ], time => time !== 0 );

const clearButton = new TextPushButton( GravityAndOrbitsStrings.clearStringProperty, {
font: new PhetFont( FONT_SIZE ),
listener: () => clock.setSimulationTime( 0 ),
maxTextWidth: 200,
tandem: tandem.createTandem( 'clearButton' )
tandem: tandem.createTandem( 'clearButton' ),
enabledProperty: isTimeNonZeroProperty
} );

// update text representation of day
clock.timeProperty.link( time => {
assert && assert( !isNaN( time ), 'time should be a number' );
clearButton.enabled = time !== 0;
} );

this.addChild( new VBox( {
align: 'right',
Expand Down

0 comments on commit 47e8e5d

Please sign in to comment.