GuiSetVisible: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 19: Line 19:
This example creates a gui window and changes its visibility every 2 seconds, infinite times.
This example creates a gui window and changes its visibility every 2 seconds, infinite times.


<syntaxhighlight lang="lua">function changeVisibility ( )
<syntaxhighlight lang="lua">
        -- we check if the gui element is visible
-- Create a GUI window called 'myWindow'
        guiSetVisible (myWindow, not guiGetVisible ( myWindow ) )
myWindow = guiCreateWindow( 0.3, 0.3, 0.5, 0.60, "GUI window title", true )
end
 
-- Set a timer to change the window's visibility every 2 seconds, indefinitely
setTimer( function( )
-- We toggle the visibility here by taking the opposite result of guiGetVisible (false => true, true => false), hence toggling its visibility
guiSetVisible( myWindow, not guiGetVisible( myWindow ) )
end, 2000, 0 )
</syntaxhighlight>
 
This example creates a GUI window with ''yes'' and ''no'' buttons and you can toggle its visibility with the ''x'' key.


--Create a gui window called 'myWindow'
<syntaxhighlight lang="lua">addEventHandler( "onClientResourceStart", resourceRoot,
myWindow = guiCreateWindow ( 0.3, 0.3, 0.5, 0.60, "GUI window title", true )
function( )
--Set a timer to change the window's visibility every 2 seconds, infinite times
newgui.wind[ 1 ] = guiCreateWindow( 434, 304, 280, 123, "New Window", false )
setTimer ( changeVisibility, 2000, 0 )</syntaxhighlight>
guiWindowSetSizable( newgui.wind[ 1 ], false )


This example creates a gui window with yes and no buttons and make it visible/invisible with the bindkey 'x'.
newgui.button[ 1 ] = guiCreateButton( 35, 46, 87, 40, "yes", false, newgui.wind[ 1 ] )
<section name="Client" class="client" show="true">
newgui.button[ 2 ] = guiCreateButton( 166, 49, 92, 37, "no", false, newgui.wind[ 1 ] )
<syntaxhighlight lang="lua">
newgui = { button = {}, wind= {} }


addEventHandler("onClientResourceStart", resourceRoot,
showCursor( true )
   
end
function()
)
newgui.wind[1] = guiCreateWindow(434, 304, 280, 123, "New Window", false)
guiWindowSetSizable(newgui.wind[1], false)
newgui.button[1] = guiCreateButton(35, 46, 87, 40, "yes", false, newgui.wind[1])
newgui.button[2] = guiCreateButton(166, 49, 92, 37, "no", false, newgui.wind[1])   
    end)


bindKey ( "x", "down", function ( )
bindKey( "x", "down",
        local state = ( not guiGetVisible ( newgui.wind[1] ) )
function( )
        guiSetVisible ( newgui.wind[1], state )
local state = not guiGetVisible( newgui.wind[ 1 ] )
        showCursor ( state )
guiSetVisible( newgui.wind[ 1 ], state )
    end
showCursor( state )
)</syntaxhighlight></section>
end
)</syntaxhighlight>


==See Also==
==See Also==
{{GUI_functions}}
{{GUI_functions}}

Revision as of 18:54, 7 April 2018

This function changes the visibility state of a GUI element.

Syntax

bool guiSetVisible ( element guiElement, bool state )

OOP Syntax Help! I don't understand this!

Counterpart: guiGetVisible


Required Arguments

  • guiElement: the GUI element whose visibility is to be changed
  • state: the new visibility state

Returns

Returns true if the element's visibility could be changed, false otherwise.

Example

This example creates a gui window and changes its visibility every 2 seconds, infinite times.

-- Create a GUI window called 'myWindow'
myWindow = guiCreateWindow( 0.3, 0.3, 0.5, 0.60, "GUI window title", true )

-- Set a timer to change the window's visibility every 2 seconds, indefinitely
setTimer( function( )
	-- We toggle the visibility here by taking the opposite result of guiGetVisible (false => true, true => false), hence toggling its visibility
	guiSetVisible( myWindow, not guiGetVisible( myWindow ) )
end, 2000, 0 )

This example creates a GUI window with yes and no buttons and you can toggle its visibility with the x key.

addEventHandler( "onClientResourceStart", resourceRoot,
	function( )
		newgui.wind[ 1 ] = guiCreateWindow( 434, 304, 280, 123, "New Window", false )
		guiWindowSetSizable( newgui.wind[ 1 ], false )

		newgui.button[ 1 ] = guiCreateButton( 35, 46, 87, 40, "yes", false, newgui.wind[ 1 ] )
		newgui.button[ 2 ] = guiCreateButton( 166, 49, 92, 37, "no", false, newgui.wind[ 1 ] )

		showCursor( true )
	end
)

bindKey( "x", "down",
	function( )
		local state = not guiGetVisible( newgui.wind[ 1 ] )
		guiSetVisible( newgui.wind[ 1 ], state )
		showCursor( state )
	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