@playcanvas/pcui
Version:
User interface component library for the web
125 lines (124 loc) • 4.28 kB
TypeScript
import { Element } from '../Element';
import { InputElement, InputElementArgs } from '../InputElement';
/**
* The arguments for the {@link NumericInput} constructor.
*/
interface NumericInputArgs extends InputElementArgs {
/**
* Sets the minimum value this field can take.
*/
min?: number;
/**
* Sets the maximum value this field can take.
*/
max?: number;
/**
* Sets the decimal precision of this field. Defaults to 2.
*/
precision?: number;
/**
* Sets the amount that the value will be increased or decreased when using the arrow keys and
* the slider input.
*/
step?: number;
/**
* Sets the amount that the value will be increased or decreased when holding shift using the
* arrow keys and the slider input. Defaults to {@link NumericInput#step} * 0.1.
*/
stepPrecision?: number;
/**
* Hide the input mouse drag slider.
*/
hideSlider?: boolean;
/**
* Sets whether the value can be `null`. If not then it will be 0 instead of `null`.
*/
allowNull?: boolean;
}
/**
* The NumericInput represents an input element that holds numbers.
*
* NumericInput accepts `number` values. It also accepts strings that contain mathematical
* expressions which are then evaluated to a number. Here are some examples:
*
* | Input String | Evaluated Number Value |
* | ------------------ | ---------------------- |
* | `"10 + 20"` | `30` |
* | `"10 - 20"` | `-10` |
* | `"10 * 20"` | `200` |
* | `"10 / 20"` | `0.5` |
* | `"10 * (20 + 30)"` | `500` |
*
* By default, a NumericInput displays a slider input that can be used to quickly change the value
* via a click and drag. The slider can be disabled by setting the `hideSlider` argument to `true`.
*/
declare class NumericInput extends InputElement {
protected _min: number;
protected _max: number;
protected _allowNull: boolean;
protected _precision: number;
protected _step: number;
protected _stepPrecision: number;
protected _oldValue: number;
protected _historyCombine: boolean;
protected _historyPostfix: string;
protected _sliderPrevValue: number;
protected _sliderControl: Element;
protected _sliderMovement: number;
protected _sliderUsed: boolean;
/**
* Creates a new NumericInput.
*
* @param args - The arguments.
*/
constructor(args?: Readonly<NumericInputArgs>);
destroy(): void;
protected _updatePosition(movement: number, shiftKey: boolean): void;
protected _onSliderMouseWheel: (evt: WheelEvent) => void;
protected _onSliderMouseMove: (evt: MouseEvent) => void;
protected _onSliderMouseDown: (evt: MouseEvent) => void;
protected _onSliderMouseUp: () => void;
protected _onInputChange(evt: Event): void;
protected _onInputKeyDown(evt: KeyboardEvent): void;
protected _getPointerLockElementByShadowRoot(pointerLockElement: any): boolean;
protected _isScrolling(): boolean;
protected _onPointerLockChange: () => void;
protected _normalizeValue(value: any): any;
protected _updateValue(value: number, force?: boolean): boolean;
set value(value: number);
get value(): number;
set values(values: number[]);
/**
* Sets the minimum value this field can take.
*/
set min(value: number);
/**
* Gets the minimum value this field can take.
*/
get min(): number;
/**
* Sets the maximum value this field can take.
*/
set max(value: number);
/**
* Gets the maximum value this field can take.
*/
get max(): number;
/**
* Sets the precision of the input.
*/
set precision(value: number);
/**
* Gets the precision of the input.
*/
get precision(): number;
/**
* Sets the amount that the value will be increased or decreased when using the arrow keys and the slider input.
*/
set step(value: number);
/**
* Gets the amount that the value will be increased or decreased when using the arrow keys and the slider input.
*/
get step(): number;
}
export { NumericInput, NumericInputArgs };