`togglebutton()` creates a checkable button.
Creates a toggle button object.
t = togglebutton().text("Enabled").checked(true);
Most visible GUI controls support these methods:
| Method | Returns | Description |
|---|---|---|
| `position(x, y)` | self | Sets the component position in pixels. |
| `size(width, height)` | self | Sets component size in pixels. Width and height are clamped to at least 1. |
| `visible(enabled)` | self | Shows or hides the component. |
| `enabled(enabled)` | self | Enables or disables user interaction. |
Common component properties:
| 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. |
| Method | Returns | Description |
|---|---|---|
| `text(value)` | self | Sets button text. |
| `checked(enabled)` | self | Sets checked state. |
| `on_change(callback)` | self | Sets callback called when checked state changes. |
| `on_click(callback)` | self | Sets callback called when clicked. |
| `click()` | boolean | Simulates a click. |
function changed() { print("changed"); } 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