XU XUv0.16.0

#ui/draw

导入方式: #ui/draw

公开 API: 109 函数, 253 方法, 23 类型, 50 常量, 0 方法集

显式 Context / Frame 绘图,支持路径、渐变、文字、图像、DisplayList、Surface 和缓存。画布默认不平移;set_pan_enabled(1) 显式启用相机。Frame.scale 使用比例,包级 scale 使用百分比。push / pop 必须配对;资源活到 present / freeze / snapshot 接受后再释放。

使用指南与生命周期

正式版示例(完整工程与源码下载):draw_gallery

绘图与游戏引擎边界

这是面向桌面工具、编辑器和小型原型的二维绘图层。平台后端使用 CoreGraphics、Cairo 和 GDI+;公共 API 没有提供游戏引擎所需的 GPU 渲染管线、着色器、绘制批处理和显示同步的帧调度契约。DisplayList 与 Surface 缓存可复用工作,但不能据此宣称达到游戏帧耗时预算;应按实际负载在目标平台测量。

示例代码 · API 声明

示例代码

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

16_ui_webview/draw/main.xu

所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

Xu本地 SDK 示例
@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

所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

Xu本地 SDK 示例
@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

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

Xu本地 SDK 示例
@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
}
更多相关示例
  • 16_ui_webview/draw_gallery/main.xu

    所需 SDK:Xu 0.10.13-dev.3 · 完整工程 · 下载源码

    Xu本地 SDK 示例
    @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

    所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

    Xu本地 SDK 示例
    @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

    所需 SDK:Xu 0.10.11 · 完整工程 · 下载源码

    Xu本地 SDK 示例
    @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

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

    Xu本地 SDK 示例
    @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

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

    Xu本地 SDK 示例
    @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

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

    Xu本地 SDK 示例
    @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

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

    Xu本地 SDK 示例
    @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

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

    Xu本地 SDK 示例
    @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

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

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

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

    Xumain.xu
    @main
    
    #ui
    #ui/widgets
    #time
    demo #"github.com/xulang-org/examples/ui_demo"
    
    fn scene(events chan ui.Event) int {
        ready := demo.ready(events) >>>
        if ready.kind == ui.EV_EXIT{ << 0}
        $screen := widgets.screen(&ready) >>>
        screen.resize(1180.0, 900.0) >>> (err) {screen.dispose()
            >> err}
        screen.set_min_size(920, 780) >>> (err) {screen.dispose()
            >> err}
        $model := create($&screen) >>> (err) {screen.dispose()
            >> err}
        workshop_loop(events, $&model, $&screen) >>> (err) {screen.dispose()
            >> err}
        screen.dispose()
        << 0
    }
    
    fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
            << }}
    
    fn launch() int {
        $app := demo.app("XUUI / Component Workshop", 1180, 900) >>>
        xu worker(app.event_ch)
        << app.run() >>>
    }
    
    fn main() int { << launch() >>> (err) {eprintln(err.msg())
            << 1}}
    
    fn next_event(events chan ui.Event, deadline time.Instant) ui.Event{
        if deadline.is_zero() { << <- events}
        delay := deadline.since(time.instant())
        if delay.nanoseconds() <= 0 { << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}}
        timer := delay.timer()
        select {event := <- events{timer.stop()
                << event}
            _ := <- timer.c{timer.stop()}}
        << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
    }
    
    fn workshop_loop(events chan ui.Event, model $&Workshop, screen $&widgets.Screen) int {
        model.apply_locale(screen) >>>
        screen.set_text(model.title, "XUUI  /  Field") >>>
        model.configure_controls(screen) >>>
        model.controls_dirty = false
        model.apply_appearance(screen) >>>
        model.appearance_dirty = false
        $dispatcher := register_events(& * model, & * screen) >>>
        model.layout(screen) >>>
        while screen.is_open() {
            register_notice_events(& * screen, $&dispatcher) >>>
            now := time.instant()
            model.work(screen, now) >>>
            if model.controls_dirty{model.configure_controls(screen) >>>
                model.controls_dirty = false}
            if model.appearance_dirty{model.apply_appearance(screen) >>>
                model.appearance_dirty = false}
            model.apply_page_options(screen) >>>
            model.layout(screen) >>>
            $deadline := screen.advance(now) >>>
            $timed_actions := false
            for action in screen.take_actions() {
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) >>>
                timed_actions = true
            }
            // Reconcile timer-driven values/styles before computing the next wait.
            if timed_actions{ -> }
            _ := screen.render() >>>
            if model.running &&(deadline.is_zero() || model.deadline.before(deadline)) {deadline = model.deadline}
            event := next_event(events, deadline) >>>
            $actions := screen.event(&event) >>>
            $count := 0
            while screen.is_open() && count < 128 {pending := ui.poll_chan(events)
                if pending.kind == ui.EV_NONE{ <- }
                more := screen.event(&pending) >>>
                for action in more{actions.push(action)}
                count += 1}
            for action in actions{register_notice_events(& * screen, $&dispatcher) >>>
                _ := dispatcher.dispatch_or_fallback(&action, model, screen) >>> }
        }
        << 0
    }
    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 声明

const IN_NONE

XuAPI
pub const IN_NONE = 0

用途

常量 IN_NONE,定义了相关的协议或算法配置参数。

const IN_CLICK

XuAPI
pub const IN_CLICK = 1

用途

常量 IN_CLICK,定义了相关的协议或算法配置参数。

const IN_SCROLL

XuAPI
pub const IN_SCROLL = 2

用途

常量 IN_SCROLL,定义了相关的协议或算法配置参数。

const IN_DRAG

XuAPI
pub const IN_DRAG = 3

用途

常量 IN_DRAG,定义了相关的协议或算法配置参数。

struct Point

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

用途

承载 x、y 等属性的结构体。

公开字段

x int
值
y int
值

struct Click

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

用途

承载 x、y、ok 等属性的结构体。

公开字段

x int
值
y int
值
ok int
字段(int)

struct Input

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

用途

承载 kind、x、y、dx、dy 等属性的结构体。

公开字段

kind int
类型标签
x int
值
y int
值
dx int
字段(int)
dy int
字段(int)

attach

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

用途

执行 attach 处理。

参数

w $&ui.Window
写入侧 / 宽度(独占借用,可修改原值;类型 $&ui.Window)

返回值

int — 该类型的值

set_input_enabled

XuAPI
pub fn set_input_enabled(on int) int

用途

设置 input enabled。

参数

on int
on(int)

返回值

int — 该类型的值

set_cursor

XuAPI
pub fn set_cursor(cursor int) int

用途

设置 cursor。

参数

cursor int
cursor(int)

返回值

int — 该类型的值

set_pan_enabled

XuAPI
pub fn set_pan_enabled(on int) int

用途

控制三个桌面平台的内置拖拽 / 滚轮相机,默认关闭。关闭时重置偏移;不影响应用接收输入事件。

参数

on int
0 关闭,1 开启;画布就绪后调用

返回值

命令结果;传输失败为负数

begin

XuAPI
pub fn begin() int

用途

执行 begin 处理。

参数

无需传入参数。

返回值

int — 该类型的值

present

XuAPI
pub fn present() int

用途

执行 present 处理。

参数

无需传入参数。

返回值

int — 该类型的值

cancel

XuAPI
pub fn cancel() int

用途

取消。

参数

无需传入参数。

返回值

int — 该类型的值

clear

XuAPI
pub fn clear() int

用途

执行 clear 处理。

参数

无需传入参数。

返回值

int — 该类型的值

set_bg

XuAPI
pub fn set_bg(hex string) int

用途

设置 bg。

参数

hex string
hex(string)

返回值

int — 该类型的值

set_color

XuAPI
pub fn set_color(hex string) int

用途

设置 color。

参数

hex string
hex(string)

返回值

int — 该类型的值

set_fill

XuAPI
pub fn set_fill(hex string) int

用途

设置 fill。

参数

hex string
hex(string)

返回值

int — 该类型的值

set_stroke

XuAPI
pub fn set_stroke(hex string) int

用途

设置 stroke。

参数

hex string
hex(string)

返回值

int — 该类型的值

set_width

XuAPI
pub fn set_width(w int) int

用途

设置 width。

参数

w int
写入侧 / 宽度(int)

返回值

int — 该类型的值

push

XuAPI
pub fn push() int

用途

压入。

参数

无需传入参数。

返回值

int — 该类型的值

pop

XuAPI
pub fn pop() int

用途

弹出。

参数

无需传入参数。

返回值

int — 该类型的值

clip_rect

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

用途

执行 clip rect 操作。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)

返回值

int — 该类型的值

origin

XuAPI
pub fn origin() int

用途

执行 origin 处理。

参数

无需传入参数。

返回值

int — 该类型的值

translate

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

用途

执行 translate 处理。

参数

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

返回值

int — 该类型的值

rotate

XuAPI
pub fn rotate(deg int) int

用途

旋转。

参数

deg int
deg(int)

返回值

int — 该类型的值

scale

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

用途

执行 scale 处理。

参数

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

返回值

int — 该类型的值

fill_rect

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

用途

执行 fill rect 操作。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)
hex string
hex(string)

返回值

int — 该类型的值

stroke_rect

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

用途

执行 stroke rect 操作。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)
hex string
hex(string)
width int
width(int)

返回值

int — 该类型的值

round_rect

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

用途

舍入矩形。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)
radius int
radius(int)
fill string
fill(string)
stroke string
stroke(string)
width int
width(int)

返回值

int — 该类型的值

diamond

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

用途

执行 diamond 处理。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)
fill string
fill(string)
stroke string
stroke(string)
width int
width(int)

返回值

int — 该类型的值

line

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

用途

执行 line 处理。

参数

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

返回值

int — 该类型的值

text

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

用途

返回当前文本。

参数

x int
值(int)
y int
值(int)
size int
size(int)
hex string
hex(string)
s string
源字符串(string)

返回值

int — 该类型的值

arrow

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

用途

执行 arrow 处理。

参数

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

返回值

int — 该类型的值

rect

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

用途

在画布上绘制矩形边框或填充矩形。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)

返回值

int — 该类型的值

rect_line

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

用途

执行 rect line 操作。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)

返回值

int — 该类型的值

circle

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

用途

执行 circle 处理。

参数

cx int
cx(int)
cy int
cy(int)
r int
rune(Unicode 码点)(int)

返回值

int — 该类型的值

circle_line

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

用途

执行 circle line 操作。

参数

cx int
cx(int)
cy int
cy(int)
r int
rune(Unicode 码点)(int)

返回值

int — 该类型的值

fill_circle

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

用途

执行 fill circle 操作。

参数

cx int
cx(int)
cy int
cy(int)
r int
rune(Unicode 码点)(int)
hex string
hex(string)

返回值

int — 该类型的值

stroke_circle

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

用途

执行 stroke circle 操作。

参数

cx int
cx(int)
cy int
cy(int)
r int
rune(Unicode 码点)(int)
hex string
hex(string)
width int
width(int)

返回值

int — 该类型的值

ellipse

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

用途

执行 ellipse 处理。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)

返回值

int — 该类型的值

ellipse_line

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

用途

执行 ellipse line 操作。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)

返回值

int — 该类型的值

fill_ellipse

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

用途

执行 fill ellipse 操作。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)
hex string
hex(string)

返回值

int — 该类型的值

stroke_ellipse

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

用途

执行 stroke ellipse 操作。

参数

x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)
hex string
hex(string)
width int
width(int)

返回值

int — 该类型的值

triangle

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

用途

执行 triangle 处理。

参数

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

返回值

int — 该类型的值

triangle_line

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

用途

执行 triangle line 操作。

参数

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

返回值

int — 该类型的值

fill_triangle

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

用途

执行 fill triangle 操作。

参数

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)

返回值

int — 该类型的值

stroke_triangle

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

用途

执行 stroke triangle 操作。

参数

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)

返回值

int — 该类型的值

poly

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

用途

执行 poly 处理。

参数

pts &[]Point
pts(只读借用,调用方仍持有原值;类型 &[]Point)
fill string
fill(string)
stroke string
stroke(string)
width int
width(int)

返回值

int — 该类型的值

arc

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

用途

执行 arc 处理。

参数

cx int
cx(int)
cy int
cy(int)
r int
rune(Unicode 码点)(int)
deg0 int
deg0(int)
deg1 int
deg1(int)
hex string
hex(string)
width int
width(int)

返回值

int — 该类型的值

point

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

用途

执行 point 处理。

参数

x int
值(int)
y int
值(int)
hex string
hex(string)
r int
rune(Unicode 码点)(int)

返回值

int — 该类型的值

click_of

XuAPI
pub fn click_of(ev ui.Event) Click

用途

执行 click of 操作。

参数

ev ui.Event
ev(ui.Event)

返回值

Click — 该类型的值

poll_click

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

用途

执行 poll click 操作。

参数

ech chan ui.Event
ech(通道;类型 chan ui.Event)

返回值

Click — 该类型的值

poll

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

用途

执行 poll 处理。

参数

ech chan ui.Event
ech(通道;类型 chan ui.Event)

返回值

Input — 该类型的值

prompt

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

用途

执行 prompt 处理。

参数

ech chan ui.Event
ech(通道;类型 chan ui.Event)
title string
title(string)
seed string
随机种子(string)

返回值

string — 结果字符串

in_rect

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

用途

执行 in rect 操作。

参数

c Click
字节或字符码(Click)
x int
值(int)
y int
值(int)
w int
写入侧 / 宽度(int)
h int
高度或句柄(int)

返回值

bool — 是否成立

in_circle

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

用途

执行 in circle 操作。

参数

c Click
字节或字符码(Click)
cx int
cx(int)
cy int
cy(int)
r int
rune(Unicode 码点)(int)

返回值

bool — 是否成立

struct SurfaceCache

XuAPI
pub struct SurfaceCache {

}

用途

SurfaceCache 上下文或状态结构体。

公开字段

此类型没有公开字段。

查看用法示例

new_surface_cache

XuAPI
pub fn new_surface_cache() SurfaceCache

用途

构造 surface cache。

参数

无需传入参数。

返回值

SurfaceCache — 该类型的值

查看用法示例

($&SurfaceCache) dispose

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

用途

释放并清理对象所持有的系统原生资源与底层句柄。

参数

cache $&SurfaceCache
本次调用使用的 SurfaceCache 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&SurfaceCache) close

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

用途

$&SurfaceCache 上的操作:关闭资源。

参数

cache $&SurfaceCache
本次调用使用的 SurfaceCache 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&SurfaceCache) invalidate

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

用途

标记控件区域为脏,请求系统在下一帧重新绘制。

参数

cache $&SurfaceCache
本次调用使用的 SurfaceCache 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&SurfaceCache) update

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

用途

$&SurfaceCache 上的操作:更新。失败时抛出错误,调用方需处理或继续传播。

参数

cache $&SurfaceCache
本次调用使用的 SurfaceCache 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
list &DisplayList
list(只读借用,调用方仍持有原值;类型 &DisplayList)
width f64
width(f64)
height f64
height(f64)
scale f64
scale(f64)

返回值

bool — 是否成立

($&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

用途

$&Frame 上的操作:执行 cached display list 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cache $&SurfaceCache
cache(独占借用,可修改原值;类型 $&SurfaceCache)
list &DisplayList
list(只读借用,调用方仍持有原值;类型 &DisplayList)
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
scale f64
scale(f64)
opacity f64
opacity(f64)
sampler int
sampler(int)

返回值

int — 该类型的值

(&Color) r

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

用途

在 &Color 上执行 r 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Color) g

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

用途

在 &Color 上执行 g 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Color) b

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

用途

在 &Color 上执行 b 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Color) a

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

用途

在 &Color 上执行 a 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Color) with_opacity

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

用途

&Color 上的操作:派生一个带 opacity 的新值。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。
opacity f64
opacity(f64)

返回值

Color — 该类型的值

(&Color) opacity

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

用途

在 &Color 上执行 opacity 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。
alpha_unit f64
alpha_unit(f64)

返回值

Color — 该类型的值

lerp_color

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

用途

执行 lerp color 操作。

参数

a Color
值(Color)
b Color
b(Color)
t f64
t(f64)

返回值

Color — 该类型的值

查看用法示例

(&Color) lighten

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

用途

在 &Color 上执行 lighten 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。
amount f64
amount(f64)

返回值

Color — 该类型的值

(&Color) darken

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

用途

在 &Color 上执行 darken 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。
amount f64
amount(f64)

返回值

Color — 该类型的值

hex

XuAPI
pub fn hex(code string) Color

用途

十六进制。失败时抛出错误,调用方需处理或继续传播。

参数

code string
码(string)

返回值

Color — 该类型的值

查看用法示例

hsla

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

用途

执行 hsla 处理。

参数

h f64
高度或句柄(f64)
s f64
s(f64)
l f64
l(f64)
a f64
值(f64)

返回值

Color — 该类型的值

hsl

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

用途

执行 hsl 处理。

参数

h f64
高度或句柄(f64)
s f64
s(f64)
l f64
l(f64)

返回值

Color — 该类型的值

查看用法示例

round_stroke

XuAPI
pub fn round_stroke(width f64) StrokeOptions

用途

执行 round stroke 操作。

参数

width f64
width(f64)

返回值

StrokeOptions — 该类型的值

dashed_stroke

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

用途

执行 dashed stroke 操作。

参数

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

返回值

StrokeOptions — 该类型的值

gradient_stop

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

用途

执行 gradient stop 操作。

参数

offset f64
偏移(f64)
color Color
color(Color)

返回值

GradientStop — 该类型的值

two_stop_linear

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

用途

执行 two stop linear 操作。

参数

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)

返回值

Gradient — 该类型的值

查看用法示例

two_stop_radial

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

用途

执行 two stop radial 操作。

参数

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

返回值

Gradient — 该类型的值

查看用法示例

(&Color) invert

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

用途

在 &Color 上执行 invert 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

Color — 该类型的值

(&Color) grayscale

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

用途

在 &Color 上执行 grayscale 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

Color — 该类型的值

(&Color) luminance

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

用途

在 &Color 上执行 luminance 操作。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

f64 — 该类型的值

contrast_ratio

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

用途

执行 contrast ratio 操作。

参数

a Color
值(Color)
b Color
b(Color)

返回值

f64 — 该类型的值

(&Color) contrasting_ink

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

用途

&Color 上的操作:执行 contrasting ink 操作。

参数

bg &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。
light Color
light(Color)
dark Color
dark(Color)

返回值

Color — 该类型的值

(&Color) to_hex_rgba

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

用途

&Color 上的操作:转换为 hex rgba。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

string — 结果字符串

(&Color) to_hex

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

用途

&Color 上的操作:转换为 hex。

参数

c &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

string — 结果字符串

(&Color) blend_over

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

用途

&Color 上的操作:执行 blend over 操作。

参数

fg &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。
bg Color
bg(Color)

返回值

Color — 该类型的值

lerp_color_premul

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

用途

执行 lerp color premul 操作。

参数

a Color
值(Color)
b Color
b(Color)
t f64
t(f64)

返回值

Color — 该类型的值

hsva

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

用途

执行 hsva 处理。

参数

h f64
高度或句柄(f64)
s f64
s(f64)
v f64
值(f64)
a f64
值(f64)

返回值

Color — 该类型的值

hsv

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

用途

执行 hsv 处理。

参数

h f64
高度或句柄(f64)
s f64
s(f64)
v f64
值(f64)

返回值

Color — 该类型的值

mix_palette

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

用途

执行 mix palette 操作。

参数

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

返回值

[]Color — 切片结果

const BLEND_SOURCE_OVER

XuAPI
pub const BLEND_SOURCE_OVER = 0

用途

常量 BLEND_SOURCE_OVER,定义了相关的协议或算法配置参数。

const BLEND_COPY

XuAPI
pub const BLEND_COPY = 1

用途

常量 BLEND_COPY,定义了相关的协议或算法配置参数。

const BLEND_DESTINATION_IN

XuAPI
pub const BLEND_DESTINATION_IN = 2

用途

常量 BLEND_DESTINATION_IN,定义了相关的协议或算法配置参数。

const BLEND_DESTINATION_OUT

XuAPI
pub const BLEND_DESTINATION_OUT = 3

用途

常量 BLEND_DESTINATION_OUT,定义了相关的协议或算法配置参数。

const BLEND_MULTIPLY

XuAPI
pub const BLEND_MULTIPLY = 4

用途

常量 BLEND_MULTIPLY,定义了相关的协议或算法配置参数。

const BLEND_SCREEN

XuAPI
pub const BLEND_SCREEN = 5

用途

常量 BLEND_SCREEN,定义了相关的协议或算法配置参数。

const BLEND_ADD

XuAPI
pub const BLEND_ADD = 6

用途

常量 BLEND_ADD,定义了相关的协议或算法配置参数。

const BLEND_XOR

XuAPI
pub const BLEND_XOR = 7

用途

常量 BLEND_XOR,定义了相关的协议或算法配置参数。

(&Surface) composite

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

用途

在 &Surface 上执行 composite 操作。失败时抛出错误,调用方需处理或继续传播。

参数

backdrop &Surface
本次调用使用的 Surface 实例;以只读借用传入,调用方仍持有实例。
source &Surface
source(只读借用,调用方仍持有原值;类型 &Surface)
mode int
模式(int)
opacity f64
opacity(f64)

返回值

Surface — 该类型的值

($&Frame) fill_path_gradient

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

用途

$&Frame 上的操作:执行 fill path gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
path &Path
文件系统路径(只读借用,调用方仍持有原值;类型 &Path)
paint &Gradient
paint(只读借用,调用方仍持有原值;类型 &Gradient)
bounds &ImageRect
bounds(只读借用,调用方仍持有原值;类型 &ImageRect)
scale f64
scale(f64)
rule int
rule(int)

返回值

int — 该类型的值

struct DisplayList

XuAPI
pub struct DisplayList {

}

用途

DisplayList 上下文或状态结构体。

公开字段

此类型没有公开字段。

查看用法示例

($&Frame) freeze

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

用途

在 $&Frame 上执行 freeze 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

DisplayList — 该类型的值

($&DisplayList) dispose

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

用途

释放并清理对象所持有的系统原生资源与底层句柄。失败时抛出错误,调用方需处理或继续传播。

参数

list $&DisplayList
本次调用使用的 DisplayList 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&DisplayList) close

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

用途

$&DisplayList 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

list $&DisplayList
本次调用使用的 DisplayList 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) display_list

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

用途

$&Frame 上的操作:执行 display list 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
list &DisplayList
list(只读借用,调用方仍持有原值;类型 &DisplayList)

返回值

int — 该类型的值

(&DisplayList) snapshot

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

用途

在 &DisplayList 上执行 snapshot 操作。失败时抛出错误,调用方需处理或继续传播。

参数

list &DisplayList
本次调用使用的 DisplayList 实例;以只读借用传入,调用方仍持有实例。
width f64
width(f64)
height f64
height(f64)
scale f64
scale(f64)

返回值

Surface — 该类型的值

struct DisplayListPool

XuAPI
pub struct DisplayListPool {

}

用途

Draw 连接池管理器,并发安全地维护和调度复用套接字连接。

公开字段

此类型没有公开字段。

(&Context) display_list_pool

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

用途

&Context 上的操作:执行 display list pool 操作。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。

返回值

DisplayListPool — 该类型的值

(&DisplayListPool) is_current

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

用途

&DisplayListPool 上的操作:判断是否 current。

参数

pool &DisplayListPool
本次调用使用的 DisplayListPool 实例;以只读借用传入,调用方仍持有实例。
key int
键(int)
revision int
revision(int)

返回值

bool — 是否成立

($&DisplayListPool) capture

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

用途

在 $&DisplayListPool 上执行 capture 操作。失败时抛出错误,调用方需处理或继续传播。

参数

pool $&DisplayListPool
本次调用使用的 DisplayListPool 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key int
键(int)
revision int
revision(int)
frame $&Frame
frame(独占借用,可修改原值;类型 $&Frame)

返回值

int — 该类型的值

($&DisplayListPool) remove

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

用途

$&DisplayListPool 上的操作:删除。

参数

pool $&DisplayListPool
本次调用使用的 DisplayListPool 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key int
键(int)

返回值

不返回值。

($&DisplayListPool) dispose

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

用途

释放并清理对象所持有的系统原生资源与底层句柄。

参数

pool $&DisplayListPool
本次调用使用的 DisplayListPool 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&DisplayListPool) close

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

用途

$&DisplayListPool 上的操作:关闭资源。

参数

pool $&DisplayListPool
本次调用使用的 DisplayListPool 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&Frame) pooled_display_list

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

用途

$&Frame 上的操作:执行 pooled display list 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
pool &DisplayListPool
pool(只读借用,调用方仍持有原值;类型 &DisplayListPool)
key int
键(int)

返回值

int — 该类型的值

default_font_stack

XuAPI
pub fn default_font_stack() font.FontStack

用途

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

参数

无需传入参数。

返回值

font.FontStack — 该类型的值

add_ttf_face

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

用途

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

参数

stack $&font.FontStack
stack(独占借用,可修改原值;类型 $&font.FontStack)
ttf_bytes &[]u8
ttf_bytes(只读借用,调用方仍持有原值;类型 &[]u8)
font_index int
font_index(int)
face_id int
face_id(int)

返回值

int — 该类型的值

font_metrics_to_draw

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

用途

执行 font metrics to draw 操作。

参数

m &font.TextMetrics
m(只读借用,调用方仍持有原值;类型 &font.TextMetrics)

返回值

TextMetrics — 该类型的值

layout_font_text

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

用途

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

参数

stack &font.FontStack
stack(只读借用,调用方仍持有原值;类型 &font.FontStack)
value &string
value(只读借用,调用方仍持有原值;类型 &string)
options &TextOptions
options(只读借用,调用方仍持有原值;类型 &TextOptions)
masked bool
masked(bool)

返回值

font.TextLayout — 该类型的值

(&Context) measure_text_options

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

用途

&Context 上的操作:执行 measure text options 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
value &string
value(只读借用,调用方仍持有原值;类型 &string)
options &TextOptions
options(只读借用,调用方仍持有原值;类型 &TextOptions)
masked bool
masked(bool)

返回值

TextMetrics — 该类型的值

($&Frame) text_font_layout

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

用途

$&Frame 上的操作:执行 text font layout 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
ly &font.TextLayout
ly(只读借用,调用方仍持有原值;类型 &font.TextLayout)
value &string
value(只读借用,调用方仍持有原值;类型 &string)
x f64
值(f64)
y f64
值(f64)
color Color
color(Color)

返回值

int — 该类型的值

const MAX_FRAME_BYTES

XuAPI
pub const MAX_FRAME_BYTES = 4194304

用途

常量 MAX_FRAME_BYTES,定义了相关的协议或算法配置参数。

const MAX_FRAME_COMMANDS

XuAPI
pub const MAX_FRAME_COMMANDS = 100000

用途

常量 MAX_FRAME_COMMANDS,定义了相关的协议或算法配置参数。

const MAX_STATE_DEPTH

XuAPI
pub const MAX_STATE_DEPTH = 256

用途

常量 MAX_STATE_DEPTH,定义了相关的协议或算法配置参数。

struct Color

XuAPI
pub struct Color {

}

用途

Color 上下文或状态结构体。

公开字段

此类型没有公开字段。

查看用法示例

rgba

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

用途

执行 rgba 处理。

参数

r int
rune(Unicode 码点)(int)
g int
g(int)
b int
b(int)
a int
值(int)

返回值

Color — 该类型的值

查看用法示例

(&Color) value

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

用途

返回直通 RGBA 的 32 位打包值,R 在最高字节。

参数

color &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。

返回值

0xRRGGBBAA 整数

(&Color) with_alpha

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

用途

派生替换 alpha 的颜色,通道夹紧到 0–255。

参数

color &Color
本次调用使用的 Color 实例;以只读借用传入,调用方仍持有实例。
alpha int
alpha(int)

返回值

新的 Color

rgb

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

用途

执行 rgb 处理。

参数

r int
rune(Unicode 码点)(int)
g int
g(int)
b int
b(int)

返回值

Color — 该类型的值

查看用法示例

struct Context

XuAPI
pub struct Context {

}

用途

Context 上下文或状态结构体。

公开字段

此类型没有公开字段。

查看用法示例

(&Context) clone

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

用途

&Context 上的操作:拷贝一份独立的 string。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。

返回值

Context — 该类型的值

(&Context) matches_canvas

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

用途

&Context 上的操作:执行 matches canvas 操作。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
identity &ui.CanvasEvent
identity(只读借用,调用方仍持有原值;类型 &ui.CanvasEvent)

返回值

bool — 是否成立

default_context

XuAPI
pub fn default_context() Context

用途

执行 default context 操作。

参数

无需传入参数。

返回值

Context — 该类型的值

hostless_context

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

用途

执行 hostless context 操作。

参数

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

返回值

Context — 该类型的值

context_of

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

用途

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

参数

event &ui.Event
event(只读借用,调用方仍持有原值;类型 &ui.Event)

返回值

Context — 该类型的值

查看用法示例

window_context

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

用途

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

参数

window &ui.Window
window(只读借用,调用方仍持有原值;类型 &ui.Window)

返回值

Context — 该类型的值

查看用法示例

struct Frame

XuAPI
pub struct Frame {

}

用途

Draw 协议数据帧结构封装。

公开字段

此类型没有公开字段。

查看用法示例

(&Context) new_frame

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

用途

&Context 上的操作:构造 frame。

参数

c &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
capacity int
capacity(int)

返回值

Frame — 该类型的值

($&Frame) begin

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

用途

在 $&Frame 上执行 begin 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) cancel

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

用途

$&Frame 上的操作:取消。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

(&Frame) byte_len

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

用途

&Frame 上的操作:执行 byte len 操作。

参数

f &Frame
本次调用使用的 Frame 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Frame) capacity

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

用途

在 &Frame 上执行 capacity 操作。

参数

f &Frame
本次调用使用的 Frame 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Frame) command_count

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

用途

&Frame 上的操作:命令计数。

参数

f &Frame
本次调用使用的 Frame 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) export_xdf

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

用途

$&Frame 上的操作:执行 export xdf 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

string — 结果字符串

($&Frame) present

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

用途

封闭并提交完整帧;成功表示排队而非已经显示。队列满时保留封闭帧,可重试或 cancel / begin 重建。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

成功为 0;失败抛出错误

($&Frame) present_wait

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

用途

$&Frame 上的操作:执行 present wait 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) set_bg

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

用途

$&Frame 上的操作:设置 bg。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) set_color

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

用途

$&Frame 上的操作:设置 color。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) set_fill

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

用途

$&Frame 上的操作:设置 fill。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) set_stroke

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

用途

$&Frame 上的操作:设置 stroke。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) set_width

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

用途

$&Frame 上的操作:设置 width。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
width f64
width(f64)

返回值

int — 该类型的值

($&Frame) push

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

用途

$&Frame 上的操作:压入。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) pop

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

用途

$&Frame 上的操作:弹出。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) origin

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

用途

在 $&Frame 上执行 origin 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) translate

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

用途

在 $&Frame 上执行 translate 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)

返回值

int — 该类型的值

($&Frame) rotate

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

用途

$&Frame 上的操作:旋转。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
degrees f64
degrees(f64)

返回值

int — 该类型的值

($&Frame) scale

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

用途

在 $&Frame 上执行 scale 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)

返回值

int — 该类型的值

($&Frame) clip_rect

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

用途

$&Frame 上的操作:执行 clip rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
w f64
写入侧 / 宽度(f64)
h f64
高度或句柄(f64)

返回值

int — 该类型的值

($&Frame) rect

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

用途

$&Frame 上的操作:在画布上绘制矩形边框或填充矩形。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
w f64
写入侧 / 宽度(f64)
h f64
高度或句柄(f64)

返回值

int — 该类型的值

($&Frame) rect_line

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

用途

$&Frame 上的操作:执行 rect line 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
w f64
写入侧 / 宽度(f64)
h f64
高度或句柄(f64)

返回值

int — 该类型的值

($&Frame) fill_rect

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

用途

$&Frame 上的操作:执行 fill rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
w f64
写入侧 / 宽度(f64)
h f64
高度或句柄(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_rect

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

用途

$&Frame 上的操作:执行 stroke rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
w f64
写入侧 / 宽度(f64)
h f64
高度或句柄(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Frame) ellipse

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

用途

在 $&Frame 上执行 ellipse 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
w f64
写入侧 / 宽度(f64)
h f64
高度或句柄(f64)

返回值

int — 该类型的值

($&Frame) line

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

用途

在 $&Frame 上执行 line 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x1 f64
x1(f64)
y1 f64
y1(f64)
x2 f64
x2(f64)
y2 f64
y2(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Frame) text

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

用途

$&Frame 上的操作:返回当前文本。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
size f64
size(f64)
color Color
color(Color)
text &string
文本(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 该类型的值

($&Frame) circle

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

用途

在 $&Frame 上执行 circle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
radius f64
radius(f64)

返回值

int — 该类型的值

($&Frame) triangle

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

用途

在 $&Frame 上执行 triangle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

f $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x1 f64
x1(f64)
y1 f64
y1(f64)
x2 f64
x2(f64)
y2 f64
y2(f64)
x3 f64
x3(f64)
y3 f64
y3(f64)

返回值

int — 该类型的值

bezier_quad_point

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

用途

执行 bezier quad point 操作。

参数

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)

返回值

PathPoint — 该类型的值

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

用途

执行 bezier cubic point 操作。

参数

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)

返回值

PathPoint — 该类型的值

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

用途

执行 bezier cubic tangent 操作。

参数

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)

返回值

PathPoint — 该类型的值

point_in_rect

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

用途

执行 point in rect 操作。

参数

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

返回值

bool — 是否成立

point_in_circle

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

用途

执行 point in circle 操作。

参数

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

返回值

bool — 是否成立

point_in_ellipse

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

用途

执行 point in ellipse 操作。

参数

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

返回值

bool — 是否成立

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

用途

执行 point in round rect 操作。

参数

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

返回值

bool — 是否成立

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

用途

执行 point in round rect corners 操作。

参数

px f64
px(f64)
py f64
py(f64)
x f64
值(f64)
y f64
值(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)

返回值

bool — 是否成立

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

用途

执行 point in triangle 操作。

参数

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)

返回值

bool — 是否成立

point_in_polygon

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

用途

执行 point in polygon 操作。

参数

px f64
px(f64)
py f64
py(f64)
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)

返回值

bool — 是否成立

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

用途

执行 point in sector 操作。

参数

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)

返回值

bool — 是否成立

distance_to_segment

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

用途

执行 distance to segment 操作。

参数

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

返回值

f64 — 该类型的值

point_near_segment

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

用途

执行 point near segment 操作。

参数

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)

返回值

bool — 是否成立

point_near_polyline

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

用途

执行 point near polyline 操作。

参数

px f64
px(f64)
py f64
py(f64)
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
tolerance f64
tolerance(f64)

返回值

bool — 是否成立

(&Path) flatten_subpaths

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

用途

&Path 上的操作:执行 flatten subpaths 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。
tolerance f64
tolerance(f64)

返回值

[][]PathPoint — 切片结果

(&Path) flatten

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

用途

在 &Path 上执行 flatten 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。
tolerance f64
tolerance(f64)

返回值

[]PathPoint — 切片结果

(&Path) contains_with_rule

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

用途

&Path 上的操作:执行 contains with rule 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。
px f64
px(f64)
py f64
py(f64)
rule int
rule(int)

返回值

bool — 是否成立

(&Path) contains

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

用途

&Path 上的操作:判断是否包含给定片段。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。
px f64
px(f64)
py f64
py(f64)

返回值

bool — 是否成立

(&Path) hit_stroke

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

用途

&Path 上的操作:执行 hit stroke 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。
px f64
px(f64)
py f64
py(f64)
tolerance f64
tolerance(f64)

返回值

bool — 是否成立

const SPREAD_PAD

XuAPI
pub const SPREAD_PAD = 0

用途

常量 SPREAD_PAD,定义了相关的协议或算法配置参数。

const SPREAD_REPEAT

XuAPI
pub const SPREAD_REPEAT = 1

用途

常量 SPREAD_REPEAT,定义了相关的协议或算法配置参数。

const SPREAD_REFLECT

XuAPI
pub const SPREAD_REFLECT = 2

用途

常量 SPREAD_REFLECT,定义了相关的协议或算法配置参数。

struct GradientStop

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

用途

承载 offset、color 等属性的结构体。

公开字段

offset f64
偏移
color Color
字段(Color)

查看用法示例

struct Gradient

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

用途

承载 spread、stops 等属性的结构体。

公开字段

spread int
字段(int)
stops []GradientStop
字段([]GradientStop)

linear_gradient

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

用途

执行 linear gradient 操作。

参数

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

返回值

Gradient — 该类型的值

查看用法示例

radial_gradient

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

用途

执行 radial gradient 操作。

参数

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

返回值

Gradient — 该类型的值

(&Context) gradient

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

用途

在 &Context 上执行 gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
width f64
width(f64)
height f64
height(f64)
scale f64
scale(f64)
paint &Gradient
paint(只读借用,调用方仍持有原值;类型 &Gradient)

返回值

Surface — 该类型的值

const SAMPLER_NEAREST

XuAPI
pub const SAMPLER_NEAREST = 0

用途

常量 SAMPLER_NEAREST,定义了相关的协议或算法配置参数。

查看用法示例

const SAMPLER_LINEAR

XuAPI
pub const SAMPLER_LINEAR = 1

用途

常量 SAMPLER_LINEAR,定义了相关的协议或算法配置参数。

查看用法示例

const MAX_IMAGE_BYTES

XuAPI
pub const MAX_IMAGE_BYTES = 67108864

用途

常量 MAX_IMAGE_BYTES,定义了相关的协议或算法配置参数。

const MAX_IMAGE_DIMENSION

XuAPI
pub const MAX_IMAGE_DIMENSION = 16384

用途

常量 MAX_IMAGE_DIMENSION,定义了相关的协议或算法配置参数。

struct Image

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

用途

承载 width、height 等属性的结构体。

公开字段

width int
字段(int)
height int
字段(int)

查看用法示例

struct ImageRect

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

用途

承载 x、y、width、height 等属性的结构体。

公开字段

x f64
值
y f64
值
width f64
字段(f64)
height f64
字段(f64)

查看用法示例

(&Context) image_rgba

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

用途

&Context 上的操作:执行 image rgba 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
width int
width(int)
height int
height(int)
stride int
stride(int)
data &string
数据(只读借用,调用方仍持有原值;类型 &string)

返回值

Image — 该类型的值

(&Context) image_pixels

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

用途

&Context 上的操作:执行 image pixels 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
bitmap &image.RGBA
bitmap(只读借用,调用方仍持有原值;类型 &image.RGBA)

返回值

Image — 该类型的值

(&Context) image_encoded

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

用途

&Context 上的操作:执行 image encoded 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
data &string
数据(只读借用,调用方仍持有原值;类型 &string)

返回值

Image — 该类型的值

(&Context) load_image

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

用途

&Context 上的操作:执行 load image 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
path &string
文件系统路径(只读借用,调用方仍持有原值;类型 &string)

返回值

Image — 该类型的值

(&Context) load_embedded_image

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

用途

&Context 上的操作:执行 load embedded image 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
path &string
文件系统路径(只读借用,调用方仍持有原值;类型 &string)

返回值

Image — 该类型的值

(&Image) update_rgba

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

用途

&Image 上的操作:执行 update rgba 操作。失败时抛出错误,调用方需处理或继续传播。

参数

image &Image
本次调用使用的 Image 实例;以只读借用传入,调用方仍持有实例。
stride int
stride(int)
data &string
数据(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 该类型的值

($&Image) dispose

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

用途

释放并清理对象所持有的系统原生资源与底层句柄。失败时抛出错误,调用方需处理或继续传播。

参数

image $&Image
本次调用使用的 Image 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Image) close

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

用途

$&Image 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

image $&Image
本次调用使用的 Image 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) image_region

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

用途

$&Frame 上的操作:执行 image region 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
image &Image
image(只读借用,调用方仍持有原值;类型 &Image)
source &ImageRect
source(只读借用,调用方仍持有原值;类型 &ImageRect)
destination &ImageRect
destination(只读借用,调用方仍持有原值;类型 &ImageRect)
opacity f64
opacity(f64)
sampler int
sampler(int)

返回值

int — 该类型的值

($&Frame) image

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

用途

在 $&Frame 上执行 image 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
image &Image
image(只读借用,调用方仍持有原值;类型 &Image)
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)

返回值

int — 该类型的值

const MAX_LAYER_DEPTH

XuAPI
pub const MAX_LAYER_DEPTH = 16

用途

常量 MAX_LAYER_DEPTH,定义了相关的协议或算法配置参数。

($&Frame) begin_layer

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

用途

$&Frame 上的操作:执行 begin layer 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
bounds &ImageRect
bounds(只读借用,调用方仍持有原值;类型 &ImageRect)
scale f64
scale(f64)
opacity f64
opacity(f64)

返回值

int — 该类型的值

($&Frame) end_layer

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

用途

$&Frame 上的操作:执行 end layer 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) dispose

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

用途

释放并清理对象所持有的系统原生资源与底层句柄。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&Frame) close

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

用途

$&Frame 上的操作:关闭资源。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

struct Matrix2D

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

用途

承载 a、b、c、d、tx 等属性的结构体。

公开字段

a f64
字段(f64)
b f64
字段(f64)
c f64
字节或字符码
d f64
字段(f64)
tx f64
字段(f64)
ty f64
字段(f64)

identity_matrix

XuAPI
pub fn identity_matrix() Matrix2D

用途

执行 identity matrix 操作。

参数

无需传入参数。

返回值

Matrix2D — 该类型的值

translation_matrix

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

用途

执行 translation matrix 操作。

参数

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

返回值

Matrix2D — 该类型的值

scaling_matrix

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

用途

执行 scaling matrix 操作。

参数

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

返回值

Matrix2D — 该类型的值

rotation_matrix

XuAPI
pub fn rotation_matrix(degrees f64) Matrix2D

用途

执行 rotation matrix 操作。

参数

degrees f64
degrees(f64)

返回值

Matrix2D — 该类型的值

skew_matrix

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

用途

执行 skew matrix 操作。

参数

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

返回值

Matrix2D — 该类型的值

(&Matrix2D) multiply

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

用途

在 &Matrix2D 上执行 multiply 操作。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。
other &Matrix2D
另一侧同类型值(只读借用,调用方仍持有原值;类型 &Matrix2D)

返回值

Matrix2D — 该类型的值

(&Matrix2D) translate

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

用途

在 &Matrix2D 上执行 translate 操作。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。
tx f64
tx(f64)
ty f64
ty(f64)

返回值

Matrix2D — 该类型的值

(&Matrix2D) scale

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

用途

在 &Matrix2D 上执行 scale 操作。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。
sx f64
sx(f64)
sy f64
sy(f64)

返回值

Matrix2D — 该类型的值

(&Matrix2D) rotate

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

用途

&Matrix2D 上的操作:旋转。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。
degrees f64
degrees(f64)

返回值

Matrix2D — 该类型的值

(&Matrix2D) determinant

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

用途

在 &Matrix2D 上执行 determinant 操作。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。

返回值

f64 — 该类型的值

(&Matrix2D) is_invertible

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

用途

&Matrix2D 上的操作:判断是否 invertible。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

(&Matrix2D) inverse

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

用途

在 &Matrix2D 上执行 inverse 操作。失败时抛出错误,调用方需处理或继续传播。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。

返回值

Matrix2D — 该类型的值

(&Matrix2D) map_point

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

用途

&Matrix2D 上的操作:执行 map point 操作。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)

返回值

PathPoint — 该类型的值

(&Matrix2D) map_bounds

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

用途

&Matrix2D 上的操作:执行 map bounds 操作。

参数

m &Matrix2D
本次调用使用的 Matrix2D 实例;以只读借用传入,调用方仍持有实例。
rect &ImageRect
rect(只读借用,调用方仍持有原值;类型 &ImageRect)

返回值

ImageRect — 该类型的值

($&Frame) rotate_around

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

用途

$&Frame 上的操作:执行 rotate around 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
degrees f64
degrees(f64)

返回值

int — 该类型的值

($&Frame) scale_around

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

用途

$&Frame 上的操作:执行 scale around 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
sx f64
sx(f64)
sy f64
sy(f64)

返回值

int — 该类型的值

(&Path) clone

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

用途

&Path 上的操作:拷贝一份独立的 string。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。

返回值

Path — 该类型的值

($&Path) append_transformed

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

用途

$&Path 上的操作:执行 append transformed 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
other &Path
另一侧同类型值(只读借用,调用方仍持有原值;类型 &Path)
m &Matrix2D
m(只读借用,调用方仍持有原值;类型 &Matrix2D)

返回值

int — 该类型的值

($&Path) append

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

用途

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

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
other &Path
另一侧同类型值(只读借用,调用方仍持有原值;类型 &Path)

返回值

int — 该类型的值

($&Path) transform

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

用途

在 $&Path 上执行 transform 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
m &Matrix2D
m(只读借用,调用方仍持有原值;类型 &Matrix2D)

返回值

int — 该类型的值

($&Path) translate

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

用途

在 $&Path 上执行 translate 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
dx f64
dx(f64)
dy f64
dy(f64)

返回值

int — 该类型的值

($&Path) scale

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

用途

在 $&Path 上执行 scale 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
sx f64
sx(f64)
sy f64
sy(f64)

返回值

int — 该类型的值

($&Path) rotate

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

用途

$&Path 上的操作:旋转。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
degrees f64
degrees(f64)

返回值

int — 该类型的值

($&Path) rotate_around

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

用途

$&Path 上的操作:执行 rotate around 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
degrees f64
degrees(f64)

返回值

int — 该类型的值

(&Path) bounds

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

用途

返回当前控件或几何对象的有效外接矩形边界(Rectangle)。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。

返回值

ImageRect — 该类型的值

(&Path) tight_bounds

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

用途

&Path 上的操作:执行 tight bounds 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。

返回值

ImageRect — 该类型的值

const PALETTE_VIRIDIS

XuAPI
pub const PALETTE_VIRIDIS = 0

用途

常量 PALETTE_VIRIDIS,定义了相关的协议或算法配置参数。

查看用法示例

const PALETTE_PLASMA

XuAPI
pub const PALETTE_PLASMA = 1

用途

常量 PALETTE_PLASMA,定义了相关的协议或算法配置参数。

const PALETTE_COOLWARM

XuAPI
pub const PALETTE_COOLWARM = 2

用途

常量 PALETTE_COOLWARM,定义了相关的协议或算法配置参数。

const PALETTE_OCEAN

XuAPI
pub const PALETTE_OCEAN = 3

用途

常量 PALETTE_OCEAN,定义了相关的协议或算法配置参数。

const PALETTE_SUNSET

XuAPI
pub const PALETTE_SUNSET = 4

用途

常量 PALETTE_SUNSET,定义了相关的协议或算法配置参数。

const PALETTE_FOREST

XuAPI
pub const PALETTE_FOREST = 5

用途

常量 PALETTE_FOREST,定义了相关的协议或算法配置参数。

palette_colors

XuAPI
pub fn palette_colors(kind int) []Color

用途

执行 palette colors 操作。

参数

kind int
类型标签(int)

返回值

[]Color — 切片结果

sample_color_stops

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

用途

执行 sample color stops 操作。

参数

colors &[]Color
colors(只读借用,调用方仍持有原值;类型 &[]Color)
t f64
t(f64)

返回值

Color — 该类型的值

