Dxlibrary-dxButton

From Multi Theft Auto: Wiki
Revision as of 03:24, 11 May 2022 by PandFort (talk | contribs) (Created page with "__NOTOC__ {{Client function}} This function allows creation of a Modern DX Library Button, which is a clickable item as part of GUI. '''Notice: This is a function exported by Modern DX Library!''' ==Syntax== <syntaxhighlight lang="lua"> element dxButton( float x, float y, float width, float height, string text [, element parent = nil, bool rounded = nil ) </syntaxhighlight> ===Required Arguments=== thumb|DGS Button *'''x:''' A float of the...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function allows creation of a Modern DX Library Button, which is a clickable item as part of GUI.

Notice: This is a function exported by Modern DX Library!

Syntax

element dxButton( float x, float y, float width, float height, string text [, element parent = nil, bool rounded = nil )

Required Arguments

DGS Button
  • x: A float of the 2D x position of the button on a player's screen.
  • y: A float of the 2D y position of the button on a player's screen.
  • width: A float of the width of the button.
  • height: A float of the height of the button.
  • text: A string of the text that will be displayed as a label on the button.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • parent: This is the parent that the Modern DX Library button is attached.
  • rounded: Whether you want the button to be rounded or not. ( true or false )

Returns

Returns an element of the created button if it was successfully created, false otherwise.

Example

This example creates an edit box alongside an "Output!" button. When the button is clicked, it will output the message in the edit box into the Chat Box.

dxLibrary = exports[ "dxLibrary" ]

--create our button
button = dxLibrary:dxButton( 276, 80, 100, 40, "Output!" )

--Create an edit box and define it as "editBox".
editBox = dxLibrary:dxEdit( 277, 184, 197, 46, "Type your message here!" )

-- and attach our button to the outputEditBox function
addEventHandler ( "onClick", editBox, outputEditBox )

--setup our function to output the message to the chatbox
function outputEditBox ()
        local text = dxLibrary:dxGetText( editBox ) --get the text from the edit box
        outputChatBox ( text, 255, 255, 255 ) --output that text
end
addEventHandler ( "onClick", button, outputEditBox )

==See Also==
{{DXLIB_FUNCTIONS}}