Table of Contents

togglebutton

`togglebutton()` creates a checkable button.

Constructor

togglebutton()

Creates a togglebutton object.

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

Example:

t = togglebutton().text('Enabled').checked(true);

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 button text.
`checked` boolean Current checked state.

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 `togglebutton`.


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 button text.

Item Description
Syntax `togglebutton.text(value)`
Arguments `value`: text shown on the button
Returns togglebutton object

Example:

t = togglebutton().text('Use probing');

checked(enabled)

Sets checked state.

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

Example:

t = togglebutton().checked(true);

on_change(callback)

Sets a callback called when checked state changes.

Item Description
Syntax `togglebutton.on_change(callback)`
Arguments `callback`: callable with one argument, the checked state
Returns togglebutton object

Example:

function changed(value)
{
    print('checked: ', value);
}
 
t = togglebutton().on_change(changed);

on_click(callback)

Sets a callback called when the button is clicked.

Item Description
Syntax `togglebutton.on_click(callback)`
Arguments `callback`: callable with no arguments
Returns togglebutton object

Example:

function clicked()
{
    print('clicked');
}
 
t = togglebutton().on_click(clicked);

click()

Simulates a click.

Item Description
Syntax `togglebutton.click()`
Arguments none
Returns togglebutton object

Example:

t.click();

Example

function changed(value)
{
    print('checked: ', value);
}
 
t = togglebutton().position(20, 20).size(160, 24).text('Use probing').on_change(changed);
window().title('Toggle').size(220, 100).add(t).show();

Previous: drawablebutton

Next: togglegroup