`panel()` creates a general-purpose container for other GUI components.
Creates a panel object.
| Item | Description |
|---|---|
| Syntax | `panel()` |
| Arguments | none |
| Returns | panel object |
Example:
p = panel().position(10, 10).size(300, 120).border(1);
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. |
| `border` | number | Current border size. `0` means no border. |
| `fit_parent` | boolean | `true` when `size(-1, -1)` was used to fit the parent area. |
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 `panel`.
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);
Sets panel border size. Values below `0` are clamped to `0`.
| Item | Description |
|---|---|
| Syntax | `panel.border(size)` |
| Arguments | `size`: border size in pixels |
| Returns | panel object |
Example:
p = panel().border(1);
Sets a callback called after the panel content area is resized.
| Item | Description |
|---|---|
| Syntax | `panel.on_resize(callback)` |
| Arguments | `callback`: callable with four arguments: `x`, `y`, `width`, `height` |
| Returns | panel object |
The callback receives the usable content area after panel border spacing is subtracted.
Example:
function panel_resized(x, y, width, height) { print('panel size: ', width, ' x ', height); } p = panel().on_resize(panel_resized);
Adds a child GUI component to the panel.
A component can belong to only one container. Adding the same component again to the same panel is ignored; adding a component that already belongs to another container raises an error.
| Item | Description |
|---|---|
| Syntax | `panel.add(component)` |
| Arguments | `component`: GUI component object |
| Returns | panel object |
Example:
p = panel().position(10, 10).size(300, 120).border(1); p.add(label().position(10, 10).size(200, 24).text('Panel content'));