checkbox.lzx
<library>
<include href="base/baseformitem.lzx"/>
<include href="base/multistatebutton.lzx"/>
<resource name="lzcheckbox_rsrc">
<frame src="resources/checkbox/checkbox_off.swf"/>
<frame src="resources/checkbox/checkbox_off_mo.swf"/>
<frame src="resources/checkbox/checkbox_on.swf"/>
<frame src="resources/checkbox/checkbox_disable_off.swf"/>
<frame src="resources/checkbox/checkbox_on.swf"/>
<frame src="resources/checkbox/checkbox_on_mo.swf"/>
<frame src="resources/checkbox/checkbox_off.swf"/>
<frame src="resources/checkbox/checkbox_disable_on.swf"/>
</resource>
<class name="checkbox" extends="baseformitem" pixellock="true">
<text name="_title" x="16" y="${classroot.text_y}" text="${parent.text}" resize="true"/>
<attribute name="text_y" value="${this.cb.height/2 - this._title.height/2+1}" type="number"/>
<attribute name="value" setter="setValue(value)" value="false
"/>
<multistatebutton name="cb" resource="lzcheckbox_rsrc" text="" statenum="${parent.value ? 1 : 0}" statelength="4" maxstate="1" reference="parent">
</multistatebutton>
<method name="doSpaceUp">
if ( this._enabled ) {
this.setAttribute('value', !this.value);
}
</method>
<handler name="onclick">
if (this._enabled)
this.setAttribute('value', !this.value);
</handler>
<method name="_applystyle" args="s">
if (this.style != null) {
if (_enabled) {
_title.setAttribute('fgcolor',s.textcolor);
} else {
_title.setAttribute('fgcolor',s.textdisabledcolor);
}
setTint(this.cb, s.basecolor);
}
</method>
<method name="_showEnabled">
_applystyle(this.style);
</method>
<method name="setValue" args="val, isinitvalue=null">
if (val == "false") val = false;
else if (val == "true") val = true;
else val = !!val;
super.setValue(val, isinitvalue);
</method>
<doc>
<tag name="shortdesc"><text>The checkbox tag provides a simple toggle button.</text></tag>
<text>
<p>
The <classname>checkbox</classname> tag provides a simple toggle
button that represents a value of <code>true</code> or
<code>false</code>. It has a disabled state where it does not
respond to mouse events when <code>enabled=false</code>.
</p>
<example title="simple checkbox">
<canvas debug="true" height="160">
<debug x="135" y="15"/>
<checkbox id="checkMe" text="Show Green Square"/>
<view visible="${checkMe.value}" bgcolor="green" width="20" height="20"/>
<button text="Toggle" onclick="checkMe.setAttribute('value', !checkMe.value)"/>
<button text="Disable" onclick="checkMe.setAttribute('enabled', false)"/>
<button text="Enable" onclick="checkMe.setAttribute('enabled', true)"/>
<button text="status" onclick="Debug.debug('value: %w', checkMe.value)"/>
<simplelayout axis="y" spacing="4"/>
</canvas>
</example>
<p>
Note that checkbox attributes may be used as constraints for other attributes.
In the example above, clicking the checkbox toggles the visibility of the
green square. Whenever the value of the checkbox changes, so does the
visibility attribute of the green view.
</p>
<seealso>
<component-design id="checkbox" title="Checkbox"/>
</seealso>
</text>
</doc>
</class>
</library>
Cross References
Includes
Resources
Classes
- <class name="checkbox" extends="baseformitem">
Named Instances