Skip to content

Commit

Permalink
fix dynamic layout, #140
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Sep 1, 2022
1 parent 880ce71 commit d5714e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
17 changes: 13 additions & 4 deletions js/common/view/SurfaceColorKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ export default class SurfaceColorKey extends Node {
}

// layout
titleText.centerX = spectrumNode.centerX;
leftLabelText.left = spectrumNode.left + options.xMargin;
rightLabelText.right = spectrumNode.right - options.xMargin;
titleText.top = leftLabelText.top = rightLabelText.top = spectrumNode.bottom + options.ySpacing;
const top = spectrumNode.bottom + options.ySpacing;
titleText.boundsProperty.link( () => {
titleText.centerX = spectrumNode.centerX;
titleText.top = top;
} );
leftLabelText.boundsProperty.link( () => {
leftLabelText.left = spectrumNode.left + options.xMargin;
leftLabelText.top = top;
} );
rightLabelText.boundsProperty.link( () => {
rightLabelText.right = spectrumNode.right - options.xMargin;
rightLabelText.top = top;
} );

this.mutate( options );
}
Expand Down
24 changes: 15 additions & 9 deletions js/twoatoms/view/TwoAtomsScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Multilink from '../../../../axon/js/Multilink.js';
import ScreenView, { ScreenViewOptions } from '../../../../joist/js/ScreenView.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
Expand Down Expand Up @@ -120,17 +121,22 @@ export default class TwoAtomsScreenView extends ScreenView {
platesNode.centerX = moleculeX;
platesNode.bottom = moleculeY + ( platesNode.plateHeight / 2 );

// centered below molecule
electronegativityPanels.centerX = moleculeX;
electronegativityPanels.bottom = this.layoutBounds.bottom - 25;
Multilink.multilink( [ electronegativityPanels.boundsProperty, bondCharacterPanel.boundsProperty ], () => {

// centered above molecule
electrostaticPotentialColorKey.centerX = electronDensityColorKey.centerX = moleculeX;
electrostaticPotentialColorKey.top = electronDensityColorKey.top = 25;
// centered below molecule
electronegativityPanels.centerX = moleculeX;
electronegativityPanels.bottom = this.layoutBounds.bottom - 25;

// centered above EN controls
bondCharacterPanel.centerX = moleculeX;
bondCharacterPanel.bottom = electronegativityPanels.top - 10;
} );

// centered above EN controls
bondCharacterPanel.centerX = moleculeX;
bondCharacterPanel.bottom = electronegativityPanels.top - 10;
// centered above molecule
electrostaticPotentialColorKey.boundsProperty.link( () => {
electrostaticPotentialColorKey.centerX = electronDensityColorKey.centerX = moleculeX;
electrostaticPotentialColorKey.top = electronDensityColorKey.top = 25;
} );

// to right of positive plate, top aligned
controlPanel.left = platesNode.right + 70;
Expand Down

0 comments on commit d5714e0

Please sign in to comment.