Skip to content

Commit

Permalink
make all arrow keys work for PHDropperNode, #249
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Oct 4, 2022
1 parent 7a37609 commit 1ce235b
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions js/common/view/PHDropperNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import EyeDropperNode, { EyeDropperNodeOptions } from '../../../../scenery-phet/js/EyeDropperNode.js';
import { DragListener, KeyboardDragListener } from '../../../../scenery/js/imports.js';
import { DragListener, KeyboardDragListener, KeyboardDragListenerOptions, KeyboardUtils } from '../../../../scenery/js/imports.js';
import phScale from '../../phScale.js';
import Dropper from '../model/Dropper.js';

Expand Down Expand Up @@ -62,7 +62,7 @@ export default class PHDropperNode extends EyeDropperNode {
phetioEnabledPropertyInstrumented: true
} ) );

this.addInputListener( new KeyboardDragListener( {
this.addInputListener( new PHDropperKeyboardDragListener( {
dragVelocity: 300, // velocity of the Node being dragged, in view coordinates per second
shiftDragVelocity: 20, // velocity with the Shift key pressed, typically slower than dragVelocity
positionProperty: dropper.positionProperty,
Expand All @@ -74,4 +74,38 @@ export default class PHDropperNode extends EyeDropperNode {
}
}

//TODO https://github.com/phetsims/ph-scale/issues/249 delete this class, replace overrides with KeyboardDragListener options
class PHDropperKeyboardDragListener extends KeyboardDragListener {

public constructor( providedOptions?: KeyboardDragListenerOptions ) {
super( providedOptions );
}

// Dragging is constrained to up/down, but we want the left/right arrows to do something.
// For now, override these methods. Eventually, this will be supported by KeyboardDragListener.
// See https://github.com/phetsims/scenery/issues/1460

public override leftMovementKeysDown(): boolean {
return this.keyInListDown( [
KeyboardUtils.KEY_LEFT_ARROW, KeyboardUtils.KEY_DOWN_ARROW,
KeyboardUtils.KEY_A, KeyboardUtils.KEY_S
] );
}

public override rightMovementKeysDown(): boolean {
return this.keyInListDown( [
KeyboardUtils.KEY_RIGHT_ARROW, KeyboardUtils.KEY_UP_ARROW,
KeyboardUtils.KEY_W, KeyboardUtils.KEY_D
] );
}

public override upMovementKeysDown(): boolean {
return false;
}

public override downMovementKeysDown(): boolean {
return false;
}
}

phScale.register( 'PHDropperNode', PHDropperNode );

0 comments on commit 1ce235b

Please sign in to comment.