Skip to content

Commit

Permalink
Notify if out of range, see #135
Browse files Browse the repository at this point in the history
  • Loading branch information
andrealin committed Aug 14, 2017
1 parent 79eefeb commit e6594ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions js/lab/view/KeypadLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ define( function( require ) {

this.saidHello = false;
var helloText = new Text('Hello!', { font: TEXT_FONT } );
var notificationText = new Text( '', { font: TEXT_FONT } );

// @private functions changing the notification text that shows up below the enter button

this.addHelloText = function() {
if ( !contentNode.hasChild( helloText ) && !this.saidHello ) {
Expand All @@ -118,6 +121,19 @@ define( function( require ) {
}
};

this.notify = function( message ) {
notificationText.setText( message );
if ( !contentNode.hasChild( notificationText ) ) {
contentNode.addChild( notificationText );
}
}

this.removeNotificationText = function() {
if ( contentNode.hasChild( notificationText ) ) {
contentNode.removeChild( notificationText );
}
}

this.keypadPanel = new Panel( contentNode, {
fill: 'rgb( 230, 230, 230 )', // {Color|string} the keypad's background color
backgroundPickable: true, // {boolean} so that clicking in the keypad's background doesn't close the keypad
Expand Down Expand Up @@ -155,7 +171,7 @@ define( function( require ) {
* @param {Range} valueRange
* @param {Object} [options]
*/
beginEdit: function( valueProperty, valueRange, options ) {
beginEdit: function( valueProperty, valueRange, unitsString, options ) {

options = _.extend( {
onBeginEdit: null, // {function} called by beginEdit
Expand All @@ -166,6 +182,7 @@ define( function( require ) {
this.onEndEdit = options.onEndEdit;

this.valueRange = valueRange; // update value range to be used in commitedit
this.rangeMessage = 'Range: ' + valueRange.min + ' - ' + valueRange.max + ' ' + ( unitsString ? unitsString : '' );

// display the keypad
this.visible = true;
Expand Down Expand Up @@ -197,6 +214,7 @@ define( function( require ) {
this.valueProperty = null;

this.removeHelloText();
this.removeNotificationText();
},

/**
Expand All @@ -206,6 +224,7 @@ define( function( require ) {
commitEdit: function() {

var valueRange = this.valueRange;
var rangeMessage = this.rangeMessage;

// get the value from the keypad
var value = this.keypadNode.valueProperty.get();
Expand All @@ -226,18 +245,22 @@ define( function( require ) {
this.sayHi();
}
else {
this.valueProperty.set( valueRange.max );
this.endEdit();
this.removeHelloText();
this.notify( rangeMessage )
// this.valueProperty.set( valueRange.max );
// this.endEdit();
}
}
// value is closer to max than min
else if ( valueRange.max + valueRange.min < 2 * value ) {
this.valueProperty.set( valueRange.max );
this.endEdit();
this.notify( rangeMessage )
// this.valueProperty.set( valueRange.max );
// this.endEdit();
}
else {
this.valueProperty.set( valueRange.min );
this.endEdit();
this.notify( rangeMessage )
// this.valueProperty.set( valueRange.min );
// this.endEdit();
}
},

Expand Down
2 changes: 1 addition & 1 deletion js/lab/view/LabProjectilePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ define( function( require ) {
} );

var editValue = function() {
keypadLayer.beginEdit( valueProperty, range, {
keypadLayer.beginEdit( valueProperty, range, unitsString, {
onBeginEdit: function() { backgroundNode.fill = PhetColorScheme.PHET_LOGO_YELLOW; },
onEndEdit: function() { backgroundNode.fill = 'white'; }
} );
Expand Down

0 comments on commit e6594ff

Please sign in to comment.