This module provides a text label view for displaying text in the terminal UI.
::: tip TIP
To use this module, you need to import it first: import("core.ui.label")
:::
::: tip NOTE
The UI module is primarily used for xmake's internal xmake f --menu menu-based visual configuration. It provides basic UI components that can also be used by users to implement their own terminal UIs.
:::
The label module extends view and provides a simple text display component with:
::: tip API
label:new(name: <string>, bounds: <rect>, text: <string>)
:::
| Parameter | Description |
|---|---|
| name | Required. Label name string |
| bounds | Required. Label bounds rectangle |
| text | Required. Text content to display |
| Type | Description |
|---|---|
| label | Returns a label instance |
Create a label with text:
import("core.ui.label")
import("core.ui.rect")
local lbl = label:new("hello", rect{1, 1, 20, 1}, "Hello, World!")
::: tip API
label:text()
:::
No parameters
| Type | Description |
|---|---|
| string | Returns the text content |
Get the text content of a label:
local text = lbl:text()
print(text) -- Output: Hello, World!
::: tip API
label:text_set(text: <string>)
:::
| Parameter | Description |
|---|---|
| text | Required. Text content to display |
| Type | Description |
|---|---|
| label | Returns the label instance (for method chaining) |
Set or update the text content:
lbl:text_set("New Text")
lbl:text_set("Line 1\nLine 2") -- Multi-line text
::: tip API
label:textattr()
:::
No parameters
| Type | Description |
|---|---|
| string | Returns the text attribute string (e.g., "red bold") |
Get the current text attribute:
local attr = lbl:textattr()
print(attr) -- Output: black
::: tip API
label:textattr_set(attr: <string>)
:::
| Parameter | Description |
|---|---|
| attr | Required. Text attribute string (e.g., "red bold", "yellow onblue") |
| Type | Description |
|---|---|
| label | Returns the label instance (for method chaining) |
Set text color and style:
lbl:textattr_set("red") -- Red text
lbl:textattr_set("yellow bold") -- Yellow bold text
lbl:textattr_set("cyan onblue") -- Cyan text on blue background
lbl:textattr_set("green bold onblack") -- Green bold text on black background
::: tip API
label:textattr_val()
:::
No parameters
| Type | Description |
|---|---|
| number | Returns the numeric attribute value (for curses) |
This is typically used internally by the drawing system. The returned value combines the text attribute with the view's background color.
::: tip API
label:splitext(text: <string>, width?: <number>)
:::
| Parameter | Description |
|---|---|
| text | Required. Text to split |
| width | Optional. Maximum line width (defaults to label width) |
| Type | Description |
|---|---|
| table | Returns array of text lines |
Split text into multiple lines:
local lines = lbl:splitext("This is a long text that needs to be wrapped", 10)
-- Returns: {"This is a ", "long text ", "that needs ", "to be ", "wrapped"}
::: tip API
label:on_draw(transparent: <boolean>)
:::
| Parameter | Description |
|---|---|
| transparent | Optional. Draw with transparency |
No return value
This is automatically called by the UI framework when the label needs to be drawn.