API
#ui/draw
Xu 0.8.8 API
import: #ui/draw
counts: 46 fns, 0 methods, 3 types, 4 consts, 0 ifaces
Immediate-mode 2D canvas.
struct Point
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
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
Purpose
Public constant `in_none`. Value `0`.
Parameters
none
const in_click
Purpose
Public constant `in_click`. Value `1`.
Parameters
none
const in_scroll
Purpose
Public constant `in_scroll`. Value `2`.
Parameters
none
const in_drag
Purpose
Public constant `in_drag`. Value `3`.
Parameters
none
struct Input
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
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
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
Purpose
begin; returns int.
Parameters
none
Returns
int — a value of this type
present
Purpose
present; returns int.
Parameters
none
Returns
int — a value of this type
clear
Purpose
clear; returns int.
Parameters
none
Returns
int — a value of this type
set_bg
pub fn set_bg(hex string) int
Purpose
Set bg.
Parameters
hex string- hex (string)
Returns
int — a value of this type
set_color
pub fn set_color(hex string) int
Purpose
Set color.
Parameters
hex string- hex (string)
Returns
int — a value of this type
set_fill
pub fn set_fill(hex string) int
Purpose
Set fill.
Parameters
hex string- hex (string)
Returns
int — a value of this type
set_stroke
pub fn set_stroke(hex string) int
Purpose
Set stroke.
Parameters
hex string- hex (string)
Returns
int — a value of this type
set_width
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
Purpose
push; returns int.
Parameters
none
Returns
int — a value of this type
pop
Purpose
pop; returns int.
Parameters
none
Returns
int — a value of this type
origin
Purpose
origin; returns int.
Parameters
none
Returns
int — a value of this type
translate
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
pub fn rotate(deg int) int
Purpose
rotate; returns int.
Parameters
deg int- deg (int)
Returns
int — a value of this type
scale
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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