fma
pub fn fma(x f64, y f64, z f64) f64Purpose
Compute fused multiply-add (x * y + z).
Parameters
xf64- value (f64)
yf64- value (f64)
zf64- z (f64)
Returns
f64 — a value of this type
#mathXu 0.11.3 rounding preserves already-integral binary64 values near 252, signed zero and non-finite inputs. round rounds ties away from zero; round_to_even resolves ties to an even integer. log(±0) returns negative infinity, log(+Inf) returns positive infinity, and frexp returns zero, infinity or NaN in its fraction with exponent zero. These boundary repairs do not establish accuracy guarantees for every finite transcendental approximation.
float16_to_f32 · Xu 0.14.1pub fn float16_to_f32(h int) f32
Use #math to convert the IEEE 754 binary16 bit pattern in the low 16 bits of h to f32. The conversion handles normal and subnormal values, signed zero, infinities, and NaNs. For example, math.float16_to_f32(0x3e00) returns 1.5. Available since Xu 0.14.1. See the local inference guide for the related APIs.
These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.
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/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}}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}}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/widgets
#time
#math
// Each control ID has one owner-specific handler. No page-number update switch.
fn register_events(m &Workshop, s &widgets.Screen) widgets.ActionDispatcher#Workshop, widgets.Screen, widgets.Action{
$d := widgets.action_dispatcher(m, s)
for page in m.pages{for id in page.ids{d.on_any(id, sample_action) >>> }}
d.on(m.navigation, widgets.ACTION_CHANGE, navigate) >>>
d.on(m.language, widgets.ACTION_CHANGE, language_changed) >>>
for id in[m.theme, m.density, m.scale, m.reduced] {d.on(id, widgets.ACTION_CHANGE, appearance_changed) >>> }
d.on(m.state, widgets.ACTION_CHANGE, state_changed) >>>
d.on(m.custom, widgets.ACTION_ACTIVATE, custom_clicked) >>>
d.on(m.motion, widgets.ACTION_ACTIVATE, motion_clicked) >>>
d.on(m.focus, widgets.ACTION_ACTIVATE, focus_clicked) >>>
for id in m.tools{d.on(id, widgets.ACTION_ACTIVATE, tool_clicked) >>> }
for i in 0:4 {d.on(m.pages[1].ids[9 + i], widgets.ACTION_CHANGE, appearance_changed) >>> }
d.on(m.pages[7].ids[1], widgets.ACTION_CHANGE, tree_filter_changed) >>>
d.on(m.pages[7].ids[0], widgets.ACTION_ITEM_ACTION, node_action) >>>
d.on(m.pages[8].ids[0], widgets.ACTION_ACTIVATE, task_clicked) >>>
for kind in[widgets.ACTION_CHANGE, widgets.ACTION_COMMIT] {
d.on(m.pages[13].ids[0], kind, slider_changed) >>>
d.on(m.pages[20].ids[0], kind, color_changed) >>>
d.on(m.pages[40].ids[0], kind, range_changed) >>>
}
d.on(m.pages[17].ids[1], widgets.ACTION_CHANGE, multi_filter_changed) >>>
d.on(m.pages[24].ids[0], widgets.ACTION_ACTIVATE, table_sorted) >>>
d.on(m.pages[25].ids[0], widgets.ACTION_CHANGE, pagination_changed) >>>
d.on(m.pages[25].ids[2], widgets.ACTION_CHANGE, page_size_changed) >>>
for kind in[widgets.ACTION_SUBMIT, widgets.ACTION_COMMIT] {d.on(m.pages[25].ids[1], kind, page_submitted) >>> }
d.on(m.pages[25].ids[4], widgets.ACTION_ACTIVATE, page_submitted) >>>
d.on(m.pages[30].ids[1], widgets.ACTION_ACTIVATE, inbox_clicked) >>>
d.on(m.pages[30].ids[2], widgets.ACTION_ACTIVATE, online_clicked) >>>
d.on(m.pages[33].ids[0], widgets.ACTION_ACTIVATE, preferences_open) >>>
d.on(m.pages[33].ids[6], widgets.ACTION_ACTIVATE, preferences_cancel) >>>
d.on(m.pages[33].ids[7], widgets.ACTION_ACTIVATE, preferences_apply) >>>
d.on(m.pages[35].ids[0], widgets.ACTION_ACTIVATE, notice_clicked) >>>
d.on(m.pages[36].ids[0], widgets.ACTION_ACTIVATE, modal_open) >>>
for i in 2:4 {d.on(m.pages[36].ids[i], widgets.ACTION_ACTIVATE, modal_close) >>> }
for id in m.pages[38].ids{for kind in[widgets.ACTION_ACTIVATE, widgets.ACTION_CHANGE] {d.on(id, kind, group_changed) >>> }}
for r in 1:7 {d.on(m.pages[39].ids[r], widgets.ACTION_CHANGE, chart_kind_changed) >>> }
for kind in[widgets.ACTION_CHART_HOVER, widgets.ACTION_CHART_SELECT] {d.on(m.pages[39].ids[0], kind, chart_hit) >>> }
d.on(m.pages[39].ids[0], widgets.ACTION_CHART_VIEWPORT, chart_viewport_changed) >>>
d.on(m.pages[41].ids[0], widgets.ACTION_COMMIT, split_committed) >>>
for page in 42:45 {for kind in[widgets.ACTION_ACTIVATE, widgets.ACTION_CHANGE] {d.on(m.pages[page].ids[0], kind, menu_action) >>> }}
d.on(m.pages[45].ids[1], widgets.ACTION_CHANGE, password_visibility_changed) >>>
for kind in[widgets.ACTION_WEB_LOADING, widgets.ACTION_WEB_LOADED, widgets.ACTION_WEB_FAILED, widgets.ACTION_WEB_PROGRESS] {
d.on(m.pages[37].ids[0], kind, webview_changed) >>>
}
<< d
}
fn register_notice_events(s &widgets.Screen, d $&widgets.ActionDispatcher#Workshop, widgets.Screen, widgets.Action) int {
for id in s.notice_ids() {d.on(id, widgets.ACTION_NOTICE_ACTION, notice_action) >>> }
<< 0
}
// Adapters catch Xu errors before crossing the function-value ABI.
fn sample_action(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
sample_action_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn navigate(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
navigate_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn language_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
language_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn appearance_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
appearance_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn custom_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
custom_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn motion_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
motion_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn focus_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
focus_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn tree_filter_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
tree_filter_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn multi_filter_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
multi_filter_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn slider_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
slider_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn color_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
color_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn pagination_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
pagination_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn page_size_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
page_size_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn page_submitted(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
page_submitted_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn task_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
task_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn inbox_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
inbox_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn online_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
online_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn preferences_open(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
preferences_open_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn preferences_cancel(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
preferences_cancel_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn preferences_apply(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
preferences_apply_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn notice_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
notice_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn notice_action(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
notice_action_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn modal_open(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
modal_open_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn modal_close(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
modal_close_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn group_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
group_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn chart_kind_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
chart_kind_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn chart_hit(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
chart_hit_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn chart_viewport_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
chart_viewport_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn range_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
range_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn split_committed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
split_committed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn menu_action(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
menu_action_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn password_visibility_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
password_visibility_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn table_sorted(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
table_sorted_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn node_action(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
node_action_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn webview_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
webview_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn state_changed(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
state_changed_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn sample_action_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
if a.kind == widgets.ACTION_COMMIT{s.set_text(m.status, "Committed value · " + str(int(a.value))) >>> }
if a.kind == widgets.ACTION_ACTIVATE{s.set_text(m.status, "Activated / 已激活 · control " + str(a.id)) >>> }
<< 0
}
fn navigate_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
old := m.page_snapshot(m.selected)
if m.selected == 33 || m.selected == 36 {s.close_overlay(old.ids[1]) >>> }
m.controls_dirty = true
m.selected = s.selected(m.navigation) >>>
s.set_scroll_offset(m.preview, 0.0) >>>
m.appearance_dirty = true
<< 0
}
fn language_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int { << m.apply_locale(s) >>> }
fn appearance_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {m.appearance_dirty = true
<< 0}
fn custom_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {m.customized = !m.customized
m.controls_dirty = true
m.appearance_dirty = true
<< 0}
fn motion_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {m.slow = !m.slow
m.controls_dirty = true
m.appearance_dirty = true
<< 0}
fn focus_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
page := m.page_snapshot(m.selected)
$target := page.ids[0]
if m.selected == 31 {target = page.ids[6]}
s.focus(target) >>>
<< 0
}
fn tree_filter_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
s.set_tree_filter(m.pages[7].ids[0], s.text_value(a.id) >>>) >>>
<< 0
}
fn multi_filter_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
s.set_multi_filter(m.pages[17].ids[0], s.text_value(a.id) >>>) >>>
<< 0
}
fn slider_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
s.set_value(m.pages[13].ids[1], str(int(a.value))) >>>
<< sample_action_update(m, s, a) >>>
}
fn color_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
s.set_value(m.pages[20].ids[1], s.color_hex(a.id) >>>) >>>
s.set_field_invalid(m.pages[20].ids[1], false) >>>
<< sample_action_update(m, s, a) >>>
}
fn pagination_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int { << m.update_pagination(s, true) >>> }
fn page_size_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
page := m.page_snapshot(25)
data := s.pagination_data(page.ids[0]) >>>
sizes :=[10, 20, 50, 100]
s.set_pagination_data(page.ids[0], max_int_local(0, data.total), sizes[s.selected(a.id) >>>]) >>>
<< m.update_pagination(s, true) >>>
}
fn page_submitted_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int { << tool_25_update(m, s, 0) >>> }
fn task_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
if m.running{ << 0}
m.revision += 1
m.completed = 0
m.checksum = 0
m.running = true
m.deadline = time.instant()
s.begin_task(a.id, m.revision) >>>
<< 0
}
fn inbox_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {m.unread = 0
<< m.update_badges(s) >>> }
fn online_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {m.online = !m.online
<< m.update_badges(s) >>> }
fn preferences_open_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int { << m.open_preferences(s) >>> }
fn preferences_cancel_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.close_overlay(m.pages[33].ids[1]) >>>
<< 0}
fn preferences_apply_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
page := m.page_snapshot(33)
name := s.text_value(page.ids[4]) >>>
if name.len == 0 {s.set_field_invalid(page.ids[4], true) >>>
<< 0}
s.set_field_invalid(page.ids[4], false) >>>
$history := "off"
if s.toggle_value(page.ids[5]) >>> {history = "on"}
m.preferences_name = name
m.preferences_history = s.toggle_value(page.ids[5]) >>>
s.set_text(page.ids[8], "Current: " + m.preferences_name + " · history " + history) >>>
s.close_overlay(page.ids[1]) >>>
<< 0
}
fn notice_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int { << tool_35_update(m, s, 0) >>> }
fn notice_action_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.set_text(m.status, "Undo requested · business state can now be restored.") >>>
<< 0}
fn modal_open_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.open(m.pages[36].ids[1]) >>>
<< 0}
fn modal_close_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.close_overlay(m.pages[36].ids[1]) >>>
<< 0}
fn group_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
values := s.button_group_values(a.id) >>>
s.set_text(m.status, "ButtonGroup · key " + str(int(a.value)) + " · selected " + str(values.len)) >>>
<< 0
}
fn chart_kind_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
m.controls_dirty = true
m.chart_kind = int(a.value) - 1
english := (s.selected(m.language) >>>) == 1
series := chart_data_locale(m.chart_kind, m.revision, english)
s.set_chart_series(m.pages[39].ids[0], &series) >>>
s.reset_chart_viewport(m.pages[39].ids[0]) >>>
m.appearance_dirty = true
<< 0
}
fn chart_hit_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
$hit := s.chart_hovered(a.id) >>>
if a.kind == widgets.ACTION_CHART_SELECT{hit = s.chart_selection(a.id) >>> }
if hit.valid{s.set_text(m.status, "Series " + str(hit.series_id) + " / point " + str(hit.point_id) + " · " + str(int(hit.y))) >>> }
<< 0
}
fn chart_viewport_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.set_text(m.status, "Viewport updated · Double click / Home to reset") >>>
<< 0}
fn range_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int { << m.range_summary(s, a.kind == widgets.ACTION_COMMIT) >>> }
fn split_committed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.set_text(m.status, "Split ratio / 分栏比例 · " + str(int(math.round(a.value * 100.0))) + "%") >>>
<< 0}
fn menu_action_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
for index in 42:45 {page := m.page_snapshot(index)
if page.ids[0] == a.id{s.set_text(page.ids[1], "Action / 操作 · " + str(int(a.value))) >>> }}
<< 0
}
fn password_visibility_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.set_password_visible(m.pages[45].ids[0], s.toggle_value(a.id) >>>) >>>
<< 0}
fn table_sorted_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
$direction := "ascending / 升序"
if s.sort_descending(a.id) >>> {direction = "descending / 降序"}
selected := s.table_selected_row(a.id) >>>
s.set_text(m.status, "Sorted / 已排序 · " + direction + " · source row " + str(selected)) >>>
<< 0
}
fn node_action_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {s.set_text(m.status, "Node action · " + str(int(a.value))) >>>
<< 0}
fn webview_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
if m.selected != 37 { << 0}s.set_text(m.status, "WebView · event " + str(a.kind) + " · " + str(int(a.value))) >>>
<< 0}
fn state_changed_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
m.controls_dirty = true
<< 0
}@main
#ui/widgets
#ui/webview
#time
#math
#errors
#strconv
fn tool_0_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(0)
id := page.ids[0]
$text := "精密 · 清晰 · 可靠。"
if option == 0 {text = "长中文:输入、选择、复制与原生排版保持一致。Long English text wraps inside its content width. Family 👨👩👧👦 and developer 👩🏽💻 remain intact."}
s.set_text(id, text) >>>
<< 0
}
fn tool_1_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(1)
id := page.ids[0]
s.set_selected_button(id, option == 0) >>>
<< 0
}
fn tool_2_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(2)
id := page.ids[0]
s.set_selected_button(id, option == 0) >>>
<< 0
}
fn tool_3_update(m $&Workshop, s $&widgets.Screen, option int) int {
index := 3
page := m.page_snapshot(3)
id := page.ids[0]
if option == 0 {s.set_value(id, "") >>> }
if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽💻 🙂 abcdefghijklmnopqrstuvwxyz"
if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
s.set_value(id, value) >>> }
<< 0
}
fn tool_4_update(m $&Workshop, s $&widgets.Screen, option int) int {
index := 4
page := m.page_snapshot(4)
id := page.ids[0]
if option == 0 {s.set_value(id, "") >>> }
if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽💻 🙂 abcdefghijklmnopqrstuvwxyz"
if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
s.set_value(id, value) >>> }
<< 0
}
fn tool_5_update(m $&Workshop, s $&widgets.Screen, option int) int {
index := 5
page := m.page_snapshot(5)
id := page.ids[0]
if option == 0 {s.set_value(id, "") >>> }
if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽💻 🙂 abcdefghijklmnopqrstuvwxyz"
if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
s.set_value(id, value) >>> }
if option == 2 && index >= 5 {m.field_options_dirty = true
m.field_options_page = index
m.variant += 1}
<< 0
}
fn tool_6_update(m $&Workshop, s $&widgets.Screen, option int) int {
index := 6
page := m.page_snapshot(6)
id := page.ids[0]
if option == 0 {s.set_value(id, "") >>> }
if option == 1 {$value := "Long text · 很长的中文与 English · 👩🏽💻 🙂 abcdefghijklmnopqrstuvwxyz"
if index == 4 || index == 6 {value = value + "\n第二行\n第三行\n第四行\n第五行\n第六行\n第七行:内部滚动"}
s.set_value(id, value) >>> }
if option == 2 && index >= 5 {m.field_options_dirty = true
m.field_options_page = index
m.variant += 1}
<< 0
}
fn tool_7_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(7)
id := page.ids[0]
if option == 0 {m.guided = !m.guided
m.tree_options_dirty = true}
if option == 1 {s.set_selected(id, 7) >>>
s.focus(id) >>> }
if option == 2 {s.set_value(page.ids[1], "") >>>
s.set_tree_filter(id, "") >>> }
<< 0
}
fn tool_8_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(8)
id := page.ids[0]
if option == 0 {m.variant += 1
s.set_task_progress_mode(id, m.variant % 3) >>> }
if option == 1 {m.failure = !m.failure
s.set_selected_button(m.tools[1], m.failure) >>> }
if option == 2 && m.running{_ := s.complete_task(id, m.revision, widgets.TASK_CANCELLED) >>>
m.running = false}
<< 0
}
fn tool_9_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(9)
id := page.ids[0]
s.set_checkbox_indeterminate(id, option == 0) >>>
if option > 0 {s.set_toggle_value(id, option == 1) >>> }
<< 0
}
fn tool_10_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(10)
id := page.ids[0]
if option == 0 {m.pending_before = s.toggle_value(id) >>>
s.set_switch_pending(id, true) >>>
s.set_text(id, "Live preview · Saving…") >>> }
else {s.set_switch_pending(id, false) >>>
s.set_toggle_value(id, option == 1 || m.pending_before) >>>
s.set_invalid(id, option == 2) >>>
s.set_text(id, "Live preview 实时预览") >>> }
<< 0
}
fn tool_11_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(11)
id := page.ids[0]
s.set_toggle_value(id, option == 0) >>>
<< 0
}
fn tool_13_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(13)
id := page.ids[0]
if option > 0 {s.set_slider_commit_only(id, option == 1) >>> }
else {text := s.text_value(page.ids[1]) >>>
value := strconv.parse_float(&text) >>> (err) {s.set_field_invalid(page.ids[1], true) >>>
<< 0}
if math.is_nan(value) || math.is_inf(value) || value < 0.0 || value > 100.0 {s.set_field_invalid(page.ids[1], true) >>>
<< 0}
s.set_number_value(id, value) >>>
s.set_field_invalid(page.ids[1], false) >>> }
<< 0
}
fn tool_15_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(15)
id := page.ids[0]
if option == 0 {s.set_candidate_open(id, true) >>> }
else {s.set_select_option_enabled(id, 2, false) >>> }
<< 0
}
fn tool_16_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(16)
id := page.ids[0]
if option < 2 {s.set_combo_custom_values(id, option == 0) >>> }
else {s.set_value(id, "") >>> }
<< 0
}
fn tool_17_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(17)
id := page.ids[0]
s.select_all(id, option == 0) >>>
<< 0
}
fn tool_18_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(18)
id := page.ids[0]
if option == 0 {s.clear_calendar(id) >>> }
else {value := time.date(2026, 10, 25, 0, 0, 0, 0)
s.set_calendar_value(id, value) >>> }
<< 0
}
fn tool_19_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(19)
id := page.ids[0]
s.set_clock_format(id, option == 0, option != 2) >>>
<< 0
}
fn tool_20_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(20)
id := page.ids[0]
$value := "#B4392DFF"
if option == 0 {value = s.text_value(page.ids[1]) >>> }
if option == 2 {value = "#3279A080"}
s.set_color_hex(id, value) >>> (err) {s.set_field_invalid(page.ids[1], true) >>>
s.set_text(m.status, err.msg()) >>>
<< 0}
s.set_field_invalid(page.ids[1], false) >>>
s.remember_color(id) >>>
s.set_value(page.ids[1], s.color_hex(id) >>>) >>>
<< 0
}
fn tool_24_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(24)
id := page.ids[0]
s.set_table_status(id,["", "Loading workspace… 正在加载", "Unable to load. Retry when ready."][option]) >>>
<< 0
}
fn tool_25_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(25)
id := page.ids[0]
sizes :=[10, 20, 50, 100]
size := sizes[s.selected(page.ids[2]) >>>]
data := s.pagination_data(id) >>>
if option == 2 {if data.total == 0 {s.set_pagination_data(id, 20000, size) >>> }
else {s.set_pagination_data(id, 0, size) >>> }}
else {
if data.pages == 0 {m.pagination_invalid(s) >>>
<< 0}
current := s.pagination_data(id) >>>
$number := current.pages
if option == 0 {text := s.text_value(page.ids[1]) >>>
number = strconv.atoi(&text) >>> (err) {m.pagination_invalid(s) >>>
<< 0}
if number < 1 || number > current.pages{m.pagination_invalid(s) >>>
<< 0}}
s.set_selected(id, number - 1) >>>
s.set_field_invalid(page.ids[1], false) >>>
}
m.update_pagination(s, true) >>>
<< 0
}
fn tool_27_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(27)
id := page.ids[0]
s.set_number_value(id,[0.0, 0.42, 1.0][option]) >>>
<< 0
}
fn tool_28_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(28)
id := page.ids[0]
if option < 2 {s.set_running(id, option == 0) >>> }
else {m.spinner_options_dirty = true}
<< 0
}
fn tool_30_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(30)
id := page.ids[0]
if option == 0 {m.unread += 1}
if option == 1 {m.unread = 0}
if option == 2 {m.unread = 123}
m.update_badges(s) >>>
<< 0
}
fn tool_32_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(32)
id := page.ids[0]
if option == 0 {s.set_scroll_offset(id, 0.0) >>> }
if option == 1 {s.set_scroll_offset(id, 100000.0) >>> }
if option == 2 {s.focus(page.ids[page.ids.len - 1]) >>> }
<< 0
}
fn tool_33_update(m $&Workshop, s $&widgets.Screen, option int) int {
index := 33
page := m.page_snapshot(33)
id := page.ids[0]
if option == 2 {m.variant =(m.variant + 1) % 4
m.popover_options_dirty = true}
if option == 0 {if index == 33 {m.open_preferences(s) >>> } else {s.open(page.ids[1]) >>> }}
else if option == 1 {s.close_overlay(page.ids[1]) >>> }
<< 0
}
fn tool_34_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(34)
id := page.ids[0]
if option == 2 {m.tooltip_side =(m.tooltip_side + 1) % 4
m.appearance_dirty = true
s.focus(id) >>>
s.set_text(m.status, "Tooltip · " +["Bottom 下", "Top 上", "Left 左", "Right 右"][m.tooltip_side] + " · flips at the viewport edge") >>> }
if option == 0 {s.focus(id) >>> }
else if option == 1 {s.focus(0) >>> }
<< 0
}
fn tool_35_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(35)
id := page.ids[0]
$notice := widgets.notice(&"Workspace saved · 工作区已保存")
notice.action = "Undo"
notice.key = "workspace-save"
if option == 1 {notice.text = "Changes restored · 已撤销"
notice.key = "workspace-undo"}
$count := 1
if option == 2 {count = 3}
for i in 0:count{if count > 1 {notice.key = "notice-" + str(i)
notice.text = "Queued notice " + str(i + 1)}
_ := s.enqueue_notice(¬ice) >>> }
<< 0
}
fn tool_36_update(m $&Workshop, s $&widgets.Screen, option int) int {
index := 36
page := m.page_snapshot(36)
id := page.ids[0]
if option == 0 {if index == 33 {m.open_preferences(s) >>> } else {s.open(page.ids[1]) >>> }}
else if option == 1 {s.close_overlay(page.ids[1]) >>> }
<< 0
}
fn tool_37_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(37)
id := page.ids[0]
if option == 0 {native := s.webview_native(id) >>>
client := webview.bind_native(&native) >>>
client.command("reload") >>> }
else {s.set_visible(id, option == 2) >>> }
<< 0
}
fn tool_38_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(38)
id := page.ids[0]
if option == 0 {m.group_disabled = !m.group_disabled
m.controls_dirty = true}
if option == 1 {m.group_vertical = !m.group_vertical}
if option == 2 {m.group_joined = !m.group_joined}
m.appearance_dirty = true
<< 0
}
fn tool_39_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(39)
id := page.ids[0]
if option == 0 {m.revision += 1
english := (s.selected(m.language) >>>) == 1
series := chart_data_locale(m.chart_kind, m.revision, english)
s.set_chart_series(id, &series) >>>
m.chart_paused = false}
if option == 1 {s.reset_chart_viewport(id) >>> }
if option == 2 {m.chart_paused = !m.chart_paused
if m.chart_paused{s.pause_chart_animation(id) >>> }
else {s.resume_chart_animation(id) >>> }}
<< 0
}
fn tool_40_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(40)
id := page.ids[0]
if option == 0 {m.range_push = !m.range_push}
if option == 1 {m.range_commit = !m.range_commit}
if option == 2 {m.range_vertical = !m.range_vertical}
m.appearance_dirty = true
m.range_summary(s, false) >>>
<< 0
}
fn tool_41_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(41)
id := page.ids[0]
if option == 0 {m.split_vertical = !m.split_vertical
m.appearance_dirty = true}
if option == 1 {m.split_collapsed =(s.split_layout(id) >>>).collapsed == 0
s.set_split_collapsed(id, 0, m.split_collapsed) >>> }
if option == 2 {m.split_collapsed = false
s.set_split_ratio(id, 0.4) >>> }
<< 0
}
fn tool_42_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(42)
id := page.ids[0]
if option == 0 {s.focus(id) >>>
s.set_menu_open(id, true) >>> }
if option == 1 {m.menu_stays_open = !m.menu_stays_open
m.appearance_dirty = true}
if option == 2 {m.menu_export_disabled = !m.menu_export_disabled
s.set_menu_item_enabled(id, 30, !m.menu_export_disabled) >>> }
<< 0
}
fn tool_43_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(43)
id := page.ids[0]
if option == 0 {s.focus(id) >>>
s.set_menu_open(id, true) >>> }
if option == 1 {m.menu_stays_open = !m.menu_stays_open
m.appearance_dirty = true}
if option == 2 {m.menu_export_disabled = !m.menu_export_disabled
s.set_menu_item_enabled(id, 30, !m.menu_export_disabled) >>> }
<< 0
}
fn tool_44_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(44)
id := page.ids[0]
if option == 0 {s.focus(id) >>>
s.set_menu_open(id, true) >>> }
if option == 1 {m.menu_stays_open = !m.menu_stays_open
m.appearance_dirty = true}
if option == 2 {m.menu_export_disabled = !m.menu_export_disabled
s.set_menu_item_enabled(id, 30, !m.menu_export_disabled) >>> }
<< 0
}
fn tool_45_update(m $&Workshop, s $&widgets.Screen, option int) int {
page := m.page_snapshot(45)
id := page.ids[0]
if option == 0 {s.set_value(id, "") >>> }
if option == 1 {s.set_value(id, "Xu-密码🙂") >>> }
if option == 2 {s.focus(id) >>> }
<< 0
}
fn tool_none_update(m $&Workshop, s $&widgets.Screen, option int) int { << 0}
fn tool_clicked_update(m $&Workshop, s $&widgets.Screen, a &widgets.Action) int {
handlers :=[tool_0, tool_1, tool_2, tool_3, tool_4, tool_5, tool_6, tool_7, tool_8, tool_9, tool_10, tool_11, tool_none, tool_13, tool_none, tool_15, tool_16, tool_17, tool_18, tool_19, tool_20, tool_none, tool_none, tool_none, tool_24, tool_25, tool_none, tool_27, tool_28, tool_none, tool_30, tool_none, tool_32, tool_33, tool_34, tool_35, tool_36, tool_37, tool_38, tool_39, tool_40, tool_41, tool_42, tool_43, tool_44, tool_45]
for i in 0:3 {if a.id == m.tools[i] {handler := handlers[m.selected]
message := handler(m, s, i)
if message.len > 0 { >> errors.new(message)}
<< 0}}
<< 0
}
fn tool_clicked(m $&Workshop, s $&widgets.Screen, a &widgets.Action) string {
tool_clicked_update(m, s, a) >>> (err) { << err.msg()}
<< ""
}
fn tool_0(m $&Workshop, s $&widgets.Screen, option int) string {
tool_0_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_1(m $&Workshop, s $&widgets.Screen, option int) string {
tool_1_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_2(m $&Workshop, s $&widgets.Screen, option int) string {
tool_2_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_3(m $&Workshop, s $&widgets.Screen, option int) string {
tool_3_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_4(m $&Workshop, s $&widgets.Screen, option int) string {
tool_4_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_5(m $&Workshop, s $&widgets.Screen, option int) string {
tool_5_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_6(m $&Workshop, s $&widgets.Screen, option int) string {
tool_6_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_7(m $&Workshop, s $&widgets.Screen, option int) string {
tool_7_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_8(m $&Workshop, s $&widgets.Screen, option int) string {
tool_8_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_9(m $&Workshop, s $&widgets.Screen, option int) string {
tool_9_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_10(m $&Workshop, s $&widgets.Screen, option int) string {
tool_10_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_11(m $&Workshop, s $&widgets.Screen, option int) string {
tool_11_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_13(m $&Workshop, s $&widgets.Screen, option int) string {
tool_13_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_15(m $&Workshop, s $&widgets.Screen, option int) string {
tool_15_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_16(m $&Workshop, s $&widgets.Screen, option int) string {
tool_16_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_17(m $&Workshop, s $&widgets.Screen, option int) string {
tool_17_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_18(m $&Workshop, s $&widgets.Screen, option int) string {
tool_18_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_19(m $&Workshop, s $&widgets.Screen, option int) string {
tool_19_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_20(m $&Workshop, s $&widgets.Screen, option int) string {
tool_20_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_24(m $&Workshop, s $&widgets.Screen, option int) string {
tool_24_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_25(m $&Workshop, s $&widgets.Screen, option int) string {
tool_25_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_27(m $&Workshop, s $&widgets.Screen, option int) string {
tool_27_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_28(m $&Workshop, s $&widgets.Screen, option int) string {
tool_28_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_30(m $&Workshop, s $&widgets.Screen, option int) string {
tool_30_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_32(m $&Workshop, s $&widgets.Screen, option int) string {
tool_32_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_33(m $&Workshop, s $&widgets.Screen, option int) string {
tool_33_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_34(m $&Workshop, s $&widgets.Screen, option int) string {
tool_34_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_35(m $&Workshop, s $&widgets.Screen, option int) string {
tool_35_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_36(m $&Workshop, s $&widgets.Screen, option int) string {
tool_36_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_37(m $&Workshop, s $&widgets.Screen, option int) string {
tool_37_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_38(m $&Workshop, s $&widgets.Screen, option int) string {
tool_38_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_39(m $&Workshop, s $&widgets.Screen, option int) string {
tool_39_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_40(m $&Workshop, s $&widgets.Screen, option int) string {
tool_40_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_41(m $&Workshop, s $&widgets.Screen, option int) string {
tool_41_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_42(m $&Workshop, s $&widgets.Screen, option int) string {
tool_42_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_43(m $&Workshop, s $&widgets.Screen, option int) string {
tool_43_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_44(m $&Workshop, s $&widgets.Screen, option int) string {
tool_44_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_45(m $&Workshop, s $&widgets.Screen, option int) string {
tool_45_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}
fn tool_none(m $&Workshop, s $&widgets.Screen, option int) string {
tool_none_update(m, s, option) >>> (err) { << err.msg()}
<< ""
}@main
#ui/widgets
#ui/layout
#math
fn focusable_sample(index int) bool { << index != 0 && index != 27 && index != 28 && index != 29 && index != 30}
fn (m &Workshop) layout(s $&widgets.Screen) int {
styles := s.styles()
scale := math.max(1.0, styles.text_scale)
width := s.width()
height := s.height()
gap := 16.0
rail := 216.0 + 40.0 *(scale - 1.0)
x := rail + 48.0
right := width - x - 24.0
row := math.max(40.0 * styles.density, 36.0 * scale)
s.place(m.title, 24.0, 20.0, width - 48.0, 36.0 * scale) >>>
$top := 36.0 * scale + 32.0
items :=[m.theme, m.density, m.scale, m.state]
part :=(width - 48.0 - gap * 3.0) / 4.0
for i in 0:4 {s.place(items[i], 24.0 + f64(i) *(part + gap), top, part, row) >>> }
top += row + 12.0
s.place(m.custom, 24.0, top, part, row) >>>
s.place(m.motion, 24.0 + part + gap, top, part, row) >>>
s.place(m.reduced, 24.0 +(part + gap) * 2.0, top, part, row) >>>
s.place(m.focus, 24.0 +(part + gap) * 3.0, top, part, row) >>>
top += row + 24.0
s.place(m.navigation, 24.0, top, rail, height - top - row - 36.0) >>>
s.place(m.language, 24.0, height - row - 24.0, rail, row) >>>
s.place(m.caption, x, top, right, 58.0 * scale) >>>
control_top := top + 66.0 * scale + 16.0
content := math.max(100.0, right - 48.0)
// Keep complete action labels at large text sizes. The toolbar shares the
// preview's scroll area so wrapping never pushes the sample off the window.
$columns := 3
if content < 780.0 * scale{columns = 2}
if content < 520.0 * scale{columns = 1}
column :=(content - f64(columns - 1) * 12.0) / f64(columns)
tool_names := tool_labels(m.selected)
$tool_count := 0
for i in 0:3 {if tool_names[i].len > 0 {
s.place(m.tools[i], 24.0 + f64(tool_count % columns) *(column + 12.0), 24.0 + f64(tool_count / columns) *(row + 12.0), column, row) >>>
tool_count += 1}}
$tool_extent := 0.0
if tool_count > 0 {tool_extent = f64((tool_count + columns - 1) / columns) *(row + 12.0) + 16.0}
bottom := height - 56.0 * scale - 24.0
s.place(m.preview, x, control_top, right, math.max(100.0, bottom - control_top)) >>>
s.place(m.status, x, math.max(bottom + 12.0, control_top + 112.0), right, 52.0 * scale) >>>
for i in 0:m.pages.len{s.set_visible(m.pages[i].group, i == m.selected) >>> }
position := m.selected
pages := &m.pages
page := &pages[position]
s.place(page.group, 0.0, tool_extent, right, 1000.0 * scale) >>>
id := page.ids[0]
$h := row
if m.selected == 0 {h = 180.0 * scale}
if m.selected == 4 {h = 220.0 * scale}
if m.selected == 5 {h = 96.0 * scale}
if m.selected == 6 {h = 210.0 * scale}
if m.selected == 7 || m.selected == 23 || m.selected == 24 || m.selected == 32 || m.selected == 37 {h = 320.0 * scale}
if m.selected == 12 {h = 144.0 * scale}
if m.selected == 13 {h = 80.0 * scale}
if m.selected == 20 {h = 280.0 * scale}
if m.selected == 27 {h = 16.0 * scale}
if m.selected == 28 {h = 54.0 * scale}
if m.selected == 29 {h = 28.0 * scale}
if m.selected == 30 {h = 320.0 * scale}
if m.selected == 31 {h = 280.0 * scale}
$y := 24.0
if m.selected == 7 || m.selected == 17 {s.place(page.ids[1], 24.0, 24.0, content, 86.0 * scale) >>>
y += 102.0 * scale}
$sample_width := content
if m.selected == 2 {sample_width = row
h = row}
if m.selected != 30 && m.selected != 1 {s.place(id, 24.0, y, sample_width, h) >>> }
if m.selected == 1 {
buttons := m.page_snapshot(1)
h = layout_buttons(s, &buttons, content, row, scale) >>>
}
if m.selected == 34 {
size := s.measure_button(id) >>>
width := math.min(content, math.ceil(size.width))
s.place(id, 24.0 +(content - width) * 0.5, y + 100.0 * scale, width, math.max(row, size.height)) >>>
h = math.max(row, size.height) + 200.0 * scale
}
if m.selected == 0 {s.place(page.ids[1], 24.0, y + h + 16.0, content, 48.0 * scale) >>>
h += 80.0 * scale}
if m.selected == 13 {s.place(page.ids[1], 24.0, y + h + 24.0, content, 100.0 * scale) >>>
h += 148.0 * scale}
if m.selected == 25 {
$summary_height := 28.0 * scale
if content < 650.0 && scale > 1.4 {summary_height = 56.0 * scale}
s.place(page.ids[3], 24.0, y, content, summary_height) >>>
page_y := y + summary_height + 12.0 * scale
s.place(id, 24.0, page_y, content, row) >>>
cy := page_y + row + 28.0 * scale
size_width := math.min(content, 150.0 * scale)
input_width := 112.0 * scale
go_width := 88.0 * scale
$input_x := 40.0 + size_width
$input_y := cy
if size_width + input_width + go_width + 32.0 > content{
input_x = 24.0
input_y = cy + row + 32.0 * scale}
s.place(page.ids[2], 24.0, cy, size_width, row) >>>
s.place(page.ids[1], input_x, input_y - 8.0 * styles.density, input_width, row + 8.0 * styles.density) >>>
s.place(page.ids[4], input_x + input_width + 16.0, input_y, go_width, row) >>>
s.place(page.ids[5], 24.0, input_y + row + 12.0 * scale, content, 40.0 * scale) >>>
h = input_y - y + row + 64.0 * scale
}
if m.selected == 33 {
s.place(id, 24.0, y, math.min(content, 200.0 * scale), row) >>>
s.place(page.ids[1], 0.0, 0.0, 360.0 * scale, 340.0 * scale) >>>
s.place(page.ids[2], 24.0 * scale, 20.0 * scale, 312.0 * scale, 30.0 * scale) >>>
s.place(page.ids[3], 24.0 * scale, 58.0 * scale, 312.0 * scale, 66.0 * scale) >>>
s.place(page.ids[4], 24.0 * scale, 132.0 * scale, 312.0 * scale, 88.0 * scale) >>>
s.place(page.ids[5], 24.0 * scale, 224.0 * scale, 312.0 * scale, row) >>>
s.place(page.ids[6], 24.0 * scale, 280.0 * scale, 148.0 * scale, row) >>>
s.place(page.ids[7], 188.0 * scale, 280.0 * scale, 148.0 * scale, row) >>>
s.place(page.ids[8], 24.0, y + row + 20.0 * scale, content, 64.0 * scale) >>>
h = row + 100.0 * scale
}
if m.selected == 20 {s.place(page.ids[1], 24.0, y + h + 24.0, content, 96.0 * scale) >>>
h += 124.0 * scale}
if m.selected == 28 || m.selected == 29 {s.place(page.ids[1], 24.0, y + h + 12.0, content, 36.0 * scale) >>>
h += 60.0 * scale}
if m.selected == 30 {
button_width := math.min(content - 16.0, 220.0 * scale)
s.place(page.ids[1], 24.0, y, button_width, row) >>>
s.place(page.ids[6], 24.0, y + row + 14.0 * scale, content, 36.0 * scale) >>>
ay := y + row + 78.0 * scale
s.place(page.ids[2], 24.0, ay, 56.0 * scale, 56.0 * scale) >>>
s.place(page.ids[7], 100.0 * scale, ay, math.max(1.0, content - 100.0 * scale), 32.0 * scale) >>>
s.place(page.ids[8], 100.0 * scale, ay + 34.0 * scale, math.max(1.0, content - 100.0 * scale), 40.0 * scale) >>>
sy := ay + 106.0 * scale
tag := s.badge_size(page.ids[4]) >>>
beta := s.badge_size(page.ids[5]) >>>
label_width := 220.0 * scale
$tx := 24.0
$ty := sy + 44.0 * scale
if label_width + tag.width + beta.width + 32.0 <= content{
s.place(page.ids[9], 24.0, sy, label_width, 32.0 * scale) >>>
tx = 40.0 + label_width
ty = sy
} else {s.place(page.ids[9], 24.0, sy, content, 32.0 * scale) >>> }
s.place(page.ids[4], tx, ty, tag.width, tag.height) >>>
s.place(page.ids[5], tx + 16.0 + tag.width, ty, beta.width, beta.height) >>>
h = ty + math.max(tag.height, 32.0 * scale)
}
if m.selected == 31 {s.place(page.ids[4], 0.0, 0.0, content - 32.0, 36.0 * scale) >>>
s.place(page.ids[5], 0.0, 0.0, content - 32.0, 110.0 * scale) >>>
s.place(page.ids[6], 0.0, 0.0, content - 32.0, row) >>> }
if m.selected == 32 {s.set_scroll_extent(id, 14.0 *(row + 16.0) + 24.0) >>>
for i in 1:page.ids.len{s.place(page.ids[i], 12.0, 12.0 + f64(i - 1) *(row + 16.0), content - 44.0, row) >>> }}
if m.selected == 38 {
height := row
$group_h := height
if m.group_vertical{group_h = row * 3.0}
$group_width := content
if m.group_vertical{group_width = math.min(content, 260.0 * scale)}
for i in 0:3 {cy := y + f64(i) *(group_h + 40.0 * scale)
s.place(page.ids[3 + i], 24.0, cy, content, 24.0 * scale) >>>
s.place(page.ids[i], 24.0, cy + 28.0 * scale, group_width, group_h) >>> }
h = 3.0 *(group_h + 40.0 * scale)
}
if m.selected == 39 {
$selector_h := row
$selector := widgets.button_group_appearance()
selector.equal_width = true
selector.allow_empty = true
if scale > 1.4 && content < 560.0 {selector.vertical = true
selector_h = row * 5.0}
$cy := y
for r in 0:6 {
gid := page.ids[1 + r]
s.set_button_group_appearance(gid, &selector) >>>
s.place(gid, 24.0, cy, content, selector_h) >>>
cy += selector_h + 8.0 * scale
}
chart_y := cy + 12.0 * scale
chart_h := math.max(320.0, 320.0 * scale)
s.place(id, 24.0, chart_y, content, chart_h) >>>
h = (chart_y - y) + chart_h + 20.0 * scale
}
if m.selected >= 40 {h = m.interaction_layout(s, row, scale, content) >>> }
if m.selected == 36 {s.place(page.ids[2], 24.0 * scale, 190.0 * scale, 170.0 * scale, row) >>>
s.place(page.ids[3], 210.0 * scale, 190.0 * scale, 170.0 * scale, row) >>> }
s.set_scroll_extent(m.preview, tool_extent + y + h + 32.0) >>>
<< 0
}
fn layout_buttons(s $&widgets.Screen, page &Page, content f64, row f64, scale f64) f64 {
stepper_width := math.min(content, 160.0 * scale)
label_height := 24.0 * scale
inspector_height := label_height + 8.0 + row + 12.0
$cy := 24.0
// Keep each direction pair together when it fits, then wrap by the native
// measured size rather than stretching every example across the preview.
for group in 0:2 {
$x := 24.0
$line_height := 0.0
for i in(group * 2):(group * 2 + 2) {
size := s.measure_button(page.ids[i]) >>>
width := math.min(content, math.ceil(size.width))
height := math.max(row, math.ceil(size.height))
column := math.max(width, stepper_width)
if x > 24.0 && x + column > 24.0 + content{
x = 24.0
cy += line_height + 12.0
line_height = 0.0
}
s.place(page.ids[13 + i], x, cy, column, label_height) >>>
s.place(page.ids[9 + i], x, cy + label_height + 8.0, stepper_width, row) >>>
s.place(page.ids[i], x, cy + inspector_height, width, height) >>>
x += column + 16.0
line_height = math.max(line_height, inspector_height + height)
}
cy += line_height + 20.0
}
$x := 24.0
$line_height := 0.0
for i in 4:9 {
size := s.measure_button(page.ids[i]) >>>
width := math.min(content, math.ceil(size.width))
height := math.max(row, math.ceil(size.height))
if x > 24.0 && x + width > 24.0 + content{
x = 24.0
cy += line_height + 12.0
line_height = 0.0
}
s.place(page.ids[i], x, cy, width, height) >>>
x += width + 12.0
line_height = math.max(line_height, height)
}
cy += line_height + 20.0
<< cy - 24.0
}
fn (m &Workshop) interaction_layout(s $&widgets.Screen, row f64, scale f64, content f64) f64 {
position := m.selected
pages := &m.pages
page := &pages[position]
id := page.ids[0]
if m.selected == 45 {
width := math.min(content, 380.0 * scale)
label_height := 28.0 * scale
input_height := math.max(row, 48.0 * s.styles().density)
input_y := 24.0 + label_height + 8.0
s.place(page.ids[2], 24.0, 24.0, width, label_height) >>>
s.place(id, 24.0, input_y, width, input_height) >>>
s.place(page.ids[1], 24.0, input_y + input_height + 16.0, content, row) >>>
s.place(page.ids[3], 24.0, input_y + input_height + row + 36.0, content, 100.0 * scale) >>>
<< label_height + input_height + row + 160.0 * scale
}
if m.selected == 40 {
$width := content
$height := 104.0 * scale
if m.range_vertical{width = math.min(content, 160.0 * scale)
height = 300.0 * scale}
s.place(page.ids[1], 24.0, 24.0, content, 32.0 * scale) >>>
s.place(id, 24.0, 64.0 * scale, width, height) >>>
s.place(page.ids[2], 24.0, 80.0 * scale + height, content, 64.0 * scale) >>>
<< height + 144.0 * scale
}
if m.selected == 41 {
height := 320.0 * scale
s.place(id, 24.0, 24.0, content, height) >>>
boxes := s.split_layout(id) >>>
for pane in 0:2 {
$width := boxes.first.width
$height := boxes.first.height
if pane == 1 {width = boxes.second.width
height = boxes.second.height}
inner := math.max(1.0, width - 32.0)
caption_height := math.max(1.0, math.min(100.0 * scale, height - row - 48.0))
s.place(page.ids[3 + pane], 16.0, 16.0, inner, caption_height) >>>
s.set_visible(page.ids[5 + pane], height >= row + 32.0) >>>
s.place(page.ids[5 + pane], 16.0, math.max(16.0, height - row - 16.0), inner, row) >>>
}
<< height
}
if m.selected >= 42 && m.selected <= 44 {
$width := math.min(content, 240.0 * scale)
$height := row
if m.selected == 43 {width = content
height = 180.0 * scale}
s.place(id, 24.0, 24.0, width, height) >>>
s.place(page.ids[1], 24.0, height + 44.0 * scale, content, 44.0 * scale) >>>
s.place(page.ids[2], 24.0, height + 100.0 * scale, content, 80.0 * scale) >>>
<< height + 180.0 * scale
}
<< row
}@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
}fmapub fn fma(x f64, y f64, z f64) f64Compute fused multiply-add (x * y + z).
x f64y f64z f64f64 — a value of this type
abspub fn abs(x f64) f64Clear only the IEEE sign bit, including negative zero and NaNs.
x f64f64 — a value of this type
minpub fn min(a f64, b f64) f64Return the smaller of two numeric values.
a f64b f64f64 — a value of this type
maxpub fn max(a f64, b f64) f64Return the larger of two numeric values.
a f64b f64f64 — a value of this type
floorpub fn floor(x f64) f64Return the greatest integer value <= x.
x f64f64 — a value of this type
ceilpub fn ceil(x f64) f64Return the least integer value >= x.
x f64f64 — a value of this type
sqrtpub fn sqrt(x f64) f64Square root.
x f64f64 — a value of this type
powpub fn pow(x f64, n int) f64Compute base x raised to power y.
x f64n intf64 — a value of this type
exppub fn exp(x f64) f64e to the power.
x f64f64 — a value of this type
logpub fn log(x f64) f64Natural logarithm.
x f64f64 — a value of this type
hypotpub fn hypot(p f64, q f64) f64Execute hypot.
p f64q f64f64 — a value of this type
pipub fn pi() f64Execute pi.
No arguments are required.
f64 — a value of this type
epub fn e() f64Execute e.
No arguments are required.
f64 — a value of this type
ln2pub fn ln2() f64Execute ln2.
No arguments are required.
f64 — a value of this type
is_nanpub fn is_nan(x f64) boolWhether the value is NaN.
x f64bool — true or false
struct Frexppub struct Frexp {
pub frac f64
pub exp int
}Structure encapsulating frac, exp.
frac f64exp intldexppub fn ldexp(frac f64, exp int) f64Execute ldexp.
frac f64exp intf64 — a value of this type
frexppub fn frexp(x f64) FrexpExecute frexp.
x f64Frexp — a value of this type
dimpub fn dim(x f64, y f64) f64Execute dim.
x f64y f64f64 — a value of this type
remainderpub fn remainder(x f64, y f64) f64Execute remainder.
x f64y f64f64 — a value of this type
is_infpub fn is_inf(x f64) boolWhether the value is infinity.
x f64bool — true or false
copysignpub fn copysign(mag f64, sign f64) f64Execute copysign.
mag f64sign f64f64 — a value of this type
truncpub fn trunc(x f64) f64Execute trunc.
x f64f64 — a value of this type
modpub fn mod(x f64, y f64) f64Compute floating-point division remainder.
x f64y f64f64 — a value of this type
roundpub fn round(x f64) f64Execute round.
x f64f64 — a value of this type
round_to_evenpub fn round_to_even(x f64) f64Round to even.
x f64f64 — a value of this type
sinpub fn sin(x f64) f64Compute trigonometric sine of x radians.
x f64f64 — a value of this type
cospub fn cos(x f64) f64Compute trigonometric cosine of x radians.
x f64f64 — a value of this type
tanpub fn tan(x f64) f64Compute trigonometric tangent of x radians.
x f64f64 — a value of this type
atanpub fn atan(x f64) f64Execute atan.
x f64f64 — a value of this type
atan2pub fn atan2(y f64, x f64) f64Execute atan2.
y f64x f64f64 — a value of this type
nanpub fn nan() f64Return IEEE 754 Not-a-Number (NaN) float value.
No arguments are required.
f64 — a value of this type
infpub fn inf(sign int) f64Execute inf.
sign intf64 — a value of this type
signbitpub fn signbit(x f64) boolExecute signbit.
x f64bool — true or false
pow_f64pub fn pow_f64(x f64, y f64) f64pow_f64 is math.Pow. The existing pow(x, n int) stays because Xu has no overloads (same split as cmp.less_int / less_f64).
x f64y f64f64 — a value of this type
log10pub fn log10(x f64) f64Execute log10.
x f64f64 — a value of this type
log2pub fn log2(x f64) f64Execute log2.
x f64f64 — a value of this type
exp2pub fn exp2(x f64) f64Execute exp2.
x f64f64 — a value of this type
cbrtpub fn cbrt(x f64) f64Execute cbrt.
x f64f64 — a value of this type
asinpub fn asin(x f64) f64Execute asin.
x f64f64 — a value of this type
acospub fn acos(x f64) f64Execute acos.
x f64f64 — a value of this type
struct ModfResultpub struct ModfResult {
pub intg f64
pub frac f64
}Structure encapsulating intg, frac.
intg f64frac f64sinhpub fn sinh(x f64) f64Execute sinh.
x f64f64 — a value of this type
coshpub fn cosh(x f64) f64Execute cosh.
x f64f64 — a value of this type
tanhpub fn tanh(x f64) f64Execute tanh.
x f64f64 — a value of this type
asinhpub fn asinh(x f64) f64Inverse hyperbolic functions ( Asinh/Acosh/Atanh). Combined from log/sqrt like sinh/cosh/tanh; large |x| uses log(2*|x|) so x*x does not overflow to Inf.
x f64f64 — a value of this type
acoshpub fn acosh(x f64) f64Execute acosh.
x f64f64 — a value of this type
atanhpub fn atanh(x f64) f64Execute atanh.
x f64f64 — a value of this type
modfpub fn modf(x f64) ModfResultExecute modf.
x f64ModfResult — a value of this type
log1ppub fn log1p(x f64) f64log1p is Log1p: ln(1+x). Small |x| returns x so 1+x does not round away the addend.
x f64f64 — a value of this type
expm1pub fn expm1(x f64) f64expm1 is Expm1: e^x - 1 without cancellation near 0.
x f64f64 — a value of this type
float64_bitspub fn float64_bits(value f64) intBinary64 bit reinterpretation, not a numeric cast. Xu int carries all 64 bits, including sign; zero signs and all NaN payload bits are preserved.
value f64int — a value of this type
float64_from_bitspub fn float64_from_bits(bits int) f64Float64 from bits.
bits intf64 — a value of this type
float32_bitspub fn float32_bits(value f64) intXu numeric floats are binary64. Convert to a binary32 bit pattern in the low 32 bits of int, round-to-nearest/ties-to-even, with gradual underflow. Overflow yields signed infinity. NaNs retain sign/high payload and become quiet; no floating-point arithmetic is used to inspect the input.
value f64int — a value of this type
float32_from_bitspub fn float32_from_bits(bits int) f64Interpret the low 32 bits as binary32 and expand exactly to Xu binary64. Zero signs, infinities and the complete binary32 NaN payload/signaling bit are preserved in their binary64 positions. Arithmetic on NaNs may quiet them.
bits intf64 — a value of this type
float16_to_f32pub fn float16_to_f32(h int) f32Convert an IEEE-754 binary16 bit pattern (low 16 bits of int) to f32.
h intf32 — a value of this type