Difference between revisions of "LGUI2:Event Handlers"

From Lavish Software Wiki
Jump to: navigation, search
(Created page with "LavishGUI 2 has a system of event handlers tied to Elements. Each element has a table of event names, which map to event handlers. == Defining an Event Handler == Each Event ...")
(No difference)

Revision as of 21:35, 12 May 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.

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"].

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 parameters.

A parameter named "type" is required and specifies the type of Event Handler, one of "method", "code", or "forward"

Event Handler types defined by JSON Arrays
  • code: Code requires one additional parameter named "code", being LavishScript code to execute. Example: {"type":"code","code":"echo Hi mom!"}
  • method: Method requires two parameters. "object" must be the LavishScript object (globally accessible) with the method to execute. "method" must be the name of the method to execute. Example: {"type":"method","object":"MyBindingController","method":"IDidIt"}. This case is also equivalent to {"type":"code","code","MyBindingController:IDidIt"}
  • forward: Forward requires an "event" parameter being the name of the event to forward to. Forward additionally has three optional parameters. "elementName" may provide the Name of a related element to forward to. "elementType" may be the Type of a related element to forward to. "flags" may specify the relationships to search for the intended element; by default, only ancestors are searched.