[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

#### 4.19.9.5 Widget Events

Some widgets have events. Most, in fact, do. These events are simply calls to functions indicated by their correct name, and are members of the widget object. A good example is the Button widget. It requires the user to specify content by defining an event handler for an event called "onDrawContent".

    <widget type="Button">
    	<event name="onDrawContent" action="function myDraw(pen) { pen.SetColor(0,0,0,1); pen.DrawRect(0,0,this.width,this.height);}" />
    </widget>

The event node has two required attributes: name and action. Name specifies the name of the event that you want to hook, and action is the action that should be taken on the event. The example above actually defines the draw function in place. That is not actually necessary.

    <widget type="Button">
    	<event name="onDrawContent" action="buttonDrawText('Pause')" />
    </widget>

It is very common to just want to draw text on a button. Therefore, the button widget has a convenience function that returns a function that draws the given label on a button. In the example above, the function buttonDrawText() is called, which returns a closure containing a drawing function that knows what label to draw on the button.

Other events may require more complex settings that have to be added to the widget. In order to accomodate that, there is a way to specify additional settings for the event by using child nodes:

    <widget type="ComplexWidget">
    	<event name="onMyEvent" action="doSomething()">
    		<setting name="mysetting" value="1" />
    		<setting name="othersetting" value="2" />
    	</event>
    </widget>

The settings may be referred to using the "this" variable in your action function. For example:

    function doSomething()
    {
    	var a = this.mysetting + this.othersetting;
    	return;
    }

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated using texi2html 1.76.