Skip to content

Commit

Permalink
make background rect a public member, phetsims/number-line-integers#24
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Sep 26, 2019
1 parent ad65a89 commit f40ba0f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions js/BackgroundNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@ define( require => {
constructor( node, options ) {

options = merge( {
xMargin: 2, // set the x margin between the Node content and background edge
yMargin: 2, // set the y margin between the Node content and background edge

// Options passed to the background Rectangle
backgroundOptions: {
fill: 'white',
opacity: 0.75
},
xMargin: 2,
yMargin: 2
}
}, options );

// translucent rectangle
const rectangle = new Rectangle( 0, 0, 1, 1, options.backgroundOptions );
super();

// @public (read-only) {Rectangle} - translucent rectangle
this.background = new Rectangle( 0, 0, 1, 1, options.backgroundOptions );

// size the rectangle to fit the node
node.on( 'bounds', function() {
rectangle.setRect( 0, 0, node.width + 2 * options.xMargin, node.height + 2 * options.yMargin );
node.center = rectangle.center;
node.on( 'bounds', () => {
this.background.setRect( 0, 0, node.width + 2 * options.xMargin, node.height + 2 * options.yMargin );
node.center = this.background.center;
} );

assert && assert( !options.children, 'BackgroundNode sets children' );
options.children = [ rectangle, node ];

super( options );
options.children = [ this.background, node ];
this.mutate( options );
}
}

Expand Down

0 comments on commit f40ba0f

Please sign in to comment.