Astrath:createButton: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "= DxButton:new = {{Client function}} {{FuncDef|element DxButton:new ( string text, float posX, float posY, float width, float height, element parent, boolean relative, table color, string font, float fontsize, string description, boolean isIcon, float iconWidth, float iconHeight )}} '''Description:''' Creates a new DX-based button element. Buttons can be attached to parent elements, support hover effects, custom colors, icons, fonts, and descriptions. Each button insta...")
 
Line 24: Line 24:


'''Methods:'''
'''Methods:'''
* `:destroy()` – Destroys the button and all its child elements.
{| class="wikitable" style="width:100%; border:none;"
* `:setVisible(boolean)` – Shows or hides the button.
! Function !! Description
* `:setEnabled(boolean)` – Enables or disables the button for interaction.
|-
* `:setText(string)` – Sets the button text.
| Ath:destroy() || Destroys the button and all its child elements.
* `:getText()` – Returns the current button text.
|-
* `:setDescription(string)` – Sets the button description.
| Ath:setVisible(boolean) || Shows or hides the button.
* `:setHoverable(boolean)` – Enables or disables hover effect.
|-
* `:setColor(r, g, b, a, type)` – Sets the main or hover color of the button.
| Ath:setEnabled(boolean) || Enables or disables the button for interaction.
* `:draw()` – Draws the button using the assigned style.
|-
| Ath:setText(string) || Sets the button text.
|-
| Ath:getText() || Returns the current button text.
|-
| Ath:setDescription(string) || Sets the button description.
|-
| Ath:setHoverable(boolean) || Enables or disables hover effect.
|-
| Ath:setColor(r, g, b, a, type) || Sets the main or hover color of the button.
|-
| Ath:draw() || Draws the button using the assigned style.
|}


'''Example:'''
'''Example:'''

Revision as of 19:36, 22 October 2025

DxButton:new

Template:FuncDef

Description: Creates a new DX-based button element. Buttons can be attached to parent elements, support hover effects, custom colors, icons, fonts, and descriptions. Each button instance is automatically registered in the DX library.

Parameters:

  • text (string) – The button label text. Defaults to "Button".
  • posX, posY (float) – Position on screen.
  • width, height (float) – Size of the button.
  • parent (element) – Parent DX element to attach this button to (optional).
  • relative (boolean) – Position relative to parent (optional).
  • color (table / tocolor) – Main background color (optional).
  • font (string) – Font used for text (optional, default: "default-bold").
  • fontsize (float) – Font size multiplier (optional, default: 1).
  • description (string) – Optional description text.
  • isIcon (boolean) – If true, the button will display an icon instead of text.
  • iconWidth, iconHeight (float) – Size of the icon relative to the button (optional).

Returns:

Returns the newly created DxButton element.

Methods:

Function Description
Ath:destroy() Destroys the button and all its child elements.
Ath:setVisible(boolean) Shows or hides the button.
Ath:setEnabled(boolean) Enables or disables the button for interaction.
Ath:setText(string) Sets the button text.
Ath:getText() Returns the current button text.
Ath:setDescription(string) Sets the button description.
Ath:setHoverable(boolean) Enables or disables hover effect.
Ath:setColor(r, g, b, a, type) Sets the main or hover color of the button.
Ath:draw() Draws the button using the assigned style.

Example:

-- Create a button at position 200x300 with size 150x50
local myButton = DxButton:new("Click Me", 200, 300, 150, 50)

-- Show the button and enable hover effect
myButton:setVisible(true)
myButton:setHoverable(true)

-- Change text and color
myButton:setText("Press Me")
myButton:setColor(255, 0, 0, 255, "mainColor")

See also: