XU XUv0.8.8
中文

API

#ui/draw

import: #ui/draw

counts: 46 fns, 0 methods, 3 types, 4 consts, 0 ifaces

Immediate-mode 2D canvas.

struct Point

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

Purpose

Immediate-mode canvas (Love2D / Raylib / Cairo-style) on `#ui` content_draw. No WebView. Origin is top-left, pixels. begin clears the display list and resets the pen; present paints. Clicks/prompt/scroll/drag: poll(app.event_ch) / poll_click / prompt `#ui` owns the host event pump; this package does not read the shell event file. Color: "#RRGGBB" or "#RRGGBBAA". "-" skips a fill or stroke. Pen (host-side, like love.graphics.setColor): set_color / set_fill set_stroke / set_width, then rect/circle/ellipse/triangle. Transform stack (CTM): push / pop / origin / translate / rotate / scale. scale(sx,sy) is percent (100 = 1x). rotate is degrees, clockwise.

Parameters

x int
value
y int
value

struct Click

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

Purpose

Public struct `Click`.

Parameters

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

const in_none

XuAPI
pub const in_none = 0

Purpose

Public constant `in_none`. Value `0`.

Parameters

none

const in_click

XuAPI
pub const in_click = 1

Purpose

Public constant `in_click`. Value `1`.

Parameters

none

const in_scroll

XuAPI
pub const in_scroll = 2

Purpose

Public constant `in_scroll`. Value `2`.

Parameters

none

const in_drag

XuAPI
pub const in_drag = 3

Purpose

Public constant `in_drag`. Value `3`.

Parameters

none

struct Input

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

Purpose

Public struct `Input`.

Parameters

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

attach

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

Purpose

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

Parameters

w &mut ui.Window
writer or width (exclusive borrow; type &mut ui.Window)

Returns

int — a value of this type

set_pan_enabled

XuAPI
pub fn set_pan_enabled(on int) int

Purpose

Windows fixed forms can disable the canvas's built-in drag/wheel camera movement.

Parameters

on int
on (int)

Returns

int — a value of this type

begin

XuAPI
pub fn begin() int

Purpose

begin; returns int.

Parameters

none

Returns

int — a value of this type

present

XuAPI
pub fn present() int

Purpose

present; returns int.

Parameters

none

Returns

int — a value of this type

clear

XuAPI
pub fn clear() int

Purpose

clear; returns int.

Parameters

none

Returns

int — a value of this type

set_bg

XuAPI
pub fn set_bg(hex string) int

Purpose

Set bg.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_color

XuAPI
pub fn set_color(hex string) int

Purpose

Set color.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_fill

XuAPI
pub fn set_fill(hex string) int

Purpose

Set fill.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_stroke

XuAPI
pub fn set_stroke(hex string) int

Purpose

Set stroke.

Parameters

hex string
hex (string)

Returns

int — a value of this type

set_width

XuAPI
pub fn set_width(w int) int

Purpose

Set width.

Parameters

w int
writer or width (int)

Returns

int — a value of this type

push

XuAPI
pub fn push() int

Purpose

push; returns int.

Parameters

none

Returns

int — a value of this type

pop

XuAPI
pub fn pop() int

Purpose

pop; returns int.

Parameters

none

Returns

int — a value of this type

origin

XuAPI
pub fn origin() int

Purpose

origin; returns int.

Parameters

none

Returns

int — a value of this type

translate

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

Purpose

translate; returns int.

Parameters

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

Returns

int — a value of this type

rotate

XuAPI
pub fn rotate(deg int) int

Purpose

rotate; returns int.

Parameters

deg int
deg (int)

Returns

int — a value of this type

scale

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

Purpose

scale; returns int.

Parameters

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

Returns

int — a value of this type

fill_rect

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

Purpose

Fill rectangle.

Parameters

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

Returns

int — a value of this type

stroke_rect

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

Purpose

Stroke rectangle.

Parameters

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

Returns

int — a value of this type

round_rect

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

Purpose

Round rectangle.

Parameters

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

Returns

int — a value of this type

diamond

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

Purpose

diamond; returns int.

Parameters

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

Returns

int — a value of this type

line

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

Purpose

line; returns int.

Parameters

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

Returns

int — a value of this type

text

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

Purpose

Return the current text.

Parameters

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

Returns

int — a value of this type

arrow

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

Purpose

arrow; returns int.

Parameters

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

Returns

int — a value of this type

rect

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

Purpose

Rectangle.

Parameters

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

Returns

int — a value of this type

rect_line

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

Purpose

Rectangle line.

Parameters

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

Returns

int — a value of this type

circle

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

Purpose

circle; returns int.

Parameters

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

Returns

int — a value of this type

circle_line

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

Purpose

Circle line.

Parameters

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

Returns

int — a value of this type

fill_circle

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

Purpose

Fill circle.

Parameters

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

Returns

int — a value of this type

stroke_circle

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

Purpose

Stroke circle.

Parameters

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

Returns

int — a value of this type

ellipse

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

Purpose

ellipse; returns int.

Parameters

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

Returns

int — a value of this type

ellipse_line

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

Purpose

Ellipse line.

Parameters

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

Returns

int — a value of this type

fill_ellipse

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

Purpose

Fill ellipse.

Parameters

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

Returns

int — a value of this type

stroke_ellipse

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

Purpose

Stroke ellipse.

Parameters

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

Returns

int — a value of this type

triangle

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

Purpose

triangle; returns int.

Parameters

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

Returns

int — a value of this type

triangle_line

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

Purpose

Triangle line.

Parameters

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

Returns

int — a value of this type

fill_triangle

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

Purpose

Fill triangle.

Parameters

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

Returns

int — a value of this type

stroke_triangle

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

Purpose

Stroke triangle.

Parameters

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

Returns

int — a value of this type

poly

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

Purpose

poly; returns int.

Parameters

pts &[]Point
pts (borrowed; caller keeps it; type &[]Point)
fill string
fill (string)
stroke string
stroke (string)
width int
width (int)

Returns

int — a value of this type

arc

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

Purpose

arc; returns int.

Parameters

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

Returns

int — a value of this type

point

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

Purpose

point; returns int.

Parameters

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

Returns

int — a value of this type

click_of

XuAPI
pub fn click_of(ev ui.Event) Click

Purpose

Click of.

Parameters

ev ui.Event
ev (ui.Event)

Returns

Click — a value of this type

poll_click

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

Purpose

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

Parameters

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

Returns

Click — a value of this type

poll

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

Purpose

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

Parameters

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

Returns

Input — a value of this type

prompt

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

Purpose

Modal text field (macOS). Result arrives as ui.ev_prompt on the same event_ch.

Parameters

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

Returns

string — result string

in_rect

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

Purpose

In rectangle.

Parameters

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

Returns

bool — true or false

in_circle

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

Purpose

In circle.

Parameters

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

Returns

bool — true or false