From ce9ced7065df1bf2236e9934af82b9aca8556a1f Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Sat, 13 Aug 2022 11:42:35 -0600 Subject: [PATCH] Button fixes (and helper improvements) for https://github.com/phetsims/chipper/issues/1302 --- js/buttons/ButtonNode.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/js/buttons/ButtonNode.ts b/js/buttons/ButtonNode.ts index fa49fe0e..a8f6f725 100644 --- a/js/buttons/ButtonNode.ts +++ b/js/buttons/ButtonNode.ts @@ -215,12 +215,19 @@ 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; @@ -228,12 +235,19 @@ export default class ButtonNode extends Sizable( Voicing( Node ) ) { }, { 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;