Table of Contents

textedit

`textedit()` creates a text editor. It can be single-line, multi-line, or automatic style.

Constructor

textedit()

Creates a textedit object.

Item Description
Syntax `textedit()`
Arguments none
Returns textedit object

Example:

edit = textedit().style_multi().text('Line 1');

Properties

Properties are read-only. Use methods to change GUI object state.

Property Type Description
`position_x` number Current x position.
`position_y` number Current y position.
`size_width` number Current width.
`size_height` number Current height.
`visible` boolean Current visible state.
`enabled` boolean Current enabled state.
`text` string Current text.
`ghost` string Placeholder text.
`readonly` boolean Current read-only state.
`style` string Current style: `single`, `multi`, or `auto`.

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

`clone()` is not supported for `textedit`.


Most visible GUI controls support these methods.

position(x, y)

Sets the component position in pixels.

Item Description
Syntax `component.position(x, y)`
Arguments `x`: x position; `y`: y position
Returns component object

Example:

label().position(20, 10);

size(width, height)

Sets the component size in pixels. Width and height are clamped to at least `1`.

Some container objects, such as `panel()` and `group()`, use `size(-1, -1)` as a special fit-parent mode.

Item Description
Syntax `component.size(width, height)`
Arguments `width`: width in pixels; `height`: height in pixels
Returns component object

Example:

textinput().size(220, 26);

visible(enabled)

Shows or hides the component.

Item Description
Syntax `component.visible(enabled)`
Arguments `enabled`: boolean
Returns component object

Example:

status.visible(false);

enabled(enabled)

Enables or disables user interaction with the component.

Item Description
Syntax `component.enabled(enabled)`
Arguments `enabled`: boolean
Returns component object

Example:

run_button.enabled(false);

Methods

text(value)

Sets current text.

Item Description
Syntax `textedit.text(value)`
Arguments `value`: text value
Returns textedit object

Example:

edit = textedit().text('Line 1');

ghost(value)

Sets placeholder text shown when the editor is empty.

Item Description
Syntax `textedit.ghost(value)`
Arguments `value`: placeholder text
Returns textedit object

Example:

edit = textedit().ghost('Notes');

readonly(enabled)

Enables or disables read-only mode.

Item Description
Syntax `textedit.readonly(enabled)`
Arguments `enabled`: boolean
Returns textedit object

Example:

edit = textedit().readonly(true);

style_single()

Uses single-line editing style.

Item Description
Syntax `textedit.style_single()`
Arguments none
Returns textedit object

Example:

edit = textedit().style_single();

style_multi()

Uses multi-line editing style.

Item Description
Syntax `textedit.style_multi()`
Arguments none
Returns textedit object

Example:

edit = textedit().style_multi();

style_auto()

Uses automatic style.

Item Description
Syntax `textedit.style_auto()`
Arguments none
Returns textedit object

Example:

edit = textedit().style_auto();

on_change(callback)

Sets a callback called when text changes.

Item Description
Syntax `textedit.on_change(callback)`
Arguments `callback`: callable with one argument, the current text
Returns textedit object

Example:

function notes_changed(text)
{
    print('notes changed');
}
 
edit = textedit().on_change(notes_changed);

Example

edit = textedit().position(20, 20).size(260, 120).style_multi().text('Notes');
window().title('Text Edit').size(320, 180).add(edit).show();

Previous: textinput

Next: numinput