sample_palette

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

用途

执行 sample palette 操作。

参数

kind int
类型标签(int)
t f64
t(f64)

返回值

Color — 该类型的值

查看用法示例

multi_stop_linear

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

用途

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

参数

x0 f64
x0(f64)
y0 f64
y0(f64)
x1 f64
x1(f64)
y1 f64
y1(f64)
colors &[]Color
colors(只读借用,调用方仍持有原值;类型 &[]Color)

返回值

Gradient — 该类型的值

multi_stop_radial

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

用途

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

参数

cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
colors &[]Color
colors(只读借用,调用方仍持有原值;类型 &[]Color)

返回值

Gradient — 该类型的值

const MAX_PATH_BYTES

XuAPI
pub const MAX_PATH_BYTES = 2097152

用途

常量 MAX_PATH_BYTES,定义了相关的协议或算法配置参数。

const MAX_PATH_SEGMENTS

XuAPI
pub const MAX_PATH_SEGMENTS = 32768

用途

常量 MAX_PATH_SEGMENTS,定义了相关的协议或算法配置参数。

const FILL_NONZERO

XuAPI
pub const FILL_NONZERO = 0

用途

常量 FILL_NONZERO,定义了相关的协议或算法配置参数。

查看用法示例

const FILL_EVENODD

XuAPI
pub const FILL_EVENODD = 1

用途

常量 FILL_EVENODD,定义了相关的协议或算法配置参数。

const CAP_BUTT

XuAPI
pub const CAP_BUTT = 0

用途

常量 CAP_BUTT,定义了相关的协议或算法配置参数。

const CAP_ROUND

XuAPI
pub const CAP_ROUND = 1

用途

常量 CAP_ROUND,定义了相关的协议或算法配置参数。

const CAP_SQUARE

XuAPI
pub const CAP_SQUARE = 2

用途

常量 CAP_SQUARE,定义了相关的协议或算法配置参数。

const JOIN_MITER

XuAPI
pub const JOIN_MITER = 0

用途

常量 JOIN_MITER,定义了相关的协议或算法配置参数。

const JOIN_ROUND

XuAPI
pub const JOIN_ROUND = 1

用途

常量 JOIN_ROUND,定义了相关的协议或算法配置参数。

const JOIN_BEVEL

XuAPI
pub const JOIN_BEVEL = 2

用途

常量 JOIN_BEVEL,定义了相关的协议或算法配置参数。

struct Path

XuAPI
pub struct Path {

}

用途

Path 上下文或状态结构体。

公开字段

此类型没有公开字段。

new_path

XuAPI
pub fn new_path(capacity int) Path

用途

构造 path。

参数

capacity int
capacity(int)

返回值

Path — 该类型的值

查看用法示例

($&Path) clear

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

用途

清空所有已缓冲或存储的数据项与内部状态。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

(&Path) byte_len

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

用途

&Path 上的操作:执行 byte len 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Path) capacity

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

用途

在 &Path 上执行 capacity 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Path) segment_count

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

用途

&Path 上的操作:执行 segment count 操作。

参数

path &Path
本次调用使用的 Path 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

($&Path) move_to

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

用途

$&Path 上的操作:移动到。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)

返回值

int — 该类型的值

($&Path) line_to

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

用途

$&Path 上的操作:执行 line to 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)

返回值

int — 该类型的值

($&Path) quad_to

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

用途

$&Path 上的操作:执行 quad to 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
x f64
值(f64)
y f64
值(f64)

返回值

int — 该类型的值

($&Path) cubic_to

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

用途

$&Path 上的操作:执行 cubic to 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
c1x f64
c1x(f64)
c1y f64
c1y(f64)
c2x f64
c2x(f64)
c2y f64
c2y(f64)
x f64
值(f64)
y f64
值(f64)

返回值

int — 该类型的值

($&Path) close

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

用途

$&Path 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

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
}

用途

Draw 配置参数与选项集合。

公开字段

width f64
字段(f64)
cap int
字段(int)
join int
字段(int)
miter_limit f64
字段(f64)
dashes []f64
字段([]f64)
dash_offset f64
字段(f64)
flatten_tolerance f64
字段(f64)

stroke_options

XuAPI
pub fn stroke_options(width f64) StrokeOptions

用途

执行 stroke options 操作。

参数

width f64
width(f64)

返回值

StrokeOptions — 该类型的值

查看用法示例

($&Frame) fill_path

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

用途

$&Frame 上的操作:执行 fill path 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
path &Path
文件系统路径(只读借用,调用方仍持有原值;类型 &Path)
color Color
color(Color)
rule int
rule(int)

返回值

int — 该类型的值

($&Frame) stroke_path

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

用途

$&Frame 上的操作:执行 stroke path 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
path &Path
文件系统路径(只读借用,调用方仍持有原值;类型 &Path)
color Color
color(Color)
style &StrokeOptions
style(只读借用,调用方仍持有原值;类型 &StrokeOptions)

返回值

int — 该类型的值

const DIR_UP

XuAPI
pub const DIR_UP = 0

用途

常量 DIR_UP,定义了相关的协议或算法配置参数。

const DIR_RIGHT

XuAPI
pub const DIR_RIGHT = 1

用途

常量 DIR_RIGHT,定义了相关的协议或算法配置参数。

const DIR_DOWN

XuAPI
pub const DIR_DOWN = 2

用途

常量 DIR_DOWN,定义了相关的协议或算法配置参数。

const DIR_LEFT

XuAPI
pub const DIR_LEFT = 3

用途

常量 DIR_LEFT,定义了相关的协议或算法配置参数。

($&Path) smooth_spline

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

用途

$&Path 上的操作:执行 smooth spline 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
tension f64
tension(f64)
closed bool
closed(bool)

返回值

int — 该类型的值

($&Frame) smooth_curve

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

用途

$&Frame 上的操作:执行 smooth curve 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
tension f64
tension(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Frame) fill_smooth_closed

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

用途

$&Frame 上的操作:执行 fill smooth closed 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
tension f64
tension(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_smooth_closed

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

用途

$&Frame 上的操作:执行 stroke smooth closed 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
tension f64
tension(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Path) rounded_polyline

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

用途

$&Path 上的操作:执行 rounded polyline 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
radius f64
radius(f64)

返回值

int — 该类型的值

($&Path) rounded_polygon

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

用途

$&Path 上的操作:执行 rounded polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
radius f64
radius(f64)

返回值

int — 该类型的值

($&Frame) rounded_polyline

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

用途

$&Frame 上的操作:执行 rounded polyline 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
radius f64
radius(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Frame) fill_rounded_polygon

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

用途

$&Frame 上的操作:执行 fill rounded polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
radius f64
radius(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_rounded_polygon

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

用途

$&Frame 上的操作:执行 stroke rounded polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
radius f64
radius(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Path) ring

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

用途

在 $&Path 上执行 ring 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
inner_radius f64
inner_radius(f64)
outer_radius f64
outer_radius(f64)

返回值

int — 该类型的值

($&Frame) fill_ring

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

用途

$&Frame 上的操作:执行 fill ring 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
inner_radius f64
inner_radius(f64)
outer_radius f64
outer_radius(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke ring 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&Path) wave

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

用途

在 $&Path 上执行 wave 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
amplitude f64
amplitude(f64)
wavelength f64
wavelength(f64)
phase_deg f64
phase_deg(f64)

返回值

int — 该类型的值

($&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

用途

在 $&Frame 上执行 wave 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&Path) cross

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

用途

在 $&Path 上执行 cross 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
size f64
size(f64)
thickness f64
thickness(f64)

返回值

int — 该类型的值

($&Frame) fill_cross

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

用途

$&Frame 上的操作:执行 fill cross 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
size f64
size(f64)
thickness f64
thickness(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_cross

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

用途

$&Frame 上的操作:执行 stroke cross 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
size f64
size(f64)
thickness f64
thickness(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Path) checkmark

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

用途

在 $&Path 上执行 checkmark 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
size f64
size(f64)

返回值

int — 该类型的值

($&Frame) checkmark

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

用途

在 $&Frame 上执行 checkmark 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
size f64
size(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Path) chevron

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

用途

在 $&Path 上执行 chevron 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
direction int
direction(int)

返回值

int — 该类型的值

($&Frame) chevron

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

用途

在 $&Frame 上执行 chevron 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
direction int
direction(int)
color Color
color(Color)
line_width f64
line_width(f64)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 double arrow 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

bezier_kappa

XuAPI
pub fn bezier_kappa() f64

用途

执行 bezier kappa 操作。

参数

无需传入参数。

返回值

f64 — 该类型的值

deg_to_rad

XuAPI
pub fn deg_to_rad() f64

用途

执行 deg to rad 操作。

参数

无需传入参数。

返回值

f64 — 该类型的值

struct PathPoint

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

用途

承载 x、y 等属性的结构体。

公开字段

x f64
值
y f64
值

path_point

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

用途

执行 path point 操作。

参数

x f64
值(f64)
y f64
值(f64)

返回值

PathPoint — 该类型的值

查看用法示例

($&Path) rect

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

用途

$&Path 上的操作:在画布上绘制矩形边框或填充矩形。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)

返回值

int — 该类型的值

($&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

用途

$&Path 上的操作:执行 round rect corners 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&Path) round_rect

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

用途

$&Path 上的操作:舍入矩形。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
radius f64
radius(f64)

返回值

int — 该类型的值

($&Path) capsule

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

用途

在 $&Path 上执行 capsule 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)

返回值

int — 该类型的值

($&Path) ellipse

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

用途

在 $&Path 上执行 ellipse 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
rx f64
rx(f64)
ry f64
ry(f64)

返回值

int — 该类型的值

($&Path) circle

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

用途

在 $&Path 上执行 circle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)

返回值

int — 该类型的值

($&Path) diamond

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

用途

在 $&Path 上执行 diamond 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
rx f64
rx(f64)
ry f64
ry(f64)

返回值

int — 该类型的值

($&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

用途

$&Path 上的操作:执行 ellipse arc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&Path) arc

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

用途

在 $&Path 上执行 arc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
start_deg f64
start_deg(f64)
sweep_deg f64
sweep_deg(f64)

返回值

int — 该类型的值

($&Path) sector

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

用途

在 $&Path 上执行 sector 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
start_deg f64
start_deg(f64)
sweep_deg f64
sweep_deg(f64)

返回值

int — 该类型的值

($&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

用途

$&Path 上的操作:执行 ring sector 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&Path) polyline

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

用途

在 $&Path 上执行 polyline 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)

返回值

int — 该类型的值

($&Path) polygon

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

用途

在 $&Path 上执行 polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)

返回值

int — 该类型的值

($&Path) regular_polygon

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

用途

$&Path 上的操作:执行 regular polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
sides int
sides(int)
rotation_deg f64
rotation_deg(f64)

返回值

int — 该类型的值

($&Path) star

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

用途

在 $&Path 上执行 star 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

在 $&Path 上执行 callout 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill callout 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke callout 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

在 $&Path 上执行 ribbon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill ribbon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke ribbon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&Path) heart

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

用途

在 $&Path 上执行 heart 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
size f64
size(f64)

返回值

int — 该类型的值

($&Frame) fill_heart

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

用途

$&Frame 上的操作:执行 fill heart 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
size f64
size(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_heart

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

用途

$&Frame 上的操作:执行 stroke heart 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
size f64
size(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Path) shield

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

用途

在 $&Path 上执行 shield 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
width f64
width(f64)
height f64
height(f64)

返回值

int — 该类型的值

($&Frame) fill_shield

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

用途

$&Frame 上的操作:执行 fill shield 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
width f64
width(f64)
height f64
height(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_shield

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

用途

$&Frame 上的操作:执行 stroke shield 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&Path) gear

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

用途

在 $&Path 上执行 gear 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill gear 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke gear 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&Path) spiral

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

用途

在 $&Path 上执行 spiral 操作。失败时抛出错误,调用方需处理或继续传播。

参数

path $&Path
本次调用使用的 Path 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

在 $&Frame 上执行 spiral 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 hatch rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 cross hatch rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
spacing f64
spacing(f64)
color Color
color(Color)
line_width f64
line_width(f64)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 dot grid 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
spacing f64
spacing(f64)
dot_radius f64
dot_radius(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) fill_circle

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

用途

$&Frame 上的操作:执行 fill circle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_circle

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

用途

$&Frame 上的操作:执行 stroke circle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Frame) fill_ellipse

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

用途

$&Frame 上的操作:执行 fill ellipse 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
rx f64
rx(f64)
ry f64
ry(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_ellipse

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

用途

$&Frame 上的操作:执行 stroke ellipse 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
rx f64
rx(f64)
ry f64
ry(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill triangle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke triangle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill round rect corners 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke round rect corners 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill round rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
radius f64
radius(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke round rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
radius f64
radius(f64)
color Color
color(Color)
line_width f64
line_width(f64)

返回值

int — 该类型的值

($&Frame) round_rect

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

用途

$&Frame 上的操作:舍入矩形。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
radius f64
radius(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) fill_capsule

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

用途

$&Frame 上的操作:执行 fill capsule 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_capsule

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

用途

$&Frame 上的操作:执行 stroke capsule 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
color Color
color(Color)
line_width f64
line_width(f64)

返回值

int — 该类型的值

($&Frame) fill_diamond

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

用途

$&Frame 上的操作:执行 fill diamond 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
rx f64
rx(f64)
ry f64
ry(f64)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_diamond

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

用途

$&Frame 上的操作:执行 stroke diamond 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
rx f64
rx(f64)
ry f64
ry(f64)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 arc styled 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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(只读借用,调用方仍持有原值;类型 &StrokeOptions)

返回值

int — 该类型的值

($&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

用途

在 $&Frame 上执行 arc 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill sector 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke sector 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill ring sector 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke ring sector 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&Frame) polyline_styled

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

用途

$&Frame 上的操作:执行 polyline styled 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
color Color
color(Color)
options &StrokeOptions
options(只读借用,调用方仍持有原值;类型 &StrokeOptions)

返回值

int — 该类型的值

($&Frame) polyline

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

用途

在 $&Frame 上执行 polyline 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&Frame) fill_polygon

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

用途

$&Frame 上的操作:执行 fill polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
color Color
color(Color)

返回值

int — 该类型的值

($&Frame) stroke_polygon

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

用途

$&Frame 上的操作:执行 stroke polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
color Color
color(Color)
width f64
width(f64)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill regular polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke regular polygon 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill star 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke star 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 quad curve 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 cubic curve 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 dashed line 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 dashed rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&Frame) arrow

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

用途

在 $&Frame 上执行 arrow 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

在 $&Frame 上执行 grid 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 box shadow 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&Frame) stroke_circle_styled

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

用途

$&Frame 上的操作:执行 stroke circle styled 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
color Color
color(Color)
options &StrokeOptions
options(只读借用,调用方仍持有原值;类型 &StrokeOptions)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 stroke round rect styled 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
radius f64
radius(f64)
color Color
color(Color)
options &StrokeOptions
options(只读借用,调用方仍持有原值;类型 &StrokeOptions)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 dashed round rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 dashed circle 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill and stroke path 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
path &Path
文件系统路径(只读借用,调用方仍持有原值;类型 &Path)
fill_color Color
fill_color(Color)
stroke_color Color
stroke_color(Color)
options &StrokeOptions
options(只读借用,调用方仍持有原值;类型 &StrokeOptions)
rule int
rule(int)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill and stroke round rect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill rect gradient scaled 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)
scale f64
scale(f64)

返回值

int — 该类型的值

($&Frame) fill_rect_gradient

XuAPI
pub fn (frame $&Frame) fill_rect_gradient(x f64, y f64, width f64, height f64, gradient &Gradient) int

用途

$&Frame 上的操作:执行 fill rect gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill round rect corners gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(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(只读借用,调用方仍持有原值;类型 &Gradient)
scale f64
scale(f64)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill round rect gradient scaled 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
radius f64
radius(f64)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)
scale f64
scale(f64)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill round rect gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
radius f64
radius(f64)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill circle gradient scaled 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)
scale f64
scale(f64)

返回值

int — 该类型的值

($&Frame) fill_circle_gradient

XuAPI
pub fn (frame $&Frame) fill_circle_gradient(cx f64, cy f64, radius f64, gradient &Gradient) int

用途

$&Frame 上的操作:执行 fill circle gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
radius f64
radius(f64)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 fill ellipse gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
cx f64
cx(f64)
cy f64
cy(f64)
rx f64
rx(f64)
ry f64
ry(f64)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)
scale f64
scale(f64)

返回值

int — 该类型的值

($&Frame) fill_polygon_gradient

XuAPI
pub fn (frame $&Frame) fill_polygon_gradient(points &[]PathPoint, gradient &Gradient, scale f64) int

用途

$&Frame 上的操作:执行 fill polygon gradient 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
points &[]PathPoint
points(只读借用,调用方仍持有原值;类型 &[]PathPoint)
gradient &Gradient
gradient(只读借用,调用方仍持有原值;类型 &Gradient)
scale f64
scale(f64)

返回值

int — 该类型的值

struct Surface

XuAPI
pub struct Surface {
    pub width f64
    pub height f64
    pub pixel_width int
    pub pixel_height int
}

用途

承载 width、height、pixel_width、pixel_height 等属性的结构体。

公开字段

width f64
字段(f64)
height f64
字段(f64)
pixel_width int
字段(int)
pixel_height int
字段(int)

($&Frame) snapshot

XuAPI
pub fn (frame $&Frame) snapshot(width f64, height f64, scale f64) Surface

用途

在 $&Frame 上执行 snapshot 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
width f64
width(f64)
height f64
height(f64)
scale f64
scale(f64)

返回值

Surface — 该类型的值

($&Surface) dispose

XuAPI
pub fn (surface $&Surface) dispose() int

用途

释放并清理对象所持有的系统原生资源与底层句柄。失败时抛出错误,调用方需处理或继续传播。

参数

surface $&Surface
本次调用使用的 Surface 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Surface) close

XuAPI
pub fn (surface $&Surface) close() int

用途

$&Surface 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

surface $&Surface
本次调用使用的 Surface 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

(&Surface) rgba_bytes

XuAPI
pub fn (surface &Surface) rgba_bytes() string

用途

&Surface 上的操作:执行 rgba bytes 操作。失败时抛出错误,调用方需处理或继续传播。

参数

surface &Surface
本次调用使用的 Surface 实例;以只读借用传入,调用方仍持有实例。

返回值

string — 结果字符串

($&Frame) surface

XuAPI
pub fn (frame $&Frame) surface(surface &Surface, x f64, y f64, width f64, height f64, opacity f64, sampler int) int

用途

在 $&Frame 上执行 surface 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
surface &Surface
surface(只读借用,调用方仍持有原值;类型 &Surface)
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
opacity f64
opacity(f64)
sampler int
sampler(int)

返回值

int — 该类型的值

const TEXT_LEFT

XuAPI
pub const TEXT_LEFT = 0

用途

常量 TEXT_LEFT,定义了相关的协议或算法配置参数。

const TEXT_CENTER

XuAPI
pub const TEXT_CENTER = 1

用途

常量 TEXT_CENTER,定义了相关的协议或算法配置参数。

const TEXT_RIGHT

XuAPI
pub const TEXT_RIGHT = 2

用途

常量 TEXT_RIGHT,定义了相关的协议或算法配置参数。

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
}

用途

Draw 配置参数与选项集合。

公开字段

family string
字段(string)
size f64
字段(f64)
width f64
字段(f64)
weight int
字段(int)
italic bool
字段(bool)
align int
字段(int)
line_height f64
字段(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
}

用途

承载 width、height、baseline、lines、ink_x 等属性的结构体。

公开字段

width f64
字段(f64)
height f64
字段(f64)
baseline f64
字段(f64)
lines int
字段(int)
ink_x f64
字段(f64)
ink_y f64
字段(f64)
ink_width f64
字段(f64)
ink_height f64
字段(f64)

text_options

XuAPI
pub fn text_options(size f64) TextOptions

用途

执行 text options 操作。

参数

size f64
size(f64)

返回值

TextOptions — 该类型的值

查看用法示例

struct TextLayout

XuAPI
pub struct TextLayout {
    pub metrics TextMetrics
}

用途

承载 metrics 等属性的结构体。

公开字段

metrics TextMetrics
字段(TextMetrics)

查看用法示例

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
}

用途

承载 index、length、trailing、inside、x 等属性的结构体。

公开字段

index int
字段(int)
length int
字段(int)
trailing bool
字段(bool)
inside bool
字段(bool)
x f64
值
y f64
值
height f64
字段(f64)

(&TextHit) byte_index

XuAPI
pub fn (hit &TextHit) byte_index() int

用途

&TextHit 上的操作:执行 byte index 操作。

参数

hit &TextHit
本次调用使用的 TextHit 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 索引值;有效范围和特殊值见用途说明

(&TextLayout) bind_input

XuAPI
pub fn (layout &TextLayout) bind_input(input &ui.TextInput, revision int, x f64, y f64) int

用途

&TextLayout 上的操作:执行 bind input 操作。失败时抛出错误,调用方需处理或继续传播。

参数

layout &TextLayout
本次调用使用的 TextLayout 实例;以只读借用传入,调用方仍持有实例。
input &ui.TextInput
input(只读借用,调用方仍持有原值;类型 &ui.TextInput)
revision int
revision(int)
x f64
值(f64)
y f64
值(f64)

返回值

int — 该类型的值

(&TextLayout) bind_input_transform

XuAPI
pub fn (layout &TextLayout) bind_input_transform(input &ui.TextInput, revision int, transform &ui.TextInputTransform, upstream bool) int

用途

&TextLayout 上的操作:执行 bind input transform 操作。失败时抛出错误,调用方需处理或继续传播。

参数

layout &TextLayout
本次调用使用的 TextLayout 实例;以只读借用传入,调用方仍持有实例。
input &ui.TextInput
input(只读借用,调用方仍持有原值;类型 &ui.TextInput)
revision int
revision(int)
transform &ui.TextInputTransform
transform(只读借用,调用方仍持有原值;类型 &ui.TextInputTransform)
upstream bool
upstream(bool)

返回值

int — 该类型的值

(&TextLayout) hit_test

XuAPI
pub fn (layout &TextLayout) hit_test(x f64, y f64) TextHit

用途

&TextLayout 上的操作:执行 hit test 操作。失败时抛出错误,调用方需处理或继续传播。

参数

layout &TextLayout
本次调用使用的 TextLayout 实例;以只读借用传入,调用方仍持有实例。
x f64
值(f64)
y f64
值(f64)

返回值

TextHit — 该类型的值

(&TextLayout) caret

XuAPI
pub fn (layout &TextLayout) caret(index int, trailing bool) TextHit

用途

在 &TextLayout 上执行 caret 操作。失败时抛出错误,调用方需处理或继续传播。

参数

layout &TextLayout
本次调用使用的 TextLayout 实例;以只读借用传入,调用方仍持有实例。
index int
index(int)
trailing bool
trailing(bool)

返回值

TextHit — 该类型的值

(&Context) empty_text_layout

XuAPI
pub fn (c &Context) empty_text_layout(metrics TextMetrics) TextLayout

用途

&Context 上的操作:执行 empty text layout 操作。

参数

c &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
metrics TextMetrics
metrics(TextMetrics)

返回值

TextLayout — 该类型的值

(&TextLayout) is_host_shaped

XuAPI
pub fn (layout &TextLayout) is_host_shaped() bool

用途

&TextLayout 上的操作:判断是否 host shaped。

参数

layout &TextLayout
本次调用使用的 TextLayout 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

(&Context) layout_text

XuAPI
pub fn (context &Context) layout_text(value &string, options &TextOptions) TextLayout

用途

&Context 上的操作:执行 layout text 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
value &string
value(只读借用,调用方仍持有原值;类型 &string)
options &TextOptions
options(只读借用,调用方仍持有原值;类型 &TextOptions)

返回值

TextLayout — 该类型的值

(&Context) layout_masked_text

XuAPI
pub fn (context &Context) layout_masked_text(value &string,options &TextOptions) TextLayout

用途

&Context 上的操作:执行 layout masked text 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
value &string
value(只读借用,调用方仍持有原值;类型 &string)
options &TextOptions
options(只读借用,调用方仍持有原值;类型 &TextOptions)

返回值

TextLayout — 该类型的值

($&TextLayout) dispose

XuAPI
pub fn (layout $&TextLayout) dispose() int

用途

释放并清理对象所持有的系统原生资源与底层句柄。失败时抛出错误,调用方需处理或继续传播。

参数

layout $&TextLayout
本次调用使用的 TextLayout 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&TextLayout) close

XuAPI
pub fn (layout $&TextLayout) close() int

用途

$&TextLayout 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

layout $&TextLayout
本次调用使用的 TextLayout 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Frame) text_layout

XuAPI
pub fn (frame $&Frame) text_layout(layout &TextLayout, x f64, y f64, color Color) int

用途

$&Frame 上的操作:执行 text layout 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
layout &TextLayout
layout(只读借用,调用方仍持有原值;类型 &TextLayout)
x f64
值(f64)
y f64
值(f64)
color Color
color(Color)

返回值

int — 该类型的值

struct TextSelectionRect

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

用途

承载 x、y、width、height 等属性的结构体。

公开字段

x f64
值
y f64
值
width f64
字段(f64)
height f64
字段(f64)

(&TextLayout) selection_rects

XuAPI
pub fn (layout &TextLayout) selection_rects(start int,end int) []TextSelectionRect

用途

&TextLayout 上的操作:执行 selection rects 操作。失败时抛出错误,调用方需处理或继续传播。

参数

layout &TextLayout
本次调用使用的 TextLayout 实例;以只读借用传入,调用方仍持有实例。
start int
start(int)
end int
end(int)

返回值

[]TextSelectionRect — 切片结果

const FIT_FILL

XuAPI
pub const FIT_FILL = 0

用途

常量 FIT_FILL,定义了相关的协议或算法配置参数。

const FIT_CONTAIN

XuAPI
pub const FIT_CONTAIN = 1

用途

常量 FIT_CONTAIN,定义了相关的协议或算法配置参数。

const FIT_COVER

XuAPI
pub const FIT_COVER = 2

用途

常量 FIT_COVER,定义了相关的协议或算法配置参数。

const FIT_CENTER

XuAPI
pub const FIT_CENTER = 3

用途

常量 FIT_CENTER,定义了相关的协议或算法配置参数。

text_options_styled

XuAPI
pub fn text_options_styled(family string, size f64, weight int, italic bool) TextOptions

用途

执行 text options styled 操作。

参数

family string
family(string)
size f64
size(f64)
weight int
weight(int)
italic bool
italic(bool)

返回值

TextOptions — 该类型的值

text_options_wrapped

XuAPI
pub fn text_options_wrapped(size f64, width f64, align int) TextOptions

用途

执行 text options wrapped 操作。

参数

size f64
size(f64)
width f64
width(f64)
align int
align(int)

返回值

TextOptions — 该类型的值

(&Context) measure_text

XuAPI
pub fn (context &Context) measure_text(value &string, size f64) TextMetrics

用途

&Context 上的操作:执行 measure text 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
value &string
value(只读借用,调用方仍持有原值;类型 &string)
size f64
size(f64)

返回值

TextMetrics — 该类型的值

($&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

用途

$&Frame 上的操作:执行 text aligned 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
layout &TextLayout
layout(只读借用,调用方仍持有原值;类型 &TextLayout)
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 text pill 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
layout &TextLayout
layout(只读借用,调用方仍持有原值;类型 &TextLayout)
x f64
值(f64)
y f64
值(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)

返回值

int — 该类型的值

($&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

用途

$&Frame 上的操作:执行 image fit 操作。失败时抛出错误,调用方需处理或继续传播。

参数

frame $&Frame
本次调用使用的 Frame 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
image &Image
image(只读借用,调用方仍持有原值;类型 &Image)
x f64
值(f64)
y f64
值(f64)
width f64
width(f64)
height f64
height(f64)
fit_mode int
fit_mode(int)
opacity f64
opacity(f64)

返回值

int — 该类型的值

(&Context) start_text_input

XuAPI
pub fn (context &Context) start_text_input(options &ui.TextInputOptions) ui.TextInput

用途

&Context 上的操作:执行 start text input 操作。失败时抛出错误,调用方需处理或继续传播。

参数

context &Context
本次调用使用的 Context 实例;以只读借用传入,调用方仍持有实例。
options &ui.TextInputOptions
options(只读借用,调用方仍持有原值;类型 &ui.TextInputOptions)

返回值

ui.TextInput — 该类型的值