Astrath:createLabel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "= DxLabel:new = {{Client function}} {{FuncDef|element DxLabel:new ( string text, float posX, float posY, float width, float height, element parent, boolean relative, string font, float fontsize, string horizontalAlign, string verticalAlign )}} '''Description:''' Creates a new DX-based label element. Labels display text, support parent-relative positioning, custom fonts, colors, alignment, and optional hover effects. Each label instance is automatically registered in th...")
 
(No difference)

Latest revision as of 20:12, 22 October 2025

DxLabel:new

Template:FuncDef

Description: Creates a new DX-based label element. Labels display text, support parent-relative positioning, custom fonts, colors, alignment, and optional hover effects. Each label instance is automatically registered in the DX library.

Parameters:

  • text (string) – Text to display in the label.
  • posX, posY (float) – Position on screen.
  • width, height (float) – Size of the label.
  • parent (element) – Parent DX element to attach this label to (optional).
  • relative (boolean) – Position relative to parent (optional).
  • font (string) – Font used for the text (optional, default: "default-bold").
  • fontsize (float) – Font size multiplier (optional, default: 1).
  • horizontalAlign (string) – Horizontal alignment ("left", "center", "right", optional, default: "center").
  • verticalAlign (string) – Vertical alignment ("top", "center", "bottom", optional, default: "center").

Returns:

Returns the newly created DxLabel element.

Methods:

Method Description
Ath:destroy() Destroys the label element and all its child elements.
Ath:setVisible(boolean) Shows or hides the label.
Ath:setEnabled(boolean) Enables or disables the label for interaction.
Ath:setText(string) Sets the label text.
Ath:getText() Returns the current label text.
Ath:setFont(string) Changes the label font.
Ath:setHoverable(boolean) Enables or disables hover effect.
Ath:setColor(r, g, b, a, type) Sets the main or hover text color.
Ath:setHorizontalAlign(string) Sets horizontal alignment of the text.
Ath:setVerticalAlign(string) Sets vertical alignment of the text.

Example:

local myLabel = DxLabel:new("Hello World", 100, 100, 200, 50)

myLabel:setVisible(true)
myLabel:setHoverable(true)
myLabel:setText("Welcome")
myLabel:setColor(255, 200, 0, 255, "mainColor")
myLabel:setHorizontalAlign("center")
myLabel:setVerticalAlign("center")
myLabel:draw()

See also: