Skip to content

Commit

Permalink
type for styling group focus highlights from node, see #708
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Jan 18, 2018
1 parent 84c59ea commit 7c47eb9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
18 changes: 12 additions & 6 deletions js/accessibility/FocusHighlightFromNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ define( function( require ) {
// {boolean} - if true, highlight will surround local bounds
useLocalBounds: false,

// {boolean} - if true, dilation for bounds around node will increase, see setShapeFromNode()
useGroupDilation: false,

// line width options, one for each highlight, will be calculated based on transform of this path unless provided
outerLineWidth: null,
innerLineWidth: null
innerLineWidth: null,

// {null|number] - default value is function of node transform (minus translation), but can be set explicitly
// see FocusHighlightPath.getDilationCoefficient()
dilationCoefficient: null,

// {boolean} - if true, dilation for bounds around node will increase, see setShapeFromNode()
useGroupDilation: false
}, options );

this.useLocalBounds = options.useLocalBounds; // @private
this.useGroupDilation = options.useGroupDilation; // @private
this.dilationCoefficient = options.dilationCoefficient; // @private

FocusHighlightPath.call( this, null, options );

Expand Down Expand Up @@ -65,8 +70,9 @@ define( function( require ) {
setShapeFromNode: function( node ) {
this.nodeBounds = this.useLocalBounds ? node.localBounds : node.bounds;

// Figure out how much dilation to apply to the focus highlight around the node
var dilationCoefficient = this.useGroupDilation ? FocusHighlightPath.getGroupDilationCoefficient( node ) : FocusHighlightPath.getDilationCoefficient( node );
// Figure out how much dilation to apply to the focus highlight around the node, calculated unless specified
// with options
var dilationCoefficient = this.dilationCoefficient || ( this.useGroupDilation ? FocusHighlightPath.getGroupDilationCoefficient( node ) : FocusHighlightPath.getDilationCoefficient( node ) );
var dilatedBounds = this.nodeBounds.dilated( dilationCoefficient );

// Update the line width of the focus highlight based on the transform of the node
Expand Down
42 changes: 42 additions & 0 deletions js/accessibility/GroupFocusHighlightFromNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2017, University of Colorado Boulder

/**
* A FocusHighlightPath subtype that is based around a Node, with styling that makes it look like a group focus
* highlight.
*
* @author Jesse Greenberg (PhET Interactive Simulations)
*/
define( function( require ) {
'use strict';

// modules
var FocusHighlightFromNode = require( 'SCENERY/accessibility/FocusHighlightFromNode' );
var FocusHighlightPath = require( 'SCENERY/accessibility/FocusHighlightPath' );
var inherit = require( 'PHET_CORE/inherit' );
var scenery = require( 'SCENERY/scenery' );

/**
*
* @param {Node|null} node
* @param {Object} [options]
* @constructor
*/
function GroupFocusHighlightFromNode( node, options ) {

options = _.extend( {
outerStroke: FocusHighlightPath.OUTER_LIGHT_GROUP_FOCUS_COLOR,
innerStroke: FocusHighlightPath.INNER_LIGHT_GROUP_FOCUS_COLOR,

outerLineWidth: FocusHighlightPath.GROUP_OUTER_LINE_WIDTH,
innerLineWidth: FocusHighlightPath.GROUP_INNER_LINE_WIDTH,

useGroupDilation: true
}, options );

FocusHighlightFromNode.call( this, node, options );
}

scenery.register( 'GroupFocusHighlightFromNode', GroupFocusHighlightFromNode );

return inherit( FocusHighlightFromNode, GroupFocusHighlightFromNode );
} );

0 comments on commit 7c47eb9

Please sign in to comment.