Skip to content

Commit

Permalink
support for dynamic locale, #140
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Aug 30, 2022
1 parent 6ffc9e1 commit 626e7f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
51 changes: 17 additions & 34 deletions js/common/view/BondDipolesCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import moleculePolarity from '../../moleculePolarity.js';
import moleculePolarityStrings from '../../moleculePolarityStrings.js';
import BondDipoleNode from './BondDipoleNode.js';

class BondDipolesCheckbox extends Checkbox {
export default class BondDipolesCheckbox extends Checkbox {

/**
* @param {Property.<boolean>} bondDipolesVisibleProperty
Expand All @@ -30,42 +30,25 @@ class BondDipolesCheckbox extends Checkbox {
tandem: Tandem.REQUIRED
}, options );

const labelNode = createLabelNode( {
singular: options.singular,
tandem: options.tandem.createTandem( 'labelNode' )
} );

super( bondDipolesVisibleProperty, labelNode, options );
}
}

/**
* Creates the label for this checkbox.
* @param {Object} [options]
* @returns {HBox}
*/
function createLabelNode( options ) {

options = merge( {
singular: false,
spacing: MPConstants.CONTROL_ICON_X_SPACING,
tandem: Tandem.REQUIRED
}, options );
const stringProperty = options.singular ?
moleculePolarityStrings.bondDipolesStringProperty :
moleculePolarityStrings.bondDipoleStringProperty;

const labelString = options.singular ? moleculePolarityStrings.bondDipole : moleculePolarityStrings.bondDipoles;
const labelText = new Text( labelString,
merge( {
tandem: options.tandem.createTandem( 'labelText' )
}, MPConstants.CONTROL_TEXT_OPTIONS )
);
const textNode = new Text( stringProperty,
merge( {
tandem: options.tandem.createTandem( 'textNode' )
}, MPConstants.CONTROL_TEXT_OPTIONS )
);

const labelIcon = BondDipoleNode.createIcon();
const iconNode = BondDipoleNode.createIcon();

assert && assert( !options.children, 'createLabelNode sets children' );
options.children = [ labelText, labelIcon ];
const content = new HBox( {
children: [ textNode, iconNode ],
spacing: MPConstants.CONTROL_ICON_X_SPACING
} );

return new HBox( options );
super( bondDipolesVisibleProperty, content, options );
}
}

moleculePolarity.register( 'BondDipolesCheckbox', BondDipolesCheckbox );
export default BondDipolesCheckbox;
moleculePolarity.register( 'BondDipolesCheckbox', BondDipolesCheckbox );
2 changes: 1 addition & 1 deletion js/molecule-polarity-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ simLauncher.launch( () => {
new RealMoleculesScreen( { tandem: Tandem.ROOT.createTandem( 'realMoleculesScreen' ) } )
];

const sim = new Sim( moleculePolarityStrings[ 'molecule-polarity' ].title, screens, {
const sim = new Sim( moleculePolarityStrings[ 'molecule-polarity' ].titleStringProperty, screens, {
preferencesModel: new PreferencesModel( {
generalOptions: {
customPreferences: [ {
Expand Down
6 changes: 0 additions & 6 deletions js/molecule-polarity-phet-io-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ window.phet.preloads.phetio.phetioElementsOverrides =
"moleculePolarity.threeAtomsScreen.view.controlPanel.separator1.visibleProperty": {
"phetioFeatured": true
},
"moleculePolarity.threeAtomsScreen.view.controlPanel.viewControls.bondDipolesCheckbox.labelNode.labelText.textProperty": {
"phetioFeatured": true
},
"moleculePolarity.threeAtomsScreen.view.controlPanel.viewControls.molecularDipoleCheckbox.labelNode.labelText.textProperty": {
"phetioFeatured": true
},
Expand Down Expand Up @@ -202,9 +199,6 @@ window.phet.preloads.phetio.phetioElementsOverrides =
"moleculePolarity.twoAtomsScreen.view.controlPanel.viewControls.bondCharacterCheckbox.labelText.textProperty": {
"phetioFeatured": true
},
"moleculePolarity.twoAtomsScreen.view.controlPanel.viewControls.bondDipoleCheckbox.labelNode.labelText.textProperty": {
"phetioFeatured": true
},
"moleculePolarity.twoAtomsScreen.view.controlPanel.viewControls.partialChargesCheckbox.labelText.textProperty": {
"phetioFeatured": true
},
Expand Down

0 comments on commit 626e7f3

Please sign in to comment.