This module provides a window with border, title, and panel support.
::: tip TIP
To use this module, you need to import it first: import("core.ui.window")
:::
::: 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 window module extends panel and provides a complete window container with:
::: tip API
window:new(name: <string>, bounds: <rect>, title?: <string>, shadow?: <boolean>)
:::
| Parameter | Description |
|---|---|
| name | Required. Window name string |
| bounds | Required. Window bounds rectangle |
| title | Optional. Window title string (centered at top) |
| shadow | Optional. Show shadow effect (true or false, default false) |
| Type | Description |
|---|---|
| window | Returns a window instance |
Create a window with title and shadow:
import("core.ui.window")
import("core.ui.rect")
local win = window:new("main", rect{10, 5, 60, 20}, "Main Window", true)
::: tip API
window:frame()
:::
No parameters
| Type | Description |
|---|---|
| panel | Returns the frame panel instance |
Access the frame panel to customize its appearance:
local frame = win:frame()
frame:background_set("cyan")
::: tip API
window:panel()
:::
No parameters
| Type | Description |
|---|---|
| panel | Returns the content panel instance |
Access the content panel to add child views:
local panel = win:panel()
panel:insert(label:new("label1", rect{1, 1, 20, 1}, "Hello"))
::: tip API
window:title()
:::
No parameters
| Type | Description |
|---|---|
| label | Returns the title label instance or nil if no title was set |
Access and customize the title label:
local title = win:title()
if title then
title:text_set("New Title")
title:textattr_set("red bold")
end
::: tip API
window:shadow()
:::
No parameters
| Type | Description |
|---|---|
| view | Returns the shadow view instance or nil if shadow was not enabled |
Access the shadow view:
local shadow = win:shadow()
if shadow then
shadow:background_set("gray")
end
::: tip API
window:border()
:::
No parameters
| Type | Description |
|---|---|
| border | Returns the border instance |
Access the border component:
local border = win:border()
::: tip API
window:on_event(e: <event>)
:::
| Parameter | Description |
|---|---|
| e | Required. Event object |
| Type | Description |
|---|---|
| boolean | Returns true if Tab key was handled, nil otherwise |
The window automatically handles Tab key navigation between focusable views in the panel:
-- Tab key is automatically handled to navigate focus
::: tip API
window:on_resize()
:::
No parameters
No return value
This is automatically called when the window is resized. It adjusts: