From b1f6c8162a1909437bc13b4d9a32c4ae81ae760b Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Tue, 10 Dec 2024 15:56:08 -0700 Subject: [PATCH] PhET-iO instrumentation for preferences controls related to speech synthesis, https://github.com/phetsims/number-pairs/issues/22 --- js/common/view/AutoHearControl.ts | 28 ++++++++++++++++------- js/common/view/LanguageAndVoiceControl.ts | 7 ++++-- js/common/view/SecondLanguageControl.ts | 15 ++++++++---- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/js/common/view/AutoHearControl.ts b/js/common/view/AutoHearControl.ts index 290ca06..dbc980e 100644 --- a/js/common/view/AutoHearControl.ts +++ b/js/common/view/AutoHearControl.ts @@ -15,19 +15,25 @@ import PreferencesControl from '../../../../joist/js/preferences/PreferencesCont import PreferencesDialog from '../../../../joist/js/preferences/PreferencesDialog.js'; import PreferencesDialogConstants from '../../../../joist/js/preferences/PreferencesDialogConstants.js'; import PhetFont from '../../../../scenery-phet/js/PhetFont.js'; -import { Color, Node, Path, Text, TextOptions, VBox } from '../../../../scenery/js/imports.js'; +import { Color, Node, NodeOptions, Path, Text, TextOptions, VBox } from '../../../../scenery/js/imports.js'; import exclamationTriangleSolidShape from '../../../../sherpa/js/fontawesome-5/exclamationTriangleSolidShape.js'; -import ToggleSwitch from '../../../../sun/js/ToggleSwitch.js'; +import ToggleSwitch, { ToggleSwitchOptions } from '../../../../sun/js/ToggleSwitch.js'; import numberSuiteCommon from '../../numberSuiteCommon.js'; import NumberSuiteCommonStrings from '../../NumberSuiteCommonStrings.js'; import NumberSuiteCommonConstants from '../NumberSuiteCommonConstants.js'; import Property from '../../../../axon/js/Property.js'; +import optionize, { combineOptions, EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; +import Tandem from '../../../../tandem/js/Tandem.js'; const MISSING_VOICE_WARNING_TEXT_OPTIONS: TextOptions = { font: new PhetFont( 14 ), maxWidth: PreferencesDialog.CONTENT_MAX_WIDTH }; +type SelfOptions = EmptySelfOptions; + +type AutoHearControlOptions = SelfOptions & NodeOptions; + export default class AutoHearControl extends Node { public constructor( @@ -35,16 +41,22 @@ export default class AutoHearControl extends Node { hasVoiceProperty: TReadOnlyProperty, labelStringProperty: TReadOnlyProperty, descriptionStringProperty: TReadOnlyProperty, - visible = true + providedOptions?: AutoHearControlOptions ) { - super( { - visible: visible, - isDisposable: false - } ); + const options = optionize()( { + + // NodeOptions + isDisposable: false, + tandem: Tandem.OPT_OUT + }, providedOptions ); + + super( options ); const toggleSwitch = new ToggleSwitch( autoHearEnabledProperty, false, true, - PreferencesDialogConstants.TOGGLE_SWITCH_OPTIONS ); + combineOptions( {}, PreferencesDialogConstants.TOGGLE_SWITCH_OPTIONS, { + tandem: options.tandem.createTandem( 'toggleSwitch' ) + } ) ); const control = new PreferencesControl( { labelNode: new Text( labelStringProperty, PreferencesDialogConstants.CONTROL_LABEL_OPTIONS ), diff --git a/js/common/view/LanguageAndVoiceControl.ts b/js/common/view/LanguageAndVoiceControl.ts index 71f23ff..041552e 100644 --- a/js/common/view/LanguageAndVoiceControl.ts +++ b/js/common/view/LanguageAndVoiceControl.ts @@ -18,6 +18,7 @@ import PhetFont from '../../../../scenery-phet/js/PhetFont.js'; import { Color, HBox, HBoxOptions, ManualConstraint, Node, RichText, RichTextOptions, Text, TextOptions, VBox } from '../../../../scenery/js/imports.js'; import Carousel, { CarouselItem, CarouselOptions } from '../../../../sun/js/Carousel.js'; import PageControl from '../../../../sun/js/PageControl.js'; +import Tandem from '../../../../tandem/js/Tandem.js'; import numberSuiteCommon from '../../numberSuiteCommon.js'; import NumberSuiteCommonStrings from '../../NumberSuiteCommonStrings.js'; import CarouselItemNode from './CarouselItemNode.js'; @@ -31,7 +32,8 @@ const CAROUSEL_OPTIONS: CarouselOptions = { itemsPerPage: 10, spacing: 6, margin: 5, - orientation: 'vertical' + orientation: 'vertical', + tandem: Tandem.OPT_OUT }; const LABEL_Y_SPACING = 10; @@ -110,7 +112,8 @@ export default class LanguageAndVoiceControl extends HBox { dotMouseAreaDilation: 5, // Hide pageControl if there's only one page. - visibleProperty: new DerivedProperty( [ languageCarousel.numberOfPagesProperty ], numberOfPages => numberOfPages > 1 ) + visibleProperty: new DerivedProperty( [ languageCarousel.numberOfPagesProperty ], numberOfPages => numberOfPages > 1 ), + tandem: Tandem.OPT_OUT } ); const voiceControlVBox = new VBox( { diff --git a/js/common/view/SecondLanguageControl.ts b/js/common/view/SecondLanguageControl.ts index 173fdd2..1f6e891 100644 --- a/js/common/view/SecondLanguageControl.ts +++ b/js/common/view/SecondLanguageControl.ts @@ -13,17 +13,18 @@ import localeProperty, { LocaleProperty } from '../../../../joist/js/i18n/locale import PreferencesControl from '../../../../joist/js/preferences/PreferencesControl.js'; import PreferencesDialog from '../../../../joist/js/preferences/PreferencesDialog.js'; import PreferencesDialogConstants from '../../../../joist/js/preferences/PreferencesDialogConstants.js'; -import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; +import optionize, { combineOptions, EmptySelfOptions } from '../../../../phet-core/js/optionize.js'; import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js'; import PhetFont from '../../../../scenery-phet/js/PhetFont.js'; import { allowLinksProperty, RichText, Text, VBox, VBoxOptions } from '../../../../scenery/js/imports.js'; -import ToggleSwitch from '../../../../sun/js/ToggleSwitch.js'; +import ToggleSwitch, { ToggleSwitchOptions } from '../../../../sun/js/ToggleSwitch.js'; import numberSuiteCommon from '../../numberSuiteCommon.js'; import NumberSuiteCommonStrings from '../../NumberSuiteCommonStrings.js'; import NumberSuiteCommonConstants from '../NumberSuiteCommonConstants.js'; import LanguageAndVoiceControl from './LanguageAndVoiceControl.js'; import NumberSuiteCommonUtteranceQueue from './NumberSuiteCommonUtteranceQueue.js'; import Property from '../../../../axon/js/Property.js'; +import Tandem from '../../../../tandem/js/Tandem.js'; type SelfOptions = EmptySelfOptions; type SecondLanguageControlOptions = SelfOptions & StrictOmit; @@ -44,7 +45,8 @@ export default class SecondLanguageControl extends VBox { isDisposable: false, excludeInvisibleChildrenFromBounds: false, align: 'left', - spacing: NumberSuiteCommonConstants.PREFERENCES_VBOX_SPACING + spacing: NumberSuiteCommonConstants.PREFERENCES_VBOX_SPACING, + tandem: Tandem.OPT_OUT }, providedOptions ); const labelText = new Text( NumberSuiteCommonStrings.secondLanguageStringProperty, @@ -54,7 +56,9 @@ export default class SecondLanguageControl extends VBox { PreferencesDialogConstants.CONTROL_DESCRIPTION_OPTIONS ); const toggleSwitch = new ToggleSwitch( secondLocaleEnabledProperty, false, true, - PreferencesDialogConstants.TOGGLE_SWITCH_OPTIONS ); + combineOptions( {}, PreferencesDialogConstants.TOGGLE_SWITCH_OPTIONS, { + tandem: options.tandem.createTandem( 'toggleSwitch' ) + } ) ); // Control for showing or hiding the languageAndVoiceControl const preferencesControl = new PreferencesControl( { @@ -70,7 +74,8 @@ export default class SecondLanguageControl extends VBox { // Control for choosing a second language and associated voice const languageAndVoiceControl = new LanguageAndVoiceControl( secondLocaleProperty, secondVoiceProperty, utteranceQueue, { - visibleProperty: secondLocaleEnabledProperty + visibleProperty: secondLocaleEnabledProperty, + tandem: Tandem.OPT_OUT } ); options.children = [