OnClientGUIBlur: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client event}} __NOTOC__ This event is triggered each time a GUI element looses input focus (mainly useful for windows, editboxes and memos but triggered for all GUI elements ...")
 
m (formatting)
 
(3 intermediate revisions by 3 users not shown)
Line 2: Line 2:
__NOTOC__  
__NOTOC__  
This event is triggered each time a GUI element looses input focus (mainly useful for windows, editboxes and memos but triggered for all GUI elements nevertheless).
This event is triggered each time a GUI element looses input focus (mainly useful for windows, editboxes and memos but triggered for all GUI elements nevertheless).
{{Note|When the focus is transfered from one GUI element to an other, it is guaranteed that ''onClientGUIBlur'' on the element that lost focus is triggered before [[onClientGUIFocus]] on the element that just gained focus}}
{{Note|When the focus of a full window is lost (transfered to an other window or lost), ''onClientGUIBlur'' is only triggered for the window itself even if one of its widgets had focus too. It's important in this case to use the 4th parameter of [[addEventHandler]] if you are only registered for the events of a child widget (cf. Example)}}
{{Note|When a window is hidden with [[guiSetVisible]], it (or its child widget having focus) keeps focus internally until an other window gains focus or the chatbox is used}}


==Parameters==  
==Parameters==  
''None''
No parameters.


==Source==
==Source==
Line 41: Line 47:
end
end
</syntaxhighlight>
</syntaxhighlight>
==Notes==
*When the focus is transfered from one GUI element to an other, it is guaranteed that ''onClientGUIBlur'' on the element that lost focus is triggered before ''onClientGUIFocus'' on the element that just gained focus
*When the focus of a full window is lost (transfered to an other window or lost), ''onClientGUIBlur'' is only triggered for the window itself even if one of its widgets had focus too. It's important in this case to use the 4th parameter of [[addEventHandler]] if you are only registered for the events of a child widget (cf. Example)
*When a window is hidden with [[guiSetVisible]], it (or its child widget having focus) keeps focus internally until an other window gains focus or the chatbox is used


==See Also==
==See Also==
===GUI events===
{{GUI_events}}
{{GUI_events}}
===Client event functions===
===Client event functions===
{{Client_event_functions}}
{{Client_event_functions}}

Latest revision as of 17:46, 1 June 2025

This event is triggered each time a GUI element looses input focus (mainly useful for windows, editboxes and memos but triggered for all GUI elements nevertheless).


[[{{{image}}}|link=|]] Note: When the focus is transfered from one GUI element to an other, it is guaranteed that onClientGUIBlur on the element that lost focus is triggered before onClientGUIFocus on the element that just gained focus
[[{{{image}}}|link=|]] Note: When the focus of a full window is lost (transfered to an other window or lost), onClientGUIBlur is only triggered for the window itself even if one of its widgets had focus too. It's important in this case to use the 4th parameter of addEventHandler if you are only registered for the events of a child widget (cf. Example)
[[{{{image}}}|link=|]] Note: When a window is hidden with guiSetVisible, it (or its child widget having focus) keeps focus internally until an other window gains focus or the chatbox is used


Parameters

No parameters.

Source

The source of this event is the GUI element which just lost input focus.

Example

local window, editbox = nil, nil
addCommandHandler("example",
function()
	local screenWidth, screenHeight = guiGetScreenSize()
	local windowWidth, windowHeight = 263, 90
	local left = screenWidth/2 - windowWidth/2
	local top = screenHeight/2 - windowHeight/2
	window = guiCreateWindow(left, top, windowWidth, windowHeight, "Example Window", false)		
	editbox = guiCreateEdit(11, 41, 241, 22, "", false, window)
	addEventHandler("onClientGUIFocus", editbox, onClientGUIFocus_editbox, true) --true because for the example we want propagated events
	addEventHandler("onClientGUIBlur", editbox, onClientGUIBlur_editbox, true) --true because for the example we want propagated events
	showCursor(true)
end)

function onClientGUIFocus_editbox()
	if source == editbox then
		outputChatBox("Example editBox received input focus")
	elseif source == window then
		outputChatBox("Example window received input focus")
	end
end

function onClientGUIBlur_editbox()
	if source == editbox then
		outputChatBox("Example editBox lost input focus")
	elseif source == window then
		outputChatBox("Example window lost input focus")
	end
end

See Also

Input

GUI


Client event functions