const CONTENT_NONE
pub const CONTENT_NONE = 0用途
常量 CONTENT_NONE,定义了相关的协议或算法配置参数。
#uiWidgets 组件目录:按组件阅读 API,并在演练场体验
移动端布局、触摸路由和系统输入法见 #ui/phone。
窗口、事件、结构化菜单、屏幕和异步桌面服务。一个 worker 消费 App.event_ch;用 window_id / canvas_id / generation 校验目标。ev_request 经 request_of 解码,使用 RequestResult.matches 与请求匹配;处理 completed、cancelled、failed、unsupported 和 timed_out。屏幕坐标与画布坐标不可混用。
正式版示例(完整工程与源码下载):desktop_services · multiwindow
以下源码来自官方 examples 仓库,可复制或下载。请在完整工程中使用本地 Xu SDK 运行;网络、数据库和桌面示例需要对应的服务或资源。
16_ui_webview/shaped/main.xu@main
#ui
// Shaped window: frameless + transparent + PNG alpha mask (macOS / Linux / Windows).
// Chrome flags are written BEFORE App.run() so the first frame has no titlebar.
// xu build examples/16ui_webview/shaped --target macos-arm64 --desktop -o /tmp/xu_shaped
// /tmp/xu_shaped
fn main() int {
$app := ui.new_app()
// Pack diagnostics: shim sets XU_PACK_TRACE beside the exe.
t := env_get("XU_PACK_TRACE")
if t.len > 0 {
_ := write_file(t, "shaped main begin\n") >>> (err) {
<< 0
}
}
$win := app.new_window(ui.WindowOpts{title: "Xu Shaped", width: 320, height: 320})
a0 := ui.native_set_frameless(1)
a1 := ui.native_set_transparent(1)
a2 := ui.native_set_window_mask("brand/xu_app_logo.png") >>> (err) {
if t.len > 0 {
_ := write_file(t, "mask fail: " + err.msg() + "\n") >>> (err2) {
<< 0
}
}
println(err.msg())
<< 1
}
a3 := ui.native_set_shadow(1)
if a0 + a1 + a2 + a3 < 0 {
<< 1
}
if t.len > 0 {
_ := write_file(t, "shaped before app.run\n") >>> (err) {
<< 0
}
}
println("shaped window — no titlebar; Esc or right-click Close; mask brand/xu_app_logo.png")
app.run() >>> (err) {
println(err.msg())
<< 1
}
<< 0
}16_ui_webview/webview_requests/main.xu@main
#ui
#ui/webview
fn route(request webview.InvokeRequest) string {
if request.name == "slow" { sleep_ns(300000000) }
if request.name == "wait" { sleep_ns(1500000000) }
if request.name == "native" {
target := ui.CanvasEvent{window_id: request.window_id,canvas_id: request.window_id,generation: request.generation}
options := ui.RequestOptions{timeout_ms: 2000}
script := "document.title"
result := ui.webview_request_wait(&target,ui.REQUEST_WEBVIEW_EVAL,&script,&options) >>> (err) { << "failed: " + err.msg() }
if result.status != ui.REQUEST_COMPLETED { << "status: " + str(result.status) }
<< result.value + ""
}
<< request.payload + ""
}
fn ipc(emit_ch chan string,ech chan ui.Event) {
webview.bind_ipc_requests_www(":mem:",route,emit_ch,ech) >>> (err) { eprintln(err.msg())
<< }
}
fn events(ech chan ui.Event,emit_ch chan string) {
while true { event := <-ech
if event.kind == ui.EV_EXIT { emit_ch <- ""
<< }
if event.kind == ui.EV_CLOSED { println("Window closed; pending document requests revoked") }
}
}
fn run() int {
ech := chan ui.Event{cap: 1024}
emit_ch := chan string{cap: 64}
$app := ui.new_app_events(ech)
webview.stage_www_root(":mem:") >>>
xu ipc(emit_ch,ech)
xu events(ech,emit_ch)
$window := app.new_window(ui.WindowOpts{title: "Xu UI / WebView Request Lifecycle",width: 880,height: 640})
$browser := webview.attach($&window)
browser.load_url(webview.app_scheme_url()) >>>
<< app.run() >>>
}
fn main() int { << run() >>> (err) { eprintln(err.msg())
<< 1 } }16_ui_webview/draw/main.xu@main
#ui
#ui/draw
demo #"github.com/xulang-org/examples/ui_demo"
fn paint(context &draw.Context,frame $&draw.Frame,hits int) int {
frame.begin() >>>
frame.set_bg(demo.background()) >>>
demo.text(context,frame,32.0,28.0,14.0,demo.accent(),"01 / FRAME RECORDER") >>>
demo.text(context,frame,32.0,58.0,30.0,demo.ink(),"Draw a frame. Submit once.") >>>
demo.text(context,frame,32.0,108.0,15.0,demo.muted(),"Click the teal circle. Resize the window. Escape closes it.") >>>
frame.set_fill(demo.accent()) >>>
frame.circle(112.0,228.0,52.0) >>>
frame.stroke_rect(200.5,176.5,128.0,104.0,draw.rgb(240,180,91),2.0) >>>
frame.push() >>>
frame.clip_rect(376.0,168.0,216.0,120.0) >>>
frame.translate(478.0,226.0) >>>
frame.rotate(18.0) >>>
frame.fill_rect(-100.0,-42.0,200.0,84.0,draw.rgb(92,127,203)) >>>
frame.pop() >>>
demo.text(context,frame,32.0,330.0,20.0,demo.ink(),"Circle activations: " + str(hits)) >>>
demo.text(context,frame,32.0,370.0,13.0,demo.muted(),"Logical coordinates / state stack / clipping / one present") >>>
frame.present() >>>
println("Frame submitted: " + str(frame.command_count()) + " commands / " + str(frame.byte_len()) + " bytes")
<< 0
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT { << 0 }
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
$frame := context.new_frame(4096)
$hits := 0
$pressed := false
paint(&context,$&frame,hits) >>>
while true {
event := demo.next(ech)
if event.kind == ui.EV_EXIT { <- }
if event.window_id != identity.window_id { -> }
if event.kind == ui.EV_CANVAS_CLOSED { <- }
if event.kind == ui.EV_BLURRED { pressed = false }
if event.kind == ui.EV_CANVAS_METRICS { paint(&context,$&frame,hits) >>> }
if ui.is_input_event(event.kind) {
input := ui.input_of(&event) >>>
if input.generation != identity.generation { -> }
if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE { demo.quit() >>> }
dx := input.x - 112.0
dy := input.y - 228.0
inside := dx * dx + dy * dy <= 2704.0
if input.kind == ui.EV_POINTER_DOWN && input.button == ui.BUTTON_LEFT { pressed = inside }
if input.kind == ui.EV_POINTER_CANCEL { pressed = false }
if input.kind == ui.EV_POINTER_UP && input.button == ui.BUTTON_LEFT {
if pressed && inside { hits = hits + 1
paint(&context,$&frame,hits) >>> }
pressed = false
}
}
}
frame.dispose()
<< 0
}
fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
<< } }
fn launch() int {
$app := demo.app("Xu UI / Frame",680,430) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) { eprintln(err.msg())
<< 1 } }16_ui_webview/shaped_webview/main.xu@main
#ui
#ui/webview
// Frameless + PNG mask + WKWebView (macOS).
// xu build examples/16ui_webview/shaped_webview --target macos-arm64 --desktop -o /tmp/xu_shaped_wv
// /tmp/xu_shaped_wv
// Drag from the top ~28px strip; Close calls shell.quit.
fn route(name string, payload string) string {
if name == "ping" {
<< "pong:" + payload
}
if name == "greet" {
<< "hello, " + payload
}
if name == "win" {
if payload == "quit" {
q := ui.native_quit() >>> (err) { << "err" }
<< "quit"
}
if payload == "minimize" {
m := ui.native_minimize() >>> (err) { << "err" }
<< "minimized"
}
<< "win?"
}
<< "miss"
}
fn demo_www() string {
<< "www"
}
fn ipc_boot(emit_ch chan string, shell_ch chan ui.Event) {
webview.bind_ipc_www(demo_www(), route, emit_ch, shell_ch) >>> (err) {
eprintln(err.msg())
<<
}
}
fn main() int {
emit_ch := chan string{cap: 32}
shell_ch := chan ui.Event{cap: 32}
$app := ui.new_app_events(shell_ch)
app.set_icon(ui.icon_from_file("brand/xu_app_logo.png"))
webview.stage_www_root(demo_www()) >>> (err) {
println(err.msg())
<< 1
}
xu ipc_boot(emit_ch, shell_ch)
sleep_ns(50000000)
$win := app.new_window(ui.WindowOpts{title: "Xu Shaped WebView", width: 360, height: 360})
r := $&win
$wv := webview.attach(r)
wv.on("ping")
wv.on("greet")
wv.on("win")
a0 := ui.native_set_frameless(1)
a1 := ui.native_set_transparent(1)
a2 := ui.native_set_window_mask("brand/xu_app_logo.png") >>> (err) {
println(err.msg())
<< 1
}
a3 := ui.native_set_shadow(1)
if a0 + a1 + a2 + a3 < 0 {
<< 1
}
wv.load_url("xu://app/shaped.html") >>> (err) {
println(err.msg())
<< 1
}
println("shaped webview — xu://app/shaped.html XUN IPC (drag top; Close quits)")
app.run() >>> (err) {
println(err.msg())
<< 1
}
<< 0
}16_ui_webview/multiwindow/main.xu@main
#ui
#ui/draw
demo #"github.com/xulang-org/examples/ui_demo"
fn paint(window ui.Window,count int) int {
context := draw.window_context(&window) >>>
$frame := context.new_frame(2048)
frame.begin() >>>
frame.set_bg(demo.background()) >>>
demo.text(&context,$&frame,26.0,28.0,14.0,demo.accent(),"06 / INDEPENDENT WINDOWS") >>>
demo.text(&context,$&frame,26.0,64.0,27.0,demo.ink(),"Window " + str(window.id)) >>>
demo.text(&context,$&frame,26.0,116.0,17.0,demo.ink(),"Clicks in this window: " + str(count)) >>>
demo.text(&context,$&frame,26.0,172.0,14.0,demo.muted(),"N: new window / W: close this window") >>>
demo.text(&context,$&frame,26.0,208.0,14.0,demo.muted(),"F: focus first window / R: resize / Escape: quit all") >>>
demo.text(&context,$&frame,26.0,258.0,13.0,demo.muted(),"One event channel. Each canvas owns its resources.") >>>
frame.present() >>>
frame.dispose()
<< 0
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT { << 0 }
identity := ui.canvas_of(&ready) >>>
$app := demo.windows(ech)
first := ui.Window{id: identity.window_id,generation: identity.generation,title: "Xu UI / Window 1",width: 560,height: 340,content_kind: ui.CONTENT_DRAW,content_backend_id: identity.canvas_id,closed: 0}
$windows := []ui.Window{}
windows.push(first)
$counts := [0]
paint(windows[0],0) >>>
while true {
event := demo.next(ech)
if event.kind == ui.EV_EXIT { <- }
$index := -1
for i in 0:windows.len { if windows[i].id == event.window_id { index = i } }
if index < 0 { -> }
if event.kind == ui.EV_CANVAS_READY {
window := windows[index]
window.content_command("input_enabled\t1") >>>
window.content_command("pan_enabled\t0") >>>
println("Canvas ready: " + str(event.window_id))
paint(window,counts[index]) >>> }
if event.kind == ui.EV_CANVAS_METRICS { paint(windows[index],counts[index]) >>> }
if event.kind == ui.EV_CLOSED { windows[index].closed = 1 }
if event.kind == ui.EV_WINDOW_FAILED { windows[index].closed = 1
eprintln("Native window creation failed: " + event.menu_id) }
if !ui.is_input_event(event.kind) { -> }
input := ui.input_of(&event) >>>
if input.generation != windows[index].generation || windows[index].closed != 0 { -> }
if input.kind == ui.EV_POINTER_UP && input.button == ui.BUTTON_LEFT {
counts[index] = counts[index] + 1
println("Window " + str(event.window_id) + " count: " + str(counts[index]))
paint(windows[index],counts[index]) >>>
}
if input.kind != ui.EV_KEY_DOWN || input.repeat != 0 { -> }
if input.key == ui.KEY_ESCAPE { demo.quit() >>> }
if input.key == 78 || input.key == 110 {
// At most six demo windows; the host's own limit is independent.
$live := 0
for window in windows { if window.closed == 0 { live = live + 1 } }
if live < 6 {
window := app.open_content_window(ui.WindowOpts{title: "Xu UI / Additional Window",width: 560,height: 340},ui.CONTENT_DRAW) >>>
windows.push(window)
counts.push(0)
}
}
if input.key == 87 || input.key == 119 {
$window := windows[index]
window.request_close() >>>
windows[index] = window
}
if input.key == 82 || input.key == 114 {
$window := windows[index]
window.resize(660,400) >>>
windows[index] = window
}
if input.key == 70 || input.key == 102 {
for window in windows { if window.closed == 0 { window.focus() >>>
<- } }
}
}
<< 0
}
fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
<< } }
fn launch() int {
$app := demo.app("Xu UI / Window 1",560,340) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) { eprintln(err.msg())
<< 1 } }16_ui_webview/remote/main.xu@main
#ui
#ui/webview
// Remote HTTP document + xu:// IPC.
// 1) python3 examples/16ui_webview/remote_http/serve.py
// 2) xu build examples/16ui_webview/remote --target macos-arm64 --desktop -o /tmp/xu_remote
// 3) /tmp/xu_remote
// Optional: XU_UI_REMOTE_URL=http://127.0.0.1:8765/
fn route(name string, payload string) string {
if name == "ping" {
<< "pong:" + payload
}
if name == "greet" {
<< "hello, " + payload
}
<< "unknown:" + name
}
fn demo_www() string {
<< "www"
}
fn remote_url() string {
u := env_get("XU_UI_REMOTE_URL")
if u.len > 0 {
<< u + ""
}
<< "http://127.0.0.1:8765/"
}
fn ipc_boot(emit_ch chan string, shell_ch chan ui.Event) {
// Still stage www + bridge so xu://app/__xu works; main document is remote.
webview.bind_ipc_www(demo_www(), route, emit_ch, shell_ch) >>> (err) {
eprintln(err.msg())
<<
}
}
fn tick_loop(emit_ch chan string) {
$n := 0
while true {
sleep_ns(3000000000)
n = n + 1
webview.bus_emit(emit_ch, "tick", str(n))
}
}
fn watch_shell(shell_ch chan ui.Event) {
while true {
ev := <-shell_ch
if ev.kind == ui.EV_EXIT || ev.kind == ui.EV_CLOSED {
println("shell event kind=" + str(ev.kind))
} else if ev.kind == ui.EV_LOADED {
println("shell event loaded")
} else if ev.kind == ui.EV_LOAD_FAILED {
println("shell event load_failed")
} else if ev.kind == ui.EV_READY {
println("shell event ready")
}
}
}
fn main() int {
emit_ch := chan string{cap: 32}
shell_ch := chan ui.Event{cap: 32}
$app := ui.new_app_events(shell_ch)
app.set_icon(ui.icon_from_file("brand/xu_app_logo.png"))
url := remote_url()
xu watch_shell(shell_ch)
xu ipc_boot(emit_ch, shell_ch)
xu tick_loop(emit_ch)
sleep_ns(50000000)
$win := app.new_window(ui.WindowOpts{title: "Xu Remote HTTP + xu:// IPC", width: 720, height: 520})
r := $&win
$wv := webview.attach(r)
wv.on("ping")
wv.on("greet")
url2 := url + ""
wv.load_remote(url2) >>> (err) {
println(err.msg())
<< 1
}
println("remote document " + url + " — IPC via xu://app/__xu (start remote_http/serve.py first)")
app.run() >>> (err) {
println(err.msg())
<< 1
}
<< 0
}16_ui_webview/draw_gallery/main.xu@main
#ui
#ui/draw
demo #"github.com/xulang-org/examples/ui_demo"
fn paint_vector_showcase(context &draw.Context, fragment $&draw.Frame) int {
demo.text(context, fragment, 32.0, 396.0, 14.0, demo.accent(), "03 / HIGH-LEVEL VECTOR PRIMITIVES & COLOR TOOLS") >>>
teal := draw.hex("#14B8A6") >>>
indigo := draw.hex("#6366F1") >>>
amber := draw.hsl(38.0, 0.92, 0.58)
coral := draw.lerp_color(amber, draw.hex("#F43F5E") >>>, 0.65)
card_grad := draw.two_stop_linear(32.0, 424.0, 224.0, 524.0, teal.darken(0.35), indigo.darken(0.35))
fragment.box_shadow(32.0, 424.0, 192.0, 100.0, 14.0, 0.0, 6.0, 12.0, 1.0, draw.rgba(0, 0, 0, 110)) >>>
fragment.fill_round_rect_gradient(32.0, 424.0, 192.0, 100.0, 14.0, &card_grad) >>>
fragment.stroke_round_rect(32.0, 424.0, 192.0, 100.0, 14.0, teal.lighten(0.35), 1.5) >>>
orb_grad := draw.two_stop_radial(82.0, 474.0, 30.0, teal.lighten(0.45), indigo)
fragment.fill_circle_gradient(82.0, 474.0, 28.0, &orb_grad) >>>
fragment.fill_capsule(126.0, 446.0, 82.0, 24.0, coral.with_opacity(0.88)) >>>
fragment.stroke_capsule(126.0, 480.0, 82.0, 24.0, amber, 1.8) >>>
fragment.fill_ring_sector(300.0, 474.0, 22.0, 46.0, -90.0, 210.0, teal) >>>
fragment.fill_ring_sector(300.0, 474.0, 22.0, 46.0, 120.0, 95.0, indigo) >>>
fragment.fill_sector(300.0, 474.0, 42.0, 225.0, 45.0, amber) >>>
fragment.arc(300.0, 474.0, 52.0, -45.0, 130.0, coral, 3.0) >>>
fragment.fill_regular_polygon(432.0, 474.0, 42.0, 6, -90.0, indigo.with_opacity(0.45)) >>>
fragment.stroke_regular_polygon(432.0, 474.0, 42.0, 6, -90.0, indigo.lighten(0.35), 2.0) >>>
fragment.fill_gear(432.0, 474.0, 26.0, 18.0, 9.0, 8, teal.with_opacity(0.85)) >>>
fragment.fill_star(536.0, 474.0, 44.0, 19.0, 5, -90.0, amber) >>>
fragment.stroke_star(536.0, 474.0, 44.0, 19.0, 5, -90.0, amber.lighten(0.45), 1.5) >>>
fragment.fill_shield(628.0, 474.0, 56.0, 68.0, coral.with_opacity(0.75)) >>>
fragment.stroke_shield(628.0, 474.0, 56.0, 68.0, coral.lighten(0.30), 1.8) >>>
fragment.checkmark(614.0, 460.0, 28.0, coral.contrasting_ink(demo.ink(), demo.background()), 2.4) >>>
fragment.grid(688.0, 424.0, 240.0, 100.0, 6, 4, demo.muted().with_opacity(0.25), 1.0) >>>
fragment.hatch_rect(688.0, 424.0, 240.0, 100.0, 16.0, false, indigo.with_opacity(0.18), 1.0) >>>
fragment.dashed_rect(688.0, 424.0, 240.0, 100.0, 6.0, 4.0, demo.muted().with_opacity(0.65), 1.2) >>>
vir_c := draw.sample_palette(draw.PALETTE_VIRIDIS, 0.72)
fragment.fill_ribbon(696.0, 488.0, 504.0, 812.0, 444.0, 460.0, vir_c.with_opacity(0.42)) >>>
spline_pts := [draw.path_point(700.0, 508.0), draw.path_point(744.0, 442.0), draw.path_point(792.0, 496.0),
draw.path_point(842.0, 436.0), draw.path_point(892.0, 482.0)]
fragment.smooth_curve(&spline_pts, 0.0, teal, 2.5) >>>
fragment.wave(700.0, 498.0, 196.0, 8.0, 48.0, 0.0, amber, 1.8) >>>
fragment.dashed_line(700.0, 464.0, 912.0, 464.0, 8.0, 5.0, coral, 1.8) >>>
fragment.double_arrow(868.0, 508.0, 916.0, 440.0, 10.0, demo.ink(), 2.0) >>>
<< 0
}
// This entire scene is recorded once; subsequent frames replay its resources.
fn record(context &draw.Context, image &draw.Image) draw.DisplayList {
$fragment := context.new_frame(8192)
fragment.begin() >>>
fragment.fill_rect(0.0, 0.0, 960.0, 548.0, draw.rgb(26, 37, 50)) >>>
demo.text(context, $&fragment, 24.0, 22.0, 18.0, demo.ink(), "Vectors / gradients / embedded PNG / shaped text / geometry builders") >>>
$path := draw.new_path(256)
path.move_to(40.0, 210.0) >>>
path.cubic_to(80.0, 60.0, 210.0, 60.0, 250.0, 210.0) >>>
path.quad_to(145.0, 300.0, 40.0, 210.0) >>>
path.close() >>>
stops := [draw.GradientStop{offset: 0.0, color: demo.accent()}, draw.GradientStop{offset: 1.0, color: draw.rgb(92, 127, 203)}]
gradient := draw.linear_gradient(20.0, 80.0, 260.0, 270.0, stops)
bounds := draw.ImageRect{x: 20.0, y: 70.0, width: 260.0, height: 230.0}
fragment.fill_path_gradient(&path, &gradient, &bounds, 2.0, draw.FILL_NONZERO) >>>
stroke := draw.stroke_options(2.0)
fragment.stroke_path(&path, demo.ink(), &stroke) >>>
fragment.image(image, 320.0, 88.0, 150.0, 150.0) >>>
source := draw.ImageRect{x: 0.0, y: 0.0, width: f64(image.width), height: f64(image.height)}
destination := draw.ImageRect{x: 510.0, y: 88.0, width: 190.0, height: 150.0}
fragment.image_region(image, &source, &destination, 0.45, draw.SAMPLER_NEAREST) >>>
demo.text(context, $&fragment, 320.0, 260.0, 14.0, demo.muted(), "Linear sampling Nearest / opacity") >>>
$options := draw.text_options(22.0)
options.width = 880.0
value := "你好,Xu · العربية · café · 👩💻\nOne native layout: shaping, fallback, wrapping and metrics."
$text := context.layout_text(&value, &options) >>>
fragment.text_layout(&text, 32.0, 318.0, demo.ink()) >>>
println("Text metrics: " + str(text.metrics.lines) + " lines")
layer := draw.ImageRect{x: 740.0, y: 80.0, width: 180.0, height: 200.0}
fragment.begin_layer(&layer, 2.0, 0.75) >>>
fragment.set_fill(draw.rgb(240, 180, 91)) >>>
fragment.circle(64.0, 80.0, 52.0) >>>
fragment.set_fill(draw.rgb(92, 127, 203)) >>>
fragment.circle(112.0, 112.0, 52.0) >>>
fragment.end_layer() >>>
demo.text(context, $&fragment, 740.0, 292.0, 14.0, demo.muted(), "Isolated group opacity") >>>
paint_vector_showcase(context, $&fragment) >>>
list := fragment.freeze() >>>
text.dispose() >>>
fragment.dispose()
<< list
}
fn paint(context &draw.Context, frame $&draw.Frame, list &draw.DisplayList, cache $&draw.SurfaceCache, density f64, cached bool) int {
frame.begin() >>>
frame.set_bg(demo.background()) >>>
demo.text(context, frame, 32.0, 24.0, 14.0, demo.accent(), "02 / RESOURCE GALLERY") >>>
demo.text(context, frame, 32.0, 54.0, 28.0, demo.ink(), "Record once. Reuse across frames.") >>>
frame.push() >>>
frame.translate(32.0, 104.0) >>>
if cached { frame.cached_display_list(cache, list, 0.0, 0.0, 960.0, 548.0, density, 1.0, draw.SAMPLER_LINEAR) >>> }
else { frame.display_list(list) >>> }
frame.pop() >>>
$mode := "vector replay"
if cached { mode = "raster cache" }
demo.text(context, frame, 32.0, 668.0, 15.0, demo.ink(), "Space: vector/cache / R: invalidate / current: " + mode) >>>
frame.present() >>>
println("Presented " + mode + ": " + str(frame.command_count()) + " frame commands")
<< 0
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT { << 0 }
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
path := "sample.png"
$image := context.load_embedded_image(&path) >>>
$list := record(&context, &image) >>>
$cache := draw.new_surface_cache()
$frame := context.new_frame(1024)
$density := 1.0
$cached := false
paint(&context, $&frame, &list, $&cache, density, cached) >>>
while true {
event := demo.next(ech)
if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
if event.window_id != identity.window_id { -> }
$dirty := false
if event.kind == ui.EV_CANVAS_METRICS {
metrics := ui.metrics_of(&event) >>>
density = metrics.scale_x
dirty = true
}
if ui.is_input_event(event.kind) {
input := ui.input_of(&event) >>>
if input.generation != identity.generation { -> }
if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
if input.key == 32 { cached = !cached
dirty = true }
if input.key == 82 || input.key == 114 { cache.invalidate()
dirty = true }
if input.key == ui.KEY_ESCAPE { demo.quit() >>> }
}
}
if dirty { paint(&context, $&frame, &list, $&cache, density, cached) >>> }
}
frame.dispose()
cache.dispose()
// Native close has already revoked all canvas-owned resources.
if demo.alive(&identity) {
list.dispose() >>>
image.dispose() >>>
}
<< 0
}
fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
<< } }
fn launch() int {
$app := demo.app("Xu UI / Resource Gallery", 1030, 720) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) { eprintln(err.msg())
<< 1 } }16_ui_webview/open/main.xu@main
#ui
#ui/webview
fn route(name string, payload string) string {
if name == "ping" {
<< "pong:" + payload
}
if name == "greet" {
<< "hello, " + payload
}
if name == "menu" {
<< "menu:" + payload
}
if name == "tray" {
<< "tray:" + payload
}
if name == "shell" {
<< "shell:" + payload
}
if name == "win" {
if payload == "hide" {
_ := ui.native_hide() >>> (err) { << "err" }
<< "hidden"
}
if payload == "show" {
_ := ui.native_show() >>> (err) { << "err" }
<< "shown"
}
if payload == "minimize" {
_ := ui.native_minimize() >>> (err) { << "err" }
<< "minimized"
}
if payload == "reload" {
_ := webview.native_reload() >>> (err) { << "err" }
<< "reloaded"
}
if payload == "float" {
_ := ui.native_set_floating(1) >>> (err) { << "err" }
<< "floating"
}
if payload == "unfloat" {
_ := ui.native_set_floating(0) >>> (err) { << "err" }
<< "unfloated"
}
if payload == "fullscreen" {
_ := ui.native_set_fullscreen(1) >>> (err) { << "err" }
<< "fullscreen"
}
if payload == "unfullscreen" {
_ := ui.native_set_fullscreen(0) >>> (err) { << "err" }
<< "unfullscreen"
}
if payload == "center" {
_ := ui.native_center() >>> (err) { << "err" }
<< "centered"
}
if payload == "devtools" {
_ := webview.native_open_devtools() >>> (err) { << "err" }
<< "devtools"
}
if payload == "zoom_in" {
_ := webview.native_set_zoom(125) >>> (err) { << "err" }
<< "zoom 125%"
}
if payload == "zoom_out" {
_ := webview.native_set_zoom(80) >>> (err) { << "err" }
<< "zoom 80%"
}
if payload == "zoom_100" {
_ := webview.native_set_zoom(100) >>> (err) { << "err" }
<< "zoom 100%"
}
if payload == "open_ext" {
_ := ui.native_open_external("https://example.com") >>> (err) { << "err" }
<< "opened browser"
}
if payload == "clip_set" {
_ := ui.native_clipboard_set("hello from Xu") >>> (err) { << "err" }
<< "clipboard set"
}
if payload == "clip_get" {
_ := ui.native_clipboard_get()
<< "clipboard:posted"
}
if payload == "back" {
_ := webview.native_go_back() >>> (err) { << "err" }
<< "back"
}
if payload == "forward" {
_ := webview.native_go_forward() >>> (err) { << "err" }
<< "forward"
}
if payload == "stop" {
_ := webview.native_stop() >>> (err) { << "err" }
<< "stop"
}
if payload == "maximize" {
_ := ui.native_set_maximized(1) >>> (err) { << "err" }
<< "maximized"
}
if payload == "unmaximize" {
_ := ui.native_set_maximized(0) >>> (err) { << "err" }
<< "unmaximized"
}
if payload == "bounce" {
_ := ui.native_bounce() >>> (err) { << "err" }
<< "bounce"
}
if payload == "pick" {
_ := ui.native_pick_file()
<< "pick:posted"
}
if payload == "save" {
_ := ui.native_save_file("xu-note.txt")
<< "save:posted"
}
if payload == "print" {
_ := webview.native_print() >>> (err) { << "err" }
<< "print"
}
if payload == "opacity_low" {
_ := ui.native_set_opacity(70) >>> (err) { << "err" }
<< "opacity 70%"
}
if payload == "opacity_full" {
_ := ui.native_set_opacity(100) >>> (err) { << "err" }
<< "opacity 100%"
}
if payload == "shot" {
_ := ui.native_screenshot()
<< "shot:posted"
}
if payload == "alert" {
_ := ui.native_alert("Xu", "Hello from alert")
<< "alert:posted"
}
if payload == "confirm" {
_ := ui.native_confirm("Xu", "Continue?")
<< "confirm:posted"
}
if payload == "notify" {
_ := ui.native_notify("Xu", "Desktop notification")
<< "notified"
}
if payload == "folder" {
_ := ui.native_pick_folder()
<< "folder:posted"
}
if payload == "minsize" {
_ := ui.native_set_min_size(480, 320) >>> (err) { << "err" }
<< "minsize 480x320"
}
if payload == "lock_size" {
_ := ui.native_set_resizable(0) >>> (err) { << "err" }
<< "not resizable"
}
if payload == "unlock_size" {
_ := ui.native_set_resizable(1) >>> (err) { << "err" }
<< "resizable"
}
if payload == "eval_result" {
r := webview.native_eval_result("1+2+3")
<< "eval:" + r
}
if payload == "find" {
r := webview.native_find("WebView")
<< "find:" + str(r)
}
if payload == "find_clear" {
_ := webview.native_find_clear()
<< "find cleared"
}
if payload == "bounds" {
_ := ui.native_get_bounds()
<< "bounds:posted"
}
if payload == "ua" {
_ := webview.native_set_user_agent("XuWebView/1.0")
<< "ua set"
}
if payload == "css" {
_ := webview.native_inject_css("body{outline:3px solid #e11d48 !important}")
<< "css injected"
}
if payload == "titlebar_hide" {
_ := ui.native_set_titlebar_visible(0)
<< "titlebar hidden"
}
if payload == "titlebar_show" {
_ := ui.native_set_titlebar_visible(1)
<< "titlebar shown"
}
if payload == "guard_on" {
_ := ui.native_set_close_guard(1)
<< "close guard on — try red close / Quit (dialog)"
}
if payload == "guard_off" {
_ := ui.native_set_close_guard(0)
<< "close guard off"
}
if payload == "accept_close" {
_ := ui.native_accept_close()
<< "accepting close"
}
if payload == "reject_close" {
_ := ui.native_reject_close()
<< "close rejected"
}
if payload == "clear_cache" {
_ := webview.native_clear_cache()
<< "clearing cache"
}
if payload == "state" {
_ := ui.native_get_state()
<< "state:posted"
}
if payload == "all_spaces" {
_ := ui.native_set_visible_on_all_spaces(1)
<< "all spaces on"
}
if payload == "mute" {
_ := webview.native_set_muted(1)
<< "muted"
}
if payload == "unmute" {
_ := webview.native_set_muted(0)
<< "unmuted"
}
if payload == "bg" {
_ := webview.native_set_background("#dc2626")
<< "bg #dc2626"
}
if payload == "bg2" {
_ := webview.native_set_background("#2563eb")
<< "bg #2563eb"
}
if payload == "reveal_shot" {
_ := write_file(ui.host_tmp() + "/xu_ui_shot_follow.txt", "reveal") >>> (err) {
<< "err"
}
_ := ui.native_screenshot()
<< "reveal_shot:posted"
}
if payload == "open_shot" {
_ := write_file(ui.host_tmp() + "/xu_ui_shot_follow.txt", "open") >>> (err) {
<< "err"
}
_ := ui.native_screenshot()
<< "open_shot:posted"
}
if payload == "dark" {
_ := ui.native_set_appearance("dark")
<< "appearance dark"
}
if payload == "light" {
_ := ui.native_set_appearance("light")
<< "appearance light"
}
if payload == "ctx_off" {
_ := webview.native_set_context_menu(0)
<< "context menu off"
}
if payload == "ctx_on" {
_ := webview.native_set_context_menu(1)
<< "context menu on"
}
if payload == "badge" {
_ := ui.native_set_dock_badge("3")
<< "dock badge 3"
}
if payload == "badge_clear" {
_ := ui.native_set_dock_badge("")
<< "dock badge cleared"
}
if payload == "shot_clip" {
_ := ui.native_screenshot_to_clipboard()
<< "shot_clip:posted"
}
if payload == "shadow_off" {
_ := ui.native_set_shadow(0)
<< "shadow off"
}
if payload == "shadow_on" {
_ := ui.native_set_shadow(1)
<< "shadow on"
}
if payload == "magnify_off" {
_ := webview.native_set_magnification(0)
<< "magnify off"
}
if payload == "magnify_on" {
_ := webview.native_set_magnification(1)
<< "magnify on"
}
if payload == "cookie_set" {
_ := webview.native_cookie_set("xu_demo", "1", "127.0.0.1")
<< "cookie set"
}
if payload == "cookies_get" {
c := webview.native_cookies_get()
<< "cookies:\n" + c
}
if payload == "cookies_clear" {
_ := webview.native_cookies_clear()
<< "cookies clearing"
}
<< "win:" + payload
}
<< "unknown:" + name
}
fn demo_www() string {
// Pack oneexe: force in-PE www (never stage developer/... or TEMP/www).
if env_get("XU_UI_WWW") == ":mem:" || env_get("XU_UI_PACK") == "1" {
<< ":mem:"
}
<< "www"
}
fn pack_trace(step string) {
// Pack has no xu_ui TMP dir; skip disk breadcrumbs (console / XU_UI_LOG still work).
d := env_get("XU_UI_TMP")
if d.len == 0 || d == ":xu:" {
<<
}
_ := write_file(d + "/xu_main_trace.txt", step + "\n") >>> (err) {
<<
}
}
fn ipc_boot(emit_ch chan string, shell_ch chan ui.Event) {
webview.bind_ipc_www(demo_www(), route, emit_ch, shell_ch) >>> (err) {
eprintln(err.msg())
<<
}
}
fn tick_loop(emit_ch chan string) {
$n := 0
while true {
// Short sleeps so a blocked/mis-scheduled task cannot sit on a 2s nanosleep
// that starves sibling work if threading is ever wrong. Emit only — no
// native_eval/title on this loop (those jam the AppKit main thread).
sleep_ns(200000000)
n = n + 1
if n % 10 == 0 {
webview.bus_emit(emit_ch, "tick", str(n / 10))
}
}
}
// Native app.run blocks main; shell events arrive on event_ch from #ui's host pump.
fn watch_shell(shell_ch chan ui.Event, emit_ch chan string) {
while true {
ev := <-shell_ch
if ev.kind == ui.EV_PROGRESS {
->
}
// Result-bearing shell ops → XUN emit (same post protocol as invoke).
if ev.kind == ui.EV_CLIPBOARD {
webview.bus_emit(emit_ch, "clipboard", ev.menu_id + "")
} else if ev.kind == ui.EV_FILE_PICKED {
webview.bus_emit(emit_ch, "file_picked", ev.menu_id + "")
} else if ev.kind == ui.EV_FILE_SAVED {
webview.bus_emit(emit_ch, "file_saved", ev.menu_id + "")
} else if ev.kind == ui.EV_FOLDER_PICKED {
webview.bus_emit(emit_ch, "folder_picked", ev.menu_id + "")
} else if ev.kind == ui.EV_SCREENSHOT {
p := ev.menu_id + ""
webview.bus_emit(emit_ch, "screenshot", p + "")
// reveal_shot / open_shot: follow-up after shell event (post protocol).
follow := shot_follow_take()
if follow == "reveal" && p.len > 0 {
_ := ui.native_reveal_path(p + "")
} else if follow == "open" && p.len > 0 {
_ := ui.native_open_path(p + "")
}
} else if ev.kind == ui.EV_ALERT {
webview.bus_emit(emit_ch, "alert", ev.menu_id + "")
} else if ev.kind == ui.EV_CONFIRM {
webview.bus_emit(emit_ch, "confirm", ev.menu_id + "")
} else if ev.kind == ui.EV_BOUNDS {
webview.bus_emit(emit_ch, "bounds", ev.menu_id + "")
} else if ev.kind == ui.EV_STATE {
webview.bus_emit(emit_ch, "state", ev.menu_id + "")
} else if ev.kind == ui.EV_NOTIFY {
webview.bus_emit(emit_ch, "notify", ev.menu_id + "")
}
if ev.kind == ui.EV_MENU_CLICKED {
println("shell event menu_clicked id=" + ev.menu_id)
} else if ev.kind == ui.EV_TRAY_MENU_CLICKED {
println("shell event tray_menu_clicked id=" + ev.menu_id)
} else if ev.kind == ui.EV_CLOSED {
println("shell event closed")
} else if ev.kind == ui.EV_EXIT {
println("shell event exit")
} else if ev.kind == ui.EV_CLOSE_REQUESTED {
println("shell event close_requested")
} else if ev.kind == ui.EV_FILE_PICKED {
println("shell event file_picked " + ev.menu_id)
} else if ev.kind == ui.EV_CLIPBOARD {
println("shell event clipboard")
} else if ev.kind == ui.EV_BOUNDS {
println("shell event bounds " + ev.menu_id)
} else if ev.kind == ui.EV_STATE {
println("shell event state " + ev.menu_id)
}
}
}
fn shot_follow_take() string {
path := ui.host_tmp() + "/xu_ui_shot_follow.txt"
body := read_file(path) >>> (err) {
<< ""
}
_ := write_file(path, "") >>> (err) {
<< body
}
<< body
}
fn soft_install_tray() int {
$tray_items := []ui.MenuItem{}
tray_items.push(ui.menu_item("show", "Show"))
tray_items.push(ui.menu_item("hide", "Hide"))
tray_items.push(ui.menu_item("quit", "Quit"))
a := ui.install_tray("Xu", ui.menu(tray_items)) >>> (err) {
pack_trace("install_tray soft-fail: " + err.msg())
<< 0
}
b := ui.install_tray_icon("brand/xu_app_logo.png") >>> (err) {
pack_trace("install_tray_icon soft-fail: " + err.msg())
<< 0
}
<< a + b
}
fn main() int {
emit_ch := chan string{cap: 64}
// Large cap: host floods progress/moved/focus during load; a full channel
// blocks the IPC worker on `shell_ch <-` and delays invoke by ~1s.
shell_ch := chan ui.Event{cap: 4096}
$app := ui.new_app_events(shell_ch)
pack_trace("main begin")
app.set_icon(ui.icon_from_file("brand/xu_app_logo.png"))
// Stage www before the window so host xu://app/ load is not empty.
webview.stage_www_root(demo_www()) >>> (err) {
pack_trace("stage_www_root fail: " + err.msg())
println(err.msg())
<< 1
}
pack_trace("stage_www_root ok")
xu watch_shell(shell_ch, emit_ch)
xu ipc_boot(emit_ch, shell_ch)
xu tick_loop(emit_ch)
pack_trace("xu tasks spawned")
sleep_ns(50000000)
$win := app.new_window(ui.WindowOpts{title: "Xu WebView IPC", width: 800, height: 560})
$menu_items := []ui.MenuItem{}
menu_items.push(ui.menu_item("about", "About"))
menu_items.push(ui.menu_item("quit", "Quit"))
win.set_menu(ui.menu(menu_items))
soft_install_tray()
app.new_tray(ui.TrayOpts{tip: "Xu", icon: ui.icon_default(), menu: ui.menu([]ui.MenuItem{})})
r := $&win
$wv := webview.attach(r)
pack_trace("webview.attach ok")
wv.on("ping")
wv.on("greet")
wv.load_url(webview.app_scheme_url()) >>> (err) {
pack_trace("load_url fail: " + err.msg())
println(err.msg())
<< 1
}
pack_trace("before app.run")
println("shell events on App.event_ch / xu://app/ (XUN IPC)")
app.run() >>> (err) {
pack_trace("app.run fail: " + err.msg())
println(err.msg())
<< 1
}
pack_trace("window closed")
println("window closed")
<< 0
}16_ui_webview/desktop_services/main.xu@main
#ui
#ui/draw
#ui/layout
demo #"github.com/xulang-org/examples/ui_demo"
fn caption(id int) string {
if id == 0 { << "1 / Copy greeting" }
if id == 1 { << "2 / Read clipboard" }
if id == 2 { << "3 / Open files" }
if id == 3 { << "4 / Choose save path" }
if id == 4 { << "5 / Choose folders" }
if id == 5 { << "6 / Prompt (15s timeout)" }
<< "Cancel pending request"
}
fn status_name(status int) string {
if status == ui.REQUEST_COMPLETED { << "completed" }
if status == ui.REQUEST_CANCELLED { << "cancelled" }
if status == ui.REQUEST_TIMED_OUT { << "timed out" }
if status == ui.REQUEST_UNSUPPORTED { << "unsupported" }
<< "failed"
}
fn submit(identity &ui.CanvasEvent,choice int) ui.Request {
options := ui.RequestOptions{timeout_ms: 5000}
if choice == 0 { value := "Hello from Xu UI 0.10 / 你好"
<< ui.clipboard_write_async(identity,&value,&options) >>> }
if choice == 1 { << ui.clipboard_read_async(identity,&options) >>> }
if choice == 5 { prompt := ui.PromptOptions{title: "Your greeting",seed: "Hello, Xu",timeout_ms: 15000}
<< ui.prompt_async(identity,&prompt) >>> }
$files := ui.file_dialog_options()
if choice == 2 {
files.title = "Select one or more text files"
files.multiple = true
files.filters = [ui.FileFilter{label: "Text",extensions: ["txt","md","xu"]}]
<< ui.open_files_async(identity,&files) >>>
}
if choice == 3 { files.title = "Choose a destination (this demo does not write)"
files.name = "xu-note.txt"
<< ui.save_file_async(identity,&files) >>> }
files.title = "Choose folders"
files.multiple = true
<< ui.select_folders_async(identity,&files) >>>
}
fn paint(context &draw.Context,frame $&draw.Frame,message string,pending int) int {
frame.begin() >>>
frame.set_bg(demo.background()) >>>
demo.text(context,frame,28.0,26.0,14.0,demo.accent(),"05 / ASYNCHRONOUS DESKTOP SERVICES") >>>
demo.text(context,frame,28.0,58.0,28.0,demo.ink(),"A request is not a result.") >>>
for id in 0:7 {
y := 120.0 + f64(id) * 48.0
frame.fill_rect(28.0,y,370.0,38.0,draw.rgb(40,57,73)) >>>
demo.text(context,frame,40.0,y + 8.0,15.0,demo.ink(),caption(id)) >>>
}
demo.text(context,frame,430.0,124.0,17.0,demo.accent(),"Pending request: " + str(pending)) >>>
$options := draw.text_options(16.0)
options.width = 360.0
$label := context.layout_text(&message,&options) >>>
frame.text_layout(&label,430.0,172.0,demo.ink()) >>>
demo.text(context,frame,28.0,490.0,13.0,demo.muted(),"One event channel / request IDs / distinct terminal states / Escape to close") >>>
frame.present() >>>
label.dispose() >>>
<< 0
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT { << 0 }
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
$frame := context.new_frame(4096)
$pending := ui.Request{id: 0,window_id: 0,canvas_id: 0,generation: 0,kind: 0}
$message := "Choose an action. File dialogs return paths; selecting a save path does not write a file."
$armed := -1
paint(&context,$&frame,message + "",pending.id) >>>
while true {
event := demo.next(ech)
if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
if event.window_id != identity.window_id { -> }
$dirty := event.kind == ui.EV_CANVAS_METRICS
if event.kind == ui.EV_REQUEST {
result := ui.request_of(&event) >>>
if result.matches(&pending) {
message = "Request " + str(pending.id) + " " + status_name(result.status)
if result.status == ui.REQUEST_COMPLETED {
if result.request.kind >= ui.REQUEST_OPEN_FILES {
paths := ui.file_paths(&result) >>>
for path in paths { message = message + "\n" + path }
} else { message = message + "\n" + result.value }
}
println("Request " + str(pending.id) + ": " + status_name(result.status))
pending.id = 0
dirty = true
}
}
if event.kind == ui.EV_BLURRED { armed = -1 }
if ui.is_input_event(event.kind) {
input := ui.input_of(&event) >>>
if input.generation != identity.generation { -> }
$choice := -1
for id in 0:7 {
bounds := layout.Rect{x: 28.0,y: 120.0 + f64(id) * 48.0,width: 370.0,height: 38.0}
if bounds.contains(input.x,input.y) { choice = id }
}
if input.kind == ui.EV_POINTER_DOWN && input.button == ui.BUTTON_LEFT { armed = choice }
if input.kind == ui.EV_POINTER_CANCEL { armed = -1 }
$activate := -1
if input.kind == ui.EV_POINTER_UP && input.button == ui.BUTTON_LEFT {
if choice == armed { activate = choice }
armed = -1
}
if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
if input.key >= 49 && input.key <= 54 { activate = input.key - 49 }
if input.key == ui.KEY_ESCAPE { demo.quit() >>> }
}
if activate == 6 && pending.id > 0 { _ := pending.cancel()
message = "Cancellation requested; waiting for terminal result."
dirty = true }
if activate >= 0 && activate < 6 {
if pending.id == 0 {
request := submit(&identity,activate) >>> (err) { message = err.msg()
paint(&context,$&frame,message + "",pending.id) >>>
-> }
pending = request
message = "Request admitted. Keep interacting; the event loop remains active."
} else { message = "Finish or cancel the current request first." }
dirty = true
}
}
if dirty { paint(&context,$&frame,message + "",pending.id) >>> }
}
if pending.id > 0 { _ := pending.cancel() }
frame.dispose()
<< 0
}
fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
<< } }
fn launch() int {
$app := demo.app("Xu UI / Desktop Services",850,550) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) { eprintln(err.msg())
<< 1 } }16_ui_webview/webview_component/main.xu@main
#ui
#ui/widgets
#ui/webview
#math
demo #"github.com/xulang-org/examples/ui_demo"
fn document(title string, tone string) string {
<< "<!doctype html><html><head><meta charset='utf-8'><title>" + title + "</title><style>body{margin:0;padding:28px;font:15px -apple-system,system-ui;color:#252521;background:#faf9f6}small{letter-spacing:.14em;color:#797970}h1{font-size:28px;font-weight:600;letter-spacing:-.04em;margin:16px 0}p{line-height:1.65;color:#6b6b63}input,button{box-sizing:border-box;font:inherit;border-radius:8px;padding:12px;width:100%;margin:8px 0}input{border:1px solid #d8d8cf;background:white;outline-color:" + tone + "}button{border:0;background:" + tone + ";color:white;cursor:pointer}output{display:block;min-height:42px;padding:12px 0;line-height:1.5;color:" + tone + "}</style></head><body><small>EMBEDDED WEBVIEW</small><h1>" + title + "</h1><p>This document has its own viewport, focus and request identity.</p><input aria-label='Message' value='Hello from " + title + "'><button onclick='send()'>Ask native Xu</button><output aria-live='polite'>Ready for an independent native request.</output><p>Tab moves inside this document.<br>Ctrl + Tab returns to the native controls.</p><script>async function send(){let out=document.querySelector('output');out.textContent='Waiting…';try{out.textContent=await window.__XU__.invoke('echo',document.querySelector('input').value)}catch(e){out.textContent=e.message}}</script></body></html>"
}
fn route(request webview.InvokeRequest) string {
target := request.target() >>> (err) { << "Target closed: " + err.msg()}
script := "document.title"
options := ui.RequestOptions{timeout_ms: 3000}
result := ui.webview_request_wait(&target, ui.REQUEST_WEBVIEW_EVAL, &script, &options) >>> (err) { << err.msg()}
<< result.value + " · " + request.payload + " · view " + str(target.canvas_id)
}
fn ipc(events chan ui.Event, emits chan string) {
webview.bind_ipc_requests_www(":mem:", route, emits, events) >>> (err) {eprintln(err.msg())
<< }
}
fn scene(events chan ui.Event) int {
ready := demo.ready(events) >>>
if ready.kind == ui.EV_EXIT{ << 0}
$screen := widgets.screen(&ready) >>>
screen.resize(1020.0, 720.0) >>>
screen.set_min_size(760, 580) >>>
title := screen.label("Web content. Native composition.", 26.0, false) >>>
subtitle := screen.label("Two independent WebViews inside a Canvas window", 13.0, true) >>>
hide := screen.button("Hide left") >>>
reload := screen.button("Reload right") >>>
close := screen.button("Dispose left") >>>
modal_button := screen.button("Open modal") >>>
left := screen.webview() >>>
right := screen.webview() >>>
status := screen.label("Resize the window, edit both pages, or test their native requests.", 13.0, true) >>>
modal := screen.modal("Native overlay", "The WebViews resume when this dialog closes.") >>>
dismiss := screen.button("Close dialog") >>>
screen.set_parent(dismiss, modal) >>>
screen.place(dismiss, 24.0, 175.0, 180.0, 38.0) >>>
screen.load_web_html(left, document("Editor preview", "#b64c3c")) >>>
screen.load_web_html(right, document("Reference panel", "#386f6b")) >>>
$model := Model{left: left, right: right, hide: hide, close: close, status: status, modal: modal, hidden: false, disposed: false}
$dispatcher := widgets.action_dispatcher(&model, &screen)
dispatcher.on(hide, widgets.ACTION_ACTIVATE, toggle_left) >>>
dispatcher.on(reload, widgets.ACTION_ACTIVATE, reload_right) >>>
dispatcher.on(close, widgets.ACTION_ACTIVATE, dispose_left) >>>
dispatcher.on(modal_button, widgets.ACTION_ACTIVATE, open_modal) >>>
dispatcher.on(dismiss, widgets.ACTION_ACTIVATE, close_modal) >>>
for id in[left, right] {
dispatcher.on(id, widgets.ACTION_WEB_LOADED, web_loaded) >>>
dispatcher.on(id, widgets.ACTION_WEB_FAILED, web_failed) >>>
}
while screen.is_open() {
width := screen.width()
height := screen.height()
half :=(width - 76.0) * 0.5
screen.place(title, 28.0, 25.0, width - 56.0, 38.0) >>>
screen.place(subtitle, 28.0, 69.0, width - 56.0, 25.0) >>>
screen.place(hide, 28.0, 112.0, 136.0, 38.0) >>>
screen.place(reload, 174.0, 112.0, 146.0, 38.0) >>>
screen.place(close, 330.0, 112.0, 136.0, 38.0) >>>
screen.place(modal_button, 476.0, 112.0, 136.0, 38.0) >>>
screen.place(left, 28.0, 174.0, half, math.max(300.0, height - 245.0)) >>>
screen.place(right, 48.0 + half, 174.0, half, math.max(300.0, height - 245.0)) >>>
screen.place(status, 28.0, height - 49.0, width - 56.0, 28.0) >>>
_ := screen.render() >>>
for action in screen.next(events) >>> {
_ := dispatcher.dispatch(&action, $&model, $&screen) >>>
}
}
screen.dispose()
<< 0
}
fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
<< }}
fn launch() int {
$app := demo.app("XUUI / WebView Components", 1020, 720) >>>
_ := ui.register_content_plugin(ui.content_plugin_webview())
emits := chan string {cap: 64}
xu ipc(app.event_ch, emits)
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) {eprintln(err.msg())
<< 1}}16_ui_webview/text_input/main.xu@main
#ui
#ui/draw
#ui/layout
#math
demo #"github.com/xulang-org/examples/ui_demo"
fn paint(context &draw.Context,frame $&draw.Frame,input &ui.TextInput) int {
state := input.snapshot() >>>
value := state.display_value()
println("Text revision: " + str(state.revision) + " / display bytes: " + str(value.len))
options := draw.text_options(28.0)
$text := context.layout_text(&value,&options) >>>
text.bind_input(input,state.revision,44.0,180.0) >>>
frame.begin() >>>
frame.set_bg(demo.background()) >>>
demo.text(context,frame,28.0,28.0,14.0,demo.accent(),"04 / NATIVE TEXT INPUT") >>>
demo.text(context,frame,28.0,60.0,28.0,demo.ink(),"Type in your own language.") >>>
demo.text(context,frame,28.0,112.0,15.0,demo.muted(),"Use an IME, arrows, Shift+arrows and Backspace. Click to move the caret.") >>>
frame.fill_rect(28.0,160.0,790.0,86.0,draw.rgb(26,37,50)) >>>
anchor := text.caret(state.display_anchor(),false) >>>
caret := text.caret(state.display_focus(),false) >>>
if state.display_anchor() != state.display_focus() && anchor.y == caret.y {
frame.fill_rect(44.0 + math.min(anchor.x,caret.x),180.0 + caret.y,math.abs(caret.x - anchor.x),caret.height,draw.rgba(78,205,196,80)) >>>
}
frame.text_layout(&text,44.0,180.0,demo.ink()) >>>
frame.fill_rect(44.0 + caret.x,180.0 + caret.y,1.5,caret.height,demo.accent()) >>>
if state.composing {
demo.text(context,frame,28.0,280.0,17.0,demo.accent(),"Composing: " + state.preedit) >>>
} else {
demo.text(context,frame,28.0,280.0,17.0,demo.muted(),"Committed text / no active preedit") >>>
}
demo.text(context,frame,28.0,324.0,14.0,demo.muted(),"Revision " + str(state.revision) + " / anchor byte " + str(state.anchor) + " / focus byte " + str(state.focus)) >>>
demo.text(context,frame,28.0,360.0,14.0,demo.muted(),"Selection uses UTF-8 byte offsets. Escape ends the session and closes the window.") >>>
frame.present_wait() >>>
text.dispose() >>>
<< 0
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT { << 0 }
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
seed := "你好,Xu 👩💻 · café"
caret := ui.TextInputRect{x: 44.0,y: 180.0,width: 2.0,height: 36.0}
options := ui.text_input_options(&seed,caret)
$input := ui.start_text_input(identity.canvas_id,identity.generation,&options) >>>
$frame := context.new_frame(4096)
paint(&context,$&frame,&input) >>>
while true {
event := demo.next(ech)
if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
if event.window_id != identity.window_id { -> }
$dirty := event.kind == ui.EV_CANVAS_METRICS
if event.kind >= ui.EV_TEXT_COMMIT && event.kind <= ui.EV_TEXT_SURROUNDING_DELETE {
edit := ui.text_edit_of(&event) >>>
if edit.input.id == input.id {
if event.kind == ui.EV_TEXT_INPUT_ENDED || event.kind == ui.EV_TEXT_INPUT_FAILED { <- }
dirty = true
}
}
if ui.is_input_event(event.kind) {
pointer := ui.input_of(&event) >>>
if pointer.generation != identity.generation { -> }
if pointer.kind == ui.EV_KEY_DOWN && pointer.key == ui.KEY_ESCAPE { demo.quit() >>> }
bounds := layout.Rect{x: 28.0,y: 160.0,width: 790.0,height: 86.0}
if pointer.kind == ui.EV_POINTER_DOWN && pointer.button == ui.BUTTON_LEFT && bounds.contains(pointer.x,pointer.y) {
state := input.snapshot() >>>
// The native editor owns preedit; do not overwrite an active composition.
if !state.composing {
hit := input.hit_test(state.revision,pointer.x,pointer.y) >>>
index := hit.byte_index()
_ := input.update(state.revision,&state.value,index,index,&caret) >>>
dirty = true
}
}
}
if dirty { paint(&context,$&frame,&input) >>> }
}
frame.dispose()
input.stop() >>> (err) { << 0 }
<< 0
}
fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
<< } }
fn launch() int {
$app := demo.app("Xu UI / Native Text Input",860,430) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) { eprintln(err.msg())
<< 1 } }16_ui_webview/xacp_screen/main.xu@main
#ui
#ui/widgets
#xacp
#errors
demo #"github.com/xulang-org/examples/ui_demo"
struct Model{
label_id int
count int
}
fn (m $&Model) layout(s $&widgets.Screen) int {
s.place(m.label_id, 32.0, 36.0, 540.0, 44.0) >>>
<< 0
}
fn inspect_screen(s $&widgets.Screen) int {
$session := xacp.open_session()
// The in-process adapter follows the current session lifecycle too.
// This token belongs only to this local demonstration; no listener is opened.
permissions := xacp.PERM_UI_READ | xacp.PERM_UI_MUTATE
limits := xacp.default_limits()
$nonces := xacp.new_nonce_registry(8, true)
hello := xacp.parse_frame("id: !i 1\nop: xacp.hello\nargs:\n ver: !ver 1.0.0\n nonce: local-screen-demo\n token: local-screen-demo\n permissions: !i " + str(permissions) + "\n") >>> (err) {
xacp.close_session($&session)
>> err
}
opened := xacp.dispatch_with_token($&session, &hello, &limits, "local-screen-demo", $&nonces)
if !opened.ok{
xacp.close_session($&session)
>> errors.new("xacp_screen: " + opened.err_msg)
}
tree := xacp.ui_tree(& * s, $&session, 2, false, 0, 32, &limits) >>> (err) {
xacp.close_session($&session)
>> err
}
println("XACP ui.tree: " + str(tree.nodes.len) + " visible nodes")
for node in tree.nodes{
println(" #" + str(node.id) + " kind=" + str(node.kind) + " " + node.text)
}
$snapshot := xacp.ui_screenshot(& * s, $&session, 3, 1.0, &limits) >>> (err) {
xacp.close_session($&session)
>> err
}
println("XACP ui.screenshot: " + str(snapshot.pixel_width) + "x" + str(snapshot.pixel_height) + " pixels")
snapshot.dispose() >>> (err) {
xacp.close_session($&session)
>> err
}
_ := xacp.ui_act(& * s, $&session, 2, 4, "focus", "", false, &limits) >>> (err) {
xacp.close_session($&session)
>> err
}
xacp.close_session($&session)
<< 0
}
fn scene(events chan ui.Event) int {
ready := demo.ready(events) >>>
if ready.kind == ui.EV_EXIT{ << 0}
$screen := widgets.screen(&ready) >>>
screen.resize(640.0, 180.0) >>>
label_id := screen.label("XACP Screen adapter", 22.0, false) >>>
button_id := screen.button("Activate locally or through ui.act") >>>
screen.place(label_id, 32.0, 36.0, 540.0, 44.0) >>>
screen.place(button_id, 32.0, 96.0, 360.0, 40.0) >>>
inspect_screen($&screen) >>> (err) {
screen.dispose()
>> err
}
$model := Model{label_id: label_id, count: 0}
$actions := widgets.action_dispatcher(&model, &screen)
actions.on(button_id, widgets.ACTION_ACTIVATE, activate) >>>
actions.set_fallback(global_key)
<< widgets.run_screen_actions($&screen, events, $&model, layout_action, &actions) >>>
}
fn worker(events chan ui.Event) {
scene(events) >>> (err) {demo.fail(err.msg())
<< }
}
fn launch() int {
$app := demo.app("Xu / XACP Screen adapter", 640, 180) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int {
<< launch() >>> (err) {eprintln(err.msg())
<< 1}
}@main
#ui
#ui/widgets
fn activate(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
m.count += 1
screen.set_text(m.label_id, "Button actions: " + str(m.count)) >>> (err) { << err.msg()}
<< ""
}
fn global_key(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
if action.kind == widgets.ACTION_KEY && int(action.value) == ui.KEY_ESCAPE{screen.close() >>> (err) { << err.msg()}}
<< ""
}
fn layout_action(m $&Model, screen $&widgets.Screen) string {
m.layout(screen) >>> (err) { << err.msg()}
<< ""
}16_ui_webview/controls_gallery/main.xu@main
#ui
#ui/draw
#ui/layout
#ui/widgets
demo #"github.com/xulang-org/examples/ui_demo"
fn rect(x f64, y f64, width f64, height f64) layout.Rect{
<< layout.Rect{x: x, y: y, width: width, height: height}
}
// One worker owns the controls and their canvas resources. Every recorded
// label remains alive until the complete frame has been accepted.
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT{ << 0}
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
$switcher := widgets.style_switcher()
switcher.use_preset(widgets.THEME_LIGHT) >>>
$toggle := widgets.switch_control(&identity, 1, &rect(48.0, 116.0, 280.0, 48.0), true) >>>
$radio := widgets.radio(&identity, 2, &rect(48.0, 180.0, 280.0, 48.0), 1, false) >>>
$slider := widgets.slider(&identity, 3, &rect(48.0, 260.0, 280.0, 36.0), 0.0, 100.0, 50.0) >>>
slider.set_step(5.0) >>>
$stepper := widgets.stepper(&identity, 4, &rect(48.0, 324.0, 280.0, 48.0), 0.0, 20.0, 1.0, 5.0) >>>
$tabs := widgets.tabs(&identity, 5, &rect(376.0, 116.0, 348.0, 48.0), 3, 0) >>>
$dropdown := widgets.select_box(&identity, 6, &rect(376.0, 196.0, 348.0, 48.0), 3, 0) >>>
$list := widgets.list_box(&identity, 7, &rect(376.0, 284.0, 348.0, 132.0), 3, 0) >>>
panel := widgets.card(&rect(24.0, 92.0, 724.0, 352.0)) >>>
badge := widgets.badge(&rect(48.0, 392.0, 280.0, 32.0)) >>>
divider := widgets.divider(&rect(48.0, 244.0, 280.0, 2.0), widgets.AXIS_HORIZONTAL) >>>
$label0 := widgets.styled_label(&context, &"Enabled")
$label1 := widgets.styled_label(&context, &"Choose this option")
$label2 := widgets.styled_label(&context, &"Stepper")
$label3 := widgets.styled_label(&context, &"One")
$label4 := widgets.styled_label(&context, &"Two")
$label5 := widgets.styled_label(&context, &"Three")
$label6 := widgets.styled_label(&context, &"Select an option")
$label7 := widgets.styled_label(&context, &"Xu 0.10.2")
$label8 := widgets.styled_label(&context, &"One")
$label9 := widgets.styled_label(&context, &"Two")
$label10 := widgets.styled_label(&context, &"Three")
$frame := context.new_frame(16384)
$state := Model{dirty: true, focus: 0}
$dispatcher := widgets.action_dispatcher(&state, &switcher)
for id in 1:8 {dispatcher.on_any(id, control_action) >>> }
while true {
if state.dirty{
styles := switcher.styles()
frame.begin() >>>
frame.set_bg(styles.background) >>>
panel.paint_styled($&frame, &styles) >>>
ink := styles.button.palette.foreground
title := "Extended controls / " + switcher.name()
frame.text(32.0, 28.0, 22.0, ink, &title) >>>
toggle.paint_styled($&frame, $&label0, &styles) >>>
radio.paint_styled($&frame, $&label1, &styles) >>>
divider.paint_styled($&frame, &styles) >>>
slider.paint_styled($&frame, &styles) >>>
stepper.paint_styled($&frame, $&label2, &styles) >>>
tabs.paint_box_styled($&frame, &styles) >>>
list.paint_box_styled($&frame, &styles) >>>
tabs.paint_tab_styled($&frame, 0, $&label3, &styles) >>>
list.paint_item_styled($&frame, 0, $&label8, &styles) >>>
tabs.paint_tab_styled($&frame, 1, $&label4, &styles) >>>
list.paint_item_styled($&frame, 1, $&label9, &styles) >>>
tabs.paint_tab_styled($&frame, 2, $&label5, &styles) >>>
list.paint_item_styled($&frame, 2, $&label10, &styles) >>>
dropdown.paint_styled($&frame, $&label6, &styles) >>>
badge.paint_styled($&frame, $&label7, &styles) >>>
frame.text(32.0, 464.0, 15.0, ink, &"T: theme / S: text size / D: density / Tab: focus / Esc: quit") >>>
status := "Slider " + str(int(slider.value())) + " / Stepper " + str(int(stepper.value())) + " / Select " + str(dropdown.selected() + 1)
frame.text(32.0, 494.0, 15.0, ink, &status) >>>
// A Select popup overlays the scene; this basic painter repeats
// its label. The selected option index is shown in the status.
dropdown.paint_popup_styled($&frame, $&label6, &styles) >>>
// This worker can repaint for a burst of control and appearance actions.
frame.present_wait() >>>
toggle.painted()
radio.painted()
slider.painted()
stepper.painted()
tabs.painted()
dropdown.painted()
list.painted()
state.dirty = false
}
event := demo.next(ech)
if event.kind == ui.EV_EXIT{ <- }
if event.window_id != identity.window_id{ -> }
if event.kind == ui.EV_CANVAS_CLOSED{ <- }
if event.kind == ui.EV_CANVAS_METRICS{state.dirty = true}
if ui.is_input_event(event.kind) {
input := ui.input_of(&event) >>>
if input.generation != identity.generation{ -> }
if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
if input.key == ui.KEY_ESCAPE{
// App shutdown revokes canvas resources. Do not enqueue
// another frame while the native host is closing.
demo.quit() >>>
<< 0
}
if appearance_key($&switcher, &input) >>> {state.dirty = true}
if input.key == ui.KEY_TAB{state.focus = state.focus % 7 + 1
state.dirty = true}
}
}
// Route the popup first. A modal option click must not also focus
// or activate the ListBox underneath it.
popup_open := dropdown.is_open()
first := dropdown.event(&event) >>>
$actions :=[first]
if !popup_open && !first.consumed{
actions.push(toggle.event(&event) >>>)
actions.push(radio.event(&event) >>>)
actions.push(slider.event(&event) >>>)
actions.push(stepper.event(&event) >>>)
actions.push(tabs.event(&event) >>>)
actions.push(list.event(&event) >>>)
}
for action in actions{
if !(dispatcher.dispatch(&action, $&state, $&switcher) >>>) {
// ACTION_NONE may carry focus/repaint metadata without a semantic event.
action_state($&state, &action)
}
}
toggle.set_focus(state.focus == 1)
radio.set_focus(state.focus == 2)
slider.set_focus(state.focus == 3)
stepper.set_focus(state.focus == 4)
tabs.set_focus(state.focus == 5)
dropdown.set_focus(state.focus == 6)
list.set_focus(state.focus == 7)
}
frame.dispose()
if demo.alive(&identity) {
label0.dispose()
label1.dispose()
label2.dispose()
label3.dispose()
label4.dispose()
label5.dispose()
label6.dispose()
label7.dispose()
label8.dispose()
label9.dispose()
label10.dispose()
}
<< 0
}
fn worker(ech chan ui.Event) {
scene(ech) >>> (err) {demo.fail(err.msg())
<< }
}
fn launch() int {
$app := demo.app("Xu UI / Extended Controls", 780, 552) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int {
<< launch() >>> (err) {eprintln(err.msg())
<< 1}
}@main
#ui
#ui/widgets
fn appearance_key(switcher $&widgets.StyleSwitcher, input &ui.InputEvent) bool {
if input.key == 84 || input.key == 116 {switcher.next() >>>
<< true}
if input.key == 83 || input.key == 115 {
$scale := 1.4
if switcher.text_scale() > 1.0 {scale = 1.0}
switcher.set_text_scale(scale) >>>
<< true
}
if input.key == 68 || input.key == 100 {
$density := 0.85
if switcher.density() < 1.0 {density = 1.0}
switcher.set_density(density) >>>
<< true
}
<< false
}16_ui_webview/component_catalog/main.xu@main
#ui
#ui/widgets
#ui/draw
#time
#math
demo #"github.com/xulang-org/examples/ui_demo"
// The model contains business choices and screen-local handles only.
struct Model{
page int
theme int
text_scale f64
density f64
appearance_dirty bool
nav []int
settings []int
pages []int
headings []int
captions []int
table int
tree int
pager int
crumbs int
combo int
multi int
color int
spinner int
overlay_buttons []int
popover int
modal int
modal_actions []int
value_label int
note int
}
fn (m &Model) fill_table(screen $&widgets.Screen) int {
names :=["Compiler", "Widgets", "Runtime", "Desktop", "Examples", "Tooling"]
states :=["Ready", "Review", "Ready", "Draft", "Ready", "Review"]
clocks :=["10:30", "11:15", "09:40", "12:00", "10:05", "08:50"]
$order :=[0, 1, 2, 3, 4, 5]
col := screen.sort_column(m.table) >>>
if col == 0 {order =[0, 3, 4, 2, 5, 1]}
if col == 1 {order =[3, 0, 2, 4, 1, 5]}
if col == 2 {order =[5, 2, 4, 0, 1, 3]}
desc := screen.sort_descending(m.table) >>>
page :=(screen.selected(m.pager) >>>) + 1
for row in 0:6 {
$slot := row
if desc{slot = 5 - row}
i := order[slot]
screen.set_cell(m.table, row, 0, names[i] + " / " + str(page)) >>>
screen.set_cell(m.table, row, 1, states[i]) >>>
screen.set_cell(m.table, row, 2, clocks[i]) >>>
}
<< 0
}
fn (m $&Model) layout(screen $&widgets.Screen) int {
width := screen.width()
height := screen.height()
row := screen.row_height()
for i in 0:3 {
screen.place(m.nav[i], 28.0 + f64(i) * 124.0, 142.0, 112.0, row) >>>
screen.set_selected_button(m.nav[i], m.page == i) >>>
screen.set_visible(m.pages[i], m.page == i) >>>
screen.place(m.settings[i], width - 420.0 + f64(i) * 132.0, 142.0, 120.0, row) >>>
}
screen.place(m.headings[0], 28.0, 26.0, width - 56.0, 24.0) >>>
screen.place(m.headings[1], 28.0, 61.0, width - 56.0, 46.0) >>>
screen.place(m.headings[2], 28.0, 108.0, width - 56.0, 30.0) >>>
screen.place(m.crumbs, 28.0, 204.0, width - 56.0, row) >>>
screen.place(m.note, 28.0, height - 48.0, width - 56.0, 30.0) >>>
content := math.max(160.0, height - 420.0)
screen.place(m.captions[0], 28.0, 253.0, width * 0.62 - 40.0, 30.0) >>>
screen.place(m.captions[1], width * 0.62 + 12.0, 253.0, width * 0.38 - 40.0, 30.0) >>>
screen.place(m.table, 28.0, 280.0, width * 0.62 - 40.0, content) >>>
screen.place(m.tree, width * 0.62 + 12.0, 280.0, width * 0.38 - 40.0, content) >>>
screen.place(m.pager, 28.0, height - 118.0, 380.0, row) >>>
screen.place(m.captions[2], 28.0, 253.0, 400.0, 30.0) >>>
screen.place(m.captions[3], 28.0, 363.0, 400.0, 30.0) >>>
screen.place(m.captions[4], 450.0, 253.0, width - 478.0, 30.0) >>>
screen.place(m.combo, 28.0, 280.0, 370.0, row) >>>
screen.place(m.multi, 28.0, 390.0, 370.0, row) >>>
screen.place(m.color, 450.0, 280.0, width - 478.0, 240.0) >>>
screen.place(m.spinner, 28.0, 562.0, 28.0, 28.0) >>>
screen.place(m.captions[5], 70.0, 568.0, width - 98.0, 30.0) >>>
screen.place(m.value_label, 28.0, 620.0, width - 56.0, 36.0) >>>
screen.place(m.captions[6], 28.0, 253.0, width - 56.0, 30.0) >>>
for i in 0:4 {screen.place(m.overlay_buttons[i], 28.0 + f64(i) * 208.0, 280.0, 190.0, row) >>>
screen.place(m.captions[i + 7], 28.0, 365.0 + f64(i) * 40.0, width - 56.0, 32.0) >>> }
screen.place(m.modal_actions[0], 24.0, 210.0, 194.0, row) >>>
screen.place(m.modal_actions[1], 234.0, 210.0, 194.0, row) >>>
<< 0
}
fn new_model(screen $&widgets.Screen) Model{
$nav :=[]int {}
for text in["Data", "Inputs", "Overlays"] {nav.push(screen.button(text) >>>)}
$settings :=[]int {}
for text in["Theme", "Text size", "Density"] {settings.push(screen.button(text) >>>)}
$pages :=[]int {}
for i in 0:3 {pages.push(screen.group() >>>)}
headings :=[screen.label("XUUI / COMPONENT CATALOG", 12.0, true) >>>,
screen.label("Native components, working together.", 26.0, false) >>>,
screen.label("Keyboard, pointer, themes, typography and density — managed by Screen.", 13.0, true) >>>]
crumbs := screen.breadcrumbs(&["Workspace", "UI", "Component catalog"]) >>>
note := screen.label("Choose a category · Tab / Shift+Tab · Escape", 13.0, true) >>>
table := screen.table(&["Module", "State", "Updated"], 6, 0) >>>
tree := screen.tree() >>>
pager := screen.pagination(3, 0) >>>
combo := screen.combo_box(&["Compiler", "Widgets", "Runtime", "Desktop", "Examples", "工具链"], "") >>>
multi := screen.multi_select(&["Native", "Keyboard", "IME", "Theming", "Motion"]) >>>
screen.set_checked(multi, 0, true) >>>
color := screen.color_picker(draw.rgba(59, 130, 246, 220)) >>>
spinner := screen.spinner() >>>
value_label := screen.label("Value: Selected tags: 1", 14.0, false) >>>
$overlay_buttons :=[]int {}
for text in["Open popover", "Open modal", "Show toast", "Hover / focus me"] {overlay_buttons.push(screen.button(text) >>>)}
popover := screen.popover(overlay_buttons[0], "An anchored panel for related actions.") >>>
modal := screen.modal("Keep focus where it belongs", "Screen owns focus, input isolation and restoration.") >>>
_ := screen.tooltip(overlay_buttons[3], "Pointer and keyboard share this hint.") >>>
modal_actions :=[screen.button("Complete action") >>>, screen.button("Close") >>>]
for id in modal_actions{screen.set_parent(id, modal) >>> }
$captions :=[]int {}
for text in["TABLE / sort columns · select rows · scroll", "TREE / expand · navigate",
"COMBO BOX / type to filter · native IME", "MULTI SELECT / independent choices",
"COLOR PICKER / red · green · blue · alpha", "Loading indicator · respects reduced motion",
"OVERLAYS / anchor placement · focus ownership · timed feedback",
"Popover: anchored to its trigger and constrained to the canvas.",
"Modal: Tab stays inside; Escape closes; focus returns to the trigger.",
"Toast: closes automatically; hover or focus pauses its lifetime.",
"Tooltip: hover or keyboard focus reveals a delayed explanation."] {captions.push(screen.label(text, 13.0, true) >>>)}
for id in[table, tree, pager, captions[0], captions[1]] {screen.set_parent(id, pages[0]) >>> }
for id in[combo, multi, color, spinner, value_label, captions[2], captions[3], captions[4], captions[5]] {screen.set_parent(id, pages[1]) >>> }
for id in overlay_buttons{screen.set_parent(id, pages[2]) >>> }
screen.set_parent(popover, pages[2]) >>>
for i in 6:11 {screen.set_parent(captions[i], pages[2]) >>> }
root := screen.tree_add(tree, - 1, "XU Workspace") >>>
compiler := screen.tree_add(tree, root, "Compiler") >>>
_ := screen.tree_add(tree, compiler, "Frontend") >>>
_ := screen.tree_add(tree, compiler, "Native backend") >>>
ui_root := screen.tree_add(tree, root, "UI") >>>
_ := screen.tree_add(tree, ui_root, "Widgets") >>>
_ := screen.tree_add(tree, ui_root, "Drawing") >>>
_ := screen.tree_add(tree, root, "Examples") >>>
for node in[root, compiler, ui_root] {screen.set_expanded(tree, node, true) >>> }
m := Model{page: 0, theme: 1, text_scale: 1.0, density: 1.0, appearance_dirty: true, nav: nav, settings: settings, pages: pages, headings: headings, captions: captions,
table: table, tree: tree, pager: pager, crumbs: crumbs, combo: combo, multi: multi, color: color, spinner: spinner,
overlay_buttons: overlay_buttons, popover: popover, modal: modal, modal_actions: modal_actions, value_label: value_label, note: note}
m.fill_table(screen) >>>
<< m
}
fn scene(events chan ui.Event) int {
ready := demo.ready(events) >>>
if ready.kind == ui.EV_EXIT{ << 0}
$screen := widgets.screen(&ready) >>>
screen.resize(1040.0, 820.0) >>>
screen.set_min_size(1040, 760) >>>
$model := new_model($&screen) >>> (err) {screen.dispose()
>> err}
actions := register_actions(&model, &screen) >>>
<< widgets.run_screen_actions($&screen, events, $&model, layout_action, &actions) >>>
}
fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
<< }}
fn launch() int {$app := demo.app("Xu UI / Component Catalog", 1040, 820) >>>
xu worker(app.event_ch)
<< app.run() >>> }
fn main() int { << launch() >>> (err) {eprintln(err.msg())
<< 1}}@main
#ui
#ui/widgets
fn page_0(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
m.page = 0
<< ""
}
fn page_1(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
m.page = 1
<< ""
}
fn page_2(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
m.page = 2
<< ""
}
fn choose_theme(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
m.theme =(m.theme + 1) % 3
m.appearance_dirty = true
<< ""
}
fn choose_scale(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
if m.text_scale == 1.0 {m.text_scale = 1.4} else {m.text_scale = 1.0}
m.appearance_dirty = true
<< ""
}
fn choose_density(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
if m.density == 1.0 {m.density = 0.8} else {m.density = 1.0}
m.appearance_dirty = true
<< ""
}
fn refresh_table(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
m.fill_table(screen) >>> (err) { << err.msg()}
<< ""
}
fn open_popover(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
screen.open(m.popover) >>> (err) { << err.msg()}
<< ""
}
fn open_modal(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
screen.open(m.modal) >>> (err) { << err.msg()}
<< ""
}
fn notify_theme(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
_ := screen.notify("All components share the same theme.") >>> (err) { << err.msg()}
<< ""
}
fn complete_modal(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
screen.close_overlay(m.modal) >>> (err) { << err.msg()}
_ := screen.notify("Action completed.") >>> (err) { << err.msg()}
<< ""
}
fn close_modal(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
screen.close_overlay(m.modal) >>> (err) { << err.msg()}
<< ""
}
fn changed(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
screen.set_text(m.note, "Value changed · Tab / Shift+Tab · Escape") >>> (err) { << err.msg()}
<< ""
}
fn page_changed(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
m.fill_table(screen) >>> (err) { << err.msg()}
<< changed(m, screen, action)
}
fn inputs_changed(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
value := screen.text_value(m.combo) >>> (err) { << err.msg()}
count :=(screen.values(m.multi) >>> (err) { << err.msg()}).len
screen.set_text(m.value_label, "Value: " + value + " Selected tags: " + str(count)) >>> (err) { << err.msg()}
<< changed(m, screen, action)
}
fn global_key(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
if action.kind == widgets.ACTION_KEY && int(action.value) == ui.KEY_ESCAPE{screen.close() >>> (err) { << err.msg()}}
<< ""
}
fn register_actions(m &Model, screen &widgets.Screen) widgets.ActionDispatcher#Model, widgets.Screen, widgets.Action{
$d := widgets.action_dispatcher(m, screen)
d.on(m.nav[0], widgets.ACTION_ACTIVATE, page_0) >>>
d.on(m.nav[1], widgets.ACTION_ACTIVATE, page_1) >>>
d.on(m.nav[2], widgets.ACTION_ACTIVATE, page_2) >>>
d.on(m.settings[0], widgets.ACTION_ACTIVATE, choose_theme) >>>
d.on(m.settings[1], widgets.ACTION_ACTIVATE, choose_scale) >>>
d.on(m.settings[2], widgets.ACTION_ACTIVATE, choose_density) >>>
d.on(m.table, widgets.ACTION_ACTIVATE, refresh_table) >>>
d.on(m.overlay_buttons[0], widgets.ACTION_ACTIVATE, open_popover) >>>
d.on(m.overlay_buttons[1], widgets.ACTION_ACTIVATE, open_modal) >>>
d.on(m.overlay_buttons[2], widgets.ACTION_ACTIVATE, notify_theme) >>>
d.on(m.modal_actions[0], widgets.ACTION_ACTIVATE, complete_modal) >>>
d.on(m.modal_actions[1], widgets.ACTION_ACTIVATE, close_modal) >>>
for id in[m.table, m.tree, m.crumbs, m.color] {d.on(id, widgets.ACTION_CHANGE, changed) >>> }
d.on(m.pager, widgets.ACTION_CHANGE, page_changed) >>>
d.on(m.combo, widgets.ACTION_CHANGE, inputs_changed) >>>
d.on(m.multi, widgets.ACTION_CHANGE, inputs_changed) >>>
// Screen-wide keys have id 0, outside the by-id control namespace.
d.set_fallback(global_key)
<< d
}16_ui_webview/widgets/main.xu@main
#ui
#ui/draw
#ui/layout
#ui/widgets
demo #"github.com/xulang-org/examples/ui_demo"
struct Model{
button widgets.Button
checkbox widgets.Checkbox
progress widgets.Progress
scroll widgets.Scroll
button_label draw.TextLayout
checkbox_label draw.TextLayout
theme widgets.Theme
context draw.Context
count int
header_id int
button_id int
check_id int
progress_id int
scroll_id int
row_ids []int
}
fn (model $&Model) button_input(kind int, input &ui.InputEvent) widgets.Action{
button := $&model.button
<< button.route(kind, input) >>>
}
fn (model $&Model) checkbox_input(kind int, input &ui.InputEvent) widgets.Action{
checkbox := $&model.checkbox
<< checkbox.route(kind, input) >>>
}
fn (model $&Model) scroll_input(kind int, input &ui.InputEvent) widgets.Action{
scroll := $&model.scroll
<< scroll.route(kind, input) >>>
}
fn (model $&Model) input(id int, kind int, input &ui.InputEvent) widgets.Action{
if id == model.button_id{ << model.button_input(kind, input) >>> }
if id == model.check_id{ << model.checkbox_input(kind, input) >>> }
if id == model.scroll_id{ << model.scroll_input(kind, input) >>> }
<< widgets.Action{kind: widgets.ACTION_NONE, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
}
fn (model $&Model) place_button(bounds &layout.Rect) int {
button := $&model.button
<< button.set_bounds(bounds) >>>
}
fn (model $&Model) place_checkbox(bounds &layout.Rect) int {
checkbox := $&model.checkbox
<< checkbox.set_bounds(bounds) >>>
}
fn (model $&Model) place_progress(bounds &layout.Rect) int {
progress := $&model.progress
<< progress.set_bounds(bounds) >>>
}
fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
model.draw_node(id, bounds, frame) >>> (err) {eprintln(err.msg())
<< false}
<< true
}
fn (model $&Model) draw_node(id int, bounds &layout.Rect, frame $&draw.Frame) int {
if id == model.header_id{
demo.text(&model.context, frame, 0.0, 0.0, 14.0, demo.accent(), "03 / RETAINED LAYOUT + CONTROLS") >>>
demo.text(&model.context, frame, 0.0, 28.0, 24.0, demo.ink(), "Actions completed: " + str(model.count)) >>>
} else if id == model.button_id{
model.place_button(bounds) >>>
model.button.paint(frame, &model.button_label, &model.theme) >>>
} else if id == model.check_id{
model.place_checkbox(bounds) >>>
model.checkbox.paint(frame, &model.checkbox_label, &model.theme) >>>
} else if id == model.progress_id{
model.place_progress(bounds) >>>
model.progress.paint(frame, &model.theme) >>>
} else if id == model.scroll_id{
scroll := $&model.scroll
scroll.set_bounds(bounds) >>>
frame.fill_rect(0.0, 0.0, bounds.width, bounds.height, draw.rgb(26, 37, 50)) >>>
} else {
for i in 0:model.row_ids.len{
if id == model.row_ids[i] {demo.text(&model.context, frame, 12.0, 5.0, 15.0, demo.muted(), "Retained row " + str(i + 1) + " / scroll, Tab, PageDown, Home") >>> }
}
}
<< 0
}
fn (model $&Model) advance() int {
model.count = model.count + 1
println("Action count: " + str(model.count))
value := f64(model.count % 11) / 10.0
progress := $&model.progress
<< progress.set_value(value) >>>
}
fn (model $&Model) enable_button(enabled bool) {
button := $&model.button
button.set_enabled(enabled)
}
fn (model $&Model) acknowledge_button() {
control := $&model.button
control.painted()
}
fn (model $&Model) acknowledge_checkbox() {
control := $&model.checkbox
control.painted()
}
fn (model $&Model) acknowledge_progress() {
control := $&model.progress
control.painted()
}
fn (model $&Model) acknowledge_scroll() {
control := $&model.scroll
control.painted()
}
fn (model $&Model) acknowledge() {
model.acknowledge_button()
model.acknowledge_checkbox()
model.acknowledge_progress()
model.acknowledge_scroll()
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT{ << 0}
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
host := widgets.Host{context: context, identity: identity}
$column := layout.box_style(layout.BOX_COLUMN)
column.padding = layout.insets(28.0) >>>
column.gap = 14.0
column.cross_alignment = layout.CROSS_STRETCH
$view := host.view(&column, demo.background()) >>>
leaf := layout.box_style(layout.BOX_LEAF)
header := view.add(view.root(), &leaf, &layout.Size{width: 400.0, height: 72.0}) >>>
button_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 44.0}) >>>
check_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 40.0}) >>>
progress_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 12.0}) >>>
$viewport := layout.box_style(layout.BOX_COLUMN)
viewport.height = 220.0
viewport.clip = true
viewport.cross_alignment = layout.CROSS_STRETCH
viewport.gap = 6.0
scroll_id := view.add(view.root(), &viewport, &layout.Size{width: 400.0, height: 220.0}) >>>
$rows :=[]int {}
for _ in 0:20 {
row := view.add(scroll_id, &leaf, &layout.Size{width: 400.0, height: 32.0}) >>>
rows.push(row)
view.set_boundary(row, true) >>>
}
for id in[header, button_id, check_id, progress_id, scroll_id] {view.set_boundary(id, true) >>> }
for id in[button_id, check_id, scroll_id] {view.set_input(id, true, true) >>> }
empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
options := draw.text_options(15.0)
first := "Complete one action"
second := "Enable action button"
$model := Model{button: widgets.button(&identity, button_id, &empty) >>>,
checkbox: widgets.checkbox(&identity, check_id, &empty, true) >>>,
progress: widgets.progress(&empty, 0.0) >>>,
scroll: widgets.scroll(&identity, scroll_id, &empty, widgets.AXIS_VERTICAL, 760.0) >>>,
button_label: context.layout_text(&first, &options) >>>,
checkbox_label: context.layout_text(&second, &options) >>>,
theme: widgets.default_theme(), context: context, count: 0, header_id: header, button_id: button_id, check_id: check_id, progress_id: progress_id, scroll_id: scroll_id, row_ids: rows}
dispatcher := register_actions(&model, &view) >>>
$width := 700.0
$height := 600.0
while true {
constraints := layout.tight(width, height) >>>
submitted := widgets.present($&view, &constraints, $&model) >>>
if submitted{model.acknowledge()}
event := demo.next(ech)
if event.kind == ui.EV_EXIT{ <- }
if event.window_id != identity.window_id{ -> }
if event.kind == ui.EV_CANVAS_METRICS{
metrics := ui.metrics_of(&event) >>>
if metrics.width > 0.0 && metrics.height > 0.0 {width = metrics.width
height = metrics.height}
}
actions := widgets.dispatch_event($&view, &event, $&model) >>>
for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) >>> }
if event.kind == ui.EV_CANVAS_CLOSED{ <- }
if ui.is_input_event(event.kind) {
input := ui.input_of(&event) >>>
if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() >>> }
}
stats := view.stats()
if stats.recorded_boundaries > 0 || stats.reused_boundaries > 0 {
println("View: " + str(stats.recorded_boundaries) + " recorded / " + str(stats.reused_boundaries) + " reused boundaries")
}
}
view.dispose()
// Native close revokes resources; only release user handles while live.
if demo.alive(&identity) {
label := $&model.button_label
label.dispose() >>>
check_label := $&model.checkbox_label
check_label.dispose() >>>
}
<< 0
}
fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
<< }}
fn launch() int {
$app := demo.app("Xu UI / Retained Controls", 700, 600) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) {eprintln(err.msg())
<< 1}}16_ui_webview/interaction_gallery/main.xu@main
#ui
#ui/widgets
#ui/layout
#time
#math
#errors
demo #"github.com/xulang-org/examples/ui_demo"
struct Model{
tree int
name int
search int
task int
cancel int
table int
theme int
guides int
density int
effects int
failure int
message int
headings []int
controls_page int
work_group int
basic_group int
extras []int
show_controls bool
theme_index int
guided bool
compact bool
reduced bool
fail_next bool
appearance_dirty bool
task_id int
completed int
running bool
checksum int
next_work time.Instant
}
fn make_model(screen $&widgets.Screen) Model{
$name_decoration := widgets.field_decoration(&"Output name")
name_decoration.helper = "A persistent label, native text selection and IME"
name_decoration.error = "Enter an output name before building."
name_decoration.clearable = true
name := screen.field("", &name_decoration) >>>
$search_decoration := widgets.field_decoration(&"Find a component")
search_decoration.helper = "Matching nodes keep their ancestor path"
search_decoration.clearable = true
search := screen.field("", &search_decoration) >>>
tree := screen.tree() >>>
root := screen.tree_add(tree, - 1, "xu-workbench") >>>
src := screen.tree_add(tree, root, "src") >>>
entry := screen.tree_add(tree, src, "main.xu") >>>
controls := screen.tree_add(tree, src, "widgets") >>>
for label in["tree_view.xu", "task_button.xu", "field.xu", "table.xu"] {
node := screen.tree_add(tree, controls, label) >>>
screen.set_tree_action(tree, node, true) >>>
}
manifest := screen.tree_add(tree, root, "xu.xun") >>>
screen.set_tree_metadata(tree, entry, "entry") >>>
screen.set_tree_metadata(tree, manifest, "module") >>>
for node in[root, src, controls] {screen.set_expanded(tree, node, true) >>> }
task := screen.task_button("Build project") >>>
screen.set_task_labels(task, "Building", "Built · run again", "Retry build", "Build again") >>>
table := screen.table(&["Component", "Experience", "Status"], 18, 0) >>>
screen.set_table_column(table, 0, 144.0, 0.0) >>>
screen.set_table_column(table, 1, 340.0, 0.0) >>>
screen.set_table_column(table, 2, 128.0, 0.0) >>>
names :=["TreeView", "TaskButton", "Field", "Table", "Select", "Popover"]
details :=["Find and reveal", "Real task progress", "Floating label / native IME", "Resizable columns", "Keyboard choices", "Anchored feedback"]
for row in 0:18 {
index := row % 6
screen.set_cell(table, row, 0, names[index]) >>>
screen.set_cell(table, row, 1, details[index]) >>>
screen.set_cell(table, row, 2, "Ready") >>>
}
headings :=[screen.label("XUUI / INTERACTION LAB", 12.0, true) >>>,
screen.label("Precision in every interaction.", 25.0, false) >>>,
screen.label("WORKSPACE", 12.0, true) >>>, screen.label("BUILD CONFIGURATION", 12.0, true) >>>,
screen.label("COMPONENTS / scroll, select and sort", 12.0, true) >>>]
work_group := screen.group() >>>
basic_group := screen.group() >>>
for id in[tree, name, search, task, table, headings[2], headings[3], headings[4]] {screen.set_parent(id, work_group) >>> }
extras := extra_controls(screen) >>>
for id in extras{screen.set_parent(id, basic_group) >>> }
cancel := screen.button("Cancel task") >>>
screen.set_parent(cancel, work_group) >>>
controls_page := screen.button("All controls") >>>
styles := screen.styles()
primary_style := styles.button_variant(widgets.BUTTON_PRIMARY) >>>
screen.set_control_style(task, &primary_style) >>>
<< Model{tree: tree, name: name, search: search, task: task, cancel: cancel,
table: table, theme: screen.button("Theme") >>>, guides: screen.button("Tree guides") >>>,
density: screen.button("Density") >>>, effects: screen.button("Motion") >>>, failure: screen.button("Fail next build") >>>,
message: screen.label("Local work batches report completed items. No simulated percentage clock.", 13.0, true) >>>,
headings: headings, controls_page: controls_page, work_group: work_group, basic_group: basic_group, extras: extras, show_controls: false, theme_index: 1, guided: false, compact: false, reduced: false, fail_next: false, appearance_dirty: true,
task_id: 0, completed: 0, running: false, checksum: 0, next_work: time.zero_instant()}
}
fn (m &Model) layout(screen $&widgets.Screen) int {
width := screen.width()
height := screen.height()
left := 310.0
screen.place(m.headings[0], 28.0, 24.0, width - 56.0, 22.0) >>>
screen.place(m.headings[1], 28.0, 54.0, width - 56.0, 36.0) >>>
buttons :=[m.theme, m.guides, m.density, m.effects, m.failure, m.controls_page]
for i in 0:buttons.len{screen.place(buttons[i], 28.0 + f64(i) * 144.0, 111.0, 132.0, 36.0) >>> }
screen.set_visible(m.work_group, !m.show_controls) >>>
screen.set_visible(m.basic_group, m.show_controls) >>>
screen.set_selected_button(m.controls_page, m.show_controls) >>>
extra_layout(screen, &m.extras) >>>
screen.set_selected_button(m.guides, m.guided) >>>
screen.set_selected_button(m.effects, m.reduced) >>>
screen.set_selected_button(m.failure, m.fail_next) >>>
screen.place(m.headings[2], 28.0, 173.0, left - 24.0, 24.0) >>>
screen.place(m.search, 28.0, 208.0, left - 24.0, 80.0) >>>
screen.place(m.tree, 28.0, 302.0, left - 24.0, height - 352.0) >>>
x := left + 36.0
right_width := width - x - 28.0
screen.place(m.headings[3], x, 173.0, right_width, 24.0) >>>
screen.place(m.name, x, 208.0, right_width, 86.0) >>>
screen.place(m.task, x, 307.0, 230.0, 40.0) >>>
screen.place(m.cancel, x + 246.0, 307.0, 136.0, 40.0) >>>
screen.set_enabled(m.cancel, m.running) >>>
screen.place(m.headings[4], x, 377.0, right_width, 24.0) >>>
screen.place(m.table, x, 413.0, right_width, height - 493.0) >>>
screen.place(m.message, 28.0, height - 41.0, width - 56.0, 24.0) >>>
<< 0
}
fn (m $&Model) work(screen $&widgets.Screen, now time.Instant) int {
if !m.running || now.before(m.next_work) { << 0}
// Each progress update follows an actual bounded work batch. The pause
// represents an application work queue and never changes the percentage.
for i in 0:5000 {m.checksum =(m.checksum + i *(m.completed + 1)) % 1000003}
m.completed = m.completed + 1
_ := screen.set_task_progress(m.task, m.task_id, f64(m.completed) / 48.0) >>>
m.next_work = now.add(time.milliseconds(35) >>>) >>>
if m.fail_next && m.completed == 18 {
_ := screen.complete_task(m.task, m.task_id, widgets.TASK_ERROR) >>>
m.running = false
m.fail_next = false
screen.set_text(m.message, "Example failure. Retry starts a new task; stale progress is rejected.") >>>
} else if m.completed == 48 {
_ := screen.complete_task(m.task, m.task_id, widgets.TASK_SUCCESS) >>>
m.running = false
screen.set_text(m.message, "48/48 work batches completed · checksum " + str(m.checksum)) >>>
}
<< 0
}
fn extra_controls(screen $&widgets.Screen)[]int {
$ids :=[]int {}
ids.push(screen.card() >>>)
ids.push(screen.label("CONTROLS / keyboard, pointer and state", 12.0, true) >>>)
ids.push(screen.checkbox("Keep generated files", true) >>>)
ids.push(screen.switch_control("Live preview", true) >>>)
ids.push(screen.radio("Use workspace settings", 1, true) >>>)
ids.push(screen.slider(0.0, 100.0, 40.0) >>>)
ids.push(screen.stepper(1.0, 16.0, 1.0, 4.0) >>>)
ids.push(screen.tabs(&["Files", "History", "Output"], 0) >>>)
ids.push(screen.segmented(&["Desktop", "Tablet", "Phone"], 0) >>>)
ids.push(screen.select_box(&["Xu source", "Configuration", "Plain text"], 0) >>>)
ids.push(screen.list_box(&["Compiler", "Widgets", "Runtime", "Desktop", "Examples", "Tooling"], 0) >>>)
ids.push(screen.progress(0.62) >>>)
ids.push(screen.badge("Ready") >>>)
ids.push(screen.divider(widgets.AXIS_HORIZONTAL) >>>)
ids.push(screen.radio_group(&["Use local build", "Use cached build", "Build dependencies"], 0) >>>)
ids.push(screen.input("Native input · 中文") >>>)
ids.push(screen.text_area("A multi-line editor.\nSelection, clipboard and native IME remain available.") >>>)
ids.push(screen.date_picker(time.date(2026, 10, 25, 10, 30, 0, 0)) >>>)
ids.push(screen.time_picker(time.date(2026, 10, 25, 10, 30, 0, 0)) >>>)
ids.push(screen.button("Queue notification") >>>)
_ := screen.tooltip(ids[19], "Repeated notifications queue; hover or focus pauses expiry.") >>>
screen.set_slider_commit_only(ids[5], true) >>>
screen.set_checkbox_indeterminate(ids[2], true) >>>
screen.set_select_option_enabled(ids[9], 2, false) >>>
screen.set_badge_tone(ids[12], widgets.BADGE_SUCCESS) >>>
screen.set_progress_buffer(ids[11], 0.84) >>>
screen.set_date_options(ids[17], time.date(2026, 10, 25, 0, 0, 0, 0), true) >>>
screen.set_clock_format(ids[18], true, true) >>>
<< ids
}
fn extra_layout(screen $&widgets.Screen, ids &[]int) int {
gap := 28.0
width :=(screen.width() - 84.0) * 0.5
right := 56.0 + width
screen.place(ids[0], gap, 628.0, width, 112.0) >>>
screen.place(ids[1], gap, 173.0, screen.width() - 56.0, 24.0) >>>
for i in 2:5 {screen.place(ids[i], gap, 211.0 + f64(i - 2) * 46.0, width, 36.0) >>> }
screen.place(ids[5], gap, 357.0, width - 136.0, 36.0) >>>
screen.place(ids[6], gap + width - 124.0, 357.0, 124.0, 36.0) >>>
screen.place(ids[7], gap, 412.0, width, 36.0) >>>
screen.place(ids[8], gap, 466.0, width, 36.0) >>>
screen.place(ids[11], gap, 522.0, width - 120.0, 12.0) >>>
screen.place(ids[12], gap + width - 100.0, 510.0, 100.0, 32.0) >>>
screen.place(ids[13], gap, 607.0, width, 1.0) >>>
screen.place(ids[14], right, 211.0, width, 126.0) >>>
screen.place(ids[9], right, 357.0, width, 36.0) >>>
screen.place(ids[10], right, 412.0, width, 158.0) >>>
screen.place(ids[15], right, 590.0, width, 36.0) >>>
screen.place(ids[16], right, 644.0, width, 96.0) >>>
screen.place(ids[17], gap, 560.0,(width - 16.0) * 0.5, 36.0) >>>
screen.place(ids[18], gap +(width + 16.0) * 0.5, 560.0,(width - 16.0) * 0.5, 36.0) >>>
screen.place(ids[19], gap + 16.0, 665.0, width - 32.0, 38.0) >>>
<< 0
}
fn next_event(events chan ui.Event, deadline time.Instant) ui.Event{
if deadline.is_zero() { << <- events}
delay := deadline.since(time.instant())
if delay.nanoseconds() <= 0 { << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}}
timer := delay.timer()
select {
event := <- events{timer.stop()
<< event}
_ := <- timer.c{timer.stop()}
}
<< ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
}
fn scene(events chan ui.Event) int {
ready := demo.ready(events) >>>
if ready.kind == ui.EV_EXIT{ << 0}
$screen := widgets.screen(&ready) >>>
screen.resize(1000.0, 820.0) >>>
screen.set_min_size(900, 720) >>>
$model := make_model($&screen) >>> (err) {screen.dispose()
>> err}
apply_appearance($&model, $&screen) >>>
model.layout($&screen) >>>
_ := screen.render() >>>
$dispatcher := register_actions(&model, &screen) >>>
while screen.is_open() {
now := time.instant()
apply_appearance($&model, $&screen) >>>
register_notices(&screen, $&dispatcher) >>>
model.work($&screen, now) >>>
model.layout($&screen) >>>
$deadline := screen.advance(now) >>> (err) { >> errors.new("gallery animation: " + err.msg())}
for action in screen.take_actions() {_ := dispatcher.dispatch(&action, $&model, $&screen) >>> }
apply_appearance($&model, $&screen) >>>
_ := screen.render() >>> (err) { >> errors.new("gallery render: " + err.msg())}
if model.running &&(deadline.is_zero() || model.next_work.before(deadline)) {deadline = model.next_work}
event := next_event(events, deadline) >>>
$actions := screen.event(&event) >>>
$count := 0
while screen.is_open() && count < 128 {
pending := ui.poll_chan(events)
if pending.kind == ui.EV_NONE{ <- }
more := screen.event(&pending) >>>
for action in more{actions.push(action)}
count += 1
}
for action in actions{_ := dispatcher.dispatch(&action, $&model, $&screen) >>> }
}
screen.dispose()
<< 0
}
fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
<< }}
fn launch() int {
$app := demo.app("XUUI / Interaction Lab", 1000, 820) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) {eprintln(err.msg())
<< 1}}16_ui_webview/editor_workbench/main.xu@main
#ui
#ui/draw
#ui/widgets
#ui/layout
tokens #xuui_tokens
demo #"github.com/xulang-org/examples/ui_demo"
struct Model{
title widgets.Editor
body widgets.Editor
context draw.Context
styles widgets.Styles
dark bool
header int
title_id int
body_id int
footer int
changes int
status string
}
fn (model $&Model) input(id int, kind int, event &ui.InputEvent) widgets.Action{
if id == model.title_id{control := $&model.title
<< control.route(kind, event) >>> }
if id == model.body_id{control := $&model.body
<< control.route(kind, event) >>> }
<< widgets.Action{kind: 0, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
}
fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
model.draw_node(id, frame) >>> (err) {eprintln(err.msg())
<< false}
<< true
}
fn (model $&Model) draw_node(id int,frame $&draw.Frame) int {
styles := model.styles.clone()
if id == model.title_id { control := $&model.title
control.paint_styled(frame,&styles) >>> }
else if id == model.body_id { control := $&model.body
control.paint_styled(frame,&styles) >>> }
else if id == model.header {
demo.text(&model.context,frame,0.0,0.0,24.0,tokens.text(model.dark),"Writing desk") >>>
demo.text(&model.context,frame,0.0,34.0,14.0,tokens.muted(model.dark),"XUUI design standard · native text and menu controls") >>>
demo.text(&model.context,frame,0.0,62.0,14.0,tokens.muted(model.dark),"Tab / Shift+Tab · drag selection · copy / cut / paste · arrows / Home / End") >>>
} else if id == model.footer {
demo.text(&model.context,frame,0.0,0.0,14.0,tokens.brand(model.dark),"Changes: " + str(model.changes) + " | " + model.status) >>>
demo.text(&model.context,frame,0.0,27.0,14.0,tokens.muted(model.dark),"Use the Document menu: toggle editing, reset, query screens. Escape quits.") >>>
}
<< 0
}
fn (model $&Model) place(view $&widgets.View) int {
title := $&model.title
widgets.place_editor(view, title) >>>
body := $&model.body
widgets.place_editor(view, body) >>>
<< 0
}
fn (model $&Model) native_event(event &ui.Event) bool {
title := $&model.title
first := title.event(event) >>>
body := $&model.body
second := body.event(event) >>>
<< first.kind == widgets.ACTION_CHANGE || second.kind == widgets.ACTION_CHANGE
}
fn (model $&Model) editing(on bool) int {
title := $&model.title
title.enable(on) >>>
body := $&model.body
body.enable(on) >>>
<< 0
}
fn (model $&Model) reset() int {
title := $&model.title
title.set_value(&"Untitled note") >>>
body := $&model.body
body.set_value(&"Write here.\n你好,Xu。\n\nSelection and IME are native; layout and painting stay in the retained View.") >>>
<< 0
}
fn menus(window &ui.Window,enabled bool,dark bool) int {
$entries := [ui.submenu("document","Document",-1)]
$reset := ui.menu_action("reset","Reset note",0)
reset.key = 82
reset.modifiers = ui.MENU_PRIMARY | ui.MOD_SHIFT
entries.push(reset)
entries.push(ui.menu_check("editing","Enable editing",0,enabled))
entries.push(ui.menu_separator(0))
entries.push(ui.submenu("display","Displays",0))
$query := ui.menu_action("screens","Query current screens",4)
query.key = 68
query.modifiers = ui.MENU_PRIMARY | ui.MOD_SHIFT
entries.push(query)
$unavailable := ui.menu_action("unavailable","Unavailable action",4)
unavailable.enabled = false
entries.push(unavailable)
entries.push(ui.menu_check("dark-theme","Dark appearance",0,dark))
<< window.set_menu_entries(entries) >>>
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT{ << 0}
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
window := ui.Window{id: identity.window_id, generation: identity.generation, title: "", width: 0, height: 0, content_kind: ui.CONTENT_DRAW, content_backend_id: identity.canvas_id, closed: 0}
menus(&window, true, false) >>>
host := widgets.Host{context: context, identity: identity}
$column := layout.box_style(layout.BOX_COLUMN)
column.padding = layout.insets(24.0) >>>
column.gap = 16.0
column.cross_alignment = layout.CROSS_STRETCH
$view := host.view(&column, tokens.canvas(false)) >>>
leaf := layout.box_style(layout.BOX_LEAF)
header := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 88.0}) >>>
title_id := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 44.0}) >>>
body_id := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 260.0}) >>>
footer := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 72.0}) >>>
for id in[header, title_id, body_id, footer] {view.set_boundary(id, true) >>> }
for id in[title_id, body_id] {view.set_input(id, true, true) >>> }
empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
$model := Model{title: widgets.input(&context, &identity, title_id, &empty, &"Untitled note") >>>,
body: widgets.text_area(&context, &identity, body_id, &empty, &"Write here.\n你好,Xu。\n\nSelection and IME are native; layout and painting stay in the retained View.") >>>,
context: context, styles: tokens.editor_styles(false), dark: false, header: header, title_id: title_id, body_id: body_id, footer: footer, changes: 0, status: "Ready"}
$dispatcher := widgets.action_dispatcher(&model, &view)
dispatcher.on(title_id, widgets.ACTION_SUBMIT, submit_title) >>>
$width := 820.0
$height := 620.0
$enabled := true
options := ui.RequestOptions{timeout_ms: 5000}
$screens := window.screens_async(&options) >>>
$event := ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
// Native text snapshots already carry the latest revision. Drain queued
// edits before painting so a key burst cannot fill the frame queue.
while true {
if event.kind == ui.EV_NONE{
constraints := layout.tight(width, height) >>>
_ := view.layout(&constraints) >>>
model.place($&view) >>>
submitted := widgets.present($&view, &constraints, $&model) >>>
if submitted{
first := $&model.title
first.painted()
second := $&model.body
second.painted()
}
event = demo.next(ech)
}
if event.kind == ui.EV_EXIT{ <- }
if event.window_id != identity.window_id{event = ui.poll_chan(ech)
-> }
if event.kind == ui.EV_CANVAS_METRICS{metrics := ui.metrics_of(&event) >>>
width = metrics.width
height = metrics.height}
actions := widgets.dispatch_event($&view, &event, $&model) >>>
if model.native_event(&event) >>> {model.changes = model.changes + 1
view.mark_paint(footer) >>> }
for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) >>> }
if event.kind == ui.EV_MENU_CLICKED{
if event.menu_id == "reset" {model.reset() >>> }
if event.menu_id == "editing" {enabled = !enabled
model.editing(enabled) >>>
for id in[title_id, body_id] {view.set_input(id, enabled, enabled) >>> }
menus(&window, enabled, model.dark) >>> }
if event.menu_id == "dark-theme" {
model.dark = !model.dark
model.styles = tokens.editor_styles(model.dark)
view.set_background(tokens.canvas(model.dark))
for id in [header,title_id,body_id,footer] { view.mark_paint(id) >>> }
menus(&window,enabled,model.dark) >>>
}
if event.menu_id == "screens" {screens.cancel()
screens = window.screens_async(&options) >>> }
}
if event.kind == ui.EV_REQUEST{result := ui.request_of(&event) >>>
if result.matches(&screens) && result.status == ui.REQUEST_COMPLETED{
displays := ui.screen_result(&result) >>>
model.status = str(displays.len) + " display(s)"
for display in displays{println("Screen: " + display.name + " / " + str(int(display.bounds.width)) + " x " + str(int(display.bounds.height)) + " / scale " + str(int(display.scale_x)))
if display.current{model.status = display.name + " · " + str(int(display.bounds.width)) + " x " + str(int(display.bounds.height))}}
view.mark_paint(footer) >>>
}
}
if event.kind == ui.EV_CANVAS_CLOSED || event.kind == ui.EV_CLOSED{ <- }
if ui.is_input_event(event.kind) {input := ui.input_of(&event) >>>
if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() >>> }}
event = ui.poll_chan(ech)
}
screens.cancel()
view.dispose()
<< 0
}
fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
<< }}
fn main() int {
$app := demo.app("Xu UI / Writing Desk", 820, 620) >>> (err) {eprintln(err.msg())
<< 1}
xu worker(app.event_ch)
<< app.run() >>> (err) {eprintln(err.msg())
<< 1}
}16_ui_webview/workbench/main.xu@main
#ui
#ui/draw
#ui/layout
#ui/widgets
#math
demo #"github.com/xulang-org/examples/ui_demo"
struct Model{
button widgets.Button
checkbox widgets.Checkbox
progress widgets.Progress
scroll widgets.Scroll
button_label draw.TextLayout
checkbox_label draw.TextLayout
theme widgets.Theme
context draw.Context
count int
message string
source string
images []draw.Image
header_id int
button_id int
check_id int
progress_id int
scroll_id int
row_ids []int
identity ui.CanvasEvent
pending ui.Request
}
fn (model $&Model) button_input(kind int, input &ui.InputEvent) widgets.Action{
button := $&model.button
<< button.route(kind, input) >>>
}
fn (model $&Model) checkbox_input(kind int, input &ui.InputEvent) widgets.Action{
checkbox := $&model.checkbox
<< checkbox.route(kind, input) >>>
}
fn (model $&Model) scroll_input(kind int, input &ui.InputEvent) widgets.Action{
scroll := $&model.scroll
<< scroll.route(kind, input) >>>
}
fn (model $&Model) input(id int, kind int, input &ui.InputEvent) widgets.Action{
if id == model.button_id{ << model.button_input(kind, input) >>> }
if id == model.check_id{ << model.checkbox_input(kind, input) >>> }
if id == model.scroll_id{ << model.scroll_input(kind, input) >>> }
<< widgets.Action{kind: widgets.ACTION_NONE, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
}
fn (model $&Model) place_button(bounds &layout.Rect) int {
button := $&model.button
<< button.set_bounds(bounds) >>>
}
fn (model $&Model) place_checkbox(bounds &layout.Rect) int {
checkbox := $&model.checkbox
<< checkbox.set_bounds(bounds) >>>
}
fn (model $&Model) place_progress(bounds &layout.Rect) int {
progress := $&model.progress
<< progress.set_bounds(bounds) >>>
}
fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
model.draw_node(id, bounds, frame) >>> (err) {eprintln(err.msg())
<< false}
<< true
}
fn (model $&Model) draw_node(id int, bounds &layout.Rect, frame $&draw.Frame) int {
if id == model.header_id{
demo.text(&model.context, frame, 0.0, 0.0, 14.0, demo.accent(), "07 / IMAGE WORKBENCH") >>>
demo.text(&model.context, frame, 0.0, 28.0, 24.0, demo.ink(), "Image workbench") >>>
demo.text(&model.context, frame, 0.0, 58.0, 13.0, demo.muted(), model.message + "") >>>
} else if id == model.button_id{
model.place_button(bounds) >>>
model.button.paint(frame, &model.button_label, &model.theme) >>>
} else if id == model.check_id{
model.place_checkbox(bounds) >>>
model.checkbox.paint(frame, &model.checkbox_label, &model.theme) >>>
} else if id == model.progress_id{
model.place_progress(bounds) >>>
model.progress.paint(frame, &model.theme) >>>
} else if id == model.scroll_id{
scroll := $&model.scroll
scroll.set_bounds(bounds) >>>
frame.fill_rect(0.0, 0.0, bounds.width, bounds.height, draw.rgb(26, 37, 50)) >>>
} else if model.row_ids.len > 0 && id == model.row_ids[0] {
if model.images.len > 0 {
image := model.images[0]
scale := math.min(bounds.width / f64(image.width), bounds.height / f64(image.height))
frame.image(&image, 0.0, 0.0, f64(image.width) * scale, f64(image.height) * scale) >>>
} else {demo.text(&model.context, frame, 12.0, 20.0, 17.0, demo.muted(), "The selected image appears here.") >>> }
}
<< 0
}
fn (model $&Model) progress_value(value f64) int {
progress := $&model.progress
<< progress.set_value(value) >>>
}
fn (model $&Model) retire_image(index int) int {
$image := model.images[index]
image.dispose() >>>
model.images[index] = image
<< 0
}
fn (model $&Model) replace_image(image draw.Image) int {
for i in 0:model.images.len{model.retire_image(i) >>> }
model.images =[]draw.Image{}
model.images.push(image)
<< 0
}
fn preview_paint(window &ui.Window, path &string) int {
context := draw.window_context(window) >>>
$image := context.load_image(path) >>>
$frame := context.new_frame(256)
frame.begin() >>>
frame.set_bg(demo.background()) >>>
scale := math.min(f64(window.width - 40) / f64(image.width), f64(window.height - 40) / f64(image.height))
frame.image(&image, 20.0, 20.0, f64(image.width) * scale, f64(image.height) * scale) >>>
frame.present() >>>
frame.dispose()
image.dispose() >>>
<< 0
}
fn (model $&Model) acknowledge_button() {
control := $&model.button
control.painted()
}
fn (model $&Model) acknowledge_checkbox() {
control := $&model.checkbox
control.painted()
}
fn (model $&Model) acknowledge_progress() {
control := $&model.progress
control.painted()
}
fn (model $&Model) acknowledge_scroll() {
control := $&model.scroll
control.painted()
}
fn (model $&Model) acknowledge() {
model.acknowledge_button()
model.acknowledge_checkbox()
model.acknowledge_progress()
model.acknowledge_scroll()
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT{ << 0}
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
host := widgets.Host{context: context, identity: identity}
$column := layout.box_style(layout.BOX_COLUMN)
column.padding = layout.insets(28.0) >>>
column.gap = 14.0
column.cross_alignment = layout.CROSS_STRETCH
$view := host.view(&column, demo.background()) >>>
leaf := layout.box_style(layout.BOX_LEAF)
header := view.add(view.root(), &leaf, &layout.Size{width: 400.0, height: 88.0}) >>>
button_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 44.0}) >>>
check_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 40.0}) >>>
progress_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 12.0}) >>>
$viewport := layout.box_style(layout.BOX_COLUMN)
viewport.height = 260.0
viewport.clip = true
viewport.cross_alignment = layout.CROSS_STRETCH
viewport.gap = 6.0
scroll_id := view.add(view.root(), &viewport, &layout.Size{width: 400.0, height: 260.0}) >>>
$rows :=[]int {}
for _ in 0:1 {
row := view.add(scroll_id, &leaf, &layout.Size{width: 400.0, height: 250.0}) >>>
rows.push(row)
view.set_boundary(row, true) >>>
}
for id in[header, button_id, check_id, progress_id, scroll_id] {view.set_boundary(id, true) >>> }
for id in[button_id, check_id, scroll_id] {view.set_input(id, true, true) >>> }
empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
options := draw.text_options(15.0)
first := "Open a PNG or JPEG"
second := "Show a separate preview window"
$model := Model{button: widgets.button(&identity, button_id, &empty) >>>,
checkbox: widgets.checkbox(&identity, check_id, &empty, true) >>>,
progress: widgets.progress(&empty, 0.0) >>>,
scroll: widgets.scroll(&identity, scroll_id, &empty, widgets.AXIS_VERTICAL, 250.0) >>>,
button_label: context.layout_text(&first, &options) >>>,
checkbox_label: context.layout_text(&second, &options) >>>,
theme: widgets.default_theme(), context: context, count: 0, message: "Open a local image to begin.", source: "", images:[]draw.Image{}, header_id: header, button_id: button_id, check_id: check_id, progress_id: progress_id, scroll_id: scroll_id, row_ids: rows, identity: identity, pending: ui.Request{id: 0, window_id: 0, canvas_id: 0, generation: 0, kind: 0}}
$width := 900.0
$height := 700.0
$native := demo.windows(ech)
$preview := ui.Window{id: 0, generation: 0, title: "Preview", width: 720, height: 500, content_kind: ui.CONTENT_DRAW, content_backend_id: 0, closed: 1}
dispatcher := register_actions(&model, &view) >>>
while true {
constraints := layout.tight(width, height) >>>
submitted := widgets.present($&view, &constraints, $&model) >>>
if submitted{model.acknowledge()}
event := demo.next(ech)
if event.kind == ui.EV_EXIT{ <- }
if preview.id > 0 && event.window_id == preview.id{
if event.kind == ui.EV_CLOSED || event.kind == ui.EV_WINDOW_FAILED{preview.closed = 1}
if event.kind == ui.EV_CANVAS_READY && model.source.len > 0 {
preview.content_command("input_enabled\t1") >>>
preview.content_command("pan_enabled\t0") >>>
preview_paint(&preview, &model.source) >>> }
if event.kind == ui.EV_CANVAS_METRICS{
metrics := ui.metrics_of(&event) >>>
if metrics.width > 40.0 && metrics.height > 40.0 {preview.width = int(metrics.width)
preview.height = int(metrics.height)
if model.source.len > 0 {preview_paint(&preview, &model.source) >>> }}
}
->
}
if event.window_id != identity.window_id{ -> }
if event.kind == ui.EV_REQUEST{
result := ui.request_of(&event) >>>
if result.matches(&model.pending) {
model.pending.id = 0
model.message = "Selection cancelled or failed."
if result.status == ui.REQUEST_COMPLETED{
paths := ui.file_paths(&result) >>>
if paths.len > 0 {
path := paths[0] + ""
image := context.load_image(&path) >>> (err) {model.message = err.msg()
view.mark_paint(header) >>>
-> }
model.replace_image(image) >>>
model.source = path + ""
model.message = "Loaded " + str(image.width) + " x " + str(image.height) + " pixels"
println(model.message + "")
model.progress_value(1.0) >>>
view.mark_paint(model.row_ids[0]) >>>
if model.checkbox.value() {
if preview.closed != 0 {preview = native.open_content_window(ui.WindowOpts{title: "Xu UI / Image Preview", width: 720, height: 500}, ui.CONTENT_DRAW) >>> }
else {preview_paint(&preview, &path) >>>
preview.focus() >>> }
}
}
}
view.mark_paint(header) >>>
view.mark_paint(progress_id) >>>
}
}
if event.kind == ui.EV_CANVAS_METRICS{
metrics := ui.metrics_of(&event) >>>
if metrics.width > 0.0 && metrics.height > 0.0 {width = metrics.width
height = metrics.height}
}
actions := widgets.dispatch_event($&view, &event, $&model) >>>
for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) >>> }
if event.kind == ui.EV_CANVAS_CLOSED{demo.quit() >>>
<- }
if ui.is_input_event(event.kind) {
input := ui.input_of(&event) >>>
if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() >>> }
}
stats := view.stats()
if stats.recorded_boundaries > 0 || stats.reused_boundaries > 0 {
println("View: " + str(stats.recorded_boundaries) + " recorded / " + str(stats.reused_boundaries) + " reused boundaries")
}
}
if model.pending.id > 0 {_ := model.pending.cancel()}
view.dispose()
// Native close has already revoked this canvas's images and text layouts.
if demo.alive(&identity) {
for i in 0:model.images.len{model.retire_image(i) >>> }
label := $&model.button_label
label.dispose() >>>
check_label := $&model.checkbox_label
check_label.dispose() >>>
}
<< 0
}
fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
<< }}
fn launch() int {
$app := demo.app("Xu UI / Retained Image Workbench", 900, 700) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) {eprintln(err.msg())
<< 1}}@main
#ui
#ui/widgets
fn open_image(m $&Model, screen $&widgets.View, action &widgets.Action) string {
if m.pending.id != 0 { << ""}
$options := ui.file_dialog_options()
options.title = "Open an image"
options.filters =[ui.FileFilter{label: "Images", extensions:["png", "jpg", "jpeg"]}]
m.pending = ui.open_files_async(&m.identity, &options) >>> (err) { << err.msg()}
m.message = "Choose a PNG or JPEG in the native dialog."
m.progress_value(0.2) >>> (err) { << err.msg()}
screen.mark_paint(m.header_id) >>> (err) { << err.msg()}
screen.mark_paint(m.progress_id) >>> (err) { << err.msg()}
<< ""
}
fn scroll(m $&Model, screen $&widgets.View, action &widgets.Action) string {
screen.set_scroll(m.scroll_id, 0.0, action.value) >>> (err) { << err.msg()}
<< ""
}
fn register_actions(m &Model, screen &widgets.View) widgets.ActionDispatcher#Model, widgets.View, widgets.Action{
$d := widgets.action_dispatcher(m, screen)
d.on(m.button_id, widgets.ACTION_ACTIVATE, open_image) >>>
d.on(m.scroll_id, widgets.ACTION_SCROLL, scroll) >>>
<< d
}16_ui_webview/style_gallery/main.xu@main
#ui
#ui/draw
#ui/widgets
#ui/layout
#time
demo #"github.com/xulang-org/examples/ui_demo"
// IDs follow the stable topology created below. All control bounds are local;
// Editor.place receives the separate canvas rectangle for native IME geometry.
struct Model{
theme widgets.Button
scale widgets.Button
density widgets.Button
brand widgets.Button
disabled widgets.Button
check widgets.Checkbox
toggle widgets.Switch
radio_a widgets.Radio
radio_b widgets.Radio
slider widgets.Slider
stepper widgets.Stepper
tabs widgets.Tabs
select_ctrl widgets.Select
select_origin layout.Rect
select_popup_armed bool
transitions []widgets.PaintTransition
switch_motion widgets.Tween
popup_motion widgets.Tween
clock time.Instant
reduced_motion bool
theme_index int
text_scale f64
density_scale f64
appearance_dirty bool
badge widgets.Badge
divider widgets.Divider
card widgets.Card
list widgets.ListBox
input widgets.Editor
invalid widgets.Editor
read_only widgets.Editor
area widgets.Editor
progress widgets.Progress
scroll widgets.Scroll
context draw.Context
icon draw.Image
switcher widgets.StyleSwitcher
theme_label widgets.StyledLabel
scale_label widgets.StyledLabel
density_label widgets.StyledLabel
brand_label widgets.StyledLabel
disabled_label widgets.StyledLabel
check_label widgets.StyledLabel
toggle_label widgets.StyledLabel
radio_a_label widgets.StyledLabel
radio_b_label widgets.StyledLabel
stepper_label widgets.StyledLabel
badge_label widgets.StyledLabel
divider_label widgets.StyledLabel
card_label widgets.StyledLabel
tab_label widgets.StyledLabel
tab_2_label widgets.StyledLabel
tab_3_label widgets.StyledLabel
select_label widgets.StyledLabel
option_auto widgets.StyledLabel
option_manual widgets.StyledLabel
option_locked widgets.StyledLabel
list_label widgets.StyledLabel
list_2_label widgets.StyledLabel
list_3_label widgets.StyledLabel
list_4_label widgets.StyledLabel
}
fn (m $&Model) motion_style(id int, base &widgets.ControlStyle, state int) widgets.ControlStyle{
now := m.clock
reduced := m.reduced_motion
motion := $&m.transitions[id]
<< motion.style(base, state, now, reduced) >>>
}
fn (m $&Model) tick(view $&widgets.View, now time.Instant) int {
m.clock = now
reduced := m.reduced_motion
for id in 1:m.transitions.len{
motion := $&m.transitions[id]
if reduced && motion.is_animating() {motion.finish()
view.mark_paint(id) >>> }
else if motion.advance(now) >>> {view.mark_paint(id) >>> }
}
$selected := 0.0
if m.toggle.value() {selected = 1.0}
switch_motion := $&m.switch_motion
before_switch := switch_motion.value()
switch_motion.retarget(selected, now, time.milliseconds(180) >>>, reduced) >>>
if before_switch != switch_motion.value() {view.mark_paint(32) >>> }
$opened := 0.0
if m.select_ctrl.is_open() {opened = 1.0}
popup_motion := $&m.popup_motion
before_popup := popup_motion.value()
$popup_duration := time.milliseconds(130) >>>
if opened == 0.0 {popup_duration = time.milliseconds(95) >>> }
popup_motion.retarget(opened, now, popup_duration, reduced) >>>
if before_popup != popup_motion.value() {view.mark_paint(1) >>> }
input := $&m.input
if input.tick(now, reduced) >>> {view.mark_paint(12) >>> }
invalid := $&m.invalid
if invalid.tick(now, reduced) >>> {view.mark_paint(13) >>> }
read_only := $&m.read_only
if read_only.tick(now, reduced) >>> {view.mark_paint(14) >>> }
area := $&m.area
if area.tick(now, reduced) >>> {view.mark_paint(15) >>> }
<< 0
}
fn (m &Model) next_frame(now time.Instant) time.Instant{
if m.switch_motion.is_animating() || m.popup_motion.is_animating() { << now.add(time.milliseconds(16) >>>) >>> }
for motion in m.transitions{if motion.is_animating() { << now.add(time.milliseconds(16) >>>) >>> }}
$deadline := time.zero_instant()
for next in[m.input.next_caret_tick(now, m.reduced_motion) >>>, m.invalid.next_caret_tick(now, m.reduced_motion) >>>,
m.read_only.next_caret_tick(now, m.reduced_motion) >>>, m.area.next_caret_tick(now, m.reduced_motion) >>>] {
if !next.is_zero() &&(deadline.is_zero() || next.before(deadline)) {deadline = next}
}
<< deadline
}
fn (m &Model) next_event(ech chan ui.Event) ui.Event{
deadline := m.next_frame(time.instant()) >>>
while true {
event := ui.poll_chan(ech)
if event.kind != ui.EV_NONE{ << event}
if !deadline.is_zero() && !time.instant().before(deadline) { << event}
pause := time.milliseconds(8) >>>
pause.sleep()
}
<< ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
}
fn (m $&Model) measure_node(id int, s &widgets.Styles) layout.Size{
if id == 4 {control := m.theme.clone()
label := $&m.theme_label
<< control.measure_styled(label, s) >>> }
if id == 5 {control := m.scale.clone()
label := $&m.scale_label
<< control.measure_styled(label, s) >>> }
if id == 6 {control := m.density.clone()
label := $&m.density_label
<< control.measure_styled(label, s) >>> }
if id == 8 {control := m.brand.clone()
label := $&m.brand_label
<< control.measure_icon_styled(label, s) >>> }
if id == 9 {control := m.disabled.clone()
label := $&m.disabled_label
<< control.measure_styled(label, s) >>> }
if id == 10 {control := m.check.clone()
label := $&m.check_label
<< control.measure_styled(label, s) >>> }
if id == 11 {control := m.progress.clone()
<< control.measure_styled(s) >>> }
if id == 12 {control := $&m.input
<< control.measure_styled(s) >>> }
if id == 13 {control := $&m.invalid
<< control.measure_styled(s) >>> }
if id == 14 {control := $&m.read_only
<< control.measure_styled(s) >>> }
if id == 15 {control := $&m.area
<< control.measure_styled(s) >>> }
if id == 32 {control := m.toggle.clone()
label := $&m.toggle_label
<< control.measure_styled(label, s) >>> }
if id == 33 {control := m.radio_a.clone()
label := $&m.radio_a_label
<< control.measure_styled(label, s) >>> }
if id == 34 {control := m.radio_b.clone()
label := $&m.radio_b_label
<< control.measure_styled(label, s) >>> }
if id == 35 {control := m.slider.clone()
<< control.measure_styled(s) >>> }
if id == 36 {control := m.stepper.clone()
label := $&m.stepper_label
<< control.measure_styled(label, s) >>> }
if id == 37 {control := m.badge.clone()
label := $&m.badge_label
<< control.measure_styled(label, s) >>> }
if id == 38 {control := m.divider.clone()
label := $&m.divider_label
<< control.measure_labeled_styled(label, s) >>> }
if id == 40 {control := m.tabs.clone()
label := $&m.tab_label
<< control.measure_styled(label, s) >>> }
if id == 41 {control := m.select_ctrl.clone()
label := $&m.select_label
<< control.measure_styled(label, s) >>> }
if id == 42 {control := m.card.clone()
label := $&m.card_label
<< control.measure_header_styled(label, s) >>> }
if id == 43 {control := m.list.clone()
label := $&m.list_label
<< control.measure_styled(label, s) >>> }
<< layout.Size{width: 0.0, height: 0.0}
}
fn (m $&Model) measure_styled(id int, s &widgets.Styles) layout.Size{
<< m.measure_node(id, s) >>> (err) {eprintln(err.msg())
<< layout.Size{width: - 1.0, height: - 1.0}}
}
fn (m $&Model) draw_node(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) int {
if id == 4 {target := $&m.theme
target.set_bounds(b) >>>
$control := m.theme.clone()
base := control.style_or(s)
appearance := m.motion_style(4, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.theme_label
control.paint_styled(f, label, s) >>> }
if id == 5 {target := $&m.scale
target.set_bounds(b) >>>
$control := m.scale.clone()
base := control.style_or(s)
appearance := m.motion_style(5, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.scale_label
control.paint_styled(f, label, s) >>> }
if id == 6 {target := $&m.density
target.set_bounds(b) >>>
$control := m.density.clone()
base := control.style_or(s)
appearance := m.motion_style(6, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.density_label
control.paint_styled(f, label, s) >>> }
if id == 8 {target := $&m.brand
target.set_bounds(b) >>>
$control := m.brand.clone()
base := control.style_or(s)
appearance := m.motion_style(8, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
icon := m.icon
label := $&m.brand_label
control.paint_icon_styled(f, label, &icon, s) >>> }
if id == 9 {target := $&m.disabled
target.set_bounds(b) >>>
$control := m.disabled.clone()
base := control.style_or(s)
appearance := m.motion_style(9, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.disabled_label
control.paint_styled(f, label, s) >>> }
if id == 10 {target := $&m.check
target.set_bounds(b) >>>
$control := m.check.clone()
base := control.style_or(s)
appearance := m.motion_style(10, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.check_label
control.paint_styled(f, label, s) >>> }
if id == 12 {
now := m.clock
reduced := m.reduced_motion
$motion := m.transitions[12]
control := $&m.input
control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
m.transitions[12] = motion}
if id == 13 {
now := m.clock
reduced := m.reduced_motion
$motion := m.transitions[13]
control := $&m.invalid
control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
m.transitions[13] = motion}
if id == 14 {
now := m.clock
reduced := m.reduced_motion
$motion := m.transitions[14]
control := $&m.read_only
control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
m.transitions[14] = motion}
if id == 15 {
now := m.clock
reduced := m.reduced_motion
$motion := m.transitions[15]
control := $&m.area
control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
m.transitions[15] = motion}
if id == 11 {control := $&m.progress
control.set_bounds(b) >>>
control.paint_styled(f, s) >>> }
if id == 32 {target := $&m.toggle
target.set_bounds(b) >>>
$control := m.toggle.clone()
base := control.style_or(s)
appearance := m.motion_style(32, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
position := m.switch_motion.value()
label := $&m.toggle_label
control.paint_position_styled(f, label, s, position) >>> }
if id == 33 {target := $&m.radio_a
target.set_bounds(b) >>>
$control := m.radio_a.clone()
base := control.style_or(s)
appearance := m.motion_style(33, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.radio_a_label
control.paint_styled(f, label, s) >>> }
if id == 34 {target := $&m.radio_b
target.set_bounds(b) >>>
$control := m.radio_b.clone()
base := control.style_or(s)
appearance := m.motion_style(34, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.radio_b_label
control.paint_styled(f, label, s) >>> }
if id == 35 {target := $&m.slider
target.set_bounds(b) >>>
$control := m.slider.clone()
base := control.style_or(s)
appearance := m.motion_style(35, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
control.paint_styled(f, s) >>> }
if id == 36 {target := $&m.stepper
target.set_bounds(b) >>>
$control := m.stepper.clone()
base := control.style_or(s)
appearance := m.motion_style(36, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.stepper_label
control.paint_styled(f, label, s) >>> }
if id == 37 {target := $&m.badge
target.set_bounds(b) >>>
control := m.badge.clone()
label := $&m.badge_label
control.paint_styled(f, label, s) >>> }
if id == 38 {target := $&m.divider
target.set_bounds(b) >>>
control := m.divider.clone()
label := $&m.divider_label
control.paint_labeled_styled(f, label, s) >>> }
if id == 40 {target := $&m.tabs
target.set_bounds(b) >>>
control := m.tabs.clone()
control.paint_box_styled(f, s) >>>
l0 := $&m.tab_label
control.paint_tab_styled(f, 0, l0, s) >>>
l1 := $&m.tab_2_label
control.paint_tab_styled(f, 1, l1, s) >>>
l2 := $&m.tab_3_label
control.paint_tab_styled(f, 2, l2, s) >>> }
if id == 41 {target := $&m.select_ctrl
target.set_bounds(b) >>>
$control := m.select_ctrl.clone()
base := control.style_or(s)
appearance := m.motion_style(41, &base, control.visual_state()) >>>
control.set_style(&appearance) >>>
label := $&m.select_label
control.paint_styled(f, label, s) >>> }
if id == 42 {target := $&m.card
target.set_bounds(b) >>>
control := m.card.clone()
label := $&m.card_label
control.paint_header_styled(f, label, s) >>>
demo.text(&m.context, f, 14.0 * s.density, 42.0 * s.density, 11.0 * s.text_scale, s.button.palette.muted, "Card body") >>> }
if id == 43 {target := $&m.list
target.set_bounds(b) >>>
control := m.list.clone()
control.paint_box_styled(f, s) >>>
r0 := $&m.list_label
control.paint_item_styled(f, 0, r0, s) >>>
r1 := $&m.list_2_label
control.paint_item_styled(f, 1, r1, s) >>>
r2 := $&m.list_3_label
control.paint_item_styled(f, 2, r2, s) >>>
r3 := $&m.list_4_label
control.paint_item_styled(f, 3, r3, s) >>> }
if id == 2 {
demo.text(&m.context, f, 0.0, 0.0, 24.0, s.button.palette.foreground, "A theme that reaches every control") >>>
demo.text(&m.context, f, 0.0, 33.0, 13.0, s.button.palette.muted, "Light / dark / contrast · typography · density · local overrides · no idle redraw") >>>
}
if id >= 18 && id <= 29 {
f.fill_rect(0.0, 0.0, b.width, b.height, s.input.palette.normal) >>>
demo.text(&m.context, f, 12.0, 5.0, 14.0, s.input.palette.foreground, "Scrollable item " + str(id - 17) + " — wheel, drag the thumb, or Page Down") >>>
}
if id == 30 {
demo.text(&m.context, f, 0.0, 0.0, 12.0, s.button.palette.muted, "The green button keeps its own font and palette. Error and read-only fields are distinct states.") >>>
demo.text(&m.context, f, 0.0, 21.0, 12.0, s.button.palette.muted, "Tab / Shift+Tab to move focus · copy from read-only text · Escape to quit") >>>
}
<< 0
}
fn (m $&Model) paint_styled(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) bool {
m.draw_node(id, b, s, f) >>> (err) {eprintln(err.msg())
<< false}
<< true
}
fn (m $&Model) overlay_styled(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) bool {
if id == 16 {control := $&m.scroll
control.paint_scrollbar(f, s) >>> (err) {eprintln(err.msg())
<< false}}
if id == 1 &&(m.select_ctrl.is_open() || m.popup_motion.value() > 0.0) {
m.paint_select_popup(s, f) >>> (err) {eprintln(err.msg())
<< false}
}
<< true
}
// Root overlay keeps the popup above every sibling and outside the button's box.
fn (m $&Model) paint_select_popup(s &widgets.Styles, f $&draw.Frame) int {
$control := m.select_ctrl.clone()
control.set_open(true)
opacity := m.popup_motion.value()
if opacity <= 0.0 { << 0}
base := control.style_or(s)
appearance := base.with_opacity(opacity) >>>
control.set_style(&appearance) >>>
popup := control.popup_bounds(s)
$offset := - 4.0 *(1.0 - opacity)
if popup.y < 0.0 {offset = 4.0 *(1.0 - opacity)}
f.push() >>>
f.translate(m.select_origin.x, m.select_origin.y + offset) >>>
control.paint_popup_box_styled(f, s) >>>
auto_label := $&m.option_auto
control.paint_option_styled(f, 0, auto_label, s) >>>
manual_label := $&m.option_manual
control.paint_option_styled(f, 1, manual_label, s) >>>
locked_label := $&m.option_locked
control.paint_option_styled(f, 2, locked_label, s) >>>
f.pop() >>>
<< 0
}
// The popup is an overlay, so route its pointer sequence before normal tree hits.
fn (m $&Model) dispatch_input(view $&widgets.View, event &ui.InputEvent)[]widgets.Action{
was_open := m.select_ctrl.is_open()
pointer := event.kind == ui.EV_POINTER_DOWN || event.kind == ui.EV_POINTER_UP ||
event.kind == ui.EV_POINTER_MOVE || event.kind == ui.EV_POINTER_SCROLL
if pointer &&(was_open || m.select_popup_armed) {
local := view.local_input(41, event) >>>
styles := view.styles_for(41) >>>
pop := m.select_ctrl.popup_bounds(&styles)
if pop.contains(local.x, local.y) || m.select_popup_armed{
if event.kind == ui.EV_POINTER_DOWN && event.button == ui.BUTTON_LEFT{m.select_popup_armed = true}
control := $&m.select_ctrl
action := control.input(&local) >>>
view.set_pointer_cursor(ui.CURSOR_HAND) >>>
if event.kind == ui.EV_POINTER_UP{m.select_popup_armed = false}
view.mark_paint(41) >>>
view.mark_paint(1) >>>
<<[action]
}
}
if event.kind == ui.EV_POINTER_CANCEL{m.select_popup_armed = false}
actions := widgets.dispatch(view, event, m) >>>
if was_open || m.select_ctrl.is_open() {view.mark_paint(1) >>> }
<< actions
}
fn (m $&Model) dispatch_event(view $&widgets.View, event &ui.Event)[]widgets.Action{
if ui.is_input_event(event.kind) {
input := ui.input_of(event) >>>
<< m.dispatch_input(view, &input) >>>
}
was_open := m.select_ctrl.is_open()
actions := widgets.dispatch_event(view, event, m) >>>
m.select_popup_armed = false
if was_open && !m.select_ctrl.is_open() {view.mark_paint(1) >>> }
<< actions
}
fn (m $&Model) input(id int, kind int, event &ui.InputEvent) widgets.Action{
if id == 4 {control := $&m.theme
<< control.route(kind, event) >>> }
if id == 5 {control := $&m.scale
<< control.route(kind, event) >>> }
if id == 6 {control := $&m.density
<< control.route(kind, event) >>> }
if id == 8 {control := $&m.brand
<< control.route(kind, event) >>> }
if id == 9 {control := $&m.disabled
<< control.route(kind, event) >>> }
if id == 10 {control := $&m.check
<< control.route(kind, event) >>> }
if id == 12 {control := $&m.input
<< control.route(kind, event) >>> }
if id == 13 {control := $&m.invalid
<< control.route(kind, event) >>> }
if id == 14 {control := $&m.read_only
<< control.route(kind, event) >>> }
if id == 15 {control := $&m.area
<< control.route(kind, event) >>> }
if id == 16 {control := $&m.scroll
<< control.route(kind, event) >>> }
if id == 32 {control := $&m.toggle
<< control.route(kind, event) >>> }
if id == 33 {control := $&m.radio_a
<< control.route(kind, event) >>> }
if id == 34 {control := $&m.radio_b
<< control.route(kind, event) >>> }
if id == 35 {control := $&m.slider
<< control.route(kind, event) >>> }
if id == 36 {control := $&m.stepper
<< control.route(kind, event) >>> }
if id == 40 {control := $&m.tabs
<< control.route(kind, event) >>> }
if id == 41 {control := $&m.select_ctrl
<< control.route(kind, event) >>> }
if id == 43 {control := $&m.list
<< control.route(kind, event) >>> }
<< widgets.Action{kind: 0, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
}
fn (m $&Model) place(view $&widgets.View) int {
select_bounds := view.node_bounds(41) >>>
m.select_origin = select_bounds
select_styles := view.styles_for(41) >>>
select_control := $&m.select_ctrl
select_control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: select_bounds.width, height: select_bounds.height}) >>>
select_control.apply_styles(&select_styles) >>>
popup := select_control.popup_bounds(&select_styles)
window_bounds := view.node_bounds(1) >>>
below := window_bounds.y + window_bounds.height - select_bounds.y - select_bounds.height
above := select_bounds.y - window_bounds.y
select_control.set_popup_above(below < popup.height + 2.0 * select_styles.density && above > below)
list_bounds := view.node_bounds(43) >>>
list_styles := view.styles_for(43) >>>
list_control := $&m.list
list_control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: list_bounds.width, height: list_bounds.height}) >>>
list_control.apply_styles(&list_styles) >>>
input := $&m.input
widgets.place_editor(view, input) >>>
invalid := $&m.invalid
widgets.place_editor(view, invalid) >>>
read_only := $&m.read_only
widgets.place_editor(view, read_only) >>>
area := $&m.area
widgets.place_editor(view, area) >>>
bounds := view.node_bounds(16) >>>
styles := view.styles_for(16) >>>
control := $&m.scroll
control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: bounds.width, height: bounds.height}) >>>
control.apply_styles(&styles) >>>
view.set_scroll(16, 0.0, control.offset()) >>>
<< 0
}
fn (m $&Model) native_event(view $&widgets.View, event &ui.Event) int {
input := $&m.input
action_12 := input.event(event) >>>
if action_12.needs_paint{view.mark_paint(12) >>> }
invalid := $&m.invalid
action_13 := invalid.event(event) >>>
if action_13.needs_paint{view.mark_paint(13) >>> }
read_only := $&m.read_only
action_14 := read_only.event(event) >>>
if action_14.needs_paint{view.mark_paint(14) >>> }
area := $&m.area
action_15 := area.event(event) >>>
if action_15.needs_paint{view.mark_paint(15) >>> }
<< 0
}
fn (m $&Model) acknowledge() {
theme := $&m.theme
theme.painted()
scale := $&m.scale
scale.painted()
density := $&m.density
density.painted()
brand := $&m.brand
brand.painted()
disabled := $&m.disabled
disabled.painted()
check := $&m.check
check.painted()
input := $&m.input
input.painted()
invalid := $&m.invalid
invalid.painted()
read_only := $&m.read_only
read_only.painted()
area := $&m.area
area.painted()
progress := $&m.progress
progress.painted()
scroll := $&m.scroll
scroll.painted()
toggle := $&m.toggle
toggle.painted()
radio_a := $&m.radio_a
radio_a.painted()
radio_b := $&m.radio_b
radio_b.painted()
slider := $&m.slider
slider.painted()
stepper := $&m.stepper
stepper.painted()
tabs := $&m.tabs
tabs.painted()
select_ctrl := $&m.select_ctrl
select_ctrl.painted()
badge := $&m.badge
badge.painted()
divider := $&m.divider
divider.painted()
card := $&m.card
card.painted()
list := $&m.list
list.painted()
}
fn (m $&Model) cleanup() {
icon := $&m.icon
icon.dispose() >>> (err) {eprintln(err.msg())
<< }
theme_label := $&m.theme_label
theme_label.dispose()
scale_label := $&m.scale_label
scale_label.dispose()
density_label := $&m.density_label
density_label.dispose()
brand_label := $&m.brand_label
brand_label.dispose()
disabled_label := $&m.disabled_label
disabled_label.dispose()
check_label := $&m.check_label
check_label.dispose()
toggle_label := $&m.toggle_label
toggle_label.dispose()
radio_a_label := $&m.radio_a_label
radio_a_label.dispose()
radio_b_label := $&m.radio_b_label
radio_b_label.dispose()
stepper_label := $&m.stepper_label
stepper_label.dispose()
badge_label := $&m.badge_label
badge_label.dispose()
divider_label := $&m.divider_label
divider_label.dispose()
card_label := $&m.card_label
card_label.dispose()
tab_label := $&m.tab_label
tab_label.dispose()
tab_2_label := $&m.tab_2_label
tab_2_label.dispose()
tab_3_label := $&m.tab_3_label
tab_3_label.dispose()
select_label := $&m.select_label
select_label.dispose()
option_auto := $&m.option_auto
option_auto.dispose()
option_manual := $&m.option_manual
option_manual.dispose()
option_locked := $&m.option_locked
option_locked.dispose()
list_label := $&m.list_label
list_label.dispose()
list_2_label := $&m.list_2_label
list_2_label.dispose()
list_3_label := $&m.list_3_label
list_3_label.dispose()
list_4_label := $&m.list_4_label
list_4_label.dispose()
input := $&m.input
input.dispose()
invalid := $&m.invalid
invalid.dispose()
read_only := $&m.read_only
read_only.dispose()
area := $&m.area
area.dispose()
}
fn leaf(view $&widgets.View, parent int, width f64, height f64) int {
style := layout.box_style(layout.BOX_LEAF)
<< view.add(parent, &style, &layout.Size{width: width, height: height}) >>>
}
fn brand_scope(view $&widgets.View) int {
$brand := widgets.light_styles()
brand.button.palette.normal = draw.rgb(10, 91, 69)
brand.button.palette.hovered = draw.rgb(17, 120, 90)
brand.button.palette.pressed = draw.rgb(7, 65, 49)
brand.button.palette.foreground = draw.rgb(255, 255, 255)
brand.button.font.size = 17.0
brand.button.font.weight = 600
brand.button.inherit_font = false
brand.button.radius = 18.0
brand.button.icon_size = 22.0
brand.button.icon_placement = widgets.ICON_TRAILING
$hover := widgets.state_paint(widgets.STATE_HOVERED)
hover.unless = widgets.STATE_DISABLED
hover.fields = widgets.PAINT_FOREGROUND | widgets.PAINT_BORDER
hover.foreground = draw.rgb(209, 250, 229)
hover.border = draw.rgb(110, 231, 183)
brand.button.states =[hover]
brand.button.shadow = draw.rgba(0, 0, 0, 28)
brand.button.shadow_y = 2.0
brand.button.shadow_blur = 6.0
view.set_style_scope(8, &brand) >>>
<< 0
}
fn scene(ech chan ui.Event) int {
ready := demo.ready(ech) >>>
if ready.kind == ui.EV_EXIT{ << 0}
identity := ui.canvas_of(&ready) >>>
context := draw.context_of(&ready) >>>
host := widgets.Host{context: context, identity: identity}
$column := layout.box_style(layout.BOX_COLUMN)
column.padding = layout.insets(22.0) >>>
column.gap = 10.0
column.cross_alignment = layout.CROSS_STRETCH
$view := host.view(&column, draw.rgb(20, 25, 34)) >>>
_ := leaf($&view, 1, 400.0, 56.0) >>> // 2 header
$row := layout.box_style(layout.BOX_ROW)
row.gap = 12.0
row.cross_alignment = layout.CROSS_CENTER
_ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>> // 3 toolbar
for i in 0:3 {_ := leaf($&view, 3, 0.0, 0.0) >>> } // 4..6
_ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>> // 7 controls
for i in 0:3 {_ := leaf($&view, 7, 0.0, 0.0) >>> } // 8..10
_ := leaf($&view, 1, 300.0, 12.0) >>> // 11 progress
for i in 0:4 {_ := leaf($&view, 1, 300.0, 0.0) >>> } // 12..15 editors
$viewport := layout.box_style(layout.BOX_COLUMN)
viewport.height = 84.0
viewport.clip = true
viewport.cross_alignment = layout.CROSS_STRETCH
_ := view.add(1, &viewport, &layout.Size{width: 0.0, height: 0.0}) >>> // 16 scroll
$items := layout.box_style(layout.BOX_COLUMN)
items.gap = 6.0
items.cross_alignment = layout.CROSS_STRETCH
_ := view.add(16, &items, &layout.Size{width: 0.0, height: 0.0}) >>> // 17 items
for i in 0:12 {_ := leaf($&view, 17, 300.0, 28.0) >>> } // 18..29
_ := leaf($&view, 1, 400.0, 42.0) >>> // 30 footer
_ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>> // 31 extended controls row 1
for i in 0:6 {_ := leaf($&view, 31, 0.0, 0.0) >>> } // 32..37: switch, radio_a, radio_b, slider, stepper, badge
_ := leaf($&view, 1, 300.0, 0.0) >>> // 38 labeled divider
_ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>> // 39 extended controls row 2
for i in 0:4 {_ := leaf($&view, 39, 0.0, 0.0) >>> } // 40..43: tabs, select, card, list_box
for id in[2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 30, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43] {view.set_boundary(id, true) >>> }
for id in[4, 5, 6, 8, 10, 12, 13, 14, 15, 16, 32, 33, 34, 35, 36, 40, 41, 43] {view.set_input(id, true, true) >>> }
view.set_capture_outside(16, true) >>>
view.set_capture_outside(35, true) >>>
for id in[4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43] {view.set_style_measure(id, true) >>> }
empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
$m := Model{theme: widgets.button(&identity, 4, &empty) >>>, scale: widgets.button(&identity, 5, &empty) >>>,
density: widgets.button(&identity, 6, &empty) >>>, brand: widgets.button(&identity, 8, &empty) >>>,
disabled: widgets.button(&identity, 9, &empty) >>>, check: widgets.checkbox(&identity, 10, &empty, true) >>>,
toggle: widgets.switch_control(&identity, 32, &empty, true) >>>,
radio_a: widgets.radio(&identity, 33, &empty, 0, true) >>>,
radio_b: widgets.radio(&identity, 34, &empty, 1, false) >>>,
slider: widgets.slider(&identity, 35, &empty, 0.0, 100.0, 64.0) >>>,
stepper: widgets.stepper(&identity, 36, &empty, 0.0, 100.0, 5.0, 65.0) >>>,
tabs: widgets.tabs(&identity, 40, &empty, 3, 0) >>>,
select_ctrl: widgets.select_box(&identity, 41, &empty, 3, 0) >>>,
select_origin: empty, select_popup_armed: false,
transitions:[]widgets.PaintTransition{}, switch_motion: widgets.tween(1.0) >>>, popup_motion: widgets.tween(0.0) >>>,
clock: time.zero_instant(), reduced_motion: false, theme_index: 0, text_scale: 1.0, density_scale: 1.0, appearance_dirty: true,
badge: widgets.badge(&empty) >>>,
divider: widgets.divider(&empty, widgets.AXIS_HORIZONTAL) >>>,
card: widgets.card(&empty) >>>,
list: widgets.list_box(&identity, 43, &empty, 4, 0) >>>,
input: widgets.input(&context, &identity, 12, &empty, &"Editable input · 你好 Xu") >>>,
invalid: widgets.input(&context, &identity, 13, &empty, &"Invalid value — custom error colors") >>>,
read_only: widgets.input(&context, &identity, 14, &empty, &"Read-only · select and copy, edits are ignored") >>>,
area: widgets.text_area(&context, &identity, 15, &empty, &"TextArea uses the same font, padding and selection theme.\nIME, preedit and caret geometry follow typography changes.") >>>,
progress: widgets.progress(&empty, 0.64) >>>, scroll: widgets.scroll(&identity, 16, &empty, widgets.AXIS_VERTICAL, 402.0) >>>,
context: context, icon: context.load_embedded_image(&"logo.png") >>>, switcher: widgets.style_switcher(),
theme_label: widgets.styled_label(&context, &"Theme: dark / light / contrast"),
scale_label: widgets.styled_label(&context, &"Text: 100% / 140%"),
density_label: widgets.styled_label(&context, &"Density: normal / compact"),
brand_label: widgets.styled_label(&context, &"Local green"),
disabled_label: widgets.styled_label(&context, &"Disabled"),
check_label: widgets.styled_label(&context, &"Checkbox"),
toggle_label: widgets.styled_label(&context, &"Switch"),
radio_a_label: widgets.styled_label(&context, &"Radio A"),
radio_b_label: widgets.styled_label(&context, &"Radio B"),
stepper_label: widgets.styled_label(&context, &"65"),
badge_label: widgets.styled_label(&context, &"Active"),
divider_label: widgets.styled_label(&context, &"Navigation & Data Components"),
card_label: widgets.styled_label(&context, &"Card Panel"),
tab_label: widgets.styled_label(&context, &"Overview"),
tab_2_label: widgets.styled_label(&context, &"Tokens"),
tab_3_label: widgets.styled_label(&context, &"Themes"),
select_label: widgets.styled_label(&context, &"Option: Auto"),
option_auto: widgets.styled_label(&context, &"Auto"),
option_manual: widgets.styled_label(&context, &"Manual"),
option_locked: widgets.styled_label(&context, &"Locked"),
list_label: widgets.styled_label(&context, &"1 · Buttons"),
list_2_label: widgets.styled_label(&context, &"2 · Editors"),
list_3_label: widgets.styled_label(&context, &"3 · Surfaces"),
list_4_label: widgets.styled_label(&context, &"4 · Controls")}
for i in 0:44 {m.transitions.push(widgets.paint_transition() >>>)}
for id in[4, 5, 6, 8, 10, 32, 33, 34, 36, 40, 41, 43] {view.set_cursor(id, ui.CURSOR_HAND) >>> }
for id in[12, 13, 14, 15] {view.set_cursor(id, ui.CURSOR_TEXT) >>> }
view.set_cursor(35, ui.CURSOR_RESIZE_HORIZONTAL) >>>
badge_ref := $&m.badge
badge_ref.set_selected(true)
disabled := $&m.disabled
disabled.set_enabled(false)
invalid := $&m.invalid
invalid.set_invalid(true)
read_only := $&m.read_only
read_only.set_read_only(true) >>>
apply_appearance($&m, $&view) >>>
brand_scope($&view) >>>
dispatcher := register_actions(&m, &view) >>>
$width := 960.0
$height := 820.0
$event := ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
// Drain input bursts before painting. Native text snapshots already hold
// the latest revision; rendering each queued key would fill the frame queue.
ui.request_canvas_preferences(&identity) >>>
while true {
if event.kind == ui.EV_NONE{
apply_appearance($&m, $&view) >>>
m.tick($&view, time.instant()) >>>
constraints := layout.tight(width, height) >>>
_ := widgets.layout_styled($&view, &constraints, $&m) >>>
m.place($&view) >>>
if widgets.present_styled($&view, &constraints, $&m) >>> {m.acknowledge()}
event = m.next_event(ech)
}
if event.kind == ui.EV_EXIT{ <- }
if event.window_id == identity.window_id{
if event.kind == ui.EV_CANVAS_CLOSED || event.kind == ui.EV_CLOSED{ <- }
if event.kind == ui.EV_CANVAS_METRICS{metrics := ui.metrics_of(&event) >>>
width = metrics.width
height = metrics.height}
if event.kind == ui.EV_FOCUSED{ui.request_canvas_preferences(&identity) >>> }
if event.kind == ui.EV_CANVAS_PREFERENCES{
preferences := ui.canvas_preferences_of(&event) >>>
if preferences.identity.canvas_id == identity.canvas_id && preferences.identity.generation == identity.generation{
m.reduced_motion = preferences.reduced_motion
view.mark_paint(1) >>>
}
}
popup_was_open := m.select_ctrl.is_open()
actions := m.dispatch_event($&view, &event) >>>
m.native_event($&view, &event) >>>
for action in actions{_ := dispatcher.dispatch(&action, $&m, $&view) >>> }
if ui.is_input_event(event.kind) {input := ui.input_of(&event) >>>
if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE && !popup_was_open{
view.dispose()
if demo.alive(&identity) {m.cleanup()}
demo.quit() >>>
<< 0
}}
}
event = ui.poll_chan(ech)
}
view.dispose()
if demo.alive(&identity) {m.cleanup()}
<< 0
}
fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
<< }}
fn main() int {
$app := demo.app("Xu UI / Style Gallery", 960, 820) >>> (err) {eprintln(err.msg())
<< 1}
xu worker(app.event_ch)
<< app.run() >>> (err) {eprintln(err.msg())
<< 1}
}16_ui_webview/component_workshop/main.xu@main
#ui
#ui/widgets
#time
demo #"github.com/xulang-org/examples/ui_demo"
fn scene(events chan ui.Event) int {
ready := demo.ready(events) >>>
if ready.kind == ui.EV_EXIT{ << 0}
$screen := widgets.screen(&ready) >>>
screen.resize(1180.0, 900.0) >>> (err) {screen.dispose()
>> err}
screen.set_min_size(920, 780) >>> (err) {screen.dispose()
>> err}
$model := create($&screen) >>> (err) {screen.dispose()
>> err}
workshop_loop(events, $&model, $&screen) >>> (err) {screen.dispose()
>> err}
screen.dispose()
<< 0
}
fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
<< }}
fn launch() int {
$app := demo.app("XUUI / Component Workshop", 1180, 900) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) {eprintln(err.msg())
<< 1}}
fn next_event(events chan ui.Event, deadline time.Instant) ui.Event{
if deadline.is_zero() { << <- events}
delay := deadline.since(time.instant())
if delay.nanoseconds() <= 0 { << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}}
timer := delay.timer()
select {event := <- events{timer.stop()
<< event}
_ := <- timer.c{timer.stop()}}
<< ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
}
fn workshop_loop(events chan ui.Event, model $&Workshop, screen $&widgets.Screen) int {
model.apply_locale(screen) >>>
screen.set_text(model.title, "XUUI / Field") >>>
model.configure_controls(screen) >>>
model.controls_dirty = false
model.apply_appearance(screen) >>>
model.appearance_dirty = false
$dispatcher := register_events(& * model, & * screen) >>>
model.layout(screen) >>>
while screen.is_open() {
register_notice_events(& * screen, $&dispatcher) >>>
now := time.instant()
model.work(screen, now) >>>
if model.controls_dirty{model.configure_controls(screen) >>>
model.controls_dirty = false}
if model.appearance_dirty{model.apply_appearance(screen) >>>
model.appearance_dirty = false}
model.apply_page_options(screen) >>>
model.layout(screen) >>>
$deadline := screen.advance(now) >>>
$timed_actions := false
for action in screen.take_actions() {
_ := dispatcher.dispatch_or_fallback(&action, model, screen) >>>
timed_actions = true
}
// Reconcile timer-driven values/styles before computing the next wait.
if timed_actions{ -> }
_ := screen.render() >>>
if model.running &&(deadline.is_zero() || model.deadline.before(deadline)) {deadline = model.deadline}
event := next_event(events, deadline) >>>
$actions := screen.event(&event) >>>
$count := 0
while screen.is_open() && count < 128 {pending := ui.poll_chan(events)
if pending.kind == ui.EV_NONE{ <- }
more := screen.event(&pending) >>>
for action in more{actions.push(action)}
count += 1}
for action in actions{register_notice_events(& * screen, $&dispatcher) >>>
_ := dispatcher.dispatch_or_fallback(&action, model, screen) >>> }
}
<< 0
}@main
#ui
#ui/widgets
#ui/chart
#ui/draw
#time
#math
fn names()[]string { << names_locale(true) }
fn names_locale(english bool)[]string {
if english {
<<["StyledLabel", "Button", "IconButton", "Input", "TextArea", "Field", "FieldArea", "TreeView", "TaskButton", "Checkbox", "Switch", "Radio", "RadioGroup", "Slider", "Stepper", "Select", "ComboBox", "MultiSelect", "DatePicker", "TimePicker", "ColorPicker", "Tabs", "Segmented", "ListBox", "Table", "Pagination", "Breadcrumbs", "Progress", "Spinner", "Divider", "Badge", "Card", "Scroll", "Popover", "Tooltip", "ToastHost", "Modal", "WebView", "ButtonGroup", "Chart", "RangeSlider", "SplitView", "Menu", "ContextMenu", "SplitButton", "PasswordInput"]
}
<<["StyledLabel 文本", "Button 按钮", "IconButton 图标按钮", "Input 单行输入", "TextArea 多行输入", "Field 表单字段", "FieldArea 多行字段", "TreeView 树形视图", "TaskButton 任务按钮", "Checkbox 复选框", "Switch 开关", "Radio 单选框", "RadioGroup 单选组", "Slider 滑块", "Stepper 步进器", "Select 下拉选择", "ComboBox 组合框", "MultiSelect 多选框", "DatePicker 日期选择", "TimePicker 时间选择", "ColorPicker 颜色选择", "Tabs 标签页", "Segmented 分段控件", "ListBox 列表框", "Table 数据表格", "Pagination 分页器", "Breadcrumbs 面包屑", "Progress 进度条", "Spinner 加载指示", "Divider 分割线", "Badge 徽标", "Card 卡片", "Scroll 滚动容器", "Popover 气泡浮层", "Tooltip 文字提示", "ToastHost 通知队列", "Modal 模态弹窗", "WebView 网页视图", "ButtonGroup 按钮组", "Chart 图表", "RangeSlider 区间滑块", "SplitView 分栏视图", "Menu 下拉菜单", "ContextMenu 右键菜单", "SplitButton 拆分按钮", "PasswordInput 密码框"]
}
fn new_page(s $&widgets.Screen, index int) Page{
group := s.group() >>>
$ids :=[]int {}
choices :=["Workspace 工作区", "History 历史", "Output 输出"]
if index == 0 {ids.push(s.label("清晰的层级,让每个细节都服务于使用。\n中文、English 与 emoji 👩🏽💻 都使用原生排版。", 20.0, false) >>>)
s.set_label_wrapped(ids[0], true) >>>
ids.push(s.label("很长的完整内容:Cluster-safe truncation · 👨👩👧👦 family · workspace / widgets / component.xu", 16.0, false) >>>)
s.set_label_ellipsis(ids[1], true) >>>
anchor := ids[1]
ids.push(s.tooltip(anchor, "很长的完整内容:Cluster-safe truncation · 👨👩👧👦 family · workspace / widgets / component.xu") >>>)}
if index == 1 {
$sizes :=[]int {}
$labels :=[]int {}
for text in["Build project", "Open workspace · trailing", "Save changes · above", "Download SDK · below"] {
// Each inspector precedes its own button in both layout and Tab order.
inspector := s.stepper(12.0, 64.0, 4.0, 24.0) >>>
sizes.push(inspector)
_ := s.tooltip(inspector, text + " · Icon size 图标尺寸 (px)") >>>
labels.push(s.label("Icon 图标 · 24 px", 14.0, true) >>>)
ids.push(s.button_with_icon("logo.png", text) >>>)}
for text in["Secondary", "Outline", "Ghost", "Danger", "Subtle"] {ids.push(s.button(text) >>>)}
s.set_button_variant(ids[0], widgets.BUTTON_PRIMARY) >>>
for variant in 1:6 {s.set_button_variant(ids[variant + 3], variant) >>> }
for id in sizes{ids.push(id)}
for id in labels{ids.push(id)}}
if index == 2 {ids.push(s.icon_button("logo.png", "Open XU workspace") >>>)
anchor := ids[0]
ids.push(s.tooltip(anchor, "Open XU workspace · Enter") >>>)}
if index == 3 {ids.push(s.input("中文 / English / 🙂") >>>)}
if index == 4 {ids.push(s.text_area("Native text editing\n选择文字、复制、粘贴,保留输入法会话。\n👩🏽💻 family 👨👩👧👦") >>>)}
if index == 5 || index == 6 {
$decoration := widgets.field_decoration(&"Project name 项目名称")
decoration.helper = "Enter a name · Native IME / selection / clipboard"
decoration.error = "名称不能为空。Please enter a project name."
decoration.clearable = true
if index == 5 {decoration.prefix = "xu /"
ids.push(s.field("", &decoration) >>>)}
else {ids.push(s.text_field_area("Build notes\n中文与 emoji 🙂", &decoration) >>>)}
$options := widgets.field_text_options()
options.counter = true
options.character_limit = 32
if index == 6 {options.min_rows = 3
options.max_rows = 6}
s.set_field_text_options(ids[0], &options) >>>
}
if index == 7 {
ids.push(s.tree() >>>)
root := s.tree_add(ids[0], - 1, "XU workspace") >>>
src := s.tree_add(ids[0], root, "src") >>>
widgets_node := s.tree_add(ids[0], src, "widgets") >>>
for name in["tree_view.xu", "task_button.xu", "field.xu", "screen.xu"] {leaf := s.tree_add(ids[0], widgets_node, name) >>>
s.set_tree_metadata(ids[0], leaf, "Xu") >>>
s.set_tree_action(ids[0], leaf, true) >>> }
_ := s.tree_add(ids[0], root, "xu.xun") >>>
for node in[root, src, widgets_node] {s.set_expanded(ids[0], node, true) >>> }
$appearance := widgets.tree_appearance()
appearance.guides = true
s.set_tree_appearance(ids[0], &appearance) >>>
$decoration := widgets.field_decoration(&"Find a node")
decoration.clearable = true
ids.push(s.field("", &decoration) >>>)
}
if index == 8 {ids.push(s.task_button("Build project") >>>)
s.set_task_labels(ids[0], "Building", "Built · run again", "Retry build", "Build again") >>> }
if index == 9 {ids.push(s.checkbox("Keep generated files 保留产物", true) >>>)}
if index == 10 {ids.push(s.switch_control("Live preview 实时预览", true) >>>)}
if index == 11 {ids.push(s.radio("Use workspace settings", 1, true) >>>)}
if index == 12 {ids.push(s.radio_group(&choices, 0) >>>)}
if index == 13 {ids.push(s.slider(0.0, 100.0, 40.0) >>>)
$appearance := widgets.slider_appearance()
appearance.ticks = 11
appearance.show_value = true
s.set_slider_appearance(ids[0], &appearance, 10.0) >>>
s.set_slider_commit_only(ids[0], true) >>>
$decoration := widgets.field_decoration(&"Exact value / 精确数值")
decoration.helper = "0–100 · step 10 · Apply input"
decoration.error = "Enter a number between 0 and 100."
ids.push(s.field("40", &decoration) >>>)}
if index == 14 {ids.push(s.stepper(0.0, 100.0, 1.0, 24.0) >>>)
s.set_stepper_repeat(ids[0], true, time.milliseconds(400) >>>, time.milliseconds(80) >>>) >>> }
if index == 15 {$unavailable := widgets.select_option("Remote (unavailable)")
unavailable.enabled = false
options :=[widgets.select_group("LOCAL"), widgets.select_option("Workspace 工作区"), widgets.select_option("History 历史"), widgets.select_group("REMOTE"), unavailable]
ids.push(s.select_options(&options, 1) >>>)}
if index == 16 {ids.push(s.combo_box(&choices, "") >>>)
s.set_combo_custom_values(ids[0], false) >>> }
if index == 17 {ids.push(s.multi_select(&choices) >>>)
$decoration := widgets.field_decoration(&"Filter options")
decoration.clearable = true
ids.push(s.field("", &decoration) >>>)}
if index == 18 || index == 19 {value := time.date(2026, 10, 25, 14, 30, 0, 0)
if index == 18 {ids.push(s.date_picker(value) >>>)
s.set_date_options(ids[0], value, true) >>> }
else {ids.push(s.time_picker(value) >>>)
s.set_clock_format(ids[0], true, true) >>> }}
if index == 20 {ids.push(s.color_picker(draw.rgb(180, 57, 45)) >>>)
s.set_color_swatches(ids[0], &[draw.rgb(180, 57, 45), draw.rgb(50, 121, 160), draw.rgb(72, 130, 90)]) >>>
$decoration := widgets.field_decoration(&"HEX / RGBA")
decoration.helper = "#RGB, #RGBA, #RRGGBB, #RRGGBBAA"
decoration.error = "Use a valid HEX value."
ids.push(s.field("#B4392DFF", &decoration) >>>)}
if index == 21 {ids.push(s.tabs(&choices, 0) >>>)
s.set_tab_behavior(ids[0], &[180.0, 144.0, 160.0], false) >>> }
if index == 22 {ids.push(s.segmented(&["Day", "Week", "Month"], 0) >>>)}
if index == 23 {ids.push(s.list_box(&["TreeView", "TaskButton", "Field", "Table", "WebView", "Scroll", "Tabs", "Select", "ToastHost"], 0) >>>)
for row in 0:9 {$detail := widgets.list_row(["TreeView", "TaskButton", "Field", "Table", "WebView", "Scroll", "Tabs", "Select", "ToastHost"][row])
detail.description = "Native component · 原生交互"
detail.detail = "Ready"
detail.icon = widgets.TREE_ICON_FILE
s.set_list_row(ids[0], row, &detail) >>> }}
if index == 24 {ids.push(s.table(&["Component", "Build ms", "Status"], 12, 0) >>>)
components :=["Button", "TreeView", "Field", "Input", "Tabs", "Checkbox", "Switch", "Menu", "WebView", "Chart", "Table", "Badge"]
durations :=[14, 7, 120, 3, 21, 7, 45, 9, 210, 32, 18, 2]
for row in 0:12 {s.set_cell(ids[0], row, 0, components[row]) >>>
s.set_cell(ids[0], row, 1, str(durations[row])) >>>
s.set_cell(ids[0], row, 2,["Ready", "Review", "Draft"][row % 3]) >>> }
s.set_table_sort_kind(ids[0], 1, widgets.TABLE_SORT_NUMBER) >>>
s.set_table_column_min_width(ids[0], 0, 160.0) >>>
s.set_table_column(ids[0], 0, 280.0, 0.0) >>>
s.set_table_column(ids[0], 1, 160.0, 1.0) >>>
s.set_table_column(ids[0], 2, 200.0, 0.0) >>> }
if index == 25 {ids.push(s.pagination(1000, 122) >>>)
s.set_pagination_data(ids[0], 20000, 20) >>>
$decoration := widgets.field_decoration(&"Page 页码")
decoration.helper = ""
decoration.error = ""
decoration.reserve_helper = false
decoration.floating = widgets.LABEL_ALWAYS
ids.push(s.field("123", &decoration) >>>)
ids.push(s.select_box(&["10 / page", "20 / page", "50 / page", "100 / page"], 1) >>>)
ids.push(s.label("", 14.0, true) >>>)
s.set_label_wrapped(ids[3], true) >>>
ids.push(s.button("Go 跳转") >>>)
ids.push(s.label("", 13.0, true) >>>)
s.set_label_wrapped(ids[5], true) >>> }
if index == 26 {ids.push(s.breadcrumbs(&["Home", "XU workspace", "src", "ui", "widgets", "A long Chinese path 中文路径", "field.xu"]) >>>)}
if index == 27 {ids.push(s.progress(0.42) >>>)
s.set_progress_buffer(ids[0], 0.72) >>> }
if index == 28 {ids.push(s.spinner() >>>)
s.set_spinner_appearance(ids[0], 32.0, 3.0, time.milliseconds(900) >>>) >>>
s.set_running(ids[0], true) >>>
ids.push(s.label("Loading assets… 正在加载", 14.0, true) >>>)}
if index == 29 {ids.push(s.divider(widgets.AXIS_HORIZONTAL) >>>)
ids.push(s.label("SECTION / 章节", 12.0, true) >>>)}
if index == 30 {
inbox := s.button("Inbox 收件箱") >>>
count := s.badge_on(inbox, "12", widgets.BADGE_COUNT) >>>
s.set_badge_tone(count, widgets.BADGE_ERROR) >>>
avatar := s.button("LW") >>>
s.set_button_variant(avatar, widgets.BUTTON_SUBTLE) >>>
dot := s.badge_on(avatar, "", widgets.BADGE_DOT) >>>
s.set_badge_anchor(dot, avatar, 0.86, 0.86) >>>
s.set_badge_tone(dot, widgets.BADGE_SUCCESS) >>>
synced := s.badge("Synced 已同步") >>>
s.set_badge_tone(synced, widgets.BADGE_SUCCESS) >>>
beta := s.badge("BETA") >>>
s.set_badge_tone(beta, widgets.BADGE_INFO) >>>
ids =[count, inbox, avatar, dot, synced, beta,
s.label("12 unread · 点击收件箱清零,徽标随数字收紧。", 14.0, true) >>>,
s.label("林文 · Available 在线", 16.0, false) >>>,
s.label("点击头像切换在线状态;状态点不单独承担文字含义。", 13.0, true) >>>,
s.label("Workspace 工作区", 16.0, false) >>>]
}
if index == 31 {
ids.push(s.card() >>>)
sections := s.card_sections(ids[0], 36.0, 44.0) >>>
for parent in[sections.header, sections.body, sections.footer] {ids.push(parent)}
ids.push(s.label("Workspace configuration", 18.0, false) >>>)
ids.push(s.label("Header, body and footer keep distinct spacing.\n正文区域随密度与字号调整。", 14.0, true) >>>)
s.set_label_wrapped(ids[5], true) >>>
ids.push(s.button("Open workspace") >>>)
s.set_parent(ids[4], sections.header) >>>
s.set_parent(ids[5], sections.body) >>>
s.set_parent(ids[6], sections.footer) >>>
}
if index == 32 {ids.push(s.scroll_area(widgets.AXIS_VERTICAL, 1100.0) >>>)
for row in 0:14 {id := s.button("Focusable row " + str(row + 1) + " · 滚动内容") >>>
s.set_parent(id, ids[0]) >>>
ids.push(id)}}
if index >= 33 && index <= 36 {ids.push(s.button(["Open popover", "Focus or hover for help", "Enqueue notification", "Open confirmation"][index - 33]) >>>)
anchor := ids[0]
if index == 33 {
ids.push(s.popover(anchor, "") >>>)
ids.push(s.label("Workspace preferences", 18.0, false) >>>)
ids.push(s.label("Edit a draft, then apply. Escape or clicking outside dismisses.\n编辑草稿后应用;关闭不会提交。", 13.0, true) >>>)
s.set_label_wrapped(ids[3], true) >>>
$decoration := widgets.field_decoration(&"Workspace name 工作区名称")
decoration.clearable = true
decoration.error = "名称不能为空 / Enter a name"
ids.push(s.field("XU workspace", &decoration) >>>)
ids.push(s.checkbox("Keep history 保留历史", true) >>>)
ids.push(s.button("Cancel 取消") >>>)
ids.push(s.button("Apply 应用") >>>)
s.set_button_variant(ids[7], widgets.BUTTON_PRIMARY) >>>
ids.push(s.label("Current: XU workspace · history on", 14.0, true) >>>)
for i in 2:8 {s.set_parent(ids[i], ids[1]) >>> }
}
if index == 34 {ids.push(s.tooltip(anchor, "Hover waits 500 ms; keyboard focus shows help immediately.\n鼠标离开或点击收起;Escape 抑制重复提示。") >>>)}
if index == 36 {ids.push(s.modal("Apply configuration?", "Focus stays inside this confirmation. Escape returns to the trigger.") >>>)
ids.push(s.button("Cancel") >>>)
ids.push(s.button("Apply changes") >>>)
s.set_parent(ids[2], ids[1]) >>>
s.set_parent(ids[3], ids[1]) >>> }
}
if index == 37 {ids.push(s.webview() >>>)
s.load_web_html(ids[0], "<!doctype html><html><meta charset='utf-8'><style>body{font:16px system-ui;background:#f3f2ee;color:#292c30;padding:24px}input{font:inherit;padding:12px;border:1px solid #747b83;border-radius:6px;width:80%}h2{font-weight:500}</style><h2>WebView is a component.</h2><p>Native focus, clipping and independent lifecycle.</p><input aria-label='Web content' placeholder='中文 / English / 🙂'></html>") >>> }
if index == 38 {
actions :=[widgets.button_group_item(10, "Undo"), widgets.button_group_item(20, "Redo"), widgets.button_group_item(30, "Save")]
group_choices :=[widgets.button_group_item(10, "Day"), widgets.button_group_item(20, "Week"), widgets.button_group_item(30, "Month")]
formats :=[widgets.button_group_item(10, "Bold"), widgets.button_group_item(20, "Italic"), widgets.button_group_item(30, "Underline")]
ids.push(s.button_group(&actions, widgets.BUTTON_GROUP_ACTIONS) >>>)
ids.push(s.button_group(&group_choices, widgets.BUTTON_GROUP_SINGLE) >>>)
ids.push(s.button_group(&formats, widgets.BUTTON_GROUP_MULTIPLE) >>>)
ids.push(s.label("Actions / 独立操作", 12.0, true) >>>)
ids.push(s.label("Single / 单选", 12.0, true) >>>)
ids.push(s.label("Multiple / 多选", 12.0, true) >>>)
}
if index == 39 {
ids.push(s.chart() >>>)
row0 :=[widgets.button_group_item(1, "Line"), widgets.button_group_item(2, "Area"), widgets.button_group_item(3, "Bar"), widgets.button_group_item(4, "Scatter"), widgets.button_group_item(5, "Donut")]
row1 :=[widgets.button_group_item(6, "Step"), widgets.button_group_item(7, "StackArea"), widgets.button_group_item(8, "StackBar"), widgets.button_group_item(9, "H-Bar"), widgets.button_group_item(10, "Pie")]
row2 :=[widgets.button_group_item(11, "Rose"), widgets.button_group_item(12, "Radar"), widgets.button_group_item(13, "Gauge"), widgets.button_group_item(14, "Bubble"), widgets.button_group_item(15, "Histogram")]
row3 :=[widgets.button_group_item(16, "Boxplot"), widgets.button_group_item(17, "Heatmap"), widgets.button_group_item(18, "Candle"), widgets.button_group_item(19, "Waterfall"), widgets.button_group_item(20, "Funnel")]
row4 :=[widgets.button_group_item(21, "Spline"), widgets.button_group_item(22, "SplineArea"), widgets.button_group_item(23, "PolarBar"), widgets.button_group_item(24, "Treemap"), widgets.button_group_item(25, "Sankey")]
row5 :=[widgets.button_group_item(26, "Violin"), widgets.button_group_item(27, "Bullet"), widgets.button_group_item(28, "Lollipop"), widgets.button_group_item(29, "Dumbbell"), widgets.button_group_item(30, "Pareto")]
$selector := widgets.button_group_appearance()
selector.equal_width = true
selector.allow_empty = true
rows :=[row0, row1, row2, row3, row4, row5]
for r in 0:6 {
gid := s.button_group(&rows[r], widgets.BUTTON_GROUP_SINGLE) >>>
s.set_button_group_appearance(gid, &selector) >>>
ids.push(gid)
}
series := chart_data(widgets.CHART_LINE, 0)
s.set_chart_series(ids[0], &series) >>>
}
if index == 40 {
ids.push(s.range_slider(0.0, 100.0, 20.0, 80.0) >>>)
ids.push(s.label("20 – 80", 18.0, false) >>>)
ids.push(s.label("Drag either thumb or the selected band. Tab visits both thumbs. Escape cancels a pending edit.\n拖动端点或整段;Tab 访问两个端点。", 14.0, true) >>>)
s.set_label_wrapped(ids[2], true) >>>
}
if index == 41 {
ids.push(s.split_view(0.4) >>>)
split := ids[0]
ids.push(s.split_pane(split, 0) >>>)
ids.push(s.split_pane(split, 1) >>>)
ids.push(s.label("Workspace / 工作区\nPane content follows the available size.", 16.0, false) >>>)
ids.push(s.label("Preview / 预览\nDrag the handle; arrows adjust, Shift accelerates.", 16.0, false) >>>)
ids.push(s.button("Open workspace") >>>)
ids.push(s.button("Refresh preview") >>>)
for i in 0:2 {s.set_label_wrapped(ids[3 + i], true) >>>
s.set_parent(ids[3 + i], ids[1 + i]) >>>
s.set_parent(ids[5 + i], ids[1 + i]) >>> }
}
if index >= 42 && index <= 44 {
mode :=[widgets.MENU_DROPDOWN, widgets.MENU_CONTEXT, widgets.MENU_SPLIT][index - 42]
label :=["Actions", "Right click here · 右键打开菜单", "Save"][index - 42]
ids.push(s.menu(label, &workshop_menu_items(true), mode, 100) >>>)
ids.push(s.label("Choose an action · 选择操作", 16.0, false) >>>)
ids.push(s.label("Check and radio items preserve their state. Navigate submenus with arrows; Escape returns one level.\n操作文案与快捷键由应用配置。", 14.0, true) >>>)
s.set_label_wrapped(ids[1], true) >>>
s.set_label_wrapped(ids[2], true) >>>
}
if index == 45 {
ids.push(s.password_input("Xu-密码🙂") >>>)
ids.push(s.checkbox("Show password 显示密码", false) >>>)
ids.push(s.label("Password 密码", 15.0, false) >>>)
ids.push(s.label("Paste is supported. Copy and cut are blocked even when revealed.\n支持粘贴、选择和中英文输入;显隐切换保留内容与光标。", 14.0, true) >>>)
s.set_label_wrapped(ids[3], true) >>>
}
for i in 0:ids.len{
// Card slots and scroll children retain their content parent.
if index == 30 &&(i == 0 || i == 3) { -> }
if index == 31 && i > 0 { -> }
if index == 41 && i > 0 { -> }
if index == 32 && i > 0 { -> }
if index == 36 && i > 1 { -> }
if index == 33 && i >= 2 && i <= 7 { -> }
s.set_parent(ids[i], group) >>>
}
s.set_visible(group, false) >>>
<< Page{group: group, ids: ids}
}
fn description(index int) string { << description_locale(index, false) }
fn description_locale(index int, english bool) string {
if english {
if index == 45 { << "Unicode grapheme masking; reveal toggle, native editing, read-only and disabled states; copy/cut blocked."}
if index == 40 { << "Dual-thumb range: step, minimum distance, clamp/push, band dragging; independent focus and commit."}
if index == 41 { << "Resizable split panes: minimum constraints, collapse/restore, keyboard adjustment; content clipped per pane."}
if index >= 42 && index <= 44 { << "Action / check / radio / submenu items; keyboard navigation, edge flipping, shortcuts and per-item feedback."}
if index == 38 { << "Actions / single / multiple selection; per-item disable, arrow navigation, Enter or Space activation."}
if index == 39 { << "Native interactive charts (30 types): stable-ID transitions, hover/select, legend; Ctrl/⌘ + wheel zoom, drag pan, double-click reset."}
en :=["Layered body, heading and muted text; native line wrapping and font overrides.",
"Leading / trailing / above / below icons; independent size steppers and content-width wrapping.",
"Standalone hit target and action label; keyboard focus also triggers tooltip help.",
"Native single-line editing: selection, copy, paste and IME composition.",
"Native multi-line editing: paragraphs, internal scrolling and IME candidate placement.",
"Floating / fixed labels and three border variants; soft counter never truncates input.",
"Multi-line Field: min 3 rows, max 6 rows; character counter and stable helper region.",
"Hierarchy guides, vector arrows, icons, metadata, filtering and node actions.",
"Real compute batches drive progress; task ID rejects stale callbacks.",
"Full-row click target; indeterminate mixed state; interruptible check animation.",
"Track and thumb transition; interruptible rapid toggling; read-only preserves focus.",
"Single radio item and selection animation; full label hit target.",
"Arrow keys manage mutual exclusion; Tab enters the group once.",
"11 ticks, step-10 snapping, value readout; commit on release.",
"Hold to repeat and accelerate; stops cleanly at bounds.",
"Typed groups and disabled options; arrow keys skip non-selectable rows.",
"Local match highlighting and empty state; configurable free-text input.",
"Candidate filtering, removable tags, select-all and clear actions.",
"Today / Clear actions; Page Up/Down switches months, Shift switches years.",
"12/24-hour clock format; stores explicit typed time values.",
"RGBA channels, exact HEX input, swatches and recent color history.",
"Variable-width tabs; arrow keys move focus, Enter activates manually.",
"Segmented selection plate and container semantics distinct from Tabs.",
"Icon / primary & secondary text / trailing detail; hit testing scales with font size.",
"Resizable columns, horizontal & vertical scrolling, and data status messages.",
"First, last and ellipsis items; fast page jumping for large datasets.",
"Preserves current path; middle segments collapse into an interactive menu.",
"Determinate progress and buffer shown separately without fabricated percentages.",
"Configurable size, stroke width and period; static feedback under reduced motion.",
"Subtle divider paired with section heading; unified horizontal and vertical spec.",
"Badges in context: unread count, avatar status dot and status tags.",
"Header / body / footer content slots; actions use standalone Buttons.",
"True child clipping, wheel bubbling, track dragging and keyboard focus scroll-into-view.",
"Anchor placement and edge flipping; outside click or Escape dismisses.",
"Hover delay and immediate focus help; Escape suppresses repeated tooltips.",
"Up to three visible notices; queueing, deduplication, priority and undo action.",
"Modal focus loop and restoration; safe action receives initial focus.",
"Native webview child component with clipping and independent lifecycle."]
<< en[index]
}
if index == 45 { << "按 Unicode 字素掩码;显隐切换、原生编辑、只读与禁用,禁止复制或剪切密码。"}
if index == 40 { << "双端区间:步进、最小间距、端点推挤、整段拖动;独立焦点与提交。"}
if index == 41 { << "可调整分栏:尺寸约束、折叠恢复、键盘调整;内容保持在各自面板内。"}
if index >= 42 && index <= 44 { << "动作 / 勾选 / 单选 / 子菜单;键盘、边缘翻转、快捷键与可定制的逐项反馈。"}
if index == 38 { << "独立操作 / 单选 / 多选;逐项禁用,方向键导航,Enter 或空格激活。"}
if index == 39 { << "原生交互图表(30 种类型):稳定 ID 数据过渡、悬停/选中、图例;Ctrl/⌘ + 滚轮缩放,拖动平移,双击复位。"}
descriptions :=["正文、标题与辅助文字分层;原生换行与字体覆盖。",
"图标左 / 右 / 上 / 下;各自调节尺寸,按钮按内容宽度自动换行。",
"独立点击目标与动作名称;键盘焦点也能查看提示。",
"原生单行编辑:选区、复制、粘贴与 IME。",
"原生多行编辑:段落、内部滚动与输入法候选定位。",
"浮动标签 / 固定标签 / 三种边框;软计数不截断输入。",
"多行 Field:最小 3 行、最大 6 行;计数与稳定辅助区。",
"层级引导、矢量箭头、图标、元数据、筛选和节点动作。",
"真实计算批次驱动进度;任务 ID 拒绝旧回调。",
"整行点击;混合态;可中断的勾选显现。",
"轨道与圆钮过渡;快速切换可中断;只读保留焦点。",
"单项选择与选中动效;完整标签点击目标。",
"方向键管理互斥;Tab 只进入一次。",
"11 个刻度、10 步吸附、数值提示;松开才提交。",
"按住连续增加并加速;到达边界停止。",
"有类型的分组 / 禁用选项;方向键跳过不可选行。",
"本地匹配高亮与无结果;可控制是否接受自由输入。",
"候选筛选、可移除标签、全选和清空。",
"今天 / 清空;Page Up/Down 快速翻月,Shift 切年。",
"12/24 小时可选;存储保持明确的时间值。",
"RGBA 通道、HEX 精确输入、色板与最近颜色。",
"可变宽标签;方向键移动,Enter 手动激活。",
"与 Tabs 分开的选中底板和容器语义。",
"图标 / 主副文本 / 尾部信息;字体放大后命中保持一致。",
"拖动调整列宽;横向与纵向滚动;数据状态文字。",
"首页、末页与省略项;大页数仍可快速定位。",
"保留当前路径;中间段收进可交互的菜单。",
"真实确定进度与缓冲区分别显示,不伪造百分比。",
"大小 / 粗细 / 周期可配置;减少动效显示静态反馈。",
"弱分隔与章节文字组合;水平和垂直使用同一规范。",
"Badge 放入真实上下文:未读计数、头像状态点与列表标签。",
"Header / body / footer 内容槽;动作使用独立 Button。",
"真实子控件裁剪、滚轮冒泡、轨道拖动与键盘焦点滚入。",
"锚点定位、边缘翻转;外点 / Escape 关闭。",
"Hover 延迟、focus 立即显示;Escape 抑制重复提示。",
"最多三条可见通知;队列、去重、优先级与撤销动作。",
"模态焦点循环与恢复;安全动作先获得焦点。",
"原生网页子视图作为 Screen 组件,支持裁剪与独立生命周期。"]
<< descriptions[index]
}
fn tool_labels(index int)[]string { << tool_labels_locale(index, false) }
fn tool_labels_locale(index int, english bool)[]string {
if english {
if index == 45 { <<["Clear", "Reset sample", "Focus input"]}
if index == 40 { <<["Clamp / push", "Commit mode", "Orientation"]}
if index == 41 { <<["Orientation", "Collapse / restore", "Reset ratio"]}
if index >= 42 && index <= 44 { <<["Open menu", "Keep open", "Disable export"]}
if index == 38 { <<["Disable middle", "Orientation", "Joined / gap"]}
if index == 39 { <<["Update data", "Reset zoom", "Pause / resume"]}
if index == 0 { <<["Long text", "Short text", ""]}
if index == 1 || index == 2 { <<["Select", "Clear selection", ""]}
if index == 3 || index == 4 { <<["Clear", "Long text", ""]}
if index == 5 || index == 6 { <<["Clear", "Long text", "Appearance"]}
if index == 7 { <<["Guides", "Reveal last", "Clear filter"]}
if index == 8 { <<["Progress mode", "Fail next", "Cancel"]}
if index == 9 { <<["Mixed", "Checked", "Unchecked"]}
if index == 10 { <<["Pending", "Resolve", "Fail"]}
if index == 11 { <<["Select", "Deselect", ""]}
if index == 13 { <<["Apply input", "Commit only", "Live updates"]}
if index == 15 { <<["Open", "Disable option", ""]}
if index == 16 { <<["Allow custom", "Options only", "Clear"]}
if index == 17 { <<["Select all", "Clear", ""]}
if index == 18 { <<["Clear", "Set today", ""]}
if index == 19 { <<["12 hour", "24 hour", "Hide seconds"]}
if index == 20 { <<["Apply HEX", "Cinnabar", "Transparent"]}
if index == 24 { <<["Data", "Loading", "Error"]}
if index == 25 { <<["Jump", "Last page", "Empty / full"]}
if index == 27 { <<["0%", "42%", "100%"]}
if index == 28 { <<["Start", "Stop", "Large size"]}
if index == 30 { <<["+1 unread", "Clear", "99+ overflow"]}
if index == 32 { <<["Scroll top", "Scroll bottom", "Focus last"]}
if index == 33 { <<["Open", "Close", "Placement"]}
if index == 34 { <<["Focus help", "Blur", "Placement"]}
if index == 35 { <<["Enqueue", "Undo", "Burst 3"]}
if index == 36 { <<["Open", "Close", ""]}
if index == 37 { <<["Reload", "Hide", "Show"]}
<<["", "", ""]
}
if index == 45 { <<["清空", "重置示例", "聚焦输入"]}
if index == 40 { <<["端点限制 / 推挤", "提交模式", "切换方向"]}
if index == 41 { <<["切换方向", "折叠 / 恢复", "复位比例"]}
if index >= 42 && index <= 44 { <<["打开菜单", "保持展开", "禁用导出"]}
if index == 38 { <<["逐项禁用", "切换方向", "拼接 / 间距"]}
if index == 39 { <<["更新数据", "复位缩放", "暂停 / 继续"]}
if index == 0 { <<["切换长文", "切换短文", ""]}
if index == 1 || index == 2 { <<["设为选中", "取消选中", ""]}
if index == 3 || index == 4 { <<["清空内容", "填充长文", ""]}
if index == 5 || index == 6 { <<["清空内容", "填充长文", "切换外观"]}
if index == 7 { <<["引导线", "定位末项", "清空筛选"]}
if index == 8 { <<["进度外观", "下次失败", "取消任务"]}
if index == 9 { <<["混合态", "勾选", "取消勾选"]}
if index == 10 { <<["等待态", "完成切换", "失败恢复"]}
if index == 11 { <<["选中", "取消选中", ""]}
if index == 13 { <<["应用输入", "松开提交", "实时更新"]}
if index == 15 { <<["展开候选", "禁用选项", ""]}
if index == 16 { <<["允许自由输入", "仅限选项", "清空"]}
if index == 17 { <<["全选", "清空", ""]}
if index == 18 { <<["清空日期", "设为今天", ""]}
if index == 19 { <<["12 小时制", "24 小时制", "隐藏秒数"]}
if index == 20 { <<["应用 HEX", "朱砂色", "半透明"]}
if index == 24 { <<["正常数据", "正在加载", "加载错误"]}
if index == 25 { <<["页码跳转", "跳至末页", "空 / 满数据"]}
if index == 27 { <<["0%", "42%", "100%"]}
if index == 28 { <<["开始旋转", "停止旋转", "切换大号"]}
if index == 30 { <<["+1 未读", "清零未读", "99+ 溢出"]}
if index == 32 { <<["滚至顶部", "滚至底部", "聚焦末项"]}
if index == 33 { <<["打开浮层", "关闭浮层", "切换方位"]}
if index == 34 { <<["聚焦提示", "移出隐藏", "切换方位"]}
if index == 35 { <<["发送通知", "撤销通知", "连发三条"]}
if index == 36 { <<["打开确认框", "关闭确认框", ""]}
if index == 37 { <<["重新加载", "隐藏视图", "恢复显示"]}
<<["", "", ""]
}
fn workshop_menu_items(english bool)[]widgets.MenuItem{
labels :=["Open workspace", "Show grid", "Export", "PNG image", "SVG image", "Unavailable", "Save", "View density", "Compact", "Comfortable"]
$translated := labels
if !english{translated =["打开工作区", "显示网格", "导出", "PNG 图片", "SVG 图片", "暂不可用", "保存", "视图密度", "紧凑", "舒适"]}
$grid := widgets.menu_item(20, translated[1])
grid.kind = widgets.MENU_CHECK
$export := widgets.menu_item(30, translated[2])
export.kind = widgets.MENU_SUBMENU
$png := widgets.menu_item(31, translated[3])
png.parent = 30
$svg := widgets.menu_item(32, translated[4])
svg.parent = 30
$unavailable := widgets.menu_item(40, translated[5])
unavailable.enabled = false
$save := widgets.menu_item(50, translated[6])
save.shortcut_key = 115
save.shortcut_modifiers = ui.MOD_META
save.shortcut_label = "⌘S"
$separator := widgets.menu_item(60, "")
separator.kind = widgets.MENU_SEPARATOR
$heading := widgets.menu_item(70, translated[7])
heading.kind = widgets.MENU_HEADING
$compact := widgets.menu_item(80, translated[8])
compact.kind = widgets.MENU_RADIO
compact.radio_group = 1
$comfortable := widgets.menu_item(81, translated[9])
comfortable.kind = widgets.MENU_RADIO
comfortable.radio_group = 1
comfortable.checked = true
<<[widgets.menu_item(10, translated[0]), grid, export, png, svg, unavailable, save, separator, heading, compact, comfortable]
}
fn chart_data(kind int, revision int)[]chart.ChartSeries{
<< chart_data_locale(kind, revision, true)
}
fn chart_data_locale(kind int, revision int, english bool)[]chart.ChartSeries{
$result :=[]chart.ChartSeries{}
$series_count := 2
single := kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
kind == widgets.CHART_GAUGE || kind == widgets.CHART_HISTOGRAM || kind == widgets.CHART_BOXPLOT ||
kind == widgets.CHART_CANDLESTICK || kind == widgets.CHART_WATERFALL || kind == widgets.CHART_FUNNEL ||
(kind >= widgets.CHART_POLAR_BAR && kind <= widgets.CHART_SANKEY) || kind == widgets.CHART_VIOLIN ||
kind == widgets.CHART_BULLET || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_PARETO
if single{series_count = 1}
if kind == widgets.CHART_HEATMAP{series_count = 3}
for si in 0:series_count{
$name := "构建"
if si == 1 {name = "索引"}
if si == 2 {name = "绘制"}
if single{name = "工作量"}
if english {
name = "Build"
if si == 1 {name = "Index"}
if si == 2 {name = "Render"}
if single{name = "Workload"}
}
$series := chart.chart_series(si + 1, name, kind)
series.smooth = kind == widgets.CHART_LINE || kind == widgets.CHART_AREA || kind == widgets.CHART_STACKED_AREA ||
kind == widgets.CHART_SMOOTH_LINE || kind == widgets.CHART_SMOOTH_AREA
$count := 12 - revision % 2
if kind == widgets.CHART_SCATTER{count = 64}
else if kind == widgets.CHART_BUBBLE{count = 16}
else if kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
kind == widgets.CHART_FUNNEL || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{count = 5}
else if kind == widgets.CHART_RADAR || kind == widgets.CHART_PARETO{count = 6}
else if kind == widgets.CHART_GAUGE{count = 3}
else if kind == widgets.CHART_POLAR_BAR{count = 4}
else if kind == widgets.CHART_HORIZONTAL_BAR || kind == widgets.CHART_HEATMAP || kind == widgets.CHART_BULLET ||
kind == widgets.CHART_LOLLIPOP || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_VIOLIN{count = 8}
else if kind == widgets.CHART_WATERFALL{count = 7}
for i in 0:count{
x := f64(i + 1)
phase := f64(revision) * 0.9 + f64(si) * 1.7
$y := 48.0 + f64(si) * 20.0 + math.sin(x * 0.55 + phase) * 20.0 + math.cos(x * 0.17 + phase) * 7.0
if kind == widgets.CHART_FUNNEL || kind == widgets.CHART_PARETO || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{
y = f64((count - i) * 22 + (revision % 3) * 4)
} else if kind == widgets.CHART_GAUGE || kind == widgets.CHART_POLAR_BAR{
y = math.max(12.0, math.min(96.0, 34.0 + f64(i) * 18.0 + math.sin(phase + x) * 14.0))
} else if kind == widgets.CHART_WATERFALL{
deltas :=[42.0, 18.0, 0.0 - 14.0, 24.0, 0.0 - 11.0, 16.0, 0.0]
y = deltas[i] + math.sin(phase) * 3.0
if i == count - 1 {y = 0.0}
}
$point := chart.chart_point(i + 1, x, y)
if kind == widgets.CHART_BUBBLE{
point = chart.chart_bubble_point(i + 1, x, y, 12.0 + math.abs(math.cos(x * 0.7 + phase)) * 36.0)
} else if kind == widgets.CHART_BOXPLOT || kind == widgets.CHART_CANDLESTICK ||
kind == widgets.CHART_VIOLIN || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_BULLET{
$close := y + math.sin(x * 0.9 + phase) * 12.0
if (kind == widgets.CHART_BOXPLOT || kind == widgets.CHART_VIOLIN || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_BULLET) && close < y{
close = y + 10.0
}
low := math.min(y, close) - 8.0 - math.abs(math.cos(x + phase)) * 6.0
high := math.max(y, close) + 8.0 + math.abs(math.sin(x + phase)) * 6.0
point = chart.chart_range_point(i + 1, x, y, low, high, close)
} else if kind == widgets.CHART_WATERFALL && i == count - 1 {
point.size = 1.0
}
if english {
point.label = "Sample " + str(i + 1)
if kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
kind == widgets.CHART_FUNNEL || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{
point.label =["Compile", "Index", "Render", "I/O", "Other"][i]
} else if kind == widgets.CHART_RADAR{
point.label =["Throughput", "Latency", "Memory", "Startup", "Cache", "Binary"][i]
} else if kind == widgets.CHART_GAUGE{
point.label =["CPU", "Memory", "Cache"][i]
} else if kind == widgets.CHART_POLAR_BAR{
point.label =["Core 0", "Core 1", "Core 2", "Core 3"][i]
} else if kind == widgets.CHART_WATERFALL && i == count - 1 {
point.label = "Total"
}
} else {
point.label = "样本 " + str(i + 1)
if kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
kind == widgets.CHART_FUNNEL || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{
point.label =["编译", "索引", "绘制", "输入输出", "其他"][i]
} else if kind == widgets.CHART_RADAR{
point.label =["吞吐量", "延迟", "内存", "启动", "缓存", "体积"][i]
} else if kind == widgets.CHART_GAUGE{
point.label =["处理器", "内存", "缓存"][i]
} else if kind == widgets.CHART_POLAR_BAR{
point.label =["核心 0", "核心 1", "核心 2", "核心 3"][i]
} else if kind == widgets.CHART_WATERFALL && i == count - 1 {
point.label = "总计"
}
}
series.points.push(point)
}
result.push(series)
}
<< result
}const CONTENT_NONEpub const CONTENT_NONE = 0常量 CONTENT_NONE,定义了相关的协议或算法配置参数。
const CONTENT_WEBVIEWpub const CONTENT_WEBVIEW = 1常量 CONTENT_WEBVIEW,定义了相关的协议或算法配置参数。
const CONTENT_DRAWpub const CONTENT_DRAW = 2常量 CONTENT_DRAW,定义了相关的协议或算法配置参数。
const CONTENT_NATIVEpub const CONTENT_NATIVE = 3常量 CONTENT_NATIVE,定义了相关的协议或算法配置参数。
const OS_MACOSpub const OS_MACOS = 0常量 OS_MACOS,定义了相关的协议或算法配置参数。
const OS_LINUXpub const OS_LINUX = 1常量 OS_LINUX,定义了相关的协议或算法配置参数。
const OS_WINDOWSpub const OS_WINDOWS = 2常量 OS_WINDOWS,定义了相关的协议或算法配置参数。
const OS_NONEpub const OS_NONE = 3常量 OS_NONE,定义了相关的协议或算法配置参数。
const EV_NONEpub const EV_NONE = 0常量 EV_NONE,定义了相关的协议或算法配置参数。
const EV_READYpub const EV_READY = 1常量 EV_READY,定义了相关的协议或算法配置参数。
const EV_EXITpub const EV_EXIT = 2常量 EV_EXIT,定义了相关的协议或算法配置参数。
const EV_BEFORE_EXITpub const EV_BEFORE_EXIT = 3常量 EV_BEFORE_EXIT,定义了相关的协议或算法配置参数。
const EV_CLOSE_REQUESTEDpub const EV_CLOSE_REQUESTED = 10常量 EV_CLOSE_REQUESTED,定义了相关的协议或算法配置参数。
const EV_CLOSEDpub const EV_CLOSED = 11常量 EV_CLOSED,定义了相关的协议或算法配置参数。
const EV_FOCUSEDpub const EV_FOCUSED = 12常量 EV_FOCUSED,定义了相关的协议或算法配置参数。
const EV_BLURREDpub const EV_BLURRED = 13常量 EV_BLURRED,定义了相关的协议或算法配置参数。
const EV_RESIZEDpub const EV_RESIZED = 14常量 EV_RESIZED,定义了相关的协议或算法配置参数。
const EV_MOVEDpub const EV_MOVED = 15常量 EV_MOVED,定义了相关的协议或算法配置参数。
const EV_MENU_CLICKEDpub const EV_MENU_CLICKED = 20常量 EV_MENU_CLICKED,定义了相关的协议或算法配置参数。
const EV_TRAY_CLICKEDpub const EV_TRAY_CLICKED = 30常量 EV_TRAY_CLICKED,定义了相关的协议或算法配置参数。
const EV_TRAY_MENU_CLICKEDpub const EV_TRAY_MENU_CLICKED = 31常量 EV_TRAY_MENU_CLICKED,定义了相关的协议或算法配置参数。
const EV_LOADINGpub const EV_LOADING = 40常量 EV_LOADING,定义了相关的协议或算法配置参数。
const EV_LOADEDpub const EV_LOADED = 41常量 EV_LOADED,定义了相关的协议或算法配置参数。
const EV_LOAD_FAILEDpub const EV_LOAD_FAILED = 42常量 EV_LOAD_FAILED,定义了相关的协议或算法配置参数。
const EV_PROGRESSpub const EV_PROGRESS = 43常量 EV_PROGRESS,定义了相关的协议或算法配置参数。
const EV_FILE_DROPpub const EV_FILE_DROP = 50常量 EV_FILE_DROP,定义了相关的协议或算法配置参数。
const EV_FILE_PICKEDpub const EV_FILE_PICKED = 51常量 EV_FILE_PICKED,定义了相关的协议或算法配置参数。
const EV_FILE_SAVEDpub const EV_FILE_SAVED = 52常量 EV_FILE_SAVED,定义了相关的协议或算法配置参数。
const EV_EXTERNAL_NAVpub const EV_EXTERNAL_NAV = 53常量 EV_EXTERNAL_NAV,定义了相关的协议或算法配置参数。
const EV_SCREENSHOTpub const EV_SCREENSHOT = 54常量 EV_SCREENSHOT,定义了相关的协议或算法配置参数。
const EV_FOLDER_PICKEDpub const EV_FOLDER_PICKED = 55常量 EV_FOLDER_PICKED,定义了相关的协议或算法配置参数。
const EV_ALERTpub const EV_ALERT = 56常量 EV_ALERT,定义了相关的协议或算法配置参数。
const EV_CONFIRMpub const EV_CONFIRM = 57常量 EV_CONFIRM,定义了相关的协议或算法配置参数。
const EV_NOTIFYpub const EV_NOTIFY = 58常量 EV_NOTIFY,定义了相关的协议或算法配置参数。
const EV_CLOSE_REJECTEDpub const EV_CLOSE_REJECTED = 59常量 EV_CLOSE_REJECTED,定义了相关的协议或算法配置参数。
const EV_CACHE_CLEAREDpub const EV_CACHE_CLEARED = 60常量 EV_CACHE_CLEARED,定义了相关的协议或算法配置参数。
const EV_DOWNLOADpub const EV_DOWNLOAD = 61常量 EV_DOWNLOAD,定义了相关的协议或算法配置参数。
const EV_DOWNLOAD_FAILEDpub const EV_DOWNLOAD_FAILED = 62常量 EV_DOWNLOAD_FAILED,定义了相关的协议或算法配置参数。
const EV_COOKIES_CLEAREDpub const EV_COOKIES_CLEARED = 63常量 EV_COOKIES_CLEARED,定义了相关的协议或算法配置参数。
const EV_COOKIE_SETpub const EV_COOKIE_SET = 64常量 EV_COOKIE_SET,定义了相关的协议或算法配置参数。
const EV_CLIPBOARDpub const EV_CLIPBOARD = 65常量 EV_CLIPBOARD,定义了相关的协议或算法配置参数。
const EV_BOUNDSpub const EV_BOUNDS = 66常量 EV_BOUNDS,定义了相关的协议或算法配置参数。
const EV_STATEpub const EV_STATE = 67常量 EV_STATE,定义了相关的协议或算法配置参数。
const EV_CLICKpub const EV_CLICK = 68常量 EV_CLICK,定义了相关的协议或算法配置参数。
const EV_PROMPTpub const EV_PROMPT = 69常量 EV_PROMPT,定义了相关的协议或算法配置参数。
const EV_SCROLLpub const EV_SCROLL = 70常量 EV_SCROLL,定义了相关的协议或算法配置参数。
const EV_DRAGpub const EV_DRAG = 71常量 EV_DRAG,定义了相关的协议或算法配置参数。
const EV_EMIT_FAILEDpub const EV_EMIT_FAILED = 84常量 EV_EMIT_FAILED,定义了相关的协议或算法配置参数。
const EV_WINDOW_READYpub const EV_WINDOW_READY = 94常量 EV_WINDOW_READY,定义了相关的协议或算法配置参数。
const EV_WINDOW_FAILEDpub const EV_WINDOW_FAILED = 95常量 EV_WINDOW_FAILED,定义了相关的协议或算法配置参数。
const EV_COMMAND_UNSUPPORTEDpub const EV_COMMAND_UNSUPPORTED = 96常量 EV_COMMAND_UNSUPPORTED,定义了相关的协议或算法配置参数。
const EV_NAVIGATE_BACKpub const EV_NAVIGATE_BACK = 99常量 EV_NAVIGATE_BACK,定义了相关的协议或算法配置参数。
struct ContentPluginpub 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
}承载 kind、bootstrap、macos_src、macos_frameworks、linux_src 等属性的结构体。
kind intbootstrap stringmacos_src stringmacos_frameworks stringlinux_src stringlinux_libs stringwindows_src stringwindows_libs stringstruct Eventpub struct Event {
pub kind int
pub window_id int
pub menu_id string
pub width int
pub height int
}承载 kind、window_id、menu_id、width、height 等属性的结构体。
kind intwindow_id intmenu_id stringwidth intheight intstruct Iconpub struct Icon {
pub path string
}承载 path 等属性的结构体。
path stringstruct MenuItempub struct MenuItem {
pub id string
pub label string
}承载 id、label 等属性的结构体。
id stringlabel stringstruct Menupub struct Menu {
pub items []MenuItem
}承载 items 等属性的结构体。
items []MenuItemstruct WindowOptspub struct WindowOpts {
pub title string
pub width int
pub height int
}承载 title、width、height 等属性的结构体。
title stringwidth intheight intstruct Windowpub struct Window {
pub generation int
pub id int
pub title string
pub width int
pub height int
pub content_kind int
pub content_backend_id int
pub closed int
}承载 generation、id、title、width、height 等属性的结构体。
generation intid inttitle stringwidth intheight intcontent_kind intcontent_backend_id intclosed intstruct TrayOptspub struct TrayOpts {
pub tip string
pub icon Icon
pub menu Menu
}承载 tip、icon、menu 等属性的结构体。
tip stringicon Iconmenu Menustruct Traypub struct Tray {
pub id int
pub tip string
}承载 id、tip 等属性的结构体。
id inttip stringstruct Apppub 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
}承载 next_id、icon、quit_flag、sim、event_ch 等属性的结构体。
next_id inticon Iconquit_flag intsim intevent_ch chan Eventpost_ch chan intmenu_ids []stringwin_title stringwin_w intwin_h intnew_apppub fn new_app() App构造 app。
无需传入参数。
App — 该类型的值
new_app_eventspub fn new_app_events(ech chan Event) App构造 app events。
ech chan EventApp — 该类型的值
icon_defaultpub fn icon_default() Icon执行 icon default 操作。
无需传入参数。
Icon — 该类型的值
icon_from_filepub fn icon_from_file(path string) Icon执行 icon from file 操作。
path stringIcon — 该类型的值
menu_itempub fn menu_item(id string, label string) MenuItem执行 menu item 操作。
id stringlabel stringMenuItem — 该类型的值
menupub fn menu(items []MenuItem) Menu执行 menu 处理。
items []MenuItemMenu — 该类型的值
target_ospub fn target_os() int执行 target os 操作。
无需传入参数。
int — 该类型的值
platform_supportedpub fn platform_supported() bool执行 platform supported 操作。
无需传入参数。
bool — 是否成立
($&App) alloc_idpub fn (a $&App) alloc_id() int$&App 上的操作:执行 alloc id 操作。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
($&App) set_iconpub fn (a $&App) set_icon(icon Icon)$&App 上的操作:设置 icon。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。icon Icon不返回值。
install_tray_iconpub fn install_tray_icon(path string) int执行 install tray icon 操作。失败时抛出错误,调用方需处理或继续传播。
path stringint — 该类型的值
($&App) new_windowpub fn (a $&App) new_window(opts WindowOpts) Window$&App 上的操作:构造 window。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。opts WindowOptsWindow — 该类型的值
install_menupub fn install_menu(m Menu) int执行 install menu 操作。失败时抛出错误,调用方需处理或继续传播。
m Menuint — 该类型的值
native_set_menu_visiblepub fn native_set_menu_visible(on int) int在 App.run 前后控制 Windows 原生窗口的默认菜单栏;写入失败时抛出错误。
on int写入操作的返回值
install_traypub fn install_tray(tip string, m Menu) int执行 install tray 操作。失败时抛出错误,调用方需处理或继续传播。
tip stringm Menuint — 该类型的值
($&Window) set_menupub fn (w $&Window) set_menu(m Menu)$&Window 上的操作:设置 menu。
w $&WindowWindow 实例;以独占借用传入,方法可修改它,调用方仍持有实例。m Menu不返回值。
($&App) new_traypub fn (a $&App) new_tray(opts TrayOpts) Tray$&App 上的操作:构造 tray。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。opts TrayOptsTray — 该类型的值
($&Window) set_titlepub fn (w $&Window) set_title(title string)$&Window 上的操作:设置 title。
w $&WindowWindow 实例;以独占借用传入,方法可修改它,调用方仍持有实例。title string不返回值。
native_set_titlepub fn native_set_title(title string) int执行 native set title 操作。失败时抛出错误,调用方需处理或继续传播。
title stringint — 该类型的值
native_set_sizepub fn native_set_size(width int, height int) int执行 native set size 操作。失败时抛出错误,调用方需处理或继续传播。
width intheight intint — 该类型的值
append_shell_cmdpub fn append_shell_cmd(line string) int执行 append shell cmd 操作。失败时抛出错误,调用方需处理或继续传播。
line stringint — 该类型的值
append_content_cmdpub fn append_content_cmd(line string) int执行 append content cmd 操作。失败时抛出错误,调用方需处理或继续传播。
line stringint — 该类型的值
append_wv_cmdpub fn append_wv_cmd(line string) int执行 append wv cmd 操作。失败时抛出错误,调用方需处理或继续传播。
line stringint — 该类型的值
host_enabledpub fn host_enabled() bool执行 host enabled 操作。
无需传入参数。
bool — 是否成立
host_tmppub fn host_tmp() string执行 host tmp 操作。
无需传入参数。
string — 结果字符串
native_showpub fn native_show() int执行 native show 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
int — 该类型的值
native_hidepub fn native_hide() int执行 native hide 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
int — 该类型的值
native_minimizepub fn native_minimize() int执行 native minimize 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
int — 该类型的值
native_set_positionpub fn native_set_position(x int, y int) int执行 native set position 操作。失败时抛出错误,调用方需处理或继续传播。
x inty intint — 该类型的值
native_set_fullscreenpub fn native_set_fullscreen(on int) int执行 native set fullscreen 操作。失败时抛出错误,调用方需处理或继续传播。
on intint — 该类型的值
native_set_floatingpub fn native_set_floating(on int) int执行 native set floating 操作。失败时抛出错误,调用方需处理或继续传播。
on intint — 该类型的值
native_centerpub fn native_center() int执行 native center 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
int — 该类型的值
native_open_externalpub fn native_open_external(url string) int执行 native open external 操作。失败时抛出错误,调用方需处理或继续传播。
url stringint — 该类型的值
native_clipboard_setpub fn native_clipboard_set(text string) int执行 native clipboard set 操作。失败时抛出错误,调用方需处理或继续传播。
text stringint — 该类型的值
native_clipboard_getpub fn native_clipboard_get() string执行 native clipboard get 操作。
无需传入参数。
string — 结果字符串
native_set_maximizedpub fn native_set_maximized(on int) int执行 native set maximized 操作。失败时抛出错误,调用方需处理或继续传播。
on intint — 该类型的值
native_bouncepub fn native_bounce() int执行 native bounce 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
int — 该类型的值
native_pick_filepub fn native_pick_file() string执行 native pick file 操作。
无需传入参数。
string — 结果字符串
native_set_opacitypub fn native_set_opacity(percent int) int执行 native set opacity 操作。失败时抛出错误,调用方需处理或继续传播。
percent intint — 该类型的值
native_save_filepub fn native_save_file(suggested_name string) string执行 native save file 操作。
suggested_name stringstring — 结果字符串
native_screenshotpub fn native_screenshot() string执行 native screenshot 操作。
无需传入参数。
string — 结果字符串
native_alertpub fn native_alert(title string, message string) int执行 native alert 操作。
title stringmessage stringint — 该类型的值
native_confirmpub fn native_confirm(title string, message string) int执行 native confirm 操作。
title stringmessage stringint — 该类型的值
native_notifypub fn native_notify(title string, body string) int原生通知。
title stringbody stringint — 该类型的值
native_pick_folderpub fn native_pick_folder() string执行 native pick folder 操作。
无需传入参数。
string — 结果字符串
native_set_min_sizepub fn native_set_min_size(width int, height int) int执行 native set min size 操作。失败时抛出错误,调用方需处理或继续传播。
width intheight intint — 该类型的值
native_set_resizablepub fn native_set_resizable(on int) int执行 native set resizable 操作。失败时抛出错误,调用方需处理或继续传播。
on intint — 该类型的值
native_get_boundspub fn native_get_bounds() string执行 native get bounds 操作。
无需传入参数。
string — 结果字符串
native_set_titlebar_visiblepub fn native_set_titlebar_visible(on int) int执行 native set titlebar visible 操作。
on intint — 该类型的值
native_set_close_guardpub fn native_set_close_guard(on int) int执行 native set close guard 操作。
on intint — 该类型的值
native_accept_closepub fn native_accept_close() int关闭原生接受。
无需传入参数。
int — 该类型的值
native_reject_closepub fn native_reject_close() int关闭原生reject。
无需传入参数。
int — 该类型的值
native_set_visible_on_all_spacespub fn native_set_visible_on_all_spaces(on int) int执行 native set visible on all spaces 操作。
on intint — 该类型的值
native_get_statepub fn native_get_state() string执行 native get state 操作。
无需传入参数。
string — 结果字符串
native_open_pathpub fn native_open_path(path string) int执行 native open path 操作。
path stringint — 该类型的值
native_reveal_pathpub fn native_reveal_path(path string) int执行 native reveal path 操作。
path stringint — 该类型的值
native_set_appearancepub fn native_set_appearance(mode string) int执行 native set appearance 操作。
mode stringint — 该类型的值
native_set_dock_badgepub fn native_set_dock_badge(text string) int执行 native set dock badge 操作。
text stringint — 该类型的值
native_screenshot_to_clipboardpub fn native_screenshot_to_clipboard() int执行 native screenshot to clipboard 操作。
无需传入参数。
int — 该类型的值
native_set_shadowpub fn native_set_shadow(on int) int执行 native set shadow 操作。
on intint — 该类型的值
native_set_framelesspub fn native_set_frameless(on int) int执行 native set frameless 操作。
on intint — 该类型的值
native_set_transparentpub fn native_set_transparent(on int) int执行 native set transparent 操作。
on intint — 该类型的值
native_set_window_maskpub fn native_set_window_mask(path string) int执行 native set window mask 操作。失败时抛出错误,调用方需处理或继续传播。
path stringint — 该类型的值
native_clear_window_maskpub fn native_clear_window_mask() int执行 native clear window mask 操作。
无需传入参数。
int — 该类型的值
native_quitpub fn native_quit() int执行 native quit 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
int — 该类型的值
unsupported_msgpub fn unsupported_msg() string执行 unsupported msg 操作。
无需传入参数。
string — 结果字符串
($&App) remember_menupub fn (a $&App) remember_menu(m Menu)$&App 上的操作:执行 remember menu 操作。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。m Menu不返回值。
($&Window) set_content_slotpub fn (w $&Window) set_content_slot(kind int, backend_id int)$&Window 上的操作:设置 content slot。
w $&WindowWindow 实例;以独占借用传入,方法可修改它,调用方仍持有实例。kind intbackend_id int不返回值。
(Window) content_slot_kindpub fn (w Window) content_slot_kind() intWindow 上的操作:执行 content slot kind 操作。
w WindowWindow 实例;按值接收。int — 该类型的值
(Window) content_slot_backend_idpub fn (w Window) content_slot_backend_id() intWindow 上的操作:执行 content slot backend id 操作。
w WindowWindow 实例;按值接收。int — 该类型的值
($&Window) closepub fn (w $&Window) close()$&Window 上的操作:关闭资源。
w $&WindowWindow 实例;以独占借用传入,方法可修改它,调用方仍持有实例。不返回值。
($&App) quitpub fn (a $&App) quit()在 $&App 上执行 quit 操作。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。不返回值。
($&App) push_eventpub fn (a $&App) push_event(ev Event)$&App 上的操作:执行 push event 操作。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。ev Event不返回值。
($&App) poll_eventpub fn (a $&App) poll_event() Event$&App 上的操作:执行 poll event 操作。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。Event — 该类型的值
($&App) postpub fn (a $&App) post(token int)在 $&App 上执行 post 操作。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。token int不返回值。
($&App) try_recv_postpub fn (a $&App) try_recv_post() int$&App 上的操作:执行 try recv post 操作。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
content_plugin_webviewpub fn content_plugin_webview() ContentPlugin执行 content plugin webview 操作。
无需传入参数。
ContentPlugin — 该类型的值
content_plugin_drawpub fn content_plugin_draw() ContentPlugin执行 content plugin draw 操作。
无需传入参数。
ContentPlugin — 该类型的值
use_draw_contentpub fn use_draw_content(w $&Window) int执行 use draw content 操作。
w $&Windowint — 该类型的值
native_draw_set_bgpub fn native_draw_set_bg(hex string) int执行 native draw set bg 操作。失败时抛出错误,调用方需处理或继续传播。
hex stringint — 该类型的值
native_draw_clearpub fn native_draw_clear() int执行 native draw clear 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
int — 该类型的值
native_draw_set_labelpub fn native_draw_set_label(text string) int执行 native draw set label 操作。失败时抛出错误,调用方需处理或继续传播。
text stringint — 该类型的值
register_content_pluginpub fn register_content_plugin(p ContentPlugin) int执行 register content plugin 操作。
p ContentPluginint — 该类型的值
($&App) runpub fn (a $&App) run() int$&App 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
load_assetpub fn load_asset(path string) string执行 load asset 操作。失败时抛出错误,调用方需处理或继续传播。
path stringstring — 结果字符串
load_embedded_assetpub fn load_embedded_asset(path &string) string执行 load embedded asset 操作。失败时抛出错误,调用方需处理或继续传播。
path &stringstring — 结果字符串
const EV_CANVAS_PREFERENCESpub const EV_CANVAS_PREFERENCES = 97常量 EV_CANVAS_PREFERENCES,定义了相关的协议或算法配置参数。
struct CanvasPreferencespub struct CanvasPreferences {
pub identity CanvasEvent
pub reduced_motion bool
}承载 identity、reduced_motion 等属性的结构体。
identity CanvasEventreduced_motion boolrequest_canvas_preferencespub fn request_canvas_preferences(identity &CanvasEvent) int执行 request canvas preferences 操作。失败时抛出错误,调用方需处理或继续传播。
identity &CanvasEventint — 该类型的值
canvas_preferences_ofpub fn canvas_preferences_of(event &Event) CanvasPreferences执行 canvas preferences of 操作。失败时抛出错误,调用方需处理或继续传播。
event &EventCanvasPreferences — 该类型的值
push_host_eventpub fn push_host_event(ech chan Event, pl0 string)执行 push host event 操作。
ech chan Eventpl0 string不返回值。
drain_host_eventspub fn drain_host_events(ech chan Event)执行 drain host events 操作。
ech chan Event不返回值。
poll_chanpub fn poll_chan(ech chan Event) Event执行 poll chan 操作。
ech chan EventEvent — 该类型的值
const REQUEST_OPEN_FILESpub const REQUEST_OPEN_FILES = 4常量 REQUEST_OPEN_FILES,定义了相关的协议或算法配置参数。
const REQUEST_SAVE_FILEpub const REQUEST_SAVE_FILE = 5常量 REQUEST_SAVE_FILE,定义了相关的协议或算法配置参数。
const REQUEST_SELECT_FOLDERSpub const REQUEST_SELECT_FOLDERS = 6常量 REQUEST_SELECT_FOLDERS,定义了相关的协议或算法配置参数。
struct FileFilterpub struct FileFilter {
pub label string
pub extensions []string
}承载 label、extensions 等属性的结构体。
label stringextensions []stringstruct FileDialogOptionspub struct FileDialogOptions {
pub title string
pub directory string
pub name string
pub filters []FileFilter
pub multiple bool
pub timeout_ms int
}Ui 配置参数与选项集合。
title stringdirectory stringname stringfilters []FileFiltermultiple booltimeout_ms intfile_dialog_optionspub fn file_dialog_options() FileDialogOptions执行 file dialog options 操作。
无需传入参数。
FileDialogOptions — 该类型的值
open_files_asyncpub fn open_files_async(target &CanvasEvent, options &FileDialogOptions) Request执行 open files async 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventoptions &FileDialogOptionsRequest — 该类型的值
save_file_asyncpub fn save_file_async(target &CanvasEvent, options &FileDialogOptions) Request执行 save file async 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventoptions &FileDialogOptionsRequest — 该类型的值
select_folders_asyncpub fn select_folders_async(target &CanvasEvent, options &FileDialogOptions) Request执行 select folders async 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventoptions &FileDialogOptionsRequest — 该类型的值
file_pathspub fn file_paths(result &RequestResult) []string执行 file paths 操作。失败时抛出错误,调用方需处理或继续传播。
result &RequestResult[]string — 切片结果
const EV_POINTER_DOWNpub const EV_POINTER_DOWN = 72常量 EV_POINTER_DOWN,定义了相关的协议或算法配置参数。
const EV_POINTER_UPpub const EV_POINTER_UP = 73常量 EV_POINTER_UP,定义了相关的协议或算法配置参数。
const EV_POINTER_MOVEpub const EV_POINTER_MOVE = 74常量 EV_POINTER_MOVE,定义了相关的协议或算法配置参数。
const EV_POINTER_ENTERpub const EV_POINTER_ENTER = 75常量 EV_POINTER_ENTER,定义了相关的协议或算法配置参数。
const EV_POINTER_LEAVEpub const EV_POINTER_LEAVE = 76常量 EV_POINTER_LEAVE,定义了相关的协议或算法配置参数。
const EV_POINTER_CANCELpub const EV_POINTER_CANCEL = 77常量 EV_POINTER_CANCEL,定义了相关的协议或算法配置参数。
const EV_KEY_DOWNpub const EV_KEY_DOWN = 78常量 EV_KEY_DOWN,定义了相关的协议或算法配置参数。
const EV_KEY_UPpub const EV_KEY_UP = 79常量 EV_KEY_UP,定义了相关的协议或算法配置参数。
const EV_POINTER_SCROLLpub const EV_POINTER_SCROLL = 80常量 EV_POINTER_SCROLL,定义了相关的协议或算法配置参数。
const EV_CANVAS_READYpub const EV_CANVAS_READY = 81常量 EV_CANVAS_READY,定义了相关的协议或算法配置参数。
const EV_CANVAS_CLOSEDpub const EV_CANVAS_CLOSED = 82常量 EV_CANVAS_CLOSED,定义了相关的协议或算法配置参数。
const MOD_SHIFTpub const MOD_SHIFT = 1常量 MOD_SHIFT,定义了相关的协议或算法配置参数。
const MOD_CONTROLpub const MOD_CONTROL = 2常量 MOD_CONTROL,定义了相关的协议或算法配置参数。
const MOD_ALTpub const MOD_ALT = 4常量 MOD_ALT,定义了相关的协议或算法配置参数。
const MOD_METApub const MOD_META = 8常量 MOD_META,定义了相关的协议或算法配置参数。
const BUTTON_LEFTpub const BUTTON_LEFT = 1常量 BUTTON_LEFT,定义了相关的协议或算法配置参数。
const BUTTON_RIGHTpub const BUTTON_RIGHT = 2常量 BUTTON_RIGHT,定义了相关的协议或算法配置参数。
const BUTTON_MIDDLEpub const BUTTON_MIDDLE = 3常量 BUTTON_MIDDLE,定义了相关的协议或算法配置参数。
const CURSOR_DEFAULTpub const CURSOR_DEFAULT = 0常量 CURSOR_DEFAULT,定义了相关的协议或算法配置参数。
const CURSOR_TEXTpub const CURSOR_TEXT = 1常量 CURSOR_TEXT,定义了相关的协议或算法配置参数。
const CURSOR_CROSSHAIRpub const CURSOR_CROSSHAIR = 2常量 CURSOR_CROSSHAIR,定义了相关的协议或算法配置参数。
const CURSOR_HANDpub const CURSOR_HAND = 3常量 CURSOR_HAND,定义了相关的协议或算法配置参数。
const CURSOR_RESIZE_HORIZONTALpub const CURSOR_RESIZE_HORIZONTAL = 4常量 CURSOR_RESIZE_HORIZONTAL,定义了相关的协议或算法配置参数。
const CURSOR_RESIZE_VERTICALpub const CURSOR_RESIZE_VERTICAL = 5常量 CURSOR_RESIZE_VERTICAL,定义了相关的协议或算法配置参数。
const KEY_ESCAPEpub const KEY_ESCAPE = 256常量 KEY_ESCAPE,定义了相关的协议或算法配置参数。
const KEY_TABpub const KEY_TAB = 257常量 KEY_TAB,定义了相关的协议或算法配置参数。
const KEY_ENTERpub const KEY_ENTER = 258常量 KEY_ENTER,定义了相关的协议或算法配置参数。
const KEY_BACKSPACEpub const KEY_BACKSPACE = 259常量 KEY_BACKSPACE,定义了相关的协议或算法配置参数。
const KEY_DELETEpub const KEY_DELETE = 260常量 KEY_DELETE,定义了相关的协议或算法配置参数。
const KEY_LEFTpub const KEY_LEFT = 261常量 KEY_LEFT,定义了相关的协议或算法配置参数。
const KEY_RIGHTpub const KEY_RIGHT = 262常量 KEY_RIGHT,定义了相关的协议或算法配置参数。
const KEY_UPpub const KEY_UP = 263常量 KEY_UP,定义了相关的协议或算法配置参数。
const KEY_DOWNpub const KEY_DOWN = 264常量 KEY_DOWN,定义了相关的协议或算法配置参数。
const KEY_HOMEpub const KEY_HOME = 265常量 KEY_HOME,定义了相关的协议或算法配置参数。
const KEY_ENDpub const KEY_END = 266常量 KEY_END,定义了相关的协议或算法配置参数。
const KEY_PAGE_UPpub const KEY_PAGE_UP = 267常量 KEY_PAGE_UP,定义了相关的协议或算法配置参数。
const KEY_PAGE_DOWNpub const KEY_PAGE_DOWN = 268常量 KEY_PAGE_DOWN,定义了相关的协议或算法配置参数。
const KEY_INSERTpub const KEY_INSERT = 269常量 KEY_INSERT,定义了相关的协议或算法配置参数。
const KEY_F1pub const KEY_F1 = 288常量 KEY_F1,定义了相关的协议或算法配置参数。
const KEY_SHIFTpub const KEY_SHIFT = 304常量 KEY_SHIFT,定义了相关的协议或算法配置参数。
const KEY_CONTROLpub const KEY_CONTROL = 305常量 KEY_CONTROL,定义了相关的协议或算法配置参数。
const KEY_ALTpub const KEY_ALT = 306常量 KEY_ALT,定义了相关的协议或算法配置参数。
const KEY_METApub const KEY_META = 307常量 KEY_META,定义了相关的协议或算法配置参数。
const KEY_CAPS_LOCKpub const KEY_CAPS_LOCK = 308常量 KEY_CAPS_LOCK,定义了相关的协议或算法配置参数。
struct CanvasEventpub struct CanvasEvent {
pub window_id int
pub canvas_id int
pub generation int
}承载 window_id、canvas_id、generation 等属性的结构体。
window_id intcanvas_id intgeneration intcanvas_ofpub fn canvas_of(event &Event) CanvasEvent执行 canvas of 操作。失败时抛出错误,调用方需处理或继续传播。
event &EventCanvasEvent — 该类型的值
struct InputEventpub struct InputEvent {
pub kind int
pub window_id int
pub canvas_id int
pub generation int
pub x f64
pub y f64
pub dx f64
pub dy f64
pub button int
pub buttons int
pub modifiers int
pub key int
pub scan int
pub repeat int
pub click_count int
pub time_ns int
}承载 kind、window_id、canvas_id、generation、x 等属性的结构体。
kind intwindow_id intcanvas_id intgeneration intx f64y f64dx f64dy f64button intbuttons intmodifiers intkey intscan intrepeat intclick_count inttime_ns intis_input_eventpub fn is_input_event(kind int) bool判断是否 input event。
kind intbool — 是否成立
input_ofpub fn input_of(event &Event) InputEvent执行 input of 操作。失败时抛出错误,调用方需处理或继续传播。
event &EventInputEvent — 该类型的值
const MENU_ACTION_KINDpub const MENU_ACTION_KIND = 1常量 MENU_ACTION_KIND,定义了相关的协议或算法配置参数。
const MENU_SUBMENU_KINDpub const MENU_SUBMENU_KIND = 2常量 MENU_SUBMENU_KIND,定义了相关的协议或算法配置参数。
const MENU_SEPARATOR_KINDpub const MENU_SEPARATOR_KIND = 3常量 MENU_SEPARATOR_KIND,定义了相关的协议或算法配置参数。
const MENU_CHECK_KINDpub const MENU_CHECK_KIND = 4常量 MENU_CHECK_KIND,定义了相关的协议或算法配置参数。
const MENU_PRIMARYpub const MENU_PRIMARY = 16常量 MENU_PRIMARY,定义了相关的协议或算法配置参数。
struct MenuEntrypub struct MenuEntry {
pub id string
pub label string
pub parent int
pub kind int
pub enabled bool
pub checked bool
pub key int
pub modifiers int
}结构化菜单项;parent 用数组下标,根必须是 submenu。仅 check 可 checked,仅 action / check 可设置快捷键。
id stringlabel stringparent intkind intenabled boolchecked boolkey intmodifiers intmenu_actionpub fn menu_action(id string,label string,parent int) MenuEntry执行 menu action 操作。
id stringlabel stringparent intMenuEntry — 该类型的值
submenupub fn submenu(id string,label string,parent int) MenuEntry执行 submenu 处理。
id stringlabel stringparent intMenuEntry — 该类型的值
menu_checkpub fn menu_check(id string,label string,parent int,checked bool) MenuEntry执行 menu check 操作。
id stringlabel stringparent intchecked boolMenuEntry — 该类型的值
menu_separatorpub fn menu_separator(parent int) MenuEntry执行 menu separator 操作。
parent intMenuEntry — 该类型的值
encode_menu_entriespub fn encode_menu_entries(entries []MenuEntry) string编码 menu entries 数据。失败时抛出错误,调用方需处理或继续传播。
entries []MenuEntrystring — 结果字符串
(&Window) set_menu_entriespub fn (window &Window) set_menu_entries(entries []MenuEntry) int在下一宿主轮次原子替换本窗菜单树;最多 256 项、深度 8。应用负责更新点击后的勾选状态。
window &WindowWindow 实例;以只读借用传入,调用方仍持有实例。entries []MenuEntry宿主命令结果;无效菜单或关闭窗口抛出错误
const EV_CANVAS_METRICSpub const EV_CANVAS_METRICS = 83常量 EV_CANVAS_METRICS,定义了相关的协议或算法配置参数。
struct CanvasMetricspub struct CanvasMetrics {
pub window_id int
pub canvas_id int
pub generation int
pub width f64
pub height f64
pub buffer_width int
pub buffer_height int
pub scale_x f64
pub scale_y f64
}承载 window_id、canvas_id、generation、width、height 等属性的结构体。
window_id intcanvas_id intgeneration intwidth f64height f64buffer_width intbuffer_height intscale_x f64scale_y f64metrics_ofpub fn metrics_of(event &Event) CanvasMetrics执行 metrics of 操作。失败时抛出错误,调用方需处理或继续传播。
event &EventCanvasMetrics — 该类型的值
const EV_NATIVE_VIEWpub const EV_NATIVE_VIEW = 98常量 EV_NATIVE_VIEW,定义了相关的协议或算法配置参数。
struct NativeViewpub struct NativeView {
pub id int
pub generation int
pub window_id int
pub parent_generation int
}承载 id、generation、window_id、parent_generation 等属性的结构体。
id intgeneration intwindow_id intparent_generation intstruct NativeViewEventpub struct NativeViewEvent {
pub identity CanvasEvent
pub payload string
}承载 identity、payload 等属性的结构体。
identity CanvasEventpayload stringnative_viewpub fn native_view(parent &CanvasEvent,kind int) NativeView原生视图。失败时抛出错误,调用方需处理或继续传播。
parent &CanvasEventkind intNativeView — 该类型的值
(&NativeView) identitypub fn (view &NativeView) identity() CanvasEvent在 &NativeView 上执行 identity 操作。
view &NativeViewNativeView 实例;以只读借用传入,调用方仍持有实例。CanvasEvent — 该类型的值
(&NativeView) is_openpub fn (view &NativeView) is_open() bool&NativeView 上的操作:判断是否 open。
view &NativeViewNativeView 实例;以只读借用传入,调用方仍持有实例。bool — 是否成立
(&NativeView) is_readypub fn (view &NativeView) is_ready() bool&NativeView 上的操作:判断是否 ready。
view &NativeViewNativeView 实例;以只读借用传入,调用方仍持有实例。bool — 是否成立
($&NativeView) updatepub fn (view $&NativeView) update(bounds &layout.Rect,clip &layout.Rect,radius f64,visible bool,enabled bool,focused bool) int$&NativeView 上的操作:更新。失败时抛出错误,调用方需处理或继续传播。
view $&NativeViewNativeView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。bounds &layout.Rectclip &layout.Rectradius f64visible boolenabled boolfocused boolint — 该类型的值
write_native_view_slotpub fn write_native_view_slot(id int,generation int,name string,body string) int执行 write native view slot 操作。失败时抛出错误,调用方需处理或继续传播。
id intgeneration intname stringbody stringint — 该类型的值
(&NativeView) write_slotpub fn (view &NativeView) write_slot(name string,body string) int&NativeView 上的操作:执行 write slot 操作。失败时抛出错误,调用方需处理或继续传播。
view &NativeViewNativeView 实例;以只读借用传入,调用方仍持有实例。name stringbody stringint — 该类型的值
native_view_commandpub fn native_view_command(id int,generation int,line string) int原生视图命令。失败时抛出错误,调用方需处理或继续传播。
id intgeneration intline stringint — 该类型的值
(&NativeView) commandpub fn (view &NativeView) command(line string) int&NativeView 上的操作:命令。失败时抛出错误,调用方需处理或继续传播。
view &NativeViewNativeView 实例;以只读借用传入,调用方仍持有实例。line stringint — 该类型的值
($&NativeView) disposepub fn (view $&NativeView) dispose() int释放并清理对象所持有的系统原生资源与底层句柄。失败时抛出错误,调用方需处理或继续传播。
view $&NativeViewNativeView 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
native_view_event_ofpub fn native_view_event_of(event &Event) NativeViewEvent执行 native view event of 操作。失败时抛出错误,调用方需处理或继续传播。
event &EventNativeViewEvent — 该类型的值
(&NativeViewEvent) content_eventpub fn (event &NativeViewEvent) content_event() Event&NativeViewEvent 上的操作:执行 content event 操作。
event &NativeViewEventNativeViewEvent 实例;以只读借用传入,调用方仍持有实例。Event — 该类型的值
const EV_REQUESTpub const EV_REQUEST = 85常量 EV_REQUEST,定义了相关的协议或算法配置参数。
const REQUEST_PROMPTpub const REQUEST_PROMPT = 1常量 REQUEST_PROMPT,定义了相关的协议或算法配置参数。
const REQUEST_CLIPBOARD_READpub const REQUEST_CLIPBOARD_READ = 2常量 REQUEST_CLIPBOARD_READ,定义了相关的协议或算法配置参数。
const REQUEST_CLIPBOARD_WRITEpub const REQUEST_CLIPBOARD_WRITE = 3常量 REQUEST_CLIPBOARD_WRITE,定义了相关的协议或算法配置参数。
const REQUEST_COMPLETEDpub const REQUEST_COMPLETED = 0常量 REQUEST_COMPLETED,定义了相关的协议或算法配置参数。
const REQUEST_CANCELLEDpub const REQUEST_CANCELLED = 1常量 REQUEST_CANCELLED,定义了相关的协议或算法配置参数。
const REQUEST_FAILEDpub const REQUEST_FAILED = 2常量 REQUEST_FAILED,定义了相关的协议或算法配置参数。
const REQUEST_UNSUPPORTEDpub const REQUEST_UNSUPPORTED = 3常量 REQUEST_UNSUPPORTED,定义了相关的协议或算法配置参数。
const REQUEST_TIMED_OUTpub const REQUEST_TIMED_OUT = 4常量 REQUEST_TIMED_OUT,定义了相关的协议或算法配置参数。
struct PromptOptionspub struct PromptOptions {
pub title string
pub seed string
pub timeout_ms int
}Ui 配置参数与选项集合。
title stringseed stringtimeout_ms intstruct RequestOptionspub struct RequestOptions {
pub timeout_ms int
}桌面请求期限;0 使用 5000 ms,显式值范围 1–3600000 ms。
timeout_ms intstruct Requestpub struct Request {
pub id int
pub window_id int
pub canvas_id int
pub generation int
pub kind int
}承载 id、window_id、canvas_id、generation、kind 等属性的结构体。
id intwindow_id intcanvas_id intgeneration intkind intstruct RequestResultpub struct RequestResult {
pub request Request
pub status int
pub value string
}承载 request、status、value 等属性的结构体。
request Requeststatus intvalue stringdefault_canvaspub fn default_canvas() CanvasEvent执行 default canvas 操作。失败时抛出错误,调用方需处理或继续传播。
无需传入参数。
CanvasEvent — 该类型的值
clipboard_read_asyncpub fn clipboard_read_async(target &CanvasEvent, options &RequestOptions) Request执行 clipboard read async 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventoptions &RequestOptionsRequest — 该类型的值
clipboard_write_asyncpub fn clipboard_write_async(target &CanvasEvent, text &string, options &RequestOptions) Request执行 clipboard write async 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventtext &stringoptions &RequestOptionsRequest — 该类型的值
prompt_asyncpub fn prompt_async(target &CanvasEvent, options &PromptOptions) Request执行 prompt async 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventoptions &PromptOptionsRequest — 该类型的值
(&Request) cancelpub fn (request &Request) cancel() bool请求取消,不能撤销已经执行的外部副作用。继续处理请求终态。
request &RequestRequest 实例;以只读借用传入,调用方仍持有实例。是否受理取消;不代表回调已停止
request_ofpub fn request_of(event &Event) RequestResult解码 ev_request 并校验事件字段;用 result.matches 检查请求完整身份。
event &Event终态 RequestResult;无效事件抛出错误
(&RequestResult) matchespub fn (result &RequestResult) matches(request &Request) bool比较请求 ID、窗口、画布、generation 和种类。
result &RequestResultRequestResult 实例;以只读借用传入,调用方仍持有实例。request &Request是否属于同一请求
prompt_waitpub fn prompt_wait(target &CanvasEvent, options &PromptOptions) RequestResult执行 prompt wait 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventoptions &PromptOptionsRequestResult — 该类型的值
const REQUEST_SCREENSpub const REQUEST_SCREENS = 7常量 REQUEST_SCREENS,定义了相关的协议或算法配置参数。
struct ScreenRectpub struct ScreenRect {
pub x f64
pub y f64
pub width f64
pub height f64
}承载 x、y、width、height 等属性的结构体。
x f64y f64width f64height f64struct ScreenInfopub struct ScreenInfo {
pub id string
pub name string
pub bounds ScreenRect
pub work_area ScreenRect
pub scale_x f64
pub scale_y f64
pub primary bool
pub current bool
pub primary_known bool
pub work_area_known bool
pub physical_coordinates bool
}显示器快照;Windows 为物理桌面像素,macOS / GTK 为逻辑桌面坐标。
id stringname stringbounds ScreenRectwork_area ScreenRectscale_x f64scale_y f64primary boolcurrent boolprimary_known boolwork_area_known boolphysical_coordinates bool(&Window) screens_asyncpub fn (window &Window) screens_async(options &RequestOptions) Request异步查询本窗所在桌面的实际屏幕快照,通过 ev_request 完成。
window &WindowWindow 实例;以只读借用传入,调用方仍持有实例。options &RequestOptions已受理的 Request;失败抛出错误
screen_resultpub fn screen_result(result &RequestResult) []ScreenInfo把成功的屏幕查询结果解码为快照;先检查 known 标记,屏幕矩形不能当作画布局部坐标。
result &RequestResult屏幕数组,最多 64 个;无效结果抛出错误
struct TextRangepub struct TextRange {
pub start int
pub end int
}承载 start、end 等属性的结构体。
start intend intclipboard_primary_modifierpub fn clipboard_primary_modifier() int执行 clipboard primary modifier 操作。
无需传入参数。
int — 该类型的值
is_clipboard_modifierpub fn is_clipboard_modifier(modifiers int) bool判断是否 clipboard modifier。
modifiers intbool — 是否成立
struct ClickTrackerpub struct ClickTracker {
}ClickTracker 上下文或状态结构体。
此类型没有公开字段。
click_trackerpub fn click_tracker() ClickTracker执行 click tracker 操作。
无需传入参数。
ClickTracker — 该类型的值
($&ClickTracker) resetpub fn (t $&ClickTracker) reset()$&ClickTracker 上的操作:清空内部状态,可再写入或读取。
t $&ClickTrackerClickTracker 实例;以独占借用传入,方法可修改它,调用方仍持有实例。不返回值。
($&ClickTracker) recordpub fn (t $&ClickTracker) record(event &InputEvent) int在 $&ClickTracker 上执行 record 操作。
t $&ClickTrackerClickTracker 实例;以独占借用传入,方法可修改它,调用方仍持有实例。event &InputEventint — 该类型的值
utf8_clamp_boundarypub fn utf8_clamp_boundary(text &string,index int) int执行 utf8 clamp boundary 操作。
text &stringindex intint — 该类型的值
utf8_prev_charpub fn utf8_prev_char(text &string,index int) int执行 utf8 prev char 操作。
text &stringindex intint — 该类型的值
utf8_next_charpub fn utf8_next_char(text &string,index int) int执行 utf8 next char 操作。
text &stringindex intint — 该类型的值
text_word_rangepub fn text_word_range(text &string,index int) TextRange执行 text word range 操作。
text &stringindex intTextRange — 该类型的值
text_line_rangepub fn text_line_range(text &string,index int) TextRange执行 text line range 操作。
text &stringindex intTextRange — 该类型的值
const EV_TEXT_COMMITpub const EV_TEXT_COMMIT = 86常量 EV_TEXT_COMMIT,定义了相关的协议或算法配置参数。
const EV_TEXT_PREEDITpub const EV_TEXT_PREEDIT = 87常量 EV_TEXT_PREEDIT,定义了相关的协议或算法配置参数。
const EV_TEXT_CANCELpub const EV_TEXT_CANCEL = 88常量 EV_TEXT_CANCEL,定义了相关的协议或算法配置参数。
const EV_TEXT_SELECTIONpub const EV_TEXT_SELECTION = 89常量 EV_TEXT_SELECTION,定义了相关的协议或算法配置参数。
const EV_TEXT_INPUT_READYpub const EV_TEXT_INPUT_READY = 90常量 EV_TEXT_INPUT_READY,定义了相关的协议或算法配置参数。
const EV_TEXT_INPUT_ENDEDpub const EV_TEXT_INPUT_ENDED = 91常量 EV_TEXT_INPUT_ENDED,定义了相关的协议或算法配置参数。
const EV_TEXT_INPUT_FAILEDpub const EV_TEXT_INPUT_FAILED = 92常量 EV_TEXT_INPUT_FAILED,定义了相关的协议或算法配置参数。
const EV_TEXT_SURROUNDING_DELETEpub const EV_TEXT_SURROUNDING_DELETE = 93常量 EV_TEXT_SURROUNDING_DELETE,定义了相关的协议或算法配置参数。
const TEXT_INPUT_STOPPEDpub const TEXT_INPUT_STOPPED = 0常量 TEXT_INPUT_STOPPED,定义了相关的协议或算法配置参数。
const TEXT_INPUT_WINDOW_CLOSEDpub const TEXT_INPUT_WINDOW_CLOSED = 1常量 TEXT_INPUT_WINDOW_CLOSED,定义了相关的协议或算法配置参数。
const TEXT_INPUT_BACKPRESSUREpub const TEXT_INPUT_BACKPRESSURE = 2常量 TEXT_INPUT_BACKPRESSURE,定义了相关的协议或算法配置参数。
const TEXT_INPUT_UNAVAILABLEpub const TEXT_INPUT_UNAVAILABLE = 3常量 TEXT_INPUT_UNAVAILABLE,定义了相关的协议或算法配置参数。
const TEXT_INPUT_ACTIVATION_TIMEOUTpub const TEXT_INPUT_ACTIVATION_TIMEOUT = 4常量 TEXT_INPUT_ACTIVATION_TIMEOUT,定义了相关的协议或算法配置参数。
const KEYBOARD_DEFAULTpub const KEYBOARD_DEFAULT = 0常量 KEYBOARD_DEFAULT,定义了相关的协议或算法配置参数。
const KEYBOARD_EMAILpub const KEYBOARD_EMAIL = 1常量 KEYBOARD_EMAIL,定义了相关的协议或算法配置参数。
const KEYBOARD_URLpub const KEYBOARD_URL = 2常量 KEYBOARD_URL,定义了相关的协议或算法配置参数。
const KEYBOARD_NUMBERpub const KEYBOARD_NUMBER = 3常量 KEYBOARD_NUMBER,定义了相关的协议或算法配置参数。
const KEYBOARD_DECIMALpub const KEYBOARD_DECIMAL = 4常量 KEYBOARD_DECIMAL,定义了相关的协议或算法配置参数。
const KEYBOARD_PHONEpub const KEYBOARD_PHONE = 5常量 KEYBOARD_PHONE,定义了相关的协议或算法配置参数。
const KEYBOARD_SEARCHpub const KEYBOARD_SEARCH = 6常量 KEYBOARD_SEARCH,定义了相关的协议或算法配置参数。
const RETURN_DEFAULTpub const RETURN_DEFAULT = 0常量 RETURN_DEFAULT,定义了相关的协议或算法配置参数。
const RETURN_DONEpub const RETURN_DONE = 1常量 RETURN_DONE,定义了相关的协议或算法配置参数。
const RETURN_GOpub const RETURN_GO = 2常量 RETURN_GO,定义了相关的协议或算法配置参数。
const RETURN_NEXTpub const RETURN_NEXT = 3常量 RETURN_NEXT,定义了相关的协议或算法配置参数。
const RETURN_SEARCHpub const RETURN_SEARCH = 4常量 RETURN_SEARCH,定义了相关的协议或算法配置参数。
const RETURN_SENDpub const RETURN_SEND = 5常量 RETURN_SEND,定义了相关的协议或算法配置参数。
struct TextInputRectpub struct TextInputRect {
pub x f64
pub y f64
pub width f64
pub height f64
}承载 x、y、width、height 等属性的结构体。
x f64y f64width f64height f64struct TextInputOptionspub struct TextInputOptions {
pub value string
pub anchor int
pub focus int
pub caret TextInputRect
pub multiline bool
pub password bool
pub keyboard_type int
pub return_key int
}Ui 配置参数与选项集合。
value stringanchor intfocus intcaret TextInputRectmultiline boolpassword boolkeyboard_type intreturn_key intstruct TextInputpub struct TextInput {
pub id int
pub window_id int
pub canvas_id int
pub generation int
}承载 id、window_id、canvas_id、generation 等属性的结构体。
id intwindow_id intcanvas_id intgeneration intstruct TextInputStatepub struct TextInputState {
pub input TextInput
pub revision int
pub ready bool
pub multiline bool
pub value string
pub anchor int
pub focus int
pub composing bool
pub preedit string
pub replacement_start int
pub replacement_end int
pub preedit_anchor int
pub preedit_focus int
pub caret TextInputRect
}承载 input、revision、ready、multiline、value 等属性的结构体。
input TextInputrevision intready boolmultiline boolvalue stringanchor intfocus intcomposing boolpreedit stringreplacement_start intreplacement_end intpreedit_anchor intpreedit_focus intcaret TextInputRectstruct TextEditEventpub struct TextEditEvent {
pub input TextInput
pub kind int
pub revision int
pub start int
pub end int
pub anchor int
pub focus int
pub reason int
pub value string
}承载 input、kind、revision、start、end 等属性的结构体。
input TextInputkind intrevision intstart intend intanchor intfocus intreason intvalue stringtext_input_optionspub fn text_input_options(value &string, caret TextInputRect) TextInputOptions执行 text input options 操作。
value &stringcaret TextInputRectTextInputOptions — 该类型的值
start_text_inputpub fn start_text_input(canvas int, generation int, options &TextInputOptions) TextInput执行 start text input 操作。失败时抛出错误,调用方需处理或继续传播。
canvas intgeneration intoptions &TextInputOptionsTextInput — 该类型的值
(&TextInput) snapshotpub fn (input &TextInput) snapshot() TextInputState在 &TextInput 上执行 snapshot 操作。失败时抛出错误,调用方需处理或继续传播。
input &TextInputTextInput 实例;以只读借用传入,调用方仍持有实例。TextInputState — 该类型的值
(&TextInput) updatepub fn (input &TextInput) update(revision int, value &string, anchor int, focus int, caret &TextInputRect) TextInputState&TextInput 上的操作:更新。失败时抛出错误,调用方需处理或继续传播。
input &TextInputTextInput 实例;以只读借用传入,调用方仍持有实例。revision intvalue &stringanchor intfocus intcaret &TextInputRectTextInputState — 该类型的值
($&TextInput) stoppub fn (input $&TextInput) stop() int$&TextInput 上的操作:停止。失败时抛出错误,调用方需处理或继续传播。
input $&TextInputTextInput 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
(&TextInputState) display_valuepub fn (state &TextInputState) display_value() string&TextInputState 上的操作:执行 display value 操作。
state &TextInputStateTextInputState 实例;以只读借用传入,调用方仍持有实例。string — 结果字符串
(&TextInputState) display_anchorpub fn (state &TextInputState) display_anchor() int&TextInputState 上的操作:执行 display anchor 操作。
state &TextInputStateTextInputState 实例;以只读借用传入,调用方仍持有实例。int — 该类型的值
(&TextInputState) display_focuspub fn (state &TextInputState) display_focus() int&TextInputState 上的操作:执行 display focus 操作。
state &TextInputStateTextInputState 实例;以只读借用传入,调用方仍持有实例。int — 该类型的值
text_edit_ofpub fn text_edit_of(event &Event) TextEditEvent执行 text edit of 操作。失败时抛出错误,调用方需处理或继续传播。
event &EventTextEditEvent — 该类型的值
struct TextInputTransformpub struct TextInputTransform {
pub a f64
pub b f64
pub c f64
pub d f64
pub tx f64
pub ty f64
}承载 a、b、c、d、tx 等属性的结构体。
a f64b f64c f64d f64tx f64ty f64text_input_translationpub fn text_input_translation(x f64, y f64) TextInputTransform执行 text input translation 操作。
x f64y f64TextInputTransform — 该类型的值
struct TextInputGeometrypub struct TextInputGeometry {
pub index int
pub length int
pub trailing bool
pub inside bool
pub rect TextInputRect
}承载 index、length、trailing、inside、rect 等属性的结构体。
index intlength inttrailing boolinside boolrect TextInputRect(&TextInputGeometry) byte_indexpub fn (hit &TextInputGeometry) byte_index() int&TextInputGeometry 上的操作:执行 byte index 操作。
hit &TextInputGeometryTextInputGeometry 实例;以只读借用传入,调用方仍持有实例。int — 索引值;有效范围和特殊值见用途说明
(&TextInput) bind_layout_handlepub fn (input &TextInput) bind_layout_handle(layout int, revision int, transform &TextInputTransform, upstream bool) int&TextInput 上的操作:执行 bind layout handle 操作。失败时抛出错误,调用方需处理或继续传播。
input &TextInputTextInput 实例;以只读借用传入,调用方仍持有实例。layout intrevision inttransform &TextInputTransformupstream boolint — 该类型的值
(&TextInput) unbind_layoutpub fn (input &TextInput) unbind_layout(revision int) int&TextInput 上的操作:执行 unbind layout 操作。失败时抛出错误,调用方需处理或继续传播。
input &TextInputTextInput 实例;以只读借用传入,调用方仍持有实例。revision intint — 该类型的值
(&TextInput) hit_testpub fn (input &TextInput) hit_test(revision int, x f64, y f64) TextInputGeometry&TextInput 上的操作:执行 hit test 操作。失败时抛出错误,调用方需处理或继续传播。
input &TextInputTextInput 实例;以只读借用传入,调用方仍持有实例。revision intx f64y f64TextInputGeometry — 该类型的值
(&TextInput) caretpub fn (input &TextInput) caret(revision int, index int, trailing bool) TextInputGeometry在 &TextInput 上执行 caret 操作。失败时抛出错误,调用方需处理或继续传播。
input &TextInputTextInput 实例;以只读借用传入,调用方仍持有实例。revision intindex inttrailing boolTextInputGeometry — 该类型的值
(&TextInput) character_rectpub fn (input &TextInput) character_rect(revision int, index int) TextInputGeometry&TextInput 上的操作:执行 character rect 操作。失败时抛出错误,调用方需处理或继续传播。
input &TextInputTextInput 实例;以只读借用传入,调用方仍持有实例。revision intindex intTextInputGeometry — 该类型的值
const REQUEST_WEBVIEW_EVALpub const REQUEST_WEBVIEW_EVAL = 8常量 REQUEST_WEBVIEW_EVAL,定义了相关的协议或算法配置参数。
const REQUEST_WEBVIEW_FINDpub const REQUEST_WEBVIEW_FIND = 9常量 REQUEST_WEBVIEW_FIND,定义了相关的协议或算法配置参数。
const REQUEST_WEBVIEW_COOKIES_GETpub const REQUEST_WEBVIEW_COOKIES_GET = 10常量 REQUEST_WEBVIEW_COOKIES_GET,定义了相关的协议或算法配置参数。
const REQUEST_WEBVIEW_COOKIE_SETpub const REQUEST_WEBVIEW_COOKIE_SET = 11常量 REQUEST_WEBVIEW_COOKIE_SET,定义了相关的协议或算法配置参数。
const REQUEST_WEBVIEW_COOKIES_CLEARpub const REQUEST_WEBVIEW_COOKIES_CLEAR = 12常量 REQUEST_WEBVIEW_COOKIES_CLEAR,定义了相关的协议或算法配置参数。
webview_request_asyncpub fn webview_request_async(target &CanvasEvent,kind int,value &string,options &RequestOptions) Request执行 webview request async 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventkind intvalue &stringoptions &RequestOptionsRequest — 该类型的值
webview_request_waitpub fn webview_request_wait(target &CanvasEvent,kind int,value &string,options &RequestOptions) RequestResult执行 webview request wait 操作。失败时抛出错误,调用方需处理或继续传播。
target &CanvasEventkind intvalue &stringoptions &RequestOptionsRequestResult — 该类型的值
($&App) open_windowpub fn (a $&App) open_window(opts WindowOpts) Window$&App 上的操作:执行 open window 操作。失败时抛出错误,调用方需处理或继续传播。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。opts WindowOptsWindow — 该类型的值
($&App) open_content_windowpub fn (a $&App) open_content_window(opts WindowOpts,kind int) Window$&App 上的操作:执行 open content window 操作。失败时抛出错误,调用方需处理或继续传播。
a $&AppApp 实例;以独占借用传入,方法可修改它,调用方仍持有实例。opts WindowOptskind intWindow — 该类型的值
open_host_content_windowpub fn open_host_content_window(opts WindowOpts,kind int) Window执行 open host content window 操作。失败时抛出错误,调用方需处理或继续传播。
opts WindowOptskind intWindow — 该类型的值
(&Window) commandpub fn (w &Window) command(line string) int&Window 上的操作:命令。失败时抛出错误,调用方需处理或继续传播。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。line stringint — 该类型的值
(&Window) content_commandpub fn (w &Window) content_command(line string) int&Window 上的操作:执行 content command 操作。失败时抛出错误,调用方需处理或继续传播。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。line stringint — 该类型的值
($&Window) bind_contentpub fn (w $&Window) bind_content(kind int,backend_id int) int$&Window 上的操作:执行 bind content 操作。失败时抛出错误,调用方需处理或继续传播。
w $&WindowWindow 实例;以独占借用传入,方法可修改它,调用方仍持有实例。kind intbackend_id intint — 该类型的值
(&Window) showpub fn (w &Window) show() int在 &Window 上执行 show 操作。失败时抛出错误,调用方需处理或继续传播。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。int — 该类型的值
(&Window) hidepub fn (w &Window) hide() int在 &Window 上执行 hide 操作。失败时抛出错误,调用方需处理或继续传播。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。int — 该类型的值
(&Window) focuspub fn (w &Window) focus() int在 &Window 上执行 focus 操作。失败时抛出错误,调用方需处理或继续传播。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。int — 该类型的值
($&Window) resizepub fn (w $&Window) resize(width int,height int) int在 $&Window 上执行 resize 操作。失败时抛出错误,调用方需处理或继续传播。
w $&WindowWindow 实例;以独占借用传入,方法可修改它,调用方仍持有实例。width intheight intint — 该类型的值
($&Window) request_closepub fn (w $&Window) request_close() int$&Window 上的操作:关闭请求。失败时抛出错误,调用方需处理或继续传播。
w $&WindowWindow 实例;以独占借用传入,方法可修改它,调用方仍持有实例。int — 该类型的值
write_window_slotpub fn write_window_slot(id int,generation int,name string,body string) int执行 write window slot 操作。失败时抛出错误,调用方需处理或继续传播。
id intgeneration intname stringbody stringint — 该类型的值
(&Window) write_slotpub fn (w &Window) write_slot(name string,body string) int&Window 上的操作:执行 write slot 操作。失败时抛出错误,调用方需处理或继续传播。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。name stringbody stringint — 该类型的值
(&Window) is_openpub fn (w &Window) is_open() bool&Window 上的操作:判断是否 open。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。bool — 是否成立
(&Window) is_readypub fn (w &Window) is_ready() bool&Window 上的操作:判断是否 ready。
w &WindowWindow 实例;以只读借用传入,调用方仍持有实例。bool — 是否成立