Skip to content

Commit

Permalink
change createDragBoundsProperty and createDragBoundsPropertyForLockTo…
Browse files Browse the repository at this point in the history
…Axis to static methods
  • Loading branch information
pixelzoom committed May 28, 2024
1 parent 9e482ea commit 9e4abd1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/bar-magnet/view/BarMagnetScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class BarMagnetScreenView extends FELScreenView {
tandem: tandem
} );

const dragBoundsProperty = this.createDragBoundsProperty( rightPanels.boundsProperty );
const dragBoundsProperty = FELScreenView.createDragBoundsProperty( rightPanels.boundsProperty, this.layoutBounds );

const barMagnetNode = new BarMagnetNode( model.barMagnet, {
seeInsideProperty: viewProperties.seeInsideBarMagnetProperty,
Expand Down
13 changes: 7 additions & 6 deletions js/common/view/FELScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ export default class FELScreenView extends ScreenView {
* compass, they can 'Reset All'. For more discussion about this, see
* https://github.com/phetsims/faradays-electromagnetic-lab/issues/163#issuecomment-2121174433
*/
protected createDragBoundsProperty( rightPanelsBoundsProperty: TReadOnlyProperty<Bounds2> ): TReadOnlyProperty<Bounds2> {
protected static createDragBoundsProperty( rightPanelsBoundsProperty: TReadOnlyProperty<Bounds2>, layoutBounds: Bounds2 ): TReadOnlyProperty<Bounds2> {
return new DerivedProperty( [ rightPanelsBoundsProperty ],
rightPanelsBounds => this.layoutBounds.withMaxX( rightPanelsBounds.left ) );
rightPanelsBounds => layoutBounds.withMaxX( rightPanelsBounds.left ) );
}

/**
Expand All @@ -184,14 +184,15 @@ export default class FELScreenView extends ScreenView {
* See notes above for createDragBoundsProperty, about why we're ignoring optional leftPanels. Those notes
* apply here as well.
*/
protected createDragBoundsPropertyForLockToAxis(
protected static createDragBoundsPropertyForLockToAxis(
lockToAxisProperty: TReadOnlyProperty<boolean>,
layoutBounds: Bounds2,
panelsBoundsProperty: TReadOnlyProperty<Bounds2>,
magnetPositionProperty: Property<Vector2>,
pickupCoilPositionProperty: Property<Vector2>
): TReadOnlyProperty<Bounds2> {

const dragBoundsProperty = new Property( this.layoutBounds );
const dragBoundsProperty = new Property( layoutBounds );

Multilink.multilink( [ lockToAxisProperty, panelsBoundsProperty ], ( lockToAxis, panelsBounds ) => {
if ( lockToAxis ) {
Expand All @@ -210,13 +211,13 @@ export default class FELScreenView extends ScreenView {
const y = pickupCoilPositionProperty.value.y;

// Constrain to horizontal dragging.
dragBoundsProperty.value = new Bounds2( this.layoutBounds.left, y, panelsBounds.left, y );
dragBoundsProperty.value = new Bounds2( layoutBounds.left, y, panelsBounds.left, y );
}
else {
// Dragging is 2D, horizontal and vertical.

// Restore drag bounds.
dragBoundsProperty.value = this.layoutBounds.withMaxX( panelsBounds.left );
dragBoundsProperty.value = layoutBounds.withMaxX( panelsBounds.left );
}
} );

Expand Down
2 changes: 1 addition & 1 deletion js/electromagnet/view/ElectromagnetScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class ElectromagnetScreenView extends FELScreenView {
tandem: tandem
} );

const dragBoundsProperty = this.createDragBoundsProperty( rightPanels.boundsProperty );
const dragBoundsProperty = FELScreenView.createDragBoundsProperty( rightPanels.boundsProperty, this.layoutBounds );

const electromagnetNode = new ElectromagnetNode( model.electromagnet, {
dragBoundsProperty: dragBoundsProperty,
Expand Down
4 changes: 2 additions & 2 deletions js/pickup-coil/view/PickupCoilScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default class PickupCoilScreenView extends FELScreenView {
tandem: tandem
} );

const dragBoundsProperty = this.createDragBoundsPropertyForLockToAxis( lockToAxisProperty,
rightPanels.boundsProperty, model.barMagnet.positionProperty, model.pickupCoil.positionProperty );
const dragBoundsProperty = FELScreenView.createDragBoundsPropertyForLockToAxis( lockToAxisProperty,
this.layoutBounds, rightPanels.boundsProperty, model.barMagnet.positionProperty, model.pickupCoil.positionProperty );

const barMagnetNode = new BarMagnetNode( model.barMagnet, {
dragBoundsProperty: dragBoundsProperty,
Expand Down
4 changes: 2 additions & 2 deletions js/transformer/view/TransformerScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default class TransformerScreenView extends FELScreenView {
tandem: tandem
} );

const dragBoundsProperty = this.createDragBoundsPropertyForLockToAxis( lockToAxisProperty,
rightPanels.boundsProperty, electromagnet.positionProperty, pickupCoil.positionProperty );
const dragBoundsProperty = FELScreenView.createDragBoundsPropertyForLockToAxis( lockToAxisProperty,
this.layoutBounds, rightPanels.boundsProperty, electromagnet.positionProperty, pickupCoil.positionProperty );

const transformerNode = new TransformerNode( model.transformer, dragBoundsProperty, lockToAxisProperty,
tandem.createTandem( 'transformerNode' ) );
Expand Down

0 comments on commit 9e4abd1

Please sign in to comment.