LGUI2:LS1:lgui2eventargs

From Lavish Software Wiki
Revision as of 10:35, 1 October 2019 by Lax (talk | contribs)
Jump to navigation Jump to search
Object Type Vitals
lgui2eventargs
Defined By LavishGUI 2
Inherits none
Reduces To lgui2eventargs
Variable Object Type none
Uses Sub-Types no
C/C++ Type void *

A lgui2eventargs object is provided as the Context Top-Level Object when an Event Handler is handling an event.

Members

  • lgui2element Source: The source of the event being fired.
  • jsonobject Args: Any properties passed with the event
  • jsonvalue Args[key]: A value from the Args object, by its key
  • bool Handled: TRUE if the event has been acknowledged as handled.

Methods

  • SetHandled: Sets the event "Handled" state to TRUE. This is generally recommended within event handlers. Hooks in particular will ignore the Handled state.

Examples

Handling input events to an element

testui-demo.json
{
  "type": "window",
  "name": "demo window",
  "title": "My Window",
  "content": {
    "type": "button",
    "name": "myButton",
    "horizontalAlignment": "stretch",
    "verticalAlignment": "stretch",
    "content": "This is my button!",
    "eventHandlers": {
      "onMouseButtonMove": [ "method", "TestUIController", "Test_OnMouseButtonMove" ],
      "onButtonMove": [ "method", "TestUIController", "Test_OnButtonMove" ],
      "onDpadMove": [ "method", "TestUIController", "Test_OnDpadMove" ],
      "onAxisMove": [ "method", "TestUIController", "Test_OnAxisMove" ],
      "onMouseMove": [ "method", "TestUIController", "Test_OnMouseMove" ],
      "onMouseWheel": [ "method", "TestUIController", "Test_OnMouseWheel" ]
    }
  }
}
testui.iss
objectdef testUIController
{
	method Initialize()
	{
; Set up a LavishScript enum to help convert DPad positions to something easily recognizable
		LavishScript:RegisterEnum[edpad]
		Enum[edpad]:SetValue[RELEASED,-1]
		Enum[edpad]:SetValue[N,0]
		Enum[edpad]:SetValue[NE,45]
		Enum[edpad]:SetValue[E,90]
		Enum[edpad]:SetValue[SE,135]
		Enum[edpad]:SetValue[S,180]
		Enum[edpad]:SetValue[SW,225]
		Enum[edpad]:SetValue[W,270]
		Enum[edpad]:SetValue[NW,315]
	}

	method Test_OnMouseButtonMove()
	{
		echo testUIController:Test_OnMouseButtonMove ${Context(type)} ${Context.Source(type)} ${Context.Args}
		if ${Context.Args[position]}
		{
			echo MOUSE BUTTON PRESSED
		}
		else
		{
			echo MOUSE BUTTON RELEASED
		}
               Context:SetHandled[1]
	} 

	method Test_OnMouseMove()
	{
		echo testUIController:Test_OnMouseMove ${Context(type)} ${Context.Source(type)} ${Context.Args}
	}

	method Test_OnMouseWheel()
	{
		echo testUIController:Test_OnMouseWheel ${Context(type)} ${Context.Source(type)} ${Context.Args}
               Context:SetHandled[1]
	}
 
	method Test_OnButtonMove()
	{
		echo testUIController:Test_OnButtonMove ${Context(type)} ${Context.Source(type)} ${Context.Args}
               Context:SetHandled[1]
	}

	method Test_OnDpadMove()
	{
		echo testUIController:Test_OnDpadMove ${Context(type)} ${Context.Source(type)} ${Context.Args}
		echo DPAD: ${Context.Args[position].Int(edpad)}
		switch ${Context.Args[position].Int(edpad)}
		{
		case RELEASED
;			echo DPAD: RELEASED
			break
		case N
;			echo DPAD: UP
			break
		case E
;			echo DPAD: RIGHT
			break
		case S
;			echo DPAD: DOWN
			break
		case W
;			echo DPAD: LEFT
			break
		}
	}

	method Test_OnAxisMove()
	{
		echo testUIController:Test_OnAxisMove ${Context(type)} ${Context.Source(type)} ${Context.Args}
	}
}

variable(global) testUIController TestUIController

function main()
{
	LGUI2:LoadFile["testui-demo.json"]

	while 1
		waitframe	
}

; Clean up our GUI when the controller script exits (could also be in testUIController:Shutdown)
atom atexit()
{
	LGUI2.Element[demo window]:ClearChildren:Detach
}


LavishGUI 2 Element Types

LavishGUI 2 LavishScript Object Types

Core API (see Using LavishGUI 2 from LavishScript)
lgui2 - lgui2animateargs - lgui2animationtype - lgui2elementref - lgui2eventargs - lgui2eventhandler - lgui2elementtype - lgui2itemviewgeneratorargs - lgui2inputbinding - lgui2layer - lgui2skin - lgui2trigger
Enums
elgui2animationframestate - elgui2dpad - elgui2edge - elgui2fontflags - elgui2horizontalalignment - elgui2imageorientation - elgui2progresstext - elgui2scrollbar - elgui2sizetocontent - elgui2verticalignment - elgui2visibility
Element Components
lgui2animation - lgui2brush - lgui2fontstyle - lgui2margins - lgui2item - lgui2property - lgui2radialitem - lgui2radialgaugeneedle
Element Base Types
lgui2element - lgui2bordered - lgui2contentbase - lgui2headeredcontentbase - lgui2itemlist
Elements