Add the dependency
In your project’s ziran.toml; pin ref to a commit for reproducible builds.
[dependencies.tk]
git = "https://git.waozi.xyz/ziranlang/tk.git"
ref = "master"Overview
Use Tk
Add the package with ziran add https://git.waozi.xyz/ziranlang/tk.git. If the
application also imports tcl/interpreter, add Tcl at the revision selected by
Tk so both packages share one interpreter type; read that revision from
ziran.lock so this works with source checkouts and relocatable libraries:
tcl_revision=$(python3 - <<'PY'
import json
from pathlib import Path
lock = json.loads(Path("ziran.lock").read_text())
packages = {package["id"]: package for package in lock["packages"]}
tk = packages[lock["root"]["dependencies"]["tk"]]
print(packages[tk["dependencies"]["tcl"]]["commit"])
PY
)
ziran add https://git.waozi.xyz/ziranlang/tcl.git --ref "$tcl_revision"
using Tcl :: #import "tcl/interpreter";
using Tk :: #import "tk/widgets";
using Paint :: #import "tk/paint";
Initialize :: (interpreter: *Tcl.Interpreter) -> bool {
if !Tk.Attach(interpreter) { return false }
result := Tcl.Eval(interpreter, "label .ready -text Ready; pack .ready");
return result.code == .OK;
}
Draw :: (pixels: []u8, width: s32, height: s32) {
Tk.Layout(width, height);
Paint.Render(pixels, width, height);
}
Attach once per application and keep the interpreter alive for the root's
lifetime. Call Layout when the window size or widget geometry changes.
Paint.Render takes a row-major RGBA buffer with four bytes per pixel; its
optional first argument paints rows first through height - 1, with the
buffer beginning at that row. Feed pointer and keyboard events to tk/widgets
and evaluate any returned Tcl script with the same interpreter.
Widgets and feature defines
The default widget set includes Canvas, labels, buttons, frames, entries, text, scales, panels, checkbuttons, radiobuttons, and scrollbars. Compiler defines select additional features or a smaller build:
| Define | Effect |
|---|---|
TK_BITMAP |
Enable image commands, bitmap labels and, with Canvas, Canvas images and bitmap fonts. |
TK_LISTBOX |
Enable listboxes. |
TK_MENU |
Enable menus and menubuttons. |
TK_NO_CANVAS |
Omit the Canvas widget and painting. |
With TK_BITMAP, Tk.SetImageLoader registers a callback that returns bytes
for images and fonts, from in-memory data or the host's own resource lookup.
@name bitmap references request name directly; plain bitmap names use the
Inferno-compatible /icons/tk/ lookup prefix. Fallback stroke lettering
covers ordinary text.
tk/widgets and tk/paint are the main entry points. The package also
exports tk/bitmap, tk/canvas, tk/check, tk/font, tk/image,
tk/listbox, tk/menu, tk/scale, tk/scrollbar, tk/text, and tk/view
for direct access to their models and helpers. This is a subset of Inferno
Tk: multiple root windows, grabs, grid layout, and embedded text widgets are
outside the current implementation.
Local tests
make test needs a Ziran toolchain and a C compiler. It checks the default
and feature-enabled exports, including the bitmap profile with Canvas off,
and runs the same widget test as native C and as a .zx bundle in the
instruction engine, comparing command results and the rendered pixel
checksum. The test uses a bitmap supplied from memory and runs without a
window server.
To develop against the sibling Tcl and Ziran source trees, create the ignored
ziran.local.toml with these canonical overrides:
[overrides]
ziran = "../../ziran"
tcl = "../tcl"
Relocatable ZX libraries
With the exact compiler and Tcl default ZX library from ziran.lock
cached, run make test artifact from a clean Tk checkout. Use
ziran pkg zx fetch-ir with the Tcl repository, revision, profile, and
digest from ziran.lock to populate the cache. This writes seven relocatable
.zx libraries and build/artifacts/manifest.json, which records the
provider and toolchain identities, the locked Tcl dependency, the exports,
the defines, and each archive's SHA-256 digest.
| Profile | Defines |
|---|---|
default |
None |
no-canvas |
TK_NO_CANVAS |
bitmap |
TK_BITMAP |
bitmap-no-canvas |
TK_BITMAP, TK_NO_CANVAS |
bitmap-menu |
TK_BITMAP, TK_MENU |
full |
TK_BITMAP, TK_LISTBOX, TK_MENU |
listbox-no-canvas |
TK_LISTBOX, TK_NO_CANVAS |
A relocatable .zx library supplies typed code and metadata for ordinary
imports such as tk/widgets and tk/paint; the consumer compiler links and
lowers it for the selected target. The consumer's ziran.lock pins Tk, Tcl,
and the exact Ziran toolchain. Once both default libraries are published,
ziran add or ziran lock discovers them and records their profile, digest,
and toolchain under each package's checked field. For explicit selection,
add entries for the Tcl default and the selected Tk profiles in
ziran.zx.lock under packages, with the package ID, profile, and
sha256 for each. Keep the Tk profile consistent with the app's feature
defines.
make artifact-smoke verifies all seven Tk libraries: it builds and runs the
widget fixture offline as a native executable and as portable ZX, using the
full Tk library and the locked default Tcl library; compares widget output
and pixel checksum; confirms the provider source cache stays empty; and tests
ziran add, ziran lock --offline, and an offline bundle with the two
default libraries. Pass TCL_ZX_LIBRARY=<path> to supply a local copy of the
locked Tcl library.
For working-tree changes, make artifact DEVELOPMENT=1 writes development
libraries to build/artifacts-dev/. Test them with
make artifact-smoke DEVELOPMENT=1 TCL_ZX_LIBRARY=<path> TCL_ZX_SHA256=<digest>
using a Tcl development library built with the same compiler.
After local tests pass, the Gitea master job publishes <profile>.zx and
<profile>.zx.tsv under tk-zx-library at the full Tk revision, then runs
make artifact-smoke REGISTRY=1 against Gitea with empty consumer caches.
Local publication uses make artifact-publish NETRC_FILE=<path> with a
private Gitea netrc.
tk/src/bitmap.zi
bitmap
Inferno bitmap pixels follow libmemdraw/cread.c, cload.c, and libdraw/rgb.c. See LICENSE (MIT).
Import with #import "tk/bitmap".
MAX_PIXELS :: 262144Encoding :: enum { Palette = 0; Mask = 1; }Bitmap :: struct { pixels: Vec(u8); left: s32; top: s32; width: s32; height: s32; pitch: s32; start_bit: s32; encoding: Encoding; }Bit :: (bitmap: *Bitmap, x: s64, y: s64) -> boolDecodeBlock :: (input: string, pixels: []u8, row_bytes: s64) -> boolCoordinate :: (field: string) -> (s64, bool)Each coordinate is a signed 32-bit Inferno rectangle endpoint. Keep span arithmetic in s64 until the allocation and renderer bounds are known.
DecodePrefix :: (bytes: string, bitmap: *Bitmap, font: bool) -> s64Subfonts append glyph metrics after the image and use legacy depth zero.
Decode :: (bytes: string, bitmap: *Bitmap) -> boolColor :: (index: s32) -> u32RGBA byte order on the hosted Linux/386 surface.
tk/src/canvas.zi
canvas
Canvas item geometry and commands, following Inferno libtk/canvs.c.
Import with #import "tk/canvas".
NONE :: -1BLACK :: 0x000000WHITE :: 0xffffffRED :: 0xff0000CELL_WIDTH :: 12TEXT_HEIGHT :: 14MAX_CELLS :: 512FRACTION :: 10000PIXELS_PER_INCH :: 100MAX_COORDINATE :: 1000000Anchor :: enum { Center = 0; North = 1; Northeast = 2; East = 3; Southeast = 4; South = 5; Southwest = 6; West = 7; Northwest = 8; }Kind :: enum { Rectangle = 0; Label = 1; Line = 2; Oval = 3; Image = 4; }Coordinates :: struct { x0: s32; y0: s32; x1: s32; y1: s32; }PathPoint :: struct { x: s64; y: s64; }FixedCoordinates :: struct { x0: s64; y0: s64; x1: s64; y1: s64; }Binding :: struct { event: s32; script: Text; }CanvasTag :: struct { name: Text; members: Vec(s64); bindings: Vec(Binding); }Item :: struct { id: s64; tags: Vec(s64); bindings: Vec(Binding); kind: Kind; coordinates: Coordinates; anchor: Anchor; fill: s32; outline: s32; text: Text; precise: FixedCoordinates; path: Vec(PathPoint); stroke: s64; marker_radius: s64; }Viewport :: struct { region: FixedCoordinates; width: s32; height: s32; x: s32; y: s32; increment: s64; resized: bool; }State :: struct { viewport: Viewport; yscroll: Text; width: s32; height: s32; precise_width: s64; precise_height: s64; background: s32; border: s32; sunken: bool; items: Vec(Item); last_id: s64; tags: Vec(CanvasTag); all_bindings: Vec(Binding); current: s64; }Default :: () -> StateMinimum :: (a: s32, b: s32) -> s32Maximum :: (a: s32, b: s32) -> s32Rectangle :: (coordinates: Coordinates) -> CoordinatesAnchoredBounds :: (coordinates: Coordinates, anchor: Anchor, width: s32, height: s32) -> CoordinatesBounds :: (item: *Item, state: *State) -> CoordinatesTextBounds :: (item: *Item) -> CoordinatesAdd :: (state: *State, kind: Kind, coordinates: Coordinates, fill: s32, outline: s32, anchor: Anchor) -> s64AddRectangle :: (state: *State, coordinates: Coordinates, fill: s32, outline: s32) -> s64AddPolyline :: (state: *State, count: s64, bounds: Coordinates, fill: s32, stroke: s64, marker_radius: s64) -> *ItemIncludePoint :: (bounds: Coordinates, x: s64, y: s64, first: bool) -> CoordinatesFind :: (state: *State, id: s64) -> *ItemSetCoordinates :: (state: *State, id: s64, coordinates: Coordinates) -> boolSetText :: (state: *State, id: s64, text: string) -> boolAddText :: (state: *State, x: s32, y: s32, anchor: Anchor, text: string, fill: s32) -> s64Clear :: (state: *State)DeleteAll :: (state: *State)FindTag :: (state: *State, name: string) -> s64EnsureTag :: (state: *State, name: string) -> s64HasTag :: (item: *Item, tag: s64) -> boolAttachTag :: (state: *State, item: *Item, tag: s64) -> boolRemoveNumber :: (values: *Vec(s64), value: s64)DiscardNewItem :: (state: *State)MoveItem :: (destination: *Item, source: *Item)Stable compaction preserves draw order and keeps IDs in search order.
TopItem :: (state: *State, name: string) -> *ItemDelete :: (state: *State, name: string) -> boolError :: (result: *T.Result, message: string)Configure :: (state: *State, args: []Text, result: *T.Result) -> boolPixel :: (number: s64) -> s32SetInteger :: (item: *Item, coordinates: Coordinates)ReadCoordinate :: (word: string) -> (s64, bool)ReadDistance :: (text: string) -> (s64, bool)Inferno uses a fixed 100 dpi and truncates the per-unit ratios for cm and mm.
ReadRegion :: (word: string) -> (FixedCoordinates, bool)ClampOrigin :: (origin: s64, first: s32, last: s32) -> s32ClampViewport :: (view: *Viewport)Resize :: (state: *State, width: s32, height: s32)YSpan :: (view: *Viewport) -> s32YFractions :: (view: *Viewport, callback: bool) -> Scroll.StateYView :: (view: *Viewport, args: []Text, result: *T.Result)CanvasY :: (state: *State, args: []Text, result: *T.Result, top: s32)SetFixed :: (item: *Item, args: []Text, count: s64) -> boolSetLine :: (item: *Item, args: []Text, allow_options: bool) -> (s64, bool)ParseAnchor :: (word: string) -> (Anchor, bool)ParseColor :: (word: string) -> (s32, bool)TagName :: (name: string) -> boolUpdateItem :: (state: *State, id: s64, args: []Text, creating: bool) -> stringCreate :: (state: *State, args: []Text, result: *T.Result)Append :: (result: *T.Result, number: s64)AppendCoordinates :: (result: *T.Result, coordinates: Coordinates, count: s64)AppendFixed :: (result: *T.Result, value: s64)BAD_TAG :: "bad/no matching tag"WithTag :: (state: *State, name: string, ids: *Vec(s64)) -> boolFindOrAddTags :: (state: *State, args: []Text, adding: bool, result: *T.Result)RemoveTag :: (state: *State, args: []Text, result: *T.Result)GetTags :: (state: *State, name: string, result: *T.Result)PRESS_MASK :: 7RELEASE_MASK :: 56MOTION :: 64ENTER :: 128LEAVE :: 256DOUBLE :: 512ButtonBit :: (button: s32) -> s32ParseEvent :: (sequence: string) -> s32Bind :: (state: *State, args: []Text, result: *T.Result)PointerEvent :: struct { mask: s32; x: s32; y: s32; screen_x: s32; screen_y: s32; }AppendAction :: (result: *Text, script: string, event: PointerEvent, widget: string)AppendActions :: (result: *Text, actions: *Vec(Binding), event: PointerEvent, widget: string)PointerActions :: (state: *State, event: PointerEvent, widget: string) -> TextAbs :: (value: s64) -> s64Hit :: (state: *State, item: *Item, x: s32, y: s32) -> boolTopHit :: (state: *State, x: s32, y: s32) -> s64AppendRequestedSize :: (result: *T.Result, pixels: s32, precise: s64)Command :: (state: *State, args: []Text, result: *T.Result, top: s32)tk/src/check.zi
check
Selection values live in the Tk root, following Inferno libtk/varbl.c.
Import with #import "tk/check".
DEFAULT_VARIABLE :: "selectedButton"MAX_VARIABLES :: 1024variables: V.VariableTableversions: [1024]u64revision: u64State :: struct { variable: Text; on: Text; off: Text; selected: bool; radio: bool; indicator: s32; observed: u64; }Find :: (name: string) -> s64Read :: (name: string, output: *Text)Put :: (name: string, value: string) -> boolOption :: (state: *State, name: string, output: *Text) -> boolIndicator :: (value: string) -> s32CopyOption :: (args: []Text, name: string, fallback: string, target: *Text) -> boolConfigure :: (state: *State, args: []Text, path: string, in_menu: bool) -> boolSwap :: (a: *State, b: *State)Value :: (value: string, radio: bool, fallback: string) -> stringSelected :: (state: *State) -> boolSelect :: (state: *State, selected: bool) -> boolInvoke :: (state: *State) -> booltk/src/font.zi
font
Inferno font descriptors and packed one-bit subfonts. See libdraw/readsubfont.c.
Import with #import "tk/font".
MAX_FONTS :: 32MAX_SUBFONTS :: 64MAX_FONT_BYTES :: 524288Subfont :: struct { first: s32; last: s32; offset: s32; ascent: s32; atlas: Bitmap.Bitmap; metrics: Text; }Font :: struct { name: Text; references: s64; height: s32; ascent: s32; subfonts: Vec(Subfont); }Store :: struct { fonts: Vec(Font); open: Images.Loader; }Glyph :: struct { atlas: *Bitmap.Bitmap; x: s32; width: s32; top: s32; bottom: s32; left: s32; rise: s32; advance: s32; }Token :: (source: string, at: *s64) -> stringNumber :: (word: string) -> (s32, bool)RelativePath :: (font: string, name: string) -> TextMetricX :: (metrics: string, at: s64) -> s32ReadSubfont :: (sub: *Subfont, bytes: string) -> boolLoad :: (font: *Font, path: string, open: Images.Loader) -> boolGet :: (store: *Store, font: s64) -> *FontAcquire :: (store: *Store, path: string) -> s64Retain :: (store: *Store, font: s64)Release :: (store: *Store, font: s64)Lookup :: (font: *Font, rune: s32) -> GlyphCharacter :: (font: *Font, rune: s32) -> GlyphLine :: (text: string, start: s64) -> (s64, s64)Inferno Canvas passes the line's byte length to Draw, which counts runes.
Measure :: (font: *Font, text: string) -> (s32, s32)tk/src/image.zi
image
A Tk root owns its names; widgets can retain images after a name is deleted. File loading is supplied by the application using the current namespace.
Import with #import "tk/image".
MAX_IMAGES :: 32Loader :: #type (path: string, bytes: *Text) -> boolEntry :: struct { name: Text; pixels: Bitmap.Bitmap; mask: Bitmap.Bitmap; refs: s32; order: s64; }Store :: struct { items: Vec(Entry); open: Loader; next_name: s64; order: s64; }SetError :: (result: *T.Result, reason: string)Find :: (store: *Store, name: string) -> s64Read :: (store: *Store, source: string, bitmap: *Bitmap.Bitmap) -> boolSetBitmap :: (target: *Bitmap.Bitmap, source: *Bitmap.Bitmap)Allocate :: (store: *Store, bitmap: *Bitmap.Bitmap, mask: *Bitmap.Bitmap, existing: s64) -> s64Retain :: (store: *Store, handle: s64)Release :: (store: *Store, handle: s64)Forget :: (store: *Store, index: s64)Create :: (store: *Store, args: []Text, result: *T.Result)Names :: (store: *Store, result: *T.Result)Command :: (store: *Store, args: []Text, result: *T.Result)tk/src/listbox.zi
listbox
Listbox commands and vertical viewport, following Inferno libtk/listb.c.
Import with #import "tk/listbox".
ROW_HEIGHT :: View.ROW_HEIGHTINSET :: 2Row :: struct { text: Text; selected: bool; }State :: struct { rows: Vec(Row); width: s32; height: s32; visible: s64; top: s64; active: s64; anchor: s64; browse: bool; }Error :: (result: *T.Result, message: string)Integer :: (result: *T.Result, value: s64)Default :: () -> StateClamp :: (value: s64, upper: s64) -> s64Move :: (list: *State, top: s64)Layout :: (list: *State, height: s32)Fractions :: (list: *State) -> Scroll.StateSee :: (list: *State, row: s64)Activate :: (list: *State, row: s64)Choose :: (list: *State, row: s64)Press :: (list: *State, y: s32)Drag :: (list: *State, y: s32)Step :: (list: *State, step: s64)Index :: (list: *State, word: string) -> (s64, bool)Range :: (list: *State, args: []Text) -> (s64, s64, bool)Reverse :: (list: *State, first: s64, end: s64)Insert :: (list: *State, index: s64, values: []Text) -> boolAfterDelete :: (index: s64, first: s64, last: s64) -> s64Delete :: (list: *State, first: s64, last: s64)Yview :: (list: *State, args: []Text, result: *T.Result)Selection :: (list: *State, args: []Text, result: *T.Result)Command :: (list: *State, args: []Text, result: *T.Result)tk/src/paint.zi
paint
A small, host-independent RGBA renderer and original stroke lettering.
Import with #import "tk/paint".
Canvas :: struct { pixels: []u8; width: s32; height: s32; first: s32; clipped: bool; clip: Tk.Box; }Ink :: struct { r: u8; g: u8; b: u8; }PAPER :: Ink.{r = 244, g = 246, b = 247}BUTTON :: Ink.{r = 224, g = 234, b = 242}PRESSED :: Ink.{r = 188, g = 213, b = 231}BORDER :: Ink.{r = 119, g = 149, b = 173}LETTER :: Ink.{r = 25, g = 47, b = 67}MUTED :: Ink.{r = 112, g = 123, b = 132}ENTRY :: Ink.{r = 255, g = 255, b = 255}SELECTION :: Ink.{r = 255, g = 228, b = 145}LINK :: Ink.{r = 30, g = 98, b = 145}Fill :: (canvas: *Canvas, box: Tk.Box, ink: Ink)Strokes :: (rune: s32) -> stringEach group is x0,y0,x1,y1 on a 5 by 7 grid. Lowercase uses the same glyphs.
Magnitude :: (value: s32) -> s32Stroke :: (canvas: *Canvas, origin_x: s32, origin_y: s32, segment: string, ink: Ink)DrawText :: (canvas: *Canvas, box: Tk.Box, text: string, center: bool, ink: Ink)TextRow :: (canvas: *Canvas, view: *View.State, box: Tk.Box, line: string, start: s64)DrawEntry :: (canvas: *Canvas, widget: *Tk.Widget, active: bool)RenderFocusedEntry :: (pixels: []u8, width: s32, height: s32)Render :: (pixels: []u8, width: s32, height: s32, first: s32)Paint the rows from first (inclusive) through height (exclusive).
Color :: (rgb: s32) -> InkDrawCanvas :: (canvas: *Canvas, widget: *Tk.Widget)Vertex :: struct { x: float64; y: float64; }CeilPixel :: (value: float64) -> s32DrawLine :: (canvas: *Canvas, x0: s32, y0: s32, x1: s32, y1: s32, half: s32, ink: Ink)EllipseSpan :: (rx: s32, ry: s32, offset: s32) -> s32DrawOval :: (canvas: *Canvas, x: s32, y: s32, rx: s32, ry: s32, half: s32, fill: s32, outline: s32)DrawIndicator :: (canvas: *Canvas, x: s32, y: s32, radio: bool, selected: bool, ink: Ink)DrawCheck :: (canvas: *Canvas, widget: *Tk.Widget)ScrollSegment :: (box: Tk.Box, horizontal: bool, first: s32, last: s32, inset: s32) -> Tk.BoxDrawScroll :: (canvas: *Canvas, widget: *Tk.Widget, index: s64)DrawScale :: (canvas: *Canvas, widget: *Tk.Widget, index: s64)DrawPanel :: (canvas: *Canvas, widget: *Tk.Widget)RenderPanels :: (pixels: []u8, width: s32, height: s32)Animated panels can refresh their existing rectangles between layout changes.
tk/src/scale.zi
scale
Fixed-point scale values and slider geometry, following Inferno libtk/scale.c.
Import with #import "tk/scale".
UNIT :: 1000SLIDER :: 16INSET :: 3MINOR :: 18VALUE_HEIGHT :: 20State :: struct { first: s64; last: s64; value: s64; resolution: s64; big_increment: s64; length: s32; horizontal: bool; show_value: bool; }Default :: () -> StateParse :: (text: string, unit: s64) -> (s64, bool)Append :: (target: *Text, value: s64, unit: s64)Bound :: (scale: *State, value: s64) -> s64Step :: (scale: *State, direction: s64) -> s64Travel :: (length: s32) -> s32Position :: (scale: *State, length: s32) -> s32Drag :: (scale: *State, length: s32, delta: s32, base: s64) -> s64tk/src/scrollbar.zi
scrollbar
Fractional scrollbar geometry and pointer hit testing.
Import with #import "tk/scrollbar".
UNIT :: 10000WIDTH :: 18LENGTH :: 54MIN_THUMB :: 8State :: struct { first: s64; last: s64; horizontal: bool; }Geometry :: struct { arrow: s32; travel: s32; first: s32; last: s32; }Clamp :: (fraction: s64) -> s64Track :: (state: *State, length: s32) -> GeometryHit :: (track: Geometry, offset: s32, length: s32) -> stringtk/src/text.zi
text
UTF-8 character boundaries shared by entry editing and stroke rendering.
Import with #import "tk/text".
Decode :: (text: string, at: s64) -> (s32, s64)Next :: (text: string, at: s64) -> s64Previous :: (text: string, at: s64) -> s64Offset :: (text: string, count: s64) -> (s64, bool)Count :: (text: string, limit: s32) -> s32SingleLine :: (text: string) -> booltk/src/view.zi
view
Reusable line wrapping and vertical viewport for a Tk text widget.
Import with #import "tk/view".
ROW_HEIGHT :: 19INSET :: 6FRACTION :: 1000000Tag :: struct { name: Text; release: Text; underline: bool; }Range :: struct { tag: s64; first: s64; last: s64; }State :: struct { rows: Vec(s64); tags: Vec(Tag); ranges: Vec(Range); columns: s32; visible: s32; top: s32; appended: bool; }FindTag :: (view: *State, name: string) -> s64EnsureTag :: (view: *State, name: string) -> s64AddRange :: (view: *State, tag: s64, first: s64, last: s64) -> boolClearRanges :: (view: *State, tag: s64)Reset :: (view: *State)Clamp :: (view: *State)Reflow :: (view: *State, source: string, columns: s32, visible: s32)Row :: (view: *State, source: string, row: s32) -> stringPoint :: (view: *State, source: string, x: s32, y: s32, width: s32) -> (s64, bool)Coordinates are relative to the wrapped content, after the widget inset.
See :: (view: *State, at: s64)Offset :: (source: string, line: s64, column: s64) -> s64Index :: (source: string, at: s64, output: *Vec(u8))Match :: (source: string, pattern: string, start: s64, stop: s64, backwards: bool) -> s64Move :: (view: *State, lines: s64)PageSize :: (view: *State) -> s32AddFraction :: (output: *Vec(u8), value: s64)Position :: (view: *State, output: *Vec(u8))Moveto :: (view: *State, fraction: string) -> booltk/src/widgets.zi
widgets
Optional Tk command model, following Inferno libtk and tcl_tk.b. See ../NOTICE.
Import with #import "tk/widgets".
MAX_WIDGETS :: 32MAX_ENTRY_BYTES :: 16384LABEL :: 0BUTTON :: 1FRAME :: 2ENTRY :: 3TEXT :: 4SCALE :: 5PANEL :: 6CHECKBUTTON :: 7SCROLLBAR :: 8CANVAS :: 9LISTBOX :: 10MENU :: 11MENUBUTTON :: 12RADIOBUTTON :: 13SelectionButton :: (kind: s64) -> boolMAX_PANEL_BYTES :: 16777216CHAR_WIDTH :: Canvas.CELL_WIDTHENTRY_INSET :: 8ROOT_INSET :: 12DEFAULT_PAD_X :: 8DEFAULT_PAD_Y :: 5Box :: struct { x: s32; y: s32; w: s32; h: s32; }Packing :: struct { side: s32; padx: s32; pady: s32; fill: s32; expand: s32; anchor_x: s32; anchor_y: s32; }Panel :: struct { pixels: Vec(u8); width: s32; height: s32; border: s32; }Widget :: struct { name: Text; text: Text; command: Text; box: Box; kind: s64; parent: s64; cursor: s64; view: View.State; scale: Scale.State; panel: Panel; check: Check.State; scroll: Scroll.State; canvas: Canvas.State; text_height: s32; last_scroll: Scroll.State; sent_scroll: bool; disabled: bool; requested: Box; order: s32; pack: Packing; }widgets: Vec(Widget)One root per application.
attached: boolclosed: boolpressed: s64pressed_range: s64focused: s64sequence: s32drag_start: s32drag_value: s64canvas_hover: s64canvas_buttons: s32canvas_x: s32canvas_y: s32canvas_pointer_known: boollast_canvas_button: s32last_canvas_press: s64Attach :: (interpreter: *Tcl.Interpreter) -> boolFind :: (name: string) -> s64ParentEnd :: (path: string) -> s64SetError :: (result: *Result, message: string)Configure :: (widget: *Widget, args: []Text, result: *Result, path: string) -> boolCreate :: (kind: s64, args: []Text, result: *Result)Pack :: (_: s64, args: []Text, result: *Result)Destroy :: (_: s64, args: []Text, result: *Result)WidgetCommand :: (_: s64, name: string, args: []Text, result: *Result, script: *Text)Focus :: (_: s64, args: []Text, result: *Result)Bind :: (_: s64, args: []Text, result: *Result)EntryOffset :: (widget: *Widget, index: string) -> (s64, bool)Insert :: (widget: *Widget, at: s64, value: string) -> boolDelete :: (widget: *Widget, first: s64, last: s64)EntryCommand :: (widget: *Widget, args: []Text, result: *Result)TextLayout :: (widget: *Widget)TextOffset :: (widget: *Widget, name: string) -> (s64, bool)TextSearch :: (widget: *Widget, args: []Text, result: *Result)TextTag :: (widget: *Widget, args: []Text, result: *Result)AppendText :: (widget: *Widget, value: string) -> boolTextCommand :: (widget: *Widget, args: []Text, result: *Result)EntryKey :: enum { Return = 0; Backspace = 1; Delete = 2; Left = 3; Right = 4; Home = 5; End = 6; Up = 7; Down = 8; PageUp = 9; PageDown = 10; }KeyDown :: (key: EntryKey) -> TextTextInput :: (value: string)Minimum :: (a: s32, b: s32) -> s32Maximum :: (a: s32, b: s32) -> s32NonNegative :: (x: s32) -> s32NextChild :: (parent: s64, after: s32) -> s64Horizontal :: (pack: Packing) -> boolEntryWidth :: (widget: *Widget) -> s32Measure :: (parent: s64) -> BoxExpansion :: (index: s64, cavity: s32, horizontal: bool) -> s32Reserve room for later siblings before sharing the cavity among expanders.
Place :: (parent: s64, cavity: Box)Layout :: (width: s32, height: s32)EntrySlots :: (box: Box) -> s32EntryStart :: (widget: *Widget) -> s64Over :: (x: s32, y: s32, kind: s64) -> s64BoundRange :: (widget: *Widget, x: s32, y: s32) -> s64PointerDown :: (x: s32, y: s32)PointerUp :: (x: s32, y: s32) -> TextPointerScript :: (script: string, local_x: s32, local_y: s32) -> TextClosed :: () -> boolMenuPosted :: () -> boolConfigureScale :: (widget: *Widget, args: []Text, result: *Result) -> boolScaleCommand :: (widget: *Widget, args: []Text, result: *Result)ScaleLength :: (widget: *Widget) -> s32ScaleCoordinate :: (widget: *Widget, x: s32, y: s32) -> s32ScaleInput :: (widget: *Widget, value: s64) -> TextScaleTrack :: (widget: *Widget) -> BoxPointerPress :: (x: s32, y: s32) -> TextDragging :: () -> boolPointerMove :: (x: s32, y: s32) -> TextCanvasPointerKind :: enum { Move = 0; Press = 1; Release = 2; }CanvasCallback :: #type (tcl: *Tcl.Interpreter, script: Text) -> boolCanvasDispatch :: (tcl: *Tcl.Interpreter, index: s64, x: s32, y: s32, mask: s32, callback: CanvasCallback) -> boolCanvasTarget :: (index: s64, x: s32, y: s32) -> s64CanvasPointer :: (tcl: *Tcl.Interpreter, x: s32, y: s32, kind: CanvasPointerKind, button: s32, time: s64, callback: CanvasCallback) -> boolScaleDrag :: (widget: *Widget, x: s32, y: s32) -> TextConfigurePanel :: (widget: *Widget, args: []Text, result: *Result) -> boolPanelCommand :: (widget: *Widget, args: []Text, result: *Result)PanelImage :: (name: string, width: s32, height: s32) -> s64Allocate a writable RGBA8 image for the panel and return its widget index. Callers take a fresh pixel view while the widget is alive.
VariableCommand :: (_: s64, args: []Text, result: *Result)CheckCommand :: (widget: *Widget, args: []Text, result: *Result, script: *Text)Distance :: (value: string) -> (s32, bool)ConfigureScroll :: (widget: *Widget, args: []Text, result: *Result) -> boolScrollCommand :: (widget: *Widget, args: []Text, result: *Result)ScrollLength :: (widget: *Widget) -> s32ScrollOffset :: (widget: *Widget, x: s32, y: s32) -> s32ScrollPress :: (index: s64, x: s32, y: s32) -> TextScrollDrag :: (widget: *Widget, x: s32, y: s32) -> TextTextScroll :: (widget: *Widget, script: *Text)AppendScroll :: (widget: *Widget, script: *Text, fractions: Scroll.State)AppendScrollCommand :: (command: string, script: *Text, fractions: Scroll.State)CanvasScroll :: (canvas: *Canvas.State, script: *Text) -> boolCollectScroll :: (script: *Text)Update :: (_: s64, name: string, args: []Text, result: *Result, script: *Text)