Skip to content

Commit

Permalink
Adding slightly improved close button to the Options dialog (now posi…
Browse files Browse the repository at this point in the history
…tioned correctly in the corner, and doesn't push content over), see #154, phetsims/molecule-shapes#96, #166
  • Loading branch information
jonathanolson committed Jan 29, 2015
1 parent 04c707f commit 13b93ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions js/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ define( function( require ) {
stroke: 'black', // {string|Color}
backgroundPickable: true,
xMargin: 20,
yMargin: 20
yMargin: 20,
closeButtonMargin: 5 // {number} how far away should the close button be from the panel border
}, options );

var dialog = this;
Expand Down Expand Up @@ -82,6 +83,8 @@ define( function( require ) {
updateTitlePosition();
}

Panel.call( this, dialogContent, options );

if ( options.hasCloseButton ) {
var crossSize = 10;
var crossNode = new Path( new Shape().moveTo( 0, 0 ).lineTo( crossSize, crossSize ).moveTo( 0, crossSize ).lineTo( crossSize, 0 ), {
Expand All @@ -98,29 +101,22 @@ define( function( require ) {
dialog.hide();
}
} );
dialogContent.addChild( closeButton );
this.addChild( closeButton );

var updateClosePosition = function() {
closeButton.left = content.right + 10;
if ( options.title ) {
closeButton.top = options.title.top;
}
else {
closeButton.top = content.top;
}
closeButton.right = dialogContent.right + options.xMargin - options.closeButtonMargin;
closeButton.top = dialogContent.top - options.xMargin + options.closeButtonMargin;
};

if ( options.resize ) {
content.addEventListener( 'bounds', updateClosePosition );
dialogContent.addEventListener( 'bounds', updateClosePosition );
if ( options.title ) {
options.title.addEventListener( 'bounds', updateClosePosition );
}
}
updateClosePosition();
}

Panel.call( this, dialogContent, options );

var sim = window.phet.sim;

function updateLayout() {
Expand Down
2 changes: 1 addition & 1 deletion js/OptionsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define( function( require ) {
title: new Text( optionsTitleString, { font: new PhetFont( 30 ) } ),
titleAlign: 'center',
modal: true,
hasCloseButton: false
hasCloseButton: true
} );
}

Expand Down

0 comments on commit 13b93ab

Please sign in to comment.