Astrath:createWindow: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
= DxWindow:new=
{{Client function}}
{{Client function}}
{{FuncDef|element Astrath:createWindow ( float x, float y, float width, float height, string title )}}
{{FuncDef|element DxWindow:new ( string title, float posX, float posY, float width, float height, table color, element parent, boolean relative, boolean header, float headerSize, table headerColor, string font, float fontsize )}}


'''Description:'''
'''Description:'''
Creates a new DX-based window element. The window can then be shown, hidden, or manipulated using other Astrath functions.
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:'''
'''Parameters:'''
* x (float) – The X position of the window on the screen
* title (string) – The title text displayed on the window. Defaults to "New window" if not provided.
* y (float) – The Y position of the window on the screen
* posX (float) – X position on screen.
* width (float) – Width of the window
* posY (float) – Y position on screen.
* height (float) – Height of the window
* width (float) – Width of the window.
* title (string) – Title displayed in 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:'''
: Returns an element representing the window.
: Returns the newly created DX window element (DxWindow instance).
 
== Methods ==
{| class="wikitable" style="width:100%; border:none;"
! Method !! Description
|-
| Ath:destroy() || Destroys the window and all its child elements.
|-
| Ath:setTitle(title) || Sets a new title for the window.
|-
| Ath:setMovable(boolean) || Enables or disables window movement.
|-
| Ath:setVisible(boolean) || Shows or hides the window.
|-
| Ath:setEnabled(boolean) || Enables or disables window for interaction.
|-
| Ath:setHoverable(boolean) || Enables or disables hover effect.
|-
| Ath:setColor(r, g, b, a, type) || Sets the main or hover color of the window.
|}


'''Example:'''
'''Example:'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local win = Astrath:createWindow(200, 200, 300, 200, "Example Window")
-- Create a window at position 200x200 with size 300x200
Astrath:show(win, true)
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)
</syntaxhighlight>
</syntaxhighlight>


'''See also:'''
'''See also:'''
* [[Astrath:drawImage]]
* [[DxButton:new]] – For creating buttons inside windows
* [[Astrath:animateText]]
* [[DxLabel:new]] – For adding text labels
* [[onClientRender]] – Event used to draw DX elements
* [[Astrath]] – Main library page

Latest revision as of 19:23, 22 October 2025

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

Method Description
Ath:destroy() Destroys the window and all its child elements.
Ath:setTitle(title) Sets a new title for the window.
Ath:setMovable(boolean) Enables or disables window movement.
Ath:setVisible(boolean) Shows or hides the window.
Ath:setEnabled(boolean) Enables or disables window for interaction.
Ath:setHoverable(boolean) Enables or disables hover effect.
Ath:setColor(r, g, b, a, type) Sets the main or hover color of the window.

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: