1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
4
<title>The Dialog Module for Lua</title>
6
<body style="margin: 32px 25% 24px 5%">
7
<hr><h2>The Dialog module</h2><hr>
9
The <tt>dialog</tt> module provides a relatively simple way to create some fairly
10
complex dialog boxes for user interaction. The general idea is very loosely based on HTML forms.
14
<p>The functions are described below. The <tt>dlg</tt> argument expects a
15
dialog object, most other arguments are strings, unless otherwise noted.</p>
17
Note that you can also use these functions in object-oriented style:<br>
18
For instance <tt>dialog.label(dlg, "hello")</tt> <br>
19
can also be written as <tt>dlg:label("hello")</tt><br></p>
24
<hr><tt><b><big>function dialog.new ( title, buttons )</big></b></tt><br><p>
25
Creates a new dialog object. The <tt>title</tt> string assigns the window's title bar
26
text for the dialog. The <tt>buttons</tt> argument is a table of
27
strings, where each string will create a button with that text and add it to the
28
bottom row of the dialog. If a button's text contains an underscore, the letter after
29
it will be seen as an underlined accelerator for the button.</p>
32
<hr><tt><b><big>function dialog.run ( dlg )</big></b></tt><br>
33
<p>Displays the dialog to the user and waits for submission.</p><p>
34
This function returns two values: the one-based <tt>index</tt> of the the clicked button,
35
and a <tt>results</tt> table containing key-value pairs collected from the dialog's elements.</p><p>
36
If the user cancels the dialog e.g. by pressing the <tt>[Esc]</tt> key, the <tt>index</tt> will be zero, and the <tt>results</tt> table will be <tt>nil</tt>.
40
<hr><tt><b><big>function dialog.label ( dlg, text )</big></b></tt><br>
41
<p>Adds some informative text to the dialog.</p>
45
<hr><tt><b><big>function dialog.hr ( dlg )</big></b></tt><br>
46
<p>Draws a horizontal separator across the dialog.</p>
49
<hr><tt><b><big>function dialog.heading ( dlg, text )</big></b></tt><br>
50
<p>Adds a horizontal separator with some informative text below it.</p>
51
<p>This function is the same as calling the <tt>hr()</tt> and <tt>label()</tt> functions individually.</p>
55
<hr><tt><b><big>function dialog.text ( dlg, key, default, prompt )</big></b></tt><br>
56
<p>Creates a single-line text entry widget.</p>
58
The value of the <tt>key</tt> field in the <tt>results</tt> table will be set to the contents of the entry box.<br>
59
If the <tt>default</tt> string is non-nil, that text will initially be displayed in the entry box.<br>
60
The <tt>prompt</tt> string displays a label in front of the entry box to describe the requested input.
65
<hr><tt><b><big>function dialog.password ( dlg, key, default, prompt )</big></b></tt><br>
66
<p>Identical to the <tt>text()</tt> function, except that the contents of the entry box are "masked", the characters are displayed as asterisks. </p>
70
<hr><tt><b><big>function dialog.textarea ( dlg, key, default, caption )</big></b></tt><br>
71
<p>Creates a multi-line text entry widget.</p>
73
The value of the <tt>key</tt> field in the results table will be set to the contents of the text area.<br>
74
If the <tt>default</tt> string is non-nil, that text will initially be displayed in the text area.<br>
75
The <tt>caption</tt> string displays a label above the text area to describe the requested input.
79
<hr><tt><b><big>function dialog.checkbox ( dlg, key, default, caption )</big></b></tt><br>
80
<p>Creates an on/off toggle button.</p>
82
If the boolean <tt>default</tt> argument is <tt>true</tt>, the button will initially be shown in a "checked" state.<br>
83
The <tt>caption</tt> argument is the human-readable text to be displayed next to the button.
85
Note that although the default argument is boolean, the <tt>key</tt> value returned in the
86
<tt>results</tt> table will be a string, either <tt>"1"</tt>
87
for checked or <tt>"0"</tt> for unchecked.
93
<hr><tt><b><big>function dialog.select ( dlg, key, default, caption )</big></b></tt><br>
94
<p>Creates an empty drop-down list box.</p>
96
The contents of the <tt>key</tt> field in the <tt>results</tt> table will be set to the value of the selected item.<br>
97
If the <tt>default</tt> string is non-nil, the item with that value will initially be selected in the list.<br>
98
The <tt>caption</tt> string displays a label in front of the list box to describe the requested input.
102
<hr><tt><b><big>function dialog.option ( dlg, key, value, label )</big></b></tt><br>
103
<p>Adds an item to the drop-down list identified by <tt>key</tt>.</p>
105
The returned value of <tt>key</tt> will be set to this <tt>value</tt> in the <tt>results</tt> table if this item is selected.<br>
106
The <tt>label</tt> argument is the human-readable text to be displayed in the list.
111
<hr><tt><b><big>function dialog.group ( dlg, key, default, caption )</big></b></tt><br>
112
<p>Creates an empty group for radio buttons.</p><p>
113
The contents of the <tt>key</tt> field in the <tt>results</tt> table will be set to
114
the value of the selected radio button.<br>
115
If the <tt>default</tt> string is non-nil, the button with that value will initially be selected in the group.<br>
116
The <tt>caption</tt> string displays a label above of the group to describe the requested input.
120
<hr><tt><b><big>function dialog.radio ( dlg, key, value, label )</big></b></tt><br>
121
<p>Adds a button to the radio group identified by <tt>key</tt>.</p>
123
The returned value of <tt>key</tt> will be set to this <tt>value</tt> in the <tt>results</tt> table if this button is selected.<br>
124
The <tt>label</tt> argument is the human-readable text to be displayed next to this button.
128
<hr><tt><b><big>function dialog.file ( dlg, key, default, caption )</big></b></tt><br>
130
Creates a single-line text entry widget, along with a "browse" button that
131
invokes a separate file-selection dialog. <br>
132
If the user selects a filename in the file dialog, the text in the
133
entry widget will be set to the selected filename.
136
The value of the <tt>key</tt> field in the <tt>results</tt> table will be set to
137
the contents of the entry box.<br>
142
<hr><tt><b><big>function dialog.color ( dlg, key, default, caption )</big></b></tt><br>
144
Creates a single-line text entry widget, along with a "choose" button that
145
invokes a separate color-selection dialog. <br>
146
If the user selects a color from the dialog, the text in the
147
entry widget will be set to the selected color name in <tt>#RRGGBB</tt> format.
150
The value of the <tt>key</tt> field in the <tt>results</tt> table will be set to
151
the contents of the entry box.<br>
156
<hr><tt><b><big>function dialog.font ( dlg, key, default, caption )</big></b></tt><br>
158
Creates a single-line text entry widget, along with a "select" button that
159
invokes a separate font-selection dialog. <br>
160
If the user selects a font from the dialog, the text in the
161
entry widget will be set to the font name.
164
The value of the <tt>key</tt> field in the <tt>results</tt> table will be set to
165
the contents of the entry box.<br>
173
<div align="right"><small>© 2007-2008 <i>Jeff Pohlmeyer </i> </small></div>