Astrath:createButton
Jump to navigation
Jump to search
DxButton:new
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:
- Astrath – Main library page
- DxWindow:new – Page for window element reference
- DxLabel:new – Page for label element reference
- onClientRender – Event used to render DX elements