Skip to content

Keypad

Overview

A flexible keypad that looks somewhat like a calculator or keyboard keypad.

@author Aadish Gupta @author John Blanco

Class Keypad

import { Keypad } from 'scenerystack/scenery-phet';

Constructor

new Keypad( layout : ( Key | null )[][], providedOptions? : KeypadOptions )

Instance Methods

clear()

Calls the clear function for the given accumulator

setClearOnNextKeyPress( clearOnNextKeyPress : boolean )

Determines whether pressing a key (except for backspace) will clear the existing value.

getClearOnNextKeyPress() : boolean

Will pressing a key (except for backspace) clear the existing value?

dispose()

Instance Properties

accumulatedKeysProperty : ReadOnlyProperty<KeyIDValue[]>

(readonly)

array of the keys that have been accumulated

stringProperty : ReadOnlyProperty<string>

(readonly)

string representation of the keys that have been accumulated

valueProperty : ReadOnlyProperty<number | null>

(readonly)

numeric representation of the keys that have been accumulated, null if no keys have been accumulated

Static Properties

PositiveIntegerLayout : KeypadLayout

(readonly)


static keypad layouts - These can be used 'as is' for common layouts or serve as examples for creating custom layouts. If the vertical span is greater than 1, the column in the next row(s) has to be null. If the horizontal span is greater than 1, the next key in that row will not overlap and will be placed in the next space in the grid. If a blank space is desired, null should be provided.


PositiveDecimalLayout : KeypadLayout

(readonly)

PositiveAndNegativeIntegerLayout : KeypadLayout

(readonly)

PositiveFloatingPointLayout : KeypadLayout

(readonly)

PositiveAndNegativeFloatingPointLayout : KeypadLayout

(readonly)

WeirdLayout : KeypadLayout

(readonly)

Weird Layout is created for testing purposes to test the edge cases and layout capabilities

KEY_0

(readonly)

KEY_1

(readonly)

KEY_2

(readonly)

KEY_3

(readonly)

KEY_4

(readonly)

KEY_5

(readonly)

KEY_6

(readonly)

KEY_7

(readonly)

KEY_8

(readonly)

KEY_9

(readonly)

KEY_WIDE_ZERO

(readonly)

KEY_DECIMAL

(readonly)

KEY_BACKSPACE

(readonly)

KEY_PLUS_MINUS

(readonly)

Type KeypadLayout

import type { KeypadLayout } from 'scenerystack/scenery-phet';

( Key | null )[][]

Type KeypadOptions

import type { KeypadOptions } from 'scenerystack/scenery-phet';
  • buttonWidth?: number
  • buttonHeight?: number
  • xSpacing?: number
  • ySpacing?: number
  • touchAreaXDilation?: number
  • touchAreaYDilation?: number
  • buttonColor?: TPaint
  • buttonFont?: Font
  • accumulator?: AbstractKeyAccumulator | null
    Accumulator that collects and interprets key presses, see various implementations for examples. If provided, this will be disposed with this Keypad
  • accumulatorOptions?: NumberAccumulatorOptions | null
    Options passed to NumberAccumulator, ignored if options.accumulator is provided
  • useGlobalKeyboardListener?: boolean
    If true, the KeyboardListener for this KeyPad will be "global" and key presses will control the Keypad regardless of where focus is in the document. Only have one Keypad at a time that can receive global keyboard input (an assertion will be thrown).
  • & NodeOptions

Source Code

See the source for Keypad.ts in the scenery-phet repository.