Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed May 8, 2024
2 parents 7c6aa6c + cce7247 commit 17ce5eb
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 9 deletions.
10 changes: 9 additions & 1 deletion js/HeaterCoolerFront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Dimension2 from '../../dot/js/Dimension2.js';
import Range from '../../dot/js/Range.js';
import { Shape } from '../../kite/js/imports.js';
import optionize, { combineOptions } from '../../phet-core/js/optionize.js';
import { Color, Font, LinearGradient, Node, NodeOptions, Path, TColor, Text } from '../../scenery/js/imports.js';
import { Color, Font, KeyboardListener, LinearGradient, Node, NodeOptions, Path, TColor, Text } from '../../scenery/js/imports.js';
import { SliderOptions } from '../../sun/js/Slider.js';
import VSlider from '../../sun/js/VSlider.js';
import Tandem from '../../tandem/js/Tandem.js';
Expand Down Expand Up @@ -208,6 +208,13 @@ export default class HeaterCoolerFront extends Node {
blur: setSliderToZero
} );

// A shortcut to easily return the value to zero when using the keyboard.
const keyboardListener = new KeyboardListener( {
keys: [ '0' ],
fire: setSliderToZero
} );
this.slider.addInputListener( keyboardListener );

// Create the tick labels.
const labelOptions = {
font: options.labelFont,
Expand Down Expand Up @@ -255,6 +262,7 @@ export default class HeaterCoolerFront extends Node {
this.disposeHeaterCoolerFront = () => {
heatTickText && heatTickText.dispose();
coolTickText && coolTickText.dispose();
keyboardListener.dispose();
};
}

Expand Down
2 changes: 2 additions & 0 deletions js/SceneryPhetStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ type StringsType = {
'keyboardHelpDialog': {
'sliderControlsStringProperty': LocalizedStringProperty;
'adjustSliderStringProperty': LocalizedStringProperty;
'spinnerControlsStringProperty': LocalizedStringProperty;
'adjustInSmallerStepsStringProperty': LocalizedStringProperty;
'adjustInLargerStepsStringProperty': LocalizedStringProperty;
'jumpToMinimumStringProperty': LocalizedStringProperty;
'jumpToMaximumStringProperty': LocalizedStringProperty;
'adjustStringProperty': LocalizedStringProperty;
'sliderStringProperty': LocalizedStringProperty;
'spinnerStringProperty': LocalizedStringProperty;
'verbSliderPatternStringProperty': LocalizedStringProperty;
'verbInSmallerStepsPatternStringProperty': LocalizedStringProperty;
'verbInLargerStepsPatternStringProperty': LocalizedStringProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type SelfOptions<ItemModel> = {
getGroupItemValue: ( itemModel: ItemModel ) => number | null;

// Define the startup value of the mouseSortCue. False by default.
mouseSortCueVisibleAtStart?: boolean;
initialMouseSortCueVisible?: boolean;
} & Pick<PhetioObjectOptions, 'tandem'>;

type ParentOptions = EnabledComponentOptions;
Expand Down Expand Up @@ -135,7 +135,7 @@ export default class GroupSortInteractionModel<ItemModel> extends EnabledCompone
const options = optionize<GroupSortInteractionModelOptions<ItemModel>, SelfOptions<ItemModel>, ParentOptions>()( {
tandem: Tandem.REQUIRED,
phetioEnabledPropertyInstrumented: false,
mouseSortCueVisibleAtStart: false
initialMouseSortCueVisible: false
}, providedOptions );

super( options );
Expand All @@ -161,7 +161,7 @@ export default class GroupSortInteractionModel<ItemModel> extends EnabledCompone
}
} );

this.mouseSortCueVisibleProperty = new Property( options.mouseSortCueVisibleAtStart );
this.mouseSortCueVisibleProperty = new Property( options.initialMouseSortCueVisible );

