XU XUv0.13.1
中文

#ui/layout

import: #ui/layout

counts: 11 functions, 29 methods, 10 types, 19 constants, 0 method sets

Constraints, sizes, rectangles, row / column / stack / padding and retained layout trees. Constraints flow downward and measured sizes upward. BoxStyle width / height=-1 means natural size. Trees allow 4096 nodes and depth 64; removed node IDs never repeat. View in widgets handles painting and input.

Usage and lifetimes

Release examples (complete projects and source downloads): widgets · text_input

Examples · API declarations

Examples

These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.

16_ui_webview/desktop_services/main.xu

Required SDK: Xu 0.10.11 · Complete project · Download source

XuLocal SDK example
@main
#ui
#ui/draw
#ui/layout
demo #"github.com/xulang-org/examples/ui_demo"

fn caption(id int) string {
    if id == 0 { << "1 / Copy greeting" }
    if id == 1 { << "2 / Read clipboard" }
    if id == 2 { << "3 / Open files" }
    if id == 3 { << "4 / Choose save path" }
    if id == 4 { << "5 / Choose folders" }
    if id == 5 { << "6 / Prompt (15s timeout)" }
    << "Cancel pending request"
}
fn status_name(status int) string {
    if status == ui.REQUEST_COMPLETED { << "completed" }
    if status == ui.REQUEST_CANCELLED { << "cancelled" }
    if status == ui.REQUEST_TIMED_OUT { << "timed out" }
    if status == ui.REQUEST_UNSUPPORTED { << "unsupported" }
    << "failed"
}
fn submit(identity &ui.CanvasEvent,choice int) ui.Request {
    options := ui.RequestOptions{timeout_ms: 5000}
    if choice == 0 { value := "Hello from Xu UI 0.10 / 你好"
        << ui.clipboard_write_async(identity,&value,&options) or >> }
    if choice == 1 { << ui.clipboard_read_async(identity,&options) or >> }
    if choice == 5 { prompt := ui.PromptOptions{title: "Your greeting",seed: "Hello, Xu",timeout_ms: 15000}
        << ui.prompt_async(identity,&prompt) or >> }
    $files := ui.file_dialog_options()
    if choice == 2 {
        files.title = "Select one or more text files"
        files.multiple = true
        files.filters = [ui.FileFilter{label: "Text",extensions: ["txt","md","xu"]}]
        << ui.open_files_async(identity,&files) or >>
    }
    if choice == 3 { files.title = "Choose a destination (this demo does not write)"
        files.name = "xu-note.txt"
        << ui.save_file_async(identity,&files) or >> }
    files.title = "Choose folders"
    files.multiple = true
    << ui.select_folders_async(identity,&files) or >>
}
fn paint(context &draw.Context,frame $&draw.Frame,message string,pending int) int {
    frame.begin() or >>
    frame.set_bg(demo.background()) or >>
    demo.text(context,frame,28.0,26.0,14.0,demo.accent(),"05 / ASYNCHRONOUS DESKTOP SERVICES") or >>
    demo.text(context,frame,28.0,58.0,28.0,demo.ink(),"A request is not a result.") or >>
    for id in 0:7 {
        y := 120.0 + f64(id) * 48.0
        frame.fill_rect(28.0,y,370.0,38.0,draw.rgb(40,57,73)) or >>
        demo.text(context,frame,40.0,y + 8.0,15.0,demo.ink(),caption(id)) or >>
    }
    demo.text(context,frame,430.0,124.0,17.0,demo.accent(),"Pending request: " + str(pending)) or >>
    $options := draw.text_options(16.0)
    options.width = 360.0
    $label := context.layout_text(&message,&options) or >>
    frame.text_layout(&label,430.0,172.0,demo.ink()) or >>
    demo.text(context,frame,28.0,490.0,13.0,demo.muted(),"One event channel / request IDs / distinct terminal states / Escape to close") or >>
    frame.present() or >>
    label.dispose() or >>
    << 0
}
fn scene(ech chan ui.Event) int {
    ready := demo.ready(ech) or >>
    if ready.kind == ui.EV_EXIT { << 0 }
    identity := ui.canvas_of(&ready) or >>
    context := draw.context_of(&ready) or >>
    $frame := context.new_frame(4096)
    $pending := ui.Request{id: 0,window_id: 0,canvas_id: 0,generation: 0,kind: 0}
    $message := "Choose an action. File dialogs return paths; selecting a save path does not write a file."
    $armed := -1
    paint(&context,$&frame,message + "",pending.id) or >>
    while true {
        event := demo.next(ech)
        if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
        if event.window_id != identity.window_id { -> }
        $dirty := event.kind == ui.EV_CANVAS_METRICS
        if event.kind == ui.EV_REQUEST {
            result := ui.request_of(&event) or >>
            if result.matches(&pending) {
                message = "Request " + str(pending.id) + " " + status_name(result.status)
                if result.status == ui.REQUEST_COMPLETED {
                    if result.request.kind >= ui.REQUEST_OPEN_FILES {
                        paths := ui.file_paths(&result) or >>
                        for path in paths { message = message + "\n" + path }
                    } else { message = message + "\n" + result.value }
                }
                println("Request " + str(pending.id) + ": " + status_name(result.status))
                pending.id = 0
                dirty = true
            }
        }
        if event.kind == ui.EV_BLURRED { armed = -1 }
        if ui.is_input_event(event.kind) {
            input := ui.input_of(&event) or >>
            if input.generation != identity.generation { -> }
            $choice := -1
            for id in 0:7 {
                bounds := layout.Rect{x: 28.0,y: 120.0 + f64(id) * 48.0,width: 370.0,height: 38.0}
                if bounds.contains(input.x,input.y) { choice = id }
            }
            if input.kind == ui.EV_POINTER_DOWN && input.button == ui.BUTTON_LEFT { armed = choice }
            if input.kind == ui.EV_POINTER_CANCEL { armed = -1 }
            $activate := -1
            if input.kind == ui.EV_POINTER_UP && input.button == ui.BUTTON_LEFT {
                if choice == armed { activate = choice }
                armed = -1
            }
            if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
                if input.key >= 49 && input.key <= 54 { activate = input.key - 49 }
                if input.key == ui.KEY_ESCAPE { demo.quit() or >> }
            }
            if activate == 6 && pending.id > 0 { _ := pending.cancel()
                message = "Cancellation requested; waiting for terminal result."
                dirty = true }
            if activate >= 0 && activate < 6 {
                if pending.id == 0 {
                    request := submit(&identity,activate) or (err) { message = err.msg()
                        paint(&context,$&frame,message + "",pending.id) or >>
                        -> }
                    pending = request
                    message = "Request admitted. Keep interacting; the event loop remains active."
                } else { message = "Finish or cancel the current request first." }
                dirty = true
            }
        }
        if dirty { paint(&context,$&frame,message + "",pending.id) or >> }
    }
    if pending.id > 0 { _ := pending.cancel() }
    frame.dispose()
    << 0
}
fn worker(ech chan ui.Event) { scene(ech) or (err) { demo.fail(err.msg())
    << } }
fn launch() int {
    $app := demo.app("Xu UI / Desktop Services",850,550) or >>
    xu worker(app.event_ch)
    << app.run() or >>
}
fn main() int { << launch() or (err) { eprintln(err.msg())
    << 1 } }
16_ui_webview/text_input/main.xu

Required SDK: Xu 0.10.11 · Complete project · Download source

XuLocal SDK example
@main
#ui
#ui/draw
#ui/layout
#math
demo #"github.com/xulang-org/examples/ui_demo"

fn paint(context &draw.Context,frame $&draw.Frame,input &ui.TextInput) int {
    state := input.snapshot() or >>
    value := state.display_value()
    println("Text revision: " + str(state.revision) + " / display bytes: " + str(value.len))
    options := draw.text_options(28.0)
    $text := context.layout_text(&value,&options) or >>
    text.bind_input(input,state.revision,44.0,180.0) or >>
    frame.begin() or >>
    frame.set_bg(demo.background()) or >>
    demo.text(context,frame,28.0,28.0,14.0,demo.accent(),"04 / NATIVE TEXT INPUT") or >>
    demo.text(context,frame,28.0,60.0,28.0,demo.ink(),"Type in your own language.") or >>
    demo.text(context,frame,28.0,112.0,15.0,demo.muted(),"Use an IME, arrows, Shift+arrows and Backspace. Click to move the caret.") or >>
    frame.fill_rect(28.0,160.0,790.0,86.0,draw.rgb(26,37,50)) or >>
    anchor := text.caret(state.display_anchor(),false) or >>
    caret := text.caret(state.display_focus(),false) or >>
    if state.display_anchor() != state.display_focus() && anchor.y == caret.y {
        frame.fill_rect(44.0 + math.min(anchor.x,caret.x),180.0 + caret.y,math.abs(caret.x - anchor.x),caret.height,draw.rgba(78,205,196,80)) or >>
    }
    frame.text_layout(&text,44.0,180.0,demo.ink()) or >>
    frame.fill_rect(44.0 + caret.x,180.0 + caret.y,1.5,caret.height,demo.accent()) or >>
    if state.composing {
        demo.text(context,frame,28.0,280.0,17.0,demo.accent(),"Composing: " + state.preedit) or >>
    } else {
        demo.text(context,frame,28.0,280.0,17.0,demo.muted(),"Committed text / no active preedit") or >>
    }
    demo.text(context,frame,28.0,324.0,14.0,demo.muted(),"Revision " + str(state.revision) + " / anchor byte " + str(state.anchor) + " / focus byte " + str(state.focus)) or >>
    demo.text(context,frame,28.0,360.0,14.0,demo.muted(),"Selection uses UTF-8 byte offsets. Escape ends the session and closes the window.") or >>
    frame.present() or >>
    text.dispose() or >>
    << 0
}
fn scene(ech chan ui.Event) int {
    ready := demo.ready(ech) or >>
    if ready.kind == ui.EV_EXIT { << 0 }
    identity := ui.canvas_of(&ready) or >>
    context := draw.context_of(&ready) or >>
    seed := "你好,Xu 👩‍💻 · café"
    caret := ui.TextInputRect{x: 44.0,y: 180.0,width: 2.0,height: 36.0}
    options := ui.text_input_options(&seed,caret)
    $input := ui.start_text_input(identity.canvas_id,identity.generation,&options) or >>
    $frame := context.new_frame(4096)
    paint(&context,$&frame,&input) or >>
    while true {
        event := demo.next(ech)
        if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
        if event.window_id != identity.window_id { -> }
        $dirty := event.kind == ui.EV_CANVAS_METRICS
        if event.kind >= ui.EV_TEXT_COMMIT && event.kind <= ui.EV_TEXT_SURROUNDING_DELETE {
            edit := ui.text_edit_of(&event) or >>
            if edit.input.id == input.id {
                if event.kind == ui.EV_TEXT_INPUT_ENDED || event.kind == ui.EV_TEXT_INPUT_FAILED { <- }
                dirty = true
            }
        }
        if ui.is_input_event(event.kind) {
            pointer := ui.input_of(&event) or >>
            if pointer.generation != identity.generation { -> }
            if pointer.kind == ui.EV_KEY_DOWN && pointer.key == ui.KEY_ESCAPE { demo.quit() or >> }
            bounds := layout.Rect{x: 28.0,y: 160.0,width: 790.0,height: 86.0}
            if pointer.kind == ui.EV_POINTER_DOWN && pointer.button == ui.BUTTON_LEFT && bounds.contains(pointer.x,pointer.y) {
                state := input.snapshot() or >>
                // The native editor owns preedit; do not overwrite an active composition.
                if !state.composing {
                    hit := input.hit_test(state.revision,pointer.x,pointer.y) or >>
                    index := hit.byte_index()
                    _ := input.update(state.revision,&state.value,index,index,&caret) or >>
                    dirty = true
                }
            }
        }
        if dirty { paint(&context,$&frame,&input) or >> }
    }
    frame.dispose()
    input.stop() or (err) { << 0 }
    << 0
}
fn worker(ech chan ui.Event) { scene(ech) or (err) { demo.fail(err.msg())
    << } }
fn launch() int {
    $app := demo.app("Xu UI / Native Text Input",860,430) or >>
    xu worker(app.event_ch)
    << app.run() or >>
}
fn main() int { << launch() or (err) { eprintln(err.msg())
    << 1 } }
16_ui_webview/controls_gallery/main.xu

Required SDK: Xu 0.10.13-dev.1 · Complete project · Download source · events.xu · style.xu

XuLocal SDK example
@main
#ui
#ui/draw
#ui/layout
#ui/widgets
demo #"github.com/xulang-org/examples/ui_demo"

fn rect(x f64, y f64, width f64, height f64) layout.Rect{
    << layout.Rect{x: x, y: y, width: width, height: height}
}

// One worker owns the controls and their canvas resources. Every recorded
// label remains alive until the complete frame has been accepted.
fn scene(ech chan ui.Event) int {
    ready := demo.ready(ech) or >>
    if ready.kind == ui.EV_EXIT{ << 0}
    identity := ui.canvas_of(&ready) or >>
    context := draw.context_of(&ready) or >>
    $switcher := widgets.style_switcher()
    switcher.use_preset(widgets.THEME_LIGHT) or >>
    $toggle := widgets.switch_control(&identity, 1, &rect(48.0, 116.0, 280.0, 48.0), true) or >>
    $radio := widgets.radio(&identity, 2, &rect(48.0, 180.0, 280.0, 48.0), 1, false) or >>
    $slider := widgets.slider(&identity, 3, &rect(48.0, 260.0, 280.0, 36.0), 0.0, 100.0, 50.0) or >>
    slider.set_step(5.0) or >>
    $stepper := widgets.stepper(&identity, 4, &rect(48.0, 324.0, 280.0, 48.0), 0.0, 20.0, 1.0, 5.0) or >>
    $tabs := widgets.tabs(&identity, 5, &rect(376.0, 116.0, 348.0, 48.0), 3, 0) or >>
    $dropdown := widgets.select_box(&identity, 6, &rect(376.0, 196.0, 348.0, 48.0), 3, 0) or >>
    $list := widgets.list_box(&identity, 7, &rect(376.0, 284.0, 348.0, 132.0), 3, 0) or >>
    panel := widgets.card(&rect(24.0, 92.0, 724.0, 352.0)) or >>
    badge := widgets.badge(&rect(48.0, 392.0, 280.0, 32.0)) or >>
    divider := widgets.divider(&rect(48.0, 244.0, 280.0, 2.0), widgets.AXIS_HORIZONTAL) or >>
    $label0 := widgets.styled_label(&context, &"Enabled")
    $label1 := widgets.styled_label(&context, &"Choose this option")
    $label2 := widgets.styled_label(&context, &"Stepper")
    $label3 := widgets.styled_label(&context, &"One")
    $label4 := widgets.styled_label(&context, &"Two")
    $label5 := widgets.styled_label(&context, &"Three")
    $label6 := widgets.styled_label(&context, &"Select an option")
    $label7 := widgets.styled_label(&context, &"Xu 0.10.2")
    $label8 := widgets.styled_label(&context, &"One")
    $label9 := widgets.styled_label(&context, &"Two")
    $label10 := widgets.styled_label(&context, &"Three")
    $frame := context.new_frame(16384)
    $state := Model{dirty: true, focus: 0}
    $dispatcher := widgets.action_dispatcher(&state, &switcher)
    for id in 1:8 {dispatcher.on_any(id, control_action) or >> }
    while true {
        if state.dirty{
            styles := switcher.styles()
            frame.begin() or >>
            frame.set_bg(styles.background) or >>
            panel.paint_styled($&frame, &styles) or >>
            ink := styles.button.palette.foreground
            title := "Extended controls / " + switcher.name()
            frame.text(32.0, 28.0, 22.0, ink, &title) or >>
            toggle.paint_styled($&frame, $&label0, &styles) or >>
            radio.paint_styled($&frame, $&label1, &styles) or >>
            divider.paint_styled($&frame, &styles) or >>
            slider.paint_styled($&frame, &styles) or >>
            stepper.paint_styled($&frame, $&label2, &styles) or >>
            tabs.paint_box_styled($&frame, &styles) or >>
            list.paint_box_styled($&frame, &styles) or >>
            tabs.paint_tab_styled($&frame, 0, $&label3, &styles) or >>
            list.paint_item_styled($&frame, 0, $&label8, &styles) or >>
            tabs.paint_tab_styled($&frame, 1, $&label4, &styles) or >>
            list.paint_item_styled($&frame, 1, $&label9, &styles) or >>
            tabs.paint_tab_styled($&frame, 2, $&label5, &styles) or >>
            list.paint_item_styled($&frame, 2, $&label10, &styles) or >>
            dropdown.paint_styled($&frame, $&label6, &styles) or >>
            badge.paint_styled($&frame, $&label7, &styles) or >>
            frame.text(32.0, 464.0, 15.0, ink, &"T: theme / S: text size / D: density / Tab: focus / Esc: quit") or >>
            status := "Slider " + str(int(slider.value())) + " / Stepper " + str(int(stepper.value())) + " / Select " + str(dropdown.selected() + 1)
            frame.text(32.0, 494.0, 15.0, ink, &status) or >>
            // A Select popup overlays the scene; this basic painter repeats
            // its label. The selected option index is shown in the status.
            dropdown.paint_popup_styled($&frame, $&label6, &styles) or >>
            // This worker can repaint for a burst of control and appearance actions.
            frame.present_wait() or >>
            toggle.painted()
            radio.painted()
            slider.painted()
            stepper.painted()
            tabs.painted()
            dropdown.painted()
            list.painted()
            state.dirty = false
        }
        event := demo.next(ech)
        if event.kind == ui.EV_EXIT{ <- }
        if event.window_id != identity.window_id{ -> }
        if event.kind == ui.EV_CANVAS_CLOSED{ <- }
        if event.kind == ui.EV_CANVAS_METRICS{state.dirty = true}
        if ui.is_input_event(event.kind) {
            input := ui.input_of(&event) or >>
            if input.generation != identity.generation{ -> }
            if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
                if input.key == ui.KEY_ESCAPE{
                    // App shutdown revokes canvas resources. Do not enqueue
                    // another frame while the native host is closing.
                    demo.quit() or >>
                    << 0
                }
                if appearance_key($&switcher, &input) or >> {state.dirty = true}
                if input.key == ui.KEY_TAB{state.focus = state.focus % 7 + 1
                    state.dirty = true}
            }
        }
        // Route the popup first. A modal option click must not also focus
        // or activate the ListBox underneath it.
        popup_open := dropdown.is_open()
        first := dropdown.event(&event) or >>
        $actions :=[first]
        if !popup_open && !first.consumed{
            actions.push(toggle.event(&event) or >>)
            actions.push(radio.event(&event) or >>)
            actions.push(slider.event(&event) or >>)
            actions.push(stepper.event(&event) or >>)
            actions.push(tabs.event(&event) or >>)
            actions.push(list.event(&event) or >>)
        }
        for action in actions{
            if !(dispatcher.dispatch(&action, $&state, $&switcher) or >>) {
                // ACTION_NONE may carry focus/repaint metadata without a semantic event.
                action_state($&state, &action)
            }
        }
        toggle.set_focus(state.focus == 1)
        radio.set_focus(state.focus == 2)
        slider.set_focus(state.focus == 3)
        stepper.set_focus(state.focus == 4)
        tabs.set_focus(state.focus == 5)
        dropdown.set_focus(state.focus == 6)
        list.set_focus(state.focus == 7)
    }
    frame.dispose()
    if demo.alive(&identity) {
        label0.dispose()
        label1.dispose()
        label2.dispose()
        label3.dispose()
        label4.dispose()
        label5.dispose()
        label6.dispose()
        label7.dispose()
        label8.dispose()
        label9.dispose()
        label10.dispose()
    }
    << 0
}
fn worker(ech chan ui.Event) {
    scene(ech) or(err) {demo.fail(err.msg())
        << }
}
fn launch() int {
    $app := demo.app("Xu UI / Extended Controls", 780, 552) or >>
    xu worker(app.event_ch)
    << app.run() or >>
}
fn main() int {
    << launch() or(err) {eprintln(err.msg())
        << 1}
}
More related examples
  • 16_ui_webview/widgets/main.xu

    Required SDK: Xu 0.10.13-dev.1 · Complete project · Download source · events.xu

    XuLocal SDK example
    @main
    #ui
    #ui/draw
    #ui/layout
    #ui/widgets
    demo #"github.com/xulang-org/examples/ui_demo"
    
    struct Model{
        button widgets.Button
        checkbox widgets.Checkbox
        progress widgets.Progress
        scroll widgets.Scroll
        button_label draw.TextLayout
        checkbox_label draw.TextLayout
        theme widgets.Theme
        context draw.Context
        count int
        header_id int
        button_id int
        check_id int
        progress_id int
        scroll_id int
        row_ids []int
    }
    fn (model $&Model) button_input(kind int, input &ui.InputEvent) widgets.Action{
        button := $&model.button
        << button.route(kind, input) or >>
    }
    fn (model $&Model) checkbox_input(kind int, input &ui.InputEvent) widgets.Action{
        checkbox := $&model.checkbox
        << checkbox.route(kind, input) or >>
    }
    fn (model $&Model) scroll_input(kind int, input &ui.InputEvent) widgets.Action{
        scroll := $&model.scroll
        << scroll.route(kind, input) or >>
    }
    fn (model $&Model) input(id int, kind int, input &ui.InputEvent) widgets.Action{
        if id == model.button_id{ << model.button_input(kind, input) or >> }
        if id == model.check_id{ << model.checkbox_input(kind, input) or >> }
        if id == model.scroll_id{ << model.scroll_input(kind, input) or >> }
        << widgets.Action{kind: widgets.ACTION_NONE, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
    }
    fn (model $&Model) place_button(bounds &layout.Rect) int {
        button := $&model.button
        << button.set_bounds(bounds) or >>
    }
    fn (model $&Model) place_checkbox(bounds &layout.Rect) int {
        checkbox := $&model.checkbox
        << checkbox.set_bounds(bounds) or >>
    }
    fn (model $&Model) place_progress(bounds &layout.Rect) int {
        progress := $&model.progress
        << progress.set_bounds(bounds) or >>
    }
    fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
        model.draw_node(id, bounds, frame) or(err) {eprintln(err.msg())
            << false}
        << true
    }
    fn (model $&Model) draw_node(id int, bounds &layout.Rect, frame $&draw.Frame) int {
        if id == model.header_id{
            demo.text(&model.context, frame, 0.0, 0.0, 14.0, demo.accent(), "03 / RETAINED LAYOUT + CONTROLS") or >>
            demo.text(&model.context, frame, 0.0, 28.0, 24.0, demo.ink(), "Actions completed: " + str(model.count)) or >>
        } else if id == model.button_id{
            model.place_button(bounds) or >>
            model.button.paint(frame, &model.button_label, &model.theme) or >>
        } else if id == model.check_id{
            model.place_checkbox(bounds) or >>
            model.checkbox.paint(frame, &model.checkbox_label, &model.theme) or >>
        } else if id == model.progress_id{
            model.place_progress(bounds) or >>
            model.progress.paint(frame, &model.theme) or >>
        } else if id == model.scroll_id{
            scroll := $&model.scroll
            scroll.set_bounds(bounds) or >>
            frame.fill_rect(0.0, 0.0, bounds.width, bounds.height, draw.rgb(26, 37, 50)) or >>
        } else {
            for i in 0:model.row_ids.len{
                if id == model.row_ids[i] {demo.text(&model.context, frame, 12.0, 5.0, 15.0, demo.muted(), "Retained row " + str(i + 1) + " / scroll, Tab, PageDown, Home") or >> }
            }
        }
        << 0
    }
    fn (model $&Model) advance() int {
        model.count = model.count + 1
        println("Action count: " + str(model.count))
        value := f64(model.count % 11) / 10.0
        progress := $&model.progress
        << progress.set_value(value) or >>
    }
    fn (model $&Model) enable_button(enabled bool) {
        button := $&model.button
        button.set_enabled(enabled)
    }
    fn (model $&Model) acknowledge_button() {
        control := $&model.button
        control.painted()
    }
    fn (model $&Model) acknowledge_checkbox() {
        control := $&model.checkbox
        control.painted()
    }
    fn (model $&Model) acknowledge_progress() {
        control := $&model.progress
        control.painted()
    }
    fn (model $&Model) acknowledge_scroll() {
        control := $&model.scroll
        control.painted()
    }
    fn (model $&Model) acknowledge() {
        model.acknowledge_button()
        model.acknowledge_checkbox()
        model.acknowledge_progress()
        model.acknowledge_scroll()
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) or >>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) or >>
        context := draw.context_of(&ready) or >>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(28.0) or >>
        column.gap = 14.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, demo.background()) or >>
        leaf := layout.box_style(layout.BOX_LEAF)
        header := view.add(view.root(), &leaf, &layout.Size{width: 400.0, height: 72.0}) or >>
        button_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 44.0}) or >>
        check_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 40.0}) or >>
        progress_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 12.0}) or >>
        $viewport := layout.box_style(layout.BOX_COLUMN)
        viewport.height = 220.0
        viewport.clip = true
        viewport.cross_alignment = layout.CROSS_STRETCH
        viewport.gap = 6.0
        scroll_id := view.add(view.root(), &viewport, &layout.Size{width: 400.0, height: 220.0}) or >>
        $rows :=[]int {}
        for _ in 0:20 {
            row := view.add(scroll_id, &leaf, &layout.Size{width: 400.0, height: 32.0}) or >>
            rows.push(row)
            view.set_boundary(row, true) or >>
        }
        for id in[header, button_id, check_id, progress_id, scroll_id] {view.set_boundary(id, true) or >> }
        for id in[button_id, check_id, scroll_id] {view.set_input(id, true, true) or >> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        options := draw.text_options(15.0)
        first := "Complete one action"
        second := "Enable action button"
        $model := Model{button: widgets.button(&identity, button_id, &empty) or >>,
            checkbox: widgets.checkbox(&identity, check_id, &empty, true) or >>,
            progress: widgets.progress(&empty, 0.0) or >>,
            scroll: widgets.scroll(&identity, scroll_id, &empty, widgets.AXIS_VERTICAL, 760.0) or >>,
            button_label: context.layout_text(&first, &options) or >>,
            checkbox_label: context.layout_text(&second, &options) or >>,
            theme: widgets.default_theme(), context: context, count: 0, header_id: header, button_id: button_id, check_id: check_id, progress_id: progress_id, scroll_id: scroll_id, row_ids: rows}
        dispatcher := register_actions(&model, &view) or >>
        $width := 700.0
        $height := 600.0
        while true {
            constraints := layout.tight(width, height) or >>
            submitted := widgets.present($&view, &constraints, $&model) or >>
            if submitted{model.acknowledge()}
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT{ <- }
            if event.window_id != identity.window_id{ -> }
            if event.kind == ui.EV_CANVAS_METRICS{
                metrics := ui.metrics_of(&event) or >>
                if metrics.width > 0.0 && metrics.height > 0.0 {width = metrics.width
                    height = metrics.height}
            }
            actions := widgets.dispatch_event($&view, &event, $&model) or >>
            for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) or >> }
            if event.kind == ui.EV_CANVAS_CLOSED{ <- }
            if ui.is_input_event(event.kind) {
                input := ui.input_of(&event) or >>
                if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() or >> }
            }
            stats := view.stats()
            if stats.recorded_boundaries > 0 || stats.reused_boundaries > 0 {
                println("View: " + str(stats.recorded_boundaries) + " recorded / " + str(stats.reused_boundaries) + " reused boundaries")
            }
        }
        view.dispose()
        // Native close revokes resources; only release user handles while live.
        if demo.alive(&identity) {
            label := $&model.button_label
            label.dispose() or >>
            check_label := $&model.checkbox_label
            check_label.dispose() or >>
        }
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) or(err) {demo.fail(err.msg())
            << }}
    fn launch() int {
        $app := demo.app("Xu UI / Retained Controls", 700, 600) or >>
        xu worker(app.event_ch)
        << app.run() or >>
    }
    fn main() int { << launch() or(err) {eprintln(err.msg())
            << 1}}
  • 16_ui_webview/editor_workbench/main.xu

    Required SDK: Xu 0.10.13-dev.1 · Complete project · Download source · events.xu

    XuLocal SDK example
    @main
    #ui
    #ui/draw
    #ui/widgets
    #ui/layout
    tokens #xuui_tokens
    demo #"github.com/xulang-org/examples/ui_demo"
    
    struct Model{
        title widgets.Editor
        body widgets.Editor
        context draw.Context
        styles widgets.Styles
        dark bool
        header int
        title_id int
        body_id int
        footer int
        changes int
        status string
    }
    fn (model $&Model) input(id int, kind int, event &ui.InputEvent) widgets.Action{
        if id == model.title_id{control := $&model.title
            << control.route(kind, event) or >> }
        if id == model.body_id{control := $&model.body
            << control.route(kind, event) or >> }
        << widgets.Action{kind: 0, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
    }
    fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
        model.draw_node(id, frame) or(err) {eprintln(err.msg())
            << false}
        << true
    }
    fn (model $&Model) draw_node(id int,frame $&draw.Frame) int {
        styles := model.styles.clone()
        if id == model.title_id { control := $&model.title
            control.paint_styled(frame,&styles) or >> }
        else if id == model.body_id { control := $&model.body
            control.paint_styled(frame,&styles) or >> }
        else if id == model.header {
            demo.text(&model.context,frame,0.0,0.0,24.0,tokens.text(model.dark),"Writing desk") or >>
            demo.text(&model.context,frame,0.0,34.0,14.0,tokens.muted(model.dark),"XUUI design standard · native text and menu controls") or >>
            demo.text(&model.context,frame,0.0,62.0,14.0,tokens.muted(model.dark),"Tab / Shift+Tab · drag selection · copy / cut / paste · arrows / Home / End") or >>
        } else if id == model.footer {
            demo.text(&model.context,frame,0.0,0.0,14.0,tokens.brand(model.dark),"Changes: " + str(model.changes) + "  |  " + model.status) or >>
            demo.text(&model.context,frame,0.0,27.0,14.0,tokens.muted(model.dark),"Use the Document menu: toggle editing, reset, query screens. Escape quits.") or >>
        }
        << 0
    }
    fn (model $&Model) place(view $&widgets.View) int {
        title := $&model.title
        widgets.place_editor(view, title) or >>
        body := $&model.body
        widgets.place_editor(view, body) or >>
        << 0
    }
    fn (model $&Model) native_event(event &ui.Event) bool {
        title := $&model.title
        first := title.event(event) or >>
        body := $&model.body
        second := body.event(event) or >>
        << first.kind == widgets.ACTION_CHANGE || second.kind == widgets.ACTION_CHANGE
    }
    fn (model $&Model) editing(on bool) int {
        title := $&model.title
        title.enable(on) or >>
        body := $&model.body
        body.enable(on) or >>
        << 0
    }
    fn (model $&Model) reset() int {
        title := $&model.title
        title.set_value(&"Untitled note") or >>
        body := $&model.body
        body.set_value(&"Write here.\n你好,Xu。\n\nSelection and IME are native; layout and painting stay in the retained View.") or >>
        << 0
    }
    fn menus(window &ui.Window,enabled bool,dark bool) int {
        $entries := [ui.submenu("document","Document",-1)]
        $reset := ui.menu_action("reset","Reset note",0)
        reset.key = 82
        reset.modifiers = ui.MENU_PRIMARY | ui.MOD_SHIFT
        entries.push(reset)
        entries.push(ui.menu_check("editing","Enable editing",0,enabled))
        entries.push(ui.menu_separator(0))
        entries.push(ui.submenu("display","Displays",0))
        $query := ui.menu_action("screens","Query current screens",4)
        query.key = 68
        query.modifiers = ui.MENU_PRIMARY | ui.MOD_SHIFT
        entries.push(query)
        $unavailable := ui.menu_action("unavailable","Unavailable action",4)
        unavailable.enabled = false
        entries.push(unavailable)
        entries.push(ui.menu_check("dark-theme","Dark appearance",0,dark))
        << window.set_menu_entries(entries) or >>
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) or >>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) or >>
        context := draw.context_of(&ready) or >>
        window := ui.Window{id: identity.window_id, generation: identity.generation, title: "", width: 0, height: 0, content_kind: ui.CONTENT_DRAW, content_backend_id: identity.canvas_id, closed: 0}
        menus(&window, true, false) or >>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(24.0) or >>
        column.gap = 16.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, tokens.canvas(false)) or >>
        leaf := layout.box_style(layout.BOX_LEAF)
        header := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 88.0}) or >>
        title_id := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 44.0}) or >>
        body_id := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 260.0}) or >>
        footer := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 72.0}) or >>
        for id in[header, title_id, body_id, footer] {view.set_boundary(id, true) or >> }
        for id in[title_id, body_id] {view.set_input(id, true, true) or >> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        $model := Model{title: widgets.input(&context, &identity, title_id, &empty, &"Untitled note") or >>,
            body: widgets.text_area(&context, &identity, body_id, &empty, &"Write here.\n你好,Xu。\n\nSelection and IME are native; layout and painting stay in the retained View.") or >>,
            context: context, styles: tokens.editor_styles(false), dark: false, header: header, title_id: title_id, body_id: body_id, footer: footer, changes: 0, status: "Ready"}
        $dispatcher := widgets.action_dispatcher(&model, &view)
        dispatcher.on(title_id, widgets.ACTION_SUBMIT, submit_title) or >>
        $width := 820.0
        $height := 620.0
        $enabled := true
        options := ui.RequestOptions{timeout_ms: 5000}
        $screens := window.screens_async(&options) or >>
        $event := ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
        // Native text snapshots already carry the latest revision. Drain queued
        // edits before painting so a key burst cannot fill the frame queue.
        while true {
            if event.kind == ui.EV_NONE{
                constraints := layout.tight(width, height) or >>
                _ := view.layout(&constraints) or >>
                model.place($&view) or >>
                submitted := widgets.present($&view, &constraints, $&model) or >>
                if submitted{
                    first := $&model.title
                    first.painted()
                    second := $&model.body
                    second.painted()
                }
                event = demo.next(ech)
            }
            if event.kind == ui.EV_EXIT{ <- }
            if event.window_id != identity.window_id{event = ui.poll_chan(ech)
                -> }
            if event.kind == ui.EV_CANVAS_METRICS{metrics := ui.metrics_of(&event) or >>
                width = metrics.width
                height = metrics.height}
            actions := widgets.dispatch_event($&view, &event, $&model) or >>
            if model.native_event(&event) or >> {model.changes = model.changes + 1
                view.mark_paint(footer) or >> }
            for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) or >> }
            if event.kind == ui.EV_MENU_CLICKED{
                if event.menu_id == "reset" {model.reset() or >> }
                if event.menu_id == "editing" {enabled = !enabled
                    model.editing(enabled) or >>
                    for id in[title_id, body_id] {view.set_input(id, enabled, enabled) or >> }
                    menus(&window, enabled, model.dark) or >> }
                if event.menu_id == "dark-theme" {
                    model.dark = !model.dark
                    model.styles = tokens.editor_styles(model.dark)
                    view.set_background(tokens.canvas(model.dark))
                    for id in [header,title_id,body_id,footer] { view.mark_paint(id) or >> }
                    menus(&window,enabled,model.dark) or >>
                }
                if event.menu_id == "screens" {screens.cancel()
                    screens = window.screens_async(&options) or >> }
            }
            if event.kind == ui.EV_REQUEST{result := ui.request_of(&event) or >>
                if result.matches(&screens) && result.status == ui.REQUEST_COMPLETED{
                    displays := ui.screen_result(&result) or >>
                    model.status = str(displays.len) + " display(s)"
                    for display in displays{println("Screen: " + display.name + " / " + str(int(display.bounds.width)) + " x " + str(int(display.bounds.height)) + " / scale " + str(int(display.scale_x)))
                        if display.current{model.status = display.name + " · " + str(int(display.bounds.width)) + " x " + str(int(display.bounds.height))}}
                    view.mark_paint(footer) or >>
                }
            }
            if event.kind == ui.EV_CANVAS_CLOSED || event.kind == ui.EV_CLOSED{ <- }
            if ui.is_input_event(event.kind) {input := ui.input_of(&event) or >>
                if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() or >> }}
            event = ui.poll_chan(ech)
        }
        screens.cancel()
        view.dispose()
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) or(err) {demo.fail(err.msg())
            << }}
    fn main() int {
        $app := demo.app("Xu UI / Writing Desk", 820, 620) or(err) {eprintln(err.msg())
            << 1}
        xu worker(app.event_ch)
        << app.run() or(err) {eprintln(err.msg())
            << 1}
    }
  • 16_ui_webview/workbench/main.xu

    Required SDK: Xu 0.10.13-dev.1 · Complete project · Download source · events.xu

    XuLocal SDK example
    @main
    #ui
    #ui/draw
    #ui/layout
    #ui/widgets
    #math
    demo #"github.com/xulang-org/examples/ui_demo"
    
    struct Model{
        button widgets.Button
        checkbox widgets.Checkbox
        progress widgets.Progress
        scroll widgets.Scroll
        button_label draw.TextLayout
        checkbox_label draw.TextLayout
        theme widgets.Theme
        context draw.Context
        count int
        message string
        source string
        images []draw.Image
        header_id int
        button_id int
        check_id int
        progress_id int
        scroll_id int
        row_ids []int
        identity ui.CanvasEvent
        pending ui.Request
    }
    fn (model $&Model) button_input(kind int, input &ui.InputEvent) widgets.Action{
        button := $&model.button
        << button.route(kind, input) or >>
    }
    fn (model $&Model) checkbox_input(kind int, input &ui.InputEvent) widgets.Action{
        checkbox := $&model.checkbox
        << checkbox.route(kind, input) or >>
    }
    fn (model $&Model) scroll_input(kind int, input &ui.InputEvent) widgets.Action{
        scroll := $&model.scroll
        << scroll.route(kind, input) or >>
    }
    fn (model $&Model) input(id int, kind int, input &ui.InputEvent) widgets.Action{
        if id == model.button_id{ << model.button_input(kind, input) or >> }
        if id == model.check_id{ << model.checkbox_input(kind, input) or >> }
        if id == model.scroll_id{ << model.scroll_input(kind, input) or >> }
        << widgets.Action{kind: widgets.ACTION_NONE, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
    }
    fn (model $&Model) place_button(bounds &layout.Rect) int {
        button := $&model.button
        << button.set_bounds(bounds) or >>
    }
    fn (model $&Model) place_checkbox(bounds &layout.Rect) int {
        checkbox := $&model.checkbox
        << checkbox.set_bounds(bounds) or >>
    }
    fn (model $&Model) place_progress(bounds &layout.Rect) int {
        progress := $&model.progress
        << progress.set_bounds(bounds) or >>
    }
    fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
        model.draw_node(id, bounds, frame) or(err) {eprintln(err.msg())
            << false}
        << true
    }
    fn (model $&Model) draw_node(id int, bounds &layout.Rect, frame $&draw.Frame) int {
        if id == model.header_id{
            demo.text(&model.context, frame, 0.0, 0.0, 14.0, demo.accent(), "07 / IMAGE WORKBENCH") or >>
            demo.text(&model.context, frame, 0.0, 28.0, 24.0, demo.ink(), "Image workbench") or >>
            demo.text(&model.context, frame, 0.0, 58.0, 13.0, demo.muted(), model.message + "") or >>
        } else if id == model.button_id{
            model.place_button(bounds) or >>
            model.button.paint(frame, &model.button_label, &model.theme) or >>
        } else if id == model.check_id{
            model.place_checkbox(bounds) or >>
            model.checkbox.paint(frame, &model.checkbox_label, &model.theme) or >>
        } else if id == model.progress_id{
            model.place_progress(bounds) or >>
            model.progress.paint(frame, &model.theme) or >>
        } else if id == model.scroll_id{
            scroll := $&model.scroll
            scroll.set_bounds(bounds) or >>
            frame.fill_rect(0.0, 0.0, bounds.width, bounds.height, draw.rgb(26, 37, 50)) or >>
        } else if model.row_ids.len > 0 && id == model.row_ids[0] {
            if model.images.len > 0 {
                image := model.images[0]
                scale := math.min(bounds.width / f64(image.width), bounds.height / f64(image.height))
                frame.image(&image, 0.0, 0.0, f64(image.width) * scale, f64(image.height) * scale) or >>
            } else {demo.text(&model.context, frame, 12.0, 20.0, 17.0, demo.muted(), "The selected image appears here.") or >> }
        }
        << 0
    }
    fn (model $&Model) progress_value(value f64) int {
        progress := $&model.progress
        << progress.set_value(value) or >>
    }
    fn (model $&Model) retire_image(index int) int {
        $image := model.images[index]
        image.dispose() or >>
        model.images[index] = image
        << 0
    }
    fn (model $&Model) replace_image(image draw.Image) int {
        for i in 0:model.images.len{model.retire_image(i) or >> }
        model.images =[]draw.Image{}
        model.images.push(image)
        << 0
    }
    fn preview_paint(window &ui.Window, path &string) int {
        context := draw.window_context(window) or >>
        $image := context.load_image(path) or >>
        $frame := context.new_frame(256)
        frame.begin() or >>
        frame.set_bg(demo.background()) or >>
        scale := math.min(f64(window.width - 40) / f64(image.width), f64(window.height - 40) / f64(image.height))
        frame.image(&image, 20.0, 20.0, f64(image.width) * scale, f64(image.height) * scale) or >>
        frame.present() or >>
        frame.dispose()
        image.dispose() or >>
        << 0
    }
    fn (model $&Model) acknowledge_button() {
        control := $&model.button
        control.painted()
    }
    fn (model $&Model) acknowledge_checkbox() {
        control := $&model.checkbox
        control.painted()
    }
    fn (model $&Model) acknowledge_progress() {
        control := $&model.progress
        control.painted()
    }
    fn (model $&Model) acknowledge_scroll() {
        control := $&model.scroll
        control.painted()
    }
    fn (model $&Model) acknowledge() {
        model.acknowledge_button()
        model.acknowledge_checkbox()
        model.acknowledge_progress()
        model.acknowledge_scroll()
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) or >>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) or >>
        context := draw.context_of(&ready) or >>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(28.0) or >>
        column.gap = 14.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, demo.background()) or >>
        leaf := layout.box_style(layout.BOX_LEAF)
        header := view.add(view.root(), &leaf, &layout.Size{width: 400.0, height: 88.0}) or >>
        button_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 44.0}) or >>
        check_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 40.0}) or >>
        progress_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 12.0}) or >>
        $viewport := layout.box_style(layout.BOX_COLUMN)
        viewport.height = 260.0
        viewport.clip = true
        viewport.cross_alignment = layout.CROSS_STRETCH
        viewport.gap = 6.0
        scroll_id := view.add(view.root(), &viewport, &layout.Size{width: 400.0, height: 260.0}) or >>
        $rows :=[]int {}
        for _ in 0:1 {
            row := view.add(scroll_id, &leaf, &layout.Size{width: 400.0, height: 250.0}) or >>
            rows.push(row)
            view.set_boundary(row, true) or >>
        }
        for id in[header, button_id, check_id, progress_id, scroll_id] {view.set_boundary(id, true) or >> }
        for id in[button_id, check_id, scroll_id] {view.set_input(id, true, true) or >> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        options := draw.text_options(15.0)
        first := "Open a PNG or JPEG"
        second := "Show a separate preview window"
        $model := Model{button: widgets.button(&identity, button_id, &empty) or >>,
            checkbox: widgets.checkbox(&identity, check_id, &empty, true) or >>,
            progress: widgets.progress(&empty, 0.0) or >>,
            scroll: widgets.scroll(&identity, scroll_id, &empty, widgets.AXIS_VERTICAL, 250.0) or >>,
            button_label: context.layout_text(&first, &options) or >>,
            checkbox_label: context.layout_text(&second, &options) or >>,
            theme: widgets.default_theme(), context: context, count: 0, message: "Open a local image to begin.", source: "", images:[]draw.Image{}, header_id: header, button_id: button_id, check_id: check_id, progress_id: progress_id, scroll_id: scroll_id, row_ids: rows, identity: identity, pending: ui.Request{id: 0, window_id: 0, canvas_id: 0, generation: 0, kind: 0}}
        $width := 900.0
        $height := 700.0
        $native := demo.windows(ech)
        $preview := ui.Window{id: 0, generation: 0, title: "Preview", width: 720, height: 500, content_kind: ui.CONTENT_DRAW, content_backend_id: 0, closed: 1}
        dispatcher := register_actions(&model, &view) or >>
        while true {
            constraints := layout.tight(width, height) or >>
            submitted := widgets.present($&view, &constraints, $&model) or >>
            if submitted{model.acknowledge()}
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT{ <- }
            if preview.id > 0 && event.window_id == preview.id{
                if event.kind == ui.EV_CLOSED || event.kind == ui.EV_WINDOW_FAILED{preview.closed = 1}
                if event.kind == ui.EV_CANVAS_READY && model.source.len > 0 {
                    preview.content_command("input_enabled\t1") or >>
                    preview.content_command("pan_enabled\t0") or >>
                    preview_paint(&preview, &model.source) or >> }
                if event.kind == ui.EV_CANVAS_METRICS{
                    metrics := ui.metrics_of(&event) or >>
                    if metrics.width > 40.0 && metrics.height > 40.0 {preview.width = int(metrics.width)
                        preview.height = int(metrics.height)
                        if model.source.len > 0 {preview_paint(&preview, &model.source) or >> }}
                }
                ->
            }
            if event.window_id != identity.window_id{ -> }
            if event.kind == ui.EV_REQUEST{
                result := ui.request_of(&event) or >>
                if result.matches(&model.pending) {
                    model.pending.id = 0
                    model.message = "Selection cancelled or failed."
                    if result.status == ui.REQUEST_COMPLETED{
                        paths := ui.file_paths(&result) or >>
                        if paths.len > 0 {
                            path := paths[0] + ""
                            image := context.load_image(&path) or(err) {model.message = err.msg()
                                view.mark_paint(header) or >>
                                -> }
                            model.replace_image(image) or >>
                            model.source = path + ""
                            model.message = "Loaded " + str(image.width) + " x " + str(image.height) + " pixels"
                            println(model.message + "")
                            model.progress_value(1.0) or >>
                            view.mark_paint(model.row_ids[0]) or >>
                            if model.checkbox.value() {
                                if preview.closed != 0 {preview = native.open_content_window(ui.WindowOpts{title: "Xu UI / Image Preview", width: 720, height: 500}, ui.CONTENT_DRAW) or >> }
                                else {preview_paint(&preview, &path) or >>
                                    preview.focus() or >> }
                            }
                        }
                    }
                    view.mark_paint(header) or >>
                    view.mark_paint(progress_id) or >>
                }
            }
            if event.kind == ui.EV_CANVAS_METRICS{
                metrics := ui.metrics_of(&event) or >>
                if metrics.width > 0.0 && metrics.height > 0.0 {width = metrics.width
                    height = metrics.height}
            }
            actions := widgets.dispatch_event($&view, &event, $&model) or >>
            for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) or >> }
            if event.kind == ui.EV_CANVAS_CLOSED{demo.quit() or >>
                <- }
            if ui.is_input_event(event.kind) {
                input := ui.input_of(&event) or >>
                if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() or >> }
            }
            stats := view.stats()
            if stats.recorded_boundaries > 0 || stats.reused_boundaries > 0 {
                println("View: " + str(stats.recorded_boundaries) + " recorded / " + str(stats.reused_boundaries) + " reused boundaries")
            }
        }
        if model.pending.id > 0 {_ := model.pending.cancel()}
        view.dispose()
        // Native close has already revoked this canvas's images and text layouts.
        if demo.alive(&identity) {
            for i in 0:model.images.len{model.retire_image(i) or >> }
            label := $&model.button_label
            label.dispose() or >>
            check_label := $&model.checkbox_label
            check_label.dispose() or >>
        }
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) or(err) {demo.fail(err.msg())
            << }}
    fn launch() int {
        $app := demo.app("Xu UI / Retained Image Workbench", 900, 700) or >>
        xu worker(app.event_ch)
        << app.run() or >>
    }
    fn main() int { << launch() or(err) {eprintln(err.msg())
            << 1}}
  • 16_ui_webview/style_gallery/main.xu

    Required SDK: Xu 0.10.13-dev.1 · Complete project · Download source · events.xu · style.xu

    XuLocal SDK example
    @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) or >>
    }
    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) or >> }
            else if motion.advance(now) or >> {view.mark_paint(id) or >> }
        }
        $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) or >>, reduced) or >>
        if before_switch != switch_motion.value() {view.mark_paint(32) or >> }
        $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) or >>
        if opened == 0.0 {popup_duration = time.milliseconds(95) or >> }
        popup_motion.retarget(opened, now, popup_duration, reduced) or >>
        if before_popup != popup_motion.value() {view.mark_paint(1) or >> }
        input := $&m.input
        if input.tick(now, reduced) or >> {view.mark_paint(12) or >> }
        invalid := $&m.invalid
        if invalid.tick(now, reduced) or >> {view.mark_paint(13) or >> }
        read_only := $&m.read_only
        if read_only.tick(now, reduced) or >> {view.mark_paint(14) or >> }
        area := $&m.area
        if area.tick(now, reduced) or >> {view.mark_paint(15) or >> }
        << 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) or >>) or >> }
        for motion in m.transitions{if motion.is_animating() { << now.add(time.milliseconds(16) or >>) or >> }}
        $deadline := time.zero_instant()
        for next in[m.input.next_caret_tick(now, m.reduced_motion) or >>, m.invalid.next_caret_tick(now, m.reduced_motion) or >>,
        m.read_only.next_caret_tick(now, m.reduced_motion) or >>, m.area.next_caret_tick(now, m.reduced_motion) or >>] {
            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()) or >>
        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) or >>
            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) or >> }
        if id == 5 {control := m.scale.clone()
            label := $&m.scale_label
            << control.measure_styled(label, s) or >> }
        if id == 6 {control := m.density.clone()
            label := $&m.density_label
            << control.measure_styled(label, s) or >> }
        if id == 8 {control := m.brand.clone()
            label := $&m.brand_label
            << control.measure_icon_styled(label, s) or >> }
        if id == 9 {control := m.disabled.clone()
            label := $&m.disabled_label
            << control.measure_styled(label, s) or >> }
        if id == 10 {control := m.check.clone()
            label := $&m.check_label
            << control.measure_styled(label, s) or >> }
        if id == 11 {control := m.progress.clone()
            << control.measure_styled(s) or >> }
        if id == 12 {control := $&m.input
            << control.measure_styled(s) or >> }
        if id == 13 {control := $&m.invalid
            << control.measure_styled(s) or >> }
        if id == 14 {control := $&m.read_only
            << control.measure_styled(s) or >> }
        if id == 15 {control := $&m.area
            << control.measure_styled(s) or >> }
        if id == 32 {control := m.toggle.clone()
            label := $&m.toggle_label
            << control.measure_styled(label, s) or >> }
        if id == 33 {control := m.radio_a.clone()
            label := $&m.radio_a_label
            << control.measure_styled(label, s) or >> }
        if id == 34 {control := m.radio_b.clone()
            label := $&m.radio_b_label
            << control.measure_styled(label, s) or >> }
        if id == 35 {control := m.slider.clone()
            << control.measure_styled(s) or >> }
        if id == 36 {control := m.stepper.clone()
            label := $&m.stepper_label
            << control.measure_styled(label, s) or >> }
        if id == 37 {control := m.badge.clone()
            label := $&m.badge_label
            << control.measure_styled(label, s) or >> }
        if id == 38 {control := m.divider.clone()
            label := $&m.divider_label
            << control.measure_labeled_styled(label, s) or >> }
        if id == 40 {control := m.tabs.clone()
            label := $&m.tab_label
            << control.measure_styled(label, s) or >> }
        if id == 41 {control := m.select_ctrl.clone()
            label := $&m.select_label
            << control.measure_styled(label, s) or >> }
        if id == 42 {control := m.card.clone()
            label := $&m.card_label
            << control.measure_header_styled(label, s) or >> }
        if id == 43 {control := m.list.clone()
            label := $&m.list_label
            << control.measure_styled(label, s) or >> }
        << 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) or(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) or >>
            $control := m.theme.clone()
            base := control.style_or(s)
            appearance := m.motion_style(4, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.theme_label
            control.paint_styled(f, label, s) or >> }
        if id == 5 {target := $&m.scale
            target.set_bounds(b) or >>
            $control := m.scale.clone()
            base := control.style_or(s)
            appearance := m.motion_style(5, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.scale_label
            control.paint_styled(f, label, s) or >> }
        if id == 6 {target := $&m.density
            target.set_bounds(b) or >>
            $control := m.density.clone()
            base := control.style_or(s)
            appearance := m.motion_style(6, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.density_label
            control.paint_styled(f, label, s) or >> }
        if id == 8 {target := $&m.brand
            target.set_bounds(b) or >>
            $control := m.brand.clone()
            base := control.style_or(s)
            appearance := m.motion_style(8, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            icon := m.icon
            label := $&m.brand_label
            control.paint_icon_styled(f, label, &icon, s) or >> }
        if id == 9 {target := $&m.disabled
            target.set_bounds(b) or >>
            $control := m.disabled.clone()
            base := control.style_or(s)
            appearance := m.motion_style(9, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.disabled_label
            control.paint_styled(f, label, s) or >> }
        if id == 10 {target := $&m.check
            target.set_bounds(b) or >>
            $control := m.check.clone()
            base := control.style_or(s)
            appearance := m.motion_style(10, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.check_label
            control.paint_styled(f, label, s) or >> }
        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) or >>
            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) or >>
            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) or >>
            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) or >>
            m.transitions[15] = motion}
        if id == 11 {control := $&m.progress
            control.set_bounds(b) or >>
            control.paint_styled(f, s) or >> }
        if id == 32 {target := $&m.toggle
            target.set_bounds(b) or >>
            $control := m.toggle.clone()
            base := control.style_or(s)
            appearance := m.motion_style(32, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            position := m.switch_motion.value()
            label := $&m.toggle_label
            control.paint_position_styled(f, label, s, position) or >> }
        if id == 33 {target := $&m.radio_a
            target.set_bounds(b) or >>
            $control := m.radio_a.clone()
            base := control.style_or(s)
            appearance := m.motion_style(33, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.radio_a_label
            control.paint_styled(f, label, s) or >> }
        if id == 34 {target := $&m.radio_b
            target.set_bounds(b) or >>
            $control := m.radio_b.clone()
            base := control.style_or(s)
            appearance := m.motion_style(34, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.radio_b_label
            control.paint_styled(f, label, s) or >> }
        if id == 35 {target := $&m.slider
            target.set_bounds(b) or >>
            $control := m.slider.clone()
            base := control.style_or(s)
            appearance := m.motion_style(35, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            control.paint_styled(f, s) or >> }
        if id == 36 {target := $&m.stepper
            target.set_bounds(b) or >>
            $control := m.stepper.clone()
            base := control.style_or(s)
            appearance := m.motion_style(36, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.stepper_label
            control.paint_styled(f, label, s) or >> }
        if id == 37 {target := $&m.badge
            target.set_bounds(b) or >>
            control := m.badge.clone()
            label := $&m.badge_label
            control.paint_styled(f, label, s) or >> }
        if id == 38 {target := $&m.divider
            target.set_bounds(b) or >>
            control := m.divider.clone()
            label := $&m.divider_label
            control.paint_labeled_styled(f, label, s) or >> }
        if id == 40 {target := $&m.tabs
            target.set_bounds(b) or >>
            control := m.tabs.clone()
            control.paint_box_styled(f, s) or >>
            l0 := $&m.tab_label
            control.paint_tab_styled(f, 0, l0, s) or >>
            l1 := $&m.tab_2_label
            control.paint_tab_styled(f, 1, l1, s) or >>
            l2 := $&m.tab_3_label
            control.paint_tab_styled(f, 2, l2, s) or >> }
        if id == 41 {target := $&m.select_ctrl
            target.set_bounds(b) or >>
            $control := m.select_ctrl.clone()
            base := control.style_or(s)
            appearance := m.motion_style(41, &base, control.visual_state()) or >>
            control.set_style(&appearance) or >>
            label := $&m.select_label
            control.paint_styled(f, label, s) or >> }
        if id == 42 {target := $&m.card
            target.set_bounds(b) or >>
            control := m.card.clone()
            label := $&m.card_label
            control.paint_header_styled(f, label, s) or >>
            demo.text(&m.context, f, 14.0 * s.density, 42.0 * s.density, 11.0 * s.text_scale, s.button.palette.muted, "Card body") or >> }
        if id == 43 {target := $&m.list
            target.set_bounds(b) or >>
            control := m.list.clone()
            control.paint_box_styled(f, s) or >>
            r0 := $&m.list_label
            control.paint_item_styled(f, 0, r0, s) or >>
            r1 := $&m.list_2_label
            control.paint_item_styled(f, 1, r1, s) or >>
            r2 := $&m.list_3_label
            control.paint_item_styled(f, 2, r2, s) or >>
            r3 := $&m.list_4_label
            control.paint_item_styled(f, 3, r3, s) or >> }
        if id == 2 {
            demo.text(&m.context, f, 0.0, 0.0, 24.0, s.button.palette.foreground, "A theme that reaches every control") or >>
            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") or >>
        }
        if id >= 18 && id <= 29 {
            f.fill_rect(0.0, 0.0, b.width, b.height, s.input.palette.normal) or >>
            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") or >>
        }
        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.") or >>
            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") or >>
        }
        << 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) or(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) or(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) or(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) or >>
        control.set_style(&appearance) or >>
        popup := control.popup_bounds(s)
        $offset := - 4.0 *(1.0 - opacity)
        if popup.y < 0.0 {offset = 4.0 *(1.0 - opacity)}
        f.push() or >>
        f.translate(m.select_origin.x, m.select_origin.y + offset) or >>
        control.paint_popup_box_styled(f, s) or >>
        auto_label := $&m.option_auto
        control.paint_option_styled(f, 0, auto_label, s) or >>
        manual_label := $&m.option_manual
        control.paint_option_styled(f, 1, manual_label, s) or >>
        locked_label := $&m.option_locked
        control.paint_option_styled(f, 2, locked_label, s) or >>
        f.pop() or >>
        << 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) or >>
            styles := view.styles_for(41) or >>
            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) or >>
                view.set_pointer_cursor(ui.CURSOR_HAND) or >>
                if event.kind == ui.EV_POINTER_UP{m.select_popup_armed = false}
                view.mark_paint(41) or >>
                view.mark_paint(1) or >>
                <<[action]
            }
        }
        if event.kind == ui.EV_POINTER_CANCEL{m.select_popup_armed = false}
        actions := widgets.dispatch(view, event, m) or >>
        if was_open || m.select_ctrl.is_open() {view.mark_paint(1) or >> }
        << 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) or >>
            << m.dispatch_input(view, &input) or >>
        }
        was_open := m.select_ctrl.is_open()
        actions := widgets.dispatch_event(view, event, m) or >>
        m.select_popup_armed = false
        if was_open && !m.select_ctrl.is_open() {view.mark_paint(1) or >> }
        << actions
    }
    fn (m $&Model) input(id int, kind int, event &ui.InputEvent) widgets.Action{
        if id == 4 {control := $&m.theme
            << control.route(kind, event) or >> }
        if id == 5 {control := $&m.scale
            << control.route(kind, event) or >> }
        if id == 6 {control := $&m.density
            << control.route(kind, event) or >> }
        if id == 8 {control := $&m.brand
            << control.route(kind, event) or >> }
        if id == 9 {control := $&m.disabled
            << control.route(kind, event) or >> }
        if id == 10 {control := $&m.check
            << control.route(kind, event) or >> }
        if id == 12 {control := $&m.input
            << control.route(kind, event) or >> }
        if id == 13 {control := $&m.invalid
            << control.route(kind, event) or >> }
        if id == 14 {control := $&m.read_only
            << control.route(kind, event) or >> }
        if id == 15 {control := $&m.area
            << control.route(kind, event) or >> }
        if id == 16 {control := $&m.scroll
            << control.route(kind, event) or >> }
        if id == 32 {control := $&m.toggle
            << control.route(kind, event) or >> }
        if id == 33 {control := $&m.radio_a
            << control.route(kind, event) or >> }
        if id == 34 {control := $&m.radio_b
            << control.route(kind, event) or >> }
        if id == 35 {control := $&m.slider
            << control.route(kind, event) or >> }
        if id == 36 {control := $&m.stepper
            << control.route(kind, event) or >> }
        if id == 40 {control := $&m.tabs
            << control.route(kind, event) or >> }
        if id == 41 {control := $&m.select_ctrl
            << control.route(kind, event) or >> }
        if id == 43 {control := $&m.list
            << control.route(kind, event) or >> }
        << 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) or >>
        m.select_origin = select_bounds
        select_styles := view.styles_for(41) or >>
        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}) or >>
        select_control.apply_styles(&select_styles) or >>
        popup := select_control.popup_bounds(&select_styles)
        window_bounds := view.node_bounds(1) or >>
        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) or >>
        list_styles := view.styles_for(43) or >>
        list_control := $&m.list
        list_control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: list_bounds.width, height: list_bounds.height}) or >>
        list_control.apply_styles(&list_styles) or >>
        input := $&m.input
        widgets.place_editor(view, input) or >>
        invalid := $&m.invalid
        widgets.place_editor(view, invalid) or >>
        read_only := $&m.read_only
        widgets.place_editor(view, read_only) or >>
        area := $&m.area
        widgets.place_editor(view, area) or >>
        bounds := view.node_bounds(16) or >>
        styles := view.styles_for(16) or >>
        control := $&m.scroll
        control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: bounds.width, height: bounds.height}) or >>
        control.apply_styles(&styles) or >>
        view.set_scroll(16, 0.0, control.offset()) or >>
        << 0
    }
    fn (m $&Model) native_event(view $&widgets.View, event &ui.Event) int {
        input := $&m.input
        action_12 := input.event(event) or >>
        if action_12.needs_paint{view.mark_paint(12) or >> }
        invalid := $&m.invalid
        action_13 := invalid.event(event) or >>
        if action_13.needs_paint{view.mark_paint(13) or >> }
        read_only := $&m.read_only
        action_14 := read_only.event(event) or >>
        if action_14.needs_paint{view.mark_paint(14) or >> }
        area := $&m.area
        action_15 := area.event(event) or >>
        if action_15.needs_paint{view.mark_paint(15) or >> }
        << 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() or(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}) or >>
    }
    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) or >>
        << 0
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) or >>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) or >>
        context := draw.context_of(&ready) or >>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(22.0) or >>
        column.gap = 10.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, draw.rgb(20, 25, 34)) or >>
        _ := leaf($&view, 1, 400.0, 56.0) or >>  // 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}) or >>  // 3 toolbar
        for i in 0:3 {_ := leaf($&view, 3, 0.0, 0.0) or >> }  // 4..6
        _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) or >>  // 7 controls
        for i in 0:3 {_ := leaf($&view, 7, 0.0, 0.0) or >> }  // 8..10
        _ := leaf($&view, 1, 300.0, 12.0) or >>  // 11 progress
        for i in 0:4 {_ := leaf($&view, 1, 300.0, 0.0) or >> }  // 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}) or >>  // 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}) or >>  // 17 items
        for i in 0:12 {_ := leaf($&view, 17, 300.0, 28.0) or >> }  // 18..29
        _ := leaf($&view, 1, 400.0, 42.0) or >>  // 30 footer
        _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) or >>  // 31 extended controls row 1
        for i in 0:6 {_ := leaf($&view, 31, 0.0, 0.0) or >> }  // 32..37: switch, radio_a, radio_b, slider, stepper, badge
        _ := leaf($&view, 1, 300.0, 0.0) or >>  // 38 labeled divider
        _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) or >>  // 39 extended controls row 2
        for i in 0:4 {_ := leaf($&view, 39, 0.0, 0.0) or >> }  // 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) or >> }
        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) or >> }
        view.set_capture_outside(16, true) or >>
        view.set_capture_outside(35, true) or >>
        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) or >> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        $m := Model{theme: widgets.button(&identity, 4, &empty) or >>, scale: widgets.button(&identity, 5, &empty) or >>,
            density: widgets.button(&identity, 6, &empty) or >>, brand: widgets.button(&identity, 8, &empty) or >>,
            disabled: widgets.button(&identity, 9, &empty) or >>, check: widgets.checkbox(&identity, 10, &empty, true) or >>,
            toggle: widgets.switch_control(&identity, 32, &empty, true) or >>,
            radio_a: widgets.radio(&identity, 33, &empty, 0, true) or >>,
            radio_b: widgets.radio(&identity, 34, &empty, 1, false) or >>,
            slider: widgets.slider(&identity, 35, &empty, 0.0, 100.0, 64.0) or >>,
            stepper: widgets.stepper(&identity, 36, &empty, 0.0, 100.0, 5.0, 65.0) or >>,
            tabs: widgets.tabs(&identity, 40, &empty, 3, 0) or >>,
            select_ctrl: widgets.select_box(&identity, 41, &empty, 3, 0) or >>,
            select_origin: empty, select_popup_armed: false,
            transitions:[]widgets.PaintTransition{}, switch_motion: widgets.tween(1.0) or >>, popup_motion: widgets.tween(0.0) or >>,
            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) or >>,
            divider: widgets.divider(&empty, widgets.AXIS_HORIZONTAL) or >>,
            card: widgets.card(&empty) or >>,
            list: widgets.list_box(&identity, 43, &empty, 4, 0) or >>,
            input: widgets.input(&context, &identity, 12, &empty, &"Editable input · 你好 Xu") or >>,
            invalid: widgets.input(&context, &identity, 13, &empty, &"Invalid value — custom error colors") or >>,
            read_only: widgets.input(&context, &identity, 14, &empty, &"Read-only · select and copy, edits are ignored") or >>,
            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.") or >>,
            progress: widgets.progress(&empty, 0.64) or >>, scroll: widgets.scroll(&identity, 16, &empty, widgets.AXIS_VERTICAL, 402.0) or >>,
            context: context, icon: context.load_embedded_image(&"logo.png") or >>, 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() or >>)}
        for id in[4, 5, 6, 8, 10, 32, 33, 34, 36, 40, 41, 43] {view.set_cursor(id, ui.CURSOR_HAND) or >> }
        for id in[12, 13, 14, 15] {view.set_cursor(id, ui.CURSOR_TEXT) or >> }
        view.set_cursor(35, ui.CURSOR_RESIZE_HORIZONTAL) or >>
        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) or >>
        apply_appearance($&m, $&view) or >>
        brand_scope($&view) or >>
        dispatcher := register_actions(&m, &view) or >>
        $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) or >>
        while true {
            if event.kind == ui.EV_NONE{
                apply_appearance($&m, $&view) or >>
                m.tick($&view, time.instant()) or >>
                constraints := layout.tight(width, height) or >>
                _ := widgets.layout_styled($&view, &constraints, $&m) or >>
                m.place($&view) or >>
                if widgets.present_styled($&view, &constraints, $&m) or >> {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) or >>
                    width = metrics.width
                    height = metrics.height}
                if event.kind == ui.EV_FOCUSED{ui.request_canvas_preferences(&identity) or >> }
                if event.kind == ui.EV_CANVAS_PREFERENCES{
                    preferences := ui.canvas_preferences_of(&event) or >>
                    if preferences.identity.canvas_id == identity.canvas_id && preferences.identity.generation == identity.generation{
                        m.reduced_motion = preferences.reduced_motion
                        view.mark_paint(1) or >>
                    }
                }
                popup_was_open := m.select_ctrl.is_open()
                actions := m.dispatch_event($&view, &event) or >>
                m.native_event($&view, &event) or >>
                for action in actions{_ := dispatcher.dispatch(&action, $&m, $&view) or >> }
                if ui.is_input_event(event.kind) {input := ui.input_of(&event) or >>
                    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() or >>
                        << 0
                    }}
            }
            event = ui.poll_chan(ech)
        }
        view.dispose()
        if demo.alive(&identity) {m.cleanup()}
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) or(err) {demo.fail(err.msg())
            << }}
    fn main() int {
        $app := demo.app("Xu UI / Style Gallery", 960, 820) or(err) {eprintln(err.msg())
            << 1}
        xu worker(app.event_ch)
        << app.run() or(err) {eprintln(err.msg())
            << 1}
    }
  • 16_ui_webview/component_workshop/main.xu

    Required SDK: Xu 0.10.13-dev.3 · Complete project · Download source · 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) or >>
        if ready.kind == ui.EV_EXIT{ << 0}
        $screen := widgets.screen(&ready) or >>
        screen.resize(1180.0, 900.0) or(err) {screen.dispose()
            >> err}
        screen.set_min_size(920, 780) or(err) {screen.dispose()
            >> err}
        $model := create($&screen) or(err) {screen.dispose()
            >> err}
        workshop_loop(events, $&model, $&screen) or(err) {screen.dispose()
            >> err}
        screen.dispose()
        << 0
    }
    
    fn worker(events chan ui.Event) {scene(events) or(err) {demo.fail(err.msg())
            << }}
    
    fn launch() int {
        $app := demo.app("XUUI / Component Workshop", 1180, 900) or >>
        xu worker(app.event_ch)
        << app.run() or >>
    }
    
    fn main() int { << launch() or(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) or >>
        screen.set_text(model.title, "XUUI  /  Field") or >>
        model.configure_controls(screen) or >>
        model.controls_dirty = false
        model.apply_appearance(screen) or >>
        model.appearance_dirty = false
        $dispatcher := register_events(& * model, & * screen) or >>
        model.layout(screen) or >>
        while screen.is_open() {
            register_notice_events(& * screen, $&dispatcher) or >>
            now := time.instant()
            model.work(screen, now) or >>
            if model.controls_dirty{model.configure_controls(screen) or >>
                model.controls_dirty = false}
            if model.appearance_dirty{model.apply_appearance(screen) or >>
                model.appearance_dirty = false}
            model.apply_page_options(screen) or >>
            model.layout(screen) or >>
            $deadline := screen.advance(now) or >>
            $timed_actions := false
            for action in screen.take_actions() {
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) or >>
                timed_actions = true
            }
            // Reconcile timer-driven values/styles before computing the next wait.
            if timed_actions{ -> }
            _ := screen.render() or >>
            if model.running &&(deadline.is_zero() || model.deadline.before(deadline)) {deadline = model.deadline}
            event := next_event(events, deadline) or >>
            $actions := screen.event(&event) or >>
            $count := 0
            while screen.is_open() && count < 128 {pending := ui.poll_chan(events)
                if pending.kind == ui.EV_NONE{ <- }
                more := screen.event(&pending) or >>
                for action in more{actions.push(action)}
                count += 1}
            for action in actions{register_notice_events(& * screen, $&dispatcher) or >>
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) or >> }
        }
        << 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) or >>
        density := s.selected(m.density) or >>
        scale := s.selected(m.scale) or >>
        preset :=[widgets.THEME_LIGHT, widgets.THEME_DARK, widgets.THEME_CONTRAST][theme]
        $styles := widgets.preset_styles(preset) or >>
        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) or >>) or >>
        s.apply_appearance(&sheet) or >>
        position := m.selected
        pages := &m.pages
        page := &pages[position]
        id := page.ids[0]
        if m.selected == 30 {$avatar := styles.button_variant(widgets.BUTTON_SUBTLE) or >>
            avatar.radius = 999.0
            s.set_control_style(page.ids[2], &avatar) or >> }
        if m.selected <= 32 || m.selected >= 40 {
            s.clear_control_style(id) or >>
            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) or >> }
        }
        $spec := widgets.motion_spec()
        if m.slow{spec.change = time.milliseconds(420) or >>
            spec.hover = time.milliseconds(320) or >>
            spec.enter = time.milliseconds(360) or >>
            spec.exit = time.milliseconds(240) or >>
            spec.curve = widgets.EASE_OUT_QUINT}
        if animated(m.selected) {s.set_motion(id, &spec) or >> }
        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) or >>) == 1
            for i in 0:4 {
                icon_size := s.number_value(page.ids[9 + i]) or >>
                $icon_prefix := "图标 · "
                if english {icon_prefix = "Icon · "}
                s.set_text(page.ids[13 + i], icon_prefix + str(int(icon_size)) + " px") or >>
                $c := styles.button_variant(widgets.BUTTON_OUTLINE) or >>
                if i == 0 {c = styles.button_variant(widgets.BUTTON_PRIMARY) or >> }
                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) or >>
                s.set_motion(handles[i], &spec) or >>
            }
        }
        if m.selected == 33 || m.selected == 34 || m.selected == 36 {s.set_motion(page.ids[1], &spec) or >>
            $c := styles.overlay_style()
            if m.customized{c.radius = 18.0
                c.border_width = 2.0}
            s.set_control_style(page.ids[1], &c) or >> }
        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) or >>
        }
        if m.selected == 35 {
            s.set_notice_motion(&spec) or >>
            if m.customized{$c := styles.overlay_style()
                c.radius = 18.0
                c.border_width = 2.0
                s.set_notice_style(&c) or >> }
            else {s.clear_notice_style() or >> }
        }
        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) or >>
                s.clear_control_style(page.ids[i]) or >>
                s.set_motion(page.ids[i], &spec) or >>
                if m.customized{$c := styles.button_variant(widgets.BUTTON_OUTLINE) or >>
                    c.radius = 12.0
                    c.border_width = 1.5
                    s.set_control_style(page.ids[i], &c) or >> }}
        }
        if m.selected == 39 {
            s.clear_control_style(id) or >>
            $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) or >> }
            s.set_chart_appearance(id, &appearance) or >>
            $options := widgets.animation_options()
            options.duration = time.milliseconds(650) or >>
            options.curve = widgets.EASE_IN_OUT_CUBIC
            if m.slow{options.duration = time.milliseconds(1200) or >> }
            s.set_chart_animation(id, &options) or >>
            if m.chart_paused{s.pause_chart_animation(id) or >> }
        }
        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) or >>
            $appearance := widgets.slider_appearance()
            appearance.ticks = 11
            appearance.show_value = true
            s.set_range_appearance(id, &appearance) or >>
        }
        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) or >>
        }
        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) or >>
        }
        if m.selected == 37 {$radius := 8.0
            if m.customized{radius = 18.0}
            s.set_webview_radius(id, radius) or >> }
        << 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) or >>
            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) or >>
            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) or >>) or >>
            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) or >>
            m.popover_options_dirty = false
        }
        << 0
    }

API declarations

const MAX_EXTENT

XuAPI
pub const MAX_EXTENT = 1000000000

Purpose

Layout uses logical pixels, with the same finite extent limit as draw.Frame. A parent supplies Constraints; children return a Size within those constraints.

struct Size

XuAPI
pub struct Size {
    pub width f64
    pub height f64
}

Purpose

Structure encapsulating width, height.

Public fields

width f64
field (f64)
height f64
field (f64)

See usage example

struct Rect

XuAPI
pub struct Rect {
    pub x f64
    pub y f64
    pub width f64
    pub height f64
}

Purpose

Structure encapsulating x, y, width, height.

Public fields

x f64
value
y f64
value
width f64
field (f64)
height f64
field (f64)

See usage example

struct Insets

XuAPI
pub struct Insets {
    pub left f64
    pub top f64
    pub right f64
    pub bottom f64
}

Purpose

Structure encapsulating left, top, right, bottom.

Public fields

left f64
field (f64)
top f64
field (f64)
right f64
field (f64)
bottom f64
field (f64)

See usage example

struct Constraints

XuAPI
pub struct Constraints {
    pub min_width f64
    pub max_width f64
    pub min_height f64
    pub max_height f64
}

Purpose

Structure encapsulating min_width, max_width, min_height, max_height.

Public fields

min_width f64
field (f64)
max_width f64
field (f64)
min_height f64
field (f64)
max_height f64
field (f64)

(&Constraints) validate

XuAPI
pub fn (c &Constraints) validate() int

Purpose

Execute validate on &Constraints. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Constraints
The Constraints instance used by this call (borrow).

Returns

int — a value of this type

constraints

XuAPI
pub fn constraints(min_width f64,max_width f64,min_height f64,max_height f64) Constraints

Purpose

Execute constraints. Throws on failure; handle the error or propagate it to the caller.

Parameters

min_width f64
min_width (f64)
max_width f64
max_width (f64)
min_height f64
min_height (f64)
max_height f64
max_height (f64)

Returns

Constraints — a value of this type

tight

XuAPI
pub fn tight(width f64,height f64) Constraints

Purpose

Execute tight. Throws on failure; handle the error or propagate it to the caller.

Parameters

width f64
width (f64)
height f64
height (f64)

Returns

Constraints — a value of this type

See usage example

loose

XuAPI
pub fn loose(max_width f64,max_height f64) Constraints

Purpose

Execute loose. Throws on failure; handle the error or propagate it to the caller.

Parameters

max_width f64
max_width (f64)
max_height f64
max_height (f64)

Returns

Constraints — a value of this type

(&Constraints) loosen

XuAPI
pub fn (c &Constraints) loosen() Constraints

Purpose

Execute loosen on &Constraints. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Constraints
The Constraints instance used by this call (borrow).

Returns

Constraints — a value of this type

(&Constraints) constrain

XuAPI
pub fn (c &Constraints) constrain(size &Size) Size

Purpose

Execute constrain on &Constraints. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Constraints
The Constraints instance used by this call (borrow).
size &Size
size (read-only borrow; caller keeps the original; type &Size)

Returns

Size — a value of this type

(&Constraints) contains

XuAPI
pub fn (c &Constraints) contains(size &Size) bool

Purpose

Operation on &Constraints: report whether the input contains the given piece. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Constraints
The Constraints instance used by this call (borrow).
size &Size
size (read-only borrow; caller keeps the original; type &Size)

Returns

bool — true or false

(&Insets) validate

XuAPI
pub fn (padding &Insets) validate() int

Purpose

Execute validate on &Insets. Throws on failure; handle the error or propagate it to the caller.

Parameters

padding &Insets
The Insets instance used by this call (borrow).

Returns

int — a value of this type

insets

XuAPI
pub fn insets(all f64) Insets

Purpose

Execute insets. Throws on failure; handle the error or propagate it to the caller.

Parameters

all f64
all (f64)

Returns

Insets — a value of this type

See usage example

(&Constraints) deflate

XuAPI
pub fn (c &Constraints) deflate(padding &Insets) Constraints

Purpose

Operation on &Constraints: compress input data using standard DEFLATE algorithm. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Constraints
The Constraints instance used by this call (borrow).
padding &Insets
padding (read-only borrow; caller keeps the original; type &Insets)

Returns

Constraints — a value of this type

(&Constraints) wrap_padding

XuAPI
pub fn (c &Constraints) wrap_padding(child &Size,padding &Insets) Size

Purpose

Return the parent's constrained size after the child has been laid out. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Constraints
The Constraints instance used by this call (borrow).
child &Size
child (read-only borrow; caller keeps the original; type &Size)
padding &Insets
padding (read-only borrow; caller keeps the original; type &Insets)

Returns

Size — a value of this type

align

XuAPI
pub fn align(parent &Rect,child &Size,x_alignment f64,y_alignment f64) Rect

Purpose

Alignment -1/0/1 means start/center/end. An oversized child may overflow its parent; clipping is a separate rendering decision. Edges are half-open. Throws on failure; handle the error or propagate it to the caller.

Parameters

parent &Rect
parent (read-only borrow; caller keeps the original; type &Rect)
child &Size
child (read-only borrow; caller keeps the original; type &Size)
x_alignment f64
x_alignment (f64)
y_alignment f64
y_alignment (f64)

Returns

Rect — a value of this type

(&Rect) contains

XuAPI
pub fn (rect &Rect) contains(x f64,y f64) bool

Purpose

Operation on &Rect: report whether the input contains the given piece.

Parameters

rect &Rect
The Rect instance used by this call (borrow).
x f64
value (f64)
y f64
value (f64)

Returns

bool — true or false

intersect

XuAPI
pub fn intersect(first &Rect,second &Rect) Rect

Purpose

Execute intersect. Throws on failure; handle the error or propagate it to the caller.

Parameters

first &Rect
first (read-only borrow; caller keeps the original; type &Rect)
second &Rect
second (read-only borrow; caller keeps the original; type &Rect)

Returns

Rect — a value of this type

const MAIN_START

XuAPI
pub const MAIN_START = 0

Purpose

Constant MAIN_START, defining protocol or algorithm parameters.

const MAIN_END

XuAPI
pub const MAIN_END = 1

Purpose

Constant MAIN_END, defining protocol or algorithm parameters.

const MAIN_CENTER

XuAPI
pub const MAIN_CENTER = 2

Purpose

Constant MAIN_CENTER, defining protocol or algorithm parameters.

const MAIN_SPACE_BETWEEN

XuAPI
pub const MAIN_SPACE_BETWEEN = 3

Purpose

Constant MAIN_SPACE_BETWEEN, defining protocol or algorithm parameters.

const MAIN_SPACE_AROUND

XuAPI
pub const MAIN_SPACE_AROUND = 4

Purpose

Constant MAIN_SPACE_AROUND, defining protocol or algorithm parameters.

const MAIN_SPACE_EVENLY

XuAPI
pub const MAIN_SPACE_EVENLY = 5

Purpose

Constant MAIN_SPACE_EVENLY, defining protocol or algorithm parameters.

const CROSS_START

XuAPI
pub const CROSS_START = 0

Purpose

Constant CROSS_START, defining protocol or algorithm parameters.

const CROSS_END

XuAPI
pub const CROSS_END = 1

Purpose

Constant CROSS_END, defining protocol or algorithm parameters.

const CROSS_CENTER

XuAPI
pub const CROSS_CENTER = 2

Purpose

Constant CROSS_CENTER, defining protocol or algorithm parameters.

See usage example

const CROSS_STRETCH

XuAPI
pub const CROSS_STRETCH = 3

Purpose

Constant CROSS_STRETCH, defining protocol or algorithm parameters.

See usage example

const MAX_CHILDREN

XuAPI
pub const MAX_CHILDREN = 4096

Purpose

Constant MAX_CHILDREN, defining protocol or algorithm parameters.

struct Flow

XuAPI
pub struct Flow {
    pub size Size
    pub children []Rect
    pub overflow_x bool
    pub overflow_y bool
}

Purpose

Structure encapsulating size, children, overflow_x, overflow_y.

Public fields

size Size
field (Size)
children []Rect
field ([]Rect)
overflow_x bool
field (bool)
overflow_y bool
field (bool)

row

XuAPI
pub fn row(parent &Constraints,children &[]Size,gap f64,main_alignment int,cross_alignment int) Flow

Purpose

Execute row. Throws on failure; handle the error or propagate it to the caller.

Parameters

parent &Constraints
parent (read-only borrow; caller keeps the original; type &Constraints)
children &[]Size
children (read-only borrow; caller keeps the original; type &[]Size)
gap f64
gap (f64)
main_alignment int
main_alignment (int)
cross_alignment int
cross_alignment (int)

Returns

Flow — a value of this type

column

XuAPI
pub fn column(parent &Constraints,children &[]Size,gap f64,main_alignment int,cross_alignment int) Flow

Purpose

Execute column. Throws on failure; handle the error or propagate it to the caller.

Parameters

parent &Constraints
parent (read-only borrow; caller keeps the original; type &Constraints)
children &[]Size
children (read-only borrow; caller keeps the original; type &[]Size)
gap f64
gap (f64)
main_alignment int
main_alignment (int)
cross_alignment int
cross_alignment (int)

Returns

Flow — a value of this type

struct VisibleRange

XuAPI
pub struct VisibleRange {
    pub start int
    pub end int
    pub offset f64
    pub content_extent f64
}

Purpose

Structure encapsulating start, end, offset, content_extent.

Public fields

start int
field (int)
end int
field (int)
offset f64
offset
content_extent f64
field (f64)

visible_range

XuAPI
pub fn visible_range(count int,item_extent f64,gap f64,viewport f64,offset f64,overscan int) VisibleRange

Purpose

Fixed-height/width viewport range, with a half-open index interval. The runtime builds only [start,end), preserving item keys outside the recycled view objects. Throws on failure; handle the error or propagate it to the caller.

Parameters

count int
count (int)
item_extent f64
item_extent (f64)
gap f64
gap (f64)
viewport f64
viewport (f64)
offset f64
offset (f64)
overscan int
overscan (int)

Returns

VisibleRange — a value of this type

const BOX_LEAF

XuAPI
pub const BOX_LEAF = 0

Purpose

Constant BOX_LEAF, defining protocol or algorithm parameters.

See usage example

const BOX_ROW

XuAPI
pub const BOX_ROW = 1

Purpose

Constant BOX_ROW, defining protocol or algorithm parameters.

See usage example

const BOX_COLUMN

XuAPI
pub const BOX_COLUMN = 2

Purpose

Constant BOX_COLUMN, defining protocol or algorithm parameters.

See usage example

const BOX_STACK

XuAPI
pub const BOX_STACK = 3

Purpose

Constant BOX_STACK, defining protocol or algorithm parameters.

const BOX_PADDING

XuAPI
pub const BOX_PADDING = 4

Purpose

Constant BOX_PADDING, defining protocol or algorithm parameters.

const MAX_TREE_NODES

XuAPI
pub const MAX_TREE_NODES = 4096

Purpose

Constant MAX_TREE_NODES, defining protocol or algorithm parameters.

const MAX_TREE_DEPTH

XuAPI
pub const MAX_TREE_DEPTH = 64

Purpose

Constant MAX_TREE_DEPTH, defining protocol or algorithm parameters.

struct Offset

XuAPI
pub struct Offset {
    pub x f64
    pub y f64
}

Purpose

Structure encapsulating x, y.

Public fields

x f64
value
y f64
value

struct BoxStyle

XuAPI
pub struct BoxStyle {
    pub kind int
    pub width f64
    pub height f64
    pub padding Insets
    pub gap f64
    pub main_alignment int
    pub cross_alignment int
    pub align_x f64
    pub align_y f64
    pub clip bool
    pub hidden bool
}

Purpose

Negative one means natural size. Fixed sizes are still constrained by the parent. Configuration contains no persistent identity or rendering resources.

Public fields

kind int
kind tag
width f64
field (f64)
height f64
field (f64)
padding Insets
field (Insets)
gap f64
field (f64)
main_alignment int
field (int)
cross_alignment int
field (int)
align_x f64
field (f64)
align_y f64
field (f64)
clip bool
field (bool)
hidden bool
field (bool)

box_style

XuAPI
pub fn box_style(kind int) BoxStyle

Purpose

Box style.

Parameters

kind int
kind tag (int)

Returns

BoxStyle — a value of this type

See usage example

(&BoxStyle) validate

XuAPI
pub fn (style &BoxStyle) validate() int

Purpose

Execute validate on &BoxStyle. Throws on failure; handle the error or propagate it to the caller.

Parameters

style &BoxStyle
The BoxStyle instance used by this call (borrow).

Returns

int — a value of this type

struct LayoutStats

XuAPI
pub struct LayoutStats {
    pub measured int
    pub reused int
}

Purpose

Structure encapsulating measured, reused.

Public fields

measured int
field (int)
reused int
field (int)

struct Tree

XuAPI
pub struct Tree {

}

Purpose

A bounded flat arena. IDs never repeat, including after remove/reuse of an arena slot. Traversal uses indices; public handles are checked at the boundary.

Public fields

This type has no public fields.

tree

XuAPI
pub fn tree() Tree

Purpose

Execute tree.

Parameters

No arguments are required.

Returns

Tree — a value of this type

(&Tree) contains

XuAPI
pub fn (tree &Tree) contains(id int) bool

Purpose

Operation on &Tree: report whether the input contains the given piece.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

bool — true or false

($&Tree) add

XuAPI
pub fn (tree $&Tree) add(parent int,style &BoxStyle,intrinsic &Size) int

Purpose

Operation on $&Tree: add. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
parent int
parent (int)
style &BoxStyle
style (read-only borrow; caller keeps the original; type &BoxStyle)
intrinsic &Size
intrinsic (read-only borrow; caller keeps the original; type &Size)

Returns

int — a value of this type

(&Tree) style

XuAPI
pub fn (tree &Tree) style(id int) BoxStyle

Purpose

Execute style on &Tree. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

BoxStyle — a value of this type

($&Tree) set_style

XuAPI
pub fn (tree $&Tree) set_style(id int,style &BoxStyle) int

Purpose

Operation on $&Tree: set style. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
id int
id (int)
style &BoxStyle
style (read-only borrow; caller keeps the original; type &BoxStyle)

Returns

int — a value of this type

($&Tree) set_intrinsic

XuAPI
pub fn (tree $&Tree) set_intrinsic(id int,size &Size) int

Purpose

Operation on $&Tree: set intrinsic. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
id int
id (int)
size &Size
size (read-only borrow; caller keeps the original; type &Size)

Returns

int — a value of this type

($&Tree) invalidate_paint

XuAPI
pub fn (tree $&Tree) invalidate_paint(id int) int

Purpose

Operation on $&Tree: invalidate paint. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
id int
id (int)

Returns

int — a value of this type

($&Tree) set_offset

XuAPI
pub fn (tree $&Tree) set_offset(id int,x f64,y f64) int

Purpose

Placement/composition never changes child measurement or its own paint record. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
id int
id (int)
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

($&Tree) set_scroll

XuAPI
pub fn (tree $&Tree) set_scroll(id int,x f64,y f64) int

Purpose

Operation on $&Tree: set scroll. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
id int
id (int)
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

(&Tree) scroll_offset

XuAPI
pub fn (tree &Tree) scroll_offset(id int) Offset

Purpose

Operation on &Tree: scroll offset. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

Offset — a value of this type

(&Tree) paint_revision

XuAPI
pub fn (tree &Tree) paint_revision(id int) int

Purpose

Operation on &Tree: paint revision. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

int — a value of this type

(&Tree) parent

XuAPI
pub fn (tree &Tree) parent(id int) int

Purpose

Execute parent on &Tree. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

int — a value of this type

(&Tree) children

XuAPI
pub fn (tree &Tree) children(id int) []int

Purpose

Execute children on &Tree. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

[]int — slice result

($&Tree) remove

XuAPI
pub fn (tree $&Tree) remove(id int) int

Purpose

Operation on $&Tree: remove. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
id int
id (int)

Returns

int — a value of this type

(&Tree) needs_layout

XuAPI
pub fn (tree &Tree) needs_layout() bool

Purpose

Operation on &Tree: needs layout.

Parameters

tree &Tree
The Tree instance used by this call (borrow).

Returns

bool — true or false

(&Tree) layout_stats

XuAPI
pub fn (tree &Tree) layout_stats() LayoutStats

Purpose

Operation on &Tree: layout stats.

Parameters

tree &Tree
The Tree instance used by this call (borrow).

Returns

LayoutStats — a value of this type

($&Tree) layout

XuAPI
pub fn (tree $&Tree) layout(constraints &Constraints) Size

Purpose

Execute layout on $&Tree. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree $&Tree
The Tree instance used by this call (exclusive borrow).
constraints &Constraints
constraints (read-only borrow; caller keeps the original; type &Constraints)

Returns

Size — a value of this type

(&Tree) bounds

XuAPI
pub fn (tree &Tree) bounds(id int) Rect

Purpose

Return the bounding Rectangle of the control or geometry. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

Rect — a value of this type

(&Tree) visible

XuAPI
pub fn (tree &Tree) visible(id int) bool

Purpose

Execute visible on &Tree. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

bool — true or false

(&Tree) global_bounds

XuAPI
pub fn (tree &Tree) global_bounds(id int) Rect

Purpose

Operation on &Tree: global bounds. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
id int
id (int)

Returns

Rect — a value of this type

(&Tree) hit_test

XuAPI
pub fn (tree &Tree) hit_test(x f64,y f64) int

Purpose

Operation on &Tree: hit test. Throws on failure; handle the error or propagate it to the caller.

Parameters

tree &Tree
The Tree instance used by this call (borrow).
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type