import { Container, NineSliceSprite, ObservablePoint } from 'pixi.js'; import { ButtonContainer } from './Button'; import { AnyText, PixiText } from './utils/helpers/text'; import { type GetViewSettings } from './utils/helpers/view'; import type { Optional, Size } from 'pixi.js'; type State = 'default' | 'hover' | 'pressed' | 'disabled'; type Pos = { x?: number; y?: number; }; type PosList = { [K in State]?: Pos; }; export type Offset = Pos & PosList; type ButtonViewType = 'defaultView' | 'hoverView' | 'pressedView' | 'disabledView'; type BasicButtonViews = { [K in ButtonViewType]?: Container | NineSliceSprite; }; type ButtonViews = BasicButtonViews & { textView?: PixiText; iconView?: Container; }; type AnimationData = { x?: number; y?: number; width?: number; height?: number; scale?: Pos; }; type Animation = { props: AnimationData; duration?: number; }; type StateAnimations = { [K in State]?: Animation; }; type BasicViewsInput = { [K in ButtonViewType]?: GetViewSettings; }; type ViewsInput = BasicViewsInput & { text?: AnyText; icon?: GetViewSettings; }; export type ContentFittingMode = 'default' | 'fill' | 'none'; export type ButtonOptions = ViewsInput & { padding?: number; scale?: number; anchor?: number; anchorX?: number; anchorY?: number; offset?: Offset; textOffset?: Offset; iconOffset?: Offset; defaultTextScale?: Pos | number; defaultIconScale?: Pos | number; defaultTextAnchor?: Pos | number; defaultIconAnchor?: Pos | number; animations?: StateAnimations; nineSliceSprite?: [number, number, number, number]; contentFittingMode?: ContentFittingMode; /** @deprecated refer to contentFittingMode instead */ ignoreRefitting?: boolean; }; /** * Button component with a lot of tweaks. * * All views, text, icon and animations are optional. You can set them via constructor or update later. * * By default text view and icon view are centered in the active view. * * Offset property of the constructor can be used to adjust the position of the text, icon and the views. * @example * const button = new FancyButton({ * defaultView: `button.png`, * hoverView: `button_hover.png`, * pressedView: `button_pressed.png`, * text: 'Click me!', * animations: { * hover: { * props: { * scale: { * x: 1.1, * y: 1.1, * } * }, * duration: 100, * }, * pressed: { * props: { * scale: { * x: 0.9, * y: 0.9, * } * }, * duration: 100, * } * } * }); * * button.onPress.connect(() => console.log('Button pressed!')); */ export declare class FancyButton extends ButtonContainer { protected animations: StateAnimations; protected originalInnerViewState: AnimationData; protected defaultDuration: number; /** FancyButton options. */ protected readonly options: ButtonOptions; /** Padding of the button text view. If button text does not fit active view + padding it will scale down to fit. */ _padding: number; /** Offset of the button state views. If state views have different sizes, this option can help adjust them. */ _offset: Offset & Pos; /** Offset of the text view. Can be set to any state of the button. */ _textOffset: Offset; /** Offset of the icon view. Can be set to any state of the button. */ iconOffset: Offset; innerView: Container; protected _views: ButtonViews; /** State of the button. Possible valuers are: 'default', 'hover', 'pressed', 'disabled' */ state: State; /** Anchor point of the button. */ anchor: ObservablePoint; /** Base text scaling to take into account when fitting inside the button */ protected _defaultTextScale: Pos; /** Base icon scaling to take into account when fitting inside the button */ protected _defaultIconScale: Pos; /** Base text anchor to take into account when fitting and placing inside the button */ protected _defaultTextAnchor: Pos; /** Base icon anchor to take into account when fitting and placing inside the button */ protected _defaultIconAnchor: Pos; /** * Creates a button with a lot of tweaks. * @param {object} options - Button options. * @param { string | Texture | Container | Sprite | Graphics } options.defaultView - Container-based view that is shown when non of the button events are active. *
Can be a string (name of texture) or an instance of Texture, Container, Sprite or Graphics. *
If you want to use NineSliceSprite, you have to pass a text (name of texture) or an instance of Texture as a parameter here. * @param { string | Texture | Container | Sprite | Graphics } options.hoverView - Container-based view that is shown when the mouse hovers over the button. *
Can be a string (name of texture) or an instance of Texture, Container, Sprite or Graphics. *
If you want to use NineSliceSprite, you have to pass a text (name of texture) or an instance of Texture as a parameter here. * @param { string | Texture | Container | Sprite | Graphics } options.pressedView - Container-based view, shown when the mouse press on the component. *
Can be a string (name of texture) or an instance of Texture, Container, Sprite or Graphics. *
If you want to use NineSliceSprite, you have to pass a text (name of texture) or an instance of Texture as a parameter here. * @param { string | Texture | Container | Sprite | Graphics } options.disabledView - Container-based view shown when the button is disabled. *
Can be a string (name of texture) or an instance of Texture, Container, Sprite or Graphics. *
If you want to use NineSliceSprite, you have to pass a text (name of texture) or an instance of Texture as a parameter here. * @param { string | Texture | Container | Sprite | Graphics } options.icon - Container-based view for the button icon. * @param {Text} options.text - Text-based view for the button text. * @param {number} options.padding - Padding of the button text and icon views. * If button text or icon does not fit active view + padding it will scale down to fit. * @param {Point} options.offset - Offset of the button state views. * @param {Point} options.textOffset - Offset of the text view. * @param {Point} options.iconOffset - Offset of the icon view. * @param {number} options.scale - Scale of the button. Scale will be applied to a main container, * when all animations scales will be applied to the inner view. * @param {number} options.defaultTextScale - Base text scaling to take into account when fitting inside the button. * @param {number} options.defaultIconScale - Base icon scaling to take into account when fitting inside the button. * @param {number} options.defaultTextAnchor - Base text anchor to take into account when fitting and placing inside the button. * @param {number} options.defaultIconAnchor - Base icon anchor to take into account when fitting and placing inside the button. * @param {number} options.anchor - Anchor point of the button. * @param {number} options.anchorX - Horizontal anchor point of the button. * @param {number} options.anchorY - Vertical anchor point of the button. * @param { Array } options.nineSliceSprite - NineSliceSprite values for views ([number, number, number, number]). *
!!! IMPORTANT: To make it work, you have to pass a views (defaultView, hoverView, pressedView, disabledView) parameters as texture name or texture instance. * @param options.animations - Animations that will be played when the button state changes. */ constructor(options?: ButtonOptions); /** * Updates the text of the button and updates its scaling basing on the new size. * @param {string | number} text */ set text(text: AnyText); /** Returns the text string of the button text element. */ get text(): string | undefined; /** * Setter, that prevents all button events from firing. * @param {boolean} enabled */ set enabled(enabled: boolean); get enabled(): boolean; /** * Updates button state and shows the according views. * * Updates positions and offsets of the views. * * Plays animations if they are set. * @param {State} newState * @param force */ setState(newState: State, force?: boolean): void; /** * * Manage button text view. * @param {string | Text} text - can be a string, Text, BitmapText ot HTMLText (Container-based element). */ protected createTextView(text: AnyText): void; /** * Manages views offsets if it's set. * @param view * @param state * @param offset */ protected setOffset(view: Container, state: State, offset: Offset): void; /** * Returns active view for the state. * @param state */ protected getStateView(state: State): Container | undefined; /** * Adjusts text view position and scale. * @param {State} state */ protected adjustTextView(state: State): void; /** * Adjusts icon view position and scale. * @param {State} state */ protected adjustIconView(state: State): void; /** * Reset views positions according to the button anchor setting. * We have to set the anchor position for each view individually, as each of them * can be a different type of view (container without anchor, sprite with anchor, etc) * we have to reset all anchors to 0,0 and then set the positions manually. */ protected updateAnchor(): void; /** * Sets the fitting mode for the button's content. * @param {ContentFittingMode} mode - fitting mode type. */ set contentFittingMode(mode: ContentFittingMode); /** Returns the fitting mode for the button's content, defaulting to 'default'. */ get contentFittingMode(): ContentFittingMode; /** * Sets the default view of the button. * @param { string | Container } view - string (path to the image) or a Container-based view */ set defaultView(view: GetViewSettings | undefined); /** Returns the default view of the button. */ get defaultView(): Container | undefined; /** * Sets the hover view of the button. * @param { string | Container } view - string (path to the image) or a Container-based view */ set hoverView(view: GetViewSettings | undefined); /** Returns the hover view of the button. */ get hoverView(): Container | undefined; /** Sets the pressed view of the button. */ set pressedView(view: GetViewSettings | undefined); /** Returns the pressed view of the button. */ get pressedView(): Container | undefined; /** Sets the disabled view of the button. */ set disabledView(view: GetViewSettings | undefined); /** Returns the disabled view of the button. */ get disabledView(): Container | undefined; /** * Helper method to update or cleanup button views. * @param { 'defaultView' | 'hoverView' | 'pressedView' | 'disabledView' } viewType - type of the view to update * @param { string | Texture | Container | null } view - new view */ protected updateView(viewType: ButtonViewType, view: GetViewSettings | undefined): void; /** * Removes button view by type * @param {'defaultView' | 'hoverView' | 'pressedView' | 'disabledView'} viewType - type of the view to remove */ removeView(viewType: ButtonViewType | 'textView' | 'iconView'): void; /** * Sets the textView of the button. * @param { string | number | PixiText | Text | BitmapText | HTMLText } textView - string, text or pixi text instance. */ set textView(textView: AnyText | null); /** * Returns the text view of the button. * @returns pixi text instance or undefined. */ get textView(): PixiText | undefined; /** * Sets the iconView of the button. * @param { string | Texture | Container } view - string (path to the image), texture instance or a Container-based view */ set iconView(view: GetViewSettings | undefined); /** Returns the icon view of the button. */ get iconView(): Container | undefined; /** * Starts animation for the current button state if configured. * @param {State} state */ protected playAnimations(state: State): void; protected setOriginalInnerViewState(): void; protected initStateControl(): void; /** * Sets the button padding. * @param {number} padding - padding of the button text and icon views. */ set padding(padding: number); /** Returns the button padding. */ get padding(): number; /** * Sets the button offset. * @param { { x?: number; y?: number } } offset - offset of the button. * Can be set for each state of the button. */ set offset(offset: Offset); /** Returns the button offset. */ get offset(): Offset; /** * Sets the button text offset. * @param { { x?: number; y?: number } } textOffset - offsets of the button text view. * can be set for each state of the button. */ set textOffset(textOffset: Offset); /** Returns the button text offset. */ get textOffset(): Offset; /** * Sets the base scale for the text view to take into account when fitting inside the button. * @param {Pos | number} scale - base scale of the text view. */ set defaultTextScale(scale: Pos | number); /** Returns the text view base scale. */ get defaultTextScale(): Pos; /** * Sets the base scale for the icon view to take into account when fitting inside the button. * @param {Pos | number} scale - base scale of the icon view. */ set defaultIconScale(scale: Pos | number); /** Returns the icon view base scale. */ get defaultIconScale(): Pos; /** * Sets the base anchor for the text view to take into account when fitting and placing inside the button. * @param {Pos | number} anchor - base anchor of the text view. */ set defaultTextAnchor(anchor: Pos | number); /** Returns the text view base anchor. */ get defaultTextAnchor(): Pos; /** * Sets the base anchor for the icon view to take into account when fitting and placing inside the button. * @param {Pos | number} anchor - base anchor of the icon view. */ set defaultIconAnchor(anchor: Pos | number); /** Returns the icon view base anchor. */ get defaultIconAnchor(): Pos; /** * Sets width of a FancyButtons state views. * If nineSliceSprite is set, then width will be set to nineSliceSprites of a views. * If nineSliceSprite is not set, then width will control components width as Container. * @param width - Width value. */ set width(width: number); /** Gets width of a FancyButton. */ get width(): number; /** * Sets height of a FancyButtons state views. * If nineSliceSprite is set, then height will be set to nineSliceSprites of a views. * If nineSliceSprite is not set, then height will control components height as Container. * @param height - Height value. */ set height(height: number); /** Gets height of a FancyButton. */ get height(): number; setSize(value: number | Optional, height?: number): void; } export {}; //# sourceMappingURL=FancyButton.d.ts.map