Skip to content

Commit

Permalink
Align probe to body, see #589
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jul 27, 2020
1 parent 3517b3b commit 58d7ded
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions js/view/AmmeterNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@ class AmmeterNode extends Node {
// @public (read-only) {Ammeter} - the model associated with this view
this.ammeter = ammeter;

const alignProbeToBody = () => {
if ( ammeter.draggingProbesWithBodyProperty.get() ) {
ammeter.probePositionProperty.set( ammeter.bodyPositionProperty.value.plusXY( 40, -80 ) );
}
};

// When the body position changes, update the body node and the wire
ammeter.bodyPositionProperty.link( bodyPosition => {
bodyNode.centerTop = bodyPosition;
wireBodyPositionProperty.value = bodyNode.centerTop.plusXY( 0, PROBE_CONNECTION_POINT_DY );
if ( ammeter.draggingProbesWithBodyProperty.get() ) {
ammeter.probePositionProperty.set( bodyPosition.plusXY( 40, -80 ) );
}
alignProbeToBody();
} );

// When the probe position changes, update the probe node and the wire
Expand All @@ -152,6 +156,7 @@ class AmmeterNode extends Node {

// Show the ammeter in the play area when dragged from toolbox
ammeter.visibleProperty.linkAttribute( this, 'visible' );
ammeter.visibleProperty.link( alignProbeToBody );

const probeDragHandler = new MovableDragHandler( ammeter.probePositionProperty, {
tandem: tandem.createTandem( 'probeDragHandler' ),
Expand Down
2 changes: 1 addition & 1 deletion js/view/CircuitLayerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ class CircuitLayerNode extends Node {
* Find the current under the given probe
* @param {Node} probeNode
* @returns {number|null}
* @private
* @public
*/
getCurrent( probeNode ) {
const mainCurrent = this.getCurrentInLayer( probeNode, this.fixedCircuitElementLayer );
Expand Down

0 comments on commit 58d7ded

Please sign in to comment.