Skip to content

Commit

Permalink
https://github.com/phetsims/scenery-phet/issues/853
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Jun 18, 2024
1 parent 43a25d2 commit c4f3651
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 9 deletions.
4 changes: 4 additions & 0 deletions js/SceneryPhetStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type StringsType = {
'adjustStringProperty': LocalizedStringProperty;
'sliderStringProperty': LocalizedStringProperty;
'spinnerStringProperty': LocalizedStringProperty;
'heatCoolControlsStringProperty': LocalizedStringProperty;
'maximumHeatStringProperty': LocalizedStringProperty;
'maximumCoolStringProperty': LocalizedStringProperty;
'heatCoolOffStringProperty': LocalizedStringProperty;
'verbSliderPatternStringProperty': LocalizedStringProperty;
'verbInSmallerStepsPatternStringProperty': LocalizedStringProperty;
'verbInLargerStepsPatternStringProperty': LocalizedStringProperty;
Expand Down
2 changes: 2 additions & 0 deletions js/demo/keyboard/KeyboardScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import demoKeyboardHelpSection from './demoKeyboardHelpSection.js';
import demoKeyboardHelpIconFactory from './demoKeyboardHelpIconFactory.js';
import demoFaucetControlsKeyboardHelpSection from './demoFaucetControlsKeyboardHelpSection.js';
import demoSpinnerControlsKeyboardHelpSection from './demoSpinnerControlsKeyboardHelpSection.js';
import demoHeaterCoolerControlsKeyboardHelpSection from './demoHeaterCoolerControlsKeyboardHelpSection.js';

type SelfOptions = EmptySelfOptions;
type KeyboardScreenViewOptions = SelfOptions & PickRequired<DemosScreenViewOptions, 'tandem'>;
Expand All @@ -35,6 +36,7 @@ export default class KeyboardScreenView extends DemosScreenView {
{ label: 'BasicActionsKeyboardHelpSection', createNode: demoBasicActionsKeyboardHelpSection },
{ label: 'ComboBoxKeyboardHelpSection', createNode: demoComboBoxKeyboardHelpSection },
{ label: 'FaucetControlsKeyboardHelpSection', createNode: demoFaucetControlsKeyboardHelpSection },
{ label: 'HeaterCoolerControlsKeyboardHelpSection', createNode: demoHeaterCoolerControlsKeyboardHelpSection },
{ label: 'KeyboardHelpIconFactory', createNode: demoKeyboardHelpIconFactory },
{ label: 'KeyboardHelpSection', createNode: demoKeyboardHelpSection },
{ label: 'KeyNode', createNode: demoKeyNode },
Expand Down
17 changes: 17 additions & 0 deletions js/demo/keyboard/demoHeaterCoolerControlsKeyboardHelpSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024, University of Colorado Boulder

/**
* Demo for HeaterCoolerControlsKeyboardHelpSection.
*
* @author Jesse Greenberg (PhET Interactive Simulations)
*/

import Bounds2 from '../../../../dot/js/Bounds2.js';
import { Node } from '../../../../scenery/js/imports.js';
import HeaterCoolerControlsKeyboardHelpSection from '../../keyboard/help/HeaterCoolerControlsKeyboardHelpSection.js';

export default function demoHeaterCoolerControlsKeyboardHelpSection( layoutBounds: Bounds2 ): Node {
const section = new HeaterCoolerControlsKeyboardHelpSection();
section.center = layoutBounds.center;
return section;
}
42 changes: 42 additions & 0 deletions js/keyboard/help/HeaterCoolerControlsKeyboardHelpSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2024, University of Colorado Boulder

/**
* The keyboard help section that describes how to interact with a HeaterCoolerNode.
*
* @author Jesse Greenberg (PhET Interactive Simulations)
*/

import SliderControlsKeyboardHelpSection, { ArrowKeyIconDisplay, SliderControlsKeyboardHelpSectionOptions } from './SliderControlsKeyboardHelpSection.js';
import sceneryPhet from '../../sceneryPhet.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import KeyboardHelpSectionRow from './KeyboardHelpSectionRow.js';
import NumberKeyNode from '../NumberKeyNode.js';
import SceneryPhetStrings from '../../SceneryPhetStrings.js';

type SelfOptions = EmptySelfOptions;
type ParentOptions = SliderControlsKeyboardHelpSectionOptions;
export type HeaterCoolerControlsKeyboardHelpSectionOptions = SelfOptions & ParentOptions;

export default class HeaterCoolerControlsKeyboardHelpSection extends SliderControlsKeyboardHelpSection {
public constructor( providedOptions?: HeaterCoolerControlsKeyboardHelpSectionOptions ) {

const offIcon = new NumberKeyNode( 0 );
const offStringRow = KeyboardHelpSectionRow.labelWithIcon( SceneryPhetStrings.keyboardHelpDialog.heatCoolOffStringProperty, offIcon );

const options = optionize<HeaterCoolerControlsKeyboardHelpSectionOptions, SelfOptions, ParentOptions>()( {
arrowKeyIconDisplay: ArrowKeyIconDisplay.UP_DOWN,

headingStringProperty: SceneryPhetStrings.keyboardHelpDialog.heatCoolControlsStringProperty,
jumpToMaximumStringProperty: SceneryPhetStrings.keyboardHelpDialog.maximumHeatStringProperty,
jumpToMinimumStringProperty: SceneryPhetStrings.keyboardHelpDialog.maximumCoolStringProperty,

additionalRows: [
offStringRow
]
}, providedOptions );

super( options );
}
}

sceneryPhet.register( 'HeaterCoolerControlsKeyboardHelpSection', HeaterCoolerControlsKeyboardHelpSection );
46 changes: 37 additions & 9 deletions js/keyboard/help/SliderControlsKeyboardHelpSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Tandem from '../../../../tandem/js/Tandem.js';
import assertMutuallyExclusiveOptions from '../../../../phet-core/js/assertMutuallyExclusiveOptions.js';

// Configurations of arrow keys that can be displayed for 'Move between items in a group'
class ArrowKeyIconDisplay extends EnumerationValue {
export class ArrowKeyIconDisplay extends EnumerationValue {
public static readonly UP_DOWN = new ArrowKeyIconDisplay();
public static readonly LEFT_RIGHT = new ArrowKeyIconDisplay();
public static readonly BOTH = new ArrowKeyIconDisplay();
Expand Down Expand Up @@ -56,14 +56,24 @@ type SelfOptions = {
sliderStringProperty?: TReadOnlyProperty<string>;

// Strings for extremities to support shortcuts like "jump to maximum" (renaming "maximum" if desired.
// @deprecated - use jumpToMaximumStringProperty and jumpToMinimumStringProperty instead.
maximumStringProperty?: TReadOnlyProperty<string>;
minimumStringProperty?: TReadOnlyProperty<string>;

// Custom strings for the full 'Jump to Minimum' and 'Jump to Maximum' rows. Mutually exclusive with
// minimumStringProperty and maximumStringProperty.
jumpToMaximumStringProperty?: TReadOnlyProperty<string>;
jumpToMinimumStringProperty?: TReadOnlyProperty<string>;

// Determines whether this keyboard help section will have the "Adjust in Smaller Steps" row.
includeSmallerStepsRow?: boolean;

// Determines whether this keyboard help section will have the "Adjust in Larger Steps" row.
includeLargerStepsRow?: boolean;

// Sometimes a slider has custom key commands. Provide additional rows for those commands and they will be added
// below default slider controls content.
additionalRows?: KeyboardHelpSectionRow[];
};

export type SliderControlsKeyboardHelpSectionOptions = SelfOptions & KeyboardHelpSectionOptions;
Expand All @@ -80,6 +90,12 @@ export default class SliderControlsKeyboardHelpSection extends KeyboardHelpSecti
[ 'verbStringProperty', 'sliderStringProperty' ],
[ 'adjustSliderStringProperty', 'adjustInSmallerStepsStringProperty', 'adjustInLargerStepsStringProperty' ] );

assert && assertMutuallyExclusiveOptions( providedOptions, [ 'maximumStringProperty' ], [ 'jumpToMaximumStringProperty' ] );
assert && assertMutuallyExclusiveOptions( providedOptions, [ 'minimumStringProperty' ], [ 'jumpToMinimumStringProperty' ] );

const ownsMaximumStringProperty = providedOptions && 'maximumStringProperty' in providedOptions;
const ownsMinimumStringProperty = providedOptions && 'minimumStringProperty' in providedOptions;

const options = optionize<SliderControlsKeyboardHelpSectionOptions, SelfOptions, KeyboardHelpSectionOptions>()( {
arrowKeyIconDisplay: ArrowKeyIconDisplay.BOTH,
headingStringProperty: SceneryPhetStrings.keyboardHelpDialog.sliderControlsStringProperty,
Expand All @@ -88,13 +104,16 @@ export default class SliderControlsKeyboardHelpSection extends KeyboardHelpSecti
sliderStringProperty: SceneryPhetStrings.keyboardHelpDialog.sliderStringProperty,
maximumStringProperty: SceneryPhetStrings.keyboardHelpDialog.maximumStringProperty,
minimumStringProperty: SceneryPhetStrings.keyboardHelpDialog.minimumStringProperty,
jumpToMaximumStringProperty: SceneryPhetStrings.keyboardHelpDialog.jumpToMaximumStringProperty,
jumpToMinimumStringProperty: SceneryPhetStrings.keyboardHelpDialog.jumpToMinimumStringProperty,

adjustSliderStringProperty: SceneryPhetStrings.keyboardHelpDialog.adjustSliderStringProperty,
adjustInSmallerStepsStringProperty: SceneryPhetStrings.keyboardHelpDialog.adjustInSmallerStepsStringProperty,
adjustInLargerStepsStringProperty: SceneryPhetStrings.keyboardHelpDialog.adjustInLargerStepsStringProperty,

includeSmallerStepsRow: true,
includeLargerStepsRow: true
includeLargerStepsRow: true,
additionalRows: []
}, providedOptions );

let adjustSliderStringProperty = options.adjustSliderStringProperty;
Expand Down Expand Up @@ -148,12 +167,20 @@ export default class SliderControlsKeyboardHelpSection extends KeyboardHelpSecti
verb: options.verbStringProperty
}, { tandem: Tandem.OPT_OUT } );

const jumpToMinimumStringProperty = new PatternStringProperty( SceneryPhetStrings.keyboardHelpDialog.jumpToMinimumPatternStringProperty, {
minimum: options.minimumStringProperty
}, { tandem: Tandem.OPT_OUT } );
const jumpToMaximumStringProperty = new PatternStringProperty( SceneryPhetStrings.keyboardHelpDialog.jumpToMaximumPatternStringProperty, {
maximum: options.maximumStringProperty
}, { tandem: Tandem.OPT_OUT } );

let jumpToMinimumStringProperty = options.jumpToMinimumStringProperty;
if ( ownsMinimumStringProperty ) {
jumpToMinimumStringProperty = new PatternStringProperty( SceneryPhetStrings.keyboardHelpDialog.jumpToMinimumPatternStringProperty, {
minimum: options.minimumStringProperty
}, { tandem: Tandem.OPT_OUT } );
}

let jumpToMaximumStringProperty = options.jumpToMaximumStringProperty;
if ( ownsMaximumStringProperty ) {
jumpToMaximumStringProperty = new PatternStringProperty( SceneryPhetStrings.keyboardHelpDialog.jumpToMaximumPatternStringProperty, {
maximum: options.maximumStringProperty
}, { tandem: Tandem.OPT_OUT } );
}
const jumpToMinimumDescriptionStringProperty = new PatternStringProperty( SceneryPhetStrings.a11y.keyboardHelpDialog.slider.jumpToMinimumDescriptionPatternStringProperty, {
minimum: options.minimumStringProperty
}, { tandem: Tandem.OPT_OUT } );
Expand Down Expand Up @@ -224,7 +251,8 @@ export default class SliderControlsKeyboardHelpSection extends KeyboardHelpSecti
...( options.includeSmallerStepsRow ? [ adjustSliderInSmallerStepsRow ] : [] ),
...( options.includeLargerStepsRow ? [ adjustInLargerStepsRow ] : [] ),
jumpToMinimumRow,
jumpToMaximumRow
jumpToMaximumRow,
...options.additionalRows
];

super( options.headingStringProperty, content, options );
Expand Down
12 changes: 12 additions & 0 deletions scenery-phet-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@
"keyboardHelpDialog.spinner": {
"value": "spinner"
},
"keyboardHelpDialog.heatCoolControls": {
"value": "Heat/Cool Controls"
},
"keyboardHelpDialog.maximumHeat": {
"value": "Maximum heat"
},
"keyboardHelpDialog.maximumCool": {
"value": "Maximum cool"
},
"keyboardHelpDialog.heatCoolOff": {
"value": "Off"
},
"keyboardHelpDialog.verbSliderPattern": {
"value": "{{verb}} {{slider}}"
},
Expand Down

0 comments on commit c4f3651

Please sign in to comment.