From 9e4abd1c878847b9add3131e4d8ba5d202cba8b3 Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Tue, 28 May 2024 09:19:46 -0600 Subject: [PATCH] change createDragBoundsProperty and createDragBoundsPropertyForLockToAxis to static methods --- js/bar-magnet/view/BarMagnetScreenView.ts | 2 +- js/common/view/FELScreenView.ts | 13 +++++++------ js/electromagnet/view/ElectromagnetScreenView.ts | 2 +- js/pickup-coil/view/PickupCoilScreenView.ts | 4 ++-- js/transformer/view/TransformerScreenView.ts | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/js/bar-magnet/view/BarMagnetScreenView.ts b/js/bar-magnet/view/BarMagnetScreenView.ts index 39b5a95d..aa336f8e 100644 --- a/js/bar-magnet/view/BarMagnetScreenView.ts +++ b/js/bar-magnet/view/BarMagnetScreenView.ts @@ -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, diff --git a/js/common/view/FELScreenView.ts b/js/common/view/FELScreenView.ts index b720eeaf..f53ffec9 100644 --- a/js/common/view/FELScreenView.ts +++ b/js/common/view/FELScreenView.ts @@ -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 ): TReadOnlyProperty { + protected static createDragBoundsProperty( rightPanelsBoundsProperty: TReadOnlyProperty, layoutBounds: Bounds2 ): TReadOnlyProperty { return new DerivedProperty( [ rightPanelsBoundsProperty ], - rightPanelsBounds => this.layoutBounds.withMaxX( rightPanelsBounds.left ) ); + rightPanelsBounds => layoutBounds.withMaxX( rightPanelsBounds.left ) ); } /** @@ -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, + layoutBounds: Bounds2, panelsBoundsProperty: TReadOnlyProperty, magnetPositionProperty: Property, pickupCoilPositionProperty: Property ): TReadOnlyProperty { - const dragBoundsProperty = new Property( this.layoutBounds ); + const dragBoundsProperty = new Property( layoutBounds ); Multilink.multilink( [ lockToAxisProperty, panelsBoundsProperty ], ( lockToAxis, panelsBounds ) => { if ( lockToAxis ) { @@ -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 ); } } ); diff --git a/js/electromagnet/view/ElectromagnetScreenView.ts b/js/electromagnet/view/ElectromagnetScreenView.ts index 937d63b8..f718b995 100644 --- a/js/electromagnet/view/ElectromagnetScreenView.ts +++ b/js/electromagnet/view/ElectromagnetScreenView.ts @@ -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, diff --git a/js/pickup-coil/view/PickupCoilScreenView.ts b/js/pickup-coil/view/PickupCoilScreenView.ts index 2fbab371..731d5770 100644 --- a/js/pickup-coil/view/PickupCoilScreenView.ts +++ b/js/pickup-coil/view/PickupCoilScreenView.ts @@ -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, diff --git a/js/transformer/view/TransformerScreenView.ts b/js/transformer/view/TransformerScreenView.ts index 3e65c975..dc4cfc32 100644 --- a/js/transformer/view/TransformerScreenView.ts +++ b/js/transformer/view/TransformerScreenView.ts @@ -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' ) );