Files
kryon/docs/API.md
T
waozi 2e74cf287b Move Plot, the data views, and Syntax into their own packages
PlotWidget now lives in kryonlabs/plot, TableView and TreeView in
kryonlabs/data-views, and the Ziran, C, and Make tokenizer in
ziranlang/syntax, which no longer depends on Kryon. Apps add them with
`ziran add URL` and import plot/Plot, data_views/TableView, or
syntax/Syntax.

Kryon exports the building blocks those packages draw with (session,
tree, surface, paint_queue, style, style_sheet, widget_kind, and the
rest), so a widget package imports kryon/NAME instead of reaching into
Kryon's source directories. The API guide describes writing one.
2026-09-29 19:47:57 -03:00

3.2 KiB

Kryon API

Kryon is an ordinary Ziran package. An application imports the modules it uses; no widget names are recognized by the Ziran compiler or .zib loader. The public package imports are declared in ziran.toml.

Import Surface
Kryon Geometry, drawing values, sessions, Text(TextProps), and Button(ButtonProps)
Widgets The core widget catalog, including Image(ImageProps), page structure, fields, controls, layout, and tree input
Page, Semantic Direct page and semantic-kind exports for document-oriented applications
Kss Optional style parsing and installation
geometry, drawing_props, session, tree, surface, paint_queue, style, style_sheet, control_props, font_metrics, scroll, semantic, tree_input, widget_kind Building blocks for widget packages

Widget packages

A widget that is not part of the core catalog lives in its own Git package and depends on Kryon. Plot and DataViews are examples. Import the building blocks by their package-qualified names, so a reader sees which package each name comes from:

#import "kryon/session"
#import "kryon/tree"
#import "kryon/surface"
#import "kryon/paint_queue"

Tests that need a host bind Kryon's internal capabilities the same way, for example --bind kryon/raster_text:RasterText=my_test_host:RasterText with ziran bundle --project.

Source coloring is the separate Syntax package. Its SyntaxColorSpan has the same fields as TextAreaColorSpan.

Style rules

InstallStyleRules copies typeface text into Kryon-owned storage and returns false without replacing the active rules when the rule count is outside 0..320 or the combined typeface text exceeds 65,536 bytes. InstallParsedStyleRules reports the same storage failure.

Use Image(ImageProps) for UI images. Its asset path, bounds, fit, and alt text describe the image at the widget boundary. Backend texture calls are renderer primitives, not alternate widget APIs.

An application using a Kryon host exports a Ziran function with this shape:

using UI :: #import "Widgets";

#program_export
Frame :: (session: Session, viewport: Rectangle) -> s32 {
    label: TextProps
    label.text = "Hello, Kryon"
    Text(session, label)
    return 0
}

The selected host owns the process entry point, calls BeginFrame and EndFrame, supplies input to the session, and presents paint operations. Application code owns its product state and calls widgets within Frame. The complete manifest and build commands are in PROJECTS.md.

Individual .zi modules under src/ui can also be imported by non-graphical Ziran programs. A program that does not import Kryon uses no Kryon code. A portable .zib links only imported modules and needs a host binding for any platform effect they call.

src/ui/modules.txt is the core build inventory. make test checks source, saved .zir, .zib, and generated C/C++/Go behavior. See FEATURE_MATRIX.md for package and host verification.