Dxlibrary-dxButton: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(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...")
 
(Blanked the page)
Tag: Blanking
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
__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===
[[Image:DGS_Button.png|thumb|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===
{{OptionalArg}}
*'''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 [[Element/Modern DX Library/Button|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.
<syntaxhighlight lang="lua">
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}}
</syntaxhighlight>

Latest revision as of 03:28, 11 May 2022