OnDgsPropertyChange
Jump to navigation
Jump to search
This event is triggered when a monitored property of a dgs element changes via dgsSetProperty. The property must be added to the listener using dgsAddPropertyListener for this event to fire.
Tip: This event does NOT fire for user input changes (like typing in edit boxes). For monitoring user text input, use onDgsTextChange instead |
Tip: This event is designed for programmatic property changes, not user interactions |
Parameters
string propertyName, mixed newValue, mixed oldValue
- propertyName: the name of the property that changed
- newValue: the new value that was set
- oldValue: the previous value before the change
Source
The source is the dgs element whose property was changed.
Example
This example shows how to monitor window position changes:
DGS = exports.dgs local window = DGS:dgsCreateWindow(200, 200, 400, 300, "Property Monitor", false) -- Add listener for position changes DGS:dgsAddPropertyListener(window, "absPos") -- Handle property changes function handlePropertyChange(propertyName, newValue, oldValue) if propertyName == "absPos" then outputChatBox("Window moved from " .. oldValue[1] .. "," .. oldValue[2] .. " to " .. newValue[1] .. "," .. newValue[2]) end end addEventHandler("onDgsPropertyChange", window, handlePropertyChange) -- Test the listener setTimer(function() DGS:dgsSetProperty(window, "absPos", {300, 250}) end, 2000, 1)
This example demonstrates onDgsPropertyChange with programmatic text updates:
DGS = exports.dgs local window = DGS:dgsCreateWindow(300, 200, 320, 320, "Property Change Demo", false) local nameEdit = DGS:dgsCreateEdit(20, 50, 280, 30, "", false, window) local emailEdit = DGS:dgsCreateEdit(20, 100, 280, 30, "", false, window) local submitBtn = DGS:dgsCreateButton(20, 150, 280, 40, "Submit (Disabled)", false, window) local statusLabel = DGS:dgsCreateLabel(20, 200, 280, 40, "Click buttons to set text", false, window) local setNameBtn = DGS:dgsCreateButton(20, 250, 135, 30, "Set Name", false, window) local setEmailBtn = DGS:dgsCreateButton(165, 250, 135, 30, "Set Email", false, window) DGS:dgsCreateLabel(20, 30, 100, 20, "Name:", false, window) DGS:dgsCreateLabel(20, 80, 100, 20, "Email:", false, window) -- Monitor text property changes DGS:dgsAddPropertyListener(nameEdit, "text") DGS:dgsAddPropertyListener(emailEdit, "text") function validateForm() local name = DGS:dgsGetProperty(nameEdit, "text") local email = DGS:dgsGetProperty(emailEdit, "text") local isValid = (name and name ~= "" and email and email ~= "" and string.find(email, "@")) DGS:dgsSetProperty(submitBtn, "enabled", isValid) if isValid then DGS:dgsSetProperty(submitBtn, "text", "Submit (Ready!)") DGS:dgsSetProperty(statusLabel, "text", "Form is valid!") DGS:dgsSetProperty(statusLabel, "textColor", tocolor(0, 255, 0, 255)) else DGS:dgsSetProperty(submitBtn, "text", "Submit (Disabled)") DGS:dgsSetProperty(statusLabel, "text", "Fill both fields") DGS:dgsSetProperty(statusLabel, "textColor", tocolor(255, 0, 0, 255)) end end function handlePropertyChange(propertyName, newValue, oldValue) outputChatBox("Property '" .. propertyName .. "' changed to: " .. tostring(newValue)) validateForm() end addEventHandler("onDgsPropertyChange", nameEdit, handlePropertyChange) addEventHandler("onDgsPropertyChange", emailEdit, handlePropertyChange) -- Button handlers to trigger property changes addEventHandler("onDgsMouseClick", setNameBtn, function() DGS:dgsSetProperty(nameEdit, "text", "John Doe") end) addEventHandler("onDgsMouseClick", setEmailBtn, function() DGS:dgsSetProperty(emailEdit, "text", "[email protected]") end) validateForm()
This example shows onDgsPropertyChange with button properties:
DGS = exports.dgs local button = DGS:dgsCreateButton(100, 100, 200, 50, "Click Me", false) -- Monitor button properties DGS:dgsAddPropertyListener(button, {"alpha", "enabled"}) function handleButtonChange(propertyName, newValue, oldValue) outputChatBox("Button property '" .. propertyName .. "' changed from " .. tostring(oldValue) .. " to " .. tostring(newValue)) end addEventHandler("onDgsPropertyChange", button, handleButtonChange) -- Test the property changes setTimer(function() DGS:dgsSetProperty(button, "alpha", 128) DGS:dgsSetProperty(button, "enabled", false) end, 2000, 1)
This example shows monitoring multiple properties:
DGS = exports.dgs local button = DGS:dgsCreateButton(100, 100, 200, 50, "Monitor Me", false) -- Monitor multiple properties DGS:dgsAddPropertyListener(button, {"text", "alpha", "visible"}) function handleButtonChange(propertyName, newValue, oldValue) outputChatBox("Property '" .. propertyName .. "' changed from " .. tostring(oldValue) .. " to " .. tostring(newValue)) end addEventHandler("onDgsPropertyChange", button, handleButtonChange) -- Test changes setTimer(function() DGS:dgsSetProperty(button, "text", "Changed!") DGS:dgsSetProperty(button, "alpha", 128) end, 1000, 1)
Tip: Use dgsRemovePropertyListener to stop monitoring properties when no longer needed |
Author: Mohab
See Also
DGS events
General
- onDgsBlur
- onDgsCreate
- onDgsCursorTypeChange
- onDgsCursorStateChange
- onDgsDestroy
- onDgsElementRender
- onDgsElementMove
- onDgsElementSize
- onDgsElementEnter
- onDgsElementLeave
- onDgsFocus
- onDgsKey
- onDgsPositionChange
- onDgsPreRender
- onDgsRender
- onDgsElementScroll
- onDgsSizeChange
- onDgsTextChange
- onDgsWindowClose
- onDgsPropertyChange
Check Box
Combo Box
Drag'N Drop
Edit
Grid List
Menu
Selector
Mouse
- onDgsMousePreClick
- onDgsMouseClick
- onDgsMouseClickDown
- onDgsMouseClickUp
- onDgsMouseDrag
- onDgsMouseDoubleClick
- onDgsMouseDoubleClickDown
- onDgsMouseDoubleClickUp
- onDgsMouseDown
- onDgsMouseHover
- onDgsMouseEnter
- onDgsMouseLeave
- onDgsMouseMultiClick
- onDgsMouseMove
- onDgsMouseStay
- onDgsMouseUp
- onDgsMouseWheel
Radio Button
Switch Button
Tab
Animation
Plugin
Media
- onDgsMediaPlay
- onDgsMediaPause
- onDgsMediaStop
- onDgsMediaLoaded
- onDgsMediaTimeUpdate
- onDgsMediaBrowserReturn
Color Picker
QRCode
Remote Image
DGS functions
- dgsAddPropertyListener
- dgsRemovePropertyListener
- dgsGetListenedProperties
- dgsSetProperty
- dgsGetProperty
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled