alert.lzx
<library>
<include href="lz/button.lzx"/>
<include href="lz/modaldialog.lzx"/>
<include href="utils/layouts/simplelayout.lzx"/>
<include href="utils/layouts/resizelayout.lzx"/>
<class name="alert" extends="modaldialog">
<attribute name="button1" value="OK
" type="string"/>
<attribute name="button2" value="
" type="string"/>
<attribute name="result" value="null
"/>
<attribute name="text_x" value="0
" type="number"/>
<attribute name="text_y" value="0
" type="number"/>
<attribute name="minwidth" value="$once{button2 == '' ? 100 : 170}"/>
<event name="onresult"/>
<attribute name="maxtextwidth" value="${Math.round(parent.width/3) - inset_left - inset_right - content_inset_left - content_inset_right}"/>
<text name="alerttext" x="${parent.text_x}" y="${parent.text_y}" resize="true" multiline="true">
<attribute name="text" type="text" value="${parent.text}"/>
<setter name="text" args="t">
super.setAttribute('text', t);
if (!parent._usecontentwidth) {
this.setAttribute('width', parent.width
- parent.inset_left - parent.inset_right
- parent.content_inset_left - parent.content_inset_right );
} else {
var twidth = this.getTextWidth();
if (twidth > parent.maxtextwidth) {
// multiline text looks funny unless its a bit wider
// since there is always extra space on the right
twidth = parent.maxtextwidth;
}
this.setAttribute('width', twidth);
}
parent.checkMinSize();
</setter>
</text>
<method name="open">
this.result = null;
if ( this.onresult ){
this.onresult.sendEvent( null );
}
super.open();
</method>
<method name="close" args="...args">
var res = args[0];
this.result = res;
if ( this.onresult ){
this.onresult.sendEvent( res);
}
super.close();
</method>
<view x="${immediateparent.width > this.width? immediateparent.width - this.width : 0}" y="${immediateparent.alerttext.height + parent.content_inset_top}">
<simplelayout axis="x" spacing="5"/>
<button onclick="classroot.close( false )" text="${classroot.button2}" visible="${classroot.button2 != '' }">
</button>
<button isdefault="true" onclick="classroot.close( true )" text="${classroot.button1}" visible="${classroot.button1 != '' }" name="b1">
</button>
</view>
<doc>
<tag name="shortdesc"><text>
A simple alert.
</text></tag>
<text>
<p>A simple subclass of <tagname>modaldialog</tagname>, <tagname>alert</tagname> provides a modal alert box that displays its text attribute (or content) and an OK button. (If you need to display more than text in an alert, use <tagname>modaldialog</tagname> itself).</p>
<example>
<canvas height="140">
<alert name="myalert">
Danger! Danger, Will Robinson!
</alert>
<button onclick="canvas.myalert.open()">Show Alert</button>
</canvas>
</example>
<p><b>See also:</b></p>
<ul>
<li><p><a href="lz.modaldialog.html"><tagname>modaldialog</tagname></a></p></li>
</ul>
</text>
</doc>
</class>
</library>
Cross References
Includes
Classes
- <class name="alert" extends="modaldialog">