Skip to content

Button ​

Путь подключения: require "ProjectMotionUI/Components/Button"


Класс PMUI.Button ​

Наследуется от: PMUI.BaseElement

Методы и функции ​

PMUI.Button:new(text) ​

Creates a new button element with default appearance and behavior.

ПараметрТипОписание
textstring|nilText displayed inside the button.

Returns: PMUI.Button

PMUI.Button:SetTextures(normalTex, hoverTex, pressedTex) ​

Assigns textures used to render the button in different interaction states. Texture paths are automatically resolved through getTexture().

ПараметрТипОписание
normalTexstring|Texture|nilTexture displayed in the default state.
hoverTexstring|Texture|nilTexture displayed while the mouse is hovering.
pressedTexstring|Texture|nilTexture displayed while the button is pressed.

Returns: PMUI.Button

PMUI.Button:SetText(text) ​

Sets the text displayed inside the button.

ПараметрТипОписание
textstringButton label.

Returns: PMUI.Button

PMUI.Button:SetFont(font) ​

Sets the font used to render the button label.

ПараметрТипОписание
fontUIFontFont assigned to the button.

Returns: PMUI.Button

PMUI.Button:SetColors(normal, hover, pressed) ​

Overrides the button colors for its interaction states. Unspecified colors retain their current values.

ПараметрТипОписание
normaltable|nilColor used in the default state.
hovertable|nilColor used while the mouse is hovering.
pressedtable|nilColor used while the button is pressed.

Returns: PMUI.Button

PMUI.Button:OnClick(callback) ​

Registers a callback executed when the button is clicked. The button instance is passed as the callback argument.

ПараметрТипОписание
callbackfunction|nilFunction invoked after a successful click.

Returns: PMUI.Button

PMUI.Button:onMouseDown(x, y) ​

Handles the initial mouse press and activates the pressed visual state.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

Returns: boolean Whether the mouse event was handled.

PMUI.Button:onMouseUp(x, y) ​

Handles mouse release and executes the click callback if released over the button. Plays the configured click sound before invoking the callback.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

Returns: boolean Whether the mouse event was handled.

PMUI.Button:onMouseUpOutside(x, y) ​

Resets the pressed state when the mouse button is released outside the element.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

PMUI.Button:prerender() ​

Renders the button background and label before the element's main render pass. Selects the appropriate texture or color based on the current interaction state. Textures take priority over solid-color backgrounds.