// Copyright 2014-2020, University of Colorado Boulder

/**
 * Shows an Options dialog that consists of sim-global options.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 * @author Chris Malley (PixelZoom, Inc.)
 */

import inherit from '../../phet-core/js/inherit.js';
import merge from '../../phet-core/js/merge.js';
import PhetFont from '../../scenery-phet/js/PhetFont.js';
import Text from '../../scenery/js/nodes/Text.js';
import Dialog from '../../sun/js/Dialog.js';
import Tandem from '../../tandem/js/Tandem.js';
import joistStrings from './joistStrings.js';
import joist from './joist.js';

const optionsTitleString = joistStrings.options.title;

/**
 * @param {function(tandem:Tandem):Node} createContent - creates the dialog's content
 * @param {Object} [options]
 * @constructor
 */
function OptionsDialog( createContent, options ) {

  options = merge( {

    titleAlign: 'center',
    bottomMargin: 20,
    ySpacing: 20,

    // phet-io
    tandem: Tandem.REQUIRED,
    phetioDynamicElement: true
  }, options );

  assert && assert( !options.title, 'OptionsDialog sets title' );
  options.title = new Text( optionsTitleString, {
    font: new PhetFont( 30 ),
    maxWidth: 400, // determined empirically
    tandem: options.tandem.createTandem( 'title' )
  } );

  const content = createContent( options.tandem.createTandem( 'content' ) );

  Dialog.call( this, content, options );

  // @private
  this.disposeOptionsDialog = () => {
    content.dispose();
    options.title.dispose();
  };
}

joist.register( 'OptionsDialog', OptionsDialog );

inherit( Dialog, OptionsDialog, {

  /**
   * @public
   * @override
   */
  dispose: function() {
    this.disposeOptionsDialog();
    Dialog.prototype.dispose.call( this );
  }
}, {
  DEFAULT_FONT: new PhetFont( 15 ),
  DEFAULT_SPACING: 10
} );

export default OptionsDialog;
// Copyright 2014-2020, University of Colorado Boulder

/**
 * Shows an Options dialog that consists of sim-global options.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 * @author Chris Malley (PixelZoom, Inc.)
 */

import inherit from '../../phet-core/js/inherit.js';
import merge from '../../phet-core/js/merge.js';
import PhetFont from '../../scenery-phet/js/PhetFont.js';
import Text from '../../scenery/js/nodes/Text.js';
import Dialog from '../../sun/js/Dialog.js';
import Tandem from '../../tandem/js/Tandem.js';
import joist from './joist.js';
import joistStrings from './joistStrings.js';

const optionsTitleString = joistStrings.options.title;

/**
 * @param {function(tandem:Tandem):Node} createContent - creates the dialog's content
 * @param {Object} [options]
 * @constructor
 */
function OptionsDialog( createContent, options ) {

  options = merge( {

    titleAlign: 'center',
    bottomMargin: 26,
    ySpacing: 26,

    // phet-io
    tandem: Tandem.REQUIRED,
    phetioDynamicElement: true
  }, options );

  assert && assert( !options.title, 'OptionsDialog sets title' );
  options.title = new Text( optionsTitleString, {
    font: new PhetFont( 30 ),
    maxWidth: 400, // determined empirically
    tandem: options.tandem.createTandem( 'title' )
  } );

  const content = createContent( options.tandem.createTandem( 'content' ) );

  Dialog.call( this, content, options );

  // @private
  this.disposeOptionsDialog = () => {
    content.dispose();
    options.title.dispose();
  };
}

joist.register( 'OptionsDialog', OptionsDialog );

inherit( Dialog, OptionsDialog, {

  /**
   * @public
   * @override
   */
  dispose: function() {
    this.disposeOptionsDialog();
    Dialog.prototype.dispose.call( this );
  }
}, {
  DEFAULT_FONT: new PhetFont( 20 ),
  DEFAULT_SPACING: 14
} );

export default OptionsDialog;
adjust OptionsDialog to account for rescaling, https://github.com/phetsims/joist/issues/586