XU XUv0.16.0

#time

导入方式: #time

公开 API: 36 函数, 57 方法, 9 类型, 0 常量, 0 方法集

Duration 为纳秒 int。now/sleep、Time、Timer/Ticker(xu+chan+sleep)。无 IANA 时区。

示例代码 · API 声明

示例代码

以下源码来自官方 examples 仓库,可复制或下载。请在完整工程中使用本地 Xu SDK 运行;网络、数据库和桌面示例需要对应的服务或资源。

16_ui_webview/interaction_gallery/main.xu

所需 SDK:Xu 0.10.13-dev.1 · 完整工程 · 下载源码 · events.xu · style.xu

Xumain.xu
@main

#ui
#ui/widgets
#ui/layout
#time
#math
#errors
demo #"github.com/xulang-org/examples/ui_demo"

struct Model{
    tree int
    name int
    search int
    task int
    cancel int
    table int
    theme int
    guides int
    density int
    effects int
    failure int
    message int
    headings []int
    controls_page int
    work_group int
    basic_group int
    extras []int
    show_controls bool
    theme_index int
    guided bool
    compact bool
    reduced bool
    fail_next bool
    appearance_dirty bool
    task_id int
    completed int
    running bool
    checksum int
    next_work time.Instant
}
fn make_model(screen $&widgets.Screen) Model{
    $name_decoration := widgets.field_decoration(&"Output name")
    name_decoration.helper = "A persistent label, native text selection and IME"
    name_decoration.error = "Enter an output name before building."
    name_decoration.clearable = true
    name := screen.field("", &name_decoration) >>>
    $search_decoration := widgets.field_decoration(&"Find a component")
    search_decoration.helper = "Matching nodes keep their ancestor path"
    search_decoration.clearable = true
    search := screen.field("", &search_decoration) >>>
    tree := screen.tree() >>>
    root := screen.tree_add(tree, - 1, "xu-workbench") >>>
    src := screen.tree_add(tree, root, "src") >>>
    entry := screen.tree_add(tree, src, "main.xu") >>>
    controls := screen.tree_add(tree, src, "widgets") >>>
    for label in["tree_view.xu", "task_button.xu", "field.xu", "table.xu"] {
        node := screen.tree_add(tree, controls, label) >>>
        screen.set_tree_action(tree, node, true) >>>
    }
    manifest := screen.tree_add(tree, root, "xu.xun") >>>
    screen.set_tree_metadata(tree, entry, "entry") >>>
    screen.set_tree_metadata(tree, manifest, "module") >>>
    for node in[root, src, controls] {screen.set_expanded(tree, node, true) >>> }
    task := screen.task_button("Build project") >>>
    screen.set_task_labels(task, "Building", "Built · run again", "Retry build", "Build again") >>>
    table := screen.table(&["Component", "Experience", "Status"], 18, 0) >>>
    screen.set_table_column(table, 0, 144.0, 0.0) >>>
    screen.set_table_column(table, 1, 340.0, 0.0) >>>
    screen.set_table_column(table, 2, 128.0, 0.0) >>>
    names :=["TreeView", "TaskButton", "Field", "Table", "Select", "Popover"]
    details :=["Find and reveal", "Real task progress", "Floating label / native IME", "Resizable columns", "Keyboard choices", "Anchored feedback"]
    for row in 0:18 {
        index := row % 6
        screen.set_cell(table, row, 0, names[index]) >>>
        screen.set_cell(table, row, 1, details[index]) >>>
        screen.set_cell(table, row, 2, "Ready") >>>
    }
    headings :=[screen.label("XUUI / INTERACTION LAB", 12.0, true) >>>,
    screen.label("Precision in every interaction.", 25.0, false) >>>,
    screen.label("WORKSPACE", 12.0, true) >>>, screen.label("BUILD CONFIGURATION", 12.0, true) >>>,
    screen.label("COMPONENTS / scroll, select and sort", 12.0, true) >>>]
    work_group := screen.group() >>>
    basic_group := screen.group() >>>
    for id in[tree, name, search, task, table, headings[2], headings[3], headings[4]] {screen.set_parent(id, work_group) >>> }
    extras := extra_controls(screen) >>>
    for id in extras{screen.set_parent(id, basic_group) >>> }
    cancel := screen.button("Cancel task") >>>
    screen.set_parent(cancel, work_group) >>>
    controls_page := screen.button("All controls") >>>
    styles := screen.styles()
    primary_style := styles.button_variant(widgets.BUTTON_PRIMARY) >>>
    screen.set_control_style(task, &primary_style) >>>
    << Model{tree: tree, name: name, search: search, task: task, cancel: cancel,
        table: table, theme: screen.button("Theme") >>>, guides: screen.button("Tree guides") >>>,
        density: screen.button("Density") >>>, effects: screen.button("Motion") >>>, failure: screen.button("Fail next build") >>>,
        message: screen.label("Local work batches report completed items. No simulated percentage clock.", 13.0, true) >>>,
        headings: headings, controls_page: controls_page, work_group: work_group, basic_group: basic_group, extras: extras, show_controls: false, theme_index: 1, guided: false, compact: false, reduced: false, fail_next: false, appearance_dirty: true,
        task_id: 0, completed: 0, running: false, checksum: 0, next_work: time.zero_instant()}
}
fn (m &Model) layout(screen $&widgets.Screen) int {
    width := screen.width()
    height := screen.height()
    left := 310.0
    screen.place(m.headings[0], 28.0, 24.0, width - 56.0, 22.0) >>>
    screen.place(m.headings[1], 28.0, 54.0, width - 56.0, 36.0) >>>
    buttons :=[m.theme, m.guides, m.density, m.effects, m.failure, m.controls_page]
    for i in 0:buttons.len{screen.place(buttons[i], 28.0 + f64(i) * 144.0, 111.0, 132.0, 36.0) >>> }
    screen.set_visible(m.work_group, !m.show_controls) >>>
    screen.set_visible(m.basic_group, m.show_controls) >>>
    screen.set_selected_button(m.controls_page, m.show_controls) >>>
    extra_layout(screen, &m.extras) >>>
    screen.set_selected_button(m.guides, m.guided) >>>
    screen.set_selected_button(m.effects, m.reduced) >>>
    screen.set_selected_button(m.failure, m.fail_next) >>>
    screen.place(m.headings[2], 28.0, 173.0, left - 24.0, 24.0) >>>
    screen.place(m.search, 28.0, 208.0, left - 24.0, 80.0) >>>
    screen.place(m.tree, 28.0, 302.0, left - 24.0, height - 352.0) >>>
    x := left + 36.0
    right_width := width - x - 28.0
    screen.place(m.headings[3], x, 173.0, right_width, 24.0) >>>
    screen.place(m.name, x, 208.0, right_width, 86.0) >>>
    screen.place(m.task, x, 307.0, 230.0, 40.0) >>>
    screen.place(m.cancel, x + 246.0, 307.0, 136.0, 40.0) >>>
    screen.set_enabled(m.cancel, m.running) >>>
    screen.place(m.headings[4], x, 377.0, right_width, 24.0) >>>
    screen.place(m.table, x, 413.0, right_width, height - 493.0) >>>
    screen.place(m.message, 28.0, height - 41.0, width - 56.0, 24.0) >>>
    << 0
}
fn (m $&Model) work(screen $&widgets.Screen, now time.Instant) int {
    if !m.running || now.before(m.next_work) { << 0}
    // Each progress update follows an actual bounded work batch. The pause
    // represents an application work queue and never changes the percentage.
    for i in 0:5000 {m.checksum =(m.checksum + i *(m.completed + 1)) % 1000003}
    m.completed = m.completed + 1
    _ := screen.set_task_progress(m.task, m.task_id, f64(m.completed) / 48.0) >>>
    m.next_work = now.add(time.milliseconds(35) >>>) >>>
    if m.fail_next && m.completed == 18 {
        _ := screen.complete_task(m.task, m.task_id, widgets.TASK_ERROR) >>>
        m.running = false
        m.fail_next = false
        screen.set_text(m.message, "Example failure. Retry starts a new task; stale progress is rejected.") >>>
    } else if m.completed == 48 {
        _ := screen.complete_task(m.task, m.task_id, widgets.TASK_SUCCESS) >>>
        m.running = false
        screen.set_text(m.message, "48/48 work batches completed · checksum " + str(m.checksum)) >>>
    }
    << 0
}
fn extra_controls(screen $&widgets.Screen)[]int {
    $ids :=[]int {}
    ids.push(screen.card() >>>)
    ids.push(screen.label("CONTROLS / keyboard, pointer and state", 12.0, true) >>>)
    ids.push(screen.checkbox("Keep generated files", true) >>>)
    ids.push(screen.switch_control("Live preview", true) >>>)
    ids.push(screen.radio("Use workspace settings", 1, true) >>>)
    ids.push(screen.slider(0.0, 100.0, 40.0) >>>)
    ids.push(screen.stepper(1.0, 16.0, 1.0, 4.0) >>>)
    ids.push(screen.tabs(&["Files", "History", "Output"], 0) >>>)
    ids.push(screen.segmented(&["Desktop", "Tablet", "Phone"], 0) >>>)
    ids.push(screen.select_box(&["Xu source", "Configuration", "Plain text"], 0) >>>)
    ids.push(screen.list_box(&["Compiler", "Widgets", "Runtime", "Desktop", "Examples", "Tooling"], 0) >>>)
    ids.push(screen.progress(0.62) >>>)
    ids.push(screen.badge("Ready") >>>)
    ids.push(screen.divider(widgets.AXIS_HORIZONTAL) >>>)
    ids.push(screen.radio_group(&["Use local build", "Use cached build", "Build dependencies"], 0) >>>)
    ids.push(screen.input("Native input · 中文") >>>)
    ids.push(screen.text_area("A multi-line editor.\nSelection, clipboard and native IME remain available.") >>>)
    ids.push(screen.date_picker(time.date(2026, 10, 25, 10, 30, 0, 0)) >>>)
    ids.push(screen.time_picker(time.date(2026, 10, 25, 10, 30, 0, 0)) >>>)
    ids.push(screen.button("Queue notification") >>>)
    _ := screen.tooltip(ids[19], "Repeated notifications queue; hover or focus pauses expiry.") >>>
    screen.set_slider_commit_only(ids[5], true) >>>
    screen.set_checkbox_indeterminate(ids[2], true) >>>
    screen.set_select_option_enabled(ids[9], 2, false) >>>
    screen.set_badge_tone(ids[12], widgets.BADGE_SUCCESS) >>>
    screen.set_progress_buffer(ids[11], 0.84) >>>
    screen.set_date_options(ids[17], time.date(2026, 10, 25, 0, 0, 0, 0), true) >>>
    screen.set_clock_format(ids[18], true, true) >>>
    << ids
}
fn extra_layout(screen $&widgets.Screen, ids &[]int) int {
    gap := 28.0
    width :=(screen.width() - 84.0) * 0.5
    right := 56.0 + width
    screen.place(ids[0], gap, 628.0, width, 112.0) >>>
    screen.place(ids[1], gap, 173.0, screen.width() - 56.0, 24.0) >>>
    for i in 2:5 {screen.place(ids[i], gap, 211.0 + f64(i - 2) * 46.0, width, 36.0) >>> }
    screen.place(ids[5], gap, 357.0, width - 136.0, 36.0) >>>
    screen.place(ids[6], gap + width - 124.0, 357.0, 124.0, 36.0) >>>
    screen.place(ids[7], gap, 412.0, width, 36.0) >>>
    screen.place(ids[8], gap, 466.0, width, 36.0) >>>
    screen.place(ids[11], gap, 522.0, width - 120.0, 12.0) >>>
    screen.place(ids[12], gap + width - 100.0, 510.0, 100.0, 32.0) >>>
    screen.place(ids[13], gap, 607.0, width, 1.0) >>>
    screen.place(ids[14], right, 211.0, width, 126.0) >>>
    screen.place(ids[9], right, 357.0, width, 36.0) >>>
    screen.place(ids[10], right, 412.0, width, 158.0) >>>
    screen.place(ids[15], right, 590.0, width, 36.0) >>>
    screen.place(ids[16], right, 644.0, width, 96.0) >>>
    screen.place(ids[17], gap, 560.0,(width - 16.0) * 0.5, 36.0) >>>
    screen.place(ids[18], gap +(width + 16.0) * 0.5, 560.0,(width - 16.0) * 0.5, 36.0) >>>
    screen.place(ids[19], gap + 16.0, 665.0, width - 32.0, 38.0) >>>
    << 0
}
fn next_event(events chan ui.Event, deadline time.Instant) ui.Event{
    if deadline.is_zero() { << <- events}
    delay := deadline.since(time.instant())
    if delay.nanoseconds() <= 0 { << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}}
    timer := delay.timer()
    select {
        event := <- events{timer.stop()
            << event}
        _ := <- timer.c{timer.stop()}
    }
    << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
}
fn scene(events chan ui.Event) int {
    ready := demo.ready(events) >>>
    if ready.kind == ui.EV_EXIT{ << 0}
    $screen := widgets.screen(&ready) >>>
    screen.resize(1000.0, 820.0) >>>
    screen.set_min_size(900, 720) >>>
    $model := make_model($&screen) >>> (err) {screen.dispose()
        >> err}
    apply_appearance($&model, $&screen) >>>
    model.layout($&screen) >>>
    _ := screen.render() >>>
    $dispatcher := register_actions(&model, &screen) >>>
    while screen.is_open() {
        now := time.instant()
        apply_appearance($&model, $&screen) >>>
        register_notices(&screen, $&dispatcher) >>>
        model.work($&screen, now) >>>
        model.layout($&screen) >>>
        $deadline := screen.advance(now) >>> (err) { >> errors.new("gallery animation: " + err.msg())}
        for action in screen.take_actions() {_ := dispatcher.dispatch(&action, $&model, $&screen) >>> }
        apply_appearance($&model, $&screen) >>>
        _ := screen.render() >>> (err) { >> errors.new("gallery render: " + err.msg())}
        if model.running &&(deadline.is_zero() || model.next_work.before(deadline)) {deadline = model.next_work}
        event := next_event(events, deadline) >>>
        $actions := screen.event(&event) >>>
        $count := 0
        while screen.is_open() && count < 128 {
            pending := ui.poll_chan(events)
            if pending.kind == ui.EV_NONE{ <- }
            more := screen.event(&pending) >>>
            for action in more{actions.push(action)}
            count += 1
        }
        for action in actions{_ := dispatcher.dispatch(&action, $&model, $&screen) >>> }
    }
    screen.dispose()
    << 0
}
fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
        << }}
fn launch() int {
    $app := demo.app("XUUI / Interaction Lab", 1000, 820) >>>
    xu worker(app.event_ch)
    << app.run() >>>
}
fn main() int { << launch() >>> (err) {eprintln(err.msg())
        << 1}}
Xuevents.xu
@main

#ui
#ui/widgets
#time

fn search_changed(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    query := screen.text_value(m.search) >>> (err) { << err.msg()}
    screen.set_tree_filter(m.tree, query) >>> (err) { << err.msg()}
    << ""
}
fn name_changed(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    screen.set_field_invalid(m.name, false) >>> (err) { << err.msg()}
    << ""
}
fn node_action(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    _ := screen.notify("Node action · " + str(int(action.value))) >>> (err) { << err.msg()}
    << ""
}
fn slider_committed(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    screen.set_text(m.message, "Slider committed · " + str(int(action.value))) >>> (err) { << err.msg()}
    << ""
}
fn toggle_controls(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    m.show_controls = !m.show_controls
    << ""
}
fn queue_notice(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    $notice := widgets.notice(&"Saved a local configuration")
    notice.action = "Undo"
    _ := screen.enqueue_notice(&notice) >>> (err) { << err.msg()}
    << ""
}
fn choose_theme(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    m.theme_index =(m.theme_index + 1) % 3
    m.appearance_dirty = true
    << ""
}
fn choose_guides(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    m.guided = !m.guided
    m.appearance_dirty = true
    << ""
}
fn choose_density(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    m.compact = !m.compact
    m.appearance_dirty = true
    << ""
}
fn choose_motion(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    m.reduced = !m.reduced
    m.appearance_dirty = true
    << ""
}
fn choose_failure(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    m.fail_next = !m.fail_next
    << ""
}
fn start_task(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    if m.running{ << ""}
    name := screen.text_value(m.name) >>> (err) { << err.msg()}
    if name.len == 0 {screen.set_field_invalid(m.name, true) >>> (err) { << err.msg()}
        screen.focus(m.name) >>> (err) { << err.msg()}
        << ""}
    m.task_id = m.task_id + 1
    m.completed = 0
    m.checksum = 0
    m.running = true
    m.next_work = time.instant()
    screen.begin_task(m.task, m.task_id) >>> (err) { << err.msg()}
    << ""
}
fn cancel_task(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    if !m.running{ << ""}
    _ := screen.complete_task(m.task, m.task_id, widgets.TASK_CANCELLED) >>> (err) { << err.msg()}
    m.running = false
    screen.set_text(m.message, "Task cancelled. Completed work remains " + str(m.completed) + "/48.") >>> (err) { << err.msg()}
    << ""
}
fn notice_action(m $&Model, screen $&widgets.Screen, action &widgets.Action) string {
    screen.set_text(m.message, "Notification action · " + str(int(action.value))) >>> (err) { << err.msg()}
    << ""
}
fn register_actions(m &Model, screen &widgets.Screen) widgets.ActionDispatcher#Model, widgets.Screen, widgets.Action{
    $d := widgets.action_dispatcher(m, screen)
    d.on(m.search, widgets.ACTION_CHANGE, search_changed) >>>
    d.on(m.name, widgets.ACTION_CHANGE, name_changed) >>>
    d.on(m.tree, widgets.ACTION_ITEM_ACTION, node_action) >>>
    d.on(m.extras[5], widgets.ACTION_COMMIT, slider_committed) >>>
    d.on(m.controls_page, widgets.ACTION_ACTIVATE, toggle_controls) >>>
    d.on(m.extras[19], widgets.ACTION_ACTIVATE, queue_notice) >>>
    d.on(m.theme, widgets.ACTION_ACTIVATE, choose_theme) >>>
    d.on(m.guides, widgets.ACTION_ACTIVATE, choose_guides) >>>
    d.on(m.density, widgets.ACTION_ACTIVATE, choose_density) >>>
    d.on(m.effects, widgets.ACTION_ACTIVATE, choose_motion) >>>
    d.on(m.failure, widgets.ACTION_ACTIVATE, choose_failure) >>>
    d.on(m.task, widgets.ACTION_ACTIVATE, start_task) >>>
    d.on(m.cancel, widgets.ACTION_ACTIVATE, cancel_task) >>>
    << d
}
fn register_notices(screen &widgets.Screen, d $&widgets.ActionDispatcher#Model, widgets.Screen, widgets.Action) int {
    for id in screen.notice_ids() {d.on(id, widgets.ACTION_NOTICE_ACTION, notice_action) >>> }
    << 0
}
16_ui_webview/style_gallery/main.xu

所需 SDK:Xu 0.10.13-dev.1 · 完整工程 · 下载源码 · events.xu · style.xu

Xu本地 SDK 示例
@main
#ui
#ui/draw
#ui/widgets
#ui/layout
#time
demo #"github.com/xulang-org/examples/ui_demo"

// IDs follow the stable topology created below. All control bounds are local;
// Editor.place receives the separate canvas rectangle for native IME geometry.
struct Model{
    theme widgets.Button
    scale widgets.Button
    density widgets.Button
    brand widgets.Button
    disabled widgets.Button
    check widgets.Checkbox
    toggle widgets.Switch
    radio_a widgets.Radio
    radio_b widgets.Radio
    slider widgets.Slider
    stepper widgets.Stepper
    tabs widgets.Tabs
    select_ctrl widgets.Select
    select_origin layout.Rect
    select_popup_armed bool
    transitions []widgets.PaintTransition
    switch_motion widgets.Tween
    popup_motion widgets.Tween
    clock time.Instant
    reduced_motion bool
    theme_index int
    text_scale f64
    density_scale f64
    appearance_dirty bool
    badge widgets.Badge
    divider widgets.Divider
    card widgets.Card
    list widgets.ListBox
    input widgets.Editor
    invalid widgets.Editor
    read_only widgets.Editor
    area widgets.Editor
    progress widgets.Progress
    scroll widgets.Scroll
    context draw.Context
    icon draw.Image
    switcher widgets.StyleSwitcher
    theme_label widgets.StyledLabel
    scale_label widgets.StyledLabel
    density_label widgets.StyledLabel
    brand_label widgets.StyledLabel
    disabled_label widgets.StyledLabel
    check_label widgets.StyledLabel
    toggle_label widgets.StyledLabel
    radio_a_label widgets.StyledLabel
    radio_b_label widgets.StyledLabel
    stepper_label widgets.StyledLabel
    badge_label widgets.StyledLabel
    divider_label widgets.StyledLabel
    card_label widgets.StyledLabel
    tab_label widgets.StyledLabel
    tab_2_label widgets.StyledLabel
    tab_3_label widgets.StyledLabel
    select_label widgets.StyledLabel
    option_auto widgets.StyledLabel
    option_manual widgets.StyledLabel
    option_locked widgets.StyledLabel
    list_label widgets.StyledLabel
    list_2_label widgets.StyledLabel
    list_3_label widgets.StyledLabel
    list_4_label widgets.StyledLabel
}
fn (m $&Model) motion_style(id int, base &widgets.ControlStyle, state int) widgets.ControlStyle{
    now := m.clock
    reduced := m.reduced_motion
    motion := $&m.transitions[id]
    << motion.style(base, state, now, reduced) >>>
}
fn (m $&Model) tick(view $&widgets.View, now time.Instant) int {
    m.clock = now
    reduced := m.reduced_motion
    for id in 1:m.transitions.len{
        motion := $&m.transitions[id]
        if reduced && motion.is_animating() {motion.finish()
            view.mark_paint(id) >>> }
        else if motion.advance(now) >>> {view.mark_paint(id) >>> }
    }
    $selected := 0.0
    if m.toggle.value() {selected = 1.0}
    switch_motion := $&m.switch_motion
    before_switch := switch_motion.value()
    switch_motion.retarget(selected, now, time.milliseconds(180) >>>, reduced) >>>
    if before_switch != switch_motion.value() {view.mark_paint(32) >>> }
    $opened := 0.0
    if m.select_ctrl.is_open() {opened = 1.0}
    popup_motion := $&m.popup_motion
    before_popup := popup_motion.value()
    $popup_duration := time.milliseconds(130) >>>
    if opened == 0.0 {popup_duration = time.milliseconds(95) >>> }
    popup_motion.retarget(opened, now, popup_duration, reduced) >>>
    if before_popup != popup_motion.value() {view.mark_paint(1) >>> }
    input := $&m.input
    if input.tick(now, reduced) >>> {view.mark_paint(12) >>> }
    invalid := $&m.invalid
    if invalid.tick(now, reduced) >>> {view.mark_paint(13) >>> }
    read_only := $&m.read_only
    if read_only.tick(now, reduced) >>> {view.mark_paint(14) >>> }
    area := $&m.area
    if area.tick(now, reduced) >>> {view.mark_paint(15) >>> }
    << 0
}
fn (m &Model) next_frame(now time.Instant) time.Instant{
    if m.switch_motion.is_animating() || m.popup_motion.is_animating() { << now.add(time.milliseconds(16) >>>) >>> }
    for motion in m.transitions{if motion.is_animating() { << now.add(time.milliseconds(16) >>>) >>> }}
    $deadline := time.zero_instant()
    for next in[m.input.next_caret_tick(now, m.reduced_motion) >>>, m.invalid.next_caret_tick(now, m.reduced_motion) >>>,
    m.read_only.next_caret_tick(now, m.reduced_motion) >>>, m.area.next_caret_tick(now, m.reduced_motion) >>>] {
        if !next.is_zero() &&(deadline.is_zero() || next.before(deadline)) {deadline = next}
    }
    << deadline
}
fn (m &Model) next_event(ech chan ui.Event) ui.Event{
    deadline := m.next_frame(time.instant()) >>>
    while true {
        event := ui.poll_chan(ech)
        if event.kind != ui.EV_NONE{ << event}
        if !deadline.is_zero() && !time.instant().before(deadline) { << event}
        pause := time.milliseconds(8) >>>
        pause.sleep()
    }
    << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
}
fn (m $&Model) measure_node(id int, s &widgets.Styles) layout.Size{
    if id == 4 {control := m.theme.clone()
        label := $&m.theme_label
        << control.measure_styled(label, s) >>> }
    if id == 5 {control := m.scale.clone()
        label := $&m.scale_label
        << control.measure_styled(label, s) >>> }
    if id == 6 {control := m.density.clone()
        label := $&m.density_label
        << control.measure_styled(label, s) >>> }
    if id == 8 {control := m.brand.clone()
        label := $&m.brand_label
        << control.measure_icon_styled(label, s) >>> }
    if id == 9 {control := m.disabled.clone()
        label := $&m.disabled_label
        << control.measure_styled(label, s) >>> }
    if id == 10 {control := m.check.clone()
        label := $&m.check_label
        << control.measure_styled(label, s) >>> }
    if id == 11 {control := m.progress.clone()
        << control.measure_styled(s) >>> }
    if id == 12 {control := $&m.input
        << control.measure_styled(s) >>> }
    if id == 13 {control := $&m.invalid
        << control.measure_styled(s) >>> }
    if id == 14 {control := $&m.read_only
        << control.measure_styled(s) >>> }
    if id == 15 {control := $&m.area
        << control.measure_styled(s) >>> }
    if id == 32 {control := m.toggle.clone()
        label := $&m.toggle_label
        << control.measure_styled(label, s) >>> }
    if id == 33 {control := m.radio_a.clone()
        label := $&m.radio_a_label
        << control.measure_styled(label, s) >>> }
    if id == 34 {control := m.radio_b.clone()
        label := $&m.radio_b_label
        << control.measure_styled(label, s) >>> }
    if id == 35 {control := m.slider.clone()
        << control.measure_styled(s) >>> }
    if id == 36 {control := m.stepper.clone()
        label := $&m.stepper_label
        << control.measure_styled(label, s) >>> }
    if id == 37 {control := m.badge.clone()
        label := $&m.badge_label
        << control.measure_styled(label, s) >>> }
    if id == 38 {control := m.divider.clone()
        label := $&m.divider_label
        << control.measure_labeled_styled(label, s) >>> }
    if id == 40 {control := m.tabs.clone()
        label := $&m.tab_label
        << control.measure_styled(label, s) >>> }
    if id == 41 {control := m.select_ctrl.clone()
        label := $&m.select_label
        << control.measure_styled(label, s) >>> }
    if id == 42 {control := m.card.clone()
        label := $&m.card_label
        << control.measure_header_styled(label, s) >>> }
    if id == 43 {control := m.list.clone()
        label := $&m.list_label
        << control.measure_styled(label, s) >>> }
    << layout.Size{width: 0.0, height: 0.0}
}
fn (m $&Model) measure_styled(id int, s &widgets.Styles) layout.Size{
    << m.measure_node(id, s) >>> (err) {eprintln(err.msg())
        << layout.Size{width: - 1.0, height: - 1.0}}
}
fn (m $&Model) draw_node(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) int {
    if id == 4 {target := $&m.theme
        target.set_bounds(b) >>>
        $control := m.theme.clone()
        base := control.style_or(s)
        appearance := m.motion_style(4, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.theme_label
        control.paint_styled(f, label, s) >>> }
    if id == 5 {target := $&m.scale
        target.set_bounds(b) >>>
        $control := m.scale.clone()
        base := control.style_or(s)
        appearance := m.motion_style(5, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.scale_label
        control.paint_styled(f, label, s) >>> }
    if id == 6 {target := $&m.density
        target.set_bounds(b) >>>
        $control := m.density.clone()
        base := control.style_or(s)
        appearance := m.motion_style(6, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.density_label
        control.paint_styled(f, label, s) >>> }
    if id == 8 {target := $&m.brand
        target.set_bounds(b) >>>
        $control := m.brand.clone()
        base := control.style_or(s)
        appearance := m.motion_style(8, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        icon := m.icon
        label := $&m.brand_label
        control.paint_icon_styled(f, label, &icon, s) >>> }
    if id == 9 {target := $&m.disabled
        target.set_bounds(b) >>>
        $control := m.disabled.clone()
        base := control.style_or(s)
        appearance := m.motion_style(9, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.disabled_label
        control.paint_styled(f, label, s) >>> }
    if id == 10 {target := $&m.check
        target.set_bounds(b) >>>
        $control := m.check.clone()
        base := control.style_or(s)
        appearance := m.motion_style(10, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.check_label
        control.paint_styled(f, label, s) >>> }
    if id == 12 {
        now := m.clock
        reduced := m.reduced_motion
        $motion := m.transitions[12]
        control := $&m.input
        control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
        m.transitions[12] = motion}
    if id == 13 {
        now := m.clock
        reduced := m.reduced_motion
        $motion := m.transitions[13]
        control := $&m.invalid
        control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
        m.transitions[13] = motion}
    if id == 14 {
        now := m.clock
        reduced := m.reduced_motion
        $motion := m.transitions[14]
        control := $&m.read_only
        control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
        m.transitions[14] = motion}
    if id == 15 {
        now := m.clock
        reduced := m.reduced_motion
        $motion := m.transitions[15]
        control := $&m.area
        control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
        m.transitions[15] = motion}
    if id == 11 {control := $&m.progress
        control.set_bounds(b) >>>
        control.paint_styled(f, s) >>> }
    if id == 32 {target := $&m.toggle
        target.set_bounds(b) >>>
        $control := m.toggle.clone()
        base := control.style_or(s)
        appearance := m.motion_style(32, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        position := m.switch_motion.value()
        label := $&m.toggle_label
        control.paint_position_styled(f, label, s, position) >>> }
    if id == 33 {target := $&m.radio_a
        target.set_bounds(b) >>>
        $control := m.radio_a.clone()
        base := control.style_or(s)
        appearance := m.motion_style(33, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.radio_a_label
        control.paint_styled(f, label, s) >>> }
    if id == 34 {target := $&m.radio_b
        target.set_bounds(b) >>>
        $control := m.radio_b.clone()
        base := control.style_or(s)
        appearance := m.motion_style(34, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.radio_b_label
        control.paint_styled(f, label, s) >>> }
    if id == 35 {target := $&m.slider
        target.set_bounds(b) >>>
        $control := m.slider.clone()
        base := control.style_or(s)
        appearance := m.motion_style(35, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        control.paint_styled(f, s) >>> }
    if id == 36 {target := $&m.stepper
        target.set_bounds(b) >>>
        $control := m.stepper.clone()
        base := control.style_or(s)
        appearance := m.motion_style(36, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.stepper_label
        control.paint_styled(f, label, s) >>> }
    if id == 37 {target := $&m.badge
        target.set_bounds(b) >>>
        control := m.badge.clone()
        label := $&m.badge_label
        control.paint_styled(f, label, s) >>> }
    if id == 38 {target := $&m.divider
        target.set_bounds(b) >>>
        control := m.divider.clone()
        label := $&m.divider_label
        control.paint_labeled_styled(f, label, s) >>> }
    if id == 40 {target := $&m.tabs
        target.set_bounds(b) >>>
        control := m.tabs.clone()
        control.paint_box_styled(f, s) >>>
        l0 := $&m.tab_label
        control.paint_tab_styled(f, 0, l0, s) >>>
        l1 := $&m.tab_2_label
        control.paint_tab_styled(f, 1, l1, s) >>>
        l2 := $&m.tab_3_label
        control.paint_tab_styled(f, 2, l2, s) >>> }
    if id == 41 {target := $&m.select_ctrl
        target.set_bounds(b) >>>
        $control := m.select_ctrl.clone()
        base := control.style_or(s)
        appearance := m.motion_style(41, &base, control.visual_state()) >>>
        control.set_style(&appearance) >>>
        label := $&m.select_label
        control.paint_styled(f, label, s) >>> }
    if id == 42 {target := $&m.card
        target.set_bounds(b) >>>
        control := m.card.clone()
        label := $&m.card_label
        control.paint_header_styled(f, label, s) >>>
        demo.text(&m.context, f, 14.0 * s.density, 42.0 * s.density, 11.0 * s.text_scale, s.button.palette.muted, "Card body") >>> }
    if id == 43 {target := $&m.list
        target.set_bounds(b) >>>
        control := m.list.clone()
        control.paint_box_styled(f, s) >>>
        r0 := $&m.list_label
        control.paint_item_styled(f, 0, r0, s) >>>
        r1 := $&m.list_2_label
        control.paint_item_styled(f, 1, r1, s) >>>
        r2 := $&m.list_3_label
        control.paint_item_styled(f, 2, r2, s) >>>
        r3 := $&m.list_4_label
        control.paint_item_styled(f, 3, r3, s) >>> }
    if id == 2 {
        demo.text(&m.context, f, 0.0, 0.0, 24.0, s.button.palette.foreground, "A theme that reaches every control") >>>
        demo.text(&m.context, f, 0.0, 33.0, 13.0, s.button.palette.muted, "Light / dark / contrast · typography · density · local overrides · no idle redraw") >>>
    }
    if id >= 18 && id <= 29 {
        f.fill_rect(0.0, 0.0, b.width, b.height, s.input.palette.normal) >>>
        demo.text(&m.context, f, 12.0, 5.0, 14.0, s.input.palette.foreground, "Scrollable item " + str(id - 17) + "   —   wheel, drag the thumb, or Page Down") >>>
    }
    if id == 30 {
        demo.text(&m.context, f, 0.0, 0.0, 12.0, s.button.palette.muted, "The green button keeps its own font and palette. Error and read-only fields are distinct states.") >>>
        demo.text(&m.context, f, 0.0, 21.0, 12.0, s.button.palette.muted, "Tab / Shift+Tab to move focus · copy from read-only text · Escape to quit") >>>
    }
    << 0
}
fn (m $&Model) paint_styled(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) bool {
    m.draw_node(id, b, s, f) >>> (err) {eprintln(err.msg())
        << false}
    << true
}
fn (m $&Model) overlay_styled(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) bool {
    if id == 16 {control := $&m.scroll
        control.paint_scrollbar(f, s) >>> (err) {eprintln(err.msg())
            << false}}
    if id == 1 &&(m.select_ctrl.is_open() || m.popup_motion.value() > 0.0) {
        m.paint_select_popup(s, f) >>> (err) {eprintln(err.msg())
            << false}
    }
    << true
}
// Root overlay keeps the popup above every sibling and outside the button's box.
fn (m $&Model) paint_select_popup(s &widgets.Styles, f $&draw.Frame) int {
    $control := m.select_ctrl.clone()
    control.set_open(true)
    opacity := m.popup_motion.value()
    if opacity <= 0.0 { << 0}
    base := control.style_or(s)
    appearance := base.with_opacity(opacity) >>>
    control.set_style(&appearance) >>>
    popup := control.popup_bounds(s)
    $offset := - 4.0 *(1.0 - opacity)
    if popup.y < 0.0 {offset = 4.0 *(1.0 - opacity)}
    f.push() >>>
    f.translate(m.select_origin.x, m.select_origin.y + offset) >>>
    control.paint_popup_box_styled(f, s) >>>
    auto_label := $&m.option_auto
    control.paint_option_styled(f, 0, auto_label, s) >>>
    manual_label := $&m.option_manual
    control.paint_option_styled(f, 1, manual_label, s) >>>
    locked_label := $&m.option_locked
    control.paint_option_styled(f, 2, locked_label, s) >>>
    f.pop() >>>
    << 0
}
// The popup is an overlay, so route its pointer sequence before normal tree hits.
fn (m $&Model) dispatch_input(view $&widgets.View, event &ui.InputEvent)[]widgets.Action{
    was_open := m.select_ctrl.is_open()
    pointer := event.kind == ui.EV_POINTER_DOWN || event.kind == ui.EV_POINTER_UP ||
    event.kind == ui.EV_POINTER_MOVE || event.kind == ui.EV_POINTER_SCROLL
    if pointer &&(was_open || m.select_popup_armed) {
        local := view.local_input(41, event) >>>
        styles := view.styles_for(41) >>>
        pop := m.select_ctrl.popup_bounds(&styles)
        if pop.contains(local.x, local.y) || m.select_popup_armed{
            if event.kind == ui.EV_POINTER_DOWN && event.button == ui.BUTTON_LEFT{m.select_popup_armed = true}
            control := $&m.select_ctrl
            action := control.input(&local) >>>
            view.set_pointer_cursor(ui.CURSOR_HAND) >>>
            if event.kind == ui.EV_POINTER_UP{m.select_popup_armed = false}
            view.mark_paint(41) >>>
            view.mark_paint(1) >>>
            <<[action]
        }
    }
    if event.kind == ui.EV_POINTER_CANCEL{m.select_popup_armed = false}
    actions := widgets.dispatch(view, event, m) >>>
    if was_open || m.select_ctrl.is_open() {view.mark_paint(1) >>> }
    << actions
}
fn (m $&Model) dispatch_event(view $&widgets.View, event &ui.Event)[]widgets.Action{
    if ui.is_input_event(event.kind) {
        input := ui.input_of(event) >>>
        << m.dispatch_input(view, &input) >>>
    }
    was_open := m.select_ctrl.is_open()
    actions := widgets.dispatch_event(view, event, m) >>>
    m.select_popup_armed = false
    if was_open && !m.select_ctrl.is_open() {view.mark_paint(1) >>> }
    << actions
}
fn (m $&Model) input(id int, kind int, event &ui.InputEvent) widgets.Action{
    if id == 4 {control := $&m.theme
        << control.route(kind, event) >>> }
    if id == 5 {control := $&m.scale
        << control.route(kind, event) >>> }
    if id == 6 {control := $&m.density
        << control.route(kind, event) >>> }
    if id == 8 {control := $&m.brand
        << control.route(kind, event) >>> }
    if id == 9 {control := $&m.disabled
        << control.route(kind, event) >>> }
    if id == 10 {control := $&m.check
        << control.route(kind, event) >>> }
    if id == 12 {control := $&m.input
        << control.route(kind, event) >>> }
    if id == 13 {control := $&m.invalid
        << control.route(kind, event) >>> }
    if id == 14 {control := $&m.read_only
        << control.route(kind, event) >>> }
    if id == 15 {control := $&m.area
        << control.route(kind, event) >>> }
    if id == 16 {control := $&m.scroll
        << control.route(kind, event) >>> }
    if id == 32 {control := $&m.toggle
        << control.route(kind, event) >>> }
    if id == 33 {control := $&m.radio_a
        << control.route(kind, event) >>> }
    if id == 34 {control := $&m.radio_b
        << control.route(kind, event) >>> }
    if id == 35 {control := $&m.slider
        << control.route(kind, event) >>> }
    if id == 36 {control := $&m.stepper
        << control.route(kind, event) >>> }
    if id == 40 {control := $&m.tabs
        << control.route(kind, event) >>> }
    if id == 41 {control := $&m.select_ctrl
        << control.route(kind, event) >>> }
    if id == 43 {control := $&m.list
        << control.route(kind, event) >>> }
    << widgets.Action{kind: 0, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
}
fn (m $&Model) place(view $&widgets.View) int {
    select_bounds := view.node_bounds(41) >>>
    m.select_origin = select_bounds
    select_styles := view.styles_for(41) >>>
    select_control := $&m.select_ctrl
    select_control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: select_bounds.width, height: select_bounds.height}) >>>
    select_control.apply_styles(&select_styles) >>>
    popup := select_control.popup_bounds(&select_styles)
    window_bounds := view.node_bounds(1) >>>
    below := window_bounds.y + window_bounds.height - select_bounds.y - select_bounds.height
    above := select_bounds.y - window_bounds.y
    select_control.set_popup_above(below < popup.height + 2.0 * select_styles.density && above > below)
    list_bounds := view.node_bounds(43) >>>
    list_styles := view.styles_for(43) >>>
    list_control := $&m.list
    list_control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: list_bounds.width, height: list_bounds.height}) >>>
    list_control.apply_styles(&list_styles) >>>
    input := $&m.input
    widgets.place_editor(view, input) >>>
    invalid := $&m.invalid
    widgets.place_editor(view, invalid) >>>
    read_only := $&m.read_only
    widgets.place_editor(view, read_only) >>>
    area := $&m.area
    widgets.place_editor(view, area) >>>
    bounds := view.node_bounds(16) >>>
    styles := view.styles_for(16) >>>
    control := $&m.scroll
    control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: bounds.width, height: bounds.height}) >>>
    control.apply_styles(&styles) >>>
    view.set_scroll(16, 0.0, control.offset()) >>>
    << 0
}
fn (m $&Model) native_event(view $&widgets.View, event &ui.Event) int {
    input := $&m.input
    action_12 := input.event(event) >>>
    if action_12.needs_paint{view.mark_paint(12) >>> }
    invalid := $&m.invalid
    action_13 := invalid.event(event) >>>
    if action_13.needs_paint{view.mark_paint(13) >>> }
    read_only := $&m.read_only
    action_14 := read_only.event(event) >>>
    if action_14.needs_paint{view.mark_paint(14) >>> }
    area := $&m.area
    action_15 := area.event(event) >>>
    if action_15.needs_paint{view.mark_paint(15) >>> }
    << 0
}
fn (m $&Model) acknowledge() {
    theme := $&m.theme
    theme.painted()
    scale := $&m.scale
    scale.painted()
    density := $&m.density
    density.painted()
    brand := $&m.brand
    brand.painted()
    disabled := $&m.disabled
    disabled.painted()
    check := $&m.check
    check.painted()
    input := $&m.input
    input.painted()
    invalid := $&m.invalid
    invalid.painted()
    read_only := $&m.read_only
    read_only.painted()
    area := $&m.area
    area.painted()
    progress := $&m.progress
    progress.painted()
    scroll := $&m.scroll
    scroll.painted()
    toggle := $&m.toggle
    toggle.painted()
    radio_a := $&m.radio_a
    radio_a.painted()
    radio_b := $&m.radio_b
    radio_b.painted()
    slider := $&m.slider
    slider.painted()
    stepper := $&m.stepper
    stepper.painted()
    tabs := $&m.tabs
    tabs.painted()
    select_ctrl := $&m.select_ctrl
    select_ctrl.painted()
    badge := $&m.badge
    badge.painted()
    divider := $&m.divider
    divider.painted()
    card := $&m.card
    card.painted()
    list := $&m.list
    list.painted()
}
fn (m $&Model) cleanup() {
    icon := $&m.icon
    icon.dispose() >>> (err) {eprintln(err.msg())
        << }
    theme_label := $&m.theme_label
    theme_label.dispose()
    scale_label := $&m.scale_label
    scale_label.dispose()
    density_label := $&m.density_label
    density_label.dispose()
    brand_label := $&m.brand_label
    brand_label.dispose()
    disabled_label := $&m.disabled_label
    disabled_label.dispose()
    check_label := $&m.check_label
    check_label.dispose()
    toggle_label := $&m.toggle_label
    toggle_label.dispose()
    radio_a_label := $&m.radio_a_label
    radio_a_label.dispose()
    radio_b_label := $&m.radio_b_label
    radio_b_label.dispose()
    stepper_label := $&m.stepper_label
    stepper_label.dispose()
    badge_label := $&m.badge_label
    badge_label.dispose()
    divider_label := $&m.divider_label
    divider_label.dispose()
    card_label := $&m.card_label
    card_label.dispose()
    tab_label := $&m.tab_label
    tab_label.dispose()
    tab_2_label := $&m.tab_2_label
    tab_2_label.dispose()
    tab_3_label := $&m.tab_3_label
    tab_3_label.dispose()
    select_label := $&m.select_label
    select_label.dispose()
    option_auto := $&m.option_auto
    option_auto.dispose()
    option_manual := $&m.option_manual
    option_manual.dispose()
    option_locked := $&m.option_locked
    option_locked.dispose()
    list_label := $&m.list_label
    list_label.dispose()
    list_2_label := $&m.list_2_label
    list_2_label.dispose()
    list_3_label := $&m.list_3_label
    list_3_label.dispose()
    list_4_label := $&m.list_4_label
    list_4_label.dispose()
    input := $&m.input
    input.dispose()
    invalid := $&m.invalid
    invalid.dispose()
    read_only := $&m.read_only
    read_only.dispose()
    area := $&m.area
    area.dispose()
}
fn leaf(view $&widgets.View, parent int, width f64, height f64) int {
    style := layout.box_style(layout.BOX_LEAF)
    << view.add(parent, &style, &layout.Size{width: width, height: height}) >>>
}
fn brand_scope(view $&widgets.View) int {
    $brand := widgets.light_styles()
    brand.button.palette.normal = draw.rgb(10, 91, 69)
    brand.button.palette.hovered = draw.rgb(17, 120, 90)
    brand.button.palette.pressed = draw.rgb(7, 65, 49)
    brand.button.palette.foreground = draw.rgb(255, 255, 255)
    brand.button.font.size = 17.0
    brand.button.font.weight = 600
    brand.button.inherit_font = false
    brand.button.radius = 18.0
    brand.button.icon_size = 22.0
    brand.button.icon_placement = widgets.ICON_TRAILING
    $hover := widgets.state_paint(widgets.STATE_HOVERED)
    hover.unless = widgets.STATE_DISABLED
    hover.fields = widgets.PAINT_FOREGROUND | widgets.PAINT_BORDER
    hover.foreground = draw.rgb(209, 250, 229)
    hover.border = draw.rgb(110, 231, 183)
    brand.button.states =[hover]
    brand.button.shadow = draw.rgba(0, 0, 0, 28)
    brand.button.shadow_y = 2.0
    brand.button.shadow_blur = 6.0
    view.set_style_scope(8, &brand) >>>
    << 0
}
fn scene(ech chan ui.Event) int {
    ready := demo.ready(ech) >>>
    if ready.kind == ui.EV_EXIT{ << 0}
    identity := ui.canvas_of(&ready) >>>
    context := draw.context_of(&ready) >>>
    host := widgets.Host{context: context, identity: identity}
    $column := layout.box_style(layout.BOX_COLUMN)
    column.padding = layout.insets(22.0) >>>
    column.gap = 10.0
    column.cross_alignment = layout.CROSS_STRETCH
    $view := host.view(&column, draw.rgb(20, 25, 34)) >>>
    _ := leaf($&view, 1, 400.0, 56.0) >>>  // 2 header
    $row := layout.box_style(layout.BOX_ROW)
    row.gap = 12.0
    row.cross_alignment = layout.CROSS_CENTER
    _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 3 toolbar
    for i in 0:3 {_ := leaf($&view, 3, 0.0, 0.0) >>> }  // 4..6
    _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 7 controls
    for i in 0:3 {_ := leaf($&view, 7, 0.0, 0.0) >>> }  // 8..10
    _ := leaf($&view, 1, 300.0, 12.0) >>>  // 11 progress
    for i in 0:4 {_ := leaf($&view, 1, 300.0, 0.0) >>> }  // 12..15 editors
    $viewport := layout.box_style(layout.BOX_COLUMN)
    viewport.height = 84.0
    viewport.clip = true
    viewport.cross_alignment = layout.CROSS_STRETCH
    _ := view.add(1, &viewport, &layout.Size{width: 0.0, height: 0.0}) >>>  // 16 scroll
    $items := layout.box_style(layout.BOX_COLUMN)
    items.gap = 6.0
    items.cross_alignment = layout.CROSS_STRETCH
    _ := view.add(16, &items, &layout.Size{width: 0.0, height: 0.0}) >>>  // 17 items
    for i in 0:12 {_ := leaf($&view, 17, 300.0, 28.0) >>> }  // 18..29
    _ := leaf($&view, 1, 400.0, 42.0) >>>  // 30 footer
    _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 31 extended controls row 1
    for i in 0:6 {_ := leaf($&view, 31, 0.0, 0.0) >>> }  // 32..37: switch, radio_a, radio_b, slider, stepper, badge
    _ := leaf($&view, 1, 300.0, 0.0) >>>  // 38 labeled divider
    _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 39 extended controls row 2
    for i in 0:4 {_ := leaf($&view, 39, 0.0, 0.0) >>> }  // 40..43: tabs, select, card, list_box
    for id in[2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 30, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43] {view.set_boundary(id, true) >>> }
    for id in[4, 5, 6, 8, 10, 12, 13, 14, 15, 16, 32, 33, 34, 35, 36, 40, 41, 43] {view.set_input(id, true, true) >>> }
    view.set_capture_outside(16, true) >>>
    view.set_capture_outside(35, true) >>>
    for id in[4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43] {view.set_style_measure(id, true) >>> }
    empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
    $m := Model{theme: widgets.button(&identity, 4, &empty) >>>, scale: widgets.button(&identity, 5, &empty) >>>,
        density: widgets.button(&identity, 6, &empty) >>>, brand: widgets.button(&identity, 8, &empty) >>>,
        disabled: widgets.button(&identity, 9, &empty) >>>, check: widgets.checkbox(&identity, 10, &empty, true) >>>,
        toggle: widgets.switch_control(&identity, 32, &empty, true) >>>,
        radio_a: widgets.radio(&identity, 33, &empty, 0, true) >>>,
        radio_b: widgets.radio(&identity, 34, &empty, 1, false) >>>,
        slider: widgets.slider(&identity, 35, &empty, 0.0, 100.0, 64.0) >>>,
        stepper: widgets.stepper(&identity, 36, &empty, 0.0, 100.0, 5.0, 65.0) >>>,
        tabs: widgets.tabs(&identity, 40, &empty, 3, 0) >>>,
        select_ctrl: widgets.select_box(&identity, 41, &empty, 3, 0) >>>,
        select_origin: empty, select_popup_armed: false,
        transitions:[]widgets.PaintTransition{}, switch_motion: widgets.tween(1.0) >>>, popup_motion: widgets.tween(0.0) >>>,
        clock: time.zero_instant(), reduced_motion: false, theme_index: 0, text_scale: 1.0, density_scale: 1.0, appearance_dirty: true,
        badge: widgets.badge(&empty) >>>,
        divider: widgets.divider(&empty, widgets.AXIS_HORIZONTAL) >>>,
        card: widgets.card(&empty) >>>,
        list: widgets.list_box(&identity, 43, &empty, 4, 0) >>>,
        input: widgets.input(&context, &identity, 12, &empty, &"Editable input · 你好 Xu") >>>,
        invalid: widgets.input(&context, &identity, 13, &empty, &"Invalid value — custom error colors") >>>,
        read_only: widgets.input(&context, &identity, 14, &empty, &"Read-only · select and copy, edits are ignored") >>>,
        area: widgets.text_area(&context, &identity, 15, &empty, &"TextArea uses the same font, padding and selection theme.\nIME, preedit and caret geometry follow typography changes.") >>>,
        progress: widgets.progress(&empty, 0.64) >>>, scroll: widgets.scroll(&identity, 16, &empty, widgets.AXIS_VERTICAL, 402.0) >>>,
        context: context, icon: context.load_embedded_image(&"logo.png") >>>, switcher: widgets.style_switcher(),
        theme_label: widgets.styled_label(&context, &"Theme: dark / light / contrast"),
        scale_label: widgets.styled_label(&context, &"Text: 100% / 140%"),
        density_label: widgets.styled_label(&context, &"Density: normal / compact"),
        brand_label: widgets.styled_label(&context, &"Local green"),
        disabled_label: widgets.styled_label(&context, &"Disabled"),
        check_label: widgets.styled_label(&context, &"Checkbox"),
        toggle_label: widgets.styled_label(&context, &"Switch"),
        radio_a_label: widgets.styled_label(&context, &"Radio A"),
        radio_b_label: widgets.styled_label(&context, &"Radio B"),
        stepper_label: widgets.styled_label(&context, &"65"),
        badge_label: widgets.styled_label(&context, &"Active"),
        divider_label: widgets.styled_label(&context, &"Navigation & Data Components"),
        card_label: widgets.styled_label(&context, &"Card Panel"),
        tab_label: widgets.styled_label(&context, &"Overview"),
        tab_2_label: widgets.styled_label(&context, &"Tokens"),
        tab_3_label: widgets.styled_label(&context, &"Themes"),
        select_label: widgets.styled_label(&context, &"Option: Auto"),
        option_auto: widgets.styled_label(&context, &"Auto"),
        option_manual: widgets.styled_label(&context, &"Manual"),
        option_locked: widgets.styled_label(&context, &"Locked"),
        list_label: widgets.styled_label(&context, &"1 · Buttons"),
        list_2_label: widgets.styled_label(&context, &"2 · Editors"),
        list_3_label: widgets.styled_label(&context, &"3 · Surfaces"),
        list_4_label: widgets.styled_label(&context, &"4 · Controls")}
    for i in 0:44 {m.transitions.push(widgets.paint_transition() >>>)}
    for id in[4, 5, 6, 8, 10, 32, 33, 34, 36, 40, 41, 43] {view.set_cursor(id, ui.CURSOR_HAND) >>> }
    for id in[12, 13, 14, 15] {view.set_cursor(id, ui.CURSOR_TEXT) >>> }
    view.set_cursor(35, ui.CURSOR_RESIZE_HORIZONTAL) >>>
    badge_ref := $&m.badge
    badge_ref.set_selected(true)
    disabled := $&m.disabled
    disabled.set_enabled(false)
    invalid := $&m.invalid
    invalid.set_invalid(true)
    read_only := $&m.read_only
    read_only.set_read_only(true) >>>
    apply_appearance($&m, $&view) >>>
    brand_scope($&view) >>>
    dispatcher := register_actions(&m, &view) >>>
    $width := 960.0
    $height := 820.0
    $event := ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
    // Drain input bursts before painting. Native text snapshots already hold
    // the latest revision; rendering each queued key would fill the frame queue.
    ui.request_canvas_preferences(&identity) >>>
    while true {
        if event.kind == ui.EV_NONE{
            apply_appearance($&m, $&view) >>>
            m.tick($&view, time.instant()) >>>
            constraints := layout.tight(width, height) >>>
            _ := widgets.layout_styled($&view, &constraints, $&m) >>>
            m.place($&view) >>>
            if widgets.present_styled($&view, &constraints, $&m) >>> {m.acknowledge()}
            event = m.next_event(ech)
        }
        if event.kind == ui.EV_EXIT{ <- }
        if event.window_id == identity.window_id{
            if event.kind == ui.EV_CANVAS_CLOSED || event.kind == ui.EV_CLOSED{ <- }
            if event.kind == ui.EV_CANVAS_METRICS{metrics := ui.metrics_of(&event) >>>
                width = metrics.width
                height = metrics.height}
            if event.kind == ui.EV_FOCUSED{ui.request_canvas_preferences(&identity) >>> }
            if event.kind == ui.EV_CANVAS_PREFERENCES{
                preferences := ui.canvas_preferences_of(&event) >>>
                if preferences.identity.canvas_id == identity.canvas_id && preferences.identity.generation == identity.generation{
                    m.reduced_motion = preferences.reduced_motion
                    view.mark_paint(1) >>>
                }
            }
            popup_was_open := m.select_ctrl.is_open()
            actions := m.dispatch_event($&view, &event) >>>
            m.native_event($&view, &event) >>>
            for action in actions{_ := dispatcher.dispatch(&action, $&m, $&view) >>> }
            if ui.is_input_event(event.kind) {input := ui.input_of(&event) >>>
                if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE && !popup_was_open{
                    view.dispose()
                    if demo.alive(&identity) {m.cleanup()}
                    demo.quit() >>>
                    << 0
                }}
        }
        event = ui.poll_chan(ech)
    }
    view.dispose()
    if demo.alive(&identity) {m.cleanup()}
    << 0
}
fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
        << }}
fn main() int {
    $app := demo.app("Xu UI / Style Gallery", 960, 820) >>> (err) {eprintln(err.msg())
        << 1}
    xu worker(app.event_ch)
    << app.run() >>> (err) {eprintln(err.msg())
        << 1}
}
16_ui_webview/component_workshop/main.xu

所需 SDK:Xu 0.10.13-dev.3 · 完整工程 · 下载源码 · events.xu · events_tools.xu · layout.xu · model.xu · style.xu · view.xu

Xumain.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
}
Xuevents.xu
@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
}
Xuevents_tools.xu
@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(&notice) >>> }
    << 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()}
    << ""
}
Xumodel.xu
@main

#ui/widgets
#time
#strconv

struct Page{group int
    ids []int}
// A state transition may reconfigure Workshop while these control IDs are in
// use. Copy the IDs; Screen keeps ownership of the actual controls.

fn (m &Workshop) page_snapshot(index int) Page{
    group := m.pages[index].group
    $ids :=[]int {}
    for id in m.pages[index].ids{ids.push(id)}
    << Page{group: group, ids: ids}
}

struct Workshop{
    controls_dirty bool
    field_options_page int
    appearance_dirty bool
    tree_options_dirty bool
    field_options_dirty bool
    spinner_options_dirty bool
    popover_options_dirty bool
    tooltip_side int
    range_push bool
    range_vertical bool
    range_commit bool
    split_vertical bool
    split_collapsed bool
    menu_stays_open bool
    menu_export_disabled bool
    chart_kind int
    chart_paused bool
    group_vertical bool
    group_joined bool
    group_disabled bool
    pages []Page
    names []string
    navigation int
    language int
    preview int
    title int
    caption int
    status int
    theme int
    density int
    scale int
    state int
    custom int
    reduced int
    motion int
    focus int
    tools []int
    selected int
    customized bool
    guided bool
    slow bool
    variant int
    revision int
    completed int
    running bool
    failure bool
    pending_before bool
    pagination_error bool
    preferences_name string
    preferences_history bool
    unread int
    online bool
    checksum int
    deadline time.Instant
}

fn create(s $&widgets.Screen) Workshop{
    labels := names()
    $pages :=[]Page{}
    preview := s.scroll_area(widgets.AXIS_VERTICAL, 760.0) >>>
    for index in 0:labels.len{page := new_page(s, index) >>>
        s.set_parent(page.group, preview) >>>
        pages.push(page)}
    title := s.label("", 25.0, false) >>>
    caption := s.label("", 13.0, true) >>>
    s.set_label_wrapped(caption, true) >>>
    status := s.label("Hover · press · Tab · arrows · Escape / 使用真实鼠标与键盘状态", 12.0, true) >>>
    s.set_label_wrapped(status, true) >>>
    navigation := s.list_box(&labels, 5) >>>
    language := s.select_box(&["中文", "English", "Custom"], 1) >>>
    _ := s.tooltip(language, "Component language · 组件默认文案与格式") >>>
    tools :=[s.button("Option 1") >>>, s.button("Option 2") >>>, s.button("Option 3") >>>]
    for tool in tools{s.set_parent(tool, preview) >>> }
    << Workshop{controls_dirty: true, field_options_page: 5, appearance_dirty: true, tree_options_dirty: false, field_options_dirty: false, spinner_options_dirty: false, popover_options_dirty: false, tooltip_side: widgets.OVERLAY_TOP, range_push: false, range_vertical: false, range_commit: false, split_vertical: false, split_collapsed: false, menu_stays_open: false, menu_export_disabled: false, chart_kind: 0, chart_paused: false, group_vertical: false, group_joined: true, group_disabled: false, language: language, pages: pages, names: labels, navigation: navigation, preview: preview, title: title, caption: caption, status: status,
        theme: s.select_box(&["Light 亮色", "Dark 暗色", "Contrast 对比"], 1) >>>,
        density: s.select_box(&["Normal 常规", "Compact 紧凑", "Touch 触控"], 0) >>>,
        scale: s.select_box(&["Text 100%", "Text 140%", "Text 200%"], 0) >>>,
        state: s.select_box(&["Normal 普通", "Disabled 禁用", "Read only 只读", "Invalid 错误"], 0) >>>,
        custom: s.button("Default 默认") >>>, reduced: s.checkbox("Reduce 减少动效", false) >>>,
        motion: s.button("Motion 160ms") >>>, focus: s.button("Focus sample") >>>,
        tools: tools, selected: 5, customized: false, guided: true, slow: false,
        variant: 0, revision: 0, completed: 0, running: false, failure: false, pending_before: false, pagination_error: false, preferences_name: "XU workspace", preferences_history: true, unread: 12, online: true, checksum: 0, deadline: time.zero_instant()}
}

fn (m $&Workshop) apply_locale(s $&widgets.Screen) int {
    index := s.selected(m.language) >>>
    $locale := widgets.locale_en_us()
    if index != 1 {locale = widgets.locale_zh_cn()}
    if index == 2 {
        locale.set_text(widgets.TEXT_TODAY, "回到今天") >>>
        locale.set_text(widgets.TEXT_CLEAR, "移除日期") >>>
        locale.set_text(widgets.TEXT_DATE_PLACEHOLDER, "预约日期") >>>
        locale.set_text(widgets.TEXT_DATE_PATTERN, "{day}.{month}.{year}") >>>
        locale.set_text(widgets.TEXT_DECIMAL_SEPARATOR, ",") >>>
        locale.set_text(widgets.TEXT_GROUP_SEPARATOR, " ") >>>
        locale.set_weekdays(&["周日", "周一", "周二", "周三", "周四", "周五", "周六"]) >>>
    }
    s.set_locale(&locale) >>>
    pages := &m.pages
    pagination := &pages[25]
    sizes :=[10, 20, 50, 100]
    for i in 0:4 {s.set_option_text(pagination.ids[2], i, locale.count_text(widgets.TEXT_ITEMS_PER_PAGE, sizes[i]) >>>) >>> }
    m.update_pagination(s, false) >>>
    // Business copy is supplied by the app, never silently translated by the widget.
    english := index == 1
    m.names = names_locale(english)
    for i in 0:m.names.len {s.set_option_text(m.navigation, i, m.names[i]) >>> }
    $themes :=["亮色", "暗色", "高对比"]
    $densities :=["常规", "紧凑", "触控"]
    $scales :=["字号 100%", "字号 140%", "字号 200%"]
    $states :=["普通", "禁用", "只读", "错误"]
    $choices :=["工作区", "历史", "输出"]
    $segments :=["日", "周", "月"]
    $group_titles :=["独立操作", "单选", "多选"]
    $btn_samples :=["构建项目", "打开工作区 · 右侧图标", "保存修改 · 上方图标", "下载 SDK · 下方图标", "次要按钮", "描边按钮", "幽灵按钮", "危险操作", "轻量按钮"]
    $overlay_triggers :=["打开浮层", "聚焦或悬停查看帮助", "发送通知", "打开确认弹窗"]
    if english{
        themes =["Light", "Dark", "Contrast"]
        densities =["Normal", "Compact", "Touch"]
        scales =["Text 100%", "Text 140%", "Text 200%"]
        states =["Normal", "Disabled", "Read only", "Invalid"]
        choices =["Workspace", "History", "Output"]
        segments =["Day", "Week", "Month"]
        group_titles =["Actions", "Single", "Multiple"]
        btn_samples =["Build project", "Open workspace · trailing", "Save changes · above", "Download SDK · below", "Secondary", "Outline", "Ghost", "Danger", "Subtle"]
        overlay_triggers =["Open popover", "Focus or hover for help", "Enqueue notification", "Open confirmation"]
    }
    for i in 0:9 {s.set_text(m.pages[1].ids[i], btn_samples[i]) >>> }
    for i in 0:4 {s.set_text(m.pages[33 + i].ids[0], overlay_triggers[i]) >>> }
    for i in 0:3 {
        s.set_option_text(m.theme, i, themes[i]) >>>
        s.set_option_text(m.density, i, densities[i]) >>>
        s.set_option_text(m.scale, i, scales[i]) >>>
        s.set_option_text(m.pages[21].ids[0], i, choices[i]) >>>
        s.set_option_text(m.pages[22].ids[0], i, segments[i]) >>>
        s.set_text(m.pages[38].ids[3 + i], group_titles[i]) >>>
    }
    for i in 0:4 {s.set_option_text(m.state, i, states[i]) >>> }
    page := &m.pages[8]
    if english {
        s.set_text(page.ids[0], "Build project") >>>
        s.set_task_labels(page.ids[0], "Building", "Built · run again", "Retry build", "Build again") >>>
        s.set_text(m.reduced, "Reduce motion") >>>
        s.set_text(m.focus, "Focus sample") >>>
        s.set_text(m.pages[9].ids[0], "Keep generated files") >>>
        s.set_text(m.pages[10].ids[0], "Live preview") >>>
        s.set_text(m.pages[11].ids[0], "Use workspace settings") >>>
        s.set_text(m.pages[25].ids[4], "Go") >>>
        s.set_text(m.pages[28].ids[1], "Loading assets…") >>>
        s.set_text(m.pages[29].ids[1], "SECTION") >>>
        s.set_text(m.pages[30].ids[1], "Inbox") >>>
        s.set_text(m.pages[30].ids[4], "Synced") >>>
        s.set_text(m.pages[30].ids[9], "Workspace") >>>
        s.set_text(m.pages[31].ids[4], "Workspace configuration") >>>
        s.set_text(m.pages[31].ids[6], "Open workspace") >>>
        s.set_text(m.pages[33].ids[2], "Workspace preferences") >>>
        s.set_text(m.pages[33].ids[5], "Keep history") >>>
        s.set_text(m.pages[33].ids[6], "Cancel") >>>
        s.set_text(m.pages[33].ids[7], "Apply") >>>
        s.set_text(m.pages[36].ids[2], "Cancel") >>>
        s.set_text(m.pages[36].ids[3], "Apply changes") >>>
        s.set_text(m.pages[41].ids[5], "Open workspace") >>>
        s.set_text(m.pages[41].ids[6], "Refresh preview") >>>
        s.set_text(m.pages[45].ids[1], "Show password") >>>
        s.set_text(m.pages[45].ids[2], "Password") >>>
    } else {
        s.set_text(page.ids[0], "构建项目") >>>
        s.set_task_labels(page.ids[0], "正在构建", "已构建 · 再次运行", "重试构建", "再次构建") >>>
        s.set_text(m.reduced, "减少动效") >>>
        s.set_text(m.focus, "聚焦示例") >>>
        s.set_text(m.pages[9].ids[0], "保留生成产物") >>>
        s.set_text(m.pages[10].ids[0], "实时预览") >>>
        s.set_text(m.pages[11].ids[0], "使用工作区设置") >>>
        s.set_text(m.pages[25].ids[4], "跳转") >>>
        s.set_text(m.pages[28].ids[1], "正在加载资源…") >>>
        s.set_text(m.pages[29].ids[1], "章节分隔") >>>
        s.set_text(m.pages[30].ids[1], "收件箱") >>>
        s.set_text(m.pages[30].ids[4], "已同步") >>>
        s.set_text(m.pages[30].ids[9], "工作区") >>>
        s.set_text(m.pages[31].ids[4], "工作区配置") >>>
        s.set_text(m.pages[31].ids[6], "打开工作区") >>>
        s.set_text(m.pages[33].ids[2], "工作区偏好设置") >>>
        s.set_text(m.pages[33].ids[5], "保留历史记录") >>>
        s.set_text(m.pages[33].ids[6], "取消") >>>
        s.set_text(m.pages[33].ids[7], "应用") >>>
        s.set_text(m.pages[36].ids[2], "取消") >>>
        s.set_text(m.pages[36].ids[3], "应用更改") >>>
        s.set_text(m.pages[41].ids[5], "打开工作区") >>>
        s.set_text(m.pages[41].ids[6], "刷新预览") >>>
        s.set_text(m.pages[45].ids[1], "显示密码") >>>
        s.set_text(m.pages[45].ids[2], "密码") >>>
    }
    m.update_badges(s) >>>
    m.range_summary(s, false) >>>
    m.appearance_dirty = true
    $group_labels :=[["Undo", "Redo", "Save"],["Day", "Week", "Month"],["Bold", "Italic", "Underline"]]
    $type_labels :=["Line", "Area", "Bar", "Scatter", "Donut",
        "Step", "StackArea", "StackBar", "H-Bar", "Pie",
        "Rose", "Radar", "Gauge", "Bubble", "Histogram",
        "Boxplot", "Heatmap", "Candle", "Waterfall", "Funnel",
        "Spline", "SplineArea", "PolarBar", "Treemap", "Sankey",
        "Violin", "Bullet", "Lollipop", "Dumbbell", "Pareto"]
    if !english {
        group_labels =[["撤销", "重做", "保存"],["日", "周", "月"],["加粗", "斜体", "下划线"]]
        type_labels =["折线", "面积", "柱状", "散点", "环形",
            "阶梯", "堆叠面积", "堆叠柱状", "水平条形", "饼图",
            "玫瑰", "雷达", "仪表盘", "气泡", "直方图",
            "箱线", "热力", "K 线", "瀑布", "漏斗",
            "样条线", "样条面积", "极坐标环", "树图", "桑基",
            "小提琴", "子弹图", "棒棒糖", "哑铃", "帕累托"]
    }
    for mode in 0:3 {for i in 0:3 {s.set_button_group_label(m.pages[38].ids[mode],(i + 1) * 10, group_labels[mode][i]) >>> }}
    for r in 0:6 {
        gid := m.pages[39].ids[1 + r]
        for k in 0:5 {
            key := r * 5 + k + 1
            s.set_button_group_label(gid, key, type_labels[key - 1]) >>>
        }
    }
    series := chart_data_locale(m.chart_kind, m.revision, english)
    s.set_chart_series(m.pages[39].ids[0], &series) >>>
    translated := workshop_menu_items(english)
    for page_index in 42:45 {for item in translated{s.set_menu_item_label(m.pages[page_index].ids[0], item.key, item.label) >>> }}
    $menu_labels :=["Actions", "Right click here", "Save"]
    if !english {menu_labels =["操作", "右键打开菜单", "保存"]}
    for page_index in 42:45 {s.set_menu_label(m.pages[page_index].ids[0], menu_labels[page_index - 42]) >>> }
    m.controls_dirty = true

    << 0
}

fn max_int_local(a int, b int) int {if a > b{ << a}
    << b}

fn (m &Workshop) open_preferences(s $&widgets.Screen) int {
    pages := &m.pages
    page := &pages[33]
    s.set_value(page.ids[4], m.preferences_name) >>>
    s.set_toggle_value(page.ids[5], m.preferences_history) >>>
    s.set_field_invalid(page.ids[4], false) >>>
    s.open(page.ids[1]) >>>
    << 0
}

fn (m $&Workshop) pagination_invalid(s $&widgets.Screen) int {
    m.pagination_error = true
    page := m.page_snapshot(25)
    data := s.pagination_data(page.ids[0]) >>>
    s.set_field_invalid(page.ids[1], true) >>>
    $message := "Enter a page from 1 to " + str(data.pages) + "."
    if(s.selected(m.language) >>>) != 1 {message = "请输入 1 至 " + str(data.pages) + " 之间的页码。"}
    if data.pages == 0 {message = "No pages / 暂无数据,无法跳页。"}
    s.set_text(page.ids[5], message) >>>
    << 0
}

fn (m $&Workshop) update_pagination(s $&widgets.Screen, sync_input bool) int {
    page := m.page_snapshot(25)
    data := s.pagination_data(page.ids[0]) >>>
    s.set_text(page.ids[3], s.pagination_summary(page.ids[0]) >>>) >>>
    s.set_enabled(page.ids[1], data.pages > 0) >>>
    s.set_enabled(page.ids[4], data.pages > 0) >>>
    if sync_input{
        m.pagination_error = false
        s.set_field_invalid(page.ids[1], false) >>>
        $text := ""
        if data.current >= 0 {text = str(data.current + 1)}
        s.set_value(page.ids[1], text) >>> }
    if m.pagination_error{m.pagination_invalid(s) >>> }
    else {$hint := "Enter ↵ · 1–" + str(data.pages)
        if data.pages == 0 {hint = "No data / 暂无数据"}
        s.set_text(page.ids[5], hint) >>> }
    << 0
}

fn (m &Workshop) update_badges(s $&widgets.Screen) int {
    english := (s.selected(m.language) >>>) == 1
    pages := &m.pages
    page := &pages[30]
    s.set_badge_count(page.ids[0], m.unread, 99, false) >>>
    $summary := str(m.unread) + " 条未读 · 点击收件箱清零,徽标随数字收紧。"
    if english {summary = str(m.unread) + " unread · Click Inbox to clear; badge tightens with digits."}
    s.set_text(page.ids[6], summary) >>>
    s.set_visible(page.ids[3], m.online) >>>
    $name := "林文 · 离线"
    if m.online{name = "林文 · 在线"}
    if english {
        name = "Lin Wen · Away"
        if m.online{name = "Lin Wen · Available"}
    }
    s.set_text(page.ids[7], name) >>>
    << 0
}

fn (m $&Workshop) work(s $&widgets.Screen, now time.Instant) int {
    if !m.running || now.before(m.deadline) { << 0}
    for i in 0:5000 {m.checksum =(m.checksum + i *(m.completed + 1)) % 1000003}
    m.completed += 1
    id := m.pages[8].ids[0]
    _ := s.set_task_progress(id, m.revision, f64(m.completed) / 48.0) >>>
    m.deadline = now.add(time.milliseconds(35) >>>) >>>
    if m.failure && m.completed == 18 {_ := s.complete_task(id, m.revision, widgets.TASK_ERROR) >>>
        m.running = false
        m.failure = false
        if m.selected == 8 {s.set_selected_button(m.tools[1], false) >>> }}
    else if m.completed == 48 {_ := s.complete_task(id, m.revision, widgets.TASK_SUCCESS) >>>
        m.running = false}
    << 0
}

fn (m &Workshop) range_summary(s $&widgets.Screen, committed bool) int {
    english := (s.selected(m.language) >>>) == 1
    pages := &m.pages
    page := &pages[40]
    values := s.range_values(page.ids[0]) >>>
    $prefix := "预览"
    if committed{prefix = "已提交"}
    if english {
        prefix = "Preview"
        if committed{prefix = "Committed"}
    }
    text := strconv.format_float(values.lower, 102, 0) >>>
    upper := strconv.format_float(values.upper, 102, 0) >>>
    s.set_text(page.ids[1], prefix + " · " + text + " – " + upper) >>>
    << 0
}

fn (m $&Workshop) configure_controls(s $&widgets.Screen) int {
    position := m.selected
    page := m.page_snapshot(position)
    s.set_text(m.title, "XUUI  /  " + m.names[position]) >>>
    s.set_selected(m.navigation, position) >>>
    id := page.ids[0]
    state := s.selected(m.state) >>>
    s.set_enabled(id, state != 1) >>>
    if position == 45 {s.set_enabled(page.ids[1], state != 1) >>> }
    if position == 25 {s.set_enabled(page.group, state != 1) >>> }
    if read_only(m.selected) {s.set_read_only(id, state == 2) >>> }
    if invalid(m.selected) || m.selected == 31 || m.selected == 32 {s.set_invalid(id, state == 3) >>> }
    if position == 1 {for i in 0:9 {s.set_enabled(page.ids[i], state != 1) >>> }}
    if position == 38 {for i in 0:3 {
            s.set_button_group_item_enabled(page.ids[i], 20, !m.group_disabled) >>>
            s.set_enabled(page.ids[i], state != 1) >>>
            s.set_read_only(page.ids[i], state == 2) >>>
        }}
    if position == 39 {
        for r in 0:6 {
            gid := page.ids[1 + r]
            for k in 0:5 {
                key := r * 5 + k + 1
                s.set_button_group_checked(gid, key, m.chart_kind + 1 == key) >>>
            }
            s.set_enabled(gid, state != 1) >>>
            s.set_read_only(gid, state == 2) >>>
        }
    }
    english := (s.selected(m.language) >>>) == 1
    s.set_enabled(m.motion, animated(m.selected) ||(m.selected >= 33 && m.selected <= 36)) >>>
    s.set_selected_button(m.custom, m.customized) >>>
    $custom_text := "默认样式"
    if m.customized{custom_text = "自定义样式"}
    if english {
        custom_text = "Default"
        if m.customized{custom_text = "Custom"}
    }
    s.set_text(m.custom, custom_text) >>>
    $motion_text := "动效 160ms"
    if m.slow{motion_text = "动效 420ms"}
    if english {
        motion_text = "Motion 160ms"
        if m.slow{motion_text = "Motion 420ms"}
    }
    s.set_text(m.motion, motion_text) >>>
    caption := description_locale(m.selected, english)
    s.set_text(m.caption, caption) >>>
    $state_text := "悬停 · 按下 · Tab · 方向键 · Escape(使用真实鼠标与键盘状态)"
    if english {state_text = "Hover · press · Tab · arrows · Escape"}
    if(state == 2 && !read_only(m.selected)) ||(state == 3 && !invalid(m.selected) && m.selected != 31 && m.selected != 32) {
        state_text = "此组件没有该状态。预览保持其实际语义。"
        if english {state_text = "This component does not have that state; preview keeps its actual semantics."}
    }
    s.set_text(m.status, state_text) >>>
    labels := tool_labels_locale(m.selected, english)
    for i in 0:3 {s.set_text(m.tools[i], labels[i]) >>>
        s.set_selected_button(m.tools[i], false) >>>
        s.set_enabled(m.tools[i], labels[i].len > 0) >>>
        s.set_visible(m.tools[i], labels[i].len > 0) >>> }
    if m.selected == 8 {s.set_selected_button(m.tools[1], m.failure) >>> }
    s.set_visible(m.focus, focusable_sample(m.selected)) >>>
    << 0
}
Xustyle.xu
@main

#ui/widgets
#ui/chart
#ui/draw
#ui/layout
#time

fn read_only(index int) bool { << index >= 38 ||(index >= 1 && index <= 26 && index != 8 && index != 25 && index != 26)}

fn invalid(index int) bool { << index >= 40 || index >= 1 && index <= 30 && index != 7 && index != 8 && index != 12 && index != 24 && index != 25 && index != 26 && index != 28}

fn animated(index int) bool { <<(index >= 38 && index <= 44) || index == 1 || index == 2 || index == 5 || index == 6 || index == 7 || index == 8 || index == 9 || index == 10 || index == 11 || index == 25}

fn appearance(styles &widgets.Styles, index int) widgets.ControlStyle{
    if index == 0 {$c := styles.input.clone()
        c.padding = layout.Insets{left: 0.0, top: 0.0, right: 0.0, bottom: 0.0}
        c.align_x = 0.0
        c.align_y = 0.0
        << c}
    if index == 7 { << styles.tree_style()}
    if index == 24 { << styles.table_style()}
    if index == 9 || index == 10 || index == 11 || index == 12 { << styles.checkbox.clone()}
    if index == 3 || index == 5 || index == 45 { << styles.input.clone()}
    if index == 4 || index == 6 { << styles.text_area.clone()}
    if index == 13 || index == 40 { << styles.slider_style()}
    if index == 41 { << styles.card_style()}
    if index == 14 { << styles.stepper_style()}
    if index == 15 { << styles.select_style()}
    if index == 21 || index == 22 { << styles.tabs_style()}
    if index == 23 { << styles.list_box_style()}
    if index == 27 { << styles.progress.clone()}
    if index == 29 { << styles.divider_style()}
    if index == 30 { << styles.badge_style()}
    if index == 31 { << styles.card_style()}
    if index == 32 { << styles.scroll.clone()}
    << styles.button.clone()
}

fn (m $&Workshop) apply_appearance(s $&widgets.Screen) int {
    theme := s.selected(m.theme) >>>
    density := s.selected(m.density) >>>
    scale := s.selected(m.scale) >>>
    preset :=[widgets.THEME_LIGHT, widgets.THEME_DARK, widgets.THEME_CONTRAST][theme]
    $styles := widgets.preset_styles(preset) >>>
    styles.density =[1.0, 0.85, 1.25][density]
    styles.text_scale =[1.0, 1.4, 2.0][scale]
    sheet := widgets.screen_appearance(&styles, s.toggle_value(m.reduced) >>>) >>>
    s.apply_appearance(&sheet) >>>
    position := m.selected
    pages := &m.pages
    page := &pages[position]
    id := page.ids[0]
    if m.selected == 30 {$avatar := styles.button_variant(widgets.BUTTON_SUBTLE) >>>
        avatar.radius = 999.0
        s.set_control_style(page.ids[2], &avatar) >>> }
    if m.selected <= 32 || m.selected >= 40 {
        s.clear_control_style(id) >>>
        if m.customized{$c := appearance(&styles, m.selected)
            c.radius = 14.0
            c.border_width = 1.5
            c.padding.left += 4.0
            c.padding.right += 4.0
            s.set_control_style(id, &c) >>> }
    }
    $spec := widgets.motion_spec()
    if m.slow{spec.change = time.milliseconds(420) >>>
        spec.hover = time.milliseconds(320) >>>
        spec.enter = time.milliseconds(360) >>>
        spec.exit = time.milliseconds(240) >>>
        spec.curve = widgets.EASE_OUT_QUINT}
    if animated(m.selected) {s.set_motion(id, &spec) >>> }
    if m.selected == 1 {
        handles :=[page.ids[0], page.ids[1], page.ids[2], page.ids[3]]
        placements :=[widgets.ICON_LEADING, widgets.ICON_TRAILING, widgets.ICON_ABOVE, widgets.ICON_BELOW]
        english := (s.selected(m.language) >>>) == 1
        for i in 0:4 {
            icon_size := s.number_value(page.ids[9 + i]) >>>
            $icon_prefix := "图标 · "
            if english {icon_prefix = "Icon · "}
            s.set_text(page.ids[13 + i], icon_prefix + str(int(icon_size)) + " px") >>>
            $c := styles.button_variant(widgets.BUTTON_OUTLINE) >>>
            if i == 0 {c = styles.button_variant(widgets.BUTTON_PRIMARY) >>> }
            c.icon_placement = placements[i]
            c.icon_size = icon_size * styles.text_scale
            if m.customized{c.radius = 14.0
                c.border_width = 1.5}
            s.set_control_style(handles[i], &c) >>>
            s.set_motion(handles[i], &spec) >>>
        }
    }
    if m.selected == 33 || m.selected == 34 || m.selected == 36 {s.set_motion(page.ids[1], &spec) >>>
        $c := styles.overlay_style()
        if m.customized{c.radius = 18.0
            c.border_width = 2.0}
        s.set_control_style(page.ids[1], &c) >>> }
    if m.selected == 34 {
        $placement := widgets.overlay_placement()
        placement.side = m.tooltip_side
        placement.align = widgets.OVERLAY_CENTER
        s.set_tooltip_placement(page.ids[1], &placement) >>>
    }
    if m.selected == 35 {
        s.set_notice_motion(&spec) >>>
        if m.customized{$c := styles.overlay_style()
            c.radius = 18.0
            c.border_width = 2.0
            s.set_notice_style(&c) >>> }
        else {s.clear_notice_style() >>> }
    }
    if m.selected == 38 {
        $group_appearance := widgets.button_group_appearance()
        group_appearance.vertical = m.group_vertical
        group_appearance.joined = m.group_joined
        for i in 0:3 {s.set_button_group_appearance(page.ids[i], &group_appearance) >>>
            s.clear_control_style(page.ids[i]) >>>
            s.set_motion(page.ids[i], &spec) >>>
            if m.customized{$c := styles.button_variant(widgets.BUTTON_OUTLINE) >>>
                c.radius = 12.0
                c.border_width = 1.5
                s.set_control_style(page.ids[i], &c) >>> }}
    }
    if m.selected == 39 {
        s.clear_control_style(id) >>>
        $appearance := chart.chart_appearance()
        appearance.y_unit = " ms"
        if m.chart_kind == widgets.CHART_DONUT || m.chart_kind == widgets.CHART_PIE || m.chart_kind == widgets.CHART_ROSE ||
           m.chart_kind == widgets.CHART_FUNNEL || m.chart_kind == widgets.CHART_TREEMAP || m.chart_kind == widgets.CHART_SANKEY{appearance.y_unit = ""}
        else if m.chart_kind == widgets.CHART_GAUGE || m.chart_kind == widgets.CHART_POLAR_BAR{appearance.y_unit = "%"}
        if m.customized{appearance.grid = false
            appearance.area_opacity = 0.26
            appearance.inner_radius = 0.78
            appearance.palette =[draw.rgb(41, 126, 178), draw.rgb(215, 146, 42), draw.rgb(56, 153, 124)]
            $c := styles.card_style()
            c.radius = 18.0
            s.set_control_style(id, &c) >>> }
        s.set_chart_appearance(id, &appearance) >>>
        $options := widgets.animation_options()
        options.duration = time.milliseconds(650) >>>
        options.curve = widgets.EASE_IN_OUT_CUBIC
        if m.slow{options.duration = time.milliseconds(1200) >>> }
        s.set_chart_animation(id, &options) >>>
        if m.chart_paused{s.pause_chart_animation(id) >>> }
    }
    if m.selected == 40 {
        $options := widgets.range_slider_options()
        options.step = 5.0
        options.min_distance = 10.0
        if m.range_push{options.collision = widgets.RANGE_PUSH}
        options.vertical = m.range_vertical
        options.commit_only = m.range_commit
        s.set_range_options(id, &options) >>>
        $appearance := widgets.slider_appearance()
        appearance.ticks = 11
        appearance.show_value = true
        s.set_range_appearance(id, &appearance) >>>
    }
    if m.selected == 41 {
        $options := widgets.split_view_options()
        options.vertical = m.split_vertical
        options.minimum_first = 120.0 * styles.text_scale
        options.minimum_second = 140.0 * styles.text_scale
        s.set_split_options(id, &options) >>>
    }
    if m.selected >= 42 && m.selected <= 44 {
        $appearance := widgets.menu_appearance()
        appearance.close_on_select = !m.menu_stays_open
        s.set_menu_appearance(id, &appearance) >>>
    }
    if m.selected == 37 {$radius := 8.0
        if m.customized{radius = 18.0}
        s.set_webview_radius(id, radius) >>> }
    << 0
}

// Business handlers set option flags. Appearance changes run only here.
fn (m $&Workshop) apply_page_options(s $&widgets.Screen) int {
    if m.tree_options_dirty{
        $appearance := widgets.tree_appearance()
        appearance.guides = m.guided
        s.set_tree_appearance(m.pages[7].ids[0], &appearance) >>>
        m.tree_options_dirty = false
    }
    if m.field_options_dirty{
        $decoration := widgets.field_decoration(&"Project name 项目名称")
        decoration.variant =(m.variant - 1) % 3
        decoration.floating =(m.variant - 1) % 4
        decoration.helper = "Floating / fixed label and stable helper area"
        decoration.error = "Please enter a valid name."
        decoration.clearable = true
        s.set_field_decoration(m.pages[m.field_options_page].ids[0], &decoration) >>>
        m.field_options_dirty = false
    }
    if m.spinner_options_dirty{
        s.set_spinner_appearance(m.pages[28].ids[0], 48.0, 4.0, time.milliseconds(1200) >>>) >>>
        m.spinner_options_dirty = false
    }
    if m.popover_options_dirty{
        $placement := widgets.overlay_placement()
        placement.side = m.variant
        placement.align = widgets.OVERLAY_CENTER
        s.set_popover_placement(m.pages[33].ids[1], &placement) >>>
        m.popover_options_dirty = false
    }
    << 0
}
Xuview.xu
@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
}

API 声明

nanosecond

XuAPI
pub fn nanosecond() int

用途

1 纳秒基础时间单位跨度。

参数

无需传入参数。

返回值

int — 该类型的值

microsecond

XuAPI
pub fn microsecond() int

用途

1 微秒时间单位跨度(1,000 纳秒)。

参数

无需传入参数。

返回值

int — 该类型的值

millisecond

XuAPI
pub fn millisecond() int

用途

1 毫秒时间单位跨度(1,000,000 纳秒)。

参数

无需传入参数。

返回值

int — 该类型的值

second

XuAPI
pub fn second() int

用途

1 秒时间单位跨度(1,000,000,000 纳秒)。

参数

无需传入参数。

返回值

int — 该类型的值

minute

XuAPI
pub fn minute() int

用途

1 分钟时间单位跨度(60 秒)。

参数

无需传入参数。

返回值

int — 该类型的值

hour

XuAPI
pub fn hour() int

用途

1 小时时间单位跨度(3600 秒)。

参数

无需传入参数。

返回值

int — 该类型的值

now

XuAPI
pub fn now() int

用途

读取并返回当前进程的高精度单调时间戳(纳秒整数)。

参数

无需传入参数。

返回值

纳秒时间戳(int)

sleep

XuAPI
pub fn sleep(d int)

用途

暂停并阻塞当前纤程/线程指定的纳秒时间跨度。

参数

d int
休眠纳秒数

返回值

无返回值

since

XuAPI
pub fn since(t int) int

用途

以来。

参数

t int
t(int)

返回值

int — 该类型的值

struct Time

XuAPI
pub struct Time {
    pub sec int
    pub nsec int
}

用途

承载 sec、nsec 等属性的结构体。

公开字段

sec int
字段(int)
nsec int
字段(int)

unix

XuAPI
pub fn unix(sec int, nsec int) Time

用途

Unix 时间。

参数

sec int
sec(int)
nsec int
nsec(int)

返回值

Time — 该类型的值

unix_from_ns

XuAPI
pub fn unix_from_ns(ns int) Time

用途

Unix 时间从纳秒。

参数

ns int
ns(int)

返回值

Time — 该类型的值

(Time) unix

XuAPI
pub fn (t Time) unix() int

用途

Time 上的操作:Unix 时间。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) is_zero

XuAPI
pub fn (t Time) is_zero() bool

用途

Time 上的操作:判断是否 zero。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

bool — 是否成立

(Time) unix_nano

XuAPI
pub fn (t Time) unix_nano() int

用途

Time 上的操作:执行 unix nano 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) unix_milli

XuAPI
pub fn (t Time) unix_milli() int

用途

Time 上的操作:执行 unix milli 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) unix_micro

XuAPI
pub fn (t Time) unix_micro() int

用途

Time 上的操作:执行 unix micro 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

unix_milli

XuAPI
pub fn unix_milli(ms int) Time

用途

执行 unix milli 操作。

参数

ms int
ms(int)

返回值

Time — 该类型的值

unix_micro

XuAPI
pub fn unix_micro(us int) Time

用途

执行 unix micro 操作。

参数

us int
us(int)

返回值

Time — 该类型的值

(Time) add

XuAPI
pub fn (t Time) add(d int) Time

用途

Time 上的操作:相加。

参数

t Time
本次调用使用的 Time 实例;按值接收。
d int
d(int)

返回值

Time — 该类型的值

(Time) sub

XuAPI
pub fn (t Time) sub(u Time) int

用途

Time 上的操作:相减。

参数

t Time
本次调用使用的 Time 实例;按值接收。
u Time
u(Time)

返回值

int — 该类型的值

(Time) before

XuAPI
pub fn (t Time) before(u Time) bool

用途

在 Time 上执行 before 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
u Time
u(Time)

返回值

bool — 是否成立

(Time) after

XuAPI
pub fn (t Time) after(u Time) bool

用途

在 Time 上执行 after 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
u Time
u(Time)

返回值

bool — 是否成立

(Time) equal

XuAPI
pub fn (t Time) equal(u Time) bool

用途

Time 上的操作:判断两值是否相等。

参数

t Time
本次调用使用的 Time 实例;按值接收。
u Time
u(Time)

返回值

bool — 是否成立

now_time

XuAPI
pub fn now_time() Time

用途

当前时间时间。

参数

无需传入参数。

返回值

Time — 该类型的值

parse_duration

XuAPI
pub fn parse_duration(s &string) int

用途

解析为 duration。失败时抛出错误,调用方需处理或继续传播。

参数

s &string
源字符串(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 该类型的值

format_duration

XuAPI
pub fn format_duration(d int) string

用途

格式化为 duration。

参数

d int
d(int)

返回值

string — 结果字符串

(Time) format_rfc3339

XuAPI
pub fn (t Time) format_rfc3339() string

用途

Time 上的操作:格式化为 rfc3339。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

string — 结果字符串

(Time) format_log

XuAPI
pub fn (t Time) format_log(date int, tod int, micro int) string

用途

Time 上的操作:格式化为 log。

参数

t Time
本次调用使用的 Time 实例;按值接收。
date int
date(int)
tod int
tod(int)
micro int
micro(int)

返回值

string — 结果字符串

parse_rfc3339

XuAPI
pub fn parse_rfc3339(s &string) Time

用途

解析为 rfc3339。失败时抛出错误,调用方需处理或继续传播。

参数

s &string
源字符串(只读借用,调用方仍持有原值;类型 &string)

返回值

Time — 该类型的值

(Time) add_date

XuAPI
pub fn (t Time) add_date(years int, months int, days int) Time

用途

Time 上的操作:增加日期。

参数

t Time
本次调用使用的 Time 实例;按值接收。
years int
years(int)
months int
months(int)
days int
days(int)

返回值

Time — 该类型的值

date

XuAPI
pub fn date(year int, month int, day int, hour int, min int, sec int, nsec int) Time

用途

日期。

参数

year int
year(int)
month int
month(int)
day int
day(int)
hour int
hour(int)
min int
下限(int)
sec int
sec(int)
nsec int
nsec(int)

返回值

Time — 该类型的值

查看用法示例

(Time) year

XuAPI
pub fn (t Time) year() int

用途

Time 上的操作:年。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) month

XuAPI
pub fn (t Time) month() int

用途

Time 上的操作:月。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) day

XuAPI
pub fn (t Time) day() int

用途

Time 上的操作:日。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) year_day

XuAPI
pub fn (t Time) year_day() int

用途

Time 上的操作:年日。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

struct Clock

XuAPI
pub struct Clock {
    pub hour int
    pub min int
    pub sec int
}

用途

承载 hour、min、sec 等属性的结构体。

公开字段

hour int
字段(int)
min int
下限
sec int
字段(int)

(Time) clock

XuAPI
pub fn (t Time) clock() Clock

用途

在 Time 上执行 clock 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

Clock — 该类型的值

(Time) nanosecond

XuAPI
pub fn (t Time) nanosecond() int

用途

Time 上的操作:1 纳秒基础时间单位跨度。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

struct DateParts

XuAPI
pub struct DateParts {
    pub year int
    pub month int
    pub day int
}

用途

年月日三元组日期拆分结构。

公开字段

year int
字段(int)
month int
字段(int)
day int
字段(int)

(Time) date_parts

XuAPI
pub fn (t Time) date_parts() DateParts

用途

Time 上的操作:执行 date parts 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

DateParts — 该类型的值

(Time) hour

XuAPI
pub fn (t Time) hour() int

用途

Time 上的操作:1 小时时间单位跨度(3600 秒)。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) minute

XuAPI
pub fn (t Time) minute() int

用途

Time 上的操作:1 分钟时间单位跨度(60 秒)。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

(Time) second

XuAPI
pub fn (t Time) second() int

用途

Time 上的操作:1 秒时间单位跨度(1,000,000,000 纳秒)。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

struct ISOWeek

XuAPI
pub struct ISOWeek {
    pub year int
    pub week int
}

用途

承载 year、week 等属性的结构体。

公开字段

year int
字段(int)
week int
字段(int)

(Time) iso_week

XuAPI
pub fn (t Time) iso_week() ISOWeek

用途

Time 上的操作:执行 iso week 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

ISOWeek — 该类型的值

(Time) weekday

XuAPI
pub fn (t Time) weekday() int

用途

Time 上的操作:星期。

参数

t Time
本次调用使用的 Time 实例;按值接收。

返回值

int — 该类型的值

weekday_name

XuAPI
pub fn weekday_name(d int) string

用途

星期名称。

参数

d int
d(int)

返回值

string — 结果字符串

month_name

XuAPI
pub fn month_name(m int) string

用途

月名称。

参数

m int
m(int)

返回值

string — 结果字符串

(Time) truncate

XuAPI
pub fn (t Time) truncate(d int) Time

用途

Time 上的操作:截断。

参数

t Time
本次调用使用的 Time 实例;按值接收。
d int
d(int)

返回值

Time — 该类型的值

(Time) round

XuAPI
pub fn (t Time) round(d int) Time

用途

Time 上的操作:舍入。

参数

t Time
本次调用使用的 Time 实例;按值接收。
d int
d(int)

返回值

Time — 该类型的值

until

XuAPI
pub fn until(t Time) int

用途

直到。

参数

t Time
t(Time)

返回值

int — 该类型的值

struct Timer

XuAPI
pub struct Timer {
    pub c chan int
    pub stop chan int
}

用途

承载 c、stop 等属性的结构体。

公开字段

c chan int
字节或字符码
stop chan int
字段(通道;类型 chan int)

new_timer

XuAPI
pub fn new_timer(d int) Timer

用途

构造 timer。

参数

d int
d(int)

返回值

Timer — 该类型的值

(Timer) stop

XuAPI
pub fn (t Timer) stop()

用途

Timer 上的操作:停止。

参数

t Timer
本次调用使用的 Timer 实例;按值接收。

返回值

不返回值。

struct Ticker

XuAPI
pub struct Ticker {
    pub c chan int
    pub stop chan int
}

用途

承载 c、stop 等属性的结构体。

公开字段

c chan int
字节或字符码
stop chan int
字段(通道;类型 chan int)

new_ticker

XuAPI
pub fn new_ticker(d int) Ticker

用途

构造 ticker。

参数

d int
d(int)

返回值

Ticker — 该类型的值

(Ticker) stop

XuAPI
pub fn (t Ticker) stop()

用途

Ticker 上的操作:停止。

参数

t Ticker
本次调用使用的 Ticker 实例;按值接收。

返回值

不返回值。

struct Location

XuAPI
pub struct Location {
    pub name string
    pub offset_sec int
    pub dst_offset_sec int
    pub has_dst int
    pub dst_sm int
    pub dst_sn int
    pub dst_sd int
    pub dst_st int
    pub dst_em int
    pub dst_en int
    pub dst_ed int
    pub dst_et int
    pub before_off int
    pub trans_sec []int
    pub trans_off []int
}

用途

包含时区名称与秒级 UTC 偏移量的地理/时区配置。

公开字段

name string
名字
offset_sec int
字段(int)
dst_offset_sec int
字段(int)
has_dst int
字段(int)
dst_sm int
字段(int)
dst_sn int
字段(int)
dst_sd int
字段(int)
dst_st int
字段(int)
dst_em int
字段(int)
dst_en int
字段(int)
dst_ed int
字段(int)
dst_et int
字段(int)
before_off int
字段(int)
trans_sec []int
字段([]int)
trans_off []int
字段([]int)

utc

XuAPI
pub fn utc() Location

用途

UTC(协调世界时)标准时区 Location 实例。

参数

无需传入参数。

返回值

Location — 该类型的值

fixed_zone

XuAPI
pub fn fixed_zone(name string, offset_sec int) Location

用途

构造具有固定名称和秒级 UTC 偏移量的时区 Location。

参数

name string
名字(string)
offset_sec int
offset_sec(int)

返回值

Location — 该类型的值

load_location

XuAPI
pub fn load_location(name string) Location

用途

执行 load location 操作。失败时抛出错误,调用方需处理或继续传播。

参数

name string
名字(string)

返回值

Location — 该类型的值

(Time) year_in

XuAPI
pub fn (t Time) year_in(loc &Location) int

用途

Time 上的操作:执行 year in 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
loc &Location
loc(只读借用,调用方仍持有原值;类型 &Location)

返回值

int — 该类型的值

(Time) month_in

XuAPI
pub fn (t Time) month_in(loc &Location) int

用途

Time 上的操作:执行 month in 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
loc &Location
loc(只读借用,调用方仍持有原值;类型 &Location)

返回值

int — 该类型的值

(Time) day_in

XuAPI
pub fn (t Time) day_in(loc &Location) int

用途

Time 上的操作:执行 day in 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
loc &Location
loc(只读借用,调用方仍持有原值;类型 &Location)

返回值

int — 该类型的值

(Time) hour_in

XuAPI
pub fn (t Time) hour_in(loc &Location) int

用途

Time 上的操作:执行 hour in 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
loc &Location
loc(只读借用,调用方仍持有原值;类型 &Location)

返回值

int — 该类型的值

(Time) minute_in

XuAPI
pub fn (t Time) minute_in(loc &Location) int

用途

Time 上的操作:执行 minute in 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
loc &Location
loc(只读借用,调用方仍持有原值;类型 &Location)

返回值

int — 该类型的值

(Time) second_in

XuAPI
pub fn (t Time) second_in(loc &Location) int

用途

Time 上的操作:执行 second in 操作。

参数

t Time
本次调用使用的 Time 实例;按值接收。
loc &Location
loc(只读借用,调用方仍持有原值;类型 &Location)

返回值

int — 该类型的值

(Time) format_rfc3339_in

XuAPI
pub fn (t Time) format_rfc3339_in(loc &Location) string

用途

Time 上的操作:格式化为 rfc3339 in。

参数

t Time
本次调用使用的 Time 实例;按值接收。
loc &Location
loc(只读借用,调用方仍持有原值;类型 &Location)

返回值

string — 结果字符串

struct Duration

XuAPI
pub struct Duration {

}

用途

带符号的纳秒级高精度时间跨度,独立于日历和时区。

公开字段

此类型没有公开字段。

duration

XuAPI
pub fn duration(ns int) Duration

用途

执行 duration 处理。

参数

ns int
ns(int)

返回值

Duration — 该类型的值

microseconds

XuAPI
pub fn microseconds(value int) Duration

用途

执行 microseconds 处理。失败时抛出错误,调用方需处理或继续传播。

参数

value int
value(int)

返回值

Duration — 该类型的值

milliseconds

XuAPI
pub fn milliseconds(value int) Duration

用途

执行 milliseconds 处理。失败时抛出错误,调用方需处理或继续传播。

参数

value int
value(int)

返回值

Duration — 该类型的值

查看用法示例

seconds

XuAPI
pub fn seconds(value int) Duration

用途

执行 seconds 处理。失败时抛出错误,调用方需处理或继续传播。

参数

value int
value(int)

返回值

Duration — 该类型的值

minutes

XuAPI
pub fn minutes(value int) Duration

用途

执行 minutes 处理。失败时抛出错误,调用方需处理或继续传播。

参数

value int
value(int)

返回值

Duration — 该类型的值

hours

XuAPI
pub fn hours(value int) Duration

用途

执行 hours 处理。失败时抛出错误,调用方需处理或继续传播。

参数

value int
value(int)

返回值

Duration — 该类型的值

(Duration) nanoseconds

XuAPI
pub fn (d Duration) nanoseconds() int

用途

在 Duration 上执行 nanoseconds 操作。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

int — 该类型的值

(Duration) milliseconds

XuAPI
pub fn (d Duration) milliseconds() int

用途

在 Duration 上执行 milliseconds 操作。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

int — 该类型的值

(Duration) seconds

XuAPI
pub fn (d Duration) seconds() f64

用途

在 Duration 上执行 seconds 操作。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

f64 — 该类型的值

(Duration) is_zero

XuAPI
pub fn (d Duration) is_zero() bool

用途

Duration 上的操作:判断是否 zero。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

bool — 是否成立

(Duration) is_negative

XuAPI
pub fn (d Duration) is_negative() bool

用途

Duration 上的操作:判断是否 negative。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

bool — 是否成立

(Duration) format

XuAPI
pub fn (d Duration) format() string

用途

Duration 上的操作:格式化为字符串。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

string — 结果字符串

parse_duration_value

XuAPI
pub fn parse_duration_value(value &string) Duration

用途

解析为 duration value。失败时抛出错误,调用方需处理或继续传播。

参数

value &string
value(只读借用,调用方仍持有原值;类型 &string)

返回值

Duration — 该类型的值

(Duration) add

XuAPI
pub fn (d Duration) add(other Duration) Duration

用途

Duration 上的操作:相加。失败时抛出错误,调用方需处理或继续传播。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。
other Duration
另一侧同类型值(Duration)

返回值

Duration — 该类型的值

(Duration) sub

XuAPI
pub fn (d Duration) sub(other Duration) Duration

用途

Duration 上的操作:相减。失败时抛出错误,调用方需处理或继续传播。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。
other Duration
另一侧同类型值(Duration)

返回值

Duration — 该类型的值

(Duration) sleep

XuAPI
pub fn (d Duration) sleep()

用途

暂停并阻塞当前纤程/线程指定的纳秒时间跨度。

参数

d Duration
休眠纳秒数

返回值

无返回值

(Duration) timer

XuAPI
pub fn (d Duration) timer() Timer

用途

Duration 上的操作:定时器。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

Timer — 该类型的值

(Duration) ticker

XuAPI
pub fn (d Duration) ticker() Ticker

用途

Duration 上的操作:周期器。失败时抛出错误,调用方需处理或继续传播。

参数

d Duration
本次调用使用的 Duration 实例;按值接收。

返回值

Ticker — 该类型的值

struct Instant

XuAPI
pub struct Instant {

}

用途

进程本地高精度单调时钟读取值,不受系统时钟跳变调整影响。

公开字段

此类型没有公开字段。

查看用法示例

zero_instant

XuAPI
pub fn zero_instant() Instant

用途

执行 zero instant 操作。

参数

无需传入参数。

返回值

Instant — 该类型的值

查看用法示例

instant

XuAPI
pub fn instant() Instant

用途

执行 instant 处理。

参数

无需传入参数。

返回值

Instant — 该类型的值

查看用法示例

instant_from_ns

XuAPI
pub fn instant_from_ns(ns int) Instant

用途

执行 instant from ns 操作。失败时抛出错误,调用方需处理或继续传播。

参数

ns int
ns(int)

返回值

Instant — 该类型的值

(Instant) nanoseconds

XuAPI
pub fn (t Instant) nanoseconds() int

用途

在 Instant 上执行 nanoseconds 操作。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。

返回值

int — 该类型的值

(Instant) is_zero

XuAPI
pub fn (t Instant) is_zero() bool

用途

Instant 上的操作:判断是否 zero。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。

返回值

bool — 是否成立

(Instant) before

XuAPI
pub fn (t Instant) before(other Instant) bool

用途

在 Instant 上执行 before 操作。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。
other Instant
另一侧同类型值(Instant)

返回值

bool — 是否成立

(Instant) after

XuAPI
pub fn (t Instant) after(other Instant) bool

用途

在 Instant 上执行 after 操作。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。
other Instant
另一侧同类型值(Instant)

返回值

bool — 是否成立

(Instant) equal

XuAPI
pub fn (t Instant) equal(other Instant) bool

用途

Instant 上的操作:判断两值是否相等。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。
other Instant
另一侧同类型值(Instant)

返回值

bool — 是否成立

(Instant) since

XuAPI
pub fn (t Instant) since(earlier Instant) Duration

用途

Instant 上的操作:以来。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。
earlier Instant
earlier(Instant)

返回值

Duration — 该类型的值

(Instant) elapsed

XuAPI
pub fn (t Instant) elapsed() Duration

用途

在 Instant 上执行 elapsed 操作。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。

返回值

Duration — 该类型的值

(Instant) add

XuAPI
pub fn (t Instant) add(d Duration) Instant

用途

Instant 上的操作:相加。失败时抛出错误,调用方需处理或继续传播。

参数

t Instant
本次调用使用的 Instant 实例;按值接收。
d Duration
d(Duration)

返回值

Instant — 该类型的值

(Time) add_duration

XuAPI
pub fn (t Time) add_duration(d Duration) Time

用途

Time 上的操作:执行 add duration 操作。失败时抛出错误,调用方需处理或继续传播。

参数

t Time
本次调用使用的 Time 实例;按值接收。
d Duration
d(Duration)

返回值

Time — 该类型的值

(Time) duration_since

XuAPI
pub fn (t Time) duration_since(earlier Time) Duration

用途

Time 上的操作:执行 duration since 操作。失败时抛出错误,调用方需处理或继续传播。

参数

t Time
本次调用使用的 Time 实例;按值接收。
earlier Time
earlier(Time)

返回值

Duration — 该类型的值