Difference between revisions of "LGUI2:Event Handlers"

From Lavish Software Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
[[LavishGUI 2]] has a system of event handlers tied to Elements. Each element has a table of event names, which map to event handlers.
 
[[LavishGUI 2]] has a system of event handlers tied to Elements. Each element has a table of event names, which map to event handlers.
 +
 +
== Types of Event Handlers ==
 +
  
 
== Defining an Event Handler ==
 
== Defining an Event Handler ==
Line 10: Line 13:
  
 
; Event Handler types defined by JSON Arrays
 
; Event Handler types defined by JSON Arrays
* code: Code requires only one additional parameter, being LavishScript code to execute. Example: ["code","echo Hi mom!"]
+
* '''code''': Code requires only one additional parameter, being LavishScript code to execute. Example: ["code","echo Hi mom!"]
* method: Method requires two parameters in this order. First, the LavishScript object (globally accessible) with the method to execute. Second, the name of the method to execute. Example: ["method","MyBindingController","IDidIt"]. This case is also equivalent to ["code","MyBindingController:IDidIt"].
+
* '''method''': Method requires two parameters in this order. First, the LavishScript object (globally accessible) with the method to execute. Second, the name of the method to execute. Example: ["method","MyBindingController","IDidIt"]. This case is also equivalent to ["code","MyBindingController:IDidIt"].
 +
* '''forward''': Forward requires at least one additional parameter, and up to 4: type, event, elementName, elementType, flags. See the Event Handler properties table below for details on each.
 +
* '''style''': Style requires at least one additional parameter, and up to 4: styleName, event, elementName, elementType, flags. See the Event Handler properties table below for details on each.
 +
* '''animation''': Style requires at least one additional parameter, and up to 4: animation (JSON format), event, elementName, elementType, flags. See the Event Handler properties table below for details on each.
  
 
=== As a JSON Object ===
 
=== As a JSON Object ===
Line 21: Line 27:
 
! type
 
! type
 
| One of "method" "code" or "forward", with additional properties below depending on the type
 
| One of "method" "code" or "forward", with additional properties below depending on the type
 +
|-
 +
!colspan="2"|"method" type
 +
|-
 +
! object
 +
| The [[LavishScript]] object (globally accessible) with the method to execute
 +
|-
 +
! method
 +
| The method on the object to execute
 +
|-
 +
!colspan="2"|"code" type
 +
|-
 +
! code
 +
| [[LavishScript]] code to execute
 
|-
 
|-
 
!colspan="2"|"forward" type
 
!colspan="2"|"forward" type
 +
|-
 +
! event
 +
| (required) The Name of an event to forward to, on the forward element
 
|-
 
|-
 
! elementName
 
! elementName
Line 33: Line 55:
 
| (optional) The relationships to search for the intended element; by default, only ancestors are searched.
 
| (optional) The relationships to search for the intended element; by default, only ancestors are searched.
 
|-
 
|-
!colspan="2"|"method" type
+
!colspan="2"|"style" type
 +
|-
 +
! styleName
 +
| (required) The Name of the style to activate, on the forward element
 +
|-
 +
! elementName
 +
| (optional) The Name of a related element to forward to
 +
|-
 +
! elementType
 +
| (optional) The Type of a related element to forward to
 +
|-
 +
! flags
 +
| (optional) The relationships to search for the intended element; by default, only ancestors are searched.
 +
|-
 +
!colspan="2"|"animation" type
 
|-
 
|-
! object
+
! animation
| The [[LavishScript]] object (globally accessible) with the method to execute
+
| An [[LGUI2:Animation|Animation]] definition specifying the Animation to activate
 
|-
 
|-
! method
+
! elementName
| The method on the object to execute
+
| (optional) The Name of a related element to forward to
 
|-
 
|-
!colspan="2"|"code" type
+
! elementType
 +
| (optional) The Type of a related element to forward to
 
|-
 
|-
! code
+
! flags
| [[LavishScript]] code to execute
+
| (optional) The relationships to search for the intended element; by default, only ancestors are searched.
 
|}
 
|}
  

Revision as of 02:57, 16 November 2018

LavishGUI 2 has a system of event handlers tied to Elements. Each element has a table of event names, which map to event handlers.

Types of Event Handlers

Defining an Event Handler

Each Event Handler is defined by a JSON object enclosed by {}, or JSON array enclosed by []. An object may be preferable for explicitness, or an array may be preferable for compactness.

As a JSON Array

When defining an Event Handler with a JSON array, each item in the array is expected to be a string, and we will refer to them as parameters.

The first parameter is to be the type of event handler, one of "code" or "method". Following the type parameter will be any type-specific parameters.

Event Handler types defined by JSON Arrays
  • code: Code requires only one additional parameter, being LavishScript code to execute. Example: ["code","echo Hi mom!"]
  • method: Method requires two parameters in this order. First, the LavishScript object (globally accessible) with the method to execute. Second, the name of the method to execute. Example: ["method","MyBindingController","IDidIt"]. This case is also equivalent to ["code","MyBindingController:IDidIt"].
  • forward: Forward requires at least one additional parameter, and up to 4: type, event, elementName, elementType, flags. See the Event Handler properties table below for details on each.
  • style: Style requires at least one additional parameter, and up to 4: styleName, event, elementName, elementType, flags. See the Event Handler properties table below for details on each.
  • animation: Style requires at least one additional parameter, and up to 4: animation (JSON format), event, elementName, elementType, flags. See the Event Handler properties table below for details on each.

As a JSON Object

When defining an Event Handler with a JSON object, each item in the object is expected to be a string, and we will refer to them as properties.

Event Handler properties
type One of "method" "code" or "forward", with additional properties below depending on the type
"method" type
object The LavishScript object (globally accessible) with the method to execute
method The method on the object to execute
"code" type
code LavishScript code to execute
"forward" type
event (required) The Name of an event to forward to, on the forward element
elementName (optional) The Name of a related element to forward to
elementType (optional) The Type of a related element to forward to
flags (optional) The relationships to search for the intended element; by default, only ancestors are searched.
"style" type
styleName (required) The Name of the style to activate, on the forward element
elementName (optional) The Name of a related element to forward to
elementType (optional) The Type of a related element to forward to
flags (optional) The relationships to search for the intended element; by default, only ancestors are searched.
"animation" type
animation An Animation definition specifying the Animation to activate
elementName (optional) The Name of a related element to forward to
elementType (optional) The Type of a related element to forward to
flags (optional) The relationships to search for the intended element; by default, only ancestors are searched.


Examples

See lgui2eventargs for a detailed example using LavishScript methods.

LavishGUI 2 Topics