Astrath:createWindow

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

DxWindow:new

Template:FuncDef

Description: Creates a new DX-based window element. The window can contain child DX elements, supports customization of colors, fonts, header, and can be attached to a parent element. Each window instance is automatically registered in the DX library for rendering and management.

Parameters:

  • title (string) – The title text displayed on the window. Defaults to "New window" if not provided.
  • posX (float) – X position on screen.
  • posY (float) – Y position on screen.
  • width (float) – Width of the window.
  • height (float) – Height of the window.
  • color (table / tocolor) – Main background color in RGBA. Optional.
  • parent (element) – Parent DX element to attach this window to. Optional.
  • relative (boolean) – If true, position will be calculated relative to parent. Optional.
  • header (boolean) – If true, the window will display a header. Optional.
  • headerSize (float) – Relative size of the header. Defaults to 5% of height.
  • headerColor (table / tocolor) – Header color in RGBA. Defaults to tocolor(91, 57, 219, 255).
  • font (string) – Font used for title text. Defaults to "default-bold".
  • fontsize (float) – Font size multiplier. Defaults to 1.

Returns:

Returns the newly created DX window element (DxWindow instance).

Methods:

  • `:destroy()` – Destroys the window and all its child elements.
  • `:setTitle(title)` – Sets a new title for the window.
  • `:setMovable(boolean)` – Enables or disables window movement.
  • `:setVisible(boolean)` – Shows or hides the window.
  • `:setEnabled(boolean)` – Enables or disables the window for interaction.
  • `:setHoverable(boolean)` – Enables or disables hover effect.
  • `:setColor(r, g, b, a, type)` – Sets the main or hover color of the window.
  • `:draw()` – Draws the window using the assigned style.

Example:

-- Create a window at position 200x200 with size 300x200
local myWindow = DxWindow:new(
    "My Window", 200, 200, 300, 200, tocolor(50, 50, 50, 255), nil, false, true, 0.05, nil, "default-bold", 1
)

-- Show window and enable hover
myWindow:setVisible(true)
myWindow:setHoverable(true)

See also: