Skip to content

Commit

Permalink
keep constant height for Equation accordion box, #157
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Aug 29, 2019
1 parent 4300a29 commit eb86e66
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions js/curve-fitting/view/EquationAccordionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ define( require => {
const Panel = require( 'SUN/Panel' );
const Text = require( 'SCENERY/nodes/Text' );
const Util = require( 'DOT/Util' );
const VStrut = require( 'SCENERY/nodes/VStrut' );

// strings
const equationString = require( 'string!CURVE_FITTING/equation' );
Expand Down Expand Up @@ -62,19 +63,6 @@ define( require => {
expandCollapseButton.touchArea = expandCollapseButton.localBounds.dilated( expandCollapseButton.width / 3 );
expandCollapseButton.mouseArea = expandCollapseButton.localBounds.dilated( expandCollapseButton.width / 3 );

const content = new HBox( {
spacing: 8,
children: [ expandCollapseButton, titleNode ]
} );

super( content, options );

// @public (read-only) is used by the screen view to bump out points from below; see #131
this.expandCollapseButton = expandCollapseButton;

// @public an emitter that is fired whenever this panel is updated: is used for background node for #126
this.updatedEmitter = new Emitter();

// visible node when panel is expanded
const equationNode = new EquationNode( orderProperty, {
coefficientSignTextOptions: {
Expand All @@ -89,6 +77,21 @@ define( require => {
maxWidth: options.equationNodeMaxWidth
} );

// So that the panel's height doesn't change.
const vStrut = new VStrut( equationNode.height );

const content = new HBox( {
spacing: 8
} );

super( content, options );

// @public (read-only) is used by the screen view to bump out points from below; see #131
this.expandCollapseButton = expandCollapseButton;

// @public an emitter that is fired whenever this panel is updated: is used for background node for #126
this.updatedEmitter = new Emitter();

/**
* This method rounds the given number to the given amount of digits
* Rounds the number to the nearest whole number if the nearest whole number has as many or more digits than maxDigits
Expand Down Expand Up @@ -134,12 +137,16 @@ define( require => {
);
equationNode.setCoefficients( coefficientStrings );

const children = [ expandCollapseButton ];
if ( equationPanelExpandedProperty.value ) {
content.children = [ expandCollapseButton, curve.isCurvePresent() ? equationNode : undefinedEquationText ];
children.push( curve.isCurvePresent() ? equationNode : undefinedEquationText );
}
else {
content.children = [ expandCollapseButton, titleNode ];
children.push( titleNode );
}
children.push( vStrut );

content.children = children;

this.updatedEmitter.emit();

Expand Down

0 comments on commit eb86e66

Please sign in to comment.