Skip to content

Commit

Permalink
add edge alerts for min/max mass interaction attempt, phetsims/gravit…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 5, 2019
1 parent 90a3921 commit fe1e575
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
21 changes: 19 additions & 2 deletions js/gravity-force-lab-basics/view/GFLBMassControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ define( require => {
* @param {Range} massRange
* @param {String} labelContent - a11y, the content of the label for the mass control
* @param {ISLCObjectEnum} thisObjectEnum
* @param {GFLBAlertManager} alertManager
* @param {GFLBMassDescriber} massDescriber
* @param {Tandem} tandem
* @param {Object} [options]
*/
constructor( titleString, valueProperty, massRange, labelContent, thisObjectEnum,
constructor( titleString, valueProperty, massRange, labelContent, thisObjectEnum, alertManager,
massDescriber, tandem, options ) {

options = merge( {
Expand All @@ -55,6 +56,9 @@ define( require => {
tandem: tandem.createTandem( 'titleText' )
} );

// Keep track of the current mass between the start and end of an interaction to see if we should alert.
let currentMass = valueProperty.value;

const numberPicker = new NumberPicker( valueProperty, new Property( massRange ), {
font: new PhetFont( 20 ),
scale: 1.5,
Expand All @@ -72,7 +76,20 @@ define( require => {
// a11y
pageKeyboardStep: BILLION_MULTIPLIER * 2,
accessibleName: labelContent,
a11yCreateAriaValueText: () => massDescriber.getMassAndUnit( thisObjectEnum )
a11yCreateAriaValueText: () => massDescriber.getMassAndUnit( thisObjectEnum ),

// on end interaction, if alert a special alert if the mass started at the min/max and didnt' change.
a11yCreateValueChangeAlert: () => {

// no change and at max or min
if ( currentMass === valueProperty.value && ( currentMass === massRange.max || currentMass === massRange.min ) ) {
return alertManager.alertMassMinMaxEdge( thisObjectEnum );
}
return null; // regular mass changed alerts come from model changes
},
startChange: () => {
currentMass = valueProperty.value;
}
} );
const numberPickerLabel = new Text( billionKgString, {
font: new PhetFont( { size: 14 } ),
Expand Down
6 changes: 3 additions & 3 deletions js/gravity-force-lab-basics/view/GFLBScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ define( require => {
// initialize a11y describers and alert manager
const positionDescriber = new GFLBPositionDescriber( model, mass1LabelString, mass2LabelString );
const forceDescriber = new GFLBForceDescriber( model, mass1LabelString, mass2LabelString, positionDescriber );
const massDescriber = new GFLBMassDescriber( model );
const massDescriber = new GFLBMassDescriber( model, forceDescriber );
const alertManager = new GFLBAlertManager( model, massDescriber, forceDescriber );

super( {
Expand Down Expand Up @@ -172,10 +172,10 @@ define( require => {

// mass controls
const massControl1 = new GFLBMassControl( mass1String, model.object1.valueProperty,
GFLBConstants.MASS_RANGE, mass1ControlLabelString, OBJECT_ONE,
GFLBConstants.MASS_RANGE, mass1ControlLabelString, OBJECT_ONE, alertManager,
massDescriber, tandem.createTandem( 'massControl1' ) );
const massControl2 = new GFLBMassControl( mass2String, model.object2.valueProperty,
GFLBConstants.MASS_RANGE, mass2ControlLabelString, OBJECT_TWO,
GFLBConstants.MASS_RANGE, mass2ControlLabelString, OBJECT_TWO, alertManager,
massDescriber, tandem.createTandem( 'massControl2' ), {
color: new Color( 255, 0, 0 )
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ define( require => {

/**
* @param {GFLBModel} model
* @param {ForceDescriber} forceDescriber
*/
constructor( model ) {
constructor( model, forceDescriber ) {

const options = {
object1Label: mass1LabelString,
Expand All @@ -34,7 +35,7 @@ define( require => {
formatMassValue: mass => StringUtils.fillIn( massBillionsPatternString, { mass: mass } )
};

super( model, options );
super( model, forceDescriber, options );
}
}

Expand Down

0 comments on commit fe1e575

Please sign in to comment.