Skip to content

Commit

Permalink
Home screen and navbar improvements to layout/organization for #725
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Jul 10, 2021
1 parent d7b0d14 commit 33aab76
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
7 changes: 1 addition & 6 deletions js/HomeScreenButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class HomeScreenButton extends VBox {

options = merge( {
cursor: 'pointer',
resize: true,
showUnselectedHomeScreenIconFrame: false, // put a frame around unselected home screen icons

// pdom
Expand Down Expand Up @@ -107,7 +106,7 @@ class HomeScreenButton extends VBox {
textPropertyOptions: { phetioReadOnly: true } // text is updated via screen.nameProperty
} );

super( merge( { children: [ nodeContainer, new Node( { children: [ text ] } ) ] }, options ) );
super( merge( { children: [ nodeContainer, text ] }, options ) );

// @public (read-only)
this.screen = screen;
Expand Down Expand Up @@ -150,9 +149,6 @@ class HomeScreenButton extends VBox {
text.maxWidth = nodeContainer.width;
setOpacityAndFill();
this.setSpacing( data.spacing );

// update the VBox layout after changing the size of its children
this.updateLayout();
} );

// update the appearance when the button is highlighted
Expand All @@ -164,7 +160,6 @@ class HomeScreenButton extends VBox {
// update the text when the screen name changes
screen.nameProperty.link( name => {
text.text = name;
this.updateLayout();
} );

let buttonWasAlreadySelected = false;
Expand Down
9 changes: 5 additions & 4 deletions js/NavigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ class NavigationBar extends Node {

// Compute the distance between *centers* of each button
const spaceBetweenButtons = maxScreenButtonWidth + SCREEN_BUTTON_SPACING;
for ( let i = 0; i < screenButtons.length; i++ ) {

screenButtons.forEach( ( screenButton, i ) => {
// Equally space the centers of the buttons around the origin of their parent (screenButtonsContainer)
screenButtons[ i ].centerX = spaceBetweenButtons * ( i - ( screenButtons.length - 1 ) / 2 );
}
screenButton.localBoundsProperty.link( localBounds => {
screenButton.centerX = spaceBetweenButtons * ( i - ( screenButtons.length - 1 ) / 2 );
} );
} );

// @private - Put all screen buttons under a parent, to simplify layout
this.screenButtonsContainer = new Node( {
Expand Down
26 changes: 14 additions & 12 deletions js/NavigationBarScreenButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ class NavigationBarScreenButton extends Node {
fill: 'black'
} );

this.addChild( iconAndText );
this.addChild( overlay );
this.addChild( brightenHighlight );
this.addChild( darkenHighlight );

// Is this button's screen selected?
const selectedProperty = new DerivedProperty( [ screenProperty ], currentScreen => ( currentScreen === screen ) );

Expand Down Expand Up @@ -184,6 +179,20 @@ class NavigationBarScreenButton extends Node {
brightenHighlight.center = darkenHighlight.center = iconAndText.center;
};

// Update the button's text and layout when the screen name changes
screen.nameProperty.link( name => {
text.text = name;
} );
iconAndText.boundsProperty.lazyLink( updateLayout );
text.boundsProperty.link( updateLayout );

this.children = [
iconAndText,
overlay,
brightenHighlight,
darkenHighlight
];

const needsIconMaxWidth = options.maxButtonWidth && ( this.width > options.maxButtonWidth );

// Constrain text and icon width, if necessary
Expand All @@ -196,13 +205,6 @@ class NavigationBarScreenButton extends Node {
text.maxWidth = this.width;
}

// Update the button's text and layout when the screen name changes
screen.nameProperty.link( name => {
text.text = name;
} );

text.textProperty.link( updateLayout );

needsIconMaxWidth && assert && assert( Utils.toFixed( this.width, 0 ) === Utils.toFixed( options.maxButtonWidth, 0 ),
`this.width ${this.width} !== options.maxButtonWidth ${options.maxButtonWidth}` );

Expand Down

0 comments on commit 33aab76

Please sign in to comment.