const IN_NONE
pub const IN_NONE = 0Purpose
Constant IN_NONE, defining protocol or algorithm parameters.
#ui/drawExplicit Context / Frame drawing with paths, gradients, text, images, DisplayList, Surface and caching. Panning is disabled by default; set_pan_enabled(1) enables the camera. Frame.scale uses factors; package-level scale uses percentages. Balance push / pop and retain resources until present / freeze / snapshot accepts the recording.
Release examples (complete projects and source downloads): draw_gallery
This is a desktop 2D drawing layer suitable for tools, editors and modest prototypes. Its platform backends use CoreGraphics, Cairo and GDI+. The public API does not provide a game-engine GPU pipeline, shaders, draw batching or a display-synchronized frame-pacing contract. DisplayList and surface caches help reuse work, but are not evidence of a game frame-time budget; measure the intended workload on each target before committing to it.
These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.
16_ui_webview/draw/main.xu@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@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@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@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@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@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@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@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@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@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@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@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@main
#ui
#ui/widgets
#time
demo #"github.com/xulang-org/examples/ui_demo"
fn scene(events chan ui.Event) int {
ready := demo.ready(events) >>>
if ready.kind == ui.EV_EXIT{ << 0}
$screen := widgets.screen(&ready) >>>
screen.resize(1180.0, 900.0) >>> (err) {screen.dispose()
>> err}
screen.set_min_size(920, 780) >>> (err) {screen.dispose()
>> err}
$model := create($&screen) >>> (err) {screen.dispose()
>> err}
workshop_loop(events, $&model, $&screen) >>> (err) {screen.dispose()
>> err}
screen.dispose()
<< 0
}
fn worker(events chan ui.Event) {scene(events) >>> (err) {demo.fail(err.msg())
<< }}
fn launch() int {
$app := demo.app("XUUI / Component Workshop", 1180, 900) >>>
xu worker(app.event_ch)
<< app.run() >>>
}
fn main() int { << launch() >>> (err) {eprintln(err.msg())
<< 1}}
fn next_event(events chan ui.Event, deadline time.Instant) ui.Event{
if deadline.is_zero() { << <- events}
delay := deadline.since(time.instant())
if delay.nanoseconds() <= 0 { << ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}}
timer := delay.timer()
select {event := <- events{timer.stop()
<< event}
_ := <- timer.c{timer.stop()}}
<< ui.Event{kind: ui.EV_NONE, window_id: 0, menu_id: "", width: 0, height: 0}
}
fn workshop_loop(events chan ui.Event, model $&Workshop, screen $&widgets.Screen) int {
model.apply_locale(screen) >>>
screen.set_text(model.title, "XUUI / Field") >>>
model.configure_controls(screen) >>>
model.controls_dirty = false
model.apply_appearance(screen) >>>
model.appearance_dirty = false
$dispatcher := register_events(& * model, & * screen) >>>
model.layout(screen) >>>
while screen.is_open() {
register_notice_events(& * screen, $&dispatcher) >>>
now := time.instant()
model.work(screen, now) >>>
if model.controls_dirty{model.configure_controls(screen) >>>
model.controls_dirty = false}
if model.appearance_dirty{model.apply_appearance(screen) >>>
model.appearance_dirty = false}
model.apply_page_options(screen) >>>
model.layout(screen) >>>
$deadline := screen.advance(now) >>>
$timed_actions := false
for action in screen.take_actions() {
_ := dispatcher.dispatch_or_fallback(&action, model, screen) >>>
timed_actions = true
}
// Reconcile timer-driven values/styles before computing the next wait.
if timed_actions{ -> }
_ := screen.render() >>>
if model.running &&(deadline.is_zero() || model.deadline.before(deadline)) {deadline = model.deadline}
event := next_event(events, deadline) >>>
$actions := screen.event(&event) >>>
$count := 0
while screen.is_open() && count < 128 {pending := ui.poll_chan(events)
if pending.kind == ui.EV_NONE{ <- }
more := screen.event(&pending) >>>
for action in more{actions.push(action)}
count += 1}
for action in actions{register_notice_events(& * screen, $&dispatcher) >>>
_ := dispatcher.dispatch_or_fallback(&action, model, screen) >>> }
}
<< 0
}@main
#ui/widgets
#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
}@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
}const IN_NONEpub const IN_NONE = 0Constant IN_NONE, defining protocol or algorithm parameters.
const IN_CLICKpub const IN_CLICK = 1Constant IN_CLICK, defining protocol or algorithm parameters.
const IN_SCROLLpub const IN_SCROLL = 2Constant IN_SCROLL, defining protocol or algorithm parameters.
const IN_DRAGpub const IN_DRAG = 3Constant IN_DRAG, defining protocol or algorithm parameters.
struct Pointpub struct Point {
pub x int
pub y int
}Structure encapsulating x, y.
x inty intstruct Clickpub struct Click {
pub x int
pub y int
pub ok int
}Structure encapsulating x, y, ok.
x inty intok intstruct Inputpub struct Input {
pub kind int
pub x int
pub y int
pub dx int
pub dy int
}Structure encapsulating kind, x, y, dx, dy.
kind intx inty intdx intdy intattachpub fn attach(w $&ui.Window) intAttach the draw canvas to a window (registers the content_draw plugin).
w $&ui.Windowint — a value of this type
set_input_enabledpub fn set_input_enabled(on int) intOpt in to pointer/key events on the shared ui event channel.
on intint — a value of this type
set_cursorpub fn set_cursor(cursor int) intCursor: default, text, crosshair, hand, horizontal/vertical resize.
cursor intint — a value of this type
set_pan_enabledpub fn set_pan_enabled(on int) intControl built-in drag / wheel panning on all three desktop platforms; disabled by default. Disabling resets offsets without suppressing application input.
on intcommand result; negative on transport failure
beginpub fn begin() intExecute begin.
No arguments are required.
int — a value of this type
presentpub fn present() intExecute present.
No arguments are required.
int — a value of this type
cancelpub fn cancel() intExecute cancel.
No arguments are required.
int — a value of this type
clearpub fn clear() intExecute clear.
No arguments are required.
int — a value of this type
set_bgpub fn set_bg(hex string) intSet bg.
hex stringint — a value of this type
set_colorpub fn set_color(hex string) intSet color.
hex stringint — a value of this type
set_fillpub fn set_fill(hex string) intSet fill.
hex stringint — a value of this type
set_strokepub fn set_stroke(hex string) intSet stroke.
hex stringint — a value of this type
set_widthpub fn set_width(w int) intSet width.
w intint — a value of this type
pushpub fn push() intExecute push.
No arguments are required.
int — a value of this type
poppub fn pop() intExecute pop.
No arguments are required.
int — a value of this type
clip_rectpub fn clip_rect(x int, y int, w int, h int) intIntersect the current clip with a rectangle in the current transform. push/pop save and restore the clip together with transform and pen.
x inty intw inth intint — a value of this type
originpub fn origin() intExecute origin.
No arguments are required.
int — a value of this type
translatepub fn translate(dx int, dy int) intExecute translate.
dx intdy intint — a value of this type
rotatepub fn rotate(deg int) intExecute rotate.
deg intint — a value of this type
scalepub fn scale(sx int, sy int) intExecute scale.
sx intsy intint — a value of this type
fill_rectpub fn fill_rect(x int, y int, w int, h int, hex string) intFill rectangle.
x inty intw inth inthex stringint — a value of this type
stroke_rectpub fn stroke_rect(x int, y int, w int, h int, hex string, width int) intStroke rectangle.
x inty intw inth inthex stringwidth intint — a value of this type
round_rectpub fn round_rect(x int, y int, w int, h int, radius int, fill string, stroke string, width int) intRound rectangle.
x inty intw inth intradius intfill stringstroke stringwidth intint — a value of this type
diamondpub fn diamond(x int, y int, w int, h int, fill string, stroke string, width int) intExecute diamond.
x inty intw inth intfill stringstroke stringwidth intint — a value of this type
linepub fn line(x1 int, y1 int, x2 int, y2 int, hex string, width int) intExecute line.
x1 inty1 intx2 inty2 inthex stringwidth intint — a value of this type
textpub fn text(x int, y int, size int, hex string, s string) intReturn the current text.
x inty intsize inthex strings stringint — a value of this type
arrowpub fn arrow(x1 int, y1 int, x2 int, y2 int, hex string, width int) intExecute arrow.
x1 inty1 intx2 inty2 inthex stringwidth intint — a value of this type
rectpub fn rect(x int, y int, w int, h int) intDraw or fill a rectangle on the canvas.
x inty intw inth intint — a value of this type
rect_linepub fn rect_line(x int, y int, w int, h int) intRectangle line.
x inty intw inth intint — a value of this type
circlepub fn circle(cx int, cy int, r int) intExecute circle.
cx intcy intr intint — a value of this type
circle_linepub fn circle_line(cx int, cy int, r int) intCircle line.
cx intcy intr intint — a value of this type
fill_circlepub fn fill_circle(cx int, cy int, r int, hex string) intFill circle.
cx intcy intr inthex stringint — a value of this type
stroke_circlepub fn stroke_circle(cx int, cy int, r int, hex string, width int) intStroke circle.
cx intcy intr inthex stringwidth intint — a value of this type
ellipsepub fn ellipse(x int, y int, w int, h int) intExecute ellipse.
x inty intw inth intint — a value of this type
ellipse_linepub fn ellipse_line(x int, y int, w int, h int) intEllipse line.
x inty intw inth intint — a value of this type
fill_ellipsepub fn fill_ellipse(x int, y int, w int, h int, hex string) intFill ellipse.
x inty intw inth inthex stringint — a value of this type
stroke_ellipsepub fn stroke_ellipse(x int, y int, w int, h int, hex string, width int) intStroke ellipse.
x inty intw inth inthex stringwidth intint — a value of this type
trianglepub fn triangle(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int) intExecute triangle.
x1 inty1 intx2 inty2 intx3 inty3 intint — a value of this type
triangle_linepub fn triangle_line(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int) intTriangle line.
x1 inty1 intx2 inty2 intx3 inty3 intint — a value of this type
fill_trianglepub fn fill_triangle(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int, hex string) intFill triangle.
x1 inty1 intx2 inty2 intx3 inty3 inthex stringint — a value of this type
stroke_trianglepub fn stroke_triangle(x1 int, y1 int, x2 int, y2 int, x3 int, y3 int, hex string, width int) intStroke triangle.
x1 inty1 intx2 inty2 intx3 inty3 inthex stringwidth intint — a value of this type
polypub fn poly(pts &[]Point, fill string, stroke string, width int) intExecute poly.
pts &[]Pointfill stringstroke stringwidth intint — a value of this type
arcpub fn arc(cx int, cy int, r int, deg0 int, deg1 int, hex string, width int) intExecute arc.
cx intcy intr intdeg0 intdeg1 inthex stringwidth intint — a value of this type
pointpub fn point(x int, y int, hex string, r int) intExecute point.
x inty inthex stringr intint — a value of this type
click_ofpub fn click_of(ev ui.Event) ClickClick of.
ev ui.EventClick — a value of this type
poll_clickpub fn poll_click(ech chan ui.Event) ClickNext UI event if it is a canvas click (ok=0 otherwise). Uses App.event_ch.
ech chan ui.EventClick — a value of this type
pollpub fn poll(ech chan ui.Event) InputClick, trackpad/mouse-wheel scroll, or drag-to-pan. Other events → in_none.
ech chan ui.EventInput — a value of this type
promptpub fn prompt(ech chan ui.Event, title string, seed string) stringCompatibility: returns empty text on cancel/failure/timeout. Use ui.prompt_async for explicit outcomes. The event channel is preserved, including unrelated events.
ech chan ui.Eventtitle stringseed stringstring — result string
in_rectpub fn in_rect(c Click, x int, y int, w int, h int) boolIn rectangle.
c Clickx inty intw inth intbool — true or false
in_circlepub fn in_circle(c Click, cx int, cy int, r int) boolIn circle.
c Clickcx intcy intr intbool — true or false
struct SurfaceCachepub struct SurfaceCache {
}Owns one rasterized DisplayList. A changed immutable list ID, logical size, density or canvas generation replaces it only after the new snapshot succeeds. Explicitly dispose when retiring the cache. No caller-owned Surface is freed.
This type has no public fields.
new_surface_cachepub fn new_surface_cache() SurfaceCacheConstruct surface cache.
No arguments are required.
SurfaceCache — a value of this type
($&SurfaceCache) disposepub fn (cache $&SurfaceCache) dispose()Release and dispose native resources and underlying handles.
cache $&SurfaceCacheSurfaceCache instance used by this call (exclusive borrow).This call does not return a value.
($&SurfaceCache) closepub fn (cache $&SurfaceCache) close()Operation on $&SurfaceCache: close the resource.
cache $&SurfaceCacheSurfaceCache instance used by this call (exclusive borrow).This call does not return a value.
($&SurfaceCache) invalidatepub fn (cache $&SurfaceCache) invalidate()Invalidate the control area, requesting a repaint on next frame.
cache $&SurfaceCacheSurfaceCache instance used by this call (exclusive borrow).This call does not return a value.
($&SurfaceCache) updatepub fn (cache $&SurfaceCache) update(list &DisplayList,width f64,height f64,scale f64) boolReturns true only when pixels were regenerated. A failed replacement leaves the previous cache intact. Image updates do not mutate an already frozen list freeze a replacement list to intentionally change that content/version. Throws on failure; handle the error or propagate it to the caller.
cache $&SurfaceCacheSurfaceCache instance used by this call (exclusive borrow).list &DisplayListwidth f64height f64scale f64bool — true or false
($&Frame) cached_display_listpub fn (frame $&Frame) cached_display_list(cache $&SurfaceCache,list &DisplayList, x f64,y f64,width f64,height f64,scale f64,opacity f64,sampler int) intOperation on $&Frame: cached display list. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cache $&SurfaceCachelist &DisplayListx f64y f64width f64height f64scale f64opacity f64sampler intint — a value of this type
(&Color) rpub fn (c &Color) r() intExecute r on &Color.
c &ColorColor instance used by this call (borrow).int — a value of this type
(&Color) gpub fn (c &Color) g() intExecute g on &Color.
c &ColorColor instance used by this call (borrow).int — a value of this type
(&Color) bpub fn (c &Color) b() intExecute b on &Color.
c &ColorColor instance used by this call (borrow).int — a value of this type
(&Color) apub fn (c &Color) a() intExecute a on &Color.
c &ColorColor instance used by this call (borrow).int — a value of this type
(&Color) with_opacitypub fn (c &Color) with_opacity(opacity f64) ColorScales the existing alpha channel by opacity in [0, 1].
c &ColorColor instance used by this call (borrow).opacity f64Color — a value of this type
(&Color) opacitypub fn (c &Color) opacity(alpha_unit f64) ColorSets the alpha channel directly from a unit opacity in [0, 1].
c &ColorColor instance used by this call (borrow).alpha_unit f64Color — a value of this type
lerp_colorpub fn lerp_color(a Color, b Color, t f64) ColorLerp color.
a Colorb Colort f64Color — a value of this type
(&Color) lightenpub fn (c &Color) lighten(amount f64) ColorExecute lighten on &Color.
c &ColorColor instance used by this call (borrow).amount f64Color — a value of this type
(&Color) darkenpub fn (c &Color) darken(amount f64) ColorExecute darken on &Color.
c &ColorColor instance used by this call (borrow).amount f64Color — a value of this type
hexpub fn hex(code string) ColorParses #RGB, #RGBA, #RRGGBB, or #RRGGBBAA (leading '#' is optional). Throws on failure; handle the error or propagate it to the caller.
code stringColor — a value of this type
hslapub fn hsla(h f64, s f64, l f64, a f64) ColorConverts HSL (hue in degrees, saturation and lightness in [0, 1]) to Color.
h f64s f64l f64a f64Color — a value of this type
hslpub fn hsl(h f64, s f64, l f64) ColorExecute hsl.
h f64s f64l f64Color — a value of this type
round_strokepub fn round_stroke(width f64) StrokeOptionsRound stroke.
width f64StrokeOptions — a value of this type
dashed_strokepub fn dashed_stroke(width f64, dash_len f64, gap_len f64) StrokeOptionsDashed stroke.
width f64dash_len f64gap_len f64StrokeOptions — a value of this type
gradient_stoppub fn gradient_stop(offset f64, color Color) GradientStopGradient stop.
offset f64color ColorGradientStop — a value of this type
two_stop_linearpub fn two_stop_linear(x1 f64, y1 f64, x2 f64, y2 f64, start_color Color, end_color Color) GradientTwo stop linear.
x1 f64y1 f64x2 f64y2 f64start_color Colorend_color ColorGradient — a value of this type
two_stop_radialpub fn two_stop_radial(cx f64, cy f64, radius f64, inner_color Color, outer_color Color) GradientTwo stop radial.
cx f64cy f64radius f64inner_color Colorouter_color ColorGradient — a value of this type
(&Color) invertpub fn (c &Color) invert() ColorExecute invert on &Color.
c &ColorColor instance used by this call (borrow).Color — a value of this type
(&Color) grayscalepub fn (c &Color) grayscale() ColorExecute grayscale on &Color.
c &ColorColor instance used by this call (borrow).Color — a value of this type
(&Color) luminancepub fn (c &Color) luminance() f64Relative WCAG luminance in [0, 1].
c &ColorColor instance used by this call (borrow).f64 — a value of this type
contrast_ratiopub fn contrast_ratio(a Color, b Color) f64Contrast ratio.
a Colorb Colorf64 — a value of this type
(&Color) contrasting_inkpub fn (bg &Color) contrasting_ink(light Color, dark Color) ColorOperation on &Color: contrasting ink.
bg &ColorColor instance used by this call (borrow).light Colordark ColorColor — a value of this type
(&Color) to_hex_rgbapub fn (c &Color) to_hex_rgba() stringOperation on &Color: convert to hex rgba.
c &ColorColor instance used by this call (borrow).string — result string
(&Color) to_hexpub fn (c &Color) to_hex() stringOperation on &Color: convert to hex.
c &ColorColor instance used by this call (borrow).string — result string
(&Color) blend_overpub fn (fg &Color) blend_over(bg Color) ColorPorter-Duff source-over compositing of foreground fg onto backdrop bg in straight sRGB.
fg &ColorColor instance used by this call (borrow).bg ColorColor — a value of this type
lerp_color_premulpub fn lerp_color_premul(a Color, b Color, t f64) ColorPremultiplied-alpha linear interpolation avoids dark fringes when fading to transparent.
a Colorb Colort f64Color — a value of this type
hsvapub fn hsva(h f64, s f64, v f64, a f64) ColorConverts HSV (hue in degrees, saturation and value in [0, 1]) to Color.
h f64s f64v f64a f64Color — a value of this type
hsvpub fn hsv(h f64, s f64, v f64) ColorExecute hsv.
h f64s f64v f64Color — a value of this type
mix_palettepub fn mix_palette(start_color Color, end_color Color, steps int) []ColorMix palette.
start_color Colorend_color Colorsteps int[]Color — slice result
const BLEND_SOURCE_OVERpub const BLEND_SOURCE_OVER = 0Constant BLEND_SOURCE_OVER, defining protocol or algorithm parameters.
const BLEND_COPYpub const BLEND_COPY = 1Constant BLEND_COPY, defining protocol or algorithm parameters.
const BLEND_DESTINATION_INpub const BLEND_DESTINATION_IN = 2Constant BLEND_DESTINATION_IN, defining protocol or algorithm parameters.
const BLEND_DESTINATION_OUTpub const BLEND_DESTINATION_OUT = 3Constant BLEND_DESTINATION_OUT, defining protocol or algorithm parameters.
const BLEND_MULTIPLYpub const BLEND_MULTIPLY = 4Constant BLEND_MULTIPLY, defining protocol or algorithm parameters.
const BLEND_SCREENpub const BLEND_SCREEN = 5Constant BLEND_SCREEN, defining protocol or algorithm parameters.
const BLEND_ADDpub const BLEND_ADD = 6Constant BLEND_ADD, defining protocol or algorithm parameters.
const BLEND_XORpub const BLEND_XOR = 7Constant BLEND_XOR, defining protocol or algorithm parameters.
(&Surface) compositepub fn (backdrop &Surface) composite(source &Surface, mode int, opacity f64) SurfaceSame logical bounds and backing resolution are required. This Surface is the backdrop, source is the foreground. Produces an immutable cache; original pixels are unchanged. The caller explicitly owns/disposes the returned handle. Throws on failure; handle the error or propagate it to the caller.
backdrop &SurfaceSurface instance used by this call (borrow).source &Surfacemode intopacity f64Surface — a value of this type
($&Frame) fill_path_gradientpub fn (frame $&Frame) fill_path_gradient(path &Path,paint &Gradient,bounds &ImageRect,scale f64,rule int) intGradient coordinates are local to bounds. Path coordinates remain in the caller's current logical space. Explicit density controls raster quality parent CTM/clip apply when the generated painted Path is composited. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).path &Pathpaint &Gradientbounds &ImageRectscale f64rule intint — a value of this type
struct DisplayListpub struct DisplayList {
}Immutable vector fragment. Captures current resource versions and compiles native paths once. Copies share one handle. Dispose explicitly; queued frames retain it. Draw under the caller's CTM/clip with isolated default pen state. Background-clearing commands cannot be captured: use an explicit rectangle.
This type has no public fields.
($&Frame) freezepub fn (frame $&Frame) freeze() DisplayListExecute freeze on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).DisplayList — a value of this type
($&DisplayList) disposepub fn (list $&DisplayList) dispose() intRelease and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.
list $&DisplayListDisplayList instance used by this call (exclusive borrow).int — a value of this type
($&DisplayList) closepub fn (list $&DisplayList) close() intOperation on $&DisplayList: close the resource. Throws on failure; handle the error or propagate it to the caller.
list $&DisplayListDisplayList instance used by this call (exclusive borrow).int — a value of this type
($&Frame) display_listpub fn (frame $&Frame) display_list(list &DisplayList) intOperation on $&Frame: display list. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).list &DisplayListint — a value of this type
(&DisplayList) snapshotpub fn (list &DisplayList) snapshot(width f64,height f64,scale f64) SurfaceExecute snapshot on &DisplayList. Throws on failure; handle the error or propagate it to the caller.
list &DisplayListDisplayList instance used by this call (borrow).width f64height f64scale f64Surface — a value of this type
struct DisplayListPoolpub struct DisplayListPool {
}Owns keyed immutable vector records in one canvas domain. Replacements are captured before retiring the old handle; queued/captured scenes retain their resource versions. The native process-wide list/memory limits still apply.
This type has no public fields.
(&Context) display_list_poolpub fn (context &Context) display_list_pool() DisplayListPoolOperation on &Context: display list pool.
context &ContextContext instance used by this call (borrow).DisplayListPool — a value of this type
(&DisplayListPool) is_currentpub fn (pool &DisplayListPool) is_current(key int,revision int) boolOperation on &DisplayListPool: whether it is current.
pool &DisplayListPoolDisplayListPool instance used by this call (borrow).key intrevision intbool — true or false
($&DisplayListPool) capturepub fn (pool $&DisplayListPool) capture(key int,revision int,frame $&Frame) intExecute capture on $&DisplayListPool. Throws on failure; handle the error or propagate it to the caller.
pool $&DisplayListPoolDisplayListPool instance used by this call (exclusive borrow).key intrevision intframe $&Frameint — a value of this type
($&DisplayListPool) removepub fn (pool $&DisplayListPool) remove(key int)Operation on $&DisplayListPool: remove.
pool $&DisplayListPoolDisplayListPool instance used by this call (exclusive borrow).key intThis call does not return a value.
($&DisplayListPool) disposepub fn (pool $&DisplayListPool) dispose()Release and dispose native resources and underlying handles.
pool $&DisplayListPoolDisplayListPool instance used by this call (exclusive borrow).This call does not return a value.
($&DisplayListPool) closepub fn (pool $&DisplayListPool) close()Operation on $&DisplayListPool: close the resource.
pool $&DisplayListPoolDisplayListPool instance used by this call (exclusive borrow).This call does not return a value.
($&Frame) pooled_display_listpub fn (frame $&Frame) pooled_display_list(pool &DisplayListPool,key int) intOperation on $&Frame: pooled display list. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).pool &DisplayListPoolkey intint — a value of this type
default_font_stackpub fn default_font_stack() font.FontStackReturns a pure-Xu font stack initialized with the embedded geometric fallback face. Throws on failure; handle the error or propagate it to the caller.
No arguments are required.
font.FontStack — a value of this type
add_ttf_facepub fn add_ttf_face(stack $&font.FontStack, ttf_bytes &[]u8, font_index int, face_id int) intParses a TrueType/OpenType font payload and registers it onto stack. Throws on failure; handle the error or propagate it to the caller.
stack $&font.FontStackttf_bytes &[]u8font_index intface_id intint — a value of this type
font_metrics_to_drawpub fn font_metrics_to_draw(m &font.TextMetrics) TextMetricsConverts pure-Xu font metrics into draw.TextMetrics.
m &font.TextMetricsTextMetrics — a value of this type
layout_font_textpub fn layout_font_text(stack &font.FontStack, value &string, options &TextOptions, masked bool) font.TextLayoutShapes UTF-8 text in pure Xu without requiring the ':xu:' native host. Throws on failure; handle the error or propagate it to the caller.
stack &font.FontStackvalue &stringoptions &TextOptionsmasked boolfont.TextLayout — a value of this type
(&Context) measure_text_optionspub fn (context &Context) measure_text_options(value &string, options &TextOptions, masked bool) TextMetricsMeasures UTF-8 text using ':xu:' when active, or pure-Xu #ui/font when hostless. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).value &stringoptions &TextOptionsmasked boolTextMetrics — a value of this type
($&Frame) text_font_layoutpub fn (frame $&Frame) text_font_layout(ly &font.TextLayout, value &string, x f64, y f64, color Color) intEmits positioned per-line XDF_OP_TEXT records from a pure-Xu font.TextLayout. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).ly &font.TextLayoutvalue &stringx f64y f64color Colorint — a value of this type
const MAX_FRAME_BYTESpub const MAX_FRAME_BYTES = 4194304XDF1 is a bounded little-endian frame ABI. Each recorder owns its storage. Explicit window contexts carry a generation and are revoked on native close.
const MAX_FRAME_COMMANDSpub const MAX_FRAME_COMMANDS = 100000Constant MAX_FRAME_COMMANDS, defining protocol or algorithm parameters.
const MAX_STATE_DEPTHpub const MAX_STATE_DEPTH = 256Constant MAX_STATE_DEPTH, defining protocol or algorithm parameters.
struct Colorpub struct Color {
}Color context or state structure.
This type has no public fields.
rgbapub fn rgba(r int, g int, b int, a int) ColorStraight (unpremultiplied) sRGB bytes. Components saturate to 0...255.
r intg intb inta intColor — a value of this type
(&Color) valuepub fn (color &Color) value() intReturn the packed straight RGBA value with R in the most significant byte.
color &ColorColor instance used by this call (borrow).0xRRGGBBAA integer
(&Color) with_alphapub fn (color &Color) with_alpha(alpha int) ColorDerive a color with alpha replaced and clamped to 0–255.
color &ColorColor instance used by this call (borrow).alpha inta new Color
rgbpub fn rgb(r int, g int, b int) ColorExecute rgb.
r intg intb intColor — a value of this type
struct Contextpub struct Context {
}Context context or state structure.
This type has no public fields.
(&Context) clonepub fn (context &Context) clone() ContextCopy only the checked canvas identity; resources remain canvas-owned.
context &ContextContext instance used by this call (borrow).Context — a value of this type
(&Context) matches_canvaspub fn (context &Context) matches_canvas(identity &ui.CanvasEvent) boolRetained controls require a checked generation from canvas_ready.
context &ContextContext instance used by this call (borrow).identity &ui.CanvasEventbool — true or false
default_contextpub fn default_context() ContextDefault context.
No arguments are required.
Context — a value of this type
hostless_contextpub fn hostless_context(canvas_id int, generation int) ContextHostless context.
canvas_id intgeneration intContext — a value of this type
context_ofpub fn context_of(event &ui.Event) ContextBind to a native canvas_ready event. The host rejects this Context after that generation closes, even if its numeric canvas ID is later reused. Throws on failure; handle the error or propagate it to the caller.
event &ui.EventContext — a value of this type
window_contextpub fn window_context(window &ui.Window) ContextWindow context. Throws on failure; handle the error or propagate it to the caller.
window &ui.WindowContext — a value of this type
struct Framepub struct Frame {
}Draw Protocol data frame encapsulation.
This type has no public fields.
(&Context) new_framepub fn (c &Context) new_frame(capacity int) FrameOperation on &Context: construct frame.
c &ContextContext instance used by this call (borrow).capacity intFrame — a value of this type
($&Frame) beginpub fn (f $&Frame) begin() intDiscards only this recorder's unsubmitted work. Capacity is retained. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).int — a value of this type
($&Frame) cancelpub fn (f $&Frame) cancel()Execute cancel on $&Frame.
f $&FrameFrame instance used by this call (exclusive borrow).This call does not return a value.
(&Frame) byte_lenpub fn (f &Frame) byte_len() intOperation on &Frame: byte len.
f &FrameFrame instance used by this call (borrow).int — a value of this type
(&Frame) capacitypub fn (f &Frame) capacity() intExecute capacity on &Frame.
f &FrameFrame instance used by this call (borrow).int — a value of this type
(&Frame) command_countpub fn (f &Frame) command_count() intOperation on &Frame: command count.
f &FrameFrame instance used by this call (borrow).int — a value of this type
($&Frame) export_xdfpub fn (f $&Frame) export_xdf() stringSeals and returns the XDF1 frame payload without submitting to the ':xu:' UI host, allowing engine/GPU/software backends to consume ui/draw commands. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).string — result string
($&Frame) presentpub fn (f $&Frame) present() intSeal and submit a complete frame. Success means queued, not displayed. A full queue preserves the sealed frame for retry or rebuilding with cancel / begin.
f $&FrameFrame instance used by this call (exclusive borrow).0 on success; throws on failure
($&Frame) present_waitpub fn (f $&Frame) present_wait() intWorker-thread submission parks for bounded queue capacity. Validation and closed-canvas errors still fail immediately once admission is available. UI hosts must continue draining commands on their own native thread. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).int — a value of this type
($&Frame) set_bgpub fn (f $&Frame) set_bg(color Color) intOperation on $&Frame: set bg. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).color Colorint — a value of this type
($&Frame) set_colorpub fn (f $&Frame) set_color(color Color) intOperation on $&Frame: set color. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).color Colorint — a value of this type
($&Frame) set_fillpub fn (f $&Frame) set_fill(color Color) intOperation on $&Frame: set fill. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).color Colorint — a value of this type
($&Frame) set_strokepub fn (f $&Frame) set_stroke(color Color) intOperation on $&Frame: set stroke. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).color Colorint — a value of this type
($&Frame) set_widthpub fn (f $&Frame) set_width(width f64) intOperation on $&Frame: set width. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).width f64int — a value of this type
($&Frame) pushpub fn (f $&Frame) push() intExecute push on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).int — a value of this type
($&Frame) poppub fn (f $&Frame) pop() intExecute pop on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).int — a value of this type
($&Frame) originpub fn (f $&Frame) origin() intExecute origin on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).int — a value of this type
($&Frame) translatepub fn (f $&Frame) translate(x f64, y f64) intExecute translate on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64int — a value of this type
($&Frame) rotatepub fn (f $&Frame) rotate(degrees f64) intExecute rotate on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).degrees f64int — a value of this type
($&Frame) scalepub fn (f $&Frame) scale(x f64, y f64) intScale factors: 1 = 100%. The legacy free function still uses percent. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64int — a value of this type
($&Frame) clip_rectpub fn (f $&Frame) clip_rect(x f64, y f64, w f64, h f64) intOperation on $&Frame: clip rectangle. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64w f64h f64int — a value of this type
($&Frame) rectpub fn (f $&Frame) rect(x f64, y f64, w f64, h f64) intOperation on $&Frame: draw or fill a rectangle on the canvas. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64w f64h f64int — a value of this type
($&Frame) rect_linepub fn (f $&Frame) rect_line(x f64, y f64, w f64, h f64) intOperation on $&Frame: rectangle line. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64w f64h f64int — a value of this type
($&Frame) fill_rectpub fn (f $&Frame) fill_rect(x f64, y f64, w f64, h f64, color Color) intOperation on $&Frame: fill rectangle. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64w f64h f64color Colorint — a value of this type
($&Frame) stroke_rectpub fn (f $&Frame) stroke_rect(x f64, y f64, w f64, h f64, color Color, width f64) intOperation on $&Frame: stroke rectangle. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64w f64h f64color Colorwidth f64int — a value of this type
($&Frame) ellipsepub fn (f $&Frame) ellipse(x f64, y f64, w f64, h f64) intExecute ellipse on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64w f64h f64int — a value of this type
($&Frame) linepub fn (f $&Frame) line(x1 f64, y1 f64, x2 f64, y2 f64, color Color, width f64) intExecute line on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64x2 f64y2 f64color Colorwidth f64int — a value of this type
($&Frame) textpub fn (f $&Frame) text(x f64, y f64, size f64, color Color, text &string) intUTF-8 text is length-delimited: tabs/newlines cannot inject host commands. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64size f64color Colortext &stringint — a value of this type
($&Frame) circlepub fn (f $&Frame) circle(x f64, y f64, radius f64) intExecute circle on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x f64y f64radius f64int — a value of this type
($&Frame) trianglepub fn (f $&Frame) triangle(x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64) intExecute triangle on $&Frame. Throws on failure; handle the error or propagate it to the caller.
f $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64x2 f64y2 f64x3 f64y3 f64int — a value of this type
bezier_quad_pointpub fn bezier_quad_point(x1 f64, y1 f64, cx f64, cy f64, x2 f64, y2 f64, t f64) PathPointBezier quad point.
x1 f64y1 f64cx f64cy f64x2 f64y2 f64t f64PathPoint — a value of this type
bezier_cubic_pointpub fn bezier_cubic_point(x1 f64, y1 f64, c1x f64, c1y f64, c2x f64, c2y f64, x2 f64, y2 f64, t f64) PathPointBezier cubic point.
x1 f64y1 f64c1x f64c1y f64c2x f64c2y f64x2 f64y2 f64t f64PathPoint — a value of this type
bezier_cubic_tangentpub fn bezier_cubic_tangent(x1 f64, y1 f64, c1x f64, c1y f64, c2x f64, c2y f64, x2 f64, y2 f64, t f64) PathPointBezier cubic tangent.
x1 f64y1 f64c1x f64c1y f64c2x f64c2y f64x2 f64y2 f64t f64PathPoint — a value of this type
point_in_rectpub fn point_in_rect(px f64, py f64, x f64, y f64, width f64, height f64) boolPoint in rectangle.
px f64py f64x f64y f64width f64height f64bool — true or false
point_in_circlepub fn point_in_circle(px f64, py f64, cx f64, cy f64, radius f64) boolPoint in circle.
px f64py f64cx f64cy f64radius f64bool — true or false
point_in_ellipsepub fn point_in_ellipse(px f64, py f64, cx f64, cy f64, rx f64, ry f64) boolPoint in ellipse.
px f64py f64cx f64cy f64rx f64ry f64bool — true or false
point_in_round_rectpub fn point_in_round_rect(px f64, py f64, x f64, y f64, width f64, height f64, radius f64) boolPoint in round rectangle.
px f64py f64x f64y f64width f64height f64radius f64bool — true or false
point_in_round_rect_cornerspub 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) boolPoint in round rectangle corners.
px f64py f64x f64y f64width f64height f64tl f64tr f64br f64bl f64bool — true or false
point_in_trianglepub fn point_in_triangle(px f64, py f64, x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64) boolPoint in triangle.
px f64py f64x1 f64y1 f64x2 f64y2 f64x3 f64y3 f64bool — true or false
point_in_polygonpub fn point_in_polygon(px f64, py f64, points &[]PathPoint) boolPoint in polygon.
px f64py f64points &[]PathPointbool — true or false
point_in_sectorpub fn point_in_sector(px f64, py f64, cx f64, cy f64, inner_radius f64, outer_radius f64, start_deg f64, sweep_deg f64) boolPoint in sector.
px f64py f64cx f64cy f64inner_radius f64outer_radius f64start_deg f64sweep_deg f64bool — true or false
distance_to_segmentpub fn distance_to_segment(px f64, py f64, x1 f64, y1 f64, x2 f64, y2 f64) f64Distance to segment.
px f64py f64x1 f64y1 f64x2 f64y2 f64f64 — a value of this type
point_near_segmentpub fn point_near_segment(px f64, py f64, x1 f64, y1 f64, x2 f64, y2 f64, tolerance f64) boolPoint near segment.
px f64py f64x1 f64y1 f64x2 f64y2 f64tolerance f64bool — true or false
point_near_polylinepub fn point_near_polyline(px f64, py f64, points &[]PathPoint, tolerance f64) boolPoint near polyline.
px f64py f64points &[]PathPointtolerance f64bool — true or false
(&Path) flatten_subpathspub fn (path &Path) flatten_subpaths(tolerance f64) [][]PathPointFlattens a Path into separate subpaths (one slice per move_to figure).
path &PathPath instance used by this call (borrow).tolerance f64[][]PathPoint — slice result
(&Path) flattenpub fn (path &Path) flatten(tolerance f64) []PathPointFlattens a Path into a polyline of anchor points by adaptive subdivision of curves.
path &PathPath instance used by this call (borrow).tolerance f64[]PathPoint — slice result
(&Path) contains_with_rulepub fn (path &Path) contains_with_rule(px f64, py f64, rule int) boolOperation on &Path: contains with rule.
path &PathPath instance used by this call (borrow).px f64py f64rule intbool — true or false
(&Path) containspub fn (path &Path) contains(px f64, py f64) boolOperation on &Path: report whether the input contains the given piece.
path &PathPath instance used by this call (borrow).px f64py f64bool — true or false
(&Path) hit_strokepub fn (path &Path) hit_stroke(px f64, py f64, tolerance f64) boolOperation on &Path: hit stroke.
path &PathPath instance used by this call (borrow).px f64py f64tolerance f64bool — true or false
const SPREAD_PADpub const SPREAD_PAD = 0Constant SPREAD_PAD, defining protocol or algorithm parameters.
const SPREAD_REPEATpub const SPREAD_REPEAT = 1Constant SPREAD_REPEAT, defining protocol or algorithm parameters.
const SPREAD_REFLECTpub const SPREAD_REFLECT = 2Constant SPREAD_REFLECT, defining protocol or algorithm parameters.
struct GradientStoppub struct GradientStop {
pub offset f64
pub color Color
}Structure encapsulating offset, color.
offset f64color Colorstruct Gradientpub struct Gradient {
pub spread int
pub stops []GradientStop
}Structure encapsulating spread, stops.
spread intstops []GradientStoplinear_gradientpub fn linear_gradient(x0 f64, y0 f64, x1 f64, y1 f64, stops []GradientStop) GradientLinear gradient.
x0 f64y0 f64x1 f64y1 f64stops []GradientStopGradient — a value of this type
radial_gradientpub fn radial_gradient(x f64, y f64, radius f64, stops []GradientStop) GradientRadial gradient.
x f64y f64radius f64stops []GradientStopGradient — a value of this type
(&Context) gradientpub fn (context &Context) gradient(width f64, height f64, scale f64, paint &Gradient) SurfaceRasterize once at explicit density, using pixel centers in logical units. 2...32 strictly increasing stops, first=0 and last=1. Interpolation uses premultiplied encoded sRGB; transparent stop RGB has no influence. This is a reusable raster paint layer; scaling it later samples its cached resolution. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).width f64height f64scale f64paint &GradientSurface — a value of this type
const SAMPLER_NEARESTpub const SAMPLER_NEAREST = 0Constant SAMPLER_NEAREST, defining protocol or algorithm parameters.
const SAMPLER_LINEARpub const SAMPLER_LINEAR = 1Constant SAMPLER_LINEAR, defining protocol or algorithm parameters.
const MAX_IMAGE_BYTESpub const MAX_IMAGE_BYTES = 67108864Constant MAX_IMAGE_BYTES, defining protocol or algorithm parameters.
const MAX_IMAGE_DIMENSIONpub const MAX_IMAGE_DIMENSION = 16384Constant MAX_IMAGE_DIMENSION, defining protocol or algorithm parameters.
struct Imagepub struct Image {
pub width int
pub height int
}A canvas-scoped resource. Explicitly dispose when no longer needed. Accepted frames retain immutable versions, so update/dispose cannot alter those frames.
width intheight intstruct ImageRectpub struct ImageRect {
pub x f64
pub y f64
pub width f64
pub height f64
}Structure encapsulating x, y, width, height.
x f64y f64width f64height f64(&Context) image_rgbapub fn (context &Context) image_rgba(width int, height int, stride int, data &string) ImageTop-left, straight sRGB RGBA8. stride=0 means width*4; otherwise include every row's padding in data. Input is borrowed; the native resource owns its copy. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).width intheight intstride intdata &stringImage — a value of this type
(&Context) image_pixelspub fn (context &Context) image_pixels(bitmap &image.RGBA) ImageInteroperate with #image's CPU pixel buffers, including nonzero rect origins. These are the same straight RGBA8 bytes used by its PNG/JPEG decoder paths. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).bitmap &image.RGBAImage — a value of this type
(&Context) image_encodedpub fn (context &Context) image_encoded(data &string) ImageDecode PNG/JPEG once at load time. Palette/gray/interlaced PNG and progressive JPEG share the same bounded native decoder on all three hosts. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).data &stringImage — a value of this type
(&Context) load_imagepub fn (context &Context) load_image(path &string) ImageBounded native file read; Windows paths are UTF-8 and opened with CreateFileW. Only regular files up to 64 MiB are accepted. The input buffer also counts toward the shared decoder scratch budget while decoding. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).path &stringImage — a value of this type
(&Context) load_embedded_imagepub fn (context &Context) load_embedded_image(path &string) ImageOperation on &Context: load embedded image. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).path &stringImage — a value of this type
(&Image) update_rgbapub fn (image &Image) update_rgba(stride int, data &string) intSame dimensions, new immutable version. Existing accepted frames keep their old pixels; the next successful present captures the new version. Throws on failure; handle the error or propagate it to the caller.
image &ImageImage instance used by this call (borrow).stride intdata &stringint — a value of this type
($&Image) disposepub fn (image $&Image) dispose() intRelease and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.
image $&ImageImage instance used by this call (exclusive borrow).int — a value of this type
($&Image) closepub fn (image $&Image) close() intOperation on $&Image: close the resource. Throws on failure; handle the error or propagate it to the caller.
image $&ImageImage instance used by this call (exclusive borrow).int — a value of this type
($&Frame) image_regionpub fn (frame $&Frame) image_region(image &Image, source &ImageRect, destination &ImageRect, opacity f64, sampler int) intSource coordinates are pixels; destination coordinates follow the frame CTM. Opacity is 0...1; sampler_nearest/linear are explicit and portable. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).image &Imagesource &ImageRectdestination &ImageRectopacity f64sampler intint — a value of this type
($&Frame) imagepub fn (frame $&Frame) image(image &Image, x f64, y f64, width f64, height f64) intExecute image on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).image &Imagex f64y f64width f64height f64int — a value of this type
const MAX_LAYER_DEPTHpub const MAX_LAYER_DEPTH = 16Constant MAX_LAYER_DEPTH, defining protocol or algorithm parameters.
($&Frame) begin_layerpub fn (frame $&Frame) begin_layer(bounds &ImageRect, scale f64, opacity f64) intIsolated transparent child frame, with its own white pen, identity CTM and [0,width]x[0,height] bounds. Parent state/clip are restored at end_layer and apply to the resulting image at (x,y). Rasterization occurs once at end_layer. begin/cancel/dispose discard every open child and owned temporary resource. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).bounds &ImageRectscale f64opacity f64int — a value of this type
($&Frame) end_layerpub fn (frame $&Frame) end_layer() intOperation on $&Frame: end layer. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).int — a value of this type
($&Frame) disposepub fn (frame $&Frame) dispose()A Frame can own transient native images after end_layer/gradient fills. Explicitly retire a recorder that will not be presented or reused.
frame $&FrameFrame instance used by this call (exclusive borrow).This call does not return a value.
($&Frame) closepub fn (frame $&Frame) close()Operation on $&Frame: close the resource.
frame $&FrameFrame instance used by this call (exclusive borrow).This call does not return a value.
struct Matrix2Dpub struct Matrix2D {
pub a f64
pub b f64
pub c f64
pub d f64
pub tx f64
pub ty f64
}2D affine transformation matrix [ a c tx ] [ b d ty ] [ 0 0 1 ]
a f64b f64c f64d f64tx f64ty f64identity_matrixpub fn identity_matrix() Matrix2DIdentity matrix.
No arguments are required.
Matrix2D — a value of this type
translation_matrixpub fn translation_matrix(tx f64, ty f64) Matrix2DTranslation matrix.
tx f64ty f64Matrix2D — a value of this type
scaling_matrixpub fn scaling_matrix(sx f64, sy f64) Matrix2DScaling matrix.
sx f64sy f64Matrix2D — a value of this type
rotation_matrixpub fn rotation_matrix(degrees f64) Matrix2DRotation matrix.
degrees f64Matrix2D — a value of this type
skew_matrixpub fn skew_matrix(skew_x_deg f64, skew_y_deg f64) Matrix2DSkew matrix.
skew_x_deg f64skew_y_deg f64Matrix2D — a value of this type
(&Matrix2D) multiplypub fn (m &Matrix2D) multiply(other &Matrix2D) Matrix2DExecute multiply on &Matrix2D.
m &Matrix2DMatrix2D instance used by this call (borrow).other &Matrix2DMatrix2D — a value of this type
(&Matrix2D) translatepub fn (m &Matrix2D) translate(tx f64, ty f64) Matrix2DExecute translate on &Matrix2D.
m &Matrix2DMatrix2D instance used by this call (borrow).tx f64ty f64Matrix2D — a value of this type
(&Matrix2D) scalepub fn (m &Matrix2D) scale(sx f64, sy f64) Matrix2DExecute scale on &Matrix2D.
m &Matrix2DMatrix2D instance used by this call (borrow).sx f64sy f64Matrix2D — a value of this type
(&Matrix2D) rotatepub fn (m &Matrix2D) rotate(degrees f64) Matrix2DExecute rotate on &Matrix2D.
m &Matrix2DMatrix2D instance used by this call (borrow).degrees f64Matrix2D — a value of this type
(&Matrix2D) determinantpub fn (m &Matrix2D) determinant() f64Execute determinant on &Matrix2D.
m &Matrix2DMatrix2D instance used by this call (borrow).f64 — a value of this type
(&Matrix2D) is_invertiblepub fn (m &Matrix2D) is_invertible() boolOperation on &Matrix2D: whether it is invertible.
m &Matrix2DMatrix2D instance used by this call (borrow).bool — true or false
(&Matrix2D) inversepub fn (m &Matrix2D) inverse() Matrix2DExecute inverse on &Matrix2D. Throws on failure; handle the error or propagate it to the caller.
m &Matrix2DMatrix2D instance used by this call (borrow).Matrix2D — a value of this type
(&Matrix2D) map_pointpub fn (m &Matrix2D) map_point(x f64, y f64) PathPointOperation on &Matrix2D: map point.
m &Matrix2DMatrix2D instance used by this call (borrow).x f64y f64PathPoint — a value of this type
(&Matrix2D) map_boundspub fn (m &Matrix2D) map_bounds(rect &ImageRect) ImageRectOperation on &Matrix2D: map bounds.
m &Matrix2DMatrix2D instance used by this call (borrow).rect &ImageRectImageRect — a value of this type
($&Frame) rotate_aroundpub fn (frame $&Frame) rotate_around(cx f64, cy f64, degrees f64) intOperation on $&Frame: rotate around. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64degrees f64int — a value of this type
($&Frame) scale_aroundpub fn (frame $&Frame) scale_around(cx f64, cy f64, sx f64, sy f64) intOperation on $&Frame: scale around. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64sx f64sy f64int — a value of this type
(&Path) clonepub fn (path &Path) clone() PathOperation on &Path: copy into a new independent string.
path &PathPath instance used by this call (borrow).Path — a value of this type
($&Path) append_transformedpub fn (path $&Path) append_transformed(other &Path, m &Matrix2D) intOperation on $&Path: append transformed. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).other &Pathm &Matrix2Dint — a value of this type
($&Path) appendpub fn (path $&Path) append(other &Path) intOperation on $&Path: append. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).other &Pathint — a value of this type
($&Path) transformpub fn (path $&Path) transform(m &Matrix2D) intExecute transform on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).m &Matrix2Dint — a value of this type
($&Path) translatepub fn (path $&Path) translate(dx f64, dy f64) intExecute translate on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).dx f64dy f64int — a value of this type
($&Path) scalepub fn (path $&Path) scale(sx f64, sy f64) intExecute scale on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).sx f64sy f64int — a value of this type
($&Path) rotatepub fn (path $&Path) rotate(degrees f64) intExecute rotate on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).degrees f64int — a value of this type
($&Path) rotate_aroundpub fn (path $&Path) rotate_around(cx f64, cy f64, degrees f64) intOperation on $&Path: rotate around. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64degrees f64int — a value of this type
(&Path) boundspub fn (path &Path) bounds() ImageRectReturn the bounding Rectangle of the control or geometry.
path &PathPath instance used by this call (borrow).ImageRect — a value of this type
(&Path) tight_boundspub fn (path &Path) tight_bounds() ImageRectOperation on &Path: tight bounds.
path &PathPath instance used by this call (borrow).ImageRect — a value of this type
const PALETTE_VIRIDISpub const PALETTE_VIRIDIS = 0Constant PALETTE_VIRIDIS, defining protocol or algorithm parameters.
const PALETTE_PLASMApub const PALETTE_PLASMA = 1Constant PALETTE_PLASMA, defining protocol or algorithm parameters.
const PALETTE_COOLWARMpub const PALETTE_COOLWARM = 2Constant PALETTE_COOLWARM, defining protocol or algorithm parameters.
const PALETTE_OCEANpub const PALETTE_OCEAN = 3Constant PALETTE_OCEAN, defining protocol or algorithm parameters.
const PALETTE_SUNSETpub const PALETTE_SUNSET = 4Constant PALETTE_SUNSET, defining protocol or algorithm parameters.
const PALETTE_FORESTpub const PALETTE_FOREST = 5Constant PALETTE_FOREST, defining protocol or algorithm parameters.
palette_colorspub fn palette_colors(kind int) []ColorPalette colors.
kind int[]Color — slice result
sample_color_stopspub fn sample_color_stops(colors &[]Color, t f64) ColorSample color stops.
colors &[]Colort f64Color — a value of this type
sample_palettepub fn sample_palette(kind int, t f64) ColorSample palette.
kind intt f64Color — a value of this type
multi_stop_linearpub fn multi_stop_linear(x0 f64, y0 f64, x1 f64, y1 f64, colors &[]Color) GradientMulti stop linear. Throws on failure; handle the error or propagate it to the caller.
x0 f64y0 f64x1 f64y1 f64colors &[]ColorGradient — a value of this type
multi_stop_radialpub fn multi_stop_radial(cx f64, cy f64, radius f64, colors &[]Color) GradientMulti stop radial. Throws on failure; handle the error or propagate it to the caller.
cx f64cy f64radius f64colors &[]ColorGradient — a value of this type
const MAX_PATH_BYTESpub const MAX_PATH_BYTES = 2097152Constant MAX_PATH_BYTES, defining protocol or algorithm parameters.
const MAX_PATH_SEGMENTSpub const MAX_PATH_SEGMENTS = 32768Constant MAX_PATH_SEGMENTS, defining protocol or algorithm parameters.
const FILL_NONZEROpub const FILL_NONZERO = 0Constant FILL_NONZERO, defining protocol or algorithm parameters.
const FILL_EVENODDpub const FILL_EVENODD = 1Constant FILL_EVENODD, defining protocol or algorithm parameters.
const CAP_BUTTpub const CAP_BUTT = 0Constant CAP_BUTT, defining protocol or algorithm parameters.
const CAP_ROUNDpub const CAP_ROUND = 1Constant CAP_ROUND, defining protocol or algorithm parameters.
const CAP_SQUAREpub const CAP_SQUARE = 2Constant CAP_SQUARE, defining protocol or algorithm parameters.
const JOIN_MITERpub const JOIN_MITER = 0Constant JOIN_MITER, defining protocol or algorithm parameters.
const JOIN_ROUNDpub const JOIN_ROUND = 1Constant JOIN_ROUND, defining protocol or algorithm parameters.
const JOIN_BEVELpub const JOIN_BEVEL = 2Constant JOIN_BEVEL, defining protocol or algorithm parameters.
struct Pathpub struct Path {
}Reusable CPU recorder. A failed operation poisons the path until clear. Frame operations copy a snapshot, so later edits cannot alter recorded work.
This type has no public fields.
new_pathpub fn new_path(capacity int) PathConstruct path.
capacity intPath — a value of this type
($&Path) clearpub fn (path $&Path) clear()Clear all buffered or stored entries and internal state.
path $&PathPath instance used by this call (exclusive borrow).This call does not return a value.
(&Path) byte_lenpub fn (path &Path) byte_len() intOperation on &Path: byte len.
path &PathPath instance used by this call (borrow).int — a value of this type
(&Path) capacitypub fn (path &Path) capacity() intExecute capacity on &Path.
path &PathPath instance used by this call (borrow).int — a value of this type
(&Path) segment_countpub fn (path &Path) segment_count() intOperation on &Path: segment count.
path &PathPath instance used by this call (borrow).int — a value of this type
($&Path) move_topub fn (path $&Path) move_to(x f64, y f64) intOperation on $&Path: move to. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64int — a value of this type
($&Path) line_topub fn (path $&Path) line_to(x f64, y f64) intOperation on $&Path: line to. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64int — a value of this type
($&Path) quad_topub fn (path $&Path) quad_to(cx f64, cy f64, x f64, y f64) intOperation on $&Path: quad to. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64x f64y f64int — a value of this type
($&Path) cubic_topub fn (path $&Path) cubic_to(c1x f64, c1y f64, c2x f64, c2y f64, x f64, y f64) intOperation on $&Path: cubic to. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).c1x f64c1y f64c2x f64c2y f64x f64y f64int — a value of this type
($&Path) closepub fn (path $&Path) close() intEnds this figure. Start another with move_to before adding more segments. Filling implicitly closes open figures; stroking preserves their open ends. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).int — a value of this type
struct StrokeOptionspub 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 Configuration parameters and options set.
width f64cap intjoin intmiter_limit f64dashes []f64dash_offset f64flatten_tolerance f64stroke_optionspub fn stroke_options(width f64) StrokeOptionsStroke options.
width f64StrokeOptions — a value of this type
($&Frame) fill_pathpub fn (frame $&Frame) fill_path(path &Path, color Color, rule int) intOperation on $&Frame: fill path. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).path &Pathcolor Colorrule intint — a value of this type
($&Frame) stroke_pathpub fn (frame $&Frame) stroke_path(path &Path, color Color, style &StrokeOptions) intDash lengths are positive, even-count on/off pairs in logical units. Phase restarts for each figure. Cap/join apply to generated dash figures too. Host admission rejects excessive flattening/dash work atomically; no partial path is displayed, and the previous scene remains intact. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).path &Pathcolor Colorstyle &StrokeOptionsint — a value of this type
const DIR_UPpub const DIR_UP = 0Constant DIR_UP, defining protocol or algorithm parameters.
const DIR_RIGHTpub const DIR_RIGHT = 1Constant DIR_RIGHT, defining protocol or algorithm parameters.
const DIR_DOWNpub const DIR_DOWN = 2Constant DIR_DOWN, defining protocol or algorithm parameters.
const DIR_LEFTpub const DIR_LEFT = 3Constant DIR_LEFT, defining protocol or algorithm parameters.
($&Path) smooth_splinepub fn (path $&Path) smooth_spline(points &[]PathPoint, tension f64, closed bool) intC1-continuous Cardinal / Catmull-Rom spline converted to cubic Beziers. tension=0 produces a standard Catmull-Rom spline; tension=1 produces lines. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).points &[]PathPointtension f64closed boolint — a value of this type
($&Frame) smooth_curvepub fn (frame $&Frame) smooth_curve(points &[]PathPoint, tension f64, color Color, width f64) intOperation on $&Frame: smooth curve. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointtension f64color Colorwidth f64int — a value of this type
($&Frame) fill_smooth_closedpub fn (frame $&Frame) fill_smooth_closed(points &[]PathPoint, tension f64, color Color) intOperation on $&Frame: fill smooth closed. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointtension f64color Colorint — a value of this type
($&Frame) stroke_smooth_closedpub fn (frame $&Frame) stroke_smooth_closed(points &[]PathPoint, tension f64, color Color, width f64) intOperation on $&Frame: stroke smooth closed. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointtension f64color Colorwidth f64int — a value of this type
($&Path) rounded_polylinepub fn (path $&Path) rounded_polyline(points &[]PathPoint, radius f64) intOperation on $&Path: rounded polyline. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).points &[]PathPointradius f64int — a value of this type
($&Path) rounded_polygonpub fn (path $&Path) rounded_polygon(points &[]PathPoint, radius f64) intOperation on $&Path: rounded polygon. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).points &[]PathPointradius f64int — a value of this type
($&Frame) rounded_polylinepub fn (frame $&Frame) rounded_polyline(points &[]PathPoint, radius f64, color Color, width f64) intOperation on $&Frame: rounded polyline. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointradius f64color Colorwidth f64int — a value of this type
($&Frame) fill_rounded_polygonpub fn (frame $&Frame) fill_rounded_polygon(points &[]PathPoint, radius f64, color Color) intOperation on $&Frame: fill rounded polygon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointradius f64color Colorint — a value of this type
($&Frame) stroke_rounded_polygonpub fn (frame $&Frame) stroke_rounded_polygon(points &[]PathPoint, radius f64, color Color, width f64) intOperation on $&Frame: stroke rounded polygon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointradius f64color Colorwidth f64int — a value of this type
($&Path) ringpub fn (path $&Path) ring(cx f64, cy f64, inner_radius f64, outer_radius f64) intFull 360-degree annular ring using opposite winding subpaths. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64inner_radius f64outer_radius f64int — a value of this type
($&Frame) fill_ringpub fn (frame $&Frame) fill_ring(cx f64, cy f64, inner_radius f64, outer_radius f64, color Color) intOperation on $&Frame: fill ring. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64inner_radius f64outer_radius f64color Colorint — a value of this type
($&Frame) stroke_ringpub fn (frame $&Frame) stroke_ring(cx f64, cy f64, inner_radius f64, outer_radius f64, color Color, width f64) intOperation on $&Frame: stroke ring. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64inner_radius f64outer_radius f64color Colorwidth f64int — a value of this type
($&Path) wavepub fn (path $&Path) wave(x f64, y f64, width f64, amplitude f64, wavelength f64, phase_deg f64) intExecute wave on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64width f64amplitude f64wavelength f64phase_deg f64int — a value of this type
($&Frame) wavepub fn (frame $&Frame) wave(x f64, y f64, width f64, amplitude f64, wavelength f64, phase_deg f64, color Color, line_width f64) intExecute wave on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64amplitude f64wavelength f64phase_deg f64color Colorline_width f64int — a value of this type
($&Path) crosspub fn (path $&Path) cross(cx f64, cy f64, size f64, thickness f64) intExecute cross on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64size f64thickness f64int — a value of this type
($&Frame) fill_crosspub fn (frame $&Frame) fill_cross(cx f64, cy f64, size f64, thickness f64, color Color) intOperation on $&Frame: fill cross. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64size f64thickness f64color Colorint — a value of this type
($&Frame) stroke_crosspub fn (frame $&Frame) stroke_cross(cx f64, cy f64, size f64, thickness f64, color Color, width f64) intOperation on $&Frame: stroke cross. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64size f64thickness f64color Colorwidth f64int — a value of this type
($&Path) checkmarkpub fn (path $&Path) checkmark(x f64, y f64, size f64) intExecute checkmark on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64size f64int — a value of this type
($&Frame) checkmarkpub fn (frame $&Frame) checkmark(x f64, y f64, size f64, color Color, width f64) intExecute checkmark on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64size f64color Colorwidth f64int — a value of this type
($&Path) chevronpub fn (path $&Path) chevron(x f64, y f64, width f64, height f64, direction int) intExecute chevron on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64width f64height f64direction intint — a value of this type
($&Frame) chevronpub fn (frame $&Frame) chevron(x f64, y f64, width f64, height f64, direction int, color Color, line_width f64) intExecute chevron on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64direction intcolor Colorline_width f64int — a value of this type
($&Frame) double_arrowpub fn (frame $&Frame) double_arrow(x1 f64, y1 f64, x2 f64, y2 f64, head_size f64, color Color, width f64) intOperation on $&Frame: double arrow. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64x2 f64y2 f64head_size f64color Colorwidth f64int — a value of this type
bezier_kappapub fn bezier_kappa() f64Bezier kappa.
No arguments are required.
f64 — a value of this type
deg_to_radpub fn deg_to_rad() f64Deg to rad.
No arguments are required.
f64 — a value of this type
struct PathPointpub struct PathPoint {
pub x f64
pub y f64
}Structure encapsulating x, y.
x f64y f64path_pointpub fn path_point(x f64, y f64) PathPointPath point.
x f64y f64PathPoint — a value of this type
($&Path) rectpub fn (path $&Path) rect(x f64, y f64, width f64, height f64) intOperation on $&Path: draw or fill a rectangle on the canvas. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64width f64height f64int — a value of this type
($&Path) round_rect_cornerspub fn (path $&Path) round_rect_corners(x f64, y f64, width f64, height f64, tl f64, tr f64, br f64, bl f64) intOperation on $&Path: round rectangle corners. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64width f64height f64tl f64tr f64br f64bl f64int — a value of this type
($&Path) round_rectpub fn (path $&Path) round_rect(x f64, y f64, width f64, height f64, radius f64) intOperation on $&Path: round rectangle. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64int — a value of this type
($&Path) capsulepub fn (path $&Path) capsule(x f64, y f64, width f64, height f64) intExecute capsule on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64width f64height f64int — a value of this type
($&Path) ellipsepub fn (path $&Path) ellipse(cx f64, cy f64, rx f64, ry f64) intExecute ellipse on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64int — a value of this type
($&Path) circlepub fn (path $&Path) circle(cx f64, cy f64, radius f64) intExecute circle on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64radius f64int — a value of this type
($&Path) diamondpub fn (path $&Path) diamond(cx f64, cy f64, rx f64, ry f64) intExecute diamond on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64int — a value of this type
($&Path) ellipse_arcpub fn (path $&Path) ellipse_arc(cx f64, cy f64, rx f64, ry f64, start_deg f64, sweep_deg f64) intOperation on $&Path: ellipse arc. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64start_deg f64sweep_deg f64int — a value of this type
($&Path) arcpub fn (path $&Path) arc(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64) intExecute arc on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64radius f64start_deg f64sweep_deg f64int — a value of this type
($&Path) sectorpub fn (path $&Path) sector(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64) intExecute sector on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64radius f64start_deg f64sweep_deg f64int — a value of this type
($&Path) ring_sectorpub fn (path $&Path) ring_sector(cx f64, cy f64, inner_radius f64, outer_radius f64, start_deg f64, sweep_deg f64) intOperation on $&Path: ring sector. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64inner_radius f64outer_radius f64start_deg f64sweep_deg f64int — a value of this type
($&Path) polylinepub fn (path $&Path) polyline(points &[]PathPoint) intExecute polyline on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).points &[]PathPointint — a value of this type
($&Path) polygonpub fn (path $&Path) polygon(points &[]PathPoint) intExecute polygon on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).points &[]PathPointint — a value of this type
($&Path) regular_polygonpub fn (path $&Path) regular_polygon(cx f64, cy f64, radius f64, sides int, rotation_deg f64) intOperation on $&Path: regular polygon. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64radius f64sides introtation_deg f64int — a value of this type
($&Path) starpub fn (path $&Path) star(cx f64, cy f64, outer_radius f64, inner_radius f64, points int, rotation_deg f64) intExecute star on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64outer_radius f64inner_radius f64points introtation_deg f64int — a value of this type
($&Path) calloutpub 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) intSpeech bubble / tooltip callout box with a pointer tail on DIR_UP, DIR_RIGHT, DIR_DOWN, or DIR_LEFT. tail_pos in [0, 1] positions the tail along the chosen edge. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64side inttail_pos f64tail_width f64tail_height f64int — a value of this type
($&Frame) fill_calloutpub 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) intOperation on $&Frame: fill callout. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64side inttail_pos f64tail_width f64tail_height f64color Colorint — a value of this type
($&Frame) stroke_calloutpub 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) intOperation on $&Frame: stroke callout. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64side inttail_pos f64tail_width f64tail_height f64color Colorline_width f64int — a value of this type
($&Path) ribbonpub fn (path $&Path) ribbon(x1 f64, y1_top f64, y1_bot f64, x2 f64, y2_top f64, y2_bot f64) intHorizontal cubic Bezier Sankey / flow ribbon connecting [x1, y1_top..y1_bot] to [x2, y2_top..y2_bot]. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).x1 f64y1_top f64y1_bot f64x2 f64y2_top f64y2_bot f64int — a value of this type
($&Frame) fill_ribbonpub fn (frame $&Frame) fill_ribbon(x1 f64, y1_top f64, y1_bot f64, x2 f64, y2_top f64, y2_bot f64, color Color) intOperation on $&Frame: fill ribbon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1_top f64y1_bot f64x2 f64y2_top f64y2_bot f64color Colorint — a value of this type
($&Frame) stroke_ribbonpub 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) intOperation on $&Frame: stroke ribbon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1_top f64y1_bot f64x2 f64y2_top f64y2_bot f64color Colorwidth f64int — a value of this type
($&Path) heartpub fn (path $&Path) heart(cx f64, cy f64, size f64) intExecute heart on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64size f64int — a value of this type
($&Frame) fill_heartpub fn (frame $&Frame) fill_heart(cx f64, cy f64, size f64, color Color) intOperation on $&Frame: fill heart. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64size f64color Colorint — a value of this type
($&Frame) stroke_heartpub fn (frame $&Frame) stroke_heart(cx f64, cy f64, size f64, color Color, width f64) intOperation on $&Frame: stroke heart. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64size f64color Colorwidth f64int — a value of this type
($&Path) shieldpub fn (path $&Path) shield(cx f64, cy f64, width f64, height f64) intExecute shield on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64width f64height f64int — a value of this type
($&Frame) fill_shieldpub fn (frame $&Frame) fill_shield(cx f64, cy f64, width f64, height f64, color Color) intOperation on $&Frame: fill shield. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64width f64height f64color Colorint — a value of this type
($&Frame) stroke_shieldpub fn (frame $&Frame) stroke_shield(cx f64, cy f64, width f64, height f64, color Color, line_width f64) intOperation on $&Frame: stroke shield. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64width f64height f64color Colorline_width f64int — a value of this type
($&Path) gearpub fn (path $&Path) gear(cx f64, cy f64, outer_radius f64, inner_radius f64, hole_radius f64, teeth int) intExecute gear on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64outer_radius f64inner_radius f64hole_radius f64teeth intint — a value of this type
($&Frame) fill_gearpub fn (frame $&Frame) fill_gear(cx f64, cy f64, outer_radius f64, inner_radius f64, hole_radius f64, teeth int, color Color) intOperation on $&Frame: fill gear. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64outer_radius f64inner_radius f64hole_radius f64teeth intcolor Colorint — a value of this type
($&Frame) stroke_gearpub fn (frame $&Frame) stroke_gear(cx f64, cy f64, outer_radius f64, inner_radius f64, hole_radius f64, teeth int, color Color, width f64) intOperation on $&Frame: stroke gear. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64outer_radius f64inner_radius f64hole_radius f64teeth intcolor Colorwidth f64int — a value of this type
($&Path) spiralpub fn (path $&Path) spiral(cx f64, cy f64, start_radius f64, end_radius f64, turns f64, rotation_deg f64) intExecute spiral on $&Path. Throws on failure; handle the error or propagate it to the caller.
path $&PathPath instance used by this call (exclusive borrow).cx f64cy f64start_radius f64end_radius f64turns f64rotation_deg f64int — a value of this type
($&Frame) spiralpub fn (frame $&Frame) spiral(cx f64, cy f64, start_radius f64, end_radius f64, turns f64, rotation_deg f64, color Color, width f64) intExecute spiral on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64start_radius f64end_radius f64turns f64rotation_deg f64color Colorwidth f64int — a value of this type
($&Frame) hatch_rectpub fn (frame $&Frame) hatch_rect(x f64, y f64, width f64, height f64, spacing f64, reverse bool, color Color, line_width f64) intClipped diagonal hatch lines inside [x, y, width, height]. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64spacing f64reverse boolcolor Colorline_width f64int — a value of this type
($&Frame) cross_hatch_rectpub fn (frame $&Frame) cross_hatch_rect(x f64, y f64, width f64, height f64, spacing f64, color Color, line_width f64) intOperation on $&Frame: cross hatch rectangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64spacing f64color Colorline_width f64int — a value of this type
($&Frame) dot_gridpub fn (frame $&Frame) dot_grid(x f64, y f64, width f64, height f64, spacing f64, dot_radius f64, color Color) intOperation on $&Frame: dot grid. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64spacing f64dot_radius f64color Colorint — a value of this type
($&Frame) fill_circlepub fn (frame $&Frame) fill_circle(cx f64, cy f64, radius f64, color Color) intOperation on $&Frame: fill circle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64color Colorint — a value of this type
($&Frame) stroke_circlepub fn (frame $&Frame) stroke_circle(cx f64, cy f64, radius f64, color Color, width f64) intOperation on $&Frame: stroke circle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64color Colorwidth f64int — a value of this type
($&Frame) fill_ellipsepub fn (frame $&Frame) fill_ellipse(cx f64, cy f64, rx f64, ry f64, color Color) intOperation on $&Frame: fill ellipse. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64color Colorint — a value of this type
($&Frame) stroke_ellipsepub fn (frame $&Frame) stroke_ellipse(cx f64, cy f64, rx f64, ry f64, color Color, width f64) intOperation on $&Frame: stroke ellipse. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64color Colorwidth f64int — a value of this type
($&Frame) fill_trianglepub fn (frame $&Frame) fill_triangle(x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64, color Color) intOperation on $&Frame: fill triangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64x2 f64y2 f64x3 f64y3 f64color Colorint — a value of this type
($&Frame) stroke_trianglepub fn (frame $&Frame) stroke_triangle(x1 f64, y1 f64, x2 f64, y2 f64, x3 f64, y3 f64, color Color, width f64) intOperation on $&Frame: stroke triangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64x2 f64y2 f64x3 f64y3 f64color Colorwidth f64int — a value of this type
($&Frame) fill_round_rect_cornerspub 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) intOperation on $&Frame: fill round rectangle corners. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64tl f64tr f64br f64bl f64color Colorint — a value of this type
($&Frame) stroke_round_rect_cornerspub 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) intOperation on $&Frame: stroke round rectangle corners. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64tl f64tr f64br f64bl f64color Colorline_width f64int — a value of this type
($&Frame) fill_round_rectpub fn (frame $&Frame) fill_round_rect(x f64, y f64, width f64, height f64, radius f64, color Color) intOperation on $&Frame: fill round rectangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64color Colorint — a value of this type
($&Frame) stroke_round_rectpub fn (frame $&Frame) stroke_round_rect(x f64, y f64, width f64, height f64, radius f64, color Color, line_width f64) intOperation on $&Frame: stroke round rectangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64color Colorline_width f64int — a value of this type
($&Frame) round_rectpub fn (frame $&Frame) round_rect(x f64, y f64, width f64, height f64, radius f64, color Color) intOperation on $&Frame: round rectangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64color Colorint — a value of this type
($&Frame) fill_capsulepub fn (frame $&Frame) fill_capsule(x f64, y f64, width f64, height f64, color Color) intOperation on $&Frame: fill capsule. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64color Colorint — a value of this type
($&Frame) stroke_capsulepub fn (frame $&Frame) stroke_capsule(x f64, y f64, width f64, height f64, color Color, line_width f64) intOperation on $&Frame: stroke capsule. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64color Colorline_width f64int — a value of this type
($&Frame) fill_diamondpub fn (frame $&Frame) fill_diamond(cx f64, cy f64, rx f64, ry f64, color Color) intOperation on $&Frame: fill diamond. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64color Colorint — a value of this type
($&Frame) stroke_diamondpub fn (frame $&Frame) stroke_diamond(cx f64, cy f64, rx f64, ry f64, color Color, width f64) intOperation on $&Frame: stroke diamond. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64color Colorwidth f64int — a value of this type
($&Frame) arc_styledpub fn (frame $&Frame) arc_styled(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color, options &StrokeOptions) intOperation on $&Frame: arc styled. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64start_deg f64sweep_deg f64color Coloroptions &StrokeOptionsint — a value of this type
($&Frame) arcpub fn (frame $&Frame) arc(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color, width f64) intExecute arc on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64start_deg f64sweep_deg f64color Colorwidth f64int — a value of this type
($&Frame) fill_sectorpub fn (frame $&Frame) fill_sector(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color) intOperation on $&Frame: fill sector. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64start_deg f64sweep_deg f64color Colorint — a value of this type
($&Frame) stroke_sectorpub fn (frame $&Frame) stroke_sector(cx f64, cy f64, radius f64, start_deg f64, sweep_deg f64, color Color, width f64) intOperation on $&Frame: stroke sector. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64start_deg f64sweep_deg f64color Colorwidth f64int — a value of this type
($&Frame) fill_ring_sectorpub fn (frame $&Frame) fill_ring_sector(cx f64, cy f64, inner_radius f64, outer_radius f64, start_deg f64, sweep_deg f64, color Color) intOperation on $&Frame: fill ring sector. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64inner_radius f64outer_radius f64start_deg f64sweep_deg f64color Colorint — a value of this type
($&Frame) stroke_ring_sectorpub 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) intOperation on $&Frame: stroke ring sector. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64inner_radius f64outer_radius f64start_deg f64sweep_deg f64color Colorwidth f64int — a value of this type
($&Frame) polyline_styledpub fn (frame $&Frame) polyline_styled(points &[]PathPoint, color Color, options &StrokeOptions) intOperation on $&Frame: polyline styled. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointcolor Coloroptions &StrokeOptionsint — a value of this type
($&Frame) polylinepub fn (frame $&Frame) polyline(points &[]PathPoint, color Color, width f64) intExecute polyline on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointcolor Colorwidth f64int — a value of this type
($&Frame) fill_polygonpub fn (frame $&Frame) fill_polygon(points &[]PathPoint, color Color) intOperation on $&Frame: fill polygon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointcolor Colorint — a value of this type
($&Frame) stroke_polygonpub fn (frame $&Frame) stroke_polygon(points &[]PathPoint, color Color, width f64) intOperation on $&Frame: stroke polygon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointcolor Colorwidth f64int — a value of this type
($&Frame) fill_regular_polygonpub fn (frame $&Frame) fill_regular_polygon(cx f64, cy f64, radius f64, sides int, rotation_deg f64, color Color) intOperation on $&Frame: fill regular polygon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64sides introtation_deg f64color Colorint — a value of this type
($&Frame) stroke_regular_polygonpub fn (frame $&Frame) stroke_regular_polygon(cx f64, cy f64, radius f64, sides int, rotation_deg f64, color Color, width f64) intOperation on $&Frame: stroke regular polygon. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64sides introtation_deg f64color Colorwidth f64int — a value of this type
($&Frame) fill_starpub fn (frame $&Frame) fill_star(cx f64, cy f64, outer_radius f64, inner_radius f64, points int, rotation_deg f64, color Color) intOperation on $&Frame: fill star. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64outer_radius f64inner_radius f64points introtation_deg f64color Colorint — a value of this type
($&Frame) stroke_starpub fn (frame $&Frame) stroke_star(cx f64, cy f64, outer_radius f64, inner_radius f64, points int, rotation_deg f64, color Color, width f64) intOperation on $&Frame: stroke star. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64outer_radius f64inner_radius f64points introtation_deg f64color Colorwidth f64int — a value of this type
($&Frame) quad_curvepub fn (frame $&Frame) quad_curve(x1 f64, y1 f64, cx f64, cy f64, x2 f64, y2 f64, color Color, width f64) intOperation on $&Frame: quad curve. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64cx f64cy f64x2 f64y2 f64color Colorwidth f64int — a value of this type
($&Frame) cubic_curvepub 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) intOperation on $&Frame: cubic curve. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64c1x f64c1y f64c2x f64c2y f64x2 f64y2 f64color Colorwidth f64int — a value of this type
($&Frame) dashed_linepub fn (frame $&Frame) dashed_line(x1 f64, y1 f64, x2 f64, y2 f64, dash_len f64, gap_len f64, color Color, width f64) intOperation on $&Frame: dashed line. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64x2 f64y2 f64dash_len f64gap_len f64color Colorwidth f64int — a value of this type
($&Frame) dashed_rectpub fn (frame $&Frame) dashed_rect(x f64, y f64, width f64, height f64, dash_len f64, gap_len f64, color Color, line_width f64) intOperation on $&Frame: dashed rectangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64dash_len f64gap_len f64color Colorline_width f64int — a value of this type
($&Frame) arrowpub fn (frame $&Frame) arrow(x1 f64, y1 f64, x2 f64, y2 f64, head_size f64, color Color, width f64) intExecute arrow on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x1 f64y1 f64x2 f64y2 f64head_size f64color Colorwidth f64int — a value of this type
($&Frame) gridpub fn (frame $&Frame) grid(x f64, y f64, width f64, height f64, cols int, rows int, color Color, line_width f64) intExecute grid on $&Frame. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64cols introws intcolor Colorline_width f64int — a value of this type
($&Frame) box_shadowpub 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) intOperation on $&Frame: box shadow. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64offset_x f64offset_y f64blur f64spread f64color Colorint — a value of this type
($&Frame) stroke_circle_styledpub fn (frame $&Frame) stroke_circle_styled(cx f64, cy f64, radius f64, color Color, options &StrokeOptions) intOperation on $&Frame: stroke circle styled. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64color Coloroptions &StrokeOptionsint — a value of this type
($&Frame) stroke_round_rect_styledpub fn (frame $&Frame) stroke_round_rect_styled(x f64, y f64, width f64, height f64, radius f64, color Color, options &StrokeOptions) intOperation on $&Frame: stroke round rectangle styled. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64color Coloroptions &StrokeOptionsint — a value of this type
($&Frame) dashed_round_rectpub 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) intOperation on $&Frame: dashed round rectangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64dash_len f64gap_len f64color Colorline_width f64int — a value of this type
($&Frame) dashed_circlepub fn (frame $&Frame) dashed_circle(cx f64, cy f64, radius f64, dash_len f64, gap_len f64, color Color, line_width f64) intOperation on $&Frame: dashed circle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64dash_len f64gap_len f64color Colorline_width f64int — a value of this type
($&Frame) fill_and_stroke_pathpub fn (frame $&Frame) fill_and_stroke_path(path &Path, fill_color Color, stroke_color Color, options &StrokeOptions, rule int) intOperation on $&Frame: fill and stroke path. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).path &Pathfill_color Colorstroke_color Coloroptions &StrokeOptionsrule intint — a value of this type
($&Frame) fill_and_stroke_round_rectpub 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) intOperation on $&Frame: fill and stroke round rectangle. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64fill_color Colorstroke_color Colorline_width f64int — a value of this type
($&Frame) fill_rect_gradient_scaledpub fn (frame $&Frame) fill_rect_gradient_scaled(x f64, y f64, width f64, height f64, gradient &Gradient, scale f64) intOperation on $&Frame: fill rectangle gradient scaled. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64gradient &Gradientscale f64int — a value of this type
($&Frame) fill_rect_gradientpub fn (frame $&Frame) fill_rect_gradient(x f64, y f64, width f64, height f64, gradient &Gradient) intOperation on $&Frame: fill rectangle gradient. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64gradient &Gradientint — a value of this type
($&Frame) fill_round_rect_corners_gradientpub 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) intOperation on $&Frame: fill round rectangle corners gradient. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64tl f64tr f64br f64bl f64gradient &Gradientscale f64int — a value of this type
($&Frame) fill_round_rect_gradient_scaledpub fn (frame $&Frame) fill_round_rect_gradient_scaled(x f64, y f64, width f64, height f64, radius f64, gradient &Gradient, scale f64) intOperation on $&Frame: fill round rectangle gradient scaled. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64gradient &Gradientscale f64int — a value of this type
($&Frame) fill_round_rect_gradientpub fn (frame $&Frame) fill_round_rect_gradient(x f64, y f64, width f64, height f64, radius f64, gradient &Gradient) intOperation on $&Frame: fill round rectangle gradient. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).x f64y f64width f64height f64radius f64gradient &Gradientint — a value of this type
($&Frame) fill_circle_gradient_scaledpub fn (frame $&Frame) fill_circle_gradient_scaled(cx f64, cy f64, radius f64, gradient &Gradient, scale f64) intOperation on $&Frame: fill circle gradient scaled. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64gradient &Gradientscale f64int — a value of this type
($&Frame) fill_circle_gradientpub fn (frame $&Frame) fill_circle_gradient(cx f64, cy f64, radius f64, gradient &Gradient) intOperation on $&Frame: fill circle gradient. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64radius f64gradient &Gradientint — a value of this type
($&Frame) fill_ellipse_gradientpub fn (frame $&Frame) fill_ellipse_gradient(cx f64, cy f64, rx f64, ry f64, gradient &Gradient, scale f64) intOperation on $&Frame: fill ellipse gradient. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).cx f64cy f64rx f64ry f64gradient &Gradientscale f64int — a value of this type
($&Frame) fill_polygon_gradientpub fn (frame $&Frame) fill_polygon_gradient(points &[]PathPoint, gradient &Gradient, scale f64) intOperation on $&Frame: fill polygon gradient. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).points &[]PathPointgradient &Gradientscale f64int — a value of this type
struct Surfacepub struct Surface {
pub width f64
pub height f64
pub pixel_width int
pub pixel_height int
}An immutable transparent raster layer, scoped to the source frame's canvas. Explicit resolution makes cache quality and memory use predictable. Reuse this handle in any number of frames; update by creating a replacement first. Accepted frames retain old pixels across dispose. Copies share one handle.
width f64height f64pixel_width intpixel_height int($&Frame) snapshotpub fn (frame $&Frame) snapshot(width f64, height f64, scale f64) SurfaceRender once, without presenting to the window or using its camera/DPI. Source coordinates cover [0,width] x [0,height]; scale determines backing pixels (ceil per dimension). The default clear is transparent; set_bg makes an opaque clear. The frame remains sealed for present or another snapshot. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).width f64height f64scale f64Surface — a value of this type
($&Surface) disposepub fn (surface $&Surface) dispose() intRelease and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.
surface $&SurfaceSurface instance used by this call (exclusive borrow).int — a value of this type
($&Surface) closepub fn (surface $&Surface) close() intOperation on $&Surface: close the resource. Throws on failure; handle the error or propagate it to the caller.
surface $&SurfaceSurface instance used by this call (exclusive borrow).int — a value of this type
(&Surface) rgba_bytespub fn (surface &Surface) rgba_bytes() stringIndependent, straight sRGB RGBA8 copy, in top-left row order. The native immutable bitmap stays owned by this Surface; editing the copy is safe. Throws on failure; handle the error or propagate it to the caller.
surface &SurfaceSurface instance used by this call (borrow).string — result string
($&Frame) surfacepub fn (frame $&Frame) surface(surface &Surface, x f64, y f64, width f64, height f64, opacity f64, sampler int) intGroup opacity is applied once to the cached layer. Destination geometry and clipping follow this frame's CTM; source frame transforms are already baked. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).surface &Surfacex f64y f64width f64height f64opacity f64sampler intint — a value of this type
const TEXT_LEFTpub const TEXT_LEFT = 0Constant TEXT_LEFT, defining protocol or algorithm parameters.
const TEXT_CENTERpub const TEXT_CENTER = 1Constant TEXT_CENTER, defining protocol or algorithm parameters.
const TEXT_RIGHTpub const TEXT_RIGHT = 2Constant TEXT_RIGHT, defining protocol or algorithm parameters.
struct TextOptionspub 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 Configuration parameters and options set.
family stringsize f64width f64weight intitalic boolalign intline_height f64struct TextMetricspub 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
}Structure encapsulating width, height, baseline, lines, ink_x.
width f64height f64baseline f64lines intink_x f64ink_y f64ink_width f64ink_height f64text_optionspub fn text_options(size f64) TextOptionsText options.
size f64TextOptions — a value of this type
struct TextLayoutpub struct TextLayout {
pub metrics TextMetrics
}Metrics and drawing share one native layout, including shaping, fallback, wrapping and trailing empty lines. Font sizes/positions use logical pixels. A Frame retains its layout even after this user handle is disposed.
metrics TextMetricsstruct TextHitpub struct TextHit {
pub index int
pub length int
pub trailing bool
pub inside bool
pub x f64
pub y f64
pub height f64
}A shaped cluster and its logical edge. Keep index/trailing together at soft wraps and bidi boundaries. index/length count UTF-8 bytes, never UTF-16 units.
index intlength inttrailing boolinside boolx f64y f64height f64(&TextHit) byte_indexpub fn (hit &TextHit) byte_index() intOperation on &TextHit: byte index.
hit &TextHitTextHit instance used by this call (borrow).int — index; see the description for its range and special values
(&TextLayout) bind_inputpub fn (layout &TextLayout) bind_input(input &ui.TextInput, revision int, x f64, y f64) intBind the same immutable layout that is drawn at x/y. Its text must equal the input snapshot's display_value, including preedit, at this revision. The session retains the layout after dispose; edits invalidate the binding. Throws on failure; handle the error or propagate it to the caller.
layout &TextLayoutTextLayout instance used by this call (borrow).input &ui.TextInputrevision intx f64y f64int — a value of this type
(&TextLayout) bind_input_transformpub fn (layout &TextLayout) bind_input_transform(input &ui.TextInput, revision int, transform &ui.TextInputTransform, upstream bool) intOperation on &TextLayout: bind input transform. Throws on failure; handle the error or propagate it to the caller.
layout &TextLayoutTextLayout instance used by this call (borrow).input &ui.TextInputrevision inttransform &ui.TextInputTransformupstream boolint — a value of this type
(&TextLayout) hit_testpub fn (layout &TextLayout) hit_test(x f64, y f64) TextHitCoordinates are relative to this layout's top-left before the frame CTM. Outside points return the nearest edge and inside=false. Throws on failure; handle the error or propagate it to the caller.
layout &TextLayoutTextLayout instance used by this call (borrow).x f64y f64TextHit — a value of this type
(&TextLayout) caretpub fn (layout &TextLayout) caret(index int, trailing bool) TextHitScalar boundaries inside a shaped cluster normalize to that cluster. Byte offsets inside a UTF-8 encoding are rejected; trailing selects its far edge. Throws on failure; handle the error or propagate it to the caller.
layout &TextLayoutTextLayout instance used by this call (borrow).index inttrailing boolTextHit — a value of this type
(&Context) empty_text_layoutpub fn (c &Context) empty_text_layout(metrics TextMetrics) TextLayoutOperation on &Context: empty text layout.
c &ContextContext instance used by this call (borrow).metrics TextMetricsTextLayout — a value of this type
(&TextLayout) is_host_shapedpub fn (layout &TextLayout) is_host_shaped() boolOperation on &TextLayout: whether it is host shaped.
layout &TextLayoutTextLayout instance used by this call (borrow).bool — true or false
(&Context) layout_textpub fn (context &Context) layout_text(value &string, options &TextOptions) TextLayoutEmpty family uses the platform UI font. size=0 selects 14px; weight=0 selects 400. width=0 disables wrapping; center/right require an explicit width. Maximum text is 16 KiB UTF-8 and family 256 bytes. Live layout identities grow dynamically within the host's byte budget. Native coordinate/shaping limits also bound size*(byte_length+1) to 262144. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).value &stringoptions &TextOptionsTextLayout — a value of this type
(&Context) layout_masked_textpub fn (context &Context) layout_masked_text(value &string,options &TextOptions) TextLayoutPaint one bullet per Unicode grapheme. Queries retain the original UTF-8 byte positions, so selection, caret and native input bindings remain valid. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).value &stringoptions &TextOptionsTextLayout — a value of this type
($&TextLayout) disposepub fn (layout $&TextLayout) dispose() intRelease and dispose native resources and underlying handles. Throws on failure; handle the error or propagate it to the caller.
layout $&TextLayoutTextLayout instance used by this call (exclusive borrow).int — a value of this type
($&TextLayout) closepub fn (layout $&TextLayout) close() intOperation on $&TextLayout: close the resource. Throws on failure; handle the error or propagate it to the caller.
layout $&TextLayoutTextLayout instance used by this call (exclusive borrow).int — a value of this type
($&Frame) text_layoutpub fn (frame $&Frame) text_layout(layout &TextLayout, x f64, y f64, color Color) intOperation on $&Frame: text layout. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).layout &TextLayoutx f64y f64color Colorint — a value of this type
struct TextSelectionRectpub struct TextSelectionRect {
pub x f64
pub y f64
pub width f64
pub height f64
}Canvas-independent layout rectangles for a UTF-8 selection. The host batches shaped cluster queries and coalesces touching rectangles on each visual line.
x f64y f64width f64height f64(&TextLayout) selection_rectspub fn (layout &TextLayout) selection_rects(start int,end int) []TextSelectionRectOperation on &TextLayout: selection rects. Throws on failure; handle the error or propagate it to the caller.
layout &TextLayoutTextLayout instance used by this call (borrow).start intend int[]TextSelectionRect — slice result
const FIT_FILLpub const FIT_FILL = 0Constant FIT_FILL, defining protocol or algorithm parameters.
const FIT_CONTAINpub const FIT_CONTAIN = 1Constant FIT_CONTAIN, defining protocol or algorithm parameters.
const FIT_COVERpub const FIT_COVER = 2Constant FIT_COVER, defining protocol or algorithm parameters.
const FIT_CENTERpub const FIT_CENTER = 3Constant FIT_CENTER, defining protocol or algorithm parameters.
text_options_styledpub fn text_options_styled(family string, size f64, weight int, italic bool) TextOptionsText options styled.
family stringsize f64weight intitalic boolTextOptions — a value of this type
text_options_wrappedpub fn text_options_wrapped(size f64, width f64, align int) TextOptionsText options wrapped.
size f64width f64align intTextOptions — a value of this type
(&Context) measure_textpub fn (context &Context) measure_text(value &string, size f64) TextMetricsMeasures text metrics using the ':xu:' native host or pure-Xu #ui/font when hostless. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).value &stringsize f64TextMetrics — a value of this type
($&Frame) text_alignedpub fn (frame $&Frame) text_aligned(layout &TextLayout, x f64, y f64, width f64, height f64, align_x f64, align_y f64, color Color) intDraws a shaped TextLayout aligned within [x, x+width] x [y, y+height] using align_x, align_y in [0, 1]. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).layout &TextLayoutx f64y f64width f64height f64align_x f64align_y f64color Colorint — a value of this type
($&Frame) text_pillpub fn (frame $&Frame) text_pill(layout &TextLayout, x f64, y f64, pad_x f64, pad_y f64, bg Color, border Color, fg Color) intDraws a rounded pill badge around a TextLayout with background, optional border, and foreground color. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).layout &TextLayoutx f64y f64pad_x f64pad_y f64bg Colorborder Colorfg Colorint — a value of this type
($&Frame) image_fitpub fn (frame $&Frame) image_fit(image &Image, x f64, y f64, width f64, height f64, fit_mode int, opacity f64) intDraws an Image into [x, y, width, height] using FIT_FILL, FIT_CONTAIN, FIT_COVER, or FIT_CENTER. Throws on failure; handle the error or propagate it to the caller.
frame $&FrameFrame instance used by this call (exclusive borrow).image &Imagex f64y f64width f64height f64fit_mode intopacity f64int — a value of this type
(&Context) start_text_inputpub fn (context &Context) start_text_input(options &ui.TextInputOptions) ui.TextInputOperation on &Context: start text input. Throws on failure; handle the error or propagate it to the caller.
context &ContextContext instance used by this call (borrow).options &ui.TextInputOptionsui.TextInput — a value of this type