Astrath:createButton

From Multi Theft Auto: Wiki
Revision as of 19:33, 22 October 2025 by Sybellex (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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:

  • `:destroy()` – Destroys the button and all its child elements.
  • `:setVisible(boolean)` – Shows or hides the button.
  • `:setEnabled(boolean)` – Enables or disables the button for interaction.
  • `:setText(string)` – Sets the button text.
  • `:getText()` – Returns the current button text.
  • `:setDescription(string)` – Sets the button description.
  • `:setHoverable(boolean)` – Enables or disables hover effect.
  • `:setColor(r, g, b, a, type)` – Sets the main or hover color of the button.
  • `: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: