Skip to content

Commit

Permalink
hide MassTag label when empty, phetsims/buoyancy#102
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed Mar 4, 2024
1 parent 20bcfcd commit 9b97a34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/common/model/MassTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class MassTag {

public static readonly PRIMARY = new MassTag( DensityBuoyancyCommonStrings.massLabel.primaryStringProperty, MassTag.PRIMARY_COLOR_PROPERTY );
public static readonly SECONDARY = new MassTag( DensityBuoyancyCommonStrings.massLabel.secondaryStringProperty, MassTag.SECONDARY_COLOR_PROPERTY );
public static readonly NONE = new MassTag( new StringProperty( 'NONE' ) ); // TODO: a bit awkward, but better than nulling the param right? https://github.com/phetsims/buoyancy/issues/102
public static readonly NONE = new MassTag( new StringProperty( 'NONE' ) );
public static readonly ONE_A = new MassTag( DensityBuoyancyCommonStrings.massLabel[ '1aStringProperty' ] );
public static readonly ONE_B = new MassTag( DensityBuoyancyCommonStrings.massLabel[ '1bStringProperty' ] );
public static readonly ONE_C = new MassTag( DensityBuoyancyCommonStrings.massLabel[ '1cStringProperty' ] );
Expand Down
7 changes: 6 additions & 1 deletion js/common/view/MassTagView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import DensityBuoyancyCommonConstants from '../DensityBuoyancyCommonConstants.js
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import BackgroundNode from '../../../../scenery-phet/js/BackgroundNode.js';
import MassTag from '../model/MassTag.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';

// Constant for MassView subtypes to use to consistently offset their tag on their shape
export const TAG_OFFSET = MASS_MIN_SHAPES_DIMENSION / 20;
Expand Down Expand Up @@ -82,9 +83,12 @@ export default class MassTagView extends TextureQuad {
}

private static getTagNode( massTag: MassTag ): Node {
const visibleProperty = new DerivedProperty( [ massTag.nameProperty ], name => name.length > 0 );

const label = new Text( massTag.nameProperty, {
font: tagFont,
maxWidth: 100
maxWidth: 100,
visibleProperty: visibleProperty
} );

const colorListener = ( color: Color ) => {
Expand All @@ -104,6 +108,7 @@ export default class MassTagView extends TextureQuad {
backgroundNode.disposeEmitter.addListener( () => {
massTag.colorProperty.unlink( colorListener );
label.dispose();
visibleProperty.dispose();
} );
return backgroundNode;
}
Expand Down

0 comments on commit 9b97a34

Please sign in to comment.