`snake()` creates a Snake game widget.
This object is a GUI component. It supports the common GUI methods, but it does not expose additional Snake-specific methods.
Creates a snake object.
| Item | Description |
|---|---|
| Syntax | `snake()` |
| Arguments | none |
| Returns | snake object |
game = snake().position(10, 10).size(300, 300);
Properties are read-only. Use methods to change values.
| Property | Type | Description |
|---|---|---|
| `position_x` | number | X position. |
| `position_y` | number | Y position. |
| `size_width` | number | Width. |
| `size_height` | number | Height. |
| `visible` | boolean | Visibility state. |
| `enabled` | boolean | Enabled state. |
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 `snake`.
Most visible GUI controls support these methods.
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);
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);
Shows or hides the component.
| Item | Description |
|---|---|
| Syntax | `component.visible(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | component object |
Example:
status.visible(false);
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);
`snake` currently exposes the common GUI methods only.
game = snake().position(10, 10).size(300, 300); window().title('Snake').size(340, 360).add(game).show();
Previous: image