OnDgsFocus: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 19: Line 19:
local left = screenWidth/2 - windowWidth/2
local left = screenWidth/2 - windowWidth/2
local top = screenHeight/2 - windowHeight/2
local top = screenHeight/2 - windowHeight/2
window = DGS:dgsDxCreateWindow(left, top, windowWidth, windowHeight, "Example Window", false)
window = DGS:dgsCreateWindow(left, top, windowWidth, windowHeight, "Example Window", false)
editbox = DGS:dgsDxCreateEdit(11, 41, 241, 22, "", false, window)
editbox = DGS:dgsCreateEdit(11, 41, 241, 22, "", false, window)
addEventHandler("onClientDgsDxFocus", editbox, onClientDGSFocus_editbox, true) --true because for the example we want propagated events
addEventHandler("onDgsFocus", editbox, onClientDGSFocus_editbox, true) --true because for the example we want propagated events
addEventHandler("onClientDgsDxBlur", editbox, onClientDGSBlur_editbox, true) --true because for the example we want propagated events
addEventHandler("onDgsBlur", editbox, onClientDGSBlur_editbox, true) --true because for the example we want propagated events
showCursor(true)
showCursor(true)
end)
end)
Line 44: Line 44:


==Note==
==Note==
When a widget in a window that didn't have focus before receives focus, ''onClientDgsDxFocus'' is triggered first for the window and then for the child widget.
When a widget in a window that didn't have focus before receives focus, ''onDgsFocus'' is triggered first for the window and then for the child widget.
When the window already had focus, ''onClientDgsDxFocus'' is only triggered for the newly focused child widget.
When the window already had focus, ''onDgsFocus'' is only triggered for the newly focused child widget.


==See Also==
==See Also==

Revision as of 13:35, 20 January 2018

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

Parameters

None

Source

The source of this event is the DGS element which just gained input focus.

Example

local window, editbox = nil, nil
DGS = exports.dgs
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 = DGS:dgsCreateWindow(left, top, windowWidth, windowHeight, "Example Window", false)		
	editbox = DGS:dgsCreateEdit(11, 41, 241, 22, "", false, window)
	addEventHandler("onDgsFocus", editbox, onClientDGSFocus_editbox, true) --true because for the example we want propagated events
	addEventHandler("onDgsBlur", editbox, onClientDGSBlur_editbox, true) --true because for the example we want propagated events
	showCursor(true)
end)

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

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

Note

When a widget in a window that didn't have focus before receives focus, onDgsFocus is triggered first for the window and then for the child widget. When the window already had focus, onDgsFocus is only triggered for the newly focused child widget.

See Also

DGS events

General

Check Box

Combo Box

Drag'N Drop

Edit

Grid List

Menu

Selector

Mouse

Radio Button

Switch Button

Tab

Animation

Plugin

Media

Color Picker

QRCode

Remote Image

Client event functions