Files
kryon/examples
waozi 197d21f2f8 Draw images warped over a grid of points
ImageProps.mesh holds a columns x rows grid of screen points; Image
stretches the picture across it, two textured triangles per cell, so a
painted limb can bend at its joint like a paper puppet. Mirrored grids
draw (nothing is culled), the bounds still clip, and fit, origin,
rotation and the style radius do not apply. A grid with too few points
draws nothing, and no placeholder covers its bounds.

The paint queue copies the points into per-session blocks when queued,
moves them with their node, and compares them in the retained snapshot,
so a moved vertex repaints and an unchanged grid reuses the frame.

RasterImageMesh draws the grid in every host: raylib (desktop and
Android) sends front-facing textured triangles in one batch, the web
canvas and Cairo draw each triangle through its affine transform under a
clip, the pixmap host and Plan 9 libdraw rasterize pixel centers with a
shared edge rule (bilinear when smooth), and the terminal shows a marker.
The bundle player, zib tool and frame replay bind it, and hosted bundles
send up to 256 points with a plain Image (a per-field slice bound in the
codec generator keeps every ImageProps codec small).

Tests: pixmap mesh test (C, C++, Go, bundles; copy, snapshot reuse,
mirror, bend, clip, seams), Cairo mesh test, RGBA canvas cases, web
canvas pixels and seam at three densities, hosted widget mesh, and a
raylib pixel test on a private Xvfb (make raylib-mesh-pixels-test).
2026-10-14 20:05:57 -03:00
..
2026-07-20 11:25:19 -03:00

Ziran example

hello.zi is a small Ziran application that imports Kryon's ordinary Button and pointer modules. It builds a retained tree, handles a press and release, and changes the button label after the click. hello_host.zi supplies four raw pointer samples, font measurements, and SVG drawing effects. The application and host are both Ziran source. No window or display server is opened.

From the Kryon repository root, with the ziran command installed:

make -C examples
make -C examples test

The first command builds build/examples/ziran/hello.zib, generates and links a native program from the two .zi sources, and writes build/examples/ziran/hello.svg. Open the SVG in an image viewer to see the idle, pressed, released, and clicked frames side by side. The test also bundles the saved .zir, verifies that both .zib files match, and checks the native host's four-frame click result and SVG content. The portable bundle is built and compared here; its execution is covered by the separate portable runtime tests.

This example shows the intended application boundary: Ziran compiles only the modules the application imports; Kryon supplies widget decisions; a separate Ziran host supplies raw input, font, and drawing effects. Applications with a window use one of the hosts in BACKENDS.md instead.

An optional Ziran desktop host links the application with SDL2 and Cairo through declared foreign calls. Build it with make -C examples desktop. Run build/examples/ziran/hello-desktop from examples/ to interact with its button. Its repeatable four-frame check runs on a private display with make -C examples desktop-test and writes build/examples/ziran/hello-desktop.png without contacting the current desktop display. make -C examples desktop-image-test renders the canonical Image(ImageProps) with a path-backed PNG and red tint, then writes build/examples/ziran/image-desktop.png. The host imports Ziran's generic c_string module for safe C string arguments. It handles shapes, text, and path-backed PNG images. Texture handles and other image formats remain open.

make -C examples desktop-text-test renders the plain Text(TextProps) example under a private display and saves build/examples/ziran/text-desktop.png. It also checks that source and saved .zir produce the same portable text.zib. Run ../build/examples/ziran/text-desktop from examples/ to open the interactive window, or open examples/text_hello.zi in an editor to see its Ziran source.

make -C examples time-picker builds time_picker_demo.zi, Kryon's TimePicker without a time, with one, disabled and in a small form, with a Light and Dark switch. Run ../build/examples/ziran/time-picker-desktop from examples/ to try it with the mouse, touch and keyboard. make -C examples time-picker-shots plays scripted scenes on a private display and saves them in build/time-picker-shots/.