GuiGetPosition: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(6 intermediate revisions by 3 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 allows retrieval of a GUI element's current position, relative to its parent.


==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">
float float guiGetPosition ( element guielement )
float, float guiGetPosition ( element guiElement, bool relative )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[GUI widgets|GuiElement]]:getPosition|position|guiSetPosition}}


===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 -->
*'''guiElement:''' The gui element of which you wish to retrieve the position.
*'''argumentName:''' description
*'''relative:''' A boolean representing whether the position should be relative to the element's parent width, or the number of offset pixels from the parent's origin.


<!-- Only include this section below if there are optional arguments -->
===Returns===
===Optional Arguments===  
Returns floats representing the ''x'' and ''y'' position of the element, or false if the position could not be retrieved.
{{OptionalArg}}
*'''argumentName2:''' description
*'''argumentName3:''' description


===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if blah, ''false'' otherwise.
*x
*y
==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example checks which corner a gui element exists in
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...
function positionCheck ( guiElement )
blabhalbalhb --abababa
local x,y = guiGetPosition ( guiElement, true ) --get the position
--This line does this...
local position --define the position
mooo
if ( x == 0.5 ) and ( y == 0.5 ) then --if its bang in the middle
position = "middle" --set position to middle
elseif ( x > 0.5 ) and ( y > 0.5 ) then --if its in the right bottom
position = "right-bottom"
elseif ( x < 0.5 ) and ( y < 0.5 ) then --if its in the left top
position = "left-top"
elseif ( x < 0.5 ) and ( y > 0.5 ) then --if its in the left bottom
position = "left-bottom"
elseif ( x > 0.5 ) and ( y < 0.5 ) then --if its in the right top
position = "right-top"
else --if it couldnt be retrieved
position = "unknown"
end
--announce this into the chatbox
outputChatBox ( "The gui element's position is "..position.."!" )
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}}
{{FunctionArea_functions}}
{{GUI_events}}
[[Category:Need_Syntax]]  -- leave this until syntax is available. Cannot document the function or event without syntax.
[[Category:Incomplete]] -- leave this unless you complete the function

Latest revision as of 17:16, 21 November 2018

This function allows retrieval of a GUI element's current position, relative to its parent.

Syntax

float, float guiGetPosition ( element guiElement, bool relative )

OOP Syntax Help! I don't understand this!

Method: GuiElement:getPosition(...)
Variable: .position
Counterpart: guiSetPosition


Required Arguments

  • guiElement: The gui element of which you wish to retrieve the position.
  • relative: A boolean representing whether the position should be relative to the element's parent width, or the number of offset pixels from the parent's origin.

Returns

Returns floats representing the x and y position of the element, or false if the position could not be retrieved.

Example

This example checks which corner a gui element exists in

function positionCheck ( guiElement )
	local x,y = guiGetPosition ( guiElement, true ) --get the position
	local position --define the position
	if ( x == 0.5 ) and ( y == 0.5 ) then --if its bang in the middle
		position = "middle" --set position to middle
	elseif ( x > 0.5 ) and ( y > 0.5 ) then --if its in the right bottom
		position = "right-bottom" 
	elseif ( x < 0.5 ) and ( y < 0.5 ) then --if its in the left top
		position = "left-top"
	elseif ( x < 0.5 ) and ( y > 0.5 ) then --if its in the left bottom
		position = "left-bottom"
	elseif ( x > 0.5 ) and ( y < 0.5 ) then --if its in the right top
		position = "right-top" 
	else --if it couldnt be retrieved
		position = "unknown"
	end
	--announce this into the chatbox
	outputChatBox ( "The gui element's position is "..position.."!" )
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