this.showMouseCueProperty = new BooleanProperty( true, {
tandem: options.tandem.createTandem( 'showMouseCueProperty' ),
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 @@ -17,6 +17,7 @@ import demoKeyNode from './demoKeyNode.js';
import demoKeyboardHelpSection from './demoKeyboardHelpSection.js';
import demoKeyboardHelpIconFactory from './demoKeyboardHelpIconFactory.js';
import demoFaucetControlsKeyboardHelpSection from './demoFaucetControlsKeyboardHelpSection.js';
import demoSpinnerControlsKeyboardHelpSection from './demoSpinnerControlsKeyboardHelpSection.js';

type SelfOptions = EmptySelfOptions;
type KeyboardScreenViewOptions = SelfOptions & PickRequired<DemosScreenViewOptions, 'tandem'>;
Expand All @@ -37,6 +38,7 @@ export default class KeyboardScreenView extends DemosScreenView {
{ label: 'KeyboardHelpIconFactory', createNode: demoKeyboardHelpIconFactory },
{ label: 'KeyboardHelpSection', createNode: demoKeyboardHelpSection },
{ label: 'KeyNode', createNode: demoKeyNode },
{ label: 'SpinnerControlsKeyboardHelpSection', createNode: demoSpinnerControlsKeyboardHelpSection },
{ label: 'SliderControlsKeyboardHelpSection', createNode: demoSliderControlsKeyboardHelpSection }
];

Expand Down
17 changes: 17 additions & 0 deletions js/demo/keyboard/demoSpinnerControlsKeyboardHelpSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2024, University of Colorado Boulder

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

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

export default function demoSpinnerControlsKeyboardHelpSection( layoutBounds: Bounds2 ): Node {
const spinnerSection = new SpinnerControlsKeyboardHelpSection();
spinnerSection.center = layoutBounds.center;
return spinnerSection;
}
19 changes: 14 additions & 5 deletions js/keyboard/help/SliderControlsKeyboardHelpSection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2023, University of Colorado Boulder
// Copyright 2017-2024, University of Colorado Boulder

/**
* Content for a KeyboardHelpDialog that describes how to use sliders.
Expand Down Expand Up @@ -59,9 +59,11 @@ type SelfOptions = {
maximumStringProperty?: TReadOnlyProperty<string>;
minimumStringProperty?: TReadOnlyProperty<string>;

// This option determines whether this keyboard help section will have the
// "Adjust in Smaller Steps" row. The row includes the string and key icons.
// 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;
};

export type SliderControlsKeyboardHelpSectionOptions = SelfOptions & KeyboardHelpSectionOptions;
Expand Down Expand Up @@ -91,7 +93,8 @@ export default class SliderControlsKeyboardHelpSection extends KeyboardHelpSecti
adjustInSmallerStepsStringProperty: SceneryPhetStrings.keyboardHelpDialog.adjustInSmallerStepsStringProperty,
adjustInLargerStepsStringProperty: SceneryPhetStrings.keyboardHelpDialog.adjustInLargerStepsStringProperty,

includeSmallerStepsRow: true
includeSmallerStepsRow: true,
includeLargerStepsRow: true
}, providedOptions );

let adjustSliderStringProperty = options.adjustSliderStringProperty;
Expand Down Expand Up @@ -216,7 +219,13 @@ export default class SliderControlsKeyboardHelpSection extends KeyboardHelpSecti
} );

// assemble final content for KeyboardHelpSection
const content = [ adjustSliderRow, ...( options.includeSmallerStepsRow ? [ adjustSliderInSmallerStepsRow ] : [] ), adjustInLargerStepsRow, jumpToMinimumRow, jumpToMaximumRow ];
const content = [
adjustSliderRow,
...( options.includeSmallerStepsRow ? [ adjustSliderInSmallerStepsRow ] : [] ),
...( options.includeLargerStepsRow ? [ adjustInLargerStepsRow ] : [] ),
jumpToMinimumRow,
jumpToMaximumRow
];

super( options.headingStringProperty, content, options );
}
Expand Down
36 changes: 36 additions & 0 deletions js/keyboard/help/SpinnerControlsKeyboardHelpSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2024, University of Colorado Boulder

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

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

const spinnerControlsStringProperty = SceneryPhetStrings.keyboardHelpDialog.spinnerControlsStringProperty;
const spinnerStringProperty = SceneryPhetStrings.keyboardHelpDialog.spinnerStringProperty;

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

export default class SpinnerControlsKeyboardHelpSection extends SliderControlsKeyboardHelpSection {
public constructor( providedOptions?: SpinnerControlsKeyboardHelpSectionOptions ) {

const options = optionize<SpinnerControlsKeyboardHelpSectionOptions, SelfOptions, ParentOptions>()( {
headingStringProperty: spinnerControlsStringProperty,
sliderStringProperty: spinnerStringProperty,

// PhET 'spinners' usually do not support larger steps with the page up/page down keys.
includeLargerStepsRow: false
}, providedOptions );

super( options );
}
}

sceneryPhet.register( 'SpinnerControlsKeyboardHelpSection', SpinnerControlsKeyboardHelpSection );
6 changes: 6 additions & 0 deletions scenery-phet-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
"keyboardHelpDialog.adjustSlider": {
"value": "Adjust slider"
},
"keyboardHelpDialog.spinnerControls": {
"value": "Spinner Controls"
},
"keyboardHelpDialog.adjustInSmallerSteps": {
"value": "Adjust in smaller steps"
},
Expand All @@ -155,6 +158,9 @@
"keyboardHelpDialog.slider": {
"value": "slider"
},
"keyboardHelpDialog.spinner": {
"value": "spinner"
},
"keyboardHelpDialog.verbSliderPattern": {
"value": "{{verb}} {{slider}}"
},
Expand Down

0 comments on commit 17ce5eb

Please sign in to comment.