Skip to content

Commit

Permalink
Use CCKCRoundPushButton in TrashButton, see #531
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 9, 2019
1 parent 05ae4ce commit 53924c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
6 changes: 1 addition & 5 deletions js/view/CCKCRoundPushButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define( require => {
class CCKCRoundPushButton extends RoundPushButton {

/**
* TODO: I don't think we should change the button interface, let's move these back to options.
* @param {Node} icon - the circuit that contains the battery
* @param {function} listener
* @param {Tandem} tandem
Expand All @@ -26,16 +27,11 @@ define( require => {
super( merge( {
baseColor: PhetColorScheme.BUTTON_YELLOW,
content: icon,

minXMargin: 10,
minYMargin: 10,
listener: listener,

tandem: tandem,

// TODO(phet-io): These elements will need to be members of a PhetioGroup
phetioState: false,

phetioComponentOptions: {
phetioState: false
}
Expand Down
35 changes: 14 additions & 21 deletions js/view/TrashButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ define( require => {

// modules
const CCKCConstants = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/CCKCConstants' );
const CCKCRoundPushButton = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/view/CCKCRoundPushButton' );
const circuitConstructionKitCommon = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/circuitConstructionKitCommon' );
const FontAwesomeNode = require( 'SUN/FontAwesomeNode' );
const merge = require( 'PHET_CORE/merge' );
const PhetColorScheme = require( 'SCENERY_PHET/PhetColorScheme' );
const RoundPushButton = require( 'SUN/buttons/RoundPushButton' );
const TrashButtonIO = require( 'CIRCUIT_CONSTRUCTION_KIT_COMMON/view/TrashButtonIO' );

// TODO: Should this use CCKCRoundPushButton?
class TrashButton extends RoundPushButton {
class TrashButton extends CCKCRoundPushButton {

/**
* @param {Circuit} circuit - the circuit from which the CircuitElement can be removed
Expand All @@ -29,24 +28,18 @@ define( require => {
constructor( circuit, circuitElement, tandem, options ) {

assert && assert( circuitElement !== undefined, 'circuit element should be null or defined' );
super( merge( {
baseColor: PhetColorScheme.BUTTON_YELLOW,
content: new FontAwesomeNode( 'trash', {
scale: CCKCConstants.FONT_AWESOME_ICON_SCALE
} ),
listener: () => {

// Only permit deletion when not being dragged, see https://github.com/phetsims/circuit-construction-kit-common/issues/414
if ( !circuitElement.startVertexProperty.value.isDragged && !circuitElement.endVertexProperty.value.isDragged ) {
circuit.circuitElements.remove( circuitElement );
circuit.disposeFromGroup( circuitElement );// TODO(phet-io): improve somehow

!this.isDisposed && this.dispose();
}
},
minXMargin: 10,
minYMargin: 10,
tandem: tandem,
super( new FontAwesomeNode( 'trash', {
scale: CCKCConstants.FONT_AWESOME_ICON_SCALE
} ), () => {

// Only permit deletion when not being dragged, see https://github.com/phetsims/circuit-construction-kit-common/issues/414
if ( !circuitElement.startVertexProperty.value.isDragged && !circuitElement.endVertexProperty.value.isDragged ) {
circuit.circuitElements.remove( circuitElement );
circuit.disposeFromGroup( circuitElement );// TODO(phet-io): improve somehow

!this.isDisposed && this.dispose();
}
}, tandem, merge( {
phetioDynamicElement: true,
phetioType: TrashButtonIO
}, options ) );
Expand Down

0 comments on commit 53924c1

Please sign in to comment.