Skip to content

Commit

Permalink
remove SunConstants.componentEnabledAppearance and its usages in enab…
Browse files Browse the repository at this point in the history
…ledAppearanceStrategy options, phetsims/scenery#1173
  • Loading branch information
zepumph committed Mar 26, 2021
1 parent 847fe25 commit 5d3249f
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 77 deletions.
7 changes: 2 additions & 5 deletions js/ABSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class ABSwitch extends Node {
// {function( Node, boolean )} method of making the labels look disabled
setEnabled: DEFAULT_SET_ENABLED,

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,
// {number} - opt into Node's disabled opacity when enabled:false
disabledOpacity: SunConstants.DISABLED_OPACITY,

// phet-io
tandem: Tandem.REQUIRED,
Expand Down Expand Up @@ -135,9 +135,6 @@ class ABSwitch extends Node {

this.mutate( options );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this ) );

// support for binder documentation, stripped out in builds and only runs when ?binder is specified
assert && phet.chipper.queryParameters.binder && InstanceRegistry.registerDataURL( 'sun', 'ABSwitch', this );
}
Expand Down
7 changes: 2 additions & 5 deletions js/AquaRadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class AquaRadioButton extends Node {
xSpacing: 8, // horizontal space between the button and the labelNode
stroke: 'black', // color used to stroke the outer edge of the button

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,
// {number} - opt into Node's disabled opacity when enabled:false
disabledOpacity: SunConstants.DISABLED_OPACITY,

// phet-io
tandem: Tandem.REQUIRED,
Expand Down Expand Up @@ -150,9 +150,6 @@ class AquaRadioButton extends Node {

this.mutate( options );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this ) );

// @private
this.disposeAquaRadioButton = () => {
this.removeInputListener( fireListener );
Expand Down
8 changes: 2 additions & 6 deletions js/AquaRadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ class AquaRadioButtonGroup extends LayoutBox {
mouseAreaXDilation: 0,
mouseAreaYDilation: 0,

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,

// {number} - opt into Node's disabled opacity when enabled:false
disabledOpacity: SunConstants.DISABLED_OPACITY,
// supertype options
orientation: 'vertical', // Aqua radio buttons are typically vertical, rarely horizontal
spacing: 3, // space between each button, perpendicular to options.orientation
Expand Down Expand Up @@ -135,9 +134,6 @@ class AquaRadioButtonGroup extends LayoutBox {
tandem: options.tandem.createTandem( 'property' )
} );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this ) );

// @private
this.disposeAquaRadioButtonGroup = () => {
this.removeInputListener( intentListener );
Expand Down
6 changes: 0 additions & 6 deletions js/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class Checkbox extends Node {
checkboxColorBackground: 'white',
disabledOpacity: SunConstants.DISABLED_OPACITY,

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,

// phet-io
tandem: Tandem.REQUIRED,
phetioEventType: EventType.USER,
Expand Down Expand Up @@ -153,9 +150,6 @@ class Checkbox extends Node {
tandem: options.tandem.createTandem( 'property' )
} );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this, { disabledOpacity: options.disabledOpacity } ) );

// support for binder documentation, stripped out in builds and only runs when ?binder is specified
assert && phet.chipper.queryParameters.binder && InstanceRegistry.registerDataURL( 'sun', 'Checkbox', this );

Expand Down
11 changes: 1 addition & 10 deletions js/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

import BooleanProperty from '../../axon/js/BooleanProperty.js';
import Vector2 from '../../dot/js/Vector2.js';
import dotRandom from '../../dot/js/dotRandom.js';
import Vector2 from '../../dot/js/Vector2.js';
import InstanceRegistry from '../../phet-core/js/documentation/InstanceRegistry.js';
import merge from '../../phet-core/js/merge.js';
import PDOMPeer from '../../scenery/js/accessibility/pdom/PDOMPeer.js';
Expand All @@ -33,7 +33,6 @@ import Tandem from '../../tandem/js/Tandem.js';
import IOType from '../../tandem/js/types/IOType.js';
import ComboBoxButton from './ComboBoxButton.js';
import ComboBoxListBox from './ComboBoxListBox.js';
import SunConstants from './SunConstants.js';
import sun from './sun.js';

// const
Expand Down Expand Up @@ -82,9 +81,6 @@ class ComboBox extends Node {
cornerRadius: 4, // applied to button, listBox, and item highlights
highlightFill: 'rgb( 245, 245, 245 )', // {Color|string} highlight behind items in the list

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,

// Margins around the edges of the button and listbox when highlight is invisible.
// Highlight margins around the items in the list are set to 1/2 of these values.
// These values must be > 0.
Expand Down Expand Up @@ -126,8 +122,6 @@ class ComboBox extends Node {
// validate option values
assert && assert( options.xMargin > 0 && options.yMargin > 0,
`margins must be > 0, xMargin=${options.xMargin}, yMargin=${options.yMargin}` );
assert && assert( options.disabledOpacity > 0 && options.disabledOpacity < 1,
`invalid disabledOpacity: ${options.disabledOpacity}` );
assert && assert( _.includes( LIST_POSITION_VALUES, options.listPosition ),
`invalid listPosition: ${options.listPosition}` );
assert && assert( _.includes( ALIGN_VALUES, options.align ),
Expand Down Expand Up @@ -207,9 +201,6 @@ class ComboBox extends Node {

this.mutate( options );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this, { disabledOpacity: options.disabledOpacity } ) );

// Clicking on the button toggles visibility of the list box
this.button.addListener( () => {
this.listBox.visibleProperty.value = !this.listBox.visibleProperty.value;
Expand Down
8 changes: 2 additions & 6 deletions js/NumberSpinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class NumberSpinner extends Node {
// may be ignored if incrementFunction and decrementFunction are provided
deltaValue: 1,

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,

// {number} - opt into Node's disabled opacity when enabled:false
disabledOpacity: SunConstants.DISABLED_OPACITY,
xSpacing: 5,
ySpacing: 3,

Expand Down Expand Up @@ -212,9 +211,6 @@ class NumberSpinner extends Node {

super( options );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this ) );

// enable/disable arrow buttons
const updateEnabled = () => {
incrementButton.enabled = ( options.incrementFunction( numberProperty.value ) <= rangeProperty.value.max );
Expand Down
6 changes: 0 additions & 6 deletions js/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ class Slider extends Node {
enabledRangeProperty: null, // {Property.<Range>|null} determine the portion of range that is enabled
disabledOpacity: SunConstants.DISABLED_OPACITY, // opacity applied to the entire Slider when disabled

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,

// phet-io
tandem: Tandem.REQUIRED,
phetioType: Slider.SliderIO,
Expand Down Expand Up @@ -291,9 +288,6 @@ class Slider extends Node {

this.mutate( options );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this, { disabledOpacity: options.disabledOpacity } ) );

// @private {function} - Called by dispose
this.disposeSlider = () => {
thumb.dispose && thumb.dispose(); // in case a custom thumb is provided via options.thumbNode that doesn't implement dispose
Expand Down
19 changes: 1 addition & 18 deletions js/SunConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import merge from '../../phet-core/js/merge.js';
import sun from './sun.js';

const SunConstants = {
Expand All @@ -25,23 +24,7 @@ const SunConstants = {
VALUE_NUMBERED_PLACEHOLDER: '{0}',

// Opacity that is typically applied to a UI component in its disabled state, to make it look grayed out.
DISABLED_OPACITY: 0.45,

/**
* The basic PhET enabled/disabled look and feel for interactive components.
* @public
* @param {boolean} enabled
* @param {Node} node
* @param {Object} [options]
* @returns {function(boolean):void}
*/
componentEnabledListener( enabled, node, options ) {
options = merge( {
disabledOpacity: SunConstants.DISABLED_OPACITY
}, options );

node.opacity = enabled ? 1.0 : options.disabledOpacity;
}
DISABLED_OPACITY: 0.45
};

sun.register( 'SunConstants', SunConstants );
Expand Down
7 changes: 2 additions & 5 deletions js/ToggleSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class ToggleSwitch extends Node {
// number of thumb-widths outside the normal range past where the model value will change
toggleThreshold: 1,

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,
// {number} - opt into Node's disabled opacity when enabled:false
disabledOpacity: SunConstants.DISABLED_OPACITY,

// thumb
thumbFill: null, // {Color|string} thumb fill, default computed below
Expand Down Expand Up @@ -238,9 +238,6 @@ class ToggleSwitch extends Node {

this.mutate( options );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this ) );

// Add a link to the Property that this switch controls
this.addLinkedElement( property, {
tandem: options.tandem.createTandem( 'property' )
Expand Down
7 changes: 2 additions & 5 deletions js/buttons/RectangularRadioButtonGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class RectangularRadioButtonGroup extends LayoutBox {
constructor( property, items, options ) {
options = merge( {

// {function(boolean, Node, Object:options):void} - function for controlling the appearance when toggling enabled.
enabledAppearanceStrategy: SunConstants.componentEnabledListener,
// {number} - opt into Node's disabled opacity when enabled:false
disabledOpacity: SunConstants.DISABLED_OPACITY,

// phet-io
tandem: Tandem.REQUIRED,
Expand Down Expand Up @@ -301,9 +301,6 @@ class RectangularRadioButtonGroup extends LayoutBox {

super( options );

// No need to dispose because enabledProperty is disposed in Node
this.enabledProperty.link( enabled => options.enabledAppearanceStrategy( enabled, this ) );

// pdom - this node's primary sibling is aria-labelledby its own label so the label content is read whenever
// a member of the group receives focus
this.addAriaLabelledbyAssociation( {
Expand Down
11 changes: 6 additions & 5 deletions js/sun-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ import './EnabledComponentTests.js';
import './SliderTests.js';
import SunConstants from './SunConstants.js';

QUnit.test( 'Node.enabledProperty', assert => {

QUnit.module( 'sun' );

QUnit.test( 'enabled/disabled appearance', assert => {

class SunComponentNode extends Node {
constructor( options ) {
options = merge( {
disabledOpacity: SunConstants.DISABLED_OPACITY
}, options );
super( options );

this.enabledProperty.link( enabled => SunConstants.componentEnabledListener( enabled, this, { disabledOpacity: options.disabledOpacity } ) );
}
}

Expand All @@ -37,9 +38,9 @@ QUnit.test( 'Node.enabledProperty', assert => {
disabledOpacity: disabledOpacity
} );

assert.ok( node.opacity === new SunComponentNode().opacity, 'opacity should default to Node default' );
assert.ok( node.effectiveOpacity === new SunComponentNode().opacity, 'opacity should default to Node default' );
node.enabled = false;
assert.ok( node.opacity === disabledOpacity, 'test disabled opacity' );
assert.ok( node.effectiveOpacity === disabledOpacity, 'test disabled opacity' );

node.dispose();

Expand Down

0 comments on commit 5d3249f

Please sign in to comment.