Skip to content

Commit

Permalink
Button fixes (and helper improvements) for phetsims/chipper#1302
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Aug 13, 2022
1 parent 2f9e329 commit ce9ced7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions js/buttons/ButtonNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,39 @@ export default class ButtonNode extends Sizable( Voicing( Node ) ) {
// Our layout sizes will need to handle treating the maxLineWidth so we have stable layout with lineWidth changes
this.layoutWidthProperty = new DerivedProperty( [
this.localPreferredWidthProperty,
this.localMinimumWidthProperty,
this.isWidthResizableProperty,
buttonBackground.boundsProperty
], ( localPreferredWidth, isWidthResizable, backgroundBounds ) => {
], ( localPreferredWidth, localMinimumWidth, isWidthResizable, backgroundBounds ) => {
if ( isWidthResizable ) {
// If needed, use the size our max-stroked path will have
return localPreferredWidth !== null ? localPreferredWidth : buttonBackground.shape!.bounds.width + this.maxLineWidth;
const result = localPreferredWidth !== null ? localPreferredWidth : buttonBackground.shape!.bounds.width + this.maxLineWidth;
if ( localMinimumWidth !== null ) {
return Math.max( localMinimumWidth, result );
}
else {
return result;
}
}
else {
return initialBackgroundWidth;
}
}, { tandem: Tandem.OPT_OUT } );
this.layoutHeightProperty = new DerivedProperty( [
this.localPreferredHeightProperty,
this.localMinimumHeightProperty,
this.isHeightResizableProperty,
buttonBackground.boundsProperty
], ( localPreferredHeight, isHeightResizable, backgroundBounds ) => {
], ( localPreferredHeight, localMinimumHeight, isHeightResizable, backgroundBounds ) => {
if ( isHeightResizable ) {
// If needed, use the size our max-stroked path will have
return localPreferredHeight !== null ? localPreferredHeight : buttonBackground.shape!.bounds.height + this.maxLineWidth;
const result = localPreferredHeight !== null ? localPreferredHeight : buttonBackground.shape!.bounds.height + this.maxLineWidth;
if ( localMinimumHeight !== null ) {
return Math.max( localMinimumHeight, result );
}
else {
return result;
}
}
else {
return initialBackgroundHeight;
Expand Down

0 comments on commit ce9ced7

Please sign in to comment.