Skip to content

Commit

Permalink
dynamic locale adjustments to the "Available Decays" panel, #90
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 21, 2023
1 parent 58bf983 commit 5bf9645
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 5 additions & 3 deletions js/chart-intro/view/DecayEquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import buildANucleus from '../../buildANucleus.js';
import DecayEquationModel from '../model/DecayEquationModel.js';
import BuildANucleusStrings from '../../BuildANucleusStrings.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
import { HBox, Text, VBox } from '../../../../scenery/js/imports.js';
import ArrowNode from '../../../../scenery-phet/js/ArrowNode.js';
import DecaySymbolNode from './DecaySymbolNode.js';
import IconFactory from '../../decay/view/IconFactory.js';
import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';
import BANColors from '../../common/BANColors.js';
import BANConstants from '../../common/BANConstants.js';
import DerivedStringProperty from '../../../../axon/js/DerivedStringProperty.js';

const unknownSpacePatternStringProperty = new PatternStringProperty( BuildANucleusStrings.unknownSpacePatternStringProperty, { space: ' ' } );

Expand Down Expand Up @@ -51,8 +51,10 @@ class DecayEquationNode extends VBox {
decayEquationModel.currentCellModelProperty.link( currentCellModel => {
equationHBox.visible = true;
if ( currentCellModel ) {
const decayLikelihoodPercentString = new Text( StringUtils.fillIn( BuildANucleusStrings.percentageInParenthesesPatternStringProperty, {
decayLikelihoodPercent: currentCellModel.decayTypeLikelihoodPercent || unknownSpacePatternStringProperty
const decayLikelihoodPercentString = new Text( new PatternStringProperty( BuildANucleusStrings.percentageInParenthesesPatternStringProperty, {
decayLikelihoodPercent: new DerivedStringProperty( [
unknownSpacePatternStringProperty
], unknownString => `${currentCellModel.decayTypeLikelihoodPercent}` || unknownString )
} ), {
font: BANConstants.LEGEND_FONT
} );
Expand Down
9 changes: 5 additions & 4 deletions js/common/view/BANScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import ParticleAtom from '../../../../shred/js/model/ParticleAtom.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import arrayRemove from '../../../../phet-core/js/arrayRemove.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
import BANQueryParameters from '../BANQueryParameters.js';
import ParticleNucleus from '../../chart-intro/model/ParticleNucleus.js';
import ParticleAtomNode from './ParticleAtomNode.js';
Expand All @@ -40,6 +39,7 @@ import dotRandom from '../../../../dot/js/dotRandom.js';
import BANParticle from '../model/BANParticle.js';
import Animation from '../../../../twixt/js/Animation.js';
import Easing from '../../../../twixt/js/Easing.js';
import PatternStringProperty from '../../../../axon/js/PatternStringProperty.js';

const TOUCH_AREA_Y_DILATION = 3;

Expand Down Expand Up @@ -728,6 +728,8 @@ abstract class BANScreenView<M extends BANModel<ParticleAtom | ParticleNucleus>>

/**
* Define the update function for the element name.
* TODO: support dynamic locale for this whole function, https://github.com/phetsims/build-a-nucleus/issues/90
*
*/
public static updateElementName( elementNameText: Text, protonCount: number, neutronCount: number,
doesNuclideExist: boolean, centerX: number, centerY?: number ): void {
Expand All @@ -739,7 +741,6 @@ abstract class BANScreenView<M extends BANModel<ParticleAtom | ParticleNucleus>>

// no protons
if ( name.length === 0 ) {
// TODO: support dynamic locale, https://github.com/phetsims/build-a-nucleus/issues/90
name += massNumber.toString() + ' ' + BuildANucleusStrings.neutronsLowercaseStringProperty.value + ' ' + BuildANucleusStrings.doesNotFormStringProperty.value;
}
else {
Expand All @@ -762,9 +763,9 @@ abstract class BANScreenView<M extends BANModel<ParticleAtom | ParticleNucleus>>

// multiple neutrons
else {
name = StringUtils.fillIn( BuildANucleusStrings.clusterOfNeutronsPatternStringProperty, {
name = new PatternStringProperty( BuildANucleusStrings.clusterOfNeutronsPatternStringProperty, {
neutronCount: neutronCount
} );
} ).value;
}

}
Expand Down
15 changes: 10 additions & 5 deletions js/decay/view/AvailableDecaysPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class AvailableDecaysPanel extends Panel {
public constructor( model: DecayModel, options: AvailableDecaysPanelOptions ) {

// create and add the title
const titleNode = new Text( BuildANucleusStrings.availableDecaysStringProperty, { font: TITLE_FONT, maxWidth: 285 } );
const titleNode = new Text( BuildANucleusStrings.availableDecaysStringProperty, {
font: TITLE_FONT, maxWidth: 250
} );

// create and add the decays info dialog and button
const decaysInfoDialog = new Dialog(
Expand Down Expand Up @@ -109,8 +111,10 @@ class AvailableDecaysPanel extends Panel {
const buttonBackgroundRectangle = new Rectangle( 0, 0, BUTTON_CONTENT_WIDTH, BUTTON_HEIGHT );
const buttonText = new RichText( decayType.labelStringProperty, { font: LABEL_FONT, maxWidth: BUTTON_CONTENT_WIDTH } );

assert && assert( BUTTON_TEXT_BOTTOM_MARGIN + buttonText.height < BUTTON_HEIGHT, 'The button text is changing the size of the button.' );
buttonText.centerBottom = buttonBackgroundRectangle.centerBottom.minusXY( 0, BUTTON_TEXT_BOTTOM_MARGIN );
buttonText.boundsProperty.link( () => {
assert && assert( BUTTON_TEXT_BOTTOM_MARGIN + buttonText.height < BUTTON_HEIGHT, 'The button text is changing the size of the button.' );
buttonText.centerBottom = buttonBackgroundRectangle.centerBottom.minusXY( 0, BUTTON_TEXT_BOTTOM_MARGIN );
} );
buttonBackgroundRectangle.addChild( buttonText );

return new RectangularPushButton( {
Expand Down Expand Up @@ -162,7 +166,7 @@ class AvailableDecaysPanel extends Panel {
return new HBox( {
children: [
new ParticleNode( particleType.particleTypeString, particleType === ParticleType.PROTON || particleType === ParticleType.NEUTRON ? NUCLEON_PARTICLE_RADIUS : ELECTRON_PARTICLE_RADIUS ),
new Text( particleType.labelStringProperty, { font: LABEL_FONT, maxWidth: 100 } )
new Text( particleType.labelStringProperty, { font: LABEL_FONT, maxWidth: 110 } )
],
spacing: SPACING
} );
Expand All @@ -180,7 +184,8 @@ class AvailableDecaysPanel extends Panel {
createParticleLabelsVBox( [ particleLabels[ 0 ], particleLabels[ 2 ] ] ),
createParticleLabelsVBox( [ particleLabels[ 1 ], particleLabels[ 3 ] ] )
],
spacing: SPACING * 5
spacing: SPACING,
minContentWidth: 100
} );
particleLabelsLegend.top = separator.bottom + SPACING;

Expand Down

0 comments on commit 5bf9645

Please sign in to comment.