GuiCreateGridList: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Simplified examples)
(13 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{Client function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function creates a grid list GUI element.  These are menu's which are designed in lists and can have multiple columns.  A good example of a gridlist element can be found in MTA's settings box, under ''Controls''.


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
returnType functionName ( arguments )
element guiCreateGridList ( float x, float y, float width, float height, bool relative, [ element parent = nil ] )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[Element/GUI/Gridlist|GuiGridList]]}}


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
[[Image:Gui-gridlist.png|frame|Example GUI gridlist.]]
*'''X:''' description
*'''x:''' A float of the 2D x position of the GUI gridlist on a player's screen.  This is affected by the ''relative'' argument.
*'''Y:''' description
*'''y:''' A float of the 2D y position of the GUI gridlist on a player's screen. This is affected by the ''relative'' argument.
*'''Z:''' description
*'''width:''' A float of the width of the GUI gridlist. This is affected by the ''relative'' argument.
*'''Width:''' description
*'''height:''' A float of the height of the GUI gridlist. This is affected by the ''relative'' argument.
*'''Height:''' description
*'''relative:''' This is whether sizes and positioning are relative.  If this is ''true'', then all x,y,width,height floats must be between 0 and 1, representing sizes relative to the parent.
*'''Relative:''' description
*'''Parent:''' description
 
<!-- Only include this section below if there are optional arguments -->


===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
*'''argumentName2:''' description
*'''parent:''' This is the parent that the gui gridlist is attached to.  If the ''relative'' argument is true, sizes and positioning will be made relative to this parent. If the ''relative'' argument is false, positioning will be the number of offset pixels from the parent's origin. If no parent is passed, the parent will become the screen - causing positioning and sizing according to screen positioning.
*'''argumentName3:''' description


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns an element of the created gridlist if it was successfully created, false otherwise.
Returns ''true'' if blah, ''false'' otherwise.


==Example==  
==Example==
<!-- Explain what the example is in a single sentance -->
'''Example 1:''' This example creates a player list on the right of the screen with 1 column and fills it
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
local playerList = guiCreateGridList(0.80, 0.40, 0.15, 0.35, true)
blabhalbalhb --abababa
guiGridListAddColumn(playerList, "Player", 0.85)
--This line does this...
 
mooo
for _, player in ipairs(getElementsByType("player")) do
guiGridListAddRow(playerList, getPlayerName(player))
end
</syntaxhighlight>
 
'''Example 2:''' Using [[OOP]] we can write shorter and cleaner code (Requires <oop>true<oop> in the meta file). This creates a player list with 2 columns.
<syntaxhighlight lang="lua">
local list = GuiGridList(0.80, 0.40, 0.15, 0.35, true)
list:addColumn("#", 0.15)
list:addColumn("name", 0.75)
 
for index, player in ipairs(getElementsByType("player")) do
list:addRow(index, player.name)
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{GUI functions}}
{{GUI functions}}
[[Category:Incomplete]]
{{GUI_events}}

Revision as of 21:54, 1 September 2018

This function creates a grid list GUI element. These are menu's which are designed in lists and can have multiple columns. A good example of a gridlist element can be found in MTA's settings box, under Controls.

Syntax

element guiCreateGridList ( float x, float y, float width, float height, bool relative, [ element parent = nil ] )

OOP Syntax Help! I don't understand this!

Method: GuiGridList(...)


Required Arguments

Example GUI gridlist.
  • x: A float of the 2D x position of the GUI gridlist on a player's screen. This is affected by the relative argument.
  • y: A float of the 2D y position of the GUI gridlist on a player's screen. This is affected by the relative argument.
  • width: A float of the width of the GUI gridlist. This is affected by the relative argument.
  • height: A float of the height of the GUI gridlist. This is affected by the relative argument.
  • relative: This is whether sizes and positioning are relative. If this is true, then all x,y,width,height floats must be between 0 and 1, representing sizes relative to the parent.

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 gui gridlist is attached to. If the relative argument is true, sizes and positioning will be made relative to this parent. If the relative argument is false, positioning will be the number of offset pixels from the parent's origin. If no parent is passed, the parent will become the screen - causing positioning and sizing according to screen positioning.

Returns

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

Example

Example 1: This example creates a player list on the right of the screen with 1 column and fills it

local playerList = guiCreateGridList(0.80, 0.40, 0.15, 0.35, true)
guiGridListAddColumn(playerList, "Player", 0.85)

for _, player in ipairs(getElementsByType("player")) do
	guiGridListAddRow(playerList, getPlayerName(player))
end

Example 2: Using OOP we can write shorter and cleaner code (Requires <oop>true<oop> in the meta file). This creates a player list with 2 columns.

local list = GuiGridList(0.80, 0.40, 0.15, 0.35, true)
list:addColumn("#", 0.15)
list:addColumn("name", 0.75)

for index, player in ipairs(getElementsByType("player")) do
	list:addRow(index, player.name)
end

See Also

General functions

Browsers

Buttons

Checkboxes

Comboboxes

Edit Boxes

Gridlists

Memos

Progressbars

Radio Buttons

Scrollbars

Scrollpanes

Static Images

Tab Panels

Tabs

Text Labels

Windows

Input

GUI