This tutorial describes how to use the different types of LiveCode fields to enter and display text.
Fields allow you to display text in your application. You can also use fields to allow the user to enter and edit text or make selections.
Fields support multiple fonts, styles and colors and can display a basic subset of HTML and RTF text.
There are 5 basic field types in LiveCode, all of which you can add to your stack from the Tools Palette.
1. Label field: a single line, non-editable field
2. Text entry field: a single line, editable field
3. Scrolling field: a multi line, scrollable, editable field
4. Basic table field: a basic table field allowing data to be displayed in cells
5. Scrolling list field: a multi line, scrollable, non-editable field allowing the user to make single or multiple selections
All these objects are really the same type, they are just templates with different properties set to give different appearance and behavior. For example you could add a basic text entry field to your stack and by setting the appropriate properties turn it into a scrolling list field.
Label, Text Entry and Scrolling fields
The first 3 field types are very similar, label fields cannot be edited by the user but the others can. The only difference between a text entry field and a scrolling field is that a scrolling field is larger and has its vertical scrollbar turned on.
The Contents of a Field
You can put text into a field by typing into it directly, using the 'Contents' pane of the field Property Inspector or by setting the text property of the field in script.
You can retrieve the contents, or a portion of the contents, of a field using the get or put command. You can use chunk expressions with fields to retrieve a portion of the text, for example:
put word 1 of field "text"
For more details on using chunk expressions see this lesson.
Table fields allow you to display data in cells, and optionally allow the user to edit the cells. Table fields are ideal for displaying basic tabular data. For more complex data display requirements we recommend you use the Data Grid control.
You move between cells in a table field by clicking in a cell or using the tab and return keys. Setting the text property of a table field to tab delimited data inserts the data into the relevant cells.
A field is made into a table field by turning on the Basic Table object option in the Property Inspector.
List fields allow you to display a set of choices. Users cannot edit list fields.
You can allow the user to select multiple lines by setting the multipleHilites property to true and allow them to select lines that do not appear together by setting the noncontiguousHilites to true. Both these properties are available in the Basic Properties pane of the Property Inspector of the field. To select a contiguous range of lines use shift-click, to select multiple non-contiguous lines use cmd-click or ctrl-click.
To check which line or lines are selected use the hilitedLines property, this returns the line number of the selected line, in this example the value of the hilitedLines property would be 1,4.
You can also set the hilitedLines property to highlight lines in the list field.
Display Properties of Fields
You can set the text color, size and font of fields. You can also set the background color and highlight color of a field.
These properties allow you to give fields a highly customized appearance within your application.