-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize ZoomButtonGroup and create subclasses with Plus/Minus or M…
…agnifyingGlass, see phetsims/circuit-construction-kit-common#620
- Loading branch information
Showing
3 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020, University of Colorado Boulder | ||
|
||
import Dimension2 from '../../dot/js/Dimension2.js'; | ||
import merge from '../../phet-core/js/merge.js'; | ||
import MagnifyingGlassNode from './MagnifyingGlassNode.js'; | ||
import MinusNode from './MinusNode.js'; | ||
import PlusNode from './PlusNode.js'; | ||
import sceneryPhet from './sceneryPhet.js'; | ||
import ZoomButtonGroup from './ZoomButtonGroup.js'; | ||
|
||
/** | ||
* ZoomButtonGroup that shows magnifying glass icons | ||
* @author Sam Reid (PhET Interactive Simulations) | ||
*/ | ||
class MagnifyingGlassZoomButtonGroup extends ZoomButtonGroup { | ||
|
||
/** | ||
* @param {NumberProperty} zoomLevelProperty - smaller value means more zoomed out | ||
* @param {Object} [options] | ||
*/ | ||
constructor( zoomLevelProperty, options ) { | ||
|
||
options = merge( { | ||
magnifyingGlassNodeOptions: { | ||
glassRadius: 10 | ||
} | ||
}, options ); | ||
|
||
|
||
// plus or minus sign in middle of magnifying glass | ||
const signOptions = { | ||
size: new Dimension2( | ||
1.3 * options.magnifyingGlassNodeOptions.glassRadius, | ||
options.magnifyingGlassNodeOptions.glassRadius / 3 | ||
) | ||
}; | ||
|
||
const zoomInIcon = new MagnifyingGlassNode( merge( {}, options.magnifyingGlassNodeOptions, { icon: new PlusNode( signOptions ) } ) ); | ||
const zoomOutIcon = new MagnifyingGlassNode( merge( {}, options.magnifyingGlassNodeOptions, { icon: new MinusNode( signOptions ) } ) ); | ||
super( zoomInIcon, zoomOutIcon, zoomLevelProperty, options ); | ||
} | ||
} | ||
|
||
sceneryPhet.register( 'MagnifyingGlassZoomButtonGroup', MagnifyingGlassZoomButtonGroup ); | ||
export default MagnifyingGlassZoomButtonGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2020, University of Colorado Boulder | ||
|
||
import Dimension2 from '../../dot/js/Dimension2.js'; | ||
import merge from '../../phet-core/js/merge.js'; | ||
import AlignBox from '../../scenery/js/nodes/AlignBox.js'; | ||
import AlignGroup from '../../scenery/js/nodes/AlignGroup.js'; | ||
import MinusNode from './MinusNode.js'; | ||
import PlusNode from './PlusNode.js'; | ||
import sceneryPhet from './sceneryPhet.js'; | ||
import ZoomButtonGroup from './ZoomButtonGroup.js'; | ||
|
||
// constants | ||
const DEFAULT_SIZE = new Dimension2( 20 * 0.35, 3.6 * 0.35 ); | ||
|
||
/** | ||
* A ZoomButtonGroup that shows a "+" and "-" sign for the button icons. | ||
* | ||
* @author Sam Reid (PhET Interactive Simulations) | ||
*/ | ||
class PlusMinusZoomButtonGroup extends ZoomButtonGroup { | ||
|
||
/** | ||
* @param {NumberProperty} zoomLevelProperty - smaller value means more zoomed out | ||
* @param {Object} [options] | ||
*/ | ||
constructor( zoomLevelProperty, options ) { | ||
options = merge( { | ||
buttonOptions: { | ||
xMargin: 9, | ||
yMargin: 10 | ||
}, | ||
iconOptions: { | ||
size: DEFAULT_SIZE | ||
} | ||
}, options ); | ||
|
||
// Make sure the + and - have the same dimensions | ||
const alignGroup = new AlignGroup(); | ||
const plusMinusNodeOptions = merge( { size: DEFAULT_SIZE }, options.iconOptions ); | ||
const alignBoxOptions = { group: alignGroup }; | ||
|
||
super( | ||
new AlignBox( new PlusNode( plusMinusNodeOptions ), alignBoxOptions ), | ||
new AlignBox( new MinusNode( plusMinusNodeOptions ), alignBoxOptions ), | ||
zoomLevelProperty, options | ||
); | ||
} | ||
} | ||
|
||
sceneryPhet.register( 'PlusMinusZoomButtonGroup', PlusMinusZoomButtonGroup ); | ||
export default PlusMinusZoomButtonGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters