XU XUv0.16.0

#ui/draw

import: #ui/draw

counts: 109 functions, 253 methods, 23 types, 50 constants, 0 method sets

Explicit Context / Frame drawing with paths, gradients, text, images, DisplayList, Surface and caching. Panning is disabled by default; set_pan_enabled(1) enables the camera. Frame.scale uses factors; package-level scale uses percentages. Balance push / pop and retain resources until present / freeze / snapshot accepts the recording.

Usage and lifetimes

Release examples (complete projects and source downloads): draw_gallery

Drawing and game engines

This is a desktop 2D drawing layer suitable for tools, editors and modest prototypes. Its platform backends use CoreGraphics, Cairo and GDI+. The public API does not provide a game-engine GPU pipeline, shaders, draw batching or a display-synchronized frame-pacing contract. DisplayList and surface caches help reuse work, but are not evidence of a game frame-time budget; measure the intended workload on each target before committing to it.

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/draw/main.xu

Required SDK: Xu 0.10.11 · Complete project · Download source

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

fn paint(context &draw.Context,frame $&draw.Frame,hits int) int {
    frame.begin() >>>
    frame.set_bg(demo.background()) >>>
    demo.text(context,frame,32.0,28.0,14.0,demo.accent(),"01 / FRAME RECORDER") >>>
    demo.text(context,frame,32.0,58.0,30.0,demo.ink(),"Draw a frame. Submit once.") >>>
    demo.text(context,frame,32.0,108.0,15.0,demo.muted(),"Click the teal circle. Resize the window. Escape closes it.") >>>
    frame.set_fill(demo.accent()) >>>
    frame.circle(112.0,228.0,52.0) >>>
    frame.stroke_rect(200.5,176.5,128.0,104.0,draw.rgb(240,180,91),2.0) >>>
    frame.push() >>>
    frame.clip_rect(376.0,168.0,216.0,120.0) >>>
    frame.translate(478.0,226.0) >>>
    frame.rotate(18.0) >>>
    frame.fill_rect(-100.0,-42.0,200.0,84.0,draw.rgb(92,127,203)) >>>
    frame.pop() >>>
    demo.text(context,frame,32.0,330.0,20.0,demo.ink(),"Circle activations: " + str(hits)) >>>
    demo.text(context,frame,32.0,370.0,13.0,demo.muted(),"Logical coordinates / state stack / clipping / one present") >>>
    frame.present() >>>
    println("Frame submitted: " + str(frame.command_count()) + " commands / " + str(frame.byte_len()) + " bytes")
    << 0
}
fn scene(ech chan ui.Event) int {
    ready := demo.ready(ech) >>>
    if ready.kind == ui.EV_EXIT { << 0 }
    identity := ui.canvas_of(&ready) >>>
    context := draw.context_of(&ready) >>>
    $frame := context.new_frame(4096)
    $hits := 0
    $pressed := false
    paint(&context,$&frame,hits) >>>
    while true {
        event := demo.next(ech)
        if event.kind == ui.EV_EXIT { <- }
        if event.window_id != identity.window_id { -> }
        if event.kind == ui.EV_CANVAS_CLOSED { <- }
        if event.kind == ui.EV_BLURRED { pressed = false }
        if event.kind == ui.EV_CANVAS_METRICS { paint(&context,$&frame,hits) >>> }
        if ui.is_input_event(event.kind) {
            input := ui.input_of(&event) >>>
            if input.generation != identity.generation { -> }
            if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE { demo.quit() >>> }
            dx := input.x - 112.0
            dy := input.y - 228.0
            inside := dx * dx + dy * dy <= 2704.0
            if input.kind == ui.EV_POINTER_DOWN && input.button == ui.BUTTON_LEFT { pressed = inside }
            if input.kind == ui.EV_POINTER_CANCEL { pressed = false }
            if input.kind == ui.EV_POINTER_UP && input.button == ui.BUTTON_LEFT {
                if pressed && inside { hits = hits + 1
                    paint(&context,$&frame,hits) >>> }
                pressed = false
            }
        }
    }
    frame.dispose()
    << 0
}
fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
    << } }
fn launch() int {
    $app := demo.app("Xu UI / Frame",680,430) >>>
    xu worker(app.event_ch)
    << app.run() >>>
}
fn main() int { << launch() >>> (err) { eprintln(err.msg())
    << 1 } }
16_ui_webview/multiwindow/main.xu

Required SDK: Xu 0.10.11 · Complete project · Download source

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

fn paint(window ui.Window,count int) int {
    context := draw.window_context(&window) >>>
    $frame := context.new_frame(2048)
    frame.begin() >>>
    frame.set_bg(demo.background()) >>>
    demo.text(&context,$&frame,26.0,28.0,14.0,demo.accent(),"06 / INDEPENDENT WINDOWS") >>>
    demo.text(&context,$&frame,26.0,64.0,27.0,demo.ink(),"Window " + str(window.id)) >>>
    demo.text(&context,$&frame,26.0,116.0,17.0,demo.ink(),"Clicks in this window: " + str(count)) >>>
    demo.text(&context,$&frame,26.0,172.0,14.0,demo.muted(),"N: new window / W: close this window") >>>
    demo.text(&context,$&frame,26.0,208.0,14.0,demo.muted(),"F: focus first window / R: resize / Escape: quit all") >>>
    demo.text(&context,$&frame,26.0,258.0,13.0,demo.muted(),"One event channel. Each canvas owns its resources.") >>>
    frame.present() >>>
    frame.dispose()
    << 0
}
fn scene(ech chan ui.Event) int {
    ready := demo.ready(ech) >>>
    if ready.kind == ui.EV_EXIT { << 0 }
    identity := ui.canvas_of(&ready) >>>
    $app := demo.windows(ech)
    first := ui.Window{id: identity.window_id,generation: identity.generation,title: "Xu UI / Window 1",width: 560,height: 340,content_kind: ui.CONTENT_DRAW,content_backend_id: identity.canvas_id,closed: 0}
    $windows := []ui.Window{}
    windows.push(first)
    $counts := [0]
    paint(windows[0],0) >>>
    while true {
        event := demo.next(ech)
        if event.kind == ui.EV_EXIT { <- }
        $index := -1
        for i in 0:windows.len { if windows[i].id == event.window_id { index = i } }
        if index < 0 { -> }
        if event.kind == ui.EV_CANVAS_READY {
            window := windows[index]
            window.content_command("input_enabled\t1") >>>
            window.content_command("pan_enabled\t0") >>>
            println("Canvas ready: " + str(event.window_id))
            paint(window,counts[index]) >>> }
        if event.kind == ui.EV_CANVAS_METRICS { paint(windows[index],counts[index]) >>> }
        if event.kind == ui.EV_CLOSED { windows[index].closed = 1 }
        if event.kind == ui.EV_WINDOW_FAILED { windows[index].closed = 1
            eprintln("Native window creation failed: " + event.menu_id) }
        if !ui.is_input_event(event.kind) { -> }
        input := ui.input_of(&event) >>>
        if input.generation != windows[index].generation || windows[index].closed != 0 { -> }
        if input.kind == ui.EV_POINTER_UP && input.button == ui.BUTTON_LEFT {
            counts[index] = counts[index] + 1
            println("Window " + str(event.window_id) + " count: " + str(counts[index]))
            paint(windows[index],counts[index]) >>>
        }
        if input.kind != ui.EV_KEY_DOWN || input.repeat != 0 { -> }
        if input.key == ui.KEY_ESCAPE { demo.quit() >>> }
        if input.key == 78 || input.key == 110 {
            // At most six demo windows; the host's own limit is independent.
            $live := 0
            for window in windows { if window.closed == 0 { live = live + 1 } }
            if live < 6 {
                window := app.open_content_window(ui.WindowOpts{title: "Xu UI / Additional Window",width: 560,height: 340},ui.CONTENT_DRAW) >>>
                windows.push(window)
                counts.push(0)
            }
        }
        if input.key == 87 || input.key == 119 {
            $window := windows[index]
            window.request_close() >>>
            windows[index] = window
        }
        if input.key == 82 || input.key == 114 {
            $window := windows[index]
            window.resize(660,400) >>>
            windows[index] = window
        }
        if input.key == 70 || input.key == 102 {
            for window in windows { if window.closed == 0 { window.focus() >>>
                <- } }
        }
    }
    << 0
}
fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
    << } }
fn launch() int {
    $app := demo.app("Xu UI / Window 1",560,340) >>>
    xu worker(app.event_ch)
    << app.run() >>>
}
fn main() int { << launch() >>> (err) { eprintln(err.msg())
    << 1 } }
16_ui_webview/editor_workbench/xuui_tokens/mod.xu

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

XuLocal SDK example
@xuui_tokens
// XUUI 0.1.1-dev.1; generated from tokens/tokens.json.
// Regenerate with npm run build; retain this provenance when vendoring.
#ui/draw
#ui/widgets

pub fn canvas(dark bool) draw.Color {
    if dark { << draw.rgb(16,14,18) }
    << draw.rgb(246,243,239)
}
pub fn surface(dark bool) draw.Color {
    if dark { << draw.rgb(25,22,28) }
    << draw.rgb(255,253,251)
}
pub fn elevated(dark bool) draw.Color {
    if dark { << draw.rgb(35,31,39) }
    << draw.rgb(238,235,231)
}
pub fn subtle(dark bool) draw.Color {
    if dark { << draw.rgb(44,39,49) }
    << draw.rgb(232,227,223)
}
pub fn text(dark bool) draw.Color {
    if dark { << draw.rgb(245,240,237) }
    << draw.rgb(40,35,41)
}
pub fn muted(dark bool) draw.Color {
    if dark { << draw.rgb(179,170,182) }
    << draw.rgb(109,98,110)
}
pub fn brand(dark bool) draw.Color {
    if dark { << draw.rgb(255,82,116) }
    << draw.rgb(190,18,60)
}
pub fn focus(dark bool) draw.Color {
    if dark { << draw.rgb(168,217,255) }
    << draw.rgb(0,95,158)
}
pub fn control_border(dark bool) draw.Color {
    if dark { << draw.rgb(138,126,144) }
    << draw.rgb(133,121,135)
}
pub fn on_brand(dark bool) draw.Color {
    if dark { << draw.rgb(25,12,18) }
    << draw.rgb(255,248,250)
}
pub fn danger(dark bool) draw.Color {
    if dark { << draw.rgb(255,142,157) }
    << draw.rgb(184,33,56)
}
pub fn danger_soft(dark bool) draw.Color {
    if dark { << draw.rgb(60,32,40) }
    << draw.rgb(251,230,233)
}

// Editor appearance for XU SDK 0.10.11. Other controls retain SDK defaults.
pub fn editor_styles(dark bool) widgets.Styles {
    $styles := widgets.light_styles()
    if dark { styles = widgets.dark_styles() }
    styles.background = canvas(dark)
    $input := styles.input.clone()
    input.radius = 8.0
    input.min_height = 40.0
    input.padding.left = 12.0
    input.padding.right = 12.0
    input.padding.top = 8.0
    input.padding.bottom = 8.0
    input.border_width = 1.0
    input.focus_width = 2.0
    input.font.size = 16.0
    input.inherit_font = false
    input.palette.normal = surface(dark)
    input.palette.hovered = surface(dark)
    input.palette.pressed = subtle(dark)
    input.palette.disabled = surface(dark)
    input.palette.foreground = text(dark)
    input.palette.muted = muted(dark)
    input.palette.placeholder = muted(dark)
    input.palette.accent = brand(dark)
    input.palette.on_accent = on_brand(dark)
    input.palette.focus = focus(dark)
    input.palette.border = control_border(dark)
    input.palette.invalid = danger(dark)
    input.palette.invalid_fill = danger_soft(dark)
    input.palette.read_only = subtle(dark)
    input.palette.selection = brand(dark)
    input.palette.selection_text = on_brand(dark)
    $hover := widgets.state_paint(widgets.STATE_HOVERED)
    hover.unless = widgets.STATE_DISABLED | widgets.STATE_INVALID | widgets.STATE_READ_ONLY
    hover.fields = widgets.PAINT_BORDER
    hover.border = brand(dark)
    $focused := widgets.state_paint(widgets.STATE_FOCUSED)
    focused.unless = widgets.STATE_DISABLED | widgets.STATE_INVALID
    focused.fields = widgets.PAINT_BORDER
    focused.border = focus(dark)
    input.states = [hover,focused]
    styles.input = input.clone()
    styles.text_area = input.clone()
    styles.text_area.align_y = 0.0
    << styles
}
More related examples
  • 16_ui_webview/draw_gallery/main.xu

    Required SDK: Xu 0.10.13-dev.3 · Complete project · Download source

    XuLocal SDK example
    @main
    #ui
    #ui/draw
    demo #"github.com/xulang-org/examples/ui_demo"
    
    fn paint_vector_showcase(context &draw.Context, fragment $&draw.Frame) int {
        demo.text(context, fragment, 32.0, 396.0, 14.0, demo.accent(), "03 / HIGH-LEVEL VECTOR PRIMITIVES & COLOR TOOLS") >>>
        teal := draw.hex("#14B8A6") >>>
        indigo := draw.hex("#6366F1") >>>
        amber := draw.hsl(38.0, 0.92, 0.58)
        coral := draw.lerp_color(amber, draw.hex("#F43F5E") >>>, 0.65)
        card_grad := draw.two_stop_linear(32.0, 424.0, 224.0, 524.0, teal.darken(0.35), indigo.darken(0.35))
        fragment.box_shadow(32.0, 424.0, 192.0, 100.0, 14.0, 0.0, 6.0, 12.0, 1.0, draw.rgba(0, 0, 0, 110)) >>>
        fragment.fill_round_rect_gradient(32.0, 424.0, 192.0, 100.0, 14.0, &card_grad) >>>
        fragment.stroke_round_rect(32.0, 424.0, 192.0, 100.0, 14.0, teal.lighten(0.35), 1.5) >>>
        orb_grad := draw.two_stop_radial(82.0, 474.0, 30.0, teal.lighten(0.45), indigo)
        fragment.fill_circle_gradient(82.0, 474.0, 28.0, &orb_grad) >>>
        fragment.fill_capsule(126.0, 446.0, 82.0, 24.0, coral.with_opacity(0.88)) >>>
        fragment.stroke_capsule(126.0, 480.0, 82.0, 24.0, amber, 1.8) >>>
    
        fragment.fill_ring_sector(300.0, 474.0, 22.0, 46.0, -90.0, 210.0, teal) >>>
        fragment.fill_ring_sector(300.0, 474.0, 22.0, 46.0, 120.0, 95.0, indigo) >>>
        fragment.fill_sector(300.0, 474.0, 42.0, 225.0, 45.0, amber) >>>
        fragment.arc(300.0, 474.0, 52.0, -45.0, 130.0, coral, 3.0) >>>
    
        fragment.fill_regular_polygon(432.0, 474.0, 42.0, 6, -90.0, indigo.with_opacity(0.45)) >>>
        fragment.stroke_regular_polygon(432.0, 474.0, 42.0, 6, -90.0, indigo.lighten(0.35), 2.0) >>>
        fragment.fill_gear(432.0, 474.0, 26.0, 18.0, 9.0, 8, teal.with_opacity(0.85)) >>>
        fragment.fill_star(536.0, 474.0, 44.0, 19.0, 5, -90.0, amber) >>>
        fragment.stroke_star(536.0, 474.0, 44.0, 19.0, 5, -90.0, amber.lighten(0.45), 1.5) >>>
        fragment.fill_shield(628.0, 474.0, 56.0, 68.0, coral.with_opacity(0.75)) >>>
        fragment.stroke_shield(628.0, 474.0, 56.0, 68.0, coral.lighten(0.30), 1.8) >>>
        fragment.checkmark(614.0, 460.0, 28.0, coral.contrasting_ink(demo.ink(), demo.background()), 2.4) >>>
    
        fragment.grid(688.0, 424.0, 240.0, 100.0, 6, 4, demo.muted().with_opacity(0.25), 1.0) >>>
        fragment.hatch_rect(688.0, 424.0, 240.0, 100.0, 16.0, false, indigo.with_opacity(0.18), 1.0) >>>
        fragment.dashed_rect(688.0, 424.0, 240.0, 100.0, 6.0, 4.0, demo.muted().with_opacity(0.65), 1.2) >>>
        vir_c := draw.sample_palette(draw.PALETTE_VIRIDIS, 0.72)
        fragment.fill_ribbon(696.0, 488.0, 504.0, 812.0, 444.0, 460.0, vir_c.with_opacity(0.42)) >>>
        spline_pts := [draw.path_point(700.0, 508.0), draw.path_point(744.0, 442.0), draw.path_point(792.0, 496.0),
            draw.path_point(842.0, 436.0), draw.path_point(892.0, 482.0)]
        fragment.smooth_curve(&spline_pts, 0.0, teal, 2.5) >>>
        fragment.wave(700.0, 498.0, 196.0, 8.0, 48.0, 0.0, amber, 1.8) >>>
        fragment.dashed_line(700.0, 464.0, 912.0, 464.0, 8.0, 5.0, coral, 1.8) >>>
        fragment.double_arrow(868.0, 508.0, 916.0, 440.0, 10.0, demo.ink(), 2.0) >>>
        << 0
    }
    
    // This entire scene is recorded once; subsequent frames replay its resources.
    fn record(context &draw.Context, image &draw.Image) draw.DisplayList {
        $fragment := context.new_frame(8192)
        fragment.begin() >>>
        fragment.fill_rect(0.0, 0.0, 960.0, 548.0, draw.rgb(26, 37, 50)) >>>
        demo.text(context, $&fragment, 24.0, 22.0, 18.0, demo.ink(), "Vectors / gradients / embedded PNG / shaped text / geometry builders") >>>
        $path := draw.new_path(256)
        path.move_to(40.0, 210.0) >>>
        path.cubic_to(80.0, 60.0, 210.0, 60.0, 250.0, 210.0) >>>
        path.quad_to(145.0, 300.0, 40.0, 210.0) >>>
        path.close() >>>
        stops := [draw.GradientStop{offset: 0.0, color: demo.accent()}, draw.GradientStop{offset: 1.0, color: draw.rgb(92, 127, 203)}]
        gradient := draw.linear_gradient(20.0, 80.0, 260.0, 270.0, stops)
        bounds := draw.ImageRect{x: 20.0, y: 70.0, width: 260.0, height: 230.0}
        fragment.fill_path_gradient(&path, &gradient, &bounds, 2.0, draw.FILL_NONZERO) >>>
        stroke := draw.stroke_options(2.0)
        fragment.stroke_path(&path, demo.ink(), &stroke) >>>
        fragment.image(image, 320.0, 88.0, 150.0, 150.0) >>>
        source := draw.ImageRect{x: 0.0, y: 0.0, width: f64(image.width), height: f64(image.height)}
        destination := draw.ImageRect{x: 510.0, y: 88.0, width: 190.0, height: 150.0}
        fragment.image_region(image, &source, &destination, 0.45, draw.SAMPLER_NEAREST) >>>
        demo.text(context, $&fragment, 320.0, 260.0, 14.0, demo.muted(), "Linear sampling      Nearest / opacity") >>>
        $options := draw.text_options(22.0)
        options.width = 880.0
        value := "你好,Xu · العربية · café · 👩‍💻\nOne native layout: shaping, fallback, wrapping and metrics."
        $text := context.layout_text(&value, &options) >>>
        fragment.text_layout(&text, 32.0, 318.0, demo.ink()) >>>
        println("Text metrics: " + str(text.metrics.lines) + " lines")
        layer := draw.ImageRect{x: 740.0, y: 80.0, width: 180.0, height: 200.0}
        fragment.begin_layer(&layer, 2.0, 0.75) >>>
        fragment.set_fill(draw.rgb(240, 180, 91)) >>>
        fragment.circle(64.0, 80.0, 52.0) >>>
        fragment.set_fill(draw.rgb(92, 127, 203)) >>>
        fragment.circle(112.0, 112.0, 52.0) >>>
        fragment.end_layer() >>>
        demo.text(context, $&fragment, 740.0, 292.0, 14.0, demo.muted(), "Isolated group opacity") >>>
        paint_vector_showcase(context, $&fragment) >>>
        list := fragment.freeze() >>>
        text.dispose() >>>
        fragment.dispose()
        << list
    }
    fn paint(context &draw.Context, frame $&draw.Frame, list &draw.DisplayList, cache $&draw.SurfaceCache, density f64, cached bool) int {
        frame.begin() >>>
        frame.set_bg(demo.background()) >>>
        demo.text(context, frame, 32.0, 24.0, 14.0, demo.accent(), "02 / RESOURCE GALLERY") >>>
        demo.text(context, frame, 32.0, 54.0, 28.0, demo.ink(), "Record once. Reuse across frames.") >>>
        frame.push() >>>
        frame.translate(32.0, 104.0) >>>
        if cached { frame.cached_display_list(cache, list, 0.0, 0.0, 960.0, 548.0, density, 1.0, draw.SAMPLER_LINEAR) >>> }
        else { frame.display_list(list) >>> }
        frame.pop() >>>
        $mode := "vector replay"
        if cached { mode = "raster cache" }
        demo.text(context, frame, 32.0, 668.0, 15.0, demo.ink(), "Space: vector/cache / R: invalidate / current: " + mode) >>>
        frame.present() >>>
        println("Presented " + mode + ": " + str(frame.command_count()) + " frame commands")
        << 0
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) >>>
        if ready.kind == ui.EV_EXIT { << 0 }
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        path := "sample.png"
        $image := context.load_embedded_image(&path) >>>
        $list := record(&context, &image) >>>
        $cache := draw.new_surface_cache()
        $frame := context.new_frame(1024)
        $density := 1.0
        $cached := false
        paint(&context, $&frame, &list, $&cache, density, cached) >>>
        while true {
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
            if event.window_id != identity.window_id { -> }
            $dirty := false
            if event.kind == ui.EV_CANVAS_METRICS {
                metrics := ui.metrics_of(&event) >>>
                density = metrics.scale_x
                dirty = true
            }
            if ui.is_input_event(event.kind) {
                input := ui.input_of(&event) >>>
                if input.generation != identity.generation { -> }
                if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
                    if input.key == 32 { cached = !cached
                        dirty = true }
                    if input.key == 82 || input.key == 114 { cache.invalidate()
                        dirty = true }
                    if input.key == ui.KEY_ESCAPE { demo.quit() >>> }
                }
            }
            if dirty { paint(&context, $&frame, &list, $&cache, density, cached) >>> }
        }
        frame.dispose()
        cache.dispose()
        // Native close has already revoked all canvas-owned resources.
        if demo.alive(&identity) {
            list.dispose() >>>
            image.dispose() >>>
        }
        << 0
    }
    fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
        << } }
    fn launch() int {
        $app := demo.app("Xu UI / Resource Gallery", 1030, 720) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    fn main() int { << launch() >>> (err) { eprintln(err.msg())
        << 1 } }
  • 16_ui_webview/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) >>> }
        if choice == 1 { << ui.clipboard_read_async(identity,&options) >>> }
        if choice == 5 { prompt := ui.PromptOptions{title: "Your greeting",seed: "Hello, Xu",timeout_ms: 15000}
            << ui.prompt_async(identity,&prompt) >>> }
        $files := ui.file_dialog_options()
        if choice == 2 {
            files.title = "Select one or more text files"
            files.multiple = true
            files.filters = [ui.FileFilter{label: "Text",extensions: ["txt","md","xu"]}]
            << ui.open_files_async(identity,&files) >>>
        }
        if choice == 3 { files.title = "Choose a destination (this demo does not write)"
            files.name = "xu-note.txt"
            << ui.save_file_async(identity,&files) >>> }
        files.title = "Choose folders"
        files.multiple = true
        << ui.select_folders_async(identity,&files) >>>
    }
    fn paint(context &draw.Context,frame $&draw.Frame,message string,pending int) int {
        frame.begin() >>>
        frame.set_bg(demo.background()) >>>
        demo.text(context,frame,28.0,26.0,14.0,demo.accent(),"05 / ASYNCHRONOUS DESKTOP SERVICES") >>>
        demo.text(context,frame,28.0,58.0,28.0,demo.ink(),"A request is not a result.") >>>
        for id in 0:7 {
            y := 120.0 + f64(id) * 48.0
            frame.fill_rect(28.0,y,370.0,38.0,draw.rgb(40,57,73)) >>>
            demo.text(context,frame,40.0,y + 8.0,15.0,demo.ink(),caption(id)) >>>
        }
        demo.text(context,frame,430.0,124.0,17.0,demo.accent(),"Pending request: " + str(pending)) >>>
        $options := draw.text_options(16.0)
        options.width = 360.0
        $label := context.layout_text(&message,&options) >>>
        frame.text_layout(&label,430.0,172.0,demo.ink()) >>>
        demo.text(context,frame,28.0,490.0,13.0,demo.muted(),"One event channel / request IDs / distinct terminal states / Escape to close") >>>
        frame.present() >>>
        label.dispose() >>>
        << 0
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) >>>
        if ready.kind == ui.EV_EXIT { << 0 }
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        $frame := context.new_frame(4096)
        $pending := ui.Request{id: 0,window_id: 0,canvas_id: 0,generation: 0,kind: 0}
        $message := "Choose an action. File dialogs return paths; selecting a save path does not write a file."
        $armed := -1
        paint(&context,$&frame,message + "",pending.id) >>>
        while true {
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
            if event.window_id != identity.window_id { -> }
            $dirty := event.kind == ui.EV_CANVAS_METRICS
            if event.kind == ui.EV_REQUEST {
                result := ui.request_of(&event) >>>
                if result.matches(&pending) {
                    message = "Request " + str(pending.id) + " " + status_name(result.status)
                    if result.status == ui.REQUEST_COMPLETED {
                        if result.request.kind >= ui.REQUEST_OPEN_FILES {
                            paths := ui.file_paths(&result) >>>
                            for path in paths { message = message + "\n" + path }
                        } else { message = message + "\n" + result.value }
                    }
                    println("Request " + str(pending.id) + ": " + status_name(result.status))
                    pending.id = 0
                    dirty = true
                }
            }
            if event.kind == ui.EV_BLURRED { armed = -1 }
            if ui.is_input_event(event.kind) {
                input := ui.input_of(&event) >>>
                if input.generation != identity.generation { -> }
                $choice := -1
                for id in 0:7 {
                    bounds := layout.Rect{x: 28.0,y: 120.0 + f64(id) * 48.0,width: 370.0,height: 38.0}
                    if bounds.contains(input.x,input.y) { choice = id }
                }
                if input.kind == ui.EV_POINTER_DOWN && input.button == ui.BUTTON_LEFT { armed = choice }
                if input.kind == ui.EV_POINTER_CANCEL { armed = -1 }
                $activate := -1
                if input.kind == ui.EV_POINTER_UP && input.button == ui.BUTTON_LEFT {
                    if choice == armed { activate = choice }
                    armed = -1
                }
                if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
                    if input.key >= 49 && input.key <= 54 { activate = input.key - 49 }
                    if input.key == ui.KEY_ESCAPE { demo.quit() >>> }
                }
                if activate == 6 && pending.id > 0 { _ := pending.cancel()
                    message = "Cancellation requested; waiting for terminal result."
                    dirty = true }
                if activate >= 0 && activate < 6 {
                    if pending.id == 0 {
                        request := submit(&identity,activate) >>> (err) { message = err.msg()
                            paint(&context,$&frame,message + "",pending.id) >>>
                            -> }
                        pending = request
                        message = "Request admitted. Keep interacting; the event loop remains active."
                    } else { message = "Finish or cancel the current request first." }
                    dirty = true
                }
            }
            if dirty { paint(&context,$&frame,message + "",pending.id) >>> }
        }
        if pending.id > 0 { _ := pending.cancel() }
        frame.dispose()
        << 0
    }
    fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
        << } }
    fn launch() int {
        $app := demo.app("Xu UI / Desktop Services",850,550) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    fn main() int { << launch() >>> (err) { eprintln(err.msg())
        << 1 } }
  • 16_ui_webview/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() >>>
        value := state.display_value()
        println("Text revision: " + str(state.revision) + " / display bytes: " + str(value.len))
        options := draw.text_options(28.0)
        $text := context.layout_text(&value,&options) >>>
        text.bind_input(input,state.revision,44.0,180.0) >>>
        frame.begin() >>>
        frame.set_bg(demo.background()) >>>
        demo.text(context,frame,28.0,28.0,14.0,demo.accent(),"04 / NATIVE TEXT INPUT") >>>
        demo.text(context,frame,28.0,60.0,28.0,demo.ink(),"Type in your own language.") >>>
        demo.text(context,frame,28.0,112.0,15.0,demo.muted(),"Use an IME, arrows, Shift+arrows and Backspace. Click to move the caret.") >>>
        frame.fill_rect(28.0,160.0,790.0,86.0,draw.rgb(26,37,50)) >>>
        anchor := text.caret(state.display_anchor(),false) >>>
        caret := text.caret(state.display_focus(),false) >>>
        if state.display_anchor() != state.display_focus() && anchor.y == caret.y {
            frame.fill_rect(44.0 + math.min(anchor.x,caret.x),180.0 + caret.y,math.abs(caret.x - anchor.x),caret.height,draw.rgba(78,205,196,80)) >>>
        }
        frame.text_layout(&text,44.0,180.0,demo.ink()) >>>
        frame.fill_rect(44.0 + caret.x,180.0 + caret.y,1.5,caret.height,demo.accent()) >>>
        if state.composing {
            demo.text(context,frame,28.0,280.0,17.0,demo.accent(),"Composing: " + state.preedit) >>>
        } else {
            demo.text(context,frame,28.0,280.0,17.0,demo.muted(),"Committed text / no active preedit") >>>
        }
        demo.text(context,frame,28.0,324.0,14.0,demo.muted(),"Revision " + str(state.revision) + " / anchor byte " + str(state.anchor) + " / focus byte " + str(state.focus)) >>>
        demo.text(context,frame,28.0,360.0,14.0,demo.muted(),"Selection uses UTF-8 byte offsets. Escape ends the session and closes the window.") >>>
        frame.present_wait() >>>
        text.dispose() >>>
        << 0
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) >>>
        if ready.kind == ui.EV_EXIT { << 0 }
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        seed := "你好,Xu 👩‍💻 · café"
        caret := ui.TextInputRect{x: 44.0,y: 180.0,width: 2.0,height: 36.0}
        options := ui.text_input_options(&seed,caret)
        $input := ui.start_text_input(identity.canvas_id,identity.generation,&options) >>>
        $frame := context.new_frame(4096)
        paint(&context,$&frame,&input) >>>
        while true {
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT || event.kind == ui.EV_CANVAS_CLOSED { <- }
            if event.window_id != identity.window_id { -> }
            $dirty := event.kind == ui.EV_CANVAS_METRICS
            if event.kind >= ui.EV_TEXT_COMMIT && event.kind <= ui.EV_TEXT_SURROUNDING_DELETE {
                edit := ui.text_edit_of(&event) >>>
                if edit.input.id == input.id {
                    if event.kind == ui.EV_TEXT_INPUT_ENDED || event.kind == ui.EV_TEXT_INPUT_FAILED { <- }
                    dirty = true
                }
            }
            if ui.is_input_event(event.kind) {
                pointer := ui.input_of(&event) >>>
                if pointer.generation != identity.generation { -> }
                if pointer.kind == ui.EV_KEY_DOWN && pointer.key == ui.KEY_ESCAPE { demo.quit() >>> }
                bounds := layout.Rect{x: 28.0,y: 160.0,width: 790.0,height: 86.0}
                if pointer.kind == ui.EV_POINTER_DOWN && pointer.button == ui.BUTTON_LEFT && bounds.contains(pointer.x,pointer.y) {
                    state := input.snapshot() >>>
                    // The native editor owns preedit; do not overwrite an active composition.
                    if !state.composing {
                        hit := input.hit_test(state.revision,pointer.x,pointer.y) >>>
                        index := hit.byte_index()
                        _ := input.update(state.revision,&state.value,index,index,&caret) >>>
                        dirty = true
                    }
                }
            }
            if dirty { paint(&context,$&frame,&input) >>> }
        }
        frame.dispose()
        input.stop() >>> (err) { << 0 }
        << 0
    }
    fn worker(ech chan ui.Event) { scene(ech) >>> (err) { demo.fail(err.msg())
        << } }
    fn launch() int {
        $app := demo.app("Xu UI / Native Text Input",860,430) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    fn main() int { << launch() >>> (err) { eprintln(err.msg())
        << 1 } }
  • 16_ui_webview/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) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        $switcher := widgets.style_switcher()
        switcher.use_preset(widgets.THEME_LIGHT) >>>
        $toggle := widgets.switch_control(&identity, 1, &rect(48.0, 116.0, 280.0, 48.0), true) >>>
        $radio := widgets.radio(&identity, 2, &rect(48.0, 180.0, 280.0, 48.0), 1, false) >>>
        $slider := widgets.slider(&identity, 3, &rect(48.0, 260.0, 280.0, 36.0), 0.0, 100.0, 50.0) >>>
        slider.set_step(5.0) >>>
        $stepper := widgets.stepper(&identity, 4, &rect(48.0, 324.0, 280.0, 48.0), 0.0, 20.0, 1.0, 5.0) >>>
        $tabs := widgets.tabs(&identity, 5, &rect(376.0, 116.0, 348.0, 48.0), 3, 0) >>>
        $dropdown := widgets.select_box(&identity, 6, &rect(376.0, 196.0, 348.0, 48.0), 3, 0) >>>
        $list := widgets.list_box(&identity, 7, &rect(376.0, 284.0, 348.0, 132.0), 3, 0) >>>
        panel := widgets.card(&rect(24.0, 92.0, 724.0, 352.0)) >>>
        badge := widgets.badge(&rect(48.0, 392.0, 280.0, 32.0)) >>>
        divider := widgets.divider(&rect(48.0, 244.0, 280.0, 2.0), widgets.AXIS_HORIZONTAL) >>>
        $label0 := widgets.styled_label(&context, &"Enabled")
        $label1 := widgets.styled_label(&context, &"Choose this option")
        $label2 := widgets.styled_label(&context, &"Stepper")
        $label3 := widgets.styled_label(&context, &"One")
        $label4 := widgets.styled_label(&context, &"Two")
        $label5 := widgets.styled_label(&context, &"Three")
        $label6 := widgets.styled_label(&context, &"Select an option")
        $label7 := widgets.styled_label(&context, &"Xu 0.10.2")
        $label8 := widgets.styled_label(&context, &"One")
        $label9 := widgets.styled_label(&context, &"Two")
        $label10 := widgets.styled_label(&context, &"Three")
        $frame := context.new_frame(16384)
        $state := Model{dirty: true, focus: 0}
        $dispatcher := widgets.action_dispatcher(&state, &switcher)
        for id in 1:8 {dispatcher.on_any(id, control_action) >>> }
        while true {
            if state.dirty{
                styles := switcher.styles()
                frame.begin() >>>
                frame.set_bg(styles.background) >>>
                panel.paint_styled($&frame, &styles) >>>
                ink := styles.button.palette.foreground
                title := "Extended controls / " + switcher.name()
                frame.text(32.0, 28.0, 22.0, ink, &title) >>>
                toggle.paint_styled($&frame, $&label0, &styles) >>>
                radio.paint_styled($&frame, $&label1, &styles) >>>
                divider.paint_styled($&frame, &styles) >>>
                slider.paint_styled($&frame, &styles) >>>
                stepper.paint_styled($&frame, $&label2, &styles) >>>
                tabs.paint_box_styled($&frame, &styles) >>>
                list.paint_box_styled($&frame, &styles) >>>
                tabs.paint_tab_styled($&frame, 0, $&label3, &styles) >>>
                list.paint_item_styled($&frame, 0, $&label8, &styles) >>>
                tabs.paint_tab_styled($&frame, 1, $&label4, &styles) >>>
                list.paint_item_styled($&frame, 1, $&label9, &styles) >>>
                tabs.paint_tab_styled($&frame, 2, $&label5, &styles) >>>
                list.paint_item_styled($&frame, 2, $&label10, &styles) >>>
                dropdown.paint_styled($&frame, $&label6, &styles) >>>
                badge.paint_styled($&frame, $&label7, &styles) >>>
                frame.text(32.0, 464.0, 15.0, ink, &"T: theme / S: text size / D: density / Tab: focus / Esc: quit") >>>
                status := "Slider " + str(int(slider.value())) + " / Stepper " + str(int(stepper.value())) + " / Select " + str(dropdown.selected() + 1)
                frame.text(32.0, 494.0, 15.0, ink, &status) >>>
                // A Select popup overlays the scene; this basic painter repeats
                // its label. The selected option index is shown in the status.
                dropdown.paint_popup_styled($&frame, $&label6, &styles) >>>
                // This worker can repaint for a burst of control and appearance actions.
                frame.present_wait() >>>
                toggle.painted()
                radio.painted()
                slider.painted()
                stepper.painted()
                tabs.painted()
                dropdown.painted()
                list.painted()
                state.dirty = false
            }
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT{ <- }
            if event.window_id != identity.window_id{ -> }
            if event.kind == ui.EV_CANVAS_CLOSED{ <- }
            if event.kind == ui.EV_CANVAS_METRICS{state.dirty = true}
            if ui.is_input_event(event.kind) {
                input := ui.input_of(&event) >>>
                if input.generation != identity.generation{ -> }
                if input.kind == ui.EV_KEY_DOWN && input.repeat == 0 {
                    if input.key == ui.KEY_ESCAPE{
                        // App shutdown revokes canvas resources. Do not enqueue
                        // another frame while the native host is closing.
                        demo.quit() >>>
                        << 0
                    }
                    if appearance_key($&switcher, &input) >>> {state.dirty = true}
                    if input.key == ui.KEY_TAB{state.focus = state.focus % 7 + 1
                        state.dirty = true}
                }
            }
            // Route the popup first. A modal option click must not also focus
            // or activate the ListBox underneath it.
            popup_open := dropdown.is_open()
            first := dropdown.event(&event) >>>
            $actions :=[first]
            if !popup_open && !first.consumed{
                actions.push(toggle.event(&event) >>>)
                actions.push(radio.event(&event) >>>)
                actions.push(slider.event(&event) >>>)
                actions.push(stepper.event(&event) >>>)
                actions.push(tabs.event(&event) >>>)
                actions.push(list.event(&event) >>>)
            }
            for action in actions{
                if !(dispatcher.dispatch(&action, $&state, $&switcher) >>>) {
                    // ACTION_NONE may carry focus/repaint metadata without a semantic event.
                    action_state($&state, &action)
                }
            }
            toggle.set_focus(state.focus == 1)
            radio.set_focus(state.focus == 2)
            slider.set_focus(state.focus == 3)
            stepper.set_focus(state.focus == 4)
            tabs.set_focus(state.focus == 5)
            dropdown.set_focus(state.focus == 6)
            list.set_focus(state.focus == 7)
        }
        frame.dispose()
        if demo.alive(&identity) {
            label0.dispose()
            label1.dispose()
            label2.dispose()
            label3.dispose()
            label4.dispose()
            label5.dispose()
            label6.dispose()
            label7.dispose()
            label8.dispose()
            label9.dispose()
            label10.dispose()
        }
        << 0
    }
    fn worker(ech chan ui.Event) {
        scene(ech) >>> (err) {demo.fail(err.msg())
            << }
    }
    fn launch() int {
        $app := demo.app("Xu UI / Extended Controls", 780, 552) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    fn main() int {
        << launch() >>> (err) {eprintln(err.msg())
            << 1}
    }
  • 16_ui_webview/component_catalog/main.xu

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

    XuLocal SDK example
    @main
    #ui
    #ui/widgets
    #ui/draw
    #time
    #math
    demo #"github.com/xulang-org/examples/ui_demo"
    
    // The model contains business choices and screen-local handles only.
    struct Model{
        page int
        theme int
        text_scale f64
        density f64
        appearance_dirty bool
        nav []int
        settings []int
        pages []int
        headings []int
        captions []int
        table int
        tree int
        pager int
        crumbs int
        combo int
        multi int
        color int
        spinner int
        overlay_buttons []int
        popover int
        modal int
        modal_actions []int
        value_label int
        note int
    }
    fn (m &Model) fill_table(screen $&widgets.Screen) int {
        names :=["Compiler", "Widgets", "Runtime", "Desktop", "Examples", "Tooling"]
        states :=["Ready", "Review", "Ready", "Draft", "Ready", "Review"]
        clocks :=["10:30", "11:15", "09:40", "12:00", "10:05", "08:50"]
        $order :=[0, 1, 2, 3, 4, 5]
        col := screen.sort_column(m.table) >>>
        if col == 0 {order =[0, 3, 4, 2, 5, 1]}
        if col == 1 {order =[3, 0, 2, 4, 1, 5]}
        if col == 2 {order =[5, 2, 4, 0, 1, 3]}
        desc := screen.sort_descending(m.table) >>>
        page :=(screen.selected(m.pager) >>>) + 1
        for row in 0:6 {
            $slot := row
            if desc{slot = 5 - row}
            i := order[slot]
            screen.set_cell(m.table, row, 0, names[i] + " / " + str(page)) >>>
            screen.set_cell(m.table, row, 1, states[i]) >>>
            screen.set_cell(m.table, row, 2, clocks[i]) >>>
        }
        << 0
    }
    fn (m $&Model) layout(screen $&widgets.Screen) int {
        width := screen.width()
        height := screen.height()
        row := screen.row_height()
        for i in 0:3 {
            screen.place(m.nav[i], 28.0 + f64(i) * 124.0, 142.0, 112.0, row) >>>
            screen.set_selected_button(m.nav[i], m.page == i) >>>
            screen.set_visible(m.pages[i], m.page == i) >>>
            screen.place(m.settings[i], width - 420.0 + f64(i) * 132.0, 142.0, 120.0, row) >>>
        }
        screen.place(m.headings[0], 28.0, 26.0, width - 56.0, 24.0) >>>
        screen.place(m.headings[1], 28.0, 61.0, width - 56.0, 46.0) >>>
        screen.place(m.headings[2], 28.0, 108.0, width - 56.0, 30.0) >>>
        screen.place(m.crumbs, 28.0, 204.0, width - 56.0, row) >>>
        screen.place(m.note, 28.0, height - 48.0, width - 56.0, 30.0) >>>
        content := math.max(160.0, height - 420.0)
        screen.place(m.captions[0], 28.0, 253.0, width * 0.62 - 40.0, 30.0) >>>
        screen.place(m.captions[1], width * 0.62 + 12.0, 253.0, width * 0.38 - 40.0, 30.0) >>>
        screen.place(m.table, 28.0, 280.0, width * 0.62 - 40.0, content) >>>
        screen.place(m.tree, width * 0.62 + 12.0, 280.0, width * 0.38 - 40.0, content) >>>
        screen.place(m.pager, 28.0, height - 118.0, 380.0, row) >>>
        screen.place(m.captions[2], 28.0, 253.0, 400.0, 30.0) >>>
        screen.place(m.captions[3], 28.0, 363.0, 400.0, 30.0) >>>
        screen.place(m.captions[4], 450.0, 253.0, width - 478.0, 30.0) >>>
        screen.place(m.combo, 28.0, 280.0, 370.0, row) >>>
        screen.place(m.multi, 28.0, 390.0, 370.0, row) >>>
        screen.place(m.color, 450.0, 280.0, width - 478.0, 240.0) >>>
        screen.place(m.spinner, 28.0, 562.0, 28.0, 28.0) >>>
        screen.place(m.captions[5], 70.0, 568.0, width - 98.0, 30.0) >>>
        screen.place(m.value_label, 28.0, 620.0, width - 56.0, 36.0) >>>
        screen.place(m.captions[6], 28.0, 253.0, width - 56.0, 30.0) >>>
        for i in 0:4 {screen.place(m.overlay_buttons[i], 28.0 + f64(i) * 208.0, 280.0, 190.0, row) >>>
            screen.place(m.captions[i + 7], 28.0, 365.0 + f64(i) * 40.0, width - 56.0, 32.0) >>> }
        screen.place(m.modal_actions[0], 24.0, 210.0, 194.0, row) >>>
        screen.place(m.modal_actions[1], 234.0, 210.0, 194.0, row) >>>
        << 0
    }
    fn new_model(screen $&widgets.Screen) Model{
        $nav :=[]int {}
        for text in["Data", "Inputs", "Overlays"] {nav.push(screen.button(text) >>>)}
        $settings :=[]int {}
        for text in["Theme", "Text size", "Density"] {settings.push(screen.button(text) >>>)}
        $pages :=[]int {}
        for i in 0:3 {pages.push(screen.group() >>>)}
        headings :=[screen.label("XUUI / COMPONENT CATALOG", 12.0, true) >>>,
        screen.label("Native components, working together.", 26.0, false) >>>,
        screen.label("Keyboard, pointer, themes, typography and density — managed by Screen.", 13.0, true) >>>]
        crumbs := screen.breadcrumbs(&["Workspace", "UI", "Component catalog"]) >>>
        note := screen.label("Choose a category · Tab / Shift+Tab · Escape", 13.0, true) >>>
        table := screen.table(&["Module", "State", "Updated"], 6, 0) >>>
        tree := screen.tree() >>>
        pager := screen.pagination(3, 0) >>>
        combo := screen.combo_box(&["Compiler", "Widgets", "Runtime", "Desktop", "Examples", "工具链"], "") >>>
        multi := screen.multi_select(&["Native", "Keyboard", "IME", "Theming", "Motion"]) >>>
        screen.set_checked(multi, 0, true) >>>
        color := screen.color_picker(draw.rgba(59, 130, 246, 220)) >>>
        spinner := screen.spinner() >>>
        value_label := screen.label("Value:    Selected tags: 1", 14.0, false) >>>
        $overlay_buttons :=[]int {}
        for text in["Open popover", "Open modal", "Show toast", "Hover / focus me"] {overlay_buttons.push(screen.button(text) >>>)}
        popover := screen.popover(overlay_buttons[0], "An anchored panel for related actions.") >>>
        modal := screen.modal("Keep focus where it belongs", "Screen owns focus, input isolation and restoration.") >>>
        _ := screen.tooltip(overlay_buttons[3], "Pointer and keyboard share this hint.") >>>
        modal_actions :=[screen.button("Complete action") >>>, screen.button("Close") >>>]
        for id in modal_actions{screen.set_parent(id, modal) >>> }
        $captions :=[]int {}
        for text in["TABLE / sort columns · select rows · scroll", "TREE / expand · navigate",
        "COMBO BOX / type to filter · native IME", "MULTI SELECT / independent choices",
        "COLOR PICKER / red · green · blue · alpha", "Loading indicator · respects reduced motion",
        "OVERLAYS / anchor placement · focus ownership · timed feedback",
        "Popover: anchored to its trigger and constrained to the canvas.",
        "Modal: Tab stays inside; Escape closes; focus returns to the trigger.",
        "Toast: closes automatically; hover or focus pauses its lifetime.",
        "Tooltip: hover or keyboard focus reveals a delayed explanation."] {captions.push(screen.label(text, 13.0, true) >>>)}
        for id in[table, tree, pager, captions[0], captions[1]] {screen.set_parent(id, pages[0]) >>> }
        for id in[combo, multi, color, spinner, value_label, captions[2], captions[3], captions[4], captions[5]] {screen.set_parent(id, pages[1]) >>> }
        for id in overlay_buttons{screen.set_parent(id, pages[2]) >>> }
        screen.set_parent(popover, pages[2]) >>>
        for i in 6:11 {screen.set_parent(captions[i], pages[2]) >>> }
        root := screen.tree_add(tree, - 1, "XU Workspace") >>>
        compiler := screen.tree_add(tree, root, "Compiler") >>>
        _ := screen.tree_add(tree, compiler, "Frontend") >>>
        _ := screen.tree_add(tree, compiler, "Native backend") >>>
        ui_root := screen.tree_add(tree, root, "UI") >>>
        _ := screen.tree_add(tree, ui_root, "Widgets") >>>
        _ := screen.tree_add(tree, ui_root, "Drawing") >>>
        _ := screen.tree_add(tree, root, "Examples") >>>
        for node in[root, compiler, ui_root] {screen.set_expanded(tree, node, true) >>> }
        m := Model{page: 0, theme: 1, text_scale: 1.0, density: 1.0, appearance_dirty: true, nav: nav, settings: settings, pages: pages, headings: headings, captions: captions,
            table: table, tree: tree, pager: pager, crumbs: crumbs, combo: combo, multi: multi, color: color, spinner: spinner,
            overlay_buttons: overlay_buttons, popover: popover, modal: modal, modal_actions: modal_actions, value_label: value_label, note: note}
        m.fill_table(screen) >>>
        << m
    }
    fn scene(events chan ui.Event) int {
        ready := demo.ready(events) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        $screen := widgets.screen(&ready) >>>
        screen.resize(1040.0, 820.0) >>>
        screen.set_min_size(1040, 760) >>>
        $model := new_model($&screen) >>> (err) {screen.dispose()
            >> err}
        actions := register_actions(&model, &screen) >>>
        << widgets.run_screen_actions($&screen, events, $&model, layout_action, &actions) >>>
    }
    fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
            << }}
    fn launch() int {$app := demo.app("Xu UI / Component Catalog", 1040, 820) >>>
        xu worker(app.event_ch)
        << app.run() >>> }
    fn main() int { << launch() >>> (err) {eprintln(err.msg())
            << 1}}
  • 16_ui_webview/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) >>>
    }
    fn (model $&Model) checkbox_input(kind int, input &ui.InputEvent) widgets.Action{
        checkbox := $&model.checkbox
        << checkbox.route(kind, input) >>>
    }
    fn (model $&Model) scroll_input(kind int, input &ui.InputEvent) widgets.Action{
        scroll := $&model.scroll
        << scroll.route(kind, input) >>>
    }
    fn (model $&Model) input(id int, kind int, input &ui.InputEvent) widgets.Action{
        if id == model.button_id{ << model.button_input(kind, input) >>> }
        if id == model.check_id{ << model.checkbox_input(kind, input) >>> }
        if id == model.scroll_id{ << model.scroll_input(kind, input) >>> }
        << widgets.Action{kind: widgets.ACTION_NONE, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
    }
    fn (model $&Model) place_button(bounds &layout.Rect) int {
        button := $&model.button
        << button.set_bounds(bounds) >>>
    }
    fn (model $&Model) place_checkbox(bounds &layout.Rect) int {
        checkbox := $&model.checkbox
        << checkbox.set_bounds(bounds) >>>
    }
    fn (model $&Model) place_progress(bounds &layout.Rect) int {
        progress := $&model.progress
        << progress.set_bounds(bounds) >>>
    }
    fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
        model.draw_node(id, bounds, frame) >>> (err) {eprintln(err.msg())
            << false}
        << true
    }
    fn (model $&Model) draw_node(id int, bounds &layout.Rect, frame $&draw.Frame) int {
        if id == model.header_id{
            demo.text(&model.context, frame, 0.0, 0.0, 14.0, demo.accent(), "03 / RETAINED LAYOUT + CONTROLS") >>>
            demo.text(&model.context, frame, 0.0, 28.0, 24.0, demo.ink(), "Actions completed: " + str(model.count)) >>>
        } else if id == model.button_id{
            model.place_button(bounds) >>>
            model.button.paint(frame, &model.button_label, &model.theme) >>>
        } else if id == model.check_id{
            model.place_checkbox(bounds) >>>
            model.checkbox.paint(frame, &model.checkbox_label, &model.theme) >>>
        } else if id == model.progress_id{
            model.place_progress(bounds) >>>
            model.progress.paint(frame, &model.theme) >>>
        } else if id == model.scroll_id{
            scroll := $&model.scroll
            scroll.set_bounds(bounds) >>>
            frame.fill_rect(0.0, 0.0, bounds.width, bounds.height, draw.rgb(26, 37, 50)) >>>
        } else {
            for i in 0:model.row_ids.len{
                if id == model.row_ids[i] {demo.text(&model.context, frame, 12.0, 5.0, 15.0, demo.muted(), "Retained row " + str(i + 1) + " / scroll, Tab, PageDown, Home") >>> }
            }
        }
        << 0
    }
    fn (model $&Model) advance() int {
        model.count = model.count + 1
        println("Action count: " + str(model.count))
        value := f64(model.count % 11) / 10.0
        progress := $&model.progress
        << progress.set_value(value) >>>
    }
    fn (model $&Model) enable_button(enabled bool) {
        button := $&model.button
        button.set_enabled(enabled)
    }
    fn (model $&Model) acknowledge_button() {
        control := $&model.button
        control.painted()
    }
    fn (model $&Model) acknowledge_checkbox() {
        control := $&model.checkbox
        control.painted()
    }
    fn (model $&Model) acknowledge_progress() {
        control := $&model.progress
        control.painted()
    }
    fn (model $&Model) acknowledge_scroll() {
        control := $&model.scroll
        control.painted()
    }
    fn (model $&Model) acknowledge() {
        model.acknowledge_button()
        model.acknowledge_checkbox()
        model.acknowledge_progress()
        model.acknowledge_scroll()
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(28.0) >>>
        column.gap = 14.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, demo.background()) >>>
        leaf := layout.box_style(layout.BOX_LEAF)
        header := view.add(view.root(), &leaf, &layout.Size{width: 400.0, height: 72.0}) >>>
        button_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 44.0}) >>>
        check_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 40.0}) >>>
        progress_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 12.0}) >>>
        $viewport := layout.box_style(layout.BOX_COLUMN)
        viewport.height = 220.0
        viewport.clip = true
        viewport.cross_alignment = layout.CROSS_STRETCH
        viewport.gap = 6.0
        scroll_id := view.add(view.root(), &viewport, &layout.Size{width: 400.0, height: 220.0}) >>>
        $rows :=[]int {}
        for _ in 0:20 {
            row := view.add(scroll_id, &leaf, &layout.Size{width: 400.0, height: 32.0}) >>>
            rows.push(row)
            view.set_boundary(row, true) >>>
        }
        for id in[header, button_id, check_id, progress_id, scroll_id] {view.set_boundary(id, true) >>> }
        for id in[button_id, check_id, scroll_id] {view.set_input(id, true, true) >>> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        options := draw.text_options(15.0)
        first := "Complete one action"
        second := "Enable action button"
        $model := Model{button: widgets.button(&identity, button_id, &empty) >>>,
            checkbox: widgets.checkbox(&identity, check_id, &empty, true) >>>,
            progress: widgets.progress(&empty, 0.0) >>>,
            scroll: widgets.scroll(&identity, scroll_id, &empty, widgets.AXIS_VERTICAL, 760.0) >>>,
            button_label: context.layout_text(&first, &options) >>>,
            checkbox_label: context.layout_text(&second, &options) >>>,
            theme: widgets.default_theme(), context: context, count: 0, header_id: header, button_id: button_id, check_id: check_id, progress_id: progress_id, scroll_id: scroll_id, row_ids: rows}
        dispatcher := register_actions(&model, &view) >>>
        $width := 700.0
        $height := 600.0
        while true {
            constraints := layout.tight(width, height) >>>
            submitted := widgets.present($&view, &constraints, $&model) >>>
            if submitted{model.acknowledge()}
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT{ <- }
            if event.window_id != identity.window_id{ -> }
            if event.kind == ui.EV_CANVAS_METRICS{
                metrics := ui.metrics_of(&event) >>>
                if metrics.width > 0.0 && metrics.height > 0.0 {width = metrics.width
                    height = metrics.height}
            }
            actions := widgets.dispatch_event($&view, &event, $&model) >>>
            for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) >>> }
            if event.kind == ui.EV_CANVAS_CLOSED{ <- }
            if ui.is_input_event(event.kind) {
                input := ui.input_of(&event) >>>
                if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() >>> }
            }
            stats := view.stats()
            if stats.recorded_boundaries > 0 || stats.reused_boundaries > 0 {
                println("View: " + str(stats.recorded_boundaries) + " recorded / " + str(stats.reused_boundaries) + " reused boundaries")
            }
        }
        view.dispose()
        // Native close revokes resources; only release user handles while live.
        if demo.alive(&identity) {
            label := $&model.button_label
            label.dispose() >>>
            check_label := $&model.checkbox_label
            check_label.dispose() >>>
        }
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
            << }}
    fn launch() int {
        $app := demo.app("Xu UI / Retained Controls", 700, 600) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    fn main() int { << launch() >>> (err) {eprintln(err.msg())
            << 1}}
  • 16_ui_webview/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) >>> }
        if id == model.body_id{control := $&model.body
            << control.route(kind, event) >>> }
        << widgets.Action{kind: 0, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
    }
    fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
        model.draw_node(id, frame) >>> (err) {eprintln(err.msg())
            << false}
        << true
    }
    fn (model $&Model) draw_node(id int,frame $&draw.Frame) int {
        styles := model.styles.clone()
        if id == model.title_id { control := $&model.title
            control.paint_styled(frame,&styles) >>> }
        else if id == model.body_id { control := $&model.body
            control.paint_styled(frame,&styles) >>> }
        else if id == model.header {
            demo.text(&model.context,frame,0.0,0.0,24.0,tokens.text(model.dark),"Writing desk") >>>
            demo.text(&model.context,frame,0.0,34.0,14.0,tokens.muted(model.dark),"XUUI design standard · native text and menu controls") >>>
            demo.text(&model.context,frame,0.0,62.0,14.0,tokens.muted(model.dark),"Tab / Shift+Tab · drag selection · copy / cut / paste · arrows / Home / End") >>>
        } else if id == model.footer {
            demo.text(&model.context,frame,0.0,0.0,14.0,tokens.brand(model.dark),"Changes: " + str(model.changes) + "  |  " + model.status) >>>
            demo.text(&model.context,frame,0.0,27.0,14.0,tokens.muted(model.dark),"Use the Document menu: toggle editing, reset, query screens. Escape quits.") >>>
        }
        << 0
    }
    fn (model $&Model) place(view $&widgets.View) int {
        title := $&model.title
        widgets.place_editor(view, title) >>>
        body := $&model.body
        widgets.place_editor(view, body) >>>
        << 0
    }
    fn (model $&Model) native_event(event &ui.Event) bool {
        title := $&model.title
        first := title.event(event) >>>
        body := $&model.body
        second := body.event(event) >>>
        << first.kind == widgets.ACTION_CHANGE || second.kind == widgets.ACTION_CHANGE
    }
    fn (model $&Model) editing(on bool) int {
        title := $&model.title
        title.enable(on) >>>
        body := $&model.body
        body.enable(on) >>>
        << 0
    }
    fn (model $&Model) reset() int {
        title := $&model.title
        title.set_value(&"Untitled note") >>>
        body := $&model.body
        body.set_value(&"Write here.\n你好,Xu。\n\nSelection and IME are native; layout and painting stay in the retained View.") >>>
        << 0
    }
    fn menus(window &ui.Window,enabled bool,dark bool) int {
        $entries := [ui.submenu("document","Document",-1)]
        $reset := ui.menu_action("reset","Reset note",0)
        reset.key = 82
        reset.modifiers = ui.MENU_PRIMARY | ui.MOD_SHIFT
        entries.push(reset)
        entries.push(ui.menu_check("editing","Enable editing",0,enabled))
        entries.push(ui.menu_separator(0))
        entries.push(ui.submenu("display","Displays",0))
        $query := ui.menu_action("screens","Query current screens",4)
        query.key = 68
        query.modifiers = ui.MENU_PRIMARY | ui.MOD_SHIFT
        entries.push(query)
        $unavailable := ui.menu_action("unavailable","Unavailable action",4)
        unavailable.enabled = false
        entries.push(unavailable)
        entries.push(ui.menu_check("dark-theme","Dark appearance",0,dark))
        << window.set_menu_entries(entries) >>>
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        window := ui.Window{id: identity.window_id, generation: identity.generation, title: "", width: 0, height: 0, content_kind: ui.CONTENT_DRAW, content_backend_id: identity.canvas_id, closed: 0}
        menus(&window, true, false) >>>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(24.0) >>>
        column.gap = 16.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, tokens.canvas(false)) >>>
        leaf := layout.box_style(layout.BOX_LEAF)
        header := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 88.0}) >>>
        title_id := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 44.0}) >>>
        body_id := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 260.0}) >>>
        footer := view.add(view.root(), &leaf, &layout.Size{width: 500.0, height: 72.0}) >>>
        for id in[header, title_id, body_id, footer] {view.set_boundary(id, true) >>> }
        for id in[title_id, body_id] {view.set_input(id, true, true) >>> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        $model := Model{title: widgets.input(&context, &identity, title_id, &empty, &"Untitled note") >>>,
            body: widgets.text_area(&context, &identity, body_id, &empty, &"Write here.\n你好,Xu。\n\nSelection and IME are native; layout and painting stay in the retained View.") >>>,
            context: context, styles: tokens.editor_styles(false), dark: false, header: header, title_id: title_id, body_id: body_id, footer: footer, changes: 0, status: "Ready"}
        $dispatcher := widgets.action_dispatcher(&model, &view)
        dispatcher.on(title_id, widgets.ACTION_SUBMIT, submit_title) >>>
        $width := 820.0
        $height := 620.0
        $enabled := true
        options := ui.RequestOptions{timeout_ms: 5000}
        $screens := window.screens_async(&options) >>>
        $event := ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
        // Native text snapshots already carry the latest revision. Drain queued
        // edits before painting so a key burst cannot fill the frame queue.
        while true {
            if event.kind == ui.EV_NONE{
                constraints := layout.tight(width, height) >>>
                _ := view.layout(&constraints) >>>
                model.place($&view) >>>
                submitted := widgets.present($&view, &constraints, $&model) >>>
                if submitted{
                    first := $&model.title
                    first.painted()
                    second := $&model.body
                    second.painted()
                }
                event = demo.next(ech)
            }
            if event.kind == ui.EV_EXIT{ <- }
            if event.window_id != identity.window_id{event = ui.poll_chan(ech)
                -> }
            if event.kind == ui.EV_CANVAS_METRICS{metrics := ui.metrics_of(&event) >>>
                width = metrics.width
                height = metrics.height}
            actions := widgets.dispatch_event($&view, &event, $&model) >>>
            if model.native_event(&event) >>> {model.changes = model.changes + 1
                view.mark_paint(footer) >>> }
            for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) >>> }
            if event.kind == ui.EV_MENU_CLICKED{
                if event.menu_id == "reset" {model.reset() >>> }
                if event.menu_id == "editing" {enabled = !enabled
                    model.editing(enabled) >>>
                    for id in[title_id, body_id] {view.set_input(id, enabled, enabled) >>> }
                    menus(&window, enabled, model.dark) >>> }
                if event.menu_id == "dark-theme" {
                    model.dark = !model.dark
                    model.styles = tokens.editor_styles(model.dark)
                    view.set_background(tokens.canvas(model.dark))
                    for id in [header,title_id,body_id,footer] { view.mark_paint(id) >>> }
                    menus(&window,enabled,model.dark) >>>
                }
                if event.menu_id == "screens" {screens.cancel()
                    screens = window.screens_async(&options) >>> }
            }
            if event.kind == ui.EV_REQUEST{result := ui.request_of(&event) >>>
                if result.matches(&screens) && result.status == ui.REQUEST_COMPLETED{
                    displays := ui.screen_result(&result) >>>
                    model.status = str(displays.len) + " display(s)"
                    for display in displays{println("Screen: " + display.name + " / " + str(int(display.bounds.width)) + " x " + str(int(display.bounds.height)) + " / scale " + str(int(display.scale_x)))
                        if display.current{model.status = display.name + " · " + str(int(display.bounds.width)) + " x " + str(int(display.bounds.height))}}
                    view.mark_paint(footer) >>>
                }
            }
            if event.kind == ui.EV_CANVAS_CLOSED || event.kind == ui.EV_CLOSED{ <- }
            if ui.is_input_event(event.kind) {input := ui.input_of(&event) >>>
                if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() >>> }}
            event = ui.poll_chan(ech)
        }
        screens.cancel()
        view.dispose()
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
            << }}
    fn main() int {
        $app := demo.app("Xu UI / Writing Desk", 820, 620) >>> (err) {eprintln(err.msg())
            << 1}
        xu worker(app.event_ch)
        << app.run() >>> (err) {eprintln(err.msg())
            << 1}
    }
  • 16_ui_webview/workbench/main.xu

    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) >>>
    }
    fn (model $&Model) checkbox_input(kind int, input &ui.InputEvent) widgets.Action{
        checkbox := $&model.checkbox
        << checkbox.route(kind, input) >>>
    }
    fn (model $&Model) scroll_input(kind int, input &ui.InputEvent) widgets.Action{
        scroll := $&model.scroll
        << scroll.route(kind, input) >>>
    }
    fn (model $&Model) input(id int, kind int, input &ui.InputEvent) widgets.Action{
        if id == model.button_id{ << model.button_input(kind, input) >>> }
        if id == model.check_id{ << model.checkbox_input(kind, input) >>> }
        if id == model.scroll_id{ << model.scroll_input(kind, input) >>> }
        << widgets.Action{kind: widgets.ACTION_NONE, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
    }
    fn (model $&Model) place_button(bounds &layout.Rect) int {
        button := $&model.button
        << button.set_bounds(bounds) >>>
    }
    fn (model $&Model) place_checkbox(bounds &layout.Rect) int {
        checkbox := $&model.checkbox
        << checkbox.set_bounds(bounds) >>>
    }
    fn (model $&Model) place_progress(bounds &layout.Rect) int {
        progress := $&model.progress
        << progress.set_bounds(bounds) >>>
    }
    fn (model $&Model) paint(id int, bounds &layout.Rect, frame $&draw.Frame) bool {
        model.draw_node(id, bounds, frame) >>> (err) {eprintln(err.msg())
            << false}
        << true
    }
    fn (model $&Model) draw_node(id int, bounds &layout.Rect, frame $&draw.Frame) int {
        if id == model.header_id{
            demo.text(&model.context, frame, 0.0, 0.0, 14.0, demo.accent(), "07 / IMAGE WORKBENCH") >>>
            demo.text(&model.context, frame, 0.0, 28.0, 24.0, demo.ink(), "Image workbench") >>>
            demo.text(&model.context, frame, 0.0, 58.0, 13.0, demo.muted(), model.message + "") >>>
        } else if id == model.button_id{
            model.place_button(bounds) >>>
            model.button.paint(frame, &model.button_label, &model.theme) >>>
        } else if id == model.check_id{
            model.place_checkbox(bounds) >>>
            model.checkbox.paint(frame, &model.checkbox_label, &model.theme) >>>
        } else if id == model.progress_id{
            model.place_progress(bounds) >>>
            model.progress.paint(frame, &model.theme) >>>
        } else if id == model.scroll_id{
            scroll := $&model.scroll
            scroll.set_bounds(bounds) >>>
            frame.fill_rect(0.0, 0.0, bounds.width, bounds.height, draw.rgb(26, 37, 50)) >>>
        } else if model.row_ids.len > 0 && id == model.row_ids[0] {
            if model.images.len > 0 {
                image := model.images[0]
                scale := math.min(bounds.width / f64(image.width), bounds.height / f64(image.height))
                frame.image(&image, 0.0, 0.0, f64(image.width) * scale, f64(image.height) * scale) >>>
            } else {demo.text(&model.context, frame, 12.0, 20.0, 17.0, demo.muted(), "The selected image appears here.") >>> }
        }
        << 0
    }
    fn (model $&Model) progress_value(value f64) int {
        progress := $&model.progress
        << progress.set_value(value) >>>
    }
    fn (model $&Model) retire_image(index int) int {
        $image := model.images[index]
        image.dispose() >>>
        model.images[index] = image
        << 0
    }
    fn (model $&Model) replace_image(image draw.Image) int {
        for i in 0:model.images.len{model.retire_image(i) >>> }
        model.images =[]draw.Image{}
        model.images.push(image)
        << 0
    }
    fn preview_paint(window &ui.Window, path &string) int {
        context := draw.window_context(window) >>>
        $image := context.load_image(path) >>>
        $frame := context.new_frame(256)
        frame.begin() >>>
        frame.set_bg(demo.background()) >>>
        scale := math.min(f64(window.width - 40) / f64(image.width), f64(window.height - 40) / f64(image.height))
        frame.image(&image, 20.0, 20.0, f64(image.width) * scale, f64(image.height) * scale) >>>
        frame.present() >>>
        frame.dispose()
        image.dispose() >>>
        << 0
    }
    fn (model $&Model) acknowledge_button() {
        control := $&model.button
        control.painted()
    }
    fn (model $&Model) acknowledge_checkbox() {
        control := $&model.checkbox
        control.painted()
    }
    fn (model $&Model) acknowledge_progress() {
        control := $&model.progress
        control.painted()
    }
    fn (model $&Model) acknowledge_scroll() {
        control := $&model.scroll
        control.painted()
    }
    fn (model $&Model) acknowledge() {
        model.acknowledge_button()
        model.acknowledge_checkbox()
        model.acknowledge_progress()
        model.acknowledge_scroll()
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(28.0) >>>
        column.gap = 14.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, demo.background()) >>>
        leaf := layout.box_style(layout.BOX_LEAF)
        header := view.add(view.root(), &leaf, &layout.Size{width: 400.0, height: 88.0}) >>>
        button_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 44.0}) >>>
        check_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 40.0}) >>>
        progress_id := view.add(view.root(), &leaf, &layout.Size{width: 280.0, height: 12.0}) >>>
        $viewport := layout.box_style(layout.BOX_COLUMN)
        viewport.height = 260.0
        viewport.clip = true
        viewport.cross_alignment = layout.CROSS_STRETCH
        viewport.gap = 6.0
        scroll_id := view.add(view.root(), &viewport, &layout.Size{width: 400.0, height: 260.0}) >>>
        $rows :=[]int {}
        for _ in 0:1 {
            row := view.add(scroll_id, &leaf, &layout.Size{width: 400.0, height: 250.0}) >>>
            rows.push(row)
            view.set_boundary(row, true) >>>
        }
        for id in[header, button_id, check_id, progress_id, scroll_id] {view.set_boundary(id, true) >>> }
        for id in[button_id, check_id, scroll_id] {view.set_input(id, true, true) >>> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        options := draw.text_options(15.0)
        first := "Open a PNG or JPEG"
        second := "Show a separate preview window"
        $model := Model{button: widgets.button(&identity, button_id, &empty) >>>,
            checkbox: widgets.checkbox(&identity, check_id, &empty, true) >>>,
            progress: widgets.progress(&empty, 0.0) >>>,
            scroll: widgets.scroll(&identity, scroll_id, &empty, widgets.AXIS_VERTICAL, 250.0) >>>,
            button_label: context.layout_text(&first, &options) >>>,
            checkbox_label: context.layout_text(&second, &options) >>>,
            theme: widgets.default_theme(), context: context, count: 0, message: "Open a local image to begin.", source: "", images:[]draw.Image{}, header_id: header, button_id: button_id, check_id: check_id, progress_id: progress_id, scroll_id: scroll_id, row_ids: rows, identity: identity, pending: ui.Request{id: 0, window_id: 0, canvas_id: 0, generation: 0, kind: 0}}
        $width := 900.0
        $height := 700.0
        $native := demo.windows(ech)
        $preview := ui.Window{id: 0, generation: 0, title: "Preview", width: 720, height: 500, content_kind: ui.CONTENT_DRAW, content_backend_id: 0, closed: 1}
        dispatcher := register_actions(&model, &view) >>>
        while true {
            constraints := layout.tight(width, height) >>>
            submitted := widgets.present($&view, &constraints, $&model) >>>
            if submitted{model.acknowledge()}
            event := demo.next(ech)
            if event.kind == ui.EV_EXIT{ <- }
            if preview.id > 0 && event.window_id == preview.id{
                if event.kind == ui.EV_CLOSED || event.kind == ui.EV_WINDOW_FAILED{preview.closed = 1}
                if event.kind == ui.EV_CANVAS_READY && model.source.len > 0 {
                    preview.content_command("input_enabled\t1") >>>
                    preview.content_command("pan_enabled\t0") >>>
                    preview_paint(&preview, &model.source) >>> }
                if event.kind == ui.EV_CANVAS_METRICS{
                    metrics := ui.metrics_of(&event) >>>
                    if metrics.width > 40.0 && metrics.height > 40.0 {preview.width = int(metrics.width)
                        preview.height = int(metrics.height)
                        if model.source.len > 0 {preview_paint(&preview, &model.source) >>> }}
                }
                ->
            }
            if event.window_id != identity.window_id{ -> }
            if event.kind == ui.EV_REQUEST{
                result := ui.request_of(&event) >>>
                if result.matches(&model.pending) {
                    model.pending.id = 0
                    model.message = "Selection cancelled or failed."
                    if result.status == ui.REQUEST_COMPLETED{
                        paths := ui.file_paths(&result) >>>
                        if paths.len > 0 {
                            path := paths[0] + ""
                            image := context.load_image(&path) >>> (err) {model.message = err.msg()
                                view.mark_paint(header) >>>
                                -> }
                            model.replace_image(image) >>>
                            model.source = path + ""
                            model.message = "Loaded " + str(image.width) + " x " + str(image.height) + " pixels"
                            println(model.message + "")
                            model.progress_value(1.0) >>>
                            view.mark_paint(model.row_ids[0]) >>>
                            if model.checkbox.value() {
                                if preview.closed != 0 {preview = native.open_content_window(ui.WindowOpts{title: "Xu UI / Image Preview", width: 720, height: 500}, ui.CONTENT_DRAW) >>> }
                                else {preview_paint(&preview, &path) >>>
                                    preview.focus() >>> }
                            }
                        }
                    }
                    view.mark_paint(header) >>>
                    view.mark_paint(progress_id) >>>
                }
            }
            if event.kind == ui.EV_CANVAS_METRICS{
                metrics := ui.metrics_of(&event) >>>
                if metrics.width > 0.0 && metrics.height > 0.0 {width = metrics.width
                    height = metrics.height}
            }
            actions := widgets.dispatch_event($&view, &event, $&model) >>>
            for action in actions{_ := dispatcher.dispatch(&action, $&model, $&view) >>> }
            if event.kind == ui.EV_CANVAS_CLOSED{demo.quit() >>>
                <- }
            if ui.is_input_event(event.kind) {
                input := ui.input_of(&event) >>>
                if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE{demo.quit() >>> }
            }
            stats := view.stats()
            if stats.recorded_boundaries > 0 || stats.reused_boundaries > 0 {
                println("View: " + str(stats.recorded_boundaries) + " recorded / " + str(stats.reused_boundaries) + " reused boundaries")
            }
        }
        if model.pending.id > 0 {_ := model.pending.cancel()}
        view.dispose()
        // Native close has already revoked this canvas's images and text layouts.
        if demo.alive(&identity) {
            for i in 0:model.images.len{model.retire_image(i) >>> }
            label := $&model.button_label
            label.dispose() >>>
            check_label := $&model.checkbox_label
            check_label.dispose() >>>
        }
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
            << }}
    fn launch() int {
        $app := demo.app("Xu UI / Retained Image Workbench", 900, 700) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    fn main() int { << launch() >>> (err) {eprintln(err.msg())
            << 1}}
  • 16_ui_webview/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) >>>
    }
    fn (m $&Model) tick(view $&widgets.View, now time.Instant) int {
        m.clock = now
        reduced := m.reduced_motion
        for id in 1:m.transitions.len{
            motion := $&m.transitions[id]
            if reduced && motion.is_animating() {motion.finish()
                view.mark_paint(id) >>> }
            else if motion.advance(now) >>> {view.mark_paint(id) >>> }
        }
        $selected := 0.0
        if m.toggle.value() {selected = 1.0}
        switch_motion := $&m.switch_motion
        before_switch := switch_motion.value()
        switch_motion.retarget(selected, now, time.milliseconds(180) >>>, reduced) >>>
        if before_switch != switch_motion.value() {view.mark_paint(32) >>> }
        $opened := 0.0
        if m.select_ctrl.is_open() {opened = 1.0}
        popup_motion := $&m.popup_motion
        before_popup := popup_motion.value()
        $popup_duration := time.milliseconds(130) >>>
        if opened == 0.0 {popup_duration = time.milliseconds(95) >>> }
        popup_motion.retarget(opened, now, popup_duration, reduced) >>>
        if before_popup != popup_motion.value() {view.mark_paint(1) >>> }
        input := $&m.input
        if input.tick(now, reduced) >>> {view.mark_paint(12) >>> }
        invalid := $&m.invalid
        if invalid.tick(now, reduced) >>> {view.mark_paint(13) >>> }
        read_only := $&m.read_only
        if read_only.tick(now, reduced) >>> {view.mark_paint(14) >>> }
        area := $&m.area
        if area.tick(now, reduced) >>> {view.mark_paint(15) >>> }
        << 0
    }
    fn (m &Model) next_frame(now time.Instant) time.Instant{
        if m.switch_motion.is_animating() || m.popup_motion.is_animating() { << now.add(time.milliseconds(16) >>>) >>> }
        for motion in m.transitions{if motion.is_animating() { << now.add(time.milliseconds(16) >>>) >>> }}
        $deadline := time.zero_instant()
        for next in[m.input.next_caret_tick(now, m.reduced_motion) >>>, m.invalid.next_caret_tick(now, m.reduced_motion) >>>,
        m.read_only.next_caret_tick(now, m.reduced_motion) >>>, m.area.next_caret_tick(now, m.reduced_motion) >>>] {
            if !next.is_zero() &&(deadline.is_zero() || next.before(deadline)) {deadline = next}
        }
        << deadline
    }
    fn (m &Model) next_event(ech chan ui.Event) ui.Event{
        deadline := m.next_frame(time.instant()) >>>
        while true {
            event := ui.poll_chan(ech)
            if event.kind != ui.EV_NONE{ << event}
            if !deadline.is_zero() && !time.instant().before(deadline) { << event}
            pause := time.milliseconds(8) >>>
            pause.sleep()
        }
        << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
    }
    fn (m $&Model) measure_node(id int, s &widgets.Styles) layout.Size{
        if id == 4 {control := m.theme.clone()
            label := $&m.theme_label
            << control.measure_styled(label, s) >>> }
        if id == 5 {control := m.scale.clone()
            label := $&m.scale_label
            << control.measure_styled(label, s) >>> }
        if id == 6 {control := m.density.clone()
            label := $&m.density_label
            << control.measure_styled(label, s) >>> }
        if id == 8 {control := m.brand.clone()
            label := $&m.brand_label
            << control.measure_icon_styled(label, s) >>> }
        if id == 9 {control := m.disabled.clone()
            label := $&m.disabled_label
            << control.measure_styled(label, s) >>> }
        if id == 10 {control := m.check.clone()
            label := $&m.check_label
            << control.measure_styled(label, s) >>> }
        if id == 11 {control := m.progress.clone()
            << control.measure_styled(s) >>> }
        if id == 12 {control := $&m.input
            << control.measure_styled(s) >>> }
        if id == 13 {control := $&m.invalid
            << control.measure_styled(s) >>> }
        if id == 14 {control := $&m.read_only
            << control.measure_styled(s) >>> }
        if id == 15 {control := $&m.area
            << control.measure_styled(s) >>> }
        if id == 32 {control := m.toggle.clone()
            label := $&m.toggle_label
            << control.measure_styled(label, s) >>> }
        if id == 33 {control := m.radio_a.clone()
            label := $&m.radio_a_label
            << control.measure_styled(label, s) >>> }
        if id == 34 {control := m.radio_b.clone()
            label := $&m.radio_b_label
            << control.measure_styled(label, s) >>> }
        if id == 35 {control := m.slider.clone()
            << control.measure_styled(s) >>> }
        if id == 36 {control := m.stepper.clone()
            label := $&m.stepper_label
            << control.measure_styled(label, s) >>> }
        if id == 37 {control := m.badge.clone()
            label := $&m.badge_label
            << control.measure_styled(label, s) >>> }
        if id == 38 {control := m.divider.clone()
            label := $&m.divider_label
            << control.measure_labeled_styled(label, s) >>> }
        if id == 40 {control := m.tabs.clone()
            label := $&m.tab_label
            << control.measure_styled(label, s) >>> }
        if id == 41 {control := m.select_ctrl.clone()
            label := $&m.select_label
            << control.measure_styled(label, s) >>> }
        if id == 42 {control := m.card.clone()
            label := $&m.card_label
            << control.measure_header_styled(label, s) >>> }
        if id == 43 {control := m.list.clone()
            label := $&m.list_label
            << control.measure_styled(label, s) >>> }
        << layout.Size{width: 0.0, height: 0.0}
    }
    fn (m $&Model) measure_styled(id int, s &widgets.Styles) layout.Size{
        << m.measure_node(id, s) >>> (err) {eprintln(err.msg())
            << layout.Size{width: - 1.0, height: - 1.0}}
    }
    fn (m $&Model) draw_node(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) int {
        if id == 4 {target := $&m.theme
            target.set_bounds(b) >>>
            $control := m.theme.clone()
            base := control.style_or(s)
            appearance := m.motion_style(4, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.theme_label
            control.paint_styled(f, label, s) >>> }
        if id == 5 {target := $&m.scale
            target.set_bounds(b) >>>
            $control := m.scale.clone()
            base := control.style_or(s)
            appearance := m.motion_style(5, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.scale_label
            control.paint_styled(f, label, s) >>> }
        if id == 6 {target := $&m.density
            target.set_bounds(b) >>>
            $control := m.density.clone()
            base := control.style_or(s)
            appearance := m.motion_style(6, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.density_label
            control.paint_styled(f, label, s) >>> }
        if id == 8 {target := $&m.brand
            target.set_bounds(b) >>>
            $control := m.brand.clone()
            base := control.style_or(s)
            appearance := m.motion_style(8, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            icon := m.icon
            label := $&m.brand_label
            control.paint_icon_styled(f, label, &icon, s) >>> }
        if id == 9 {target := $&m.disabled
            target.set_bounds(b) >>>
            $control := m.disabled.clone()
            base := control.style_or(s)
            appearance := m.motion_style(9, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.disabled_label
            control.paint_styled(f, label, s) >>> }
        if id == 10 {target := $&m.check
            target.set_bounds(b) >>>
            $control := m.check.clone()
            base := control.style_or(s)
            appearance := m.motion_style(10, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.check_label
            control.paint_styled(f, label, s) >>> }
        if id == 12 {
            now := m.clock
            reduced := m.reduced_motion
            $motion := m.transitions[12]
            control := $&m.input
            control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
            m.transitions[12] = motion}
        if id == 13 {
            now := m.clock
            reduced := m.reduced_motion
            $motion := m.transitions[13]
            control := $&m.invalid
            control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
            m.transitions[13] = motion}
        if id == 14 {
            now := m.clock
            reduced := m.reduced_motion
            $motion := m.transitions[14]
            control := $&m.read_only
            control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
            m.transitions[14] = motion}
        if id == 15 {
            now := m.clock
            reduced := m.reduced_motion
            $motion := m.transitions[15]
            control := $&m.area
            control.paint_motion_styled(f, s, $&motion, now, reduced) >>>
            m.transitions[15] = motion}
        if id == 11 {control := $&m.progress
            control.set_bounds(b) >>>
            control.paint_styled(f, s) >>> }
        if id == 32 {target := $&m.toggle
            target.set_bounds(b) >>>
            $control := m.toggle.clone()
            base := control.style_or(s)
            appearance := m.motion_style(32, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            position := m.switch_motion.value()
            label := $&m.toggle_label
            control.paint_position_styled(f, label, s, position) >>> }
        if id == 33 {target := $&m.radio_a
            target.set_bounds(b) >>>
            $control := m.radio_a.clone()
            base := control.style_or(s)
            appearance := m.motion_style(33, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.radio_a_label
            control.paint_styled(f, label, s) >>> }
        if id == 34 {target := $&m.radio_b
            target.set_bounds(b) >>>
            $control := m.radio_b.clone()
            base := control.style_or(s)
            appearance := m.motion_style(34, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.radio_b_label
            control.paint_styled(f, label, s) >>> }
        if id == 35 {target := $&m.slider
            target.set_bounds(b) >>>
            $control := m.slider.clone()
            base := control.style_or(s)
            appearance := m.motion_style(35, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            control.paint_styled(f, s) >>> }
        if id == 36 {target := $&m.stepper
            target.set_bounds(b) >>>
            $control := m.stepper.clone()
            base := control.style_or(s)
            appearance := m.motion_style(36, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.stepper_label
            control.paint_styled(f, label, s) >>> }
        if id == 37 {target := $&m.badge
            target.set_bounds(b) >>>
            control := m.badge.clone()
            label := $&m.badge_label
            control.paint_styled(f, label, s) >>> }
        if id == 38 {target := $&m.divider
            target.set_bounds(b) >>>
            control := m.divider.clone()
            label := $&m.divider_label
            control.paint_labeled_styled(f, label, s) >>> }
        if id == 40 {target := $&m.tabs
            target.set_bounds(b) >>>
            control := m.tabs.clone()
            control.paint_box_styled(f, s) >>>
            l0 := $&m.tab_label
            control.paint_tab_styled(f, 0, l0, s) >>>
            l1 := $&m.tab_2_label
            control.paint_tab_styled(f, 1, l1, s) >>>
            l2 := $&m.tab_3_label
            control.paint_tab_styled(f, 2, l2, s) >>> }
        if id == 41 {target := $&m.select_ctrl
            target.set_bounds(b) >>>
            $control := m.select_ctrl.clone()
            base := control.style_or(s)
            appearance := m.motion_style(41, &base, control.visual_state()) >>>
            control.set_style(&appearance) >>>
            label := $&m.select_label
            control.paint_styled(f, label, s) >>> }
        if id == 42 {target := $&m.card
            target.set_bounds(b) >>>
            control := m.card.clone()
            label := $&m.card_label
            control.paint_header_styled(f, label, s) >>>
            demo.text(&m.context, f, 14.0 * s.density, 42.0 * s.density, 11.0 * s.text_scale, s.button.palette.muted, "Card body") >>> }
        if id == 43 {target := $&m.list
            target.set_bounds(b) >>>
            control := m.list.clone()
            control.paint_box_styled(f, s) >>>
            r0 := $&m.list_label
            control.paint_item_styled(f, 0, r0, s) >>>
            r1 := $&m.list_2_label
            control.paint_item_styled(f, 1, r1, s) >>>
            r2 := $&m.list_3_label
            control.paint_item_styled(f, 2, r2, s) >>>
            r3 := $&m.list_4_label
            control.paint_item_styled(f, 3, r3, s) >>> }
        if id == 2 {
            demo.text(&m.context, f, 0.0, 0.0, 24.0, s.button.palette.foreground, "A theme that reaches every control") >>>
            demo.text(&m.context, f, 0.0, 33.0, 13.0, s.button.palette.muted, "Light / dark / contrast · typography · density · local overrides · no idle redraw") >>>
        }
        if id >= 18 && id <= 29 {
            f.fill_rect(0.0, 0.0, b.width, b.height, s.input.palette.normal) >>>
            demo.text(&m.context, f, 12.0, 5.0, 14.0, s.input.palette.foreground, "Scrollable item " + str(id - 17) + "   —   wheel, drag the thumb, or Page Down") >>>
        }
        if id == 30 {
            demo.text(&m.context, f, 0.0, 0.0, 12.0, s.button.palette.muted, "The green button keeps its own font and palette. Error and read-only fields are distinct states.") >>>
            demo.text(&m.context, f, 0.0, 21.0, 12.0, s.button.palette.muted, "Tab / Shift+Tab to move focus · copy from read-only text · Escape to quit") >>>
        }
        << 0
    }
    fn (m $&Model) paint_styled(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) bool {
        m.draw_node(id, b, s, f) >>> (err) {eprintln(err.msg())
            << false}
        << true
    }
    fn (m $&Model) overlay_styled(id int, b &layout.Rect, s &widgets.Styles, f $&draw.Frame) bool {
        if id == 16 {control := $&m.scroll
            control.paint_scrollbar(f, s) >>> (err) {eprintln(err.msg())
                << false}}
        if id == 1 &&(m.select_ctrl.is_open() || m.popup_motion.value() > 0.0) {
            m.paint_select_popup(s, f) >>> (err) {eprintln(err.msg())
                << false}
        }
        << true
    }
    // Root overlay keeps the popup above every sibling and outside the button's box.
    fn (m $&Model) paint_select_popup(s &widgets.Styles, f $&draw.Frame) int {
        $control := m.select_ctrl.clone()
        control.set_open(true)
        opacity := m.popup_motion.value()
        if opacity <= 0.0 { << 0}
        base := control.style_or(s)
        appearance := base.with_opacity(opacity) >>>
        control.set_style(&appearance) >>>
        popup := control.popup_bounds(s)
        $offset := - 4.0 *(1.0 - opacity)
        if popup.y < 0.0 {offset = 4.0 *(1.0 - opacity)}
        f.push() >>>
        f.translate(m.select_origin.x, m.select_origin.y + offset) >>>
        control.paint_popup_box_styled(f, s) >>>
        auto_label := $&m.option_auto
        control.paint_option_styled(f, 0, auto_label, s) >>>
        manual_label := $&m.option_manual
        control.paint_option_styled(f, 1, manual_label, s) >>>
        locked_label := $&m.option_locked
        control.paint_option_styled(f, 2, locked_label, s) >>>
        f.pop() >>>
        << 0
    }
    // The popup is an overlay, so route its pointer sequence before normal tree hits.
    fn (m $&Model) dispatch_input(view $&widgets.View, event &ui.InputEvent)[]widgets.Action{
        was_open := m.select_ctrl.is_open()
        pointer := event.kind == ui.EV_POINTER_DOWN || event.kind == ui.EV_POINTER_UP ||
        event.kind == ui.EV_POINTER_MOVE || event.kind == ui.EV_POINTER_SCROLL
        if pointer &&(was_open || m.select_popup_armed) {
            local := view.local_input(41, event) >>>
            styles := view.styles_for(41) >>>
            pop := m.select_ctrl.popup_bounds(&styles)
            if pop.contains(local.x, local.y) || m.select_popup_armed{
                if event.kind == ui.EV_POINTER_DOWN && event.button == ui.BUTTON_LEFT{m.select_popup_armed = true}
                control := $&m.select_ctrl
                action := control.input(&local) >>>
                view.set_pointer_cursor(ui.CURSOR_HAND) >>>
                if event.kind == ui.EV_POINTER_UP{m.select_popup_armed = false}
                view.mark_paint(41) >>>
                view.mark_paint(1) >>>
                <<[action]
            }
        }
        if event.kind == ui.EV_POINTER_CANCEL{m.select_popup_armed = false}
        actions := widgets.dispatch(view, event, m) >>>
        if was_open || m.select_ctrl.is_open() {view.mark_paint(1) >>> }
        << actions
    }
    fn (m $&Model) dispatch_event(view $&widgets.View, event &ui.Event)[]widgets.Action{
        if ui.is_input_event(event.kind) {
            input := ui.input_of(event) >>>
            << m.dispatch_input(view, &input) >>>
        }
        was_open := m.select_ctrl.is_open()
        actions := widgets.dispatch_event(view, event, m) >>>
        m.select_popup_armed = false
        if was_open && !m.select_ctrl.is_open() {view.mark_paint(1) >>> }
        << actions
    }
    fn (m $&Model) input(id int, kind int, event &ui.InputEvent) widgets.Action{
        if id == 4 {control := $&m.theme
            << control.route(kind, event) >>> }
        if id == 5 {control := $&m.scale
            << control.route(kind, event) >>> }
        if id == 6 {control := $&m.density
            << control.route(kind, event) >>> }
        if id == 8 {control := $&m.brand
            << control.route(kind, event) >>> }
        if id == 9 {control := $&m.disabled
            << control.route(kind, event) >>> }
        if id == 10 {control := $&m.check
            << control.route(kind, event) >>> }
        if id == 12 {control := $&m.input
            << control.route(kind, event) >>> }
        if id == 13 {control := $&m.invalid
            << control.route(kind, event) >>> }
        if id == 14 {control := $&m.read_only
            << control.route(kind, event) >>> }
        if id == 15 {control := $&m.area
            << control.route(kind, event) >>> }
        if id == 16 {control := $&m.scroll
            << control.route(kind, event) >>> }
        if id == 32 {control := $&m.toggle
            << control.route(kind, event) >>> }
        if id == 33 {control := $&m.radio_a
            << control.route(kind, event) >>> }
        if id == 34 {control := $&m.radio_b
            << control.route(kind, event) >>> }
        if id == 35 {control := $&m.slider
            << control.route(kind, event) >>> }
        if id == 36 {control := $&m.stepper
            << control.route(kind, event) >>> }
        if id == 40 {control := $&m.tabs
            << control.route(kind, event) >>> }
        if id == 41 {control := $&m.select_ctrl
            << control.route(kind, event) >>> }
        if id == 43 {control := $&m.list
            << control.route(kind, event) >>> }
        << widgets.Action{kind: 0, id: id, needs_paint: false, request_focus: false, consumed: false, value: 0.0}
    }
    fn (m $&Model) place(view $&widgets.View) int {
        select_bounds := view.node_bounds(41) >>>
        m.select_origin = select_bounds
        select_styles := view.styles_for(41) >>>
        select_control := $&m.select_ctrl
        select_control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: select_bounds.width, height: select_bounds.height}) >>>
        select_control.apply_styles(&select_styles) >>>
        popup := select_control.popup_bounds(&select_styles)
        window_bounds := view.node_bounds(1) >>>
        below := window_bounds.y + window_bounds.height - select_bounds.y - select_bounds.height
        above := select_bounds.y - window_bounds.y
        select_control.set_popup_above(below < popup.height + 2.0 * select_styles.density && above > below)
        list_bounds := view.node_bounds(43) >>>
        list_styles := view.styles_for(43) >>>
        list_control := $&m.list
        list_control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: list_bounds.width, height: list_bounds.height}) >>>
        list_control.apply_styles(&list_styles) >>>
        input := $&m.input
        widgets.place_editor(view, input) >>>
        invalid := $&m.invalid
        widgets.place_editor(view, invalid) >>>
        read_only := $&m.read_only
        widgets.place_editor(view, read_only) >>>
        area := $&m.area
        widgets.place_editor(view, area) >>>
        bounds := view.node_bounds(16) >>>
        styles := view.styles_for(16) >>>
        control := $&m.scroll
        control.set_bounds(&layout.Rect{x: 0.0, y: 0.0, width: bounds.width, height: bounds.height}) >>>
        control.apply_styles(&styles) >>>
        view.set_scroll(16, 0.0, control.offset()) >>>
        << 0
    }
    fn (m $&Model) native_event(view $&widgets.View, event &ui.Event) int {
        input := $&m.input
        action_12 := input.event(event) >>>
        if action_12.needs_paint{view.mark_paint(12) >>> }
        invalid := $&m.invalid
        action_13 := invalid.event(event) >>>
        if action_13.needs_paint{view.mark_paint(13) >>> }
        read_only := $&m.read_only
        action_14 := read_only.event(event) >>>
        if action_14.needs_paint{view.mark_paint(14) >>> }
        area := $&m.area
        action_15 := area.event(event) >>>
        if action_15.needs_paint{view.mark_paint(15) >>> }
        << 0
    }
    fn (m $&Model) acknowledge() {
        theme := $&m.theme
        theme.painted()
        scale := $&m.scale
        scale.painted()
        density := $&m.density
        density.painted()
        brand := $&m.brand
        brand.painted()
        disabled := $&m.disabled
        disabled.painted()
        check := $&m.check
        check.painted()
        input := $&m.input
        input.painted()
        invalid := $&m.invalid
        invalid.painted()
        read_only := $&m.read_only
        read_only.painted()
        area := $&m.area
        area.painted()
        progress := $&m.progress
        progress.painted()
        scroll := $&m.scroll
        scroll.painted()
        toggle := $&m.toggle
        toggle.painted()
        radio_a := $&m.radio_a
        radio_a.painted()
        radio_b := $&m.radio_b
        radio_b.painted()
        slider := $&m.slider
        slider.painted()
        stepper := $&m.stepper
        stepper.painted()
        tabs := $&m.tabs
        tabs.painted()
        select_ctrl := $&m.select_ctrl
        select_ctrl.painted()
        badge := $&m.badge
        badge.painted()
        divider := $&m.divider
        divider.painted()
        card := $&m.card
        card.painted()
        list := $&m.list
        list.painted()
    }
    fn (m $&Model) cleanup() {
        icon := $&m.icon
        icon.dispose() >>> (err) {eprintln(err.msg())
            << }
        theme_label := $&m.theme_label
        theme_label.dispose()
        scale_label := $&m.scale_label
        scale_label.dispose()
        density_label := $&m.density_label
        density_label.dispose()
        brand_label := $&m.brand_label
        brand_label.dispose()
        disabled_label := $&m.disabled_label
        disabled_label.dispose()
        check_label := $&m.check_label
        check_label.dispose()
        toggle_label := $&m.toggle_label
        toggle_label.dispose()
        radio_a_label := $&m.radio_a_label
        radio_a_label.dispose()
        radio_b_label := $&m.radio_b_label
        radio_b_label.dispose()
        stepper_label := $&m.stepper_label
        stepper_label.dispose()
        badge_label := $&m.badge_label
        badge_label.dispose()
        divider_label := $&m.divider_label
        divider_label.dispose()
        card_label := $&m.card_label
        card_label.dispose()
        tab_label := $&m.tab_label
        tab_label.dispose()
        tab_2_label := $&m.tab_2_label
        tab_2_label.dispose()
        tab_3_label := $&m.tab_3_label
        tab_3_label.dispose()
        select_label := $&m.select_label
        select_label.dispose()
        option_auto := $&m.option_auto
        option_auto.dispose()
        option_manual := $&m.option_manual
        option_manual.dispose()
        option_locked := $&m.option_locked
        option_locked.dispose()
        list_label := $&m.list_label
        list_label.dispose()
        list_2_label := $&m.list_2_label
        list_2_label.dispose()
        list_3_label := $&m.list_3_label
        list_3_label.dispose()
        list_4_label := $&m.list_4_label
        list_4_label.dispose()
        input := $&m.input
        input.dispose()
        invalid := $&m.invalid
        invalid.dispose()
        read_only := $&m.read_only
        read_only.dispose()
        area := $&m.area
        area.dispose()
    }
    fn leaf(view $&widgets.View, parent int, width f64, height f64) int {
        style := layout.box_style(layout.BOX_LEAF)
        << view.add(parent, &style, &layout.Size{width: width, height: height}) >>>
    }
    fn brand_scope(view $&widgets.View) int {
        $brand := widgets.light_styles()
        brand.button.palette.normal = draw.rgb(10, 91, 69)
        brand.button.palette.hovered = draw.rgb(17, 120, 90)
        brand.button.palette.pressed = draw.rgb(7, 65, 49)
        brand.button.palette.foreground = draw.rgb(255, 255, 255)
        brand.button.font.size = 17.0
        brand.button.font.weight = 600
        brand.button.inherit_font = false
        brand.button.radius = 18.0
        brand.button.icon_size = 22.0
        brand.button.icon_placement = widgets.ICON_TRAILING
        $hover := widgets.state_paint(widgets.STATE_HOVERED)
        hover.unless = widgets.STATE_DISABLED
        hover.fields = widgets.PAINT_FOREGROUND | widgets.PAINT_BORDER
        hover.foreground = draw.rgb(209, 250, 229)
        hover.border = draw.rgb(110, 231, 183)
        brand.button.states =[hover]
        brand.button.shadow = draw.rgba(0, 0, 0, 28)
        brand.button.shadow_y = 2.0
        brand.button.shadow_blur = 6.0
        view.set_style_scope(8, &brand) >>>
        << 0
    }
    fn scene(ech chan ui.Event) int {
        ready := demo.ready(ech) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        identity := ui.canvas_of(&ready) >>>
        context := draw.context_of(&ready) >>>
        host := widgets.Host{context: context, identity: identity}
        $column := layout.box_style(layout.BOX_COLUMN)
        column.padding = layout.insets(22.0) >>>
        column.gap = 10.0
        column.cross_alignment = layout.CROSS_STRETCH
        $view := host.view(&column, draw.rgb(20, 25, 34)) >>>
        _ := leaf($&view, 1, 400.0, 56.0) >>>  // 2 header
        $row := layout.box_style(layout.BOX_ROW)
        row.gap = 12.0
        row.cross_alignment = layout.CROSS_CENTER
        _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 3 toolbar
        for i in 0:3 {_ := leaf($&view, 3, 0.0, 0.0) >>> }  // 4..6
        _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 7 controls
        for i in 0:3 {_ := leaf($&view, 7, 0.0, 0.0) >>> }  // 8..10
        _ := leaf($&view, 1, 300.0, 12.0) >>>  // 11 progress
        for i in 0:4 {_ := leaf($&view, 1, 300.0, 0.0) >>> }  // 12..15 editors
        $viewport := layout.box_style(layout.BOX_COLUMN)
        viewport.height = 84.0
        viewport.clip = true
        viewport.cross_alignment = layout.CROSS_STRETCH
        _ := view.add(1, &viewport, &layout.Size{width: 0.0, height: 0.0}) >>>  // 16 scroll
        $items := layout.box_style(layout.BOX_COLUMN)
        items.gap = 6.0
        items.cross_alignment = layout.CROSS_STRETCH
        _ := view.add(16, &items, &layout.Size{width: 0.0, height: 0.0}) >>>  // 17 items
        for i in 0:12 {_ := leaf($&view, 17, 300.0, 28.0) >>> }  // 18..29
        _ := leaf($&view, 1, 400.0, 42.0) >>>  // 30 footer
        _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 31 extended controls row 1
        for i in 0:6 {_ := leaf($&view, 31, 0.0, 0.0) >>> }  // 32..37: switch, radio_a, radio_b, slider, stepper, badge
        _ := leaf($&view, 1, 300.0, 0.0) >>>  // 38 labeled divider
        _ := view.add(1, &row, &layout.Size{width: 0.0, height: 0.0}) >>>  // 39 extended controls row 2
        for i in 0:4 {_ := leaf($&view, 39, 0.0, 0.0) >>> }  // 40..43: tabs, select, card, list_box
        for id in[2, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 30, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43] {view.set_boundary(id, true) >>> }
        for id in[4, 5, 6, 8, 10, 12, 13, 14, 15, 16, 32, 33, 34, 35, 36, 40, 41, 43] {view.set_input(id, true, true) >>> }
        view.set_capture_outside(16, true) >>>
        view.set_capture_outside(35, true) >>>
        for id in[4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43] {view.set_style_measure(id, true) >>> }
        empty := layout.Rect{x: 0.0, y: 0.0, width: 0.0, height: 0.0}
        $m := Model{theme: widgets.button(&identity, 4, &empty) >>>, scale: widgets.button(&identity, 5, &empty) >>>,
            density: widgets.button(&identity, 6, &empty) >>>, brand: widgets.button(&identity, 8, &empty) >>>,
            disabled: widgets.button(&identity, 9, &empty) >>>, check: widgets.checkbox(&identity, 10, &empty, true) >>>,
            toggle: widgets.switch_control(&identity, 32, &empty, true) >>>,
            radio_a: widgets.radio(&identity, 33, &empty, 0, true) >>>,
            radio_b: widgets.radio(&identity, 34, &empty, 1, false) >>>,
            slider: widgets.slider(&identity, 35, &empty, 0.0, 100.0, 64.0) >>>,
            stepper: widgets.stepper(&identity, 36, &empty, 0.0, 100.0, 5.0, 65.0) >>>,
            tabs: widgets.tabs(&identity, 40, &empty, 3, 0) >>>,
            select_ctrl: widgets.select_box(&identity, 41, &empty, 3, 0) >>>,
            select_origin: empty, select_popup_armed: false,
            transitions:[]widgets.PaintTransition{}, switch_motion: widgets.tween(1.0) >>>, popup_motion: widgets.tween(0.0) >>>,
            clock: time.zero_instant(), reduced_motion: false, theme_index: 0, text_scale: 1.0, density_scale: 1.0, appearance_dirty: true,
            badge: widgets.badge(&empty) >>>,
            divider: widgets.divider(&empty, widgets.AXIS_HORIZONTAL) >>>,
            card: widgets.card(&empty) >>>,
            list: widgets.list_box(&identity, 43, &empty, 4, 0) >>>,
            input: widgets.input(&context, &identity, 12, &empty, &"Editable input · 你好 Xu") >>>,
            invalid: widgets.input(&context, &identity, 13, &empty, &"Invalid value — custom error colors") >>>,
            read_only: widgets.input(&context, &identity, 14, &empty, &"Read-only · select and copy, edits are ignored") >>>,
            area: widgets.text_area(&context, &identity, 15, &empty, &"TextArea uses the same font, padding and selection theme.\nIME, preedit and caret geometry follow typography changes.") >>>,
            progress: widgets.progress(&empty, 0.64) >>>, scroll: widgets.scroll(&identity, 16, &empty, widgets.AXIS_VERTICAL, 402.0) >>>,
            context: context, icon: context.load_embedded_image(&"logo.png") >>>, switcher: widgets.style_switcher(),
            theme_label: widgets.styled_label(&context, &"Theme: dark / light / contrast"),
            scale_label: widgets.styled_label(&context, &"Text: 100% / 140%"),
            density_label: widgets.styled_label(&context, &"Density: normal / compact"),
            brand_label: widgets.styled_label(&context, &"Local green"),
            disabled_label: widgets.styled_label(&context, &"Disabled"),
            check_label: widgets.styled_label(&context, &"Checkbox"),
            toggle_label: widgets.styled_label(&context, &"Switch"),
            radio_a_label: widgets.styled_label(&context, &"Radio A"),
            radio_b_label: widgets.styled_label(&context, &"Radio B"),
            stepper_label: widgets.styled_label(&context, &"65"),
            badge_label: widgets.styled_label(&context, &"Active"),
            divider_label: widgets.styled_label(&context, &"Navigation & Data Components"),
            card_label: widgets.styled_label(&context, &"Card Panel"),
            tab_label: widgets.styled_label(&context, &"Overview"),
            tab_2_label: widgets.styled_label(&context, &"Tokens"),
            tab_3_label: widgets.styled_label(&context, &"Themes"),
            select_label: widgets.styled_label(&context, &"Option: Auto"),
            option_auto: widgets.styled_label(&context, &"Auto"),
            option_manual: widgets.styled_label(&context, &"Manual"),
            option_locked: widgets.styled_label(&context, &"Locked"),
            list_label: widgets.styled_label(&context, &"1 · Buttons"),
            list_2_label: widgets.styled_label(&context, &"2 · Editors"),
            list_3_label: widgets.styled_label(&context, &"3 · Surfaces"),
            list_4_label: widgets.styled_label(&context, &"4 · Controls")}
        for i in 0:44 {m.transitions.push(widgets.paint_transition() >>>)}
        for id in[4, 5, 6, 8, 10, 32, 33, 34, 36, 40, 41, 43] {view.set_cursor(id, ui.CURSOR_HAND) >>> }
        for id in[12, 13, 14, 15] {view.set_cursor(id, ui.CURSOR_TEXT) >>> }
        view.set_cursor(35, ui.CURSOR_RESIZE_HORIZONTAL) >>>
        badge_ref := $&m.badge
        badge_ref.set_selected(true)
        disabled := $&m.disabled
        disabled.set_enabled(false)
        invalid := $&m.invalid
        invalid.set_invalid(true)
        read_only := $&m.read_only
        read_only.set_read_only(true) >>>
        apply_appearance($&m, $&view) >>>
        brand_scope($&view) >>>
        dispatcher := register_actions(&m, &view) >>>
        $width := 960.0
        $height := 820.0
        $event := ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
        // Drain input bursts before painting. Native text snapshots already hold
        // the latest revision; rendering each queued key would fill the frame queue.
        ui.request_canvas_preferences(&identity) >>>
        while true {
            if event.kind == ui.EV_NONE{
                apply_appearance($&m, $&view) >>>
                m.tick($&view, time.instant()) >>>
                constraints := layout.tight(width, height) >>>
                _ := widgets.layout_styled($&view, &constraints, $&m) >>>
                m.place($&view) >>>
                if widgets.present_styled($&view, &constraints, $&m) >>> {m.acknowledge()}
                event = m.next_event(ech)
            }
            if event.kind == ui.EV_EXIT{ <- }
            if event.window_id == identity.window_id{
                if event.kind == ui.EV_CANVAS_CLOSED || event.kind == ui.EV_CLOSED{ <- }
                if event.kind == ui.EV_CANVAS_METRICS{metrics := ui.metrics_of(&event) >>>
                    width = metrics.width
                    height = metrics.height}
                if event.kind == ui.EV_FOCUSED{ui.request_canvas_preferences(&identity) >>> }
                if event.kind == ui.EV_CANVAS_PREFERENCES{
                    preferences := ui.canvas_preferences_of(&event) >>>
                    if preferences.identity.canvas_id == identity.canvas_id && preferences.identity.generation == identity.generation{
                        m.reduced_motion = preferences.reduced_motion
                        view.mark_paint(1) >>>
                    }
                }
                popup_was_open := m.select_ctrl.is_open()
                actions := m.dispatch_event($&view, &event) >>>
                m.native_event($&view, &event) >>>
                for action in actions{_ := dispatcher.dispatch(&action, $&m, $&view) >>> }
                if ui.is_input_event(event.kind) {input := ui.input_of(&event) >>>
                    if input.kind == ui.EV_KEY_DOWN && input.key == ui.KEY_ESCAPE && !popup_was_open{
                        view.dispose()
                        if demo.alive(&identity) {m.cleanup()}
                        demo.quit() >>>
                        << 0
                    }}
            }
            event = ui.poll_chan(ech)
        }
        view.dispose()
        if demo.alive(&identity) {m.cleanup()}
        << 0
    }
    fn worker(ech chan ui.Event) {scene(ech) >>> (err) {demo.fail(err.msg())
            << }}
    fn main() int {
        $app := demo.app("Xu UI / Style Gallery", 960, 820) >>> (err) {eprintln(err.msg())
            << 1}
        xu worker(app.event_ch)
        << app.run() >>> (err) {eprintln(err.msg())
            << 1}
    }
  • 16_ui_webview/component_workshop/main.xu

    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) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        $screen := widgets.screen(&ready) >>>
        screen.resize(1180.0, 900.0) >>> (err) {screen.dispose()
            >> err}
        screen.set_min_size(920, 780) >>> (err) {screen.dispose()
            >> err}
        $model := create($&screen) >>> (err) {screen.dispose()
            >> err}
        workshop_loop(events, $&model, $&screen) >>> (err) {screen.dispose()
            >> err}
        screen.dispose()
        << 0
    }
    
    fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
            << }}
    
    fn launch() int {
        $app := demo.app("XUUI / Component Workshop", 1180, 900) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    
    fn main() int { << launch() >>> (err) {eprintln(err.msg())
            << 1}}
    
    fn next_event(events chan ui.Event, deadline time.Instant) ui.Event{
        if deadline.is_zero() { << <- events}
        delay := deadline.since(time.instant())
        if delay.nanoseconds() <= 0 { << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}}
        timer := delay.timer()
        select {event := <- events{timer.stop()
                << event}
            _ := <- timer.c{timer.stop()}}
        << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
    }
    
    fn workshop_loop(events chan ui.Event, model $&Workshop, screen $&widgets.Screen) int {
        model.apply_locale(screen) >>>
        screen.set_text(model.title, "XUUI  /  Field") >>>
        model.configure_controls(screen) >>>
        model.controls_dirty = false
        model.apply_appearance(screen) >>>
        model.appearance_dirty = false
        $dispatcher := register_events(& * model, & * screen) >>>
        model.layout(screen) >>>
        while screen.is_open() {
            register_notice_events(& * screen, $&dispatcher) >>>
            now := time.instant()
            model.work(screen, now) >>>
            if model.controls_dirty{model.configure_controls(screen) >>>
                model.controls_dirty = false}
            if model.appearance_dirty{model.apply_appearance(screen) >>>
                model.appearance_dirty = false}
            model.apply_page_options(screen) >>>
            model.layout(screen) >>>
            $deadline := screen.advance(now) >>>
            $timed_actions := false
            for action in screen.take_actions() {
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) >>>
                timed_actions = true
            }
            // Reconcile timer-driven values/styles before computing the next wait.
            if timed_actions{ -> }
            _ := screen.render() >>>
            if model.running &&(deadline.is_zero() || model.deadline.before(deadline)) {deadline = model.deadline}
            event := next_event(events, deadline) >>>
            $actions := screen.event(&event) >>>
            $count := 0
            while screen.is_open() && count < 128 {pending := ui.poll_chan(events)
                if pending.kind == ui.EV_NONE{ <- }
                more := screen.event(&pending) >>>
                for action in more{actions.push(action)}
                count += 1}
            for action in actions{register_notice_events(& * screen, $&dispatcher) >>>
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) >>> }
        }
        << 0
    }
    Xustyle.xu
    @main
    
    #ui/widgets
    #ui/chart
    #ui/draw
    #ui/layout
    #time
    
    fn read_only(index int) bool { << index >= 38 ||(index >= 1 && index <= 26 && index != 8 && index != 25 && index != 26)}
    
    fn invalid(index int) bool { << index >= 40 || index >= 1 && index <= 30 && index != 7 && index != 8 && index != 12 && index != 24 && index != 25 && index != 26 && index != 28}
    
    fn animated(index int) bool { <<(index >= 38 && index <= 44) || index == 1 || index == 2 || index == 5 || index == 6 || index == 7 || index == 8 || index == 9 || index == 10 || index == 11 || index == 25}
    
    fn appearance(styles &widgets.Styles, index int) widgets.ControlStyle{
        if index == 0 {$c := styles.input.clone()
            c.padding = layout.Insets{left: 0.0, top: 0.0, right: 0.0, bottom: 0.0}
            c.align_x = 0.0
            c.align_y = 0.0
            << c}
        if index == 7 { << styles.tree_style()}
        if index == 24 { << styles.table_style()}
        if index == 9 || index == 10 || index == 11 || index == 12 { << styles.checkbox.clone()}
        if index == 3 || index == 5 || index == 45 { << styles.input.clone()}
        if index == 4 || index == 6 { << styles.text_area.clone()}
        if index == 13 || index == 40 { << styles.slider_style()}
        if index == 41 { << styles.card_style()}
        if index == 14 { << styles.stepper_style()}
        if index == 15 { << styles.select_style()}
        if index == 21 || index == 22 { << styles.tabs_style()}
        if index == 23 { << styles.list_box_style()}
        if index == 27 { << styles.progress.clone()}
        if index == 29 { << styles.divider_style()}
        if index == 30 { << styles.badge_style()}
        if index == 31 { << styles.card_style()}
        if index == 32 { << styles.scroll.clone()}
        << styles.button.clone()
    }
    
    fn (m $&Workshop) apply_appearance(s $&widgets.Screen) int {
        theme := s.selected(m.theme) >>>
        density := s.selected(m.density) >>>
        scale := s.selected(m.scale) >>>
        preset :=[widgets.THEME_LIGHT, widgets.THEME_DARK, widgets.THEME_CONTRAST][theme]
        $styles := widgets.preset_styles(preset) >>>
        styles.density =[1.0, 0.85, 1.25][density]
        styles.text_scale =[1.0, 1.4, 2.0][scale]
        sheet := widgets.screen_appearance(&styles, s.toggle_value(m.reduced) >>>) >>>
        s.apply_appearance(&sheet) >>>
        position := m.selected
        pages := &m.pages
        page := &pages[position]
        id := page.ids[0]
        if m.selected == 30 {$avatar := styles.button_variant(widgets.BUTTON_SUBTLE) >>>
            avatar.radius = 999.0
            s.set_control_style(page.ids[2], &avatar) >>> }
        if m.selected <= 32 || m.selected >= 40 {
            s.clear_control_style(id) >>>
            if m.customized{$c := appearance(&styles, m.selected)
                c.radius = 14.0
                c.border_width = 1.5
                c.padding.left += 4.0
                c.padding.right += 4.0
                s.set_control_style(id, &c) >>> }
        }
        $spec := widgets.motion_spec()
        if m.slow{spec.change = time.milliseconds(420) >>>
            spec.hover = time.milliseconds(320) >>>
            spec.enter = time.milliseconds(360) >>>
            spec.exit = time.milliseconds(240) >>>
            spec.curve = widgets.EASE_OUT_QUINT}
        if animated(m.selected) {s.set_motion(id, &spec) >>> }
        if m.selected == 1 {
            handles :=[page.ids[0], page.ids[1], page.ids[2], page.ids[3]]
            placements :=[widgets.ICON_LEADING, widgets.ICON_TRAILING, widgets.ICON_ABOVE, widgets.ICON_BELOW]
            english := (s.selected(m.language) >>>) == 1
            for i in 0:4 {
                icon_size := s.number_value(page.ids[9 + i]) >>>
                $icon_prefix := "图标 · "
                if english {icon_prefix = "Icon · "}
                s.set_text(page.ids[13 + i], icon_prefix + str(int(icon_size)) + " px") >>>
                $c := styles.button_variant(widgets.BUTTON_OUTLINE) >>>
                if i == 0 {c = styles.button_variant(widgets.BUTTON_PRIMARY) >>> }
                c.icon_placement = placements[i]
                c.icon_size = icon_size * styles.text_scale
                if m.customized{c.radius = 14.0
                    c.border_width = 1.5}
                s.set_control_style(handles[i], &c) >>>
                s.set_motion(handles[i], &spec) >>>
            }
        }
        if m.selected == 33 || m.selected == 34 || m.selected == 36 {s.set_motion(page.ids[1], &spec) >>>
            $c := styles.overlay_style()
            if m.customized{c.radius = 18.0
                c.border_width = 2.0}
            s.set_control_style(page.ids[1], &c) >>> }
        if m.selected == 34 {
            $placement := widgets.overlay_placement()
            placement.side = m.tooltip_side
            placement.align = widgets.OVERLAY_CENTER
            s.set_tooltip_placement(page.ids[1], &placement) >>>
        }
        if m.selected == 35 {
            s.set_notice_motion(&spec) >>>
            if m.customized{$c := styles.overlay_style()
                c.radius = 18.0
                c.border_width = 2.0
                s.set_notice_style(&c) >>> }
            else {s.clear_notice_style() >>> }
        }
        if m.selected == 38 {
            $group_appearance := widgets.button_group_appearance()
            group_appearance.vertical = m.group_vertical
            group_appearance.joined = m.group_joined
            for i in 0:3 {s.set_button_group_appearance(page.ids[i], &group_appearance) >>>
                s.clear_control_style(page.ids[i]) >>>
                s.set_motion(page.ids[i], &spec) >>>
                if m.customized{$c := styles.button_variant(widgets.BUTTON_OUTLINE) >>>
                    c.radius = 12.0
                    c.border_width = 1.5
                    s.set_control_style(page.ids[i], &c) >>> }}
        }
        if m.selected == 39 {
            s.clear_control_style(id) >>>
            $appearance := chart.chart_appearance()
            appearance.y_unit = " ms"
            if m.chart_kind == widgets.CHART_DONUT || m.chart_kind == widgets.CHART_PIE || m.chart_kind == widgets.CHART_ROSE ||
               m.chart_kind == widgets.CHART_FUNNEL || m.chart_kind == widgets.CHART_TREEMAP || m.chart_kind == widgets.CHART_SANKEY{appearance.y_unit = ""}
            else if m.chart_kind == widgets.CHART_GAUGE || m.chart_kind == widgets.CHART_POLAR_BAR{appearance.y_unit = "%"}
            if m.customized{appearance.grid = false
                appearance.area_opacity = 0.26
                appearance.inner_radius = 0.78
                appearance.palette =[draw.rgb(41, 126, 178), draw.rgb(215, 146, 42), draw.rgb(56, 153, 124)]
                $c := styles.card_style()
                c.radius = 18.0
                s.set_control_style(id, &c) >>> }
            s.set_chart_appearance(id, &appearance) >>>
            $options := widgets.animation_options()
            options.duration = time.milliseconds(650) >>>
            options.curve = widgets.EASE_IN_OUT_CUBIC
            if m.slow{options.duration = time.milliseconds(1200) >>> }
            s.set_chart_animation(id, &options) >>>
            if m.chart_paused{s.pause_chart_animation(id) >>> }
        }
        if m.selected == 40 {
            $options := widgets.range_slider_options()
            options.step = 5.0
            options.min_distance = 10.0
            if m.range_push{options.collision = widgets.RANGE_PUSH}
            options.vertical = m.range_vertical
            options.commit_only = m.range_commit
            s.set_range_options(id, &options) >>>
            $appearance := widgets.slider_appearance()
            appearance.ticks = 11
            appearance.show_value = true
            s.set_range_appearance(id, &appearance) >>>
        }
        if m.selected == 41 {
            $options := widgets.split_view_options()
            options.vertical = m.split_vertical
            options.minimum_first = 120.0 * styles.text_scale
            options.minimum_second = 140.0 * styles.text_scale
            s.set_split_options(id, &options) >>>
        }
        if m.selected >= 42 && m.selected <= 44 {
            $appearance := widgets.menu_appearance()
            appearance.close_on_select = !m.menu_stays_open
            s.set_menu_appearance(id, &appearance) >>>
        }
        if m.selected == 37 {$radius := 8.0
            if m.customized{radius = 18.0}
            s.set_webview_radius(id, radius) >>> }
        << 0
    }
    
    // Business handlers set option flags. Appearance changes run only here.
    fn (m $&Workshop) apply_page_options(s $&widgets.Screen) int {
        if m.tree_options_dirty{
            $appearance := widgets.tree_appearance()
            appearance.guides = m.guided
            s.set_tree_appearance(m.pages[7].ids[0], &appearance) >>>
            m.tree_options_dirty = false
        }
        if m.field_options_dirty{
            $decoration := widgets.field_decoration(&"Project name 项目名称")
            decoration.variant =(m.variant - 1) % 3
            decoration.floating =(m.variant - 1) % 4
            decoration.helper = "Floating / fixed label and stable helper area"
            decoration.error = "Please enter a valid name."
            decoration.clearable = true
            s.set_field_decoration(m.pages[m.field_options_page].ids[0], &decoration) >>>
            m.field_options_dirty = false
        }
        if m.spinner_options_dirty{
            s.set_spinner_appearance(m.pages[28].ids[0], 48.0, 4.0, time.milliseconds(1200) >>>) >>>
            m.spinner_options_dirty = false
        }
        if m.popover_options_dirty{
            $placement := widgets.overlay_placement()
            placement.side = m.variant
            placement.align = widgets.OVERLAY_CENTER
            s.set_popover_placement(m.pages[33].ids[1], &placement) >>>
            m.popover_options_dirty = false
        }
        << 0
    }
    Xuview.xu
    @main
    
    #ui
    #ui/widgets
    #ui/chart
    #ui/draw
    #time
    #math
    
    fn names()[]string { << names_locale(true) }
    
    fn names_locale(english bool)[]string {
        if english {
            <<["StyledLabel", "Button", "IconButton", "Input", "TextArea", "Field", "FieldArea", "TreeView", "TaskButton", "Checkbox", "Switch", "Radio", "RadioGroup", "Slider", "Stepper", "Select", "ComboBox", "MultiSelect", "DatePicker", "TimePicker", "ColorPicker", "Tabs", "Segmented", "ListBox", "Table", "Pagination", "Breadcrumbs", "Progress", "Spinner", "Divider", "Badge", "Card", "Scroll", "Popover", "Tooltip", "ToastHost", "Modal", "WebView", "ButtonGroup", "Chart", "RangeSlider", "SplitView", "Menu", "ContextMenu", "SplitButton", "PasswordInput"]
        }
        <<["StyledLabel 文本", "Button 按钮", "IconButton 图标按钮", "Input 单行输入", "TextArea 多行输入", "Field 表单字段", "FieldArea 多行字段", "TreeView 树形视图", "TaskButton 任务按钮", "Checkbox 复选框", "Switch 开关", "Radio 单选框", "RadioGroup 单选组", "Slider 滑块", "Stepper 步进器", "Select 下拉选择", "ComboBox 组合框", "MultiSelect 多选框", "DatePicker 日期选择", "TimePicker 时间选择", "ColorPicker 颜色选择", "Tabs 标签页", "Segmented 分段控件", "ListBox 列表框", "Table 数据表格", "Pagination 分页器", "Breadcrumbs 面包屑", "Progress 进度条", "Spinner 加载指示", "Divider 分割线", "Badge 徽标", "Card 卡片", "Scroll 滚动容器", "Popover 气泡浮层", "Tooltip 文字提示", "ToastHost 通知队列", "Modal 模态弹窗", "WebView 网页视图", "ButtonGroup 按钮组", "Chart 图表", "RangeSlider 区间滑块", "SplitView 分栏视图", "Menu 下拉菜单", "ContextMenu 右键菜单", "SplitButton 拆分按钮", "PasswordInput 密码框"]
    }
    
    fn new_page(s $&widgets.Screen, index int) Page{
        group := s.group() >>>
        $ids :=[]int {}
        choices :=["Workspace 工作区", "History 历史", "Output 输出"]
        if index == 0 {ids.push(s.label("清晰的层级,让每个细节都服务于使用。\n中文、English 与 emoji 👩🏽‍💻 都使用原生排版。", 20.0, false) >>>)
            s.set_label_wrapped(ids[0], true) >>>
            ids.push(s.label("很长的完整内容:Cluster-safe truncation · 👨‍👩‍👧‍👦 family · workspace / widgets / component.xu", 16.0, false) >>>)
            s.set_label_ellipsis(ids[1], true) >>>
            anchor := ids[1]
            ids.push(s.tooltip(anchor, "很长的完整内容:Cluster-safe truncation · 👨‍👩‍👧‍👦 family · workspace / widgets / component.xu") >>>)}
        if index == 1 {
            $sizes :=[]int {}
            $labels :=[]int {}
            for text in["Build project", "Open workspace · trailing", "Save changes · above", "Download SDK · below"] {
                // Each inspector precedes its own button in both layout and Tab order.
                inspector := s.stepper(12.0, 64.0, 4.0, 24.0) >>>
                sizes.push(inspector)
                _ := s.tooltip(inspector, text + " · Icon size 图标尺寸 (px)") >>>
                labels.push(s.label("Icon 图标 · 24 px", 14.0, true) >>>)
                ids.push(s.button_with_icon("logo.png", text) >>>)}
            for text in["Secondary", "Outline", "Ghost", "Danger", "Subtle"] {ids.push(s.button(text) >>>)}
            s.set_button_variant(ids[0], widgets.BUTTON_PRIMARY) >>>
            for variant in 1:6 {s.set_button_variant(ids[variant + 3], variant) >>> }
            for id in sizes{ids.push(id)}
            for id in labels{ids.push(id)}}
        if index == 2 {ids.push(s.icon_button("logo.png", "Open XU workspace") >>>)
            anchor := ids[0]
            ids.push(s.tooltip(anchor, "Open XU workspace · Enter") >>>)}
        if index == 3 {ids.push(s.input("中文 / English / 🙂") >>>)}
        if index == 4 {ids.push(s.text_area("Native text editing\n选择文字、复制、粘贴,保留输入法会话。\n👩🏽‍💻 family 👨‍👩‍👧‍👦") >>>)}
        if index == 5 || index == 6 {
            $decoration := widgets.field_decoration(&"Project name 项目名称")
            decoration.helper = "Enter a name · Native IME / selection / clipboard"
            decoration.error = "名称不能为空。Please enter a project name."
            decoration.clearable = true
            if index == 5 {decoration.prefix = "xu /"
                ids.push(s.field("", &decoration) >>>)}
            else {ids.push(s.text_field_area("Build notes\n中文与 emoji 🙂", &decoration) >>>)}
            $options := widgets.field_text_options()
            options.counter = true
            options.character_limit = 32
            if index == 6 {options.min_rows = 3
                options.max_rows = 6}
            s.set_field_text_options(ids[0], &options) >>>
        }
        if index == 7 {
            ids.push(s.tree() >>>)
            root := s.tree_add(ids[0], - 1, "XU workspace") >>>
            src := s.tree_add(ids[0], root, "src") >>>
            widgets_node := s.tree_add(ids[0], src, "widgets") >>>
            for name in["tree_view.xu", "task_button.xu", "field.xu", "screen.xu"] {leaf := s.tree_add(ids[0], widgets_node, name) >>>
                s.set_tree_metadata(ids[0], leaf, "Xu") >>>
                s.set_tree_action(ids[0], leaf, true) >>> }
            _ := s.tree_add(ids[0], root, "xu.xun") >>>
            for node in[root, src, widgets_node] {s.set_expanded(ids[0], node, true) >>> }
            $appearance := widgets.tree_appearance()
            appearance.guides = true
            s.set_tree_appearance(ids[0], &appearance) >>>
            $decoration := widgets.field_decoration(&"Find a node")
            decoration.clearable = true
            ids.push(s.field("", &decoration) >>>)
        }
        if index == 8 {ids.push(s.task_button("Build project") >>>)
            s.set_task_labels(ids[0], "Building", "Built · run again", "Retry build", "Build again") >>> }
        if index == 9 {ids.push(s.checkbox("Keep generated files 保留产物", true) >>>)}
        if index == 10 {ids.push(s.switch_control("Live preview 实时预览", true) >>>)}
        if index == 11 {ids.push(s.radio("Use workspace settings", 1, true) >>>)}
        if index == 12 {ids.push(s.radio_group(&choices, 0) >>>)}
        if index == 13 {ids.push(s.slider(0.0, 100.0, 40.0) >>>)
            $appearance := widgets.slider_appearance()
            appearance.ticks = 11
            appearance.show_value = true
            s.set_slider_appearance(ids[0], &appearance, 10.0) >>>
            s.set_slider_commit_only(ids[0], true) >>>
            $decoration := widgets.field_decoration(&"Exact value / 精确数值")
            decoration.helper = "0–100 · step 10 · Apply input"
            decoration.error = "Enter a number between 0 and 100."
            ids.push(s.field("40", &decoration) >>>)}
        if index == 14 {ids.push(s.stepper(0.0, 100.0, 1.0, 24.0) >>>)
            s.set_stepper_repeat(ids[0], true, time.milliseconds(400) >>>, time.milliseconds(80) >>>) >>> }
        if index == 15 {$unavailable := widgets.select_option("Remote (unavailable)")
            unavailable.enabled = false
            options :=[widgets.select_group("LOCAL"), widgets.select_option("Workspace 工作区"), widgets.select_option("History 历史"), widgets.select_group("REMOTE"), unavailable]
            ids.push(s.select_options(&options, 1) >>>)}
        if index == 16 {ids.push(s.combo_box(&choices, "") >>>)
            s.set_combo_custom_values(ids[0], false) >>> }
        if index == 17 {ids.push(s.multi_select(&choices) >>>)
            $decoration := widgets.field_decoration(&"Filter options")
            decoration.clearable = true
            ids.push(s.field("", &decoration) >>>)}
        if index == 18 || index == 19 {value := time.date(2026, 10, 25, 14, 30, 0, 0)
            if index == 18 {ids.push(s.date_picker(value) >>>)
                s.set_date_options(ids[0], value, true) >>> }
            else {ids.push(s.time_picker(value) >>>)
                s.set_clock_format(ids[0], true, true) >>> }}
        if index == 20 {ids.push(s.color_picker(draw.rgb(180, 57, 45)) >>>)
            s.set_color_swatches(ids[0], &[draw.rgb(180, 57, 45), draw.rgb(50, 121, 160), draw.rgb(72, 130, 90)]) >>>
            $decoration := widgets.field_decoration(&"HEX / RGBA")
            decoration.helper = "#RGB, #RGBA, #RRGGBB, #RRGGBBAA"
            decoration.error = "Use a valid HEX value."
            ids.push(s.field("#B4392DFF", &decoration) >>>)}
        if index == 21 {ids.push(s.tabs(&choices, 0) >>>)
            s.set_tab_behavior(ids[0], &[180.0, 144.0, 160.0], false) >>> }
        if index == 22 {ids.push(s.segmented(&["Day", "Week", "Month"], 0) >>>)}
        if index == 23 {ids.push(s.list_box(&["TreeView", "TaskButton", "Field", "Table", "WebView", "Scroll", "Tabs", "Select", "ToastHost"], 0) >>>)
            for row in 0:9 {$detail := widgets.list_row(["TreeView", "TaskButton", "Field", "Table", "WebView", "Scroll", "Tabs", "Select", "ToastHost"][row])
                detail.description = "Native component · 原生交互"
                detail.detail = "Ready"
                detail.icon = widgets.TREE_ICON_FILE
                s.set_list_row(ids[0], row, &detail) >>> }}
        if index == 24 {ids.push(s.table(&["Component", "Build ms", "Status"], 12, 0) >>>)
            components :=["Button", "TreeView", "Field", "Input", "Tabs", "Checkbox", "Switch", "Menu", "WebView", "Chart", "Table", "Badge"]
            durations :=[14, 7, 120, 3, 21, 7, 45, 9, 210, 32, 18, 2]
            for row in 0:12 {s.set_cell(ids[0], row, 0, components[row]) >>>
                s.set_cell(ids[0], row, 1, str(durations[row])) >>>
                s.set_cell(ids[0], row, 2,["Ready", "Review", "Draft"][row % 3]) >>> }
            s.set_table_sort_kind(ids[0], 1, widgets.TABLE_SORT_NUMBER) >>>
            s.set_table_column_min_width(ids[0], 0, 160.0) >>>
            s.set_table_column(ids[0], 0, 280.0, 0.0) >>>
            s.set_table_column(ids[0], 1, 160.0, 1.0) >>>
            s.set_table_column(ids[0], 2, 200.0, 0.0) >>> }
        if index == 25 {ids.push(s.pagination(1000, 122) >>>)
            s.set_pagination_data(ids[0], 20000, 20) >>>
            $decoration := widgets.field_decoration(&"Page 页码")
            decoration.helper = ""
            decoration.error = ""
            decoration.reserve_helper = false
            decoration.floating = widgets.LABEL_ALWAYS
            ids.push(s.field("123", &decoration) >>>)
            ids.push(s.select_box(&["10 / page", "20 / page", "50 / page", "100 / page"], 1) >>>)
            ids.push(s.label("", 14.0, true) >>>)
            s.set_label_wrapped(ids[3], true) >>>
            ids.push(s.button("Go 跳转") >>>)
            ids.push(s.label("", 13.0, true) >>>)
            s.set_label_wrapped(ids[5], true) >>> }
        if index == 26 {ids.push(s.breadcrumbs(&["Home", "XU workspace", "src", "ui", "widgets", "A long Chinese path 中文路径", "field.xu"]) >>>)}
        if index == 27 {ids.push(s.progress(0.42) >>>)
            s.set_progress_buffer(ids[0], 0.72) >>> }
        if index == 28 {ids.push(s.spinner() >>>)
            s.set_spinner_appearance(ids[0], 32.0, 3.0, time.milliseconds(900) >>>) >>>
            s.set_running(ids[0], true) >>>
            ids.push(s.label("Loading assets… 正在加载", 14.0, true) >>>)}
        if index == 29 {ids.push(s.divider(widgets.AXIS_HORIZONTAL) >>>)
            ids.push(s.label("SECTION / 章节", 12.0, true) >>>)}
        if index == 30 {
            inbox := s.button("Inbox 收件箱") >>>
            count := s.badge_on(inbox, "12", widgets.BADGE_COUNT) >>>
            s.set_badge_tone(count, widgets.BADGE_ERROR) >>>
            avatar := s.button("LW") >>>
            s.set_button_variant(avatar, widgets.BUTTON_SUBTLE) >>>
            dot := s.badge_on(avatar, "", widgets.BADGE_DOT) >>>
            s.set_badge_anchor(dot, avatar, 0.86, 0.86) >>>
            s.set_badge_tone(dot, widgets.BADGE_SUCCESS) >>>
            synced := s.badge("Synced 已同步") >>>
            s.set_badge_tone(synced, widgets.BADGE_SUCCESS) >>>
            beta := s.badge("BETA") >>>
            s.set_badge_tone(beta, widgets.BADGE_INFO) >>>
            ids =[count, inbox, avatar, dot, synced, beta,
            s.label("12 unread · 点击收件箱清零,徽标随数字收紧。", 14.0, true) >>>,
            s.label("林文 · Available 在线", 16.0, false) >>>,
            s.label("点击头像切换在线状态;状态点不单独承担文字含义。", 13.0, true) >>>,
            s.label("Workspace 工作区", 16.0, false) >>>]
        }
        if index == 31 {
            ids.push(s.card() >>>)
            sections := s.card_sections(ids[0], 36.0, 44.0) >>>
            for parent in[sections.header, sections.body, sections.footer] {ids.push(parent)}
            ids.push(s.label("Workspace configuration", 18.0, false) >>>)
            ids.push(s.label("Header, body and footer keep distinct spacing.\n正文区域随密度与字号调整。", 14.0, true) >>>)
            s.set_label_wrapped(ids[5], true) >>>
            ids.push(s.button("Open workspace") >>>)
            s.set_parent(ids[4], sections.header) >>>
            s.set_parent(ids[5], sections.body) >>>
            s.set_parent(ids[6], sections.footer) >>>
        }
        if index == 32 {ids.push(s.scroll_area(widgets.AXIS_VERTICAL, 1100.0) >>>)
            for row in 0:14 {id := s.button("Focusable row " + str(row + 1) + " · 滚动内容") >>>
                s.set_parent(id, ids[0]) >>>
                ids.push(id)}}
        if index >= 33 && index <= 36 {ids.push(s.button(["Open popover", "Focus or hover for help", "Enqueue notification", "Open confirmation"][index - 33]) >>>)
            anchor := ids[0]
            if index == 33 {
                ids.push(s.popover(anchor, "") >>>)
                ids.push(s.label("Workspace preferences", 18.0, false) >>>)
                ids.push(s.label("Edit a draft, then apply. Escape or clicking outside dismisses.\n编辑草稿后应用;关闭不会提交。", 13.0, true) >>>)
                s.set_label_wrapped(ids[3], true) >>>
                $decoration := widgets.field_decoration(&"Workspace name 工作区名称")
                decoration.clearable = true
                decoration.error = "名称不能为空 / Enter a name"
                ids.push(s.field("XU workspace", &decoration) >>>)
                ids.push(s.checkbox("Keep history 保留历史", true) >>>)
                ids.push(s.button("Cancel 取消") >>>)
                ids.push(s.button("Apply 应用") >>>)
                s.set_button_variant(ids[7], widgets.BUTTON_PRIMARY) >>>
                ids.push(s.label("Current: XU workspace · history on", 14.0, true) >>>)
                for i in 2:8 {s.set_parent(ids[i], ids[1]) >>> }
            }
            if index == 34 {ids.push(s.tooltip(anchor, "Hover waits 500 ms; keyboard focus shows help immediately.\n鼠标离开或点击收起;Escape 抑制重复提示。") >>>)}
            if index == 36 {ids.push(s.modal("Apply configuration?", "Focus stays inside this confirmation. Escape returns to the trigger.") >>>)
                ids.push(s.button("Cancel") >>>)
                ids.push(s.button("Apply changes") >>>)
                s.set_parent(ids[2], ids[1]) >>>
                s.set_parent(ids[3], ids[1]) >>> }
        }
        if index == 37 {ids.push(s.webview() >>>)
            s.load_web_html(ids[0], "<!doctype html><html><meta charset='utf-8'><style>body{font:16px system-ui;background:#f3f2ee;color:#292c30;padding:24px}input{font:inherit;padding:12px;border:1px solid #747b83;border-radius:6px;width:80%}h2{font-weight:500}</style><h2>WebView is a component.</h2><p>Native focus, clipping and independent lifecycle.</p><input aria-label='Web content' placeholder='中文 / English / 🙂'></html>") >>> }
        if index == 38 {
            actions :=[widgets.button_group_item(10, "Undo"), widgets.button_group_item(20, "Redo"), widgets.button_group_item(30, "Save")]
            group_choices :=[widgets.button_group_item(10, "Day"), widgets.button_group_item(20, "Week"), widgets.button_group_item(30, "Month")]
            formats :=[widgets.button_group_item(10, "Bold"), widgets.button_group_item(20, "Italic"), widgets.button_group_item(30, "Underline")]
            ids.push(s.button_group(&actions, widgets.BUTTON_GROUP_ACTIONS) >>>)
            ids.push(s.button_group(&group_choices, widgets.BUTTON_GROUP_SINGLE) >>>)
            ids.push(s.button_group(&formats, widgets.BUTTON_GROUP_MULTIPLE) >>>)
            ids.push(s.label("Actions / 独立操作", 12.0, true) >>>)
            ids.push(s.label("Single / 单选", 12.0, true) >>>)
            ids.push(s.label("Multiple / 多选", 12.0, true) >>>)
        }
        if index == 39 {
            ids.push(s.chart() >>>)
            row0 :=[widgets.button_group_item(1, "Line"), widgets.button_group_item(2, "Area"), widgets.button_group_item(3, "Bar"), widgets.button_group_item(4, "Scatter"), widgets.button_group_item(5, "Donut")]
            row1 :=[widgets.button_group_item(6, "Step"), widgets.button_group_item(7, "StackArea"), widgets.button_group_item(8, "StackBar"), widgets.button_group_item(9, "H-Bar"), widgets.button_group_item(10, "Pie")]
            row2 :=[widgets.button_group_item(11, "Rose"), widgets.button_group_item(12, "Radar"), widgets.button_group_item(13, "Gauge"), widgets.button_group_item(14, "Bubble"), widgets.button_group_item(15, "Histogram")]
            row3 :=[widgets.button_group_item(16, "Boxplot"), widgets.button_group_item(17, "Heatmap"), widgets.button_group_item(18, "Candle"), widgets.button_group_item(19, "Waterfall"), widgets.button_group_item(20, "Funnel")]
            row4 :=[widgets.button_group_item(21, "Spline"), widgets.button_group_item(22, "SplineArea"), widgets.button_group_item(23, "PolarBar"), widgets.button_group_item(24, "Treemap"), widgets.button_group_item(25, "Sankey")]
            row5 :=[widgets.button_group_item(26, "Violin"), widgets.button_group_item(27, "Bullet"), widgets.button_group_item(28, "Lollipop"), widgets.button_group_item(29, "Dumbbell"), widgets.button_group_item(30, "Pareto")]
            $selector := widgets.button_group_appearance()
            selector.equal_width = true
            selector.allow_empty = true
            rows :=[row0, row1, row2, row3, row4, row5]
            for r in 0:6 {
                gid := s.button_group(&rows[r], widgets.BUTTON_GROUP_SINGLE) >>>
                s.set_button_group_appearance(gid, &selector) >>>
                ids.push(gid)
            }
            series := chart_data(widgets.CHART_LINE, 0)
            s.set_chart_series(ids[0], &series) >>>
        }
        if index == 40 {
            ids.push(s.range_slider(0.0, 100.0, 20.0, 80.0) >>>)
            ids.push(s.label("20 – 80", 18.0, false) >>>)
            ids.push(s.label("Drag either thumb or the selected band. Tab visits both thumbs. Escape cancels a pending edit.\n拖动端点或整段;Tab 访问两个端点。", 14.0, true) >>>)
            s.set_label_wrapped(ids[2], true) >>>
        }
        if index == 41 {
            ids.push(s.split_view(0.4) >>>)
            split := ids[0]
            ids.push(s.split_pane(split, 0) >>>)
            ids.push(s.split_pane(split, 1) >>>)
            ids.push(s.label("Workspace / 工作区\nPane content follows the available size.", 16.0, false) >>>)
            ids.push(s.label("Preview / 预览\nDrag the handle; arrows adjust, Shift accelerates.", 16.0, false) >>>)
            ids.push(s.button("Open workspace") >>>)
            ids.push(s.button("Refresh preview") >>>)
            for i in 0:2 {s.set_label_wrapped(ids[3 + i], true) >>>
                s.set_parent(ids[3 + i], ids[1 + i]) >>>
                s.set_parent(ids[5 + i], ids[1 + i]) >>> }
        }
        if index >= 42 && index <= 44 {
            mode :=[widgets.MENU_DROPDOWN, widgets.MENU_CONTEXT, widgets.MENU_SPLIT][index - 42]
            label :=["Actions", "Right click here · 右键打开菜单", "Save"][index - 42]
            ids.push(s.menu(label, &workshop_menu_items(true), mode, 100) >>>)
            ids.push(s.label("Choose an action · 选择操作", 16.0, false) >>>)
            ids.push(s.label("Check and radio items preserve their state. Navigate submenus with arrows; Escape returns one level.\n操作文案与快捷键由应用配置。", 14.0, true) >>>)
            s.set_label_wrapped(ids[1], true) >>>
            s.set_label_wrapped(ids[2], true) >>>
        }
        if index == 45 {
            ids.push(s.password_input("Xu-密码🙂") >>>)
            ids.push(s.checkbox("Show password 显示密码", false) >>>)
            ids.push(s.label("Password 密码", 15.0, false) >>>)
            ids.push(s.label("Paste is supported. Copy and cut are blocked even when revealed.\n支持粘贴、选择和中英文输入;显隐切换保留内容与光标。", 14.0, true) >>>)
            s.set_label_wrapped(ids[3], true) >>>
        }
        for i in 0:ids.len{
            // Card slots and scroll children retain their content parent.
            if index == 30 &&(i == 0 || i == 3) { -> }
            if index == 31 && i > 0 { -> }
            if index == 41 && i > 0 { -> }
            if index == 32 && i > 0 { -> }
            if index == 36 && i > 1 { -> }
            if index == 33 && i >= 2 && i <= 7 { -> }
            s.set_parent(ids[i], group) >>>
        }
        s.set_visible(group, false) >>>
        << Page{group: group, ids: ids}
    }
    
    fn description(index int) string { << description_locale(index, false) }
    
    fn description_locale(index int, english bool) string {
        if english {
            if index == 45 { << "Unicode grapheme masking; reveal toggle, native editing, read-only and disabled states; copy/cut blocked."}
            if index == 40 { << "Dual-thumb range: step, minimum distance, clamp/push, band dragging; independent focus and commit."}
            if index == 41 { << "Resizable split panes: minimum constraints, collapse/restore, keyboard adjustment; content clipped per pane."}
            if index >= 42 && index <= 44 { << "Action / check / radio / submenu items; keyboard navigation, edge flipping, shortcuts and per-item feedback."}
            if index == 38 { << "Actions / single / multiple selection; per-item disable, arrow navigation, Enter or Space activation."}
            if index == 39 { << "Native interactive charts (30 types): stable-ID transitions, hover/select, legend; Ctrl/⌘ + wheel zoom, drag pan, double-click reset."}
            en :=["Layered body, heading and muted text; native line wrapping and font overrides.",
            "Leading / trailing / above / below icons; independent size steppers and content-width wrapping.",
            "Standalone hit target and action label; keyboard focus also triggers tooltip help.",
            "Native single-line editing: selection, copy, paste and IME composition.",
            "Native multi-line editing: paragraphs, internal scrolling and IME candidate placement.",
            "Floating / fixed labels and three border variants; soft counter never truncates input.",
            "Multi-line Field: min 3 rows, max 6 rows; character counter and stable helper region.",
            "Hierarchy guides, vector arrows, icons, metadata, filtering and node actions.",
            "Real compute batches drive progress; task ID rejects stale callbacks.",
            "Full-row click target; indeterminate mixed state; interruptible check animation.",
            "Track and thumb transition; interruptible rapid toggling; read-only preserves focus.",
            "Single radio item and selection animation; full label hit target.",
            "Arrow keys manage mutual exclusion; Tab enters the group once.",
            "11 ticks, step-10 snapping, value readout; commit on release.",
            "Hold to repeat and accelerate; stops cleanly at bounds.",
            "Typed groups and disabled options; arrow keys skip non-selectable rows.",
            "Local match highlighting and empty state; configurable free-text input.",
            "Candidate filtering, removable tags, select-all and clear actions.",
            "Today / Clear actions; Page Up/Down switches months, Shift switches years.",
            "12/24-hour clock format; stores explicit typed time values.",
            "RGBA channels, exact HEX input, swatches and recent color history.",
            "Variable-width tabs; arrow keys move focus, Enter activates manually.",
            "Segmented selection plate and container semantics distinct from Tabs.",
            "Icon / primary & secondary text / trailing detail; hit testing scales with font size.",
            "Resizable columns, horizontal & vertical scrolling, and data status messages.",
            "First, last and ellipsis items; fast page jumping for large datasets.",
            "Preserves current path; middle segments collapse into an interactive menu.",
            "Determinate progress and buffer shown separately without fabricated percentages.",
            "Configurable size, stroke width and period; static feedback under reduced motion.",
            "Subtle divider paired with section heading; unified horizontal and vertical spec.",
            "Badges in context: unread count, avatar status dot and status tags.",
            "Header / body / footer content slots; actions use standalone Buttons.",
            "True child clipping, wheel bubbling, track dragging and keyboard focus scroll-into-view.",
            "Anchor placement and edge flipping; outside click or Escape dismisses.",
            "Hover delay and immediate focus help; Escape suppresses repeated tooltips.",
            "Up to three visible notices; queueing, deduplication, priority and undo action.",
            "Modal focus loop and restoration; safe action receives initial focus.",
            "Native webview child component with clipping and independent lifecycle."]
            << en[index]
        }
        if index == 45 { << "按 Unicode 字素掩码;显隐切换、原生编辑、只读与禁用,禁止复制或剪切密码。"}
        if index == 40 { << "双端区间:步进、最小间距、端点推挤、整段拖动;独立焦点与提交。"}
        if index == 41 { << "可调整分栏:尺寸约束、折叠恢复、键盘调整;内容保持在各自面板内。"}
        if index >= 42 && index <= 44 { << "动作 / 勾选 / 单选 / 子菜单;键盘、边缘翻转、快捷键与可定制的逐项反馈。"}
        if index == 38 { << "独立操作 / 单选 / 多选;逐项禁用,方向键导航,Enter 或空格激活。"}
        if index == 39 { << "原生交互图表(30 种类型):稳定 ID 数据过渡、悬停/选中、图例;Ctrl/⌘ + 滚轮缩放,拖动平移,双击复位。"}
        descriptions :=["正文、标题与辅助文字分层;原生换行与字体覆盖。",
        "图标左 / 右 / 上 / 下;各自调节尺寸,按钮按内容宽度自动换行。",
        "独立点击目标与动作名称;键盘焦点也能查看提示。",
        "原生单行编辑:选区、复制、粘贴与 IME。",
        "原生多行编辑:段落、内部滚动与输入法候选定位。",
        "浮动标签 / 固定标签 / 三种边框;软计数不截断输入。",
        "多行 Field:最小 3 行、最大 6 行;计数与稳定辅助区。",
        "层级引导、矢量箭头、图标、元数据、筛选和节点动作。",
        "真实计算批次驱动进度;任务 ID 拒绝旧回调。",
        "整行点击;混合态;可中断的勾选显现。",
        "轨道与圆钮过渡;快速切换可中断;只读保留焦点。",
        "单项选择与选中动效;完整标签点击目标。",
        "方向键管理互斥;Tab 只进入一次。",
        "11 个刻度、10 步吸附、数值提示;松开才提交。",
        "按住连续增加并加速;到达边界停止。",
        "有类型的分组 / 禁用选项;方向键跳过不可选行。",
        "本地匹配高亮与无结果;可控制是否接受自由输入。",
        "候选筛选、可移除标签、全选和清空。",
        "今天 / 清空;Page Up/Down 快速翻月,Shift 切年。",
        "12/24 小时可选;存储保持明确的时间值。",
        "RGBA 通道、HEX 精确输入、色板与最近颜色。",
        "可变宽标签;方向键移动,Enter 手动激活。",
        "与 Tabs 分开的选中底板和容器语义。",
        "图标 / 主副文本 / 尾部信息;字体放大后命中保持一致。",
        "拖动调整列宽;横向与纵向滚动;数据状态文字。",
        "首页、末页与省略项;大页数仍可快速定位。",
        "保留当前路径;中间段收进可交互的菜单。",
        "真实确定进度与缓冲区分别显示,不伪造百分比。",
        "大小 / 粗细 / 周期可配置;减少动效显示静态反馈。",
        "弱分隔与章节文字组合;水平和垂直使用同一规范。",
        "Badge 放入真实上下文:未读计数、头像状态点与列表标签。",
        "Header / body / footer 内容槽;动作使用独立 Button。",
        "真实子控件裁剪、滚轮冒泡、轨道拖动与键盘焦点滚入。",
        "锚点定位、边缘翻转;外点 / Escape 关闭。",
        "Hover 延迟、focus 立即显示;Escape 抑制重复提示。",
        "最多三条可见通知;队列、去重、优先级与撤销动作。",
        "模态焦点循环与恢复;安全动作先获得焦点。",
        "原生网页子视图作为 Screen 组件,支持裁剪与独立生命周期。"]
        << descriptions[index]
    }
    
    fn tool_labels(index int)[]string { << tool_labels_locale(index, false) }
    
    fn tool_labels_locale(index int, english bool)[]string {
        if english {
            if index == 45 { <<["Clear", "Reset sample", "Focus input"]}
            if index == 40 { <<["Clamp / push", "Commit mode", "Orientation"]}
            if index == 41 { <<["Orientation", "Collapse / restore", "Reset ratio"]}
            if index >= 42 && index <= 44 { <<["Open menu", "Keep open", "Disable export"]}
            if index == 38 { <<["Disable middle", "Orientation", "Joined / gap"]}
            if index == 39 { <<["Update data", "Reset zoom", "Pause / resume"]}
            if index == 0 { <<["Long text", "Short text", ""]}
            if index == 1 || index == 2 { <<["Select", "Clear selection", ""]}
            if index == 3 || index == 4 { <<["Clear", "Long text", ""]}
            if index == 5 || index == 6 { <<["Clear", "Long text", "Appearance"]}
            if index == 7 { <<["Guides", "Reveal last", "Clear filter"]}
            if index == 8 { <<["Progress mode", "Fail next", "Cancel"]}
            if index == 9 { <<["Mixed", "Checked", "Unchecked"]}
            if index == 10 { <<["Pending", "Resolve", "Fail"]}
            if index == 11 { <<["Select", "Deselect", ""]}
            if index == 13 { <<["Apply input", "Commit only", "Live updates"]}
            if index == 15 { <<["Open", "Disable option", ""]}
            if index == 16 { <<["Allow custom", "Options only", "Clear"]}
            if index == 17 { <<["Select all", "Clear", ""]}
            if index == 18 { <<["Clear", "Set today", ""]}
            if index == 19 { <<["12 hour", "24 hour", "Hide seconds"]}
            if index == 20 { <<["Apply HEX", "Cinnabar", "Transparent"]}
            if index == 24 { <<["Data", "Loading", "Error"]}
            if index == 25 { <<["Jump", "Last page", "Empty / full"]}
            if index == 27 { <<["0%", "42%", "100%"]}
            if index == 28 { <<["Start", "Stop", "Large size"]}
            if index == 30 { <<["+1 unread", "Clear", "99+ overflow"]}
            if index == 32 { <<["Scroll top", "Scroll bottom", "Focus last"]}
            if index == 33 { <<["Open", "Close", "Placement"]}
            if index == 34 { <<["Focus help", "Blur", "Placement"]}
            if index == 35 { <<["Enqueue", "Undo", "Burst 3"]}
            if index == 36 { <<["Open", "Close", ""]}
            if index == 37 { <<["Reload", "Hide", "Show"]}
            <<["", "", ""]
        }
        if index == 45 { <<["清空", "重置示例", "聚焦输入"]}
        if index == 40 { <<["端点限制 / 推挤", "提交模式", "切换方向"]}
        if index == 41 { <<["切换方向", "折叠 / 恢复", "复位比例"]}
        if index >= 42 && index <= 44 { <<["打开菜单", "保持展开", "禁用导出"]}
        if index == 38 { <<["逐项禁用", "切换方向", "拼接 / 间距"]}
        if index == 39 { <<["更新数据", "复位缩放", "暂停 / 继续"]}
        if index == 0 { <<["切换长文", "切换短文", ""]}
        if index == 1 || index == 2 { <<["设为选中", "取消选中", ""]}
        if index == 3 || index == 4 { <<["清空内容", "填充长文", ""]}
        if index == 5 || index == 6 { <<["清空内容", "填充长文", "切换外观"]}
        if index == 7 { <<["引导线", "定位末项", "清空筛选"]}
        if index == 8 { <<["进度外观", "下次失败", "取消任务"]}
        if index == 9 { <<["混合态", "勾选", "取消勾选"]}
        if index == 10 { <<["等待态", "完成切换", "失败恢复"]}
        if index == 11 { <<["选中", "取消选中", ""]}
        if index == 13 { <<["应用输入", "松开提交", "实时更新"]}
        if index == 15 { <<["展开候选", "禁用选项", ""]}
        if index == 16 { <<["允许自由输入", "仅限选项", "清空"]}
        if index == 17 { <<["全选", "清空", ""]}
        if index == 18 { <<["清空日期", "设为今天", ""]}
        if index == 19 { <<["12 小时制", "24 小时制", "隐藏秒数"]}
        if index == 20 { <<["应用 HEX", "朱砂色", "半透明"]}
        if index == 24 { <<["正常数据", "正在加载", "加载错误"]}
        if index == 25 { <<["页码跳转", "跳至末页", "空 / 满数据"]}
        if index == 27 { <<["0%", "42%", "100%"]}
        if index == 28 { <<["开始旋转", "停止旋转", "切换大号"]}
        if index == 30 { <<["+1 未读", "清零未读", "99+ 溢出"]}
        if index == 32 { <<["滚至顶部", "滚至底部", "聚焦末项"]}
        if index == 33 { <<["打开浮层", "关闭浮层", "切换方位"]}
        if index == 34 { <<["聚焦提示", "移出隐藏", "切换方位"]}
        if index == 35 { <<["发送通知", "撤销通知", "连发三条"]}
        if index == 36 { <<["打开确认框", "关闭确认框", ""]}
        if index == 37 { <<["重新加载", "隐藏视图", "恢复显示"]}
        <<["", "", ""]
    }
    
    fn workshop_menu_items(english bool)[]widgets.MenuItem{
        labels :=["Open workspace", "Show grid", "Export", "PNG image", "SVG image", "Unavailable", "Save", "View density", "Compact", "Comfortable"]
        $translated := labels
        if !english{translated =["打开工作区", "显示网格", "导出", "PNG 图片", "SVG 图片", "暂不可用", "保存", "视图密度", "紧凑", "舒适"]}
        $grid := widgets.menu_item(20, translated[1])
        grid.kind = widgets.MENU_CHECK
        $export := widgets.menu_item(30, translated[2])
        export.kind = widgets.MENU_SUBMENU
        $png := widgets.menu_item(31, translated[3])
        png.parent = 30
        $svg := widgets.menu_item(32, translated[4])
        svg.parent = 30
        $unavailable := widgets.menu_item(40, translated[5])
        unavailable.enabled = false
        $save := widgets.menu_item(50, translated[6])
        save.shortcut_key = 115
        save.shortcut_modifiers = ui.MOD_META
        save.shortcut_label = "⌘S"
        $separator := widgets.menu_item(60, "")
        separator.kind = widgets.MENU_SEPARATOR
        $heading := widgets.menu_item(70, translated[7])
        heading.kind = widgets.MENU_HEADING
        $compact := widgets.menu_item(80, translated[8])
        compact.kind = widgets.MENU_RADIO
        compact.radio_group = 1
        $comfortable := widgets.menu_item(81, translated[9])
        comfortable.kind = widgets.MENU_RADIO
        comfortable.radio_group = 1
        comfortable.checked = true
        <<[widgets.menu_item(10, translated[0]), grid, export, png, svg, unavailable, save, separator, heading, compact, comfortable]
    }
    
    fn chart_data(kind int, revision int)[]chart.ChartSeries{
        << chart_data_locale(kind, revision, true)
    }
    
    fn chart_data_locale(kind int, revision int, english bool)[]chart.ChartSeries{
        $result :=[]chart.ChartSeries{}
        $series_count := 2
        single := kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
            kind == widgets.CHART_GAUGE || kind == widgets.CHART_HISTOGRAM || kind == widgets.CHART_BOXPLOT ||
            kind == widgets.CHART_CANDLESTICK || kind == widgets.CHART_WATERFALL || kind == widgets.CHART_FUNNEL ||
            (kind >= widgets.CHART_POLAR_BAR && kind <= widgets.CHART_SANKEY) || kind == widgets.CHART_VIOLIN ||
            kind == widgets.CHART_BULLET || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_PARETO
        if single{series_count = 1}
        if kind == widgets.CHART_HEATMAP{series_count = 3}
        for si in 0:series_count{
            $name := "构建"
            if si == 1 {name = "索引"}
            if si == 2 {name = "绘制"}
            if single{name = "工作量"}
            if english {
                name = "Build"
                if si == 1 {name = "Index"}
                if si == 2 {name = "Render"}
                if single{name = "Workload"}
            }
            $series := chart.chart_series(si + 1, name, kind)
            series.smooth = kind == widgets.CHART_LINE || kind == widgets.CHART_AREA || kind == widgets.CHART_STACKED_AREA ||
                kind == widgets.CHART_SMOOTH_LINE || kind == widgets.CHART_SMOOTH_AREA
            $count := 12 - revision % 2
            if kind == widgets.CHART_SCATTER{count = 64}
            else if kind == widgets.CHART_BUBBLE{count = 16}
            else if kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
                    kind == widgets.CHART_FUNNEL || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{count = 5}
            else if kind == widgets.CHART_RADAR || kind == widgets.CHART_PARETO{count = 6}
            else if kind == widgets.CHART_GAUGE{count = 3}
            else if kind == widgets.CHART_POLAR_BAR{count = 4}
            else if kind == widgets.CHART_HORIZONTAL_BAR || kind == widgets.CHART_HEATMAP || kind == widgets.CHART_BULLET ||
                    kind == widgets.CHART_LOLLIPOP || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_VIOLIN{count = 8}
            else if kind == widgets.CHART_WATERFALL{count = 7}
            for i in 0:count{
                x := f64(i + 1)
                phase := f64(revision) * 0.9 + f64(si) * 1.7
                $y := 48.0 + f64(si) * 20.0 + math.sin(x * 0.55 + phase) * 20.0 + math.cos(x * 0.17 + phase) * 7.0
                if kind == widgets.CHART_FUNNEL || kind == widgets.CHART_PARETO || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{
                    y = f64((count - i) * 22 + (revision % 3) * 4)
                } else if kind == widgets.CHART_GAUGE || kind == widgets.CHART_POLAR_BAR{
                    y = math.max(12.0, math.min(96.0, 34.0 + f64(i) * 18.0 + math.sin(phase + x) * 14.0))
                } else if kind == widgets.CHART_WATERFALL{
                    deltas :=[42.0, 18.0, 0.0 - 14.0, 24.0, 0.0 - 11.0, 16.0, 0.0]
                    y = deltas[i] + math.sin(phase) * 3.0
                    if i == count - 1 {y = 0.0}
                }
                $point := chart.chart_point(i + 1, x, y)
                if kind == widgets.CHART_BUBBLE{
                    point = chart.chart_bubble_point(i + 1, x, y, 12.0 + math.abs(math.cos(x * 0.7 + phase)) * 36.0)
                } else if kind == widgets.CHART_BOXPLOT || kind == widgets.CHART_CANDLESTICK ||
                          kind == widgets.CHART_VIOLIN || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_BULLET{
                    $close := y + math.sin(x * 0.9 + phase) * 12.0
                    if (kind == widgets.CHART_BOXPLOT || kind == widgets.CHART_VIOLIN || kind == widgets.CHART_DUMBBELL || kind == widgets.CHART_BULLET) && close < y{
                        close = y + 10.0
                    }
                    low := math.min(y, close) - 8.0 - math.abs(math.cos(x + phase)) * 6.0
                    high := math.max(y, close) + 8.0 + math.abs(math.sin(x + phase)) * 6.0
                    point = chart.chart_range_point(i + 1, x, y, low, high, close)
                } else if kind == widgets.CHART_WATERFALL && i == count - 1 {
                    point.size = 1.0
                }
                if english {
                    point.label = "Sample " + str(i + 1)
                    if kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
                       kind == widgets.CHART_FUNNEL || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{
                        point.label =["Compile", "Index", "Render", "I/O", "Other"][i]
                    } else if kind == widgets.CHART_RADAR{
                        point.label =["Throughput", "Latency", "Memory", "Startup", "Cache", "Binary"][i]
                    } else if kind == widgets.CHART_GAUGE{
                        point.label =["CPU", "Memory", "Cache"][i]
                    } else if kind == widgets.CHART_POLAR_BAR{
                        point.label =["Core 0", "Core 1", "Core 2", "Core 3"][i]
                    } else if kind == widgets.CHART_WATERFALL && i == count - 1 {
                        point.label = "Total"
                    }
                } else {
                    point.label = "样本 " + str(i + 1)
                    if kind == widgets.CHART_DONUT || kind == widgets.CHART_PIE || kind == widgets.CHART_ROSE ||
                       kind == widgets.CHART_FUNNEL || kind == widgets.CHART_TREEMAP || kind == widgets.CHART_SANKEY{
                        point.label =["编译", "索引", "绘制", "输入输出", "其他"][i]
                    } else if kind == widgets.CHART_RADAR{
                        point.label =["吞吐量", "延迟", "内存", "启动", "缓存", "体积"][i]
                    } else if kind == widgets.CHART_GAUGE{
                        point.label =["处理器", "内存", "缓存"][i]
                    } else if kind == widgets.CHART_POLAR_BAR{
                        point.label =["核心 0", "核心 1", "核心 2", "核心 3"][i]
                    } else if kind == widgets.CHART_WATERFALL && i == count - 1 {
                        point.label = "总计"
                    }
                }
                series.points.push(point)
            }
            result.push(series)
        }
        << result
    }

API declarations

const IN_NONE

XuAPI
pub const IN_NONE = 0

Purpose

Constant IN_NONE, defining protocol or algorithm parameters.

const IN_CLICK

XuAPI
pub const IN_CLICK = 1

Purpose

Constant IN_CLICK, defining protocol or algorithm parameters.

const IN_SCROLL

XuAPI
pub const IN_SCROLL = 2

Purpose

Constant IN_SCROLL, defining protocol or algorithm parameters.

const IN_DRAG

XuAPI
pub const IN_DRAG = 3

Purpose

Constant IN_DRAG, defining protocol or algorithm parameters.

struct Point

XuAPI
pub struct Point {
    pub x int
    pub y int
}

Purpose

Structure encapsulating x, y.

Public fields

x int
value
y int
value

struct Click

XuAPI
pub struct Click {
    pub x int
    pub y int
    pub ok int
}

Purpose

Structure encapsulating x, y, ok.

Public fields

x int
value
y int
value
ok int
field (int)

struct Input

XuAPI
pub struct Input {
    pub kind int
    pub x int
    pub y int
    pub dx int
    pub dy int
}

Purpose

Structure encapsulating kind, x, y, dx, dy.

Public fields

kind int
kind tag
x int
value
y int
value
dx int
field (int)
dy int
field (int)

attach

XuAPI
pub fn attach(w $&ui.Window) int

Purpose

Attach the draw canvas to a window (registers the content_draw plugin).

Parameters

w $&ui.Window
writer or width (exclusive borrow; may modify the original; type $&ui.Window)

Returns

int — a value of this type

set_input_enabled

XuAPI
pub fn set_input_enabled(on int) int

Purpose

Opt in to pointer/key events on the shared ui event channel.

Parameters

on int
on (int)

Returns

int — a value of this type

set_cursor

XuAPI
pub fn set_cursor(cursor int) int

Purpose

Cursor: default, text, crosshair, hand, horizontal/vertical resize.

Parameters

cursor int
cursor (int)

Returns

int — a value of this type

set_pan_enabled

XuAPI
pub fn set_pan_enabled(on int) int

Purpose

Control built-in drag / wheel panning on all three desktop platforms; disabled by default. Disabling resets offsets without suppressing application input.

Parameters

on int
0 disables, 1 enables; call after canvas readiness

Returns

command result; negative on transport failure

begin

XuAPI
pub fn begin() int

Purpose

Execute begin.

Parameters

No arguments are required.

Returns

int — a value of this type

present

XuAPI
pub fn present() int

Purpose

Execute present.

Parameters

No arguments are required.

Returns

int — a value of this type

cancel

XuAPI
pub fn cancel() int

Purpose

Execute cancel.

Parameters

No arguments are required.

Returns

int — a value of this type

clear

XuAPI
pub fn clear() int

Purpose

Execute clear.

Parameters

No arguments are required.

Returns

int — a value of this type

set_bg

XuAPI
pub fn set_bg(hex string) int

Purpose

Set bg.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_color

XuAPI
pub fn set_color(hex string) int

Purpose

Set color.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_fill

XuAPI
pub fn set_fill(hex string) int

Purpose

Set fill.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_stroke

XuAPI
pub fn set_stroke(hex string) int

Purpose

Set stroke.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_width

XuAPI
pub fn set_width(w int) int

Purpose

Set width.

Parameters

w int
writer or width (int)

Returns

int — a value of this type

push

XuAPI
pub fn push() int

Purpose

Execute push.

Parameters

No arguments are required.

Returns

int — a value of this type

pop

XuAPI
pub fn pop() int

Purpose

Execute pop.

Parameters

No arguments are required.

Returns

int — a value of this type

clip_rect

XuAPI
pub fn clip_rect(x int, y int, w int, h int) int

Purpose

Intersect the current clip with a rectangle in the current transform. push/pop save and restore the clip together with transform and pen.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)

Returns

int — a value of this type

origin

XuAPI
pub fn origin() int

Purpose

Execute origin.

Parameters

No arguments are required.

Returns

int — a value of this type

translate

XuAPI
pub fn translate(dx int, dy int) int

Purpose

Execute translate.

Parameters

dx int
dx (int)
dy int
dy (int)

Returns

int — a value of this type

rotate

XuAPI
pub fn rotate(deg int) int

Purpose

Execute rotate.

Parameters

deg int
deg (int)

Returns

int — a value of this type

scale

XuAPI
pub fn scale(sx int, sy int) int

Purpose

Execute scale.

Parameters

sx int
sx (int)
sy int
sy (int)

Returns

int — a value of this type

fill_rect

XuAPI
pub fn fill_rect(x int, y int, w int, h int, hex string) int

Purpose

Fill rectangle.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)
hex string
hex (string)

Returns

int — a value of this type

stroke_rect

XuAPI
pub fn stroke_rect(x int, y int, w int, h int, hex string, width int) int

Purpose

Stroke rectangle.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)
hex string
hex (string)
width int
width (int)

Returns

int — a value of this type

round_rect

XuAPI
pub fn round_rect(x int, y int, w int, h int, radius int, fill string, stroke string, width int) int

Purpose

Round rectangle.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)
radius int
radius (int)
fill string
fill (string)
stroke string
stroke (string)
width int
width (int)

Returns

int — a value of this type

diamond

XuAPI
pub fn diamond(x int, y int, w int, h int, fill string, stroke string, width int) int

Purpose

Execute diamond.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)
fill string
fill (string)
stroke string
stroke (string)
width int
width (int)

Returns

int — a value of this type

line

XuAPI
pub fn line(x1 int, y1 int, x2 int, y2 int, hex string, width int) int

Purpose

Execute line.

Parameters

x1 int
x1 (int)
y1 int
y1 (int)
x2 int
x2 (int)
y2 int
y2 (int)
hex string
hex (string)
width int
width (int)

Returns

int — a value of this type

text

XuAPI
pub fn text(x int, y int, size int, hex string, s string) int

Purpose

Return the current text.

Parameters

x int
value (int)
y int
value (int)
size int
size (int)
hex string
hex (string)
s string
source string (string)

Returns

int — a value of this type

arrow

XuAPI
pub fn arrow(x1 int, y1 int, x2 int, y2 int, hex string, width int) int

Purpose

Execute arrow.

Parameters

x1 int
x1 (int)
y1 int
y1 (int)
x2 int
x2 (int)
y2 int
y2 (int)
hex string
hex (string)
width int
width (int)

Returns

int — a value of this type

rect

XuAPI
pub fn rect(x int, y int, w int, h int) int

Purpose

Draw or fill a rectangle on the canvas.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)

Returns

int — a value of this type

rect_line

XuAPI
pub fn rect_line(x int, y int, w int, h int) int

Purpose

Rectangle line.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)

Returns

int — a value of this type

circle

XuAPI
pub fn circle(cx int, cy int, r int) int

Purpose

Execute circle.

Parameters

cx int
cx (int)
cy int
cy (int)
r int
rune (Unicode code point) (int)

Returns

int — a value of this type

circle_line

XuAPI
pub fn circle_line(cx int, cy int, r int) int

Purpose

Circle line.

Parameters

cx int
cx (int)
cy int
cy (int)
r int
rune (Unicode code point) (int)

Returns

int — a value of this type

fill_circle

XuAPI
pub fn fill_circle(cx int, cy int, r int, hex string) int

Purpose

Fill circle.

Parameters

cx int
cx (int)
cy int
cy (int)
r int
rune (Unicode code point) (int)
hex string
hex (string)

Returns

int — a value of this type

stroke_circle

XuAPI
pub fn stroke_circle(cx int, cy int, r int, hex string, width int) int

Purpose

Stroke circle.

Parameters

cx int
cx (int)
cy int
cy (int)
r int
rune (Unicode code point) (int)
hex string
hex (string)
width int
width (int)

Returns

int — a value of this type

ellipse

XuAPI
pub fn ellipse(x int, y int, w int, h int) int

Purpose

Execute ellipse.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)

Returns

int — a value of this type

ellipse_line

XuAPI
pub fn ellipse_line(x int, y int, w int, h int) int

Purpose

Ellipse line.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)

Returns

int — a value of this type

fill_ellipse

XuAPI
pub fn fill_ellipse(x int, y int, w int, h int, hex string) int

Purpose

Fill ellipse.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)
hex string
hex (string)

Returns

int — a value of this type

stroke_ellipse

XuAPI
pub fn stroke_ellipse(x int, y int, w int, h int, hex string, width int) int

Purpose

Stroke ellipse.

Parameters

x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)
hex string
hex (string)
width int
width (int)

Returns

int — a value of this type

triangle

XuAPI
pub fn triangle(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int) int

Purpose

Execute triangle.

Parameters

x1 int
x1 (int)
y1 int
y1 (int)
x2 int
x2 (int)
y2 int
y2 (int)
x3 int
x3 (int)
y3 int
y3 (int)

Returns

int — a value of this type

triangle_line

XuAPI
pub fn triangle_line(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int) int

Purpose

Triangle line.

Parameters

x1 int
x1 (int)
y1 int
y1 (int)
x2 int
x2 (int)
y2 int
y2 (int)
x3 int
x3 (int)
y3 int
y3 (int)

Returns

int — a value of this type

fill_triangle

XuAPI
pub fn fill_triangle(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int, hex string) int

Purpose

Fill triangle.

Parameters

x1 int
x1 (int)
y1 int
y1 (int)
x2 int
x2 (int)
y2 int
y2 (int)
x3 int
x3 (int)
y3 int
y3 (int)
hex string
hex (string)

Returns

int — a value of this type

stroke_triangle

XuAPI
pub fn stroke_triangle(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int, hex string, width int) int

Purpose

Stroke triangle.

Parameters

x1 int
x1 (int)
y1 int
y1 (int)
x2 int
x2 (int)
y2 int
y2 (int)
x3 int
x3 (int)
y3 int
y3 (int)
hex string
hex (string)
width int
width (int)

Returns

int — a value of this type

poly

XuAPI
pub fn poly(pts &[]Point, fill string, stroke string, width int) int

Purpose

Execute poly.

Parameters

pts &[]Point
pts (read-only borrow; caller keeps the original; type &[]Point)
fill string
fill (string)
stroke string
stroke (string)
width int
width (int)

Returns

int — a value of this type

arc

XuAPI
pub fn arc(cx int, cy int, r int, deg0 int, deg1 int, hex string, width int) int

Purpose

Execute arc.

Parameters

cx int
cx (int)
cy int
cy (int)
r int
rune (Unicode code point) (int)
deg0 int
deg0 (int)
deg1 int
deg1 (int)
hex string
hex (string)
width int
width (int)

Returns

int — a value of this type

point

XuAPI
pub fn point(x int, y int, hex string, r int) int

Purpose

Execute point.

Parameters

x int
value (int)
y int
value (int)
hex string
hex (string)
r int
rune (Unicode code point) (int)

Returns

int — a value of this type

click_of

XuAPI
pub fn click_of(ev ui.Event) Click

Purpose

Click of.

Parameters

ev ui.Event
ev (ui.Event)

Returns

Click — a value of this type

poll_click

XuAPI
pub fn poll_click(ech chan ui.Event) Click

Purpose

Next UI event if it is a canvas click (ok=0 otherwise). Uses App.event_ch.

Parameters

ech chan ui.Event
ech (channel; type chan ui.Event)

Returns

Click — a value of this type

poll

XuAPI
pub fn poll(ech chan ui.Event) Input

Purpose

Click, trackpad/mouse-wheel scroll, or drag-to-pan. Other events → in_none.

Parameters

ech chan ui.Event
ech (channel; type chan ui.Event)

Returns

Input — a value of this type

prompt

XuAPI
pub fn prompt(ech chan ui.Event, title string, seed string) string

Purpose

Compatibility: returns empty text on cancel/failure/timeout. Use ui.prompt_async for explicit outcomes. The event channel is preserved, including unrelated events.

Parameters

ech chan ui.Event
ech (channel; type chan ui.Event)
title string
title (string)
seed string
random seed (string)

Returns

string — result string

in_rect

XuAPI
pub fn in_rect(c Click, x int, y int, w int, h int) bool

Purpose

In rectangle.

Parameters

c Click
byte or character code (Click)
x int
value (int)
y int
value (int)
w int
writer or width (int)
h int
height or handle (int)

Returns

bool — true or false

in_circle

XuAPI
pub fn in_circle(c Click, cx int, cy int, r int) bool

Purpose

In circle.

Parameters

c Click
byte or character code (Click)
cx int
cx (int)
cy int
cy (int)
r int
rune (Unicode code point) (int)

Returns

bool — true or false

struct SurfaceCache

XuAPI
pub struct SurfaceCache {

}

Purpose

Owns one rasterized DisplayList. A changed immutable list ID, logical size, density or canvas generation replaces it only after the new snapshot succeeds. Explicitly dispose when retiring the cache. No caller-owned Surface is freed.

Public fields

This type has no public fields.

See usage example

new_surface_cache

XuAPI
pub fn new_surface_cache() SurfaceCache

Purpose

Construct surface cache.

Parameters

No arguments are required.

Returns

SurfaceCache — a value of this type

See usage example

($&SurfaceCache) dispose

XuAPI
pub fn (cache $&SurfaceCache) dispose()

Purpose

Release and dispose native resources and underlying handles.

Parameters

cache $&SurfaceCache
The SurfaceCache instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&SurfaceCache) close

XuAPI
pub fn (cache $&SurfaceCache) close()

Purpose

Operation on $&SurfaceCache: close the resource.

Parameters

cache $&SurfaceCache
The SurfaceCache instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&SurfaceCache) invalidate

XuAPI
pub fn (cache $&SurfaceCache) invalidate()

Purpose

Invalidate the control area, requesting a repaint on next frame.

Parameters

cache $&SurfaceCache
The SurfaceCache instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&SurfaceCache) update

XuAPI
pub fn (cache $&SurfaceCache) update(list &DisplayList,width f64,height f64,scale f64) bool

Purpose

Returns true only when pixels were regenerated. A failed replacement leaves the previous cache intact. Image updates do not mutate an already frozen list freeze a replacement list to intentionally change that content/version. Throws on failure; handle the error or propagate it to the caller.

Parameters

cache $&SurfaceCache
The SurfaceCache instance used by this call (exclusive borrow).
list &DisplayList
list (read-only borrow; caller keeps the original; type &DisplayList)
width f64
width (f64)
height f64
height (f64)
scale f64
scale (f64)

Returns

bool — true or false

($&Frame) cached_display_list

XuAPI
pub fn (frame $&Frame) cached_display_list(cache $&SurfaceCache,list &DisplayList, x f64,y f64,width f64,height f64,scale f64,opacity f64,sampler int) int

Purpose

Operation on $&Frame: cached display list. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cache $&SurfaceCache
cache (exclusive borrow; may modify the original; type $&SurfaceCache)
list &DisplayList
list (read-only borrow; caller keeps the original; type &DisplayList)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
scale f64
scale (f64)
opacity f64
opacity (f64)
sampler int
sampler (int)

Returns

int — a value of this type

(&Color) r

XuAPI
pub fn (c &Color) r() int

Purpose

Execute r on &Color.

Parameters

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

Returns

int — a value of this type

(&Color) g

XuAPI
pub fn (c &Color) g() int

Purpose

Execute g on &Color.

Parameters

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

Returns

int — a value of this type

(&Color) b

XuAPI
pub fn (c &Color) b() int

Purpose

Execute b on &Color.

Parameters

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

Returns

int — a value of this type

(&Color) a

XuAPI
pub fn (c &Color) a() int

Purpose

Execute a on &Color.

Parameters

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

Returns

int — a value of this type

(&Color) with_opacity

XuAPI
pub fn (c &Color) with_opacity(opacity f64) Color

Purpose

Scales the existing alpha channel by opacity in [0, 1].

Parameters

c &Color
The Color instance used by this call (borrow).
opacity f64
opacity (f64)

Returns

Color — a value of this type

(&Color) opacity

XuAPI
pub fn (c &Color) opacity(alpha_unit f64) Color

Purpose

Sets the alpha channel directly from a unit opacity in [0, 1].

Parameters

c &Color
The Color instance used by this call (borrow).
alpha_unit f64
alpha_unit (f64)

Returns

Color — a value of this type

lerp_color

XuAPI
pub fn lerp_color(a Color, b Color, t f64) Color

Purpose

Lerp color.

Parameters

a Color
value (Color)
b Color
b (Color)
t f64
t (f64)

Returns

Color — a value of this type

See usage example

(&Color) lighten

XuAPI
pub fn (c &Color) lighten(amount f64) Color

Purpose

Execute lighten on &Color.

Parameters

c &Color
The Color instance used by this call (borrow).
amount f64
amount (f64)

Returns

Color — a value of this type

(&Color) darken

XuAPI
pub fn (c &Color) darken(amount f64) Color

Purpose

Execute darken on &Color.

Parameters

c &Color
The Color instance used by this call (borrow).
amount f64
amount (f64)

Returns

Color — a value of this type

hex

XuAPI
pub fn hex(code string) Color

Purpose

Parses #RGB, #RGBA, #RRGGBB, or #RRGGBBAA (leading '#' is optional). Throws on failure; handle the error or propagate it to the caller.

Parameters

code string
code (string)

Returns

Color — a value of this type

See usage example

hsla

XuAPI
pub fn hsla(h f64, s f64, l f64, a f64) Color

Purpose

Converts HSL (hue in degrees, saturation and lightness in [0, 1]) to Color.

Parameters

h f64
height or handle (f64)
s f64
s (f64)
l f64
l (f64)
a f64
value (f64)

Returns

Color — a value of this type

hsl

XuAPI
pub fn hsl(h f64, s f64, l f64) Color

Purpose

Execute hsl.

Parameters

h f64
height or handle (f64)
s f64
s (f64)
l f64
l (f64)

Returns

Color — a value of this type

See usage example

round_stroke

XuAPI
pub fn round_stroke(width f64) StrokeOptions

Purpose

Round stroke.

Parameters

width f64
width (f64)

Returns

StrokeOptions — a value of this type

dashed_stroke

XuAPI
pub fn dashed_stroke(width f64, dash_len f64, gap_len f64) StrokeOptions

Purpose

Dashed stroke.

Parameters

width f64
width (f64)
dash_len f64
dash_len (f64)
gap_len f64
gap_len (f64)

Returns

StrokeOptions — a value of this type

gradient_stop

XuAPI
pub fn gradient_stop(offset f64, color Color) GradientStop

Purpose

Gradient stop.

Parameters

offset f64
offset (f64)
color Color
color (Color)

Returns

GradientStop — a value of this type

two_stop_linear

XuAPI
pub fn two_stop_linear(x1 f64, y1 f64, x2 f64, y2 f64, start_color Color, end_color Color) Gradient

Purpose

Two stop linear.

Parameters

x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
start_color Color
start_color (Color)
end_color Color
end_color (Color)

Returns

Gradient — a value of this type

See usage example

two_stop_radial

XuAPI
pub fn two_stop_radial(cx f64, cy f64, radius f64, inner_color Color, outer_color Color) Gradient

Purpose

Two stop radial.

Parameters

cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
inner_color Color
inner_color (Color)
outer_color Color
outer_color (Color)

Returns

Gradient — a value of this type

See usage example

(&Color) invert

XuAPI
pub fn (c &Color) invert() Color

Purpose

Execute invert on &Color.

Parameters

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

Returns

Color — a value of this type

(&Color) grayscale

XuAPI
pub fn (c &Color) grayscale() Color

Purpose

Execute grayscale on &Color.

Parameters

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

Returns

Color — a value of this type

(&Color) luminance

XuAPI
pub fn (c &Color) luminance() f64

Purpose

Relative WCAG luminance in [0, 1].

Parameters

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

Returns

f64 — a value of this type

contrast_ratio

XuAPI
pub fn contrast_ratio(a Color, b Color) f64

Purpose

Contrast ratio.

Parameters

a Color
value (Color)
b Color
b (Color)

Returns

f64 — a value of this type

(&Color) contrasting_ink

XuAPI
pub fn (bg &Color) contrasting_ink(light Color, dark Color) Color

Purpose

Operation on &Color: contrasting ink.

Parameters

bg &Color
The Color instance used by this call (borrow).
light Color
light (Color)
dark Color
dark (Color)

Returns

Color — a value of this type

(&Color) to_hex_rgba

XuAPI
pub fn (c &Color) to_hex_rgba() string

Purpose

Operation on &Color: convert to hex rgba.

Parameters

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

Returns

string — result string

(&Color) to_hex

XuAPI
pub fn (c &Color) to_hex() string

Purpose

Operation on &Color: convert to hex.

Parameters

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

Returns

string — result string

(&Color) blend_over

XuAPI
pub fn (fg &Color) blend_over(bg Color) Color

Purpose

Porter-Duff source-over compositing of foreground fg onto backdrop bg in straight sRGB.

Parameters

fg &Color
The Color instance used by this call (borrow).
bg Color
bg (Color)

Returns

Color — a value of this type

lerp_color_premul

XuAPI
pub fn lerp_color_premul(a Color, b Color, t f64) Color

Purpose

Premultiplied-alpha linear interpolation avoids dark fringes when fading to transparent.

Parameters

a Color
value (Color)
b Color
b (Color)
t f64
t (f64)

Returns

Color — a value of this type

hsva

XuAPI
pub fn hsva(h f64, s f64, v f64, a f64) Color

Purpose

Converts HSV (hue in degrees, saturation and value in [0, 1]) to Color.

Parameters

h f64
height or handle (f64)
s f64
s (f64)
v f64
value (f64)
a f64
value (f64)

Returns

Color — a value of this type

hsv

XuAPI
pub fn hsv(h f64, s f64, v f64) Color

Purpose

Execute hsv.

Parameters

h f64
height or handle (f64)
s f64
s (f64)
v f64
value (f64)

Returns

Color — a value of this type

mix_palette

XuAPI
pub fn mix_palette(start_color Color, end_color Color, steps int) []Color

Purpose

Mix palette.

Parameters

start_color Color
start_color (Color)
end_color Color
end_color (Color)
steps int
steps (int)

Returns

[]Color — slice result

const BLEND_SOURCE_OVER

XuAPI
pub const BLEND_SOURCE_OVER = 0

Purpose

Constant BLEND_SOURCE_OVER, defining protocol or algorithm parameters.

const BLEND_COPY

XuAPI
pub const BLEND_COPY = 1

Purpose

Constant BLEND_COPY, defining protocol or algorithm parameters.

const BLEND_DESTINATION_IN

XuAPI
pub const BLEND_DESTINATION_IN = 2

Purpose

Constant BLEND_DESTINATION_IN, defining protocol or algorithm parameters.

const BLEND_DESTINATION_OUT

XuAPI
pub const BLEND_DESTINATION_OUT = 3

Purpose

Constant BLEND_DESTINATION_OUT, defining protocol or algorithm parameters.

const BLEND_MULTIPLY

XuAPI
pub const BLEND_MULTIPLY = 4

Purpose

Constant BLEND_MULTIPLY, defining protocol or algorithm parameters.

const BLEND_SCREEN

XuAPI
pub const BLEND_SCREEN = 5

Purpose

Constant BLEND_SCREEN, defining protocol or algorithm parameters.

const BLEND_ADD

XuAPI
pub const BLEND_ADD = 6

Purpose

Constant BLEND_ADD, defining protocol or algorithm parameters.

const BLEND_XOR

XuAPI
pub const BLEND_XOR = 7

Purpose

Constant BLEND_XOR, defining protocol or algorithm parameters.

(&Surface) composite

XuAPI
pub fn (backdrop &Surface) composite(source &Surface, mode int, opacity f64) Surface

Purpose

Same logical bounds and backing resolution are required. This Surface is the backdrop, source is the foreground. Produces an immutable cache; original pixels are unchanged. The caller explicitly owns/disposes the returned handle. Throws on failure; handle the error or propagate it to the caller.

Parameters

backdrop &Surface
The Surface instance used by this call (borrow).
source &Surface
source (read-only borrow; caller keeps the original; type &Surface)
mode int
mode (int)
opacity f64
opacity (f64)

Returns

Surface — a value of this type

($&Frame) fill_path_gradient

XuAPI
pub fn (frame $&Frame) fill_path_gradient(path &Path,paint &Gradient,bounds &ImageRect,scale f64,rule int) int

Purpose

Gradient coordinates are local to bounds. Path coordinates remain in the caller's current logical space. Explicit density controls raster quality parent CTM/clip apply when the generated painted Path is composited. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
path &Path
filesystem path (read-only borrow; caller keeps the original; type &Path)
paint &Gradient
paint (read-only borrow; caller keeps the original; type &Gradient)
bounds &ImageRect
bounds (read-only borrow; caller keeps the original; type &ImageRect)
scale f64
scale (f64)
rule int
rule (int)

Returns

int — a value of this type

struct DisplayList

XuAPI
pub struct DisplayList {

}

Purpose

Immutable vector fragment. Captures current resource versions and compiles native paths once. Copies share one handle. Dispose explicitly; queued frames retain it. Draw under the caller's CTM/clip with isolated default pen state. Background-clearing commands cannot be captured: use an explicit rectangle.

Public fields

This type has no public fields.

See usage example

($&Frame) freeze

XuAPI
pub fn (frame $&Frame) freeze() DisplayList

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

DisplayList — a value of this type

($&DisplayList) dispose

XuAPI
pub fn (list $&DisplayList) dispose() int

Purpose

Release and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.

Parameters

list $&DisplayList
The DisplayList instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&DisplayList) close

XuAPI
pub fn (list $&DisplayList) close() int

Purpose

Operation on $&DisplayList: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

list $&DisplayList
The DisplayList instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) display_list

XuAPI
pub fn (frame $&Frame) display_list(list &DisplayList) int

Purpose

Operation on $&Frame: display list. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
list &DisplayList
list (read-only borrow; caller keeps the original; type &DisplayList)

Returns

int — a value of this type

(&DisplayList) snapshot

XuAPI
pub fn (list &DisplayList) snapshot(width f64,height f64,scale f64) Surface

Purpose

Execute snapshot on &DisplayList. Throws on failure; handle the error or propagate it to the caller.

Parameters

list &DisplayList
The DisplayList instance used by this call (borrow).
width f64
width (f64)
height f64
height (f64)
scale f64
scale (f64)

Returns

Surface — a value of this type

struct DisplayListPool

XuAPI
pub struct DisplayListPool {

}

Purpose

Owns keyed immutable vector records in one canvas domain. Replacements are captured before retiring the old handle; queued/captured scenes retain their resource versions. The native process-wide list/memory limits still apply.

Public fields

This type has no public fields.

(&Context) display_list_pool

XuAPI
pub fn (context &Context) display_list_pool() DisplayListPool

Purpose

Operation on &Context: display list pool.

Parameters

context &Context
The Context instance used by this call (borrow).

Returns

DisplayListPool — a value of this type

(&DisplayListPool) is_current

XuAPI
pub fn (pool &DisplayListPool) is_current(key int,revision int) bool

Purpose

Operation on &DisplayListPool: whether it is current.

Parameters

pool &DisplayListPool
The DisplayListPool instance used by this call (borrow).
key int
key (int)
revision int
revision (int)

Returns

bool — true or false

($&DisplayListPool) capture

XuAPI
pub fn (pool $&DisplayListPool) capture(key int,revision int,frame $&Frame) int

Purpose

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

Parameters

pool $&DisplayListPool
The DisplayListPool instance used by this call (exclusive borrow).
key int
key (int)
revision int
revision (int)
frame $&Frame
frame (exclusive borrow; may modify the original; type $&Frame)

Returns

int — a value of this type

($&DisplayListPool) remove

XuAPI
pub fn (pool $&DisplayListPool) remove(key int)

Purpose

Operation on $&DisplayListPool: remove.

Parameters

pool $&DisplayListPool
The DisplayListPool instance used by this call (exclusive borrow).
key int
key (int)

Returns

This call does not return a value.

($&DisplayListPool) dispose

XuAPI
pub fn (pool $&DisplayListPool) dispose()

Purpose

Release and dispose native resources and underlying handles.

Parameters

pool $&DisplayListPool
The DisplayListPool instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&DisplayListPool) close

XuAPI
pub fn (pool $&DisplayListPool) close()

Purpose

Operation on $&DisplayListPool: close the resource.

Parameters

pool $&DisplayListPool
The DisplayListPool instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Frame) pooled_display_list

XuAPI
pub fn (frame $&Frame) pooled_display_list(pool &DisplayListPool,key int) int

Purpose

Operation on $&Frame: pooled display list. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
pool &DisplayListPool
pool (read-only borrow; caller keeps the original; type &DisplayListPool)
key int
key (int)

Returns

int — a value of this type

default_font_stack

XuAPI
pub fn default_font_stack() font.FontStack

Purpose

Returns a pure-Xu font stack initialized with the embedded geometric fallback face. Throws on failure; handle the error or propagate it to the caller.

Parameters

No arguments are required.

Returns

font.FontStack — a value of this type

add_ttf_face

XuAPI
pub fn add_ttf_face(stack $&font.FontStack, ttf_bytes &[]u8, font_index int, face_id int) int

Purpose

Parses a TrueType/OpenType font payload and registers it onto stack. Throws on failure; handle the error or propagate it to the caller.

Parameters

stack $&font.FontStack
stack (exclusive borrow; may modify the original; type $&font.FontStack)
ttf_bytes &[]u8
ttf_bytes (read-only borrow; caller keeps the original; type &[]u8)
font_index int
font_index (int)
face_id int
face_id (int)

Returns

int — a value of this type

font_metrics_to_draw

XuAPI
pub fn font_metrics_to_draw(m &font.TextMetrics) TextMetrics

Purpose

Converts pure-Xu font metrics into draw.TextMetrics.

Parameters

m &font.TextMetrics
m (read-only borrow; caller keeps the original; type &font.TextMetrics)

Returns

TextMetrics — a value of this type

layout_font_text

XuAPI
pub fn layout_font_text(stack &font.FontStack, value &string, options &TextOptions, masked bool) font.TextLayout

Purpose

Shapes UTF-8 text in pure Xu without requiring the ':xu:' native host. Throws on failure; handle the error or propagate it to the caller.

Parameters

stack &font.FontStack
stack (read-only borrow; caller keeps the original; type &font.FontStack)
value &string
value (read-only borrow; caller keeps the original; type &string)
options &TextOptions
options (read-only borrow; caller keeps the original; type &TextOptions)
masked bool
masked (bool)

Returns

font.TextLayout — a value of this type

(&Context) measure_text_options

XuAPI
pub fn (context &Context) measure_text_options(value &string, options &TextOptions, masked bool) TextMetrics

Purpose

Measures UTF-8 text using ':xu:' when active, or pure-Xu #ui/font when hostless. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
value &string
value (read-only borrow; caller keeps the original; type &string)
options &TextOptions
options (read-only borrow; caller keeps the original; type &TextOptions)
masked bool
masked (bool)

Returns

TextMetrics — a value of this type

($&Frame) text_font_layout

XuAPI
pub fn (frame $&Frame) text_font_layout(ly &font.TextLayout, value &string, x f64, y f64, color Color) int

Purpose

Emits positioned per-line XDF_OP_TEXT records from a pure-Xu font.TextLayout. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
ly &font.TextLayout
ly (read-only borrow; caller keeps the original; type &font.TextLayout)
value &string
value (read-only borrow; caller keeps the original; type &string)
x f64
value (f64)
y f64
value (f64)
color Color
color (Color)

Returns

int — a value of this type

const MAX_FRAME_BYTES

XuAPI
pub const MAX_FRAME_BYTES = 4194304

Purpose

XDF1 is a bounded little-endian frame ABI. Each recorder owns its storage. Explicit window contexts carry a generation and are revoked on native close.

const MAX_FRAME_COMMANDS

XuAPI
pub const MAX_FRAME_COMMANDS = 100000

Purpose

Constant MAX_FRAME_COMMANDS, defining protocol or algorithm parameters.

const MAX_STATE_DEPTH

XuAPI
pub const MAX_STATE_DEPTH = 256

Purpose

Constant MAX_STATE_DEPTH, defining protocol or algorithm parameters.

struct Color

XuAPI
pub struct Color {

}

Purpose

Color context or state structure.

Public fields

This type has no public fields.

See usage example

rgba

XuAPI
pub fn rgba(r int, g int, b int, a int) Color

Purpose

Straight (unpremultiplied) sRGB bytes. Components saturate to 0...255.

Parameters

r int
rune (Unicode code point) (int)
g int
g (int)
b int
b (int)
a int
value (int)

Returns

Color — a value of this type

See usage example

(&Color) value

XuAPI
pub fn (color &Color) value() int

Purpose

Return the packed straight RGBA value with R in the most significant byte.

Parameters

color &Color
The Color instance used by this call (borrow).

Returns

0xRRGGBBAA integer

(&Color) with_alpha

XuAPI
pub fn (color &Color) with_alpha(alpha int) Color

Purpose

Derive a color with alpha replaced and clamped to 0–255.

Parameters

color &Color
The Color instance used by this call (borrow).
alpha int
alpha (int)

Returns

a new Color

rgb

XuAPI
pub fn rgb(r int, g int, b int) Color

Purpose

Execute rgb.

Parameters

r int
rune (Unicode code point) (int)
g int
g (int)
b int
b (int)

Returns

Color — a value of this type

See usage example

struct Context

XuAPI
pub struct Context {

}

Purpose

Context context or state structure.

Public fields

This type has no public fields.

See usage example

(&Context) clone

XuAPI
pub fn (context &Context) clone() Context

Purpose

Copy only the checked canvas identity; resources remain canvas-owned.

Parameters

context &Context
The Context instance used by this call (borrow).

Returns

Context — a value of this type

(&Context) matches_canvas

XuAPI
pub fn (context &Context) matches_canvas(identity &ui.CanvasEvent) bool

Purpose

Retained controls require a checked generation from canvas_ready.

Parameters

context &Context
The Context instance used by this call (borrow).
identity &ui.CanvasEvent
identity (read-only borrow; caller keeps the original; type &ui.CanvasEvent)

Returns

bool — true or false

default_context

XuAPI
pub fn default_context() Context

Purpose

Default context.

Parameters

No arguments are required.

Returns

Context — a value of this type

hostless_context

XuAPI
pub fn hostless_context(canvas_id int, generation int) Context

Purpose

Hostless context.

Parameters

canvas_id int
canvas_id (int)
generation int
generation (int)

Returns

Context — a value of this type

context_of

XuAPI
pub fn context_of(event &ui.Event) Context

Purpose

Bind to a native canvas_ready event. The host rejects this Context after that generation closes, even if its numeric canvas ID is later reused. Throws on failure; handle the error or propagate it to the caller.

Parameters

event &ui.Event
event (read-only borrow; caller keeps the original; type &ui.Event)

Returns

Context — a value of this type

See usage example

window_context

XuAPI
pub fn window_context(window &ui.Window) Context

Purpose

Window context. Throws on failure; handle the error or propagate it to the caller.

Parameters

window &ui.Window
window (read-only borrow; caller keeps the original; type &ui.Window)

Returns

Context — a value of this type

See usage example

struct Frame

XuAPI
pub struct Frame {

}

Purpose

Draw Protocol data frame encapsulation.

Public fields

This type has no public fields.

See usage example

(&Context) new_frame

XuAPI
pub fn (c &Context) new_frame(capacity int) Frame

Purpose

Operation on &Context: construct frame.

Parameters

c &Context
The Context instance used by this call (borrow).
capacity int
capacity (int)

Returns

Frame — a value of this type

($&Frame) begin

XuAPI
pub fn (f $&Frame) begin() int

Purpose

Discards only this recorder's unsubmitted work. Capacity is retained. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) cancel

XuAPI
pub fn (f $&Frame) cancel()

Purpose

Execute cancel on $&Frame.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Frame) byte_len

XuAPI
pub fn (f &Frame) byte_len() int

Purpose

Operation on &Frame: byte len.

Parameters

f &Frame
The Frame instance used by this call (borrow).

Returns

int — a value of this type

(&Frame) capacity

XuAPI
pub fn (f &Frame) capacity() int

Purpose

Execute capacity on &Frame.

Parameters

f &Frame
The Frame instance used by this call (borrow).

Returns

int — a value of this type

(&Frame) command_count

XuAPI
pub fn (f &Frame) command_count() int

Purpose

Operation on &Frame: command count.

Parameters

f &Frame
The Frame instance used by this call (borrow).

Returns

int — a value of this type

($&Frame) export_xdf

XuAPI
pub fn (f $&Frame) export_xdf() string

Purpose

Seals and returns the XDF1 frame payload without submitting to the ':xu:' UI host, allowing engine/GPU/software backends to consume ui/draw commands. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

string — result string

($&Frame) present

XuAPI
pub fn (f $&Frame) present() int

Purpose

Seal and submit a complete frame. Success means queued, not displayed. A full queue preserves the sealed frame for retry or rebuilding with cancel / begin.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

0 on success; throws on failure

($&Frame) present_wait

XuAPI
pub fn (f $&Frame) present_wait() int

Purpose

Worker-thread submission parks for bounded queue capacity. Validation and closed-canvas errors still fail immediately once admission is available. UI hosts must continue draining commands on their own native thread. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) set_bg

XuAPI
pub fn (f $&Frame) set_bg(color Color) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
color Color
color (Color)

Returns

int — a value of this type

($&Frame) set_color

XuAPI
pub fn (f $&Frame) set_color(color Color) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
color Color
color (Color)

Returns

int — a value of this type

($&Frame) set_fill

XuAPI
pub fn (f $&Frame) set_fill(color Color) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
color Color
color (Color)

Returns

int — a value of this type

($&Frame) set_stroke

XuAPI
pub fn (f $&Frame) set_stroke(color Color) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
color Color
color (Color)

Returns

int — a value of this type

($&Frame) set_width

XuAPI
pub fn (f $&Frame) set_width(width f64) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
width f64
width (f64)

Returns

int — a value of this type

($&Frame) push

XuAPI
pub fn (f $&Frame) push() int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) pop

XuAPI
pub fn (f $&Frame) pop() int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) origin

XuAPI
pub fn (f $&Frame) origin() int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) translate

XuAPI
pub fn (f $&Frame) translate(x f64, y f64) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

($&Frame) rotate

XuAPI
pub fn (f $&Frame) rotate(degrees f64) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
degrees f64
degrees (f64)

Returns

int — a value of this type

($&Frame) scale

XuAPI
pub fn (f $&Frame) scale(x f64, y f64) int

Purpose

Scale factors: 1 = 100%. The legacy free function still uses percent. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

($&Frame) clip_rect

XuAPI
pub fn (f $&Frame) clip_rect(x f64, y f64, w f64, h f64) int

Purpose

Operation on $&Frame: clip rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
w f64
writer or width (f64)
h f64
height or handle (f64)

Returns

int — a value of this type

($&Frame) rect

XuAPI
pub fn (f $&Frame) rect(x f64, y f64, w f64, h f64) int

Purpose

Operation on $&Frame: draw or fill a rectangle on the canvas. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
w f64
writer or width (f64)
h f64
height or handle (f64)

Returns

int — a value of this type

($&Frame) rect_line

XuAPI
pub fn (f $&Frame) rect_line(x f64, y f64, w f64, h f64) int

Purpose

Operation on $&Frame: rectangle line. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
w f64
writer or width (f64)
h f64
height or handle (f64)

Returns

int — a value of this type

($&Frame) fill_rect

XuAPI
pub fn (f $&Frame) fill_rect(x f64, y f64, w f64, h f64, color Color) int

Purpose

Operation on $&Frame: fill rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
w f64
writer or width (f64)
h f64
height or handle (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_rect

XuAPI
pub fn (f $&Frame) stroke_rect(x f64, y f64, w f64, h f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
w f64
writer or width (f64)
h f64
height or handle (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) ellipse

XuAPI
pub fn (f $&Frame) ellipse(x f64, y f64, w f64, h f64) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
w f64
writer or width (f64)
h f64
height or handle (f64)

Returns

int — a value of this type

($&Frame) line

XuAPI
pub fn (f $&Frame) line(x1 f64, y1 f64, x2 f64, y2 f64, color Color, width f64) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) text

XuAPI
pub fn (f $&Frame) text(x f64, y f64, size f64, color Color, text &string) int

Purpose

UTF-8 text is length-delimited: tabs/newlines cannot inject host commands. Throws on failure; handle the error or propagate it to the caller.

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
size f64
size (f64)
color Color
color (Color)
text &string
text (read-only borrow; caller keeps the original; type &string)

Returns

int — a value of this type

($&Frame) circle

XuAPI
pub fn (f $&Frame) circle(x f64, y f64, radius f64) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
radius f64
radius (f64)

Returns

int — a value of this type

($&Frame) triangle

XuAPI
pub fn (f $&Frame) triangle(x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64) int

Purpose

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

Parameters

f $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
x3 f64
x3 (f64)
y3 f64
y3 (f64)

Returns

int — a value of this type

bezier_quad_point

XuAPI
pub fn bezier_quad_point(x1 f64, y1 f64, cx f64, cy f64, x2 f64, y2 f64, t f64) PathPoint

Purpose

Bezier quad point.

Parameters

x1 f64
x1 (f64)
y1 f64
y1 (f64)
cx f64
cx (f64)
cy f64
cy (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
t f64
t (f64)

Returns

PathPoint — a value of this type

bezier_cubic_point

XuAPI
pub fn bezier_cubic_point(x1 f64, y1 f64, c1x f64, c1y f64, c2x f64, c2y f64, x2 f64, y2 f64, t f64) PathPoint

Purpose

Bezier cubic point.

Parameters

x1 f64
x1 (f64)
y1 f64
y1 (f64)
c1x f64
c1x (f64)
c1y f64
c1y (f64)
c2x f64
c2x (f64)
c2y f64
c2y (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
t f64
t (f64)

Returns

PathPoint — a value of this type

bezier_cubic_tangent

XuAPI
pub fn bezier_cubic_tangent(x1 f64, y1 f64, c1x f64, c1y f64, c2x f64, c2y f64, x2 f64, y2 f64, t f64) PathPoint

Purpose

Bezier cubic tangent.

Parameters

x1 f64
x1 (f64)
y1 f64
y1 (f64)
c1x f64
c1x (f64)
c1y f64
c1y (f64)
c2x f64
c2x (f64)
c2y f64
c2y (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
t f64
t (f64)

Returns

PathPoint — a value of this type

point_in_rect

XuAPI
pub fn point_in_rect(px f64, py f64, x f64, y f64, width f64, height f64) bool

Purpose

Point in rectangle.

Parameters

px f64
px (f64)
py f64
py (f64)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)

Returns

bool — true or false

point_in_circle

XuAPI
pub fn point_in_circle(px f64, py f64, cx f64, cy f64, radius f64) bool

Purpose

Point in circle.

Parameters

px f64
px (f64)
py f64
py (f64)
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)

Returns

bool — true or false

point_in_ellipse

XuAPI
pub fn point_in_ellipse(px f64, py f64, cx f64, cy f64, rx f64, ry f64) bool

Purpose

Point in ellipse.

Parameters

px f64
px (f64)
py f64
py (f64)
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)

Returns

bool — true or false

point_in_round_rect

XuAPI
pub fn point_in_round_rect(px f64, py f64, x f64, y f64, width f64, height f64, radius f64) bool

Purpose

Point in round rectangle.

Parameters

px f64
px (f64)
py f64
py (f64)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)

Returns

bool — true or false

point_in_round_rect_corners

XuAPI
pub fn point_in_round_rect_corners(px f64, py f64, x f64, y f64, width f64, height f64, tl f64, tr f64, br f64, bl f64) bool

Purpose

Point in round rectangle corners.

Parameters

px f64
px (f64)
py f64
py (f64)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
tl f64
tl (f64)
tr f64
tr (f64)
br f64
br (f64)
bl f64
bl (f64)

Returns

bool — true or false

point_in_triangle

XuAPI
pub fn point_in_triangle(px f64, py f64, x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64) bool

Purpose

Point in triangle.

Parameters

px f64
px (f64)
py f64
py (f64)
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
x3 f64
x3 (f64)
y3 f64
y3 (f64)

Returns

bool — true or false

point_in_polygon

XuAPI
pub fn point_in_polygon(px f64, py f64, points &[]PathPoint) bool

Purpose

Point in polygon.

Parameters

px f64
px (f64)
py f64
py (f64)
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)

Returns

bool — true or false

point_in_sector

XuAPI
pub fn point_in_sector(px f64, py f64, cx f64, cy f64, inner_radius f64, outer_radius f64, start_deg f64, sweep_deg f64) bool

Purpose

Point in sector.

Parameters

px f64
px (f64)
py f64
py (f64)
cx f64
cx (f64)
cy f64
cy (f64)
inner_radius f64
inner_radius (f64)
outer_radius f64
outer_radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)

Returns

bool — true or false

distance_to_segment

XuAPI
pub fn distance_to_segment(px f64, py f64, x1 f64, y1 f64, x2 f64, y2 f64) f64

Purpose

Distance to segment.

Parameters

px f64
px (f64)
py f64
py (f64)
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)

Returns

f64 — a value of this type

point_near_segment

XuAPI
pub fn point_near_segment(px f64, py f64, x1 f64, y1 f64, x2 f64, y2 f64, tolerance f64) bool

Purpose

Point near segment.

Parameters

px f64
px (f64)
py f64
py (f64)
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
tolerance f64
tolerance (f64)

Returns

bool — true or false

point_near_polyline

XuAPI
pub fn point_near_polyline(px f64, py f64, points &[]PathPoint, tolerance f64) bool

Purpose

Point near polyline.

Parameters

px f64
px (f64)
py f64
py (f64)
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
tolerance f64
tolerance (f64)

Returns

bool — true or false

(&Path) flatten_subpaths

XuAPI
pub fn (path &Path) flatten_subpaths(tolerance f64) [][]PathPoint

Purpose

Flattens a Path into separate subpaths (one slice per move_to figure).

Parameters

path &Path
The Path instance used by this call (borrow).
tolerance f64
tolerance (f64)

Returns

[][]PathPoint — slice result

(&Path) flatten

XuAPI
pub fn (path &Path) flatten(tolerance f64) []PathPoint

Purpose

Flattens a Path into a polyline of anchor points by adaptive subdivision of curves.

Parameters

path &Path
The Path instance used by this call (borrow).
tolerance f64
tolerance (f64)

Returns

[]PathPoint — slice result

(&Path) contains_with_rule

XuAPI
pub fn (path &Path) contains_with_rule(px f64, py f64, rule int) bool

Purpose

Operation on &Path: contains with rule.

Parameters

path &Path
The Path instance used by this call (borrow).
px f64
px (f64)
py f64
py (f64)
rule int
rule (int)

Returns

bool — true or false

(&Path) contains

XuAPI
pub fn (path &Path) contains(px f64, py f64) bool

Purpose

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

Parameters

path &Path
The Path instance used by this call (borrow).
px f64
px (f64)
py f64
py (f64)

Returns

bool — true or false

(&Path) hit_stroke

XuAPI
pub fn (path &Path) hit_stroke(px f64, py f64, tolerance f64) bool

Purpose

Operation on &Path: hit stroke.

Parameters

path &Path
The Path instance used by this call (borrow).
px f64
px (f64)
py f64
py (f64)
tolerance f64
tolerance (f64)

Returns

bool — true or false

const SPREAD_PAD

XuAPI
pub const SPREAD_PAD = 0

Purpose

Constant SPREAD_PAD, defining protocol or algorithm parameters.

const SPREAD_REPEAT

XuAPI
pub const SPREAD_REPEAT = 1

Purpose

Constant SPREAD_REPEAT, defining protocol or algorithm parameters.

const SPREAD_REFLECT

XuAPI
pub const SPREAD_REFLECT = 2

Purpose

Constant SPREAD_REFLECT, defining protocol or algorithm parameters.

struct GradientStop

XuAPI
pub struct GradientStop {
    pub offset f64
    pub color Color
}

Purpose

Structure encapsulating offset, color.

Public fields

offset f64
offset
color Color
field (Color)

See usage example

struct Gradient

XuAPI
pub struct Gradient {
    pub spread int
    pub stops []GradientStop
}

Purpose

Structure encapsulating spread, stops.

Public fields

spread int
field (int)
stops []GradientStop
field ([]GradientStop)

linear_gradient

XuAPI
pub fn linear_gradient(x0 f64, y0 f64, x1 f64, y1 f64, stops []GradientStop) Gradient

Purpose

Linear gradient.

Parameters

x0 f64
x0 (f64)
y0 f64
y0 (f64)
x1 f64
x1 (f64)
y1 f64
y1 (f64)
stops []GradientStop
stops ([]GradientStop)

Returns

Gradient — a value of this type

See usage example

radial_gradient

XuAPI
pub fn radial_gradient(x f64, y f64, radius f64, stops []GradientStop) Gradient

Purpose

Radial gradient.

Parameters

x f64
value (f64)
y f64
value (f64)
radius f64
radius (f64)
stops []GradientStop
stops ([]GradientStop)

Returns

Gradient — a value of this type

(&Context) gradient

XuAPI
pub fn (context &Context) gradient(width f64, height f64, scale f64, paint &Gradient) Surface

Purpose

Rasterize once at explicit density, using pixel centers in logical units. 2...32 strictly increasing stops, first=0 and last=1. Interpolation uses premultiplied encoded sRGB; transparent stop RGB has no influence. This is a reusable raster paint layer; scaling it later samples its cached resolution. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
width f64
width (f64)
height f64
height (f64)
scale f64
scale (f64)
paint &Gradient
paint (read-only borrow; caller keeps the original; type &Gradient)

Returns

Surface — a value of this type

const SAMPLER_NEAREST

XuAPI
pub const SAMPLER_NEAREST = 0

Purpose

Constant SAMPLER_NEAREST, defining protocol or algorithm parameters.

See usage example

const SAMPLER_LINEAR

XuAPI
pub const SAMPLER_LINEAR = 1

Purpose

Constant SAMPLER_LINEAR, defining protocol or algorithm parameters.

See usage example

const MAX_IMAGE_BYTES

XuAPI
pub const MAX_IMAGE_BYTES = 67108864

Purpose

Constant MAX_IMAGE_BYTES, defining protocol or algorithm parameters.

const MAX_IMAGE_DIMENSION

XuAPI
pub const MAX_IMAGE_DIMENSION = 16384

Purpose

Constant MAX_IMAGE_DIMENSION, defining protocol or algorithm parameters.

struct Image

XuAPI
pub struct Image {
    pub width int
    pub height int
}

Purpose

A canvas-scoped resource. Explicitly dispose when no longer needed. Accepted frames retain immutable versions, so update/dispose cannot alter those frames.

Public fields

width int
field (int)
height int
field (int)

See usage example

struct ImageRect

XuAPI
pub struct ImageRect {
    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

(&Context) image_rgba

XuAPI
pub fn (context &Context) image_rgba(width int, height int, stride int, data &string) Image

Purpose

Top-left, straight sRGB RGBA8. stride=0 means width*4; otherwise include every row's padding in data. Input is borrowed; the native resource owns its copy. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
width int
width (int)
height int
height (int)
stride int
stride (int)
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

Image — a value of this type

(&Context) image_pixels

XuAPI
pub fn (context &Context) image_pixels(bitmap &image.RGBA) Image

Purpose

Interoperate with #image's CPU pixel buffers, including nonzero rect origins. These are the same straight RGBA8 bytes used by its PNG/JPEG decoder paths. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
bitmap &image.RGBA
bitmap (read-only borrow; caller keeps the original; type &image.RGBA)

Returns

Image — a value of this type

(&Context) image_encoded

XuAPI
pub fn (context &Context) image_encoded(data &string) Image

Purpose

Decode PNG/JPEG once at load time. Palette/gray/interlaced PNG and progressive JPEG share the same bounded native decoder on all three hosts. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

Image — a value of this type

(&Context) load_image

XuAPI
pub fn (context &Context) load_image(path &string) Image

Purpose

Bounded native file read; Windows paths are UTF-8 and opened with CreateFileW. Only regular files up to 64 MiB are accepted. The input buffer also counts toward the shared decoder scratch budget while decoding. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
path &string
filesystem path (read-only borrow; caller keeps the original; type &string)

Returns

Image — a value of this type

(&Context) load_embedded_image

XuAPI
pub fn (context &Context) load_embedded_image(path &string) Image

Purpose

Operation on &Context: load embedded image. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
path &string
filesystem path (read-only borrow; caller keeps the original; type &string)

Returns

Image — a value of this type

(&Image) update_rgba

XuAPI
pub fn (image &Image) update_rgba(stride int, data &string) int

Purpose

Same dimensions, new immutable version. Existing accepted frames keep their old pixels; the next successful present captures the new version. Throws on failure; handle the error or propagate it to the caller.

Parameters

image &Image
The Image instance used by this call (borrow).
stride int
stride (int)
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

int — a value of this type

($&Image) dispose

XuAPI
pub fn (image $&Image) dispose() int

Purpose

Release and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.

Parameters

image $&Image
The Image instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Image) close

XuAPI
pub fn (image $&Image) close() int

Purpose

Operation on $&Image: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

image $&Image
The Image instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) image_region

XuAPI
pub fn (frame $&Frame) image_region(image &Image, source &ImageRect, destination &ImageRect, opacity f64, sampler int) int

Purpose

Source coordinates are pixels; destination coordinates follow the frame CTM. Opacity is 0...1; sampler_nearest/linear are explicit and portable. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
image &Image
image (read-only borrow; caller keeps the original; type &Image)
source &ImageRect
source (read-only borrow; caller keeps the original; type &ImageRect)
destination &ImageRect
destination (read-only borrow; caller keeps the original; type &ImageRect)
opacity f64
opacity (f64)
sampler int
sampler (int)

Returns

int — a value of this type

($&Frame) image

XuAPI
pub fn (frame $&Frame) image(image &Image, x f64, y f64, width f64, height f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
image &Image
image (read-only borrow; caller keeps the original; type &Image)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)

Returns

int — a value of this type

const MAX_LAYER_DEPTH

XuAPI
pub const MAX_LAYER_DEPTH = 16

Purpose

Constant MAX_LAYER_DEPTH, defining protocol or algorithm parameters.

($&Frame) begin_layer

XuAPI
pub fn (frame $&Frame) begin_layer(bounds &ImageRect, scale f64, opacity f64) int

Purpose

Isolated transparent child frame, with its own white pen, identity CTM and [0,width]x[0,height] bounds. Parent state/clip are restored at end_layer and apply to the resulting image at (x,y). Rasterization occurs once at end_layer. begin/cancel/dispose discard every open child and owned temporary resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
bounds &ImageRect
bounds (read-only borrow; caller keeps the original; type &ImageRect)
scale f64
scale (f64)
opacity f64
opacity (f64)

Returns

int — a value of this type

($&Frame) end_layer

XuAPI
pub fn (frame $&Frame) end_layer() int

Purpose

Operation on $&Frame: end layer. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) dispose

XuAPI
pub fn (frame $&Frame) dispose()

Purpose

A Frame can own transient native images after end_layer/gradient fills. Explicitly retire a recorder that will not be presented or reused.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Frame) close

XuAPI
pub fn (frame $&Frame) close()

Purpose

Operation on $&Frame: close the resource.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).

Returns

This call does not return a value.

struct Matrix2D

XuAPI
pub struct Matrix2D {
    pub a f64
    pub b f64
    pub c f64
    pub d f64
    pub tx f64
    pub ty f64
}

Purpose

2D affine transformation matrix [ a c tx ] [ b d ty ] [ 0 0 1 ]

Public fields

a f64
field (f64)
b f64
field (f64)
c f64
byte or character code
d f64
field (f64)
tx f64
field (f64)
ty f64
field (f64)

identity_matrix

XuAPI
pub fn identity_matrix() Matrix2D

Purpose

Identity matrix.

Parameters

No arguments are required.

Returns

Matrix2D — a value of this type

translation_matrix

XuAPI
pub fn translation_matrix(tx f64, ty f64) Matrix2D

Purpose

Translation matrix.

Parameters

tx f64
tx (f64)
ty f64
ty (f64)

Returns

Matrix2D — a value of this type

scaling_matrix

XuAPI
pub fn scaling_matrix(sx f64, sy f64) Matrix2D

Purpose

Scaling matrix.

Parameters

sx f64
sx (f64)
sy f64
sy (f64)

Returns

Matrix2D — a value of this type

rotation_matrix

XuAPI
pub fn rotation_matrix(degrees f64) Matrix2D

Purpose

Rotation matrix.

Parameters

degrees f64
degrees (f64)

Returns

Matrix2D — a value of this type

skew_matrix

XuAPI
pub fn skew_matrix(skew_x_deg f64, skew_y_deg f64) Matrix2D

Purpose

Skew matrix.

Parameters

skew_x_deg f64
skew_x_deg (f64)
skew_y_deg f64
skew_y_deg (f64)

Returns

Matrix2D — a value of this type

(&Matrix2D) multiply

XuAPI
pub fn (m &Matrix2D) multiply(other &Matrix2D) Matrix2D

Purpose

Execute multiply on &Matrix2D.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).
other &Matrix2D
the other value of the same type (read-only borrow; caller keeps the original; type &Matrix2D)

Returns

Matrix2D — a value of this type

(&Matrix2D) translate

XuAPI
pub fn (m &Matrix2D) translate(tx f64, ty f64) Matrix2D

Purpose

Execute translate on &Matrix2D.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).
tx f64
tx (f64)
ty f64
ty (f64)

Returns

Matrix2D — a value of this type

(&Matrix2D) scale

XuAPI
pub fn (m &Matrix2D) scale(sx f64, sy f64) Matrix2D

Purpose

Execute scale on &Matrix2D.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).
sx f64
sx (f64)
sy f64
sy (f64)

Returns

Matrix2D — a value of this type

(&Matrix2D) rotate

XuAPI
pub fn (m &Matrix2D) rotate(degrees f64) Matrix2D

Purpose

Execute rotate on &Matrix2D.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).
degrees f64
degrees (f64)

Returns

Matrix2D — a value of this type

(&Matrix2D) determinant

XuAPI
pub fn (m &Matrix2D) determinant() f64

Purpose

Execute determinant on &Matrix2D.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).

Returns

f64 — a value of this type

(&Matrix2D) is_invertible

XuAPI
pub fn (m &Matrix2D) is_invertible() bool

Purpose

Operation on &Matrix2D: whether it is invertible.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).

Returns

bool — true or false

(&Matrix2D) inverse

XuAPI
pub fn (m &Matrix2D) inverse() Matrix2D

Purpose

Execute inverse on &Matrix2D. Throws on failure; handle the error or propagate it to the caller.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).

Returns

Matrix2D — a value of this type

(&Matrix2D) map_point

XuAPI
pub fn (m &Matrix2D) map_point(x f64, y f64) PathPoint

Purpose

Operation on &Matrix2D: map point.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).
x f64
value (f64)
y f64
value (f64)

Returns

PathPoint — a value of this type

(&Matrix2D) map_bounds

XuAPI
pub fn (m &Matrix2D) map_bounds(rect &ImageRect) ImageRect

Purpose

Operation on &Matrix2D: map bounds.

Parameters

m &Matrix2D
The Matrix2D instance used by this call (borrow).
rect &ImageRect
rect (read-only borrow; caller keeps the original; type &ImageRect)

Returns

ImageRect — a value of this type

($&Frame) rotate_around

XuAPI
pub fn (frame $&Frame) rotate_around(cx f64, cy f64, degrees f64) int

Purpose

Operation on $&Frame: rotate around. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
degrees f64
degrees (f64)

Returns

int — a value of this type

($&Frame) scale_around

XuAPI
pub fn (frame $&Frame) scale_around(cx f64, cy f64, sx f64, sy f64) int

Purpose

Operation on $&Frame: scale around. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
sx f64
sx (f64)
sy f64
sy (f64)

Returns

int — a value of this type

(&Path) clone

XuAPI
pub fn (path &Path) clone() Path

Purpose

Operation on &Path: copy into a new independent string.

Parameters

path &Path
The Path instance used by this call (borrow).

Returns

Path — a value of this type

($&Path) append_transformed

XuAPI
pub fn (path $&Path) append_transformed(other &Path, m &Matrix2D) int

Purpose

Operation on $&Path: append transformed. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
other &Path
the other value of the same type (read-only borrow; caller keeps the original; type &Path)
m &Matrix2D
m (read-only borrow; caller keeps the original; type &Matrix2D)

Returns

int — a value of this type

($&Path) append

XuAPI
pub fn (path $&Path) append(other &Path) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
other &Path
the other value of the same type (read-only borrow; caller keeps the original; type &Path)

Returns

int — a value of this type

($&Path) transform

XuAPI
pub fn (path $&Path) transform(m &Matrix2D) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
m &Matrix2D
m (read-only borrow; caller keeps the original; type &Matrix2D)

Returns

int — a value of this type

($&Path) translate

XuAPI
pub fn (path $&Path) translate(dx f64, dy f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
dx f64
dx (f64)
dy f64
dy (f64)

Returns

int — a value of this type

($&Path) scale

XuAPI
pub fn (path $&Path) scale(sx f64, sy f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
sx f64
sx (f64)
sy f64
sy (f64)

Returns

int — a value of this type

($&Path) rotate

XuAPI
pub fn (path $&Path) rotate(degrees f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
degrees f64
degrees (f64)

Returns

int — a value of this type

($&Path) rotate_around

XuAPI
pub fn (path $&Path) rotate_around(cx f64, cy f64, degrees f64) int

Purpose

Operation on $&Path: rotate around. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
degrees f64
degrees (f64)

Returns

int — a value of this type

(&Path) bounds

XuAPI
pub fn (path &Path) bounds() ImageRect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

path &Path
The Path instance used by this call (borrow).

Returns

ImageRect — a value of this type

(&Path) tight_bounds

XuAPI
pub fn (path &Path) tight_bounds() ImageRect

Purpose

Operation on &Path: tight bounds.

Parameters

path &Path
The Path instance used by this call (borrow).

Returns

ImageRect — a value of this type

const PALETTE_VIRIDIS

XuAPI
pub const PALETTE_VIRIDIS = 0

Purpose

Constant PALETTE_VIRIDIS, defining protocol or algorithm parameters.

See usage example

const PALETTE_PLASMA

XuAPI
pub const PALETTE_PLASMA = 1

Purpose

Constant PALETTE_PLASMA, defining protocol or algorithm parameters.

const PALETTE_COOLWARM

XuAPI
pub const PALETTE_COOLWARM = 2

Purpose

Constant PALETTE_COOLWARM, defining protocol or algorithm parameters.

const PALETTE_OCEAN

XuAPI
pub const PALETTE_OCEAN = 3

Purpose

Constant PALETTE_OCEAN, defining protocol or algorithm parameters.

const PALETTE_SUNSET

XuAPI
pub const PALETTE_SUNSET = 4

Purpose

Constant PALETTE_SUNSET, defining protocol or algorithm parameters.

const PALETTE_FOREST

XuAPI
pub const PALETTE_FOREST = 5

Purpose

Constant PALETTE_FOREST, defining protocol or algorithm parameters.

palette_colors

XuAPI
pub fn palette_colors(kind int) []Color

Purpose

Palette colors.

Parameters

kind int
kind tag (int)

Returns

[]Color — slice result

sample_color_stops

XuAPI
pub fn sample_color_stops(colors &[]Color, t f64) Color

Purpose

Sample color stops.

Parameters

colors &[]Color
colors (read-only borrow; caller keeps the original; type &[]Color)
t f64
t (f64)

Returns

Color — a value of this type

sample_palette

XuAPI
pub fn sample_palette(kind int, t f64) Color

Purpose

Sample palette.

Parameters

kind int
kind tag (int)
t f64
t (f64)

Returns

Color — a value of this type

See usage example

multi_stop_linear

XuAPI
pub fn multi_stop_linear(x0 f64, y0 f64, x1 f64, y1 f64, colors &[]Color) Gradient

Purpose

Multi stop linear. Throws on failure; handle the error or propagate it to the caller.

Parameters

x0 f64
x0 (f64)
y0 f64
y0 (f64)
x1 f64
x1 (f64)
y1 f64
y1 (f64)
colors &[]Color
colors (read-only borrow; caller keeps the original; type &[]Color)

Returns

Gradient — a value of this type

multi_stop_radial

XuAPI
pub fn multi_stop_radial(cx f64, cy f64, radius f64, colors &[]Color) Gradient

Purpose

Multi stop radial. Throws on failure; handle the error or propagate it to the caller.

Parameters

cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
colors &[]Color
colors (read-only borrow; caller keeps the original; type &[]Color)

Returns

Gradient — a value of this type

const MAX_PATH_BYTES

XuAPI
pub const MAX_PATH_BYTES = 2097152

Purpose

Constant MAX_PATH_BYTES, defining protocol or algorithm parameters.

const MAX_PATH_SEGMENTS

XuAPI
pub const MAX_PATH_SEGMENTS = 32768

Purpose

Constant MAX_PATH_SEGMENTS, defining protocol or algorithm parameters.

const FILL_NONZERO

XuAPI
pub const FILL_NONZERO = 0

Purpose

Constant FILL_NONZERO, defining protocol or algorithm parameters.

See usage example

const FILL_EVENODD

XuAPI
pub const FILL_EVENODD = 1

Purpose

Constant FILL_EVENODD, defining protocol or algorithm parameters.

const CAP_BUTT

XuAPI
pub const CAP_BUTT = 0

Purpose

Constant CAP_BUTT, defining protocol or algorithm parameters.

const CAP_ROUND

XuAPI
pub const CAP_ROUND = 1

Purpose

Constant CAP_ROUND, defining protocol or algorithm parameters.

const CAP_SQUARE

XuAPI
pub const CAP_SQUARE = 2

Purpose

Constant CAP_SQUARE, defining protocol or algorithm parameters.

const JOIN_MITER

XuAPI
pub const JOIN_MITER = 0

Purpose

Constant JOIN_MITER, defining protocol or algorithm parameters.

const JOIN_ROUND

XuAPI
pub const JOIN_ROUND = 1

Purpose

Constant JOIN_ROUND, defining protocol or algorithm parameters.

const JOIN_BEVEL

XuAPI
pub const JOIN_BEVEL = 2

Purpose

Constant JOIN_BEVEL, defining protocol or algorithm parameters.

struct Path

XuAPI
pub struct Path {

}

Purpose

Reusable CPU recorder. A failed operation poisons the path until clear. Frame operations copy a snapshot, so later edits cannot alter recorded work.

Public fields

This type has no public fields.

new_path

XuAPI
pub fn new_path(capacity int) Path

Purpose

Construct path.

Parameters

capacity int
capacity (int)

Returns

Path — a value of this type

See usage example

($&Path) clear

XuAPI
pub fn (path $&Path) clear()

Purpose

Clear all buffered or stored entries and internal state.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Path) byte_len

XuAPI
pub fn (path &Path) byte_len() int

Purpose

Operation on &Path: byte len.

Parameters

path &Path
The Path instance used by this call (borrow).

Returns

int — a value of this type

(&Path) capacity

XuAPI
pub fn (path &Path) capacity() int

Purpose

Execute capacity on &Path.

Parameters

path &Path
The Path instance used by this call (borrow).

Returns

int — a value of this type

(&Path) segment_count

XuAPI
pub fn (path &Path) segment_count() int

Purpose

Operation on &Path: segment count.

Parameters

path &Path
The Path instance used by this call (borrow).

Returns

int — a value of this type

($&Path) move_to

XuAPI
pub fn (path $&Path) move_to(x f64, y f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

($&Path) line_to

XuAPI
pub fn (path $&Path) line_to(x f64, y f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

($&Path) quad_to

XuAPI
pub fn (path $&Path) quad_to(cx f64, cy f64, x f64, y f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

($&Path) cubic_to

XuAPI
pub fn (path $&Path) cubic_to(c1x f64, c1y f64, c2x f64, c2y f64, x f64, y f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
c1x f64
c1x (f64)
c1y f64
c1y (f64)
c2x f64
c2x (f64)
c2y f64
c2y (f64)
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

($&Path) close

XuAPI
pub fn (path $&Path) close() int

Purpose

Ends this figure. Start another with move_to before adding more segments. Filling implicitly closes open figures; stroking preserves their open ends. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).

Returns

int — a value of this type

struct StrokeOptions

XuAPI
pub struct StrokeOptions {
    pub width f64
    pub cap int
    pub join int
    pub miter_limit f64
    pub dashes []f64
    pub dash_offset f64
    pub flatten_tolerance f64
}

Purpose

Draw Configuration parameters and options set.

Public fields

width f64
field (f64)
cap int
field (int)
join int
field (int)
miter_limit f64
field (f64)
dashes []f64
field ([]f64)
dash_offset f64
field (f64)
flatten_tolerance f64
Logical-unit error bound for the shared curved-dash approximation. Continuous curves stay native. Reduce this when magnifying a path.

stroke_options

XuAPI
pub fn stroke_options(width f64) StrokeOptions

Purpose

Stroke options.

Parameters

width f64
width (f64)

Returns

StrokeOptions — a value of this type

See usage example

($&Frame) fill_path

XuAPI
pub fn (frame $&Frame) fill_path(path &Path, color Color, rule int) int

Purpose

Operation on $&Frame: fill path. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
path &Path
filesystem path (read-only borrow; caller keeps the original; type &Path)
color Color
color (Color)
rule int
rule (int)

Returns

int — a value of this type

($&Frame) stroke_path

XuAPI
pub fn (frame $&Frame) stroke_path(path &Path, color Color, style &StrokeOptions) int

Purpose

Dash lengths are positive, even-count on/off pairs in logical units. Phase restarts for each figure. Cap/join apply to generated dash figures too. Host admission rejects excessive flattening/dash work atomically; no partial path is displayed, and the previous scene remains intact. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
path &Path
filesystem path (read-only borrow; caller keeps the original; type &Path)
color Color
color (Color)
style &StrokeOptions
style (read-only borrow; caller keeps the original; type &StrokeOptions)

Returns

int — a value of this type

const DIR_UP

XuAPI
pub const DIR_UP = 0

Purpose

Constant DIR_UP, defining protocol or algorithm parameters.

const DIR_RIGHT

XuAPI
pub const DIR_RIGHT = 1

Purpose

Constant DIR_RIGHT, defining protocol or algorithm parameters.

const DIR_DOWN

XuAPI
pub const DIR_DOWN = 2

Purpose

Constant DIR_DOWN, defining protocol or algorithm parameters.

const DIR_LEFT

XuAPI
pub const DIR_LEFT = 3

Purpose

Constant DIR_LEFT, defining protocol or algorithm parameters.

($&Path) smooth_spline

XuAPI
pub fn (path $&Path) smooth_spline(points &[]PathPoint, tension f64, closed bool) int

Purpose

C1-continuous Cardinal / Catmull-Rom spline converted to cubic Beziers. tension=0 produces a standard Catmull-Rom spline; tension=1 produces lines. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
tension f64
tension (f64)
closed bool
closed (bool)

Returns

int — a value of this type

($&Frame) smooth_curve

XuAPI
pub fn (frame $&Frame) smooth_curve(points &[]PathPoint, tension f64, color Color, width f64) int

Purpose

Operation on $&Frame: smooth curve. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
tension f64
tension (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_smooth_closed

XuAPI
pub fn (frame $&Frame) fill_smooth_closed(points &[]PathPoint, tension f64, color Color) int

Purpose

Operation on $&Frame: fill smooth closed. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
tension f64
tension (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_smooth_closed

XuAPI
pub fn (frame $&Frame) stroke_smooth_closed(points &[]PathPoint, tension f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke smooth closed. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
tension f64
tension (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) rounded_polyline

XuAPI
pub fn (path $&Path) rounded_polyline(points &[]PathPoint, radius f64) int

Purpose

Operation on $&Path: rounded polyline. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
radius f64
radius (f64)

Returns

int — a value of this type

($&Path) rounded_polygon

XuAPI
pub fn (path $&Path) rounded_polygon(points &[]PathPoint, radius f64) int

Purpose

Operation on $&Path: rounded polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
radius f64
radius (f64)

Returns

int — a value of this type

($&Frame) rounded_polyline

XuAPI
pub fn (frame $&Frame) rounded_polyline(points &[]PathPoint, radius f64, color Color, width f64) int

Purpose

Operation on $&Frame: rounded polyline. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
radius f64
radius (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_rounded_polygon

XuAPI
pub fn (frame $&Frame) fill_rounded_polygon(points &[]PathPoint, radius f64, color Color) int

Purpose

Operation on $&Frame: fill rounded polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
radius f64
radius (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_rounded_polygon

XuAPI
pub fn (frame $&Frame) stroke_rounded_polygon(points &[]PathPoint, radius f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke rounded polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
radius f64
radius (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) ring

XuAPI
pub fn (path $&Path) ring(cx f64, cy f64, inner_radius f64, outer_radius f64) int

Purpose

Full 360-degree annular ring using opposite winding subpaths. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
inner_radius f64
inner_radius (f64)
outer_radius f64
outer_radius (f64)

Returns

int — a value of this type

($&Frame) fill_ring

XuAPI
pub fn (frame $&Frame) fill_ring(cx f64, cy f64, inner_radius f64, outer_radius f64, color Color) int

Purpose

Operation on $&Frame: fill ring. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
inner_radius f64
inner_radius (f64)
outer_radius f64
outer_radius (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_ring

XuAPI
pub fn (frame $&Frame) stroke_ring(cx f64, cy f64, inner_radius f64, outer_radius f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke ring. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
inner_radius f64
inner_radius (f64)
outer_radius f64
outer_radius (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) wave

XuAPI
pub fn (path $&Path) wave(x f64, y f64, width f64, amplitude f64, wavelength f64, phase_deg f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
amplitude f64
amplitude (f64)
wavelength f64
wavelength (f64)
phase_deg f64
phase_deg (f64)

Returns

int — a value of this type

($&Frame) wave

XuAPI
pub fn (frame $&Frame) wave(x f64, y f64, width f64, amplitude f64, wavelength f64, phase_deg f64, color Color, line_width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
amplitude f64
amplitude (f64)
wavelength f64
wavelength (f64)
phase_deg f64
phase_deg (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Path) cross

XuAPI
pub fn (path $&Path) cross(cx f64, cy f64, size f64, thickness f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
size f64
size (f64)
thickness f64
thickness (f64)

Returns

int — a value of this type

($&Frame) fill_cross

XuAPI
pub fn (frame $&Frame) fill_cross(cx f64, cy f64, size f64, thickness f64, color Color) int

Purpose

Operation on $&Frame: fill cross. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
size f64
size (f64)
thickness f64
thickness (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_cross

XuAPI
pub fn (frame $&Frame) stroke_cross(cx f64, cy f64, size f64, thickness f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke cross. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
size f64
size (f64)
thickness f64
thickness (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) checkmark

XuAPI
pub fn (path $&Path) checkmark(x f64, y f64, size f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
size f64
size (f64)

Returns

int — a value of this type

($&Frame) checkmark

XuAPI
pub fn (frame $&Frame) checkmark(x f64, y f64, size f64, color Color, width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
size f64
size (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) chevron

XuAPI
pub fn (path $&Path) chevron(x f64, y f64, width f64, height f64, direction int) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
direction int
direction (int)

Returns

int — a value of this type

($&Frame) chevron

XuAPI
pub fn (frame $&Frame) chevron(x f64, y f64, width f64, height f64, direction int, color Color, line_width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
direction int
direction (int)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) double_arrow

XuAPI
pub fn (frame $&Frame) double_arrow(x1 f64, y1 f64, x2 f64, y2 f64, head_size f64, color Color, width f64) int

Purpose

Operation on $&Frame: double arrow. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
head_size f64
head_size (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

bezier_kappa

XuAPI
pub fn bezier_kappa() f64

Purpose

Bezier kappa.

Parameters

No arguments are required.

Returns

f64 — a value of this type

deg_to_rad

XuAPI
pub fn deg_to_rad() f64

Purpose

Deg to rad.

Parameters

No arguments are required.

Returns

f64 — a value of this type

struct PathPoint

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

Purpose

Structure encapsulating x, y.

Public fields

x f64
value
y f64
value

path_point

XuAPI
pub fn path_point(x f64, y f64) PathPoint

Purpose

Path point.

Parameters

x f64
value (f64)
y f64
value (f64)

Returns

PathPoint — a value of this type

See usage example

($&Path) rect

XuAPI
pub fn (path $&Path) rect(x f64, y f64, width f64, height f64) int

Purpose

Operation on $&Path: draw or fill a rectangle on the canvas. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)

Returns

int — a value of this type

($&Path) round_rect_corners

XuAPI
pub fn (path $&Path) round_rect_corners(x f64, y f64, width f64, height f64, tl f64, tr f64, br f64, bl f64) int

Purpose

Operation on $&Path: round rectangle corners. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
tl f64
tl (f64)
tr f64
tr (f64)
br f64
br (f64)
bl f64
bl (f64)

Returns

int — a value of this type

($&Path) round_rect

XuAPI
pub fn (path $&Path) round_rect(x f64, y f64, width f64, height f64, radius f64) int

Purpose

Operation on $&Path: round rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)

Returns

int — a value of this type

($&Path) capsule

XuAPI
pub fn (path $&Path) capsule(x f64, y f64, width f64, height f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)

Returns

int — a value of this type

($&Path) ellipse

XuAPI
pub fn (path $&Path) ellipse(cx f64, cy f64, rx f64, ry f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)

Returns

int — a value of this type

($&Path) circle

XuAPI
pub fn (path $&Path) circle(cx f64, cy f64, radius f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)

Returns

int — a value of this type

($&Path) diamond

XuAPI
pub fn (path $&Path) diamond(cx f64, cy f64, rx f64, ry f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)

Returns

int — a value of this type

($&Path) ellipse_arc

XuAPI
pub fn (path $&Path) ellipse_arc(cx f64, cy f64, rx f64, ry f64, start_deg f64, sweep_deg f64) int

Purpose

Operation on $&Path: ellipse arc. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)

Returns

int — a value of this type

($&Path) arc

XuAPI
pub fn (path $&Path) arc(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)

Returns

int — a value of this type

($&Path) sector

XuAPI
pub fn (path $&Path) sector(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)

Returns

int — a value of this type

($&Path) ring_sector

XuAPI
pub fn (path $&Path) ring_sector(cx f64, cy f64, inner_radius f64, outer_radius f64, start_deg f64, sweep_deg f64) int

Purpose

Operation on $&Path: ring sector. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
inner_radius f64
inner_radius (f64)
outer_radius f64
outer_radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)

Returns

int — a value of this type

($&Path) polyline

XuAPI
pub fn (path $&Path) polyline(points &[]PathPoint) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)

Returns

int — a value of this type

($&Path) polygon

XuAPI
pub fn (path $&Path) polygon(points &[]PathPoint) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)

Returns

int — a value of this type

($&Path) regular_polygon

XuAPI
pub fn (path $&Path) regular_polygon(cx f64, cy f64, radius f64, sides int, rotation_deg f64) int

Purpose

Operation on $&Path: regular polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
sides int
sides (int)
rotation_deg f64
rotation_deg (f64)

Returns

int — a value of this type

($&Path) star

XuAPI
pub fn (path $&Path) star(cx f64, cy f64, outer_radius f64, inner_radius f64, points int, rotation_deg f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
outer_radius f64
outer_radius (f64)
inner_radius f64
inner_radius (f64)
points int
points (int)
rotation_deg f64
rotation_deg (f64)

Returns

int — a value of this type

($&Path) callout

XuAPI
pub fn (path $&Path) callout(x f64, y f64, width f64, height f64, radius f64, side int, tail_pos f64, tail_width f64, tail_height f64) int

Purpose

Speech bubble / tooltip callout box with a pointer tail on DIR_UP, DIR_RIGHT, DIR_DOWN, or DIR_LEFT. tail_pos in [0, 1] positions the tail along the chosen edge. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
side int
side (int)
tail_pos f64
tail_pos (f64)
tail_width f64
tail_width (f64)
tail_height f64
tail_height (f64)

Returns

int — a value of this type

($&Frame) fill_callout

XuAPI
pub fn (frame $&Frame) fill_callout(x f64, y f64, width f64, height f64, radius f64, side int, tail_pos f64, tail_width f64, tail_height f64, color Color) int

Purpose

Operation on $&Frame: fill callout. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
side int
side (int)
tail_pos f64
tail_pos (f64)
tail_width f64
tail_width (f64)
tail_height f64
tail_height (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_callout

XuAPI
pub fn (frame $&Frame) stroke_callout(x f64, y f64, width f64, height f64, radius f64, side int, tail_pos f64, tail_width f64, tail_height f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: stroke callout. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
side int
side (int)
tail_pos f64
tail_pos (f64)
tail_width f64
tail_width (f64)
tail_height f64
tail_height (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Path) ribbon

XuAPI
pub fn (path $&Path) ribbon(x1 f64, y1_top f64, y1_bot f64, x2 f64, y2_top f64, y2_bot f64) int

Purpose

Horizontal cubic Bezier Sankey / flow ribbon connecting [x1, y1_top..y1_bot] to [x2, y2_top..y2_bot]. Throws on failure; handle the error or propagate it to the caller.

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1_top f64
y1_top (f64)
y1_bot f64
y1_bot (f64)
x2 f64
x2 (f64)
y2_top f64
y2_top (f64)
y2_bot f64
y2_bot (f64)

Returns

int — a value of this type

($&Frame) fill_ribbon

XuAPI
pub fn (frame $&Frame) fill_ribbon(x1 f64, y1_top f64, y1_bot f64, x2 f64, y2_top f64, y2_bot f64, color Color) int

Purpose

Operation on $&Frame: fill ribbon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1_top f64
y1_top (f64)
y1_bot f64
y1_bot (f64)
x2 f64
x2 (f64)
y2_top f64
y2_top (f64)
y2_bot f64
y2_bot (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_ribbon

XuAPI
pub fn (frame $&Frame) stroke_ribbon(x1 f64, y1_top f64, y1_bot f64, x2 f64, y2_top f64, y2_bot f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke ribbon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1_top f64
y1_top (f64)
y1_bot f64
y1_bot (f64)
x2 f64
x2 (f64)
y2_top f64
y2_top (f64)
y2_bot f64
y2_bot (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) heart

XuAPI
pub fn (path $&Path) heart(cx f64, cy f64, size f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
size f64
size (f64)

Returns

int — a value of this type

($&Frame) fill_heart

XuAPI
pub fn (frame $&Frame) fill_heart(cx f64, cy f64, size f64, color Color) int

Purpose

Operation on $&Frame: fill heart. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
size f64
size (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_heart

XuAPI
pub fn (frame $&Frame) stroke_heart(cx f64, cy f64, size f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke heart. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
size f64
size (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) shield

XuAPI
pub fn (path $&Path) shield(cx f64, cy f64, width f64, height f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
width f64
width (f64)
height f64
height (f64)

Returns

int — a value of this type

($&Frame) fill_shield

XuAPI
pub fn (frame $&Frame) fill_shield(cx f64, cy f64, width f64, height f64, color Color) int

Purpose

Operation on $&Frame: fill shield. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
width f64
width (f64)
height f64
height (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_shield

XuAPI
pub fn (frame $&Frame) stroke_shield(cx f64, cy f64, width f64, height f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: stroke shield. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
width f64
width (f64)
height f64
height (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Path) gear

XuAPI
pub fn (path $&Path) gear(cx f64, cy f64, outer_radius f64, inner_radius f64, hole_radius f64, teeth int) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
outer_radius f64
outer_radius (f64)
inner_radius f64
inner_radius (f64)
hole_radius f64
hole_radius (f64)
teeth int
teeth (int)

Returns

int — a value of this type

($&Frame) fill_gear

XuAPI
pub fn (frame $&Frame) fill_gear(cx f64, cy f64, outer_radius f64, inner_radius f64, hole_radius f64, teeth int, color Color) int

Purpose

Operation on $&Frame: fill gear. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
outer_radius f64
outer_radius (f64)
inner_radius f64
inner_radius (f64)
hole_radius f64
hole_radius (f64)
teeth int
teeth (int)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_gear

XuAPI
pub fn (frame $&Frame) stroke_gear(cx f64, cy f64, outer_radius f64, inner_radius f64, hole_radius f64, teeth int, color Color, width f64) int

Purpose

Operation on $&Frame: stroke gear. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
outer_radius f64
outer_radius (f64)
inner_radius f64
inner_radius (f64)
hole_radius f64
hole_radius (f64)
teeth int
teeth (int)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Path) spiral

XuAPI
pub fn (path $&Path) spiral(cx f64, cy f64, start_radius f64, end_radius f64, turns f64, rotation_deg f64) int

Purpose

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

Parameters

path $&Path
The Path instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
start_radius f64
start_radius (f64)
end_radius f64
end_radius (f64)
turns f64
turns (f64)
rotation_deg f64
rotation_deg (f64)

Returns

int — a value of this type

($&Frame) spiral

XuAPI
pub fn (frame $&Frame) spiral(cx f64, cy f64, start_radius f64, end_radius f64, turns f64, rotation_deg f64, color Color, width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
start_radius f64
start_radius (f64)
end_radius f64
end_radius (f64)
turns f64
turns (f64)
rotation_deg f64
rotation_deg (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) hatch_rect

XuAPI
pub fn (frame $&Frame) hatch_rect(x f64, y f64, width f64, height f64, spacing f64, reverse bool, color Color, line_width f64) int

Purpose

Clipped diagonal hatch lines inside [x, y, width, height]. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
spacing f64
spacing (f64)
reverse bool
reverse (bool)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) cross_hatch_rect

XuAPI
pub fn (frame $&Frame) cross_hatch_rect(x f64, y f64, width f64, height f64, spacing f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: cross hatch rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
spacing f64
spacing (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) dot_grid

XuAPI
pub fn (frame $&Frame) dot_grid(x f64, y f64, width f64, height f64, spacing f64, dot_radius f64, color Color) int

Purpose

Operation on $&Frame: dot grid. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
spacing f64
spacing (f64)
dot_radius f64
dot_radius (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) fill_circle

XuAPI
pub fn (frame $&Frame) fill_circle(cx f64, cy f64, radius f64, color Color) int

Purpose

Operation on $&Frame: fill circle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_circle

XuAPI
pub fn (frame $&Frame) stroke_circle(cx f64, cy f64, radius f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke circle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_ellipse

XuAPI
pub fn (frame $&Frame) fill_ellipse(cx f64, cy f64, rx f64, ry f64, color Color) int

Purpose

Operation on $&Frame: fill ellipse. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_ellipse

XuAPI
pub fn (frame $&Frame) stroke_ellipse(cx f64, cy f64, rx f64, ry f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke ellipse. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_triangle

XuAPI
pub fn (frame $&Frame) fill_triangle(x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64, color Color) int

Purpose

Operation on $&Frame: fill triangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
x3 f64
x3 (f64)
y3 f64
y3 (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_triangle

XuAPI
pub fn (frame $&Frame) stroke_triangle(x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke triangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
x3 f64
x3 (f64)
y3 f64
y3 (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_round_rect_corners

XuAPI
pub fn (frame $&Frame) fill_round_rect_corners(x f64, y f64, width f64, height f64, tl f64, tr f64, br f64, bl f64, color Color) int

Purpose

Operation on $&Frame: fill round rectangle corners. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
tl f64
tl (f64)
tr f64
tr (f64)
br f64
br (f64)
bl f64
bl (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_round_rect_corners

XuAPI
pub fn (frame $&Frame) stroke_round_rect_corners(x f64, y f64, width f64, height f64, tl f64, tr f64, br f64, bl f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: stroke round rectangle corners. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
tl f64
tl (f64)
tr f64
tr (f64)
br f64
br (f64)
bl f64
bl (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) fill_round_rect

XuAPI
pub fn (frame $&Frame) fill_round_rect(x f64, y f64, width f64, height f64, radius f64, color Color) int

Purpose

Operation on $&Frame: fill round rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_round_rect

XuAPI
pub fn (frame $&Frame) stroke_round_rect(x f64, y f64, width f64, height f64, radius f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: stroke round rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) round_rect

XuAPI
pub fn (frame $&Frame) round_rect(x f64, y f64, width f64, height f64, radius f64, color Color) int

Purpose

Operation on $&Frame: round rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) fill_capsule

XuAPI
pub fn (frame $&Frame) fill_capsule(x f64, y f64, width f64, height f64, color Color) int

Purpose

Operation on $&Frame: fill capsule. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_capsule

XuAPI
pub fn (frame $&Frame) stroke_capsule(x f64, y f64, width f64, height f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: stroke capsule. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) fill_diamond

XuAPI
pub fn (frame $&Frame) fill_diamond(cx f64, cy f64, rx f64, ry f64, color Color) int

Purpose

Operation on $&Frame: fill diamond. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_diamond

XuAPI
pub fn (frame $&Frame) stroke_diamond(cx f64, cy f64, rx f64, ry f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke diamond. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) arc_styled

XuAPI
pub fn (frame $&Frame) arc_styled(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color, options &StrokeOptions) int

Purpose

Operation on $&Frame: arc styled. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)
color Color
color (Color)
options &StrokeOptions
options (read-only borrow; caller keeps the original; type &StrokeOptions)

Returns

int — a value of this type

($&Frame) arc

XuAPI
pub fn (frame $&Frame) arc(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color, width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_sector

XuAPI
pub fn (frame $&Frame) fill_sector(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color) int

Purpose

Operation on $&Frame: fill sector. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_sector

XuAPI
pub fn (frame $&Frame) stroke_sector(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke sector. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_ring_sector

XuAPI
pub fn (frame $&Frame) fill_ring_sector(cx f64, cy f64, inner_radius f64, outer_radius f64, start_deg f64, sweep_deg f64, color Color) int

Purpose

Operation on $&Frame: fill ring sector. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
inner_radius f64
inner_radius (f64)
outer_radius f64
outer_radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_ring_sector

XuAPI
pub fn (frame $&Frame) stroke_ring_sector(cx f64, cy f64, inner_radius f64, outer_radius f64, start_deg f64, sweep_deg f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke ring sector. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
inner_radius f64
inner_radius (f64)
outer_radius f64
outer_radius (f64)
start_deg f64
start_deg (f64)
sweep_deg f64
sweep_deg (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) polyline_styled

XuAPI
pub fn (frame $&Frame) polyline_styled(points &[]PathPoint, color Color, options &StrokeOptions) int

Purpose

Operation on $&Frame: polyline styled. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
color Color
color (Color)
options &StrokeOptions
options (read-only borrow; caller keeps the original; type &StrokeOptions)

Returns

int — a value of this type

($&Frame) polyline

XuAPI
pub fn (frame $&Frame) polyline(points &[]PathPoint, color Color, width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_polygon

XuAPI
pub fn (frame $&Frame) fill_polygon(points &[]PathPoint, color Color) int

Purpose

Operation on $&Frame: fill polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_polygon

XuAPI
pub fn (frame $&Frame) stroke_polygon(points &[]PathPoint, color Color, width f64) int

Purpose

Operation on $&Frame: stroke polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_regular_polygon

XuAPI
pub fn (frame $&Frame) fill_regular_polygon(cx f64, cy f64, radius f64, sides int, rotation_deg f64, color Color) int

Purpose

Operation on $&Frame: fill regular polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
sides int
sides (int)
rotation_deg f64
rotation_deg (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_regular_polygon

XuAPI
pub fn (frame $&Frame) stroke_regular_polygon(cx f64, cy f64, radius f64, sides int, rotation_deg f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke regular polygon. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
sides int
sides (int)
rotation_deg f64
rotation_deg (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) fill_star

XuAPI
pub fn (frame $&Frame) fill_star(cx f64, cy f64, outer_radius f64, inner_radius f64, points int, rotation_deg f64, color Color) int

Purpose

Operation on $&Frame: fill star. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
outer_radius f64
outer_radius (f64)
inner_radius f64
inner_radius (f64)
points int
points (int)
rotation_deg f64
rotation_deg (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_star

XuAPI
pub fn (frame $&Frame) stroke_star(cx f64, cy f64, outer_radius f64, inner_radius f64, points int, rotation_deg f64, color Color, width f64) int

Purpose

Operation on $&Frame: stroke star. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
outer_radius f64
outer_radius (f64)
inner_radius f64
inner_radius (f64)
points int
points (int)
rotation_deg f64
rotation_deg (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) quad_curve

XuAPI
pub fn (frame $&Frame) quad_curve(x1 f64, y1 f64, cx f64, cy f64, x2 f64, y2 f64, color Color, width f64) int

Purpose

Operation on $&Frame: quad curve. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
cx f64
cx (f64)
cy f64
cy (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) cubic_curve

XuAPI
pub fn (frame $&Frame) cubic_curve(x1 f64, y1 f64, c1x f64, c1y f64, c2x f64, c2y f64, x2 f64, y2 f64, color Color, width f64) int

Purpose

Operation on $&Frame: cubic curve. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
c1x f64
c1x (f64)
c1y f64
c1y (f64)
c2x f64
c2x (f64)
c2y f64
c2y (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) dashed_line

XuAPI
pub fn (frame $&Frame) dashed_line(x1 f64, y1 f64, x2 f64, y2 f64, dash_len f64, gap_len f64, color Color, width f64) int

Purpose

Operation on $&Frame: dashed line. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
dash_len f64
dash_len (f64)
gap_len f64
gap_len (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) dashed_rect

XuAPI
pub fn (frame $&Frame) dashed_rect(x f64, y f64, width f64, height f64, dash_len f64, gap_len f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: dashed rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
dash_len f64
dash_len (f64)
gap_len f64
gap_len (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) arrow

XuAPI
pub fn (frame $&Frame) arrow(x1 f64, y1 f64, x2 f64, y2 f64, head_size f64, color Color, width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x1 f64
x1 (f64)
y1 f64
y1 (f64)
x2 f64
x2 (f64)
y2 f64
y2 (f64)
head_size f64
head_size (f64)
color Color
color (Color)
width f64
width (f64)

Returns

int — a value of this type

($&Frame) grid

XuAPI
pub fn (frame $&Frame) grid(x f64, y f64, width f64, height f64, cols int, rows int, color Color, line_width f64) int

Purpose

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

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
cols int
cols (int)
rows int
rows (int)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) box_shadow

XuAPI
pub fn (frame $&Frame) box_shadow(x f64, y f64, width f64, height f64, radius f64, offset_x f64, offset_y f64, blur f64, spread f64, color Color) int

Purpose

Operation on $&Frame: box shadow. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
offset_x f64
offset_x (f64)
offset_y f64
offset_y (f64)
blur f64
blur (f64)
spread f64
spread (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) stroke_circle_styled

XuAPI
pub fn (frame $&Frame) stroke_circle_styled(cx f64, cy f64, radius f64, color Color, options &StrokeOptions) int

Purpose

Operation on $&Frame: stroke circle styled. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
color Color
color (Color)
options &StrokeOptions
options (read-only borrow; caller keeps the original; type &StrokeOptions)

Returns

int — a value of this type

($&Frame) stroke_round_rect_styled

XuAPI
pub fn (frame $&Frame) stroke_round_rect_styled(x f64, y f64, width f64, height f64, radius f64, color Color, options &StrokeOptions) int

Purpose

Operation on $&Frame: stroke round rectangle styled. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
color Color
color (Color)
options &StrokeOptions
options (read-only borrow; caller keeps the original; type &StrokeOptions)

Returns

int — a value of this type

($&Frame) dashed_round_rect

XuAPI
pub fn (frame $&Frame) dashed_round_rect(x f64, y f64, width f64, height f64, radius f64, dash_len f64, gap_len f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: dashed round rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
dash_len f64
dash_len (f64)
gap_len f64
gap_len (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) dashed_circle

XuAPI
pub fn (frame $&Frame) dashed_circle(cx f64, cy f64, radius f64, dash_len f64, gap_len f64, color Color, line_width f64) int

Purpose

Operation on $&Frame: dashed circle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
dash_len f64
dash_len (f64)
gap_len f64
gap_len (f64)
color Color
color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) fill_and_stroke_path

XuAPI
pub fn (frame $&Frame) fill_and_stroke_path(path &Path, fill_color Color, stroke_color Color, options &StrokeOptions, rule int) int

Purpose

Operation on $&Frame: fill and stroke path. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
path &Path
filesystem path (read-only borrow; caller keeps the original; type &Path)
fill_color Color
fill_color (Color)
stroke_color Color
stroke_color (Color)
options &StrokeOptions
options (read-only borrow; caller keeps the original; type &StrokeOptions)
rule int
rule (int)

Returns

int — a value of this type

($&Frame) fill_and_stroke_round_rect

XuAPI
pub fn (frame $&Frame) fill_and_stroke_round_rect(x f64, y f64, width f64, height f64, radius f64, fill_color Color, stroke_color Color, line_width f64) int

Purpose

Operation on $&Frame: fill and stroke round rectangle. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
fill_color Color
fill_color (Color)
stroke_color Color
stroke_color (Color)
line_width f64
line_width (f64)

Returns

int — a value of this type

($&Frame) fill_rect_gradient_scaled

XuAPI
pub fn (frame $&Frame) fill_rect_gradient_scaled(x f64, y f64, width f64, height f64, gradient &Gradient, scale f64) int

Purpose

Operation on $&Frame: fill rectangle gradient scaled. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)
scale f64
scale (f64)

Returns

int — a value of this type

($&Frame) fill_rect_gradient

XuAPI
pub fn (frame $&Frame) fill_rect_gradient(x f64, y f64, width f64, height f64, gradient &Gradient) int

Purpose

Operation on $&Frame: fill rectangle gradient. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)

Returns

int — a value of this type

($&Frame) fill_round_rect_corners_gradient

XuAPI
pub fn (frame $&Frame) fill_round_rect_corners_gradient(x f64, y f64, width f64, height f64, tl f64, tr f64, br f64, bl f64, gradient &Gradient, scale f64) int

Purpose

Operation on $&Frame: fill round rectangle corners gradient. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
tl f64
tl (f64)
tr f64
tr (f64)
br f64
br (f64)
bl f64
bl (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)
scale f64
scale (f64)

Returns

int — a value of this type

($&Frame) fill_round_rect_gradient_scaled

XuAPI
pub fn (frame $&Frame) fill_round_rect_gradient_scaled(x f64, y f64, width f64, height f64, radius f64, gradient &Gradient, scale f64) int

Purpose

Operation on $&Frame: fill round rectangle gradient scaled. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)
scale f64
scale (f64)

Returns

int — a value of this type

($&Frame) fill_round_rect_gradient

XuAPI
pub fn (frame $&Frame) fill_round_rect_gradient(x f64, y f64, width f64, height f64, radius f64, gradient &Gradient) int

Purpose

Operation on $&Frame: fill round rectangle gradient. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
radius f64
radius (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)

Returns

int — a value of this type

($&Frame) fill_circle_gradient_scaled

XuAPI
pub fn (frame $&Frame) fill_circle_gradient_scaled(cx f64, cy f64, radius f64, gradient &Gradient, scale f64) int

Purpose

Operation on $&Frame: fill circle gradient scaled. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)
scale f64
scale (f64)

Returns

int — a value of this type

($&Frame) fill_circle_gradient

XuAPI
pub fn (frame $&Frame) fill_circle_gradient(cx f64, cy f64, radius f64, gradient &Gradient) int

Purpose

Operation on $&Frame: fill circle gradient. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
radius f64
radius (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)

Returns

int — a value of this type

($&Frame) fill_ellipse_gradient

XuAPI
pub fn (frame $&Frame) fill_ellipse_gradient(cx f64, cy f64, rx f64, ry f64, gradient &Gradient, scale f64) int

Purpose

Operation on $&Frame: fill ellipse gradient. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
cx f64
cx (f64)
cy f64
cy (f64)
rx f64
rx (f64)
ry f64
ry (f64)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)
scale f64
scale (f64)

Returns

int — a value of this type

($&Frame) fill_polygon_gradient

XuAPI
pub fn (frame $&Frame) fill_polygon_gradient(points &[]PathPoint, gradient &Gradient, scale f64) int

Purpose

Operation on $&Frame: fill polygon gradient. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
points &[]PathPoint
points (read-only borrow; caller keeps the original; type &[]PathPoint)
gradient &Gradient
gradient (read-only borrow; caller keeps the original; type &Gradient)
scale f64
scale (f64)

Returns

int — a value of this type

struct Surface

XuAPI
pub struct Surface {
    pub width f64
    pub height f64
    pub pixel_width int
    pub pixel_height int
}

Purpose

An immutable transparent raster layer, scoped to the source frame's canvas. Explicit resolution makes cache quality and memory use predictable. Reuse this handle in any number of frames; update by creating a replacement first. Accepted frames retain old pixels across dispose. Copies share one handle.

Public fields

width f64
field (f64)
height f64
field (f64)
pixel_width int
field (int)
pixel_height int
field (int)

($&Frame) snapshot

XuAPI
pub fn (frame $&Frame) snapshot(width f64, height f64, scale f64) Surface

Purpose

Render once, without presenting to the window or using its camera/DPI. Source coordinates cover [0,width] x [0,height]; scale determines backing pixels (ceil per dimension). The default clear is transparent; set_bg makes an opaque clear. The frame remains sealed for present or another snapshot. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
width f64
width (f64)
height f64
height (f64)
scale f64
scale (f64)

Returns

Surface — a value of this type

($&Surface) dispose

XuAPI
pub fn (surface $&Surface) dispose() int

Purpose

Release and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.

Parameters

surface $&Surface
The Surface instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Surface) close

XuAPI
pub fn (surface $&Surface) close() int

Purpose

Operation on $&Surface: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

surface $&Surface
The Surface instance used by this call (exclusive borrow).

Returns

int — a value of this type

(&Surface) rgba_bytes

XuAPI
pub fn (surface &Surface) rgba_bytes() string

Purpose

Independent, straight sRGB RGBA8 copy, in top-left row order. The native immutable bitmap stays owned by this Surface; editing the copy is safe. Throws on failure; handle the error or propagate it to the caller.

Parameters

surface &Surface
The Surface instance used by this call (borrow).

Returns

string — result string

($&Frame) surface

XuAPI
pub fn (frame $&Frame) surface(surface &Surface, x f64, y f64, width f64, height f64, opacity f64, sampler int) int

Purpose

Group opacity is applied once to the cached layer. Destination geometry and clipping follow this frame's CTM; source frame transforms are already baked. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
surface &Surface
surface (read-only borrow; caller keeps the original; type &Surface)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
opacity f64
opacity (f64)
sampler int
sampler (int)

Returns

int — a value of this type

const TEXT_LEFT

XuAPI
pub const TEXT_LEFT = 0

Purpose

Constant TEXT_LEFT, defining protocol or algorithm parameters.

const TEXT_CENTER

XuAPI
pub const TEXT_CENTER = 1

Purpose

Constant TEXT_CENTER, defining protocol or algorithm parameters.

const TEXT_RIGHT

XuAPI
pub const TEXT_RIGHT = 2

Purpose

Constant TEXT_RIGHT, defining protocol or algorithm parameters.

struct TextOptions

XuAPI
pub struct TextOptions {
    pub family string
    pub size f64
    pub width f64
    pub weight int
    pub italic bool
    pub align int
    pub line_height f64
}

Purpose

Draw Configuration parameters and options set.

Public fields

family string
field (string)
size f64
field (f64)
width f64
field (f64)
weight int
field (int)
italic bool
field (bool)
align int
field (int)
line_height f64
field (f64)

struct TextMetrics

XuAPI
pub struct TextMetrics {
    pub width f64
    pub height f64
    pub baseline f64
    pub lines int
    pub ink_x f64
    pub ink_y f64
    pub ink_width f64
    pub ink_height f64
}

Purpose

Structure encapsulating width, height, baseline, lines, ink_x.

Public fields

width f64
field (f64)
height f64
field (f64)
baseline f64
field (f64)
lines int
field (int)
ink_x f64
field (f64)
ink_y f64
field (f64)
ink_width f64
field (f64)
ink_height f64
field (f64)

text_options

XuAPI
pub fn text_options(size f64) TextOptions

Purpose

Text options.

Parameters

size f64
size (f64)

Returns

TextOptions — a value of this type

See usage example

struct TextLayout

XuAPI
pub struct TextLayout {
    pub metrics TextMetrics
}

Purpose

Metrics and drawing share one native layout, including shaping, fallback, wrapping and trailing empty lines. Font sizes/positions use logical pixels. A Frame retains its layout even after this user handle is disposed.

Public fields

metrics TextMetrics
field (TextMetrics)

See usage example

struct TextHit

XuAPI
pub struct TextHit {
    pub index int
    pub length int
    pub trailing bool
    pub inside bool
    pub x f64
    pub y f64
    pub height f64
}

Purpose

A shaped cluster and its logical edge. Keep index/trailing together at soft wraps and bidi boundaries. index/length count UTF-8 bytes, never UTF-16 units.

Public fields

index int
field (int)
length int
field (int)
trailing bool
field (bool)
inside bool
field (bool)
x f64
value
y f64
value
height f64
field (f64)

(&TextHit) byte_index

XuAPI
pub fn (hit &TextHit) byte_index() int

Purpose

Operation on &TextHit: byte index.

Parameters

hit &TextHit
The TextHit instance used by this call (borrow).

Returns

int — index; see the description for its range and special values

(&TextLayout) bind_input

XuAPI
pub fn (layout &TextLayout) bind_input(input &ui.TextInput, revision int, x f64, y f64) int

Purpose

Bind the same immutable layout that is drawn at x/y. Its text must equal the input snapshot's display_value, including preedit, at this revision. The session retains the layout after dispose; edits invalidate the binding. Throws on failure; handle the error or propagate it to the caller.

Parameters

layout &TextLayout
The TextLayout instance used by this call (borrow).
input &ui.TextInput
input (read-only borrow; caller keeps the original; type &ui.TextInput)
revision int
revision (int)
x f64
value (f64)
y f64
value (f64)

Returns

int — a value of this type

(&TextLayout) bind_input_transform

XuAPI
pub fn (layout &TextLayout) bind_input_transform(input &ui.TextInput, revision int, transform &ui.TextInputTransform, upstream bool) int

Purpose

Operation on &TextLayout: bind input transform. Throws on failure; handle the error or propagate it to the caller.

Parameters

layout &TextLayout
The TextLayout instance used by this call (borrow).
input &ui.TextInput
input (read-only borrow; caller keeps the original; type &ui.TextInput)
revision int
revision (int)
transform &ui.TextInputTransform
transform (read-only borrow; caller keeps the original; type &ui.TextInputTransform)
upstream bool
upstream (bool)

Returns

int — a value of this type

(&TextLayout) hit_test

XuAPI
pub fn (layout &TextLayout) hit_test(x f64, y f64) TextHit

Purpose

Coordinates are relative to this layout's top-left before the frame CTM. Outside points return the nearest edge and inside=false. Throws on failure; handle the error or propagate it to the caller.

Parameters

layout &TextLayout
The TextLayout instance used by this call (borrow).
x f64
value (f64)
y f64
value (f64)

Returns

TextHit — a value of this type

(&TextLayout) caret

XuAPI
pub fn (layout &TextLayout) caret(index int, trailing bool) TextHit

Purpose

Scalar boundaries inside a shaped cluster normalize to that cluster. Byte offsets inside a UTF-8 encoding are rejected; trailing selects its far edge. Throws on failure; handle the error or propagate it to the caller.

Parameters

layout &TextLayout
The TextLayout instance used by this call (borrow).
index int
index (int)
trailing bool
trailing (bool)

Returns

TextHit — a value of this type

(&Context) empty_text_layout

XuAPI
pub fn (c &Context) empty_text_layout(metrics TextMetrics) TextLayout

Purpose

Operation on &Context: empty text layout.

Parameters

c &Context
The Context instance used by this call (borrow).
metrics TextMetrics
metrics (TextMetrics)

Returns

TextLayout — a value of this type

(&TextLayout) is_host_shaped

XuAPI
pub fn (layout &TextLayout) is_host_shaped() bool

Purpose

Operation on &TextLayout: whether it is host shaped.

Parameters

layout &TextLayout
The TextLayout instance used by this call (borrow).

Returns

bool — true or false

(&Context) layout_text

XuAPI
pub fn (context &Context) layout_text(value &string, options &TextOptions) TextLayout

Purpose

Empty family uses the platform UI font. size=0 selects 14px; weight=0 selects 400. width=0 disables wrapping; center/right require an explicit width. Maximum text is 16 KiB UTF-8 and family 256 bytes. Live layout identities grow dynamically within the host's byte budget. Native coordinate/shaping limits also bound size*(byte_length+1) to 262144. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
value &string
value (read-only borrow; caller keeps the original; type &string)
options &TextOptions
options (read-only borrow; caller keeps the original; type &TextOptions)

Returns

TextLayout — a value of this type

(&Context) layout_masked_text

XuAPI
pub fn (context &Context) layout_masked_text(value &string,options &TextOptions) TextLayout

Purpose

Paint one bullet per Unicode grapheme. Queries retain the original UTF-8 byte positions, so selection, caret and native input bindings remain valid. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
value &string
value (read-only borrow; caller keeps the original; type &string)
options &TextOptions
options (read-only borrow; caller keeps the original; type &TextOptions)

Returns

TextLayout — a value of this type

($&TextLayout) dispose

XuAPI
pub fn (layout $&TextLayout) dispose() int

Purpose

Release and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.

Parameters

layout $&TextLayout
The TextLayout instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&TextLayout) close

XuAPI
pub fn (layout $&TextLayout) close() int

Purpose

Operation on $&TextLayout: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

layout $&TextLayout
The TextLayout instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Frame) text_layout

XuAPI
pub fn (frame $&Frame) text_layout(layout &TextLayout, x f64, y f64, color Color) int

Purpose

Operation on $&Frame: text layout. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
layout &TextLayout
layout (read-only borrow; caller keeps the original; type &TextLayout)
x f64
value (f64)
y f64
value (f64)
color Color
color (Color)

Returns

int — a value of this type

struct TextSelectionRect

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

Purpose

Canvas-independent layout rectangles for a UTF-8 selection. The host batches shaped cluster queries and coalesces touching rectangles on each visual line.

Public fields

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

(&TextLayout) selection_rects

XuAPI
pub fn (layout &TextLayout) selection_rects(start int,end int) []TextSelectionRect

Purpose

Operation on &TextLayout: selection rects. Throws on failure; handle the error or propagate it to the caller.

Parameters

layout &TextLayout
The TextLayout instance used by this call (borrow).
start int
start (int)
end int
end (int)

Returns

[]TextSelectionRect — slice result

const FIT_FILL

XuAPI
pub const FIT_FILL = 0

Purpose

Constant FIT_FILL, defining protocol or algorithm parameters.

const FIT_CONTAIN

XuAPI
pub const FIT_CONTAIN = 1

Purpose

Constant FIT_CONTAIN, defining protocol or algorithm parameters.

const FIT_COVER

XuAPI
pub const FIT_COVER = 2

Purpose

Constant FIT_COVER, defining protocol or algorithm parameters.

const FIT_CENTER

XuAPI
pub const FIT_CENTER = 3

Purpose

Constant FIT_CENTER, defining protocol or algorithm parameters.

text_options_styled

XuAPI
pub fn text_options_styled(family string, size f64, weight int, italic bool) TextOptions

Purpose

Text options styled.

Parameters

family string
family (string)
size f64
size (f64)
weight int
weight (int)
italic bool
italic (bool)

Returns

TextOptions — a value of this type

text_options_wrapped

XuAPI
pub fn text_options_wrapped(size f64, width f64, align int) TextOptions

Purpose

Text options wrapped.

Parameters

size f64
size (f64)
width f64
width (f64)
align int
align (int)

Returns

TextOptions — a value of this type

(&Context) measure_text

XuAPI
pub fn (context &Context) measure_text(value &string, size f64) TextMetrics

Purpose

Measures text metrics using the ':xu:' native host or pure-Xu #ui/font when hostless. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
value &string
value (read-only borrow; caller keeps the original; type &string)
size f64
size (f64)

Returns

TextMetrics — a value of this type

($&Frame) text_aligned

XuAPI
pub fn (frame $&Frame) text_aligned(layout &TextLayout, x f64, y f64, width f64, height f64, align_x f64, align_y f64, color Color) int

Purpose

Draws a shaped TextLayout aligned within [x, x+width] x [y, y+height] using align_x, align_y in [0, 1]. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
layout &TextLayout
layout (read-only borrow; caller keeps the original; type &TextLayout)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
align_x f64
align_x (f64)
align_y f64
align_y (f64)
color Color
color (Color)

Returns

int — a value of this type

($&Frame) text_pill

XuAPI
pub fn (frame $&Frame) text_pill(layout &TextLayout, x f64, y f64, pad_x f64, pad_y f64, bg Color, border Color, fg Color) int

Purpose

Draws a rounded pill badge around a TextLayout with background, optional border, and foreground color. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
layout &TextLayout
layout (read-only borrow; caller keeps the original; type &TextLayout)
x f64
value (f64)
y f64
value (f64)
pad_x f64
pad_x (f64)
pad_y f64
pad_y (f64)
bg Color
bg (Color)
border Color
border (Color)
fg Color
fg (Color)

Returns

int — a value of this type

($&Frame) image_fit

XuAPI
pub fn (frame $&Frame) image_fit(image &Image, x f64, y f64, width f64, height f64, fit_mode int, opacity f64) int

Purpose

Draws an Image into [x, y, width, height] using FIT_FILL, FIT_CONTAIN, FIT_COVER, or FIT_CENTER. Throws on failure; handle the error or propagate it to the caller.

Parameters

frame $&Frame
The Frame instance used by this call (exclusive borrow).
image &Image
image (read-only borrow; caller keeps the original; type &Image)
x f64
value (f64)
y f64
value (f64)
width f64
width (f64)
height f64
height (f64)
fit_mode int
fit_mode (int)
opacity f64
opacity (f64)

Returns

int — a value of this type

(&Context) start_text_input

XuAPI
pub fn (context &Context) start_text_input(options &ui.TextInputOptions) ui.TextInput

Purpose

Operation on &Context: start text input. Throws on failure; handle the error or propagate it to the caller.

Parameters

context &Context
The Context instance used by this call (borrow).
options &ui.TextInputOptions
options (read-only borrow; caller keeps the original; type &ui.TextInputOptions)

Returns

ui.TextInput — a value of this type