UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

166 lines 5.62 kB
import Texture from "../textures/Texture"; import TextFormat from "../text/TextFormat"; import MeshStyle from "../styles/MeshStyle"; import Sprite from "./Sprite"; import DisplayObjectContainer from "./DisplayObjectContainer"; import DisplayObject from "./DisplayObject"; import Rectangle from "openfl/geom/Rectangle"; import Point from "openfl/geom/Point"; declare namespace starling.display { /** * Dispatched when the user triggers the button. Bubbles. */ export class Button extends DisplayObjectContainer { /** * Creates a button with a set of state-textures and (optionally) some text. * * Any state that is left 'null' will display the up-state texture. Beware that all * * state textures should have the same dimensions. */ constructor(upState: Texture, text?: string, downState?: Texture, overState?: Texture, disabledState?: Texture); /** * @inheritDoc */ override dispose(): void; /** * @private */ override hitTest(localPoint: Point): DisplayObject; /** * Readjusts the dimensions of the button according to its current state texture. * * Call this method to synchronize button and texture size after assigning a texture * * with a different size. Per default, this method also resets the bounds of the * * button's text. */ readjustSize(resetTextBounds?: boolean): void; /** * The current state of the button. The corresponding strings are found * * in the ButtonState class. */ get state(): string; set state(value: string) /** * The scale factor of the button on touch. Per default, a button without a down state * * texture will be made slightly smaller, while a button with a down state texture * * remains unscaled. */ get scaleWhenDown(): number; set scaleWhenDown(value: number) /** * The scale factor of the button while the mouse cursor hovers over it. @default 1.0 */ get scaleWhenOver(): number; set scaleWhenOver(value: number) /** * The alpha value of the button on touch. @default 1.0 */ get alphaWhenDown(): number; set alphaWhenDown(value: number) /** * The alpha value of the button when it is disabled. @default 0.5 */ get alphaWhenDisabled(): number; set alphaWhenDisabled(value: number) /** * Indicates if the button can be triggered. */ get enabled(): boolean; set enabled(value: boolean) /** * The text that is displayed on the button. */ get text(): string; set text(value: string) /** * The format of the button's TextField. */ get textFormat(): TextFormat; set textFormat(value: TextFormat) /** * The style that is used to render the button's TextField. */ get textStyle(): MeshStyle; set textStyle(value: MeshStyle) /** * The style that is used to render the button. * * Note that a style instance may only be used on one mesh at a time. */ get style(): MeshStyle; set style(value: MeshStyle) /** * The texture that is displayed when the button is not being touched. */ get upState(): Texture; set upState(value: Texture) /** * The texture that is displayed while the button is touched. */ get downState(): Texture; set downState(value: Texture) /** * The texture that is displayed while mouse hovers over the button. */ get overState(): Texture; set overState(value: Texture) /** * The texture that is displayed when the button is disabled. */ get disabledState(): Texture; set disabledState(value: Texture) /** * The bounds of the textfield on the button. Allows moving the text to a custom position. */ get textBounds(): Rectangle; set textBounds(value: Rectangle) /** * The color of the button's state image. Just like every image object, each pixel's * * color is multiplied with this value. @default white */ get color(): number; set color(value: number) /** * The smoothing type used for the button's state image. */ get textureSmoothing(): string; set textureSmoothing(value: string) /** * The overlay sprite is displayed on top of the button contents. It scales with the * * button when pressed. Use it to add additional objects to the button (e.g. an icon). */ get overlay(): Sprite; /** * Controls whether or not the instance snaps to the nearest pixel. This can prevent the * * object from looking blurry when it's not exactly aligned with the pixels of the screen. * * @default true */ get pixelSnapping(): boolean; set pixelSnapping(value: boolean) /** * The current scaling grid used for the button's state image. Use this property to create * * buttons that resize in a smart way, i.e. with the four corners keeping the same size * * and only stretching the center area. * * * * @see Image#scale9Grid * * @default null * */ get scale9Grid(): Rectangle; set scale9Grid(value: Rectangle) /** * The button's hit area will be extended to have at least this width / height. * * @default on Desktop: 16, on mobile: 44 */ get minHitAreaSize(): number; set minHitAreaSize(value: number) get_minHitAreaSize(): number; set_minHitAreaSize(value: number): number; /** * The distance you can move away your finger before triggering is aborted. * * @default 50 */ get abortDistance(): number; set abortDistance(value: number) get_abortDistance(): number; set_abortDistance(value: number): number; } } export default starling.display.Button;