Skip to content

Commit

Permalink
focusPanDirection -> limitPanDirection, see phetsims/center-and-varia…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Oct 9, 2023
1 parent 8ebefb7 commit 9b92a67
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
39 changes: 19 additions & 20 deletions js/accessibility/pdom/ParallelDOM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const DEFAULT_DESCRIPTION_TAG_NAME = P_TAG;
const DEFAULT_LABEL_TAG_NAME = P_TAG;

export type PDOMValueType = string | TReadOnlyProperty<string>;
export type FocusPanDirection = 'horizontal' | 'vertical';
export type LimitPanDirection = 'horizontal' | 'vertical';

// see setPDOMHeadingBehavior for more details
const DEFAULT_PDOM_HEADING_BEHAVIOR = ( node: Node, options: ParallelDOMOptions, heading: PDOMValueType ) => {
Expand Down Expand Up @@ -232,7 +232,7 @@ const ACCESSIBILITY_OPTION_KEYS = [
'activeDescendantAssociations',

'createFocusPanTargetBounds',
'focusPanDirection',
'limitPanDirection',

'positionInPDOM',

Expand Down Expand Up @@ -289,7 +289,7 @@ export type ParallelDOMOptions = {
activeDescendantAssociations?: Association[]; // sets the list of aria-activedescendant associations between from this node to others (including itself)

createFocusPanTargetBounds?: ( () => Bounds2 ) | null; // A function that sets the global bounds for an AnimatedPanZoomListener to keep in view
focusPanDirection?: FocusPanDirection | null; // A constraint on the direction of panning when this Node is focused
limitPanDirection?: LimitPanDirection | null; // A constraint on the direction of panning when interacting with this Node.

positionInPDOM?: boolean; // Sets whether the node's DOM elements are positioned in the viewport

Expand Down Expand Up @@ -515,9 +515,8 @@ export default class ParallelDOM extends PhetioObject {
// focus
private _createFocusPanTargetBounds: ( () => Bounds2 ) | null;

// If provided, the AnimatedPanZoomListener will ONLY pan in the specified direction as long as this Node has
// focus.
private _focusPanDirection: FocusPanDirection | null;
// If provided, the AnimatedPanZoomListener will ONLY pan in the specified direction
private _limitPanDirection: LimitPanDirection | null;

// Contains information about what pdom displays
// this node is "visible" for, see PDOMDisplaysInfo.js for more information.
Expand Down Expand Up @@ -610,7 +609,7 @@ export default class ParallelDOM extends PhetioObject {
this._pdomParent = null;
this._pdomTransformSourceNode = null;
this._createFocusPanTargetBounds = null;
this._focusPanDirection = null;
this._limitPanDirection = null;
this._pdomDisplaysInfo = new PDOMDisplaysInfo( this as unknown as Node );
this._pdomInstances = [];
this._positionInPDOM = false;
Expand Down Expand Up @@ -2618,36 +2617,36 @@ export default class ParallelDOM extends PhetioObject {
}

/**
* Sets the direction that the global AnimatedPanZoomListener will pan while focus is on this Node. Pan will ONLY
* Sets the direction that the global AnimatedPanZoomListener will pan while interacting with this Node. Pan will ONLY
* occur in this dimension. This is especially useful for panning to large Nodes where panning to the center of the
* Node would move other Nodes out of the viewport.
*
* Set to null for default behavior (panning in all directions).
*/
public setFocusPanDirection( focusPanDirection: FocusPanDirection | null ): void {
this._focusPanDirection = focusPanDirection;
public setLimitPanDirection( limitPanDirection: LimitPanDirection | null ): void {
this._limitPanDirection = limitPanDirection;
}

/**
* See setFocusPanDirection for more information.
* See setLimitPanDirection for more information.
*/
public getFocusPanDirection(): FocusPanDirection | null {
return this._focusPanDirection;
public getLimitPanDirection(): LimitPanDirection | null {
return this._limitPanDirection;
}

/**
* See setFocusPanDirection for more information.
* @param focusPanDirection
* See setLimitPanDirection for more information.
* @param limitPanDirection
*/
public set focusPanDirection( focusPanDirection: FocusPanDirection ) {
this.setFocusPanDirection( focusPanDirection );
public set limitPanDirection( limitPanDirection: LimitPanDirection ) {
this.setLimitPanDirection( limitPanDirection );
}

/**
* See getFocusPanDirection for more information.
* See getLimitPanDirection for more information.
*/
public get focusPanDirection(): FocusPanDirection | null {
return this.getFocusPanDirection();
public get limitPanDirection(): LimitPanDirection | null {
return this.getLimitPanDirection();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export { default as Saturate } from './filters/Saturate.js';
export { default as Sepia } from './filters/Sepia.js';

export { default as ParallelDOM, ACCESSIBILITY_OPTION_KEYS } from './accessibility/pdom/ParallelDOM.js';
export type { ParallelDOMOptions, PDOMValueType, FocusPanDirection, PDOMBehaviorFunction } from './accessibility/pdom/ParallelDOM.js';
export type { ParallelDOMOptions, PDOMValueType, LimitPanDirection, PDOMBehaviorFunction } from './accessibility/pdom/ParallelDOM.js';
export { default as Node, REQUIRES_BOUNDS_OPTION_KEYS } from './nodes/Node.js';
export type { NodeOptions, NodeBoundsBasedTranslationOptions, NodeTranslationOptions, NodeTransformOptions, RendererType } from './nodes/Node.js';
export { default as Picker } from './util/Picker.js';
Expand Down
14 changes: 7 additions & 7 deletions js/listeners/AnimatedPanZoomListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import platform from '../../../phet-core/js/platform.js';
import EventType from '../../../tandem/js/EventType.js';
import isSettingPhetioStateProperty from '../../../tandem/js/isSettingPhetioStateProperty.js';
import PhetioAction from '../../../tandem/js/PhetioAction.js';
import { EventIO, Focus, FocusManager, globalKeyStateTracker, Intent, KeyboardDragListener, KeyboardUtils, KeyboardZoomUtils, KeyStateTracker, Mouse, MultiListenerPress, Node, FocusPanDirection, PanZoomListener, PanZoomListenerOptions, PDOMPointer, PDOMUtils, Pointer, PressListener, scenery, SceneryEvent, Trail, TransformTracker } from '../imports.js';
import { EventIO, Focus, FocusManager, globalKeyStateTracker, Intent, KeyboardDragListener, KeyboardUtils, KeyboardZoomUtils, KeyStateTracker, Mouse, MultiListenerPress, Node, LimitPanDirection, PanZoomListener, PanZoomListenerOptions, PDOMPointer, PDOMUtils, Pointer, PressListener, scenery, SceneryEvent, Trail, TransformTracker } from '../imports.js';
import optionize, { EmptySelfOptions } from '../../../phet-core/js/optionize.js';
import Tandem from '../../../tandem/js/Tandem.js';
import BooleanProperty from '../../../axon/js/BooleanProperty.js';
Expand Down Expand Up @@ -453,7 +453,7 @@ class AnimatedPanZoomListener extends PanZoomListener {
private repositionDuringDrag(): void {
const globalBounds = this.getGlobalBoundsToViewDuringDrag();
const targetNode = this.getTargetNodeDuringDrag();
globalBounds && this.keepBoundsInView( globalBounds, this._attachedPointers.some( pointer => pointer instanceof PDOMPointer ), targetNode?.focusPanDirection );
globalBounds && this.keepBoundsInView( globalBounds, this._attachedPointers.some( pointer => pointer instanceof PDOMPointer ), targetNode?.limitPanDirection );
}

/**
Expand Down Expand Up @@ -606,12 +606,12 @@ class AnimatedPanZoomListener extends PanZoomListener {
globalBounds = focus.trail.localToGlobalBounds( focus.trail.lastNode().localBounds );
}

this.keepBoundsInView( globalBounds, true, lastNode.focusPanDirection );
this.keepBoundsInView( globalBounds, true, lastNode.limitPanDirection );
}
} );

// Pan to the focus trail right away if it is off-screen
this.keepTrailInView( focus.trail, lastNode.focusPanDirection );
this.keepTrailInView( focus.trail, lastNode.limitPanDirection );
}
}

Expand Down Expand Up @@ -910,7 +910,7 @@ class AnimatedPanZoomListener extends PanZoomListener {
* until the Node is fully displayed in the viewport.
* @param panDirection - if provided, we will only pan in the direction specified, null for all directions
*/
public panToNode( node: Node, panToCenter: boolean, panDirection?: FocusPanDirection | null ): void {
public panToNode( node: Node, panToCenter: boolean, panDirection?: LimitPanDirection | null ): void {
assert && assert( this._panBounds.isFinite(), 'panBounds should be defined when panning.' );
this.keepBoundsInView( node.globalBounds, panToCenter, panDirection );
}
Expand All @@ -928,7 +928,7 @@ class AnimatedPanZoomListener extends PanZoomListener {
* until all edges are on screen
* @param panDirection - if provided, we will only pan in the direction specified, null for all directions
*/
private keepBoundsInView( globalBounds: Bounds2, panToCenter: boolean, panDirection?: FocusPanDirection | null ): void {
private keepBoundsInView( globalBounds: Bounds2, panToCenter: boolean, panDirection?: LimitPanDirection | null ): void {
assert && assert( this._panBounds.isFinite(), 'panBounds should be defined when panning.' );
const sourcePosition = this.sourcePosition!;
assert && assert( sourcePosition, 'sourcePosition must be defined to handle keepBoundsInView, be sure to call initializePositions' );
Expand Down Expand Up @@ -989,7 +989,7 @@ class AnimatedPanZoomListener extends PanZoomListener {
/**
* Keep a trail in view by panning to it if it has bounds that are outside of the global panBounds.
*/
private keepTrailInView( trail: Trail, panDirection?: FocusPanDirection | null ): void {
private keepTrailInView( trail: Trail, panDirection?: LimitPanDirection | null ): void {
if ( this._panBounds.isFinite() && trail.lastNode().bounds.isFinite() ) {
const globalBounds = trail.localToGlobalBounds( trail.lastNode().localBounds );
if ( !this._panBounds.containsBounds( globalBounds ) ) {
Expand Down

0 comments on commit 9b92a67

Please sign in to comment.