API
#ui
Xu 0.8.8 API
import: #ui
counts: 71 fns, 17 methods, 10 types, 47 consts, 0 ifaces
Windows, menus, tray. run reports host not available when the host is not wired.
const content_none
pub const content_none = 0
Purpose
Desktop shell: App / Window / Icon / Menu / Tray / events / post queue. Owns the UI (shell) runtime event loop and host process. Content backends: register_content_plugin(ContentPlugin) with per-OS sources. Native open: compile-time `$macos` / `$linux` / `$windows` files (host_open_*.xu) each define open_native_window — App.run does not branch on OS. Host modes default → OS native host (macOS / Linux / Windows) XU_UI_SIM=1 → in-process sim (fixtures/CI) Value `0`.
Parameters
none
const content_webview
pub const content_webview = 1
Purpose
Public constant `content_webview`. Value `1`.
Parameters
none
const content_draw
pub const content_draw = 2
Purpose
Public constant `content_draw`. Value `2`.
Parameters
none
const content_native
pub const content_native = 3
Purpose
Public constant `content_native`. Value `3`.
Parameters
none
struct ContentPlugin
pub struct ContentPlugin {
pub kind int
pub bootstrap string
pub macos_src string
pub macos_frameworks string
pub linux_src string
pub linux_libs string
pub windows_src string
pub windows_libs string
}
Purpose
Per-OS content backend registration. Shell picks fields for xu_target_os only. Empty src on an OS ⇒ that backend is unavailable there (shell may still run empty).
Parameters
kind int- kind tag
bootstrap string- field (string)
macos_src string- field (string)
macos_frameworks string- field (string)
linux_src string- field (string)
linux_libs string- field (string)
windows_src string- field (string)
windows_libs string- field (string)
const os_macos
Purpose
Public constant `os_macos`. Value `0`.
Parameters
none
const os_linux
Purpose
Public constant `os_linux`. Value `1`.
Parameters
none
const os_windows
Purpose
Public constant `os_windows`. Value `2`.
Parameters
none
const os_none
Purpose
Public constant `os_none`. Value `3`.
Parameters
none
const ev_none
Purpose
Public constant `ev_none`. Value `0`.
Parameters
none
const ev_ready
Purpose
Public constant `ev_ready`. Value `1`.
Parameters
none
const ev_exit
Purpose
Public constant `ev_exit`. Value `2`.
Parameters
none
const ev_before_exit
pub const ev_before_exit = 3
Purpose
Public constant `ev_before_exit`. Value `3`.
Parameters
none
const ev_close_requested
pub const ev_close_requested = 10
Purpose
Public constant `ev_close_requested`. Value `10`.
Parameters
none
const ev_closed
Purpose
Public constant `ev_closed`. Value `11`.
Parameters
none
const ev_focused
pub const ev_focused = 12
Purpose
Public constant `ev_focused`. Value `12`.
Parameters
none
const ev_blurred
pub const ev_blurred = 13
Purpose
Public constant `ev_blurred`. Value `13`.
Parameters
none
const ev_resized
pub const ev_resized = 14
Purpose
Public constant `ev_resized`. Value `14`.
Parameters
none
const ev_moved
Purpose
Public constant `ev_moved`. Value `15`.
Parameters
none
const ev_tray_clicked
pub const ev_tray_clicked = 30
Purpose
Public constant `ev_tray_clicked`. Value `30`.
Parameters
none
const ev_loading
pub const ev_loading = 40
Purpose
Public constant `ev_loading`. Value `40`.
Parameters
none
const ev_loaded
Purpose
Public constant `ev_loaded`. Value `41`.
Parameters
none
const ev_load_failed
pub const ev_load_failed = 42
Purpose
Public constant `ev_load_failed`. Value `42`.
Parameters
none
const ev_progress
pub const ev_progress = 43
Purpose
Public constant `ev_progress`. Value `43`.
Parameters
none
const ev_file_drop
pub const ev_file_drop = 50
Purpose
Public constant `ev_file_drop`. Value `50`.
Parameters
none
const ev_file_picked
pub const ev_file_picked = 51
Purpose
Public constant `ev_file_picked`. Value `51`.
Parameters
none
const ev_file_saved
pub const ev_file_saved = 52
Purpose
Public constant `ev_file_saved`. Value `52`.
Parameters
none
const ev_external_nav
pub const ev_external_nav = 53
Purpose
Public constant `ev_external_nav`. Value `53`.
Parameters
none
const ev_screenshot
pub const ev_screenshot = 54
Purpose
Public constant `ev_screenshot`. Value `54`.
Parameters
none
const ev_folder_picked
pub const ev_folder_picked = 55
Purpose
Public constant `ev_folder_picked`. Value `55`.
Parameters
none
const ev_alert
Purpose
Public constant `ev_alert`. Value `56`.
Parameters
none
const ev_confirm
pub const ev_confirm = 57
Purpose
Public constant `ev_confirm`. Value `57`.
Parameters
none
const ev_notify
Purpose
Public constant `ev_notify`. Value `58`.
Parameters
none
const ev_close_rejected
pub const ev_close_rejected = 59
Purpose
Public constant `ev_close_rejected`. Value `59`.
Parameters
none
const ev_cache_cleared
pub const ev_cache_cleared = 60
Purpose
Public constant `ev_cache_cleared`. Value `60`.
Parameters
none
const ev_download
pub const ev_download = 61
Purpose
Public constant `ev_download`. Value `61`.
Parameters
none
const ev_download_failed
pub const ev_download_failed = 62
Purpose
Public constant `ev_download_failed`. Value `62`.
Parameters
none
const ev_cookies_cleared
pub const ev_cookies_cleared = 63
Purpose
Public constant `ev_cookies_cleared`. Value `63`.
Parameters
none
const ev_cookie_set
pub const ev_cookie_set = 64
Purpose
Public constant `ev_cookie_set`. Value `64`.
Parameters
none
const ev_clipboard
pub const ev_clipboard = 65
Purpose
Public constant `ev_clipboard`. Value `65`.
Parameters
none
const ev_bounds
Purpose
Public constant `ev_bounds`. Value `66`.
Parameters
none
const ev_state
Purpose
Public constant `ev_state`. Value `67`.
Parameters
none
const ev_click
Purpose
Public constant `ev_click`. Value `68`.
Parameters
none
const ev_prompt
Purpose
Public constant `ev_prompt`. Value `69`.
Parameters
none
const ev_scroll
Purpose
Public constant `ev_scroll`. Value `70`.
Parameters
none
const ev_drag
Purpose
Public constant `ev_drag`. Value `71`.
Parameters
none
struct Event
pub struct Event {
pub kind int
pub window_id int
pub menu_id string
pub width int
pub height int
}
Purpose
Public struct `Event`.
Parameters
kind int- kind tag
window_id int- field (int)
menu_id string- field (string)
width int- field (int)
height int- field (int)
struct Icon
pub struct Icon {
pub path string
}
Purpose
Public struct `Icon`.
Parameters
path string- filesystem path
struct WindowOpts
pub struct WindowOpts {
pub title string
pub width int
pub height int
}
Purpose
Public struct `WindowOpts`.
Parameters
title string- field (string)
width int- field (int)
height int- field (int)
struct Window
pub struct Window {
pub id int
pub title string
pub width int
pub height int
pub content_kind int
pub content_backend_id int
pub closed int
}
Purpose
Public struct `Window`.
Parameters
id int- field (int)
title string- field (string)
width int- field (int)
height int- field (int)
content_kind int- field (int)
content_backend_id int- field (int)
closed int- field (int)
struct TrayOpts
pub struct TrayOpts {
pub tip string
pub icon Icon
pub menu Menu
}
Purpose
Public struct `TrayOpts`.
Parameters
tip string- field (string)
icon Icon- field (Icon)
menu Menu- field (Menu)
struct Tray
pub struct Tray {
pub id int
pub tip string
}
Purpose
Public struct `Tray`.
Parameters
id int- field (int)
tip string- field (string)
struct App
pub struct App {
pub next_id int
pub icon Icon
pub quit_flag int
pub sim int
pub event_ch chan Event
pub post_ch chan int
pub menu_ids []string
pub win_title string
pub win_w int
pub win_h int
}
Purpose
Public struct `App`.
Parameters
next_id int- field (int)
icon Icon- field (Icon)
quit_flag int- field (int)
sim int- field (int)
event_ch chan Event- field (channel; type chan Event)
post_ch chan int- field (channel; type chan int)
menu_ids []string- field ([]string)
win_title string- field (string)
win_w int- field (int)
win_h int- field (int)
new_app
Purpose
Construct app.
Parameters
none
Returns
App — a value of this type
new_app_events
pub fn new_app_events(ech chan Event) App
Purpose
new_app_events shares `ech` with IPC / draw workers. Host events are pumped here (not in #ui/webview.bind_ipc).
Parameters
ech chan Event- ech (channel; type chan Event)
Returns
App — a value of this type
icon_default
pub fn icon_default() Icon
Purpose
Icon default.
Parameters
none
Returns
Icon — a value of this type
icon_from_file
pub fn icon_from_file(path string) Icon
Purpose
Icon from file.
Parameters
path string- filesystem path (string)
Returns
Icon — a value of this type
target_os
Purpose
Target os.
Parameters
none
Returns
int — a value of this type
platform_supported
pub fn platform_supported() bool
Purpose
Platform supported.
Parameters
none
Returns
bool — true or false
(&mut App) alloc_id
pub fn (a &mut App) alloc_id() int
Purpose
Method on `&mut App`: alloc id.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
Returns
int — a value of this type
(&mut App) set_icon
pub fn (a &mut App) set_icon(icon Icon)
Purpose
Method on `&mut App`: set icon.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
icon Icon- icon (Icon)
install_tray_icon
pub fn install_tray_icon(path string) int
Purpose
Install tray icon. Throws on failure.
Parameters
path string- filesystem path (string)
Returns
int — a value of this type
(&mut App) new_window
pub fn (a &mut App) new_window(opts WindowOpts) Window
Purpose
Method on `&mut App`: construct window.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
opts WindowOpts- opts (WindowOpts)
Returns
Window — a value of this type
install_tray
pub fn install_tray(tip string, m Menu) int
Purpose
Install tray. Throws on failure.
Parameters
tip string- tip (string)
m Menu- m (Menu)
Returns
int — a value of this type
(&mut App) new_tray
pub fn (a &mut App) new_tray(opts TrayOpts) Tray
Purpose
Method on `&mut App`: construct tray.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
opts TrayOpts- opts (TrayOpts)
Returns
Tray — a value of this type
(&mut Window) set_title
pub fn (w &mut Window) set_title(title string)
Purpose
Method on `&mut Window`: set title.
Parameters
w &mut Window- receiver &mut Window (exclusive borrow)
title string- title (string)
native_set_title
pub fn native_set_title(title string) int
Purpose
native_set_title updates the live host title file (no Window handle needed). Throws on failure.
Parameters
title string- title (string)
Returns
int — a value of this type
native_set_size
pub fn native_set_size(width int, height int) int
Purpose
native_set_size updates live window size (host polls xu_ui_size.txt). Throws on failure.
Parameters
width int- width (int)
height int- height (int)
Returns
int — a value of this type
append_shell_cmd
pub fn append_shell_cmd(line string) int
Purpose
Append shell cmd. Throws on failure.
Parameters
line string- line (string)
Returns
int — a value of this type
append_content_cmd
pub fn append_content_cmd(line string) int
Purpose
Content-backend cmds (#ui/webview / #ui/draw / …). Prefer this for non-shell backends. Throws on failure.
Parameters
line string- line (string)
Returns
int — a value of this type
append_wv_cmd
pub fn append_wv_cmd(line string) int
Purpose
Alias: webview historically used the "wv." prefix (still accepted by host). Throws on failure.
Parameters
line string- line (string)
Returns
int — a value of this type
host_enabled
pub fn host_enabled() bool
Purpose
Host enabled.
Parameters
none
Returns
bool — true or false
host_tmp
Purpose
Host tmp.
Parameters
none
Returns
string — result string
native_show
Purpose
Native show. Throws on failure.
Parameters
none
Returns
int — a value of this type
native_hide
Purpose
Native hide. Throws on failure.
Parameters
none
Returns
int — a value of this type
native_minimize
pub fn native_minimize() int
Purpose
Native minimize. Throws on failure.
Parameters
none
Returns
int — a value of this type
native_set_position
pub fn native_set_position(x int, y int) int
Purpose
Native set position. Throws on failure.
Parameters
x int- value (int)
y int- value (int)
Returns
int — a value of this type
native_set_fullscreen
pub fn native_set_fullscreen(on int) int
Purpose
Native set fullscreen. Throws on failure.
Parameters
on int- on (int)
Returns
int — a value of this type
native_set_floating
pub fn native_set_floating(on int) int
Purpose
Native set floating. Throws on failure.
Parameters
on int- on (int)
Returns
int — a value of this type
native_center
pub fn native_center() int
Purpose
Native center. Throws on failure.
Parameters
none
Returns
int — a value of this type
native_open_external
pub fn native_open_external(url string) int
Purpose
Native open external. Throws on failure.
Parameters
url string- url (string)
Returns
int — a value of this type
native_clipboard_set
pub fn native_clipboard_set(text string) int
Purpose
Native clipboard set. Throws on failure.
Parameters
text string- text (string)
Returns
int — a value of this type
native_clipboard_get
pub fn native_clipboard_get() string
Purpose
Posts clipboard_get. Result arrives as shell event `clipboard\t…` → emit (XUN post).
Parameters
none
Returns
string — result string
native_set_maximized
pub fn native_set_maximized(on int) int
Purpose
Native set maximized. Throws on failure.
Parameters
on int- on (int)
Returns
int — a value of this type
native_bounce
pub fn native_bounce() int
Purpose
Native bounce. Throws on failure.
Parameters
none
Returns
int — a value of this type
native_pick_file
pub fn native_pick_file() string
Purpose
Posts pick_file. Result: shell event `file_picked\tpath` (empty path = cancel).
Parameters
none
Returns
string — result string
native_set_opacity
pub fn native_set_opacity(percent int) int
Purpose
Native set opacity. Throws on failure.
Parameters
percent int- percent (int)
Returns
int — a value of this type
native_save_file
pub fn native_save_file(suggested_name string) string
Purpose
Posts save_file. Result: shell event `file_saved\tpath`.
Parameters
suggested_name string- suggested_name (string)
Returns
string — result string
native_screenshot
pub fn native_screenshot() string
Purpose
Posts screenshot. Result: shell event `screenshot\tpath`.
Parameters
none
Returns
string — result string
native_alert
pub fn native_alert(title string, message string) int
Purpose
Posts alert. Completion: shell event `alert\tok`.
Parameters
title string- title (string)
message string- message (string)
Returns
int — a value of this type
native_confirm
pub fn native_confirm(title string, message string) int
Purpose
Posts confirm. Result: shell event `confirm\t1|0`.
Parameters
title string- title (string)
message string- message (string)
Returns
int — a value of this type
native_notify
pub fn native_notify(title string, body string) int
Purpose
Native notify.
Parameters
title string- title (string)
body string- body (string)
Returns
int — a value of this type
native_pick_folder
pub fn native_pick_folder() string
Purpose
Posts pick_folder. Result: shell event `folder_picked\tpath`.
Parameters
none
Returns
string — result string
native_set_min_size
pub fn native_set_min_size(width int, height int) int
Purpose
Native set min size. Throws on failure.
Parameters
width int- width (int)
height int- height (int)
Returns
int — a value of this type
native_set_resizable
pub fn native_set_resizable(on int) int
Purpose
Native set resizable. Throws on failure.
Parameters
on int- on (int)
Returns
int — a value of this type
native_get_bounds
pub fn native_get_bounds() string
Purpose
Posts get_bounds. Result: shell event `bounds\t…`.
Parameters
none
Returns
string — result string
native_set_titlebar_visible
pub fn native_set_titlebar_visible(on int) int
Purpose
Native set titlebar visible.
Parameters
on int- on (int)
Returns
int — a value of this type
native_set_close_guard
pub fn native_set_close_guard(on int) int
Purpose
Native set close guard.
Parameters
on int- on (int)
Returns
int — a value of this type
native_accept_close
pub fn native_accept_close() int
Purpose
Native accept close.
Parameters
none
Returns
int — a value of this type
native_reject_close
pub fn native_reject_close() int
Purpose
Native reject close.
Parameters
none
Returns
int — a value of this type
native_set_visible_on_all_spaces
pub fn native_set_visible_on_all_spaces(on int) int
Purpose
Native set visible on all spaces.
Parameters
on int- on (int)
Returns
int — a value of this type
native_get_state
pub fn native_get_state() string
Purpose
Posts get_state. Result: shell event `state\t…`.
Parameters
none
Returns
string — result string
native_open_path
pub fn native_open_path(path string) int
Purpose
Native open path.
Parameters
path string- filesystem path (string)
Returns
int — a value of this type
native_reveal_path
pub fn native_reveal_path(path string) int
Purpose
Native reveal path.
Parameters
path string- filesystem path (string)
Returns
int — a value of this type
native_set_appearance
pub fn native_set_appearance(mode string) int
Purpose
"dark" | "light" | "system"
Parameters
mode string- mode (string)
Returns
int — a value of this type
native_set_dock_badge
pub fn native_set_dock_badge(text string) int
Purpose
Native set dock badge.
Parameters
text string- text (string)
Returns
int — a value of this type
native_screenshot_to_clipboard
pub fn native_screenshot_to_clipboard() int
Purpose
Native screenshot to clipboard.
Parameters
none
Returns
int — a value of this type
native_set_shadow
pub fn native_set_shadow(on int) int
Purpose
Native set shadow.
Parameters
on int- on (int)
Returns
int — a value of this type
native_set_frameless
pub fn native_set_frameless(on int) int
Purpose
Frameless shell (no system titlebar/chrome). Prefer with transparent + mask for shaped windows.
Parameters
on int- on (int)
Returns
int — a value of this type
native_set_transparent
pub fn native_set_transparent(on int) int
Purpose
Transparent window / client background (needed for PNG alpha shaped windows).
Parameters
on int- on (int)
Returns
int — a value of this type
native_set_window_mask
pub fn native_set_window_mask(path string) int
Purpose
PNG alpha mask: opaque pixels visible + hit-test; alpha≈0 click-through. macOS AppKit / Linux GTK4 / Windows Win32+GDI+ UpdateLayeredWindow. Throws on failure.
Parameters
path string- filesystem path (string)
Returns
int — a value of this type
native_clear_window_mask
pub fn native_clear_window_mask() int
Purpose
Native clear window mask.
Parameters
none
Returns
int — a value of this type
native_quit
Purpose
Ask the native host to quit (frameless windows have no red close button). Throws on failure.
Parameters
none
Returns
int — a value of this type
unsupported_msg
pub fn unsupported_msg() string
Purpose
Unsupported msg.
Parameters
none
Returns
string — result string
(&mut Window) set_content_slot
pub fn (w &mut Window) set_content_slot(kind int, backend_id int)
Purpose
Method on `&mut Window`: set content slot.
Parameters
w &mut Window- receiver &mut Window (exclusive borrow)
kind int- kind tag (int)
backend_id int- backend_id (int)
(Window) content_slot_kind
pub fn (w Window) content_slot_kind() int
Purpose
Method on `Window`: content slot kind.
Parameters
w Window- receiver Window (value receiver)
Returns
int — a value of this type
(Window) content_slot_backend_id
pub fn (w Window) content_slot_backend_id() int
Purpose
Method on `Window`: content slot backend id.
Parameters
w Window- receiver Window (value receiver)
Returns
int — a value of this type
(&mut Window) close
pub fn (w &mut Window) close()
Purpose
Method on `&mut Window`: close the resource.
Parameters
w &mut Window- receiver &mut Window (exclusive borrow)
(&mut App) quit
pub fn (a &mut App) quit()
Purpose
Call `quit` on `&mut App`.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
(&mut App) push_event
pub fn (a &mut App) push_event(ev Event)
Purpose
Method on `&mut App`: push event.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
ev Event- ev (Event)
(&mut App) poll_event
pub fn (a &mut App) poll_event() Event
Purpose
Method on `&mut App`: poll event.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
Returns
Event — a value of this type
(&mut App) post
pub fn (a &mut App) post(token int)
Purpose
Call `post` on `&mut App`.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
token int- token (int)
(&mut App) try_recv_post
pub fn (a &mut App) try_recv_post() int
Purpose
Method on `&mut App`: try recv post.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
Returns
int — a value of this type
content_plugin_webview
pub fn content_plugin_webview() ContentPlugin
Purpose
Default webview ContentPlugin (per-OS host sources). Used by #ui/webview.attach.
Parameters
none
Returns
ContentPlugin — a value of this type
content_plugin_draw
pub fn content_plugin_draw() ContentPlugin
Purpose
Direct-draw content plugin (no WebKit). Same registration shape as webview.
Parameters
none
Returns
ContentPlugin — a value of this type
use_draw_content
pub fn use_draw_content(w &mut Window) int
Purpose
Attach draw backend to a window slot and register the plugin for App.run.
Parameters
w &mut Window- writer or width (exclusive borrow; type &mut Window)
Returns
int — a value of this type
native_draw_set_bg
pub fn native_draw_set_bg(hex string) int
Purpose
Draw-plugin cmds (content_draw). Hex like "#3366cc" or "3366cc". Canvas API (immediate-mode 2D, Love2D/Raylib-style): `#ui/draw`. Throws on failure.
Parameters
hex string- hex (string)
Returns
int — a value of this type
native_draw_clear
pub fn native_draw_clear() int
Purpose
Native draw clear. Throws on failure.
Parameters
none
Returns
int — a value of this type
native_draw_set_label
pub fn native_draw_set_label(text string) int
Purpose
Native draw set label. Throws on failure.
Parameters
text string- text (string)
Returns
int — a value of this type
register_content_plugin
pub fn register_content_plugin(p ContentPlugin) int
Purpose
Register a content backend before App.run. Spec carries macOS / Linux / Windows sources separately — shell never hardcodes a backend or a single-OS path. Future draw / native views use the same shape.
Parameters
p ContentPlugin- p (ContentPlugin)
Returns
int — a value of this type
(&mut App) run
pub fn (a &mut App) run() int
Purpose
Call `run` on `&mut App`. Throws on failure.
Parameters
a &mut App- receiver &mut App (exclusive borrow)
Returns
int — a value of this type
load_asset
pub fn load_asset(path string) string
Purpose
Load asset. Throws on failure.
Parameters
path string- filesystem path (string)
Returns
string — result string
push_host_event
pub fn push_host_event(ech chan Event, pl0 string)
Purpose
Push host event.
Parameters
ech chan Event- ech (channel; type chan Event)
pl0 string- pl0 (string)
drain_host_events
pub fn drain_host_events(ech chan Event)
Purpose
Drain host events.
Parameters
ech chan Event- ech (channel; type chan Event)
poll_chan
pub fn poll_chan(ech chan Event) Event
Purpose
Poll chan.
Parameters
ech chan Event- ech (channel; type chan Event)
Returns
Event — a value of this type