Commit Graph
13 Commits
Author SHA1 Message Date
waozi 6d9702870a atlas: sub-pixel advances; language cartridge from traced values
KFA1 glyph advances are now 1/256-px fixed point ((int)(adv*scale*256
+0.5) at bake; single rounding at draw/measure, matching ui_text.c's
float path). Spec updated.

The instrumented title run exposed the real screen content: the title
is 'Choose Language' (locale key), not 'Language' — resolving the
width anomaly. The cartridge now uses the traced strings, sizes,
and positions ('Choose Language' fs24 phys(159,32), 'Language' fs16
(45,273), 'Next' fs12 (230,377)); per-mille scale verified in-binary
(scale=1125, scale_px(141)=159).

Native parity 5765 -> 5179/307200 (98.3%). The residual is the
classic last mile: every glyph edge sits one sub-pixel off between
an exact integer blit and GL quad rasterization — closing it means
emulating the GPU's quad fill/sample rule in kry_sw. Cross-engine
8/8 byte-identical (after rebuilding the stale SDL host); suites and
goldens green.
2026-08-17 07:12:25 -03:00
waozi e9fe1e17e0 krb v2: dropdown controls
KRB_CTRL_DROPDOWN (kind 4) implemented end to end: the control record's
reserved options_off/option_count now carry consecutive NUL-terminated
option strings (k2b appends them without interning so they stay
contiguous; Dropdown(id,x,y,w,"a;b;c",&val)). Click toggles the popup,
clicking a row writes the selected index to the bound int and closes.
Loader initializes the open-dropdown slot to -1 (0 is a valid index).
2026-08-16 22:11:03 -03:00
waozi cb6faf430d krb v2: scroll containers
SCROLL node (type 12): viewport bounds, content height in font_size,
mounted pixel offset at name_off. Children (parent = scroll index)
draw translated by -offset and clipped to the viewport; a new
optional KryBackend.wheel entry drives the offset when the pointer is
over the viewport, clamped to [0, content_h - h]. Implemented in
kry_sw (+KrySwWheel injection), the raylib surface backend, the null
and recorder backends; krb-sdl maps SDL_MOUSEWHEEL, krb-web exposes
krb_web_wheel from canvas wheel events. k2b compiles

  Scroll(x, y, w, h, contentH, &state.off) ... EndScroll()

bracketing child widgets (parent-linked). Fixed a compounding-offset
bug where draw_tree's origin was mutated across children.
2026-08-16 22:03:44 -03:00
waozi c1be0cb82d k2b+engines: KFA1 glyph atlas — antialiased Noto text in cartridges
- k2b bakes a per-cartridge atlas (stb_truetype over the vendored
  NotoSans) covering the cartridge's charset at its used pixel sizes,
  embeds it as the kind 1 asset '@atlas'. K2B_FONT overrides the face.
- kry_sw renders atlas text: UTF-8 decoding, per-glyph advances,
  source-over coverage blending, nearest-size scaling; measure uses
  real advance widths. KrySwSetAtlas installs it; krb-run, krb-sdl,
  and krb-web all load '@atlas' after KrbLoad.
- Cartridge cap raised 64 KiB -> 16 MiB (output buffer static) to fit
  atlases/images; krb_cartridge_test budget adjusted. Engine goldens
  regenerated (atlas advances change text layout).
- Fixed on the way: atlas record stride (18 bytes), pack buffer
  ownership, and a realloc'd-header write in the baker.

Verified: 'Ag' at 24px renders as antialiased glyphs from embedded
bytes; full krb suite green.
2026-08-16 21:59:11 -03:00
waozi f17bc26987 krb v2: embedded asset section + texture_rgba blit
Cartridges can now carry their pictures: a v2 asset section (header
offset 28 = asset_bytes) after controls[] holds a directory of
20-byte entries (path, absolute data offset, size, kind, w, h) plus
blobs. KrbAssetFind looks paths up; a PICTURE node whose path is
embedded renders from cartridge pixels through the new optional
KryBackend.texture_rgba (nearest-neighbor scaled, tint-modulated,
clipped) — kry_sw implements it, so krb-run, krb-web, and krb-sdl all
get embedded assets. Non-embedded paths still fall back to host
texture loading. kinds: 0 raw RGBA8, 1 reserved for the glyph atlas.

tests/krb_asset_test.c proves lookup + 2x2->8x8 scaled, tinted blit
with correct bounds; spec updated in KRB_FORMAT.md. k2b embedding of
decoded image files is the follow-up.
2026-08-16 21:29:13 -03:00
waozi d35b412a96 docs: KRB_FORMAT.md rewritten as an exact byte-level specification
Every record now carries explicit field offsets and sizes (header 32B,
node 28B, control 24B), section layout formulas, encoding rules
(little-endian, string references, absolute prog offsets), validation
requirements, per-node-type rendering and interaction semantics, full
VM opcode table with stack/jump rules, limits, and the host surface a
renderer must provide — enough to write an independent parser and
renderer from the document alone.
2026-08-16 21:07:52 -03:00
waozi 89dc220fda krb v2: in-cartridge logic VM + circle/ring geometry nodes
The plan-07 core: cartridges stop being static pictures.

- New v2 opcodes: a 16-deep int stack machine (PUSH_CONST/PUSH_PATH/
  POP_STORE, ADD..GE, JMP/JZ, TIME) plus OP_DRAW_NODE so UI can be
  conditional on mounted state. Loader accepts v1 and v2; k2b now
  writes version 2.
- New node types CIRCLE (center+radius) and RING (annulus), the shapes
  the inbe breath visualizer needs; k2b parses DrawCircleV/DrawRing
  (with (Color){r,g,b,a} literals). KryBackend gains optional circle/
  ring entries — implemented in kry_sw, the raylib surface backend,
  the null backend, and forwarded+logged by the recorder.
- tests/krb_logic_test.c: hand-assembled v2 cartridge proving counter
  increments per frame, conditional node visibility across frames,
  circle/ring rasterization bounds, and TIME. Engine golden test passes
  unchanged on v2 output (render back-compat).
- KRB_FORMAT.md documents v2 and the R>=0x80 theme-slot color caveat.
2026-08-16 20:37:44 -03:00
waozi d84db61262 Document KIR compiler roadmap 2026-08-13 10:36:32 -03:00
waozi 115a104457 krb: controls[] section + range widgets (Slider, VerticalSlider, Spinbox)
Add a controls[] table to the format for interactive widgets whose args don't
fit the 28-byte node. The header's reserved field becomes control_count
(backward compatible: old files have 0 -> no section). Each 24-byte KrbControl
record carries kind/id/min/max/step + value_off/label_off/options_off; a
KRB_NODE_CONTROL (9) node references it by bind_slot.

Range widgets bind a state{} field (value_off), render with KryBackend
primitives, and update the value on interaction:
- Slider / VerticalSlider: a held drag sets the value across [min,max].
- Spinbox: a click steps by 'step' (clamped), left half down / right half up.

The cartridge owns the value (read/write via the mount), like Checkbox/Toggle.
Dropdown/Combobox (need a state-array option parser) and by-value Radio/TabBar
remain deferred.

Verified: 03_theme.kry emits a Slider as a CONTROL node + control record;
krb_mount_test builds a SLIDER cartridge and asserts a drag sets 0->80 (and a
no-drag frame leaves it); make test green. KRB_FORMAT.md documents the
controls[] section and the CONTROL node.
2026-08-13 06:50:14 -05:00
waozi 0397d5e6c1 krb: interactive Checkbox + Toggle widgets (value-bound, self-contained toggle)
Add the first interactive cartridge widgets. CHECKBOX (7) and TOGGLE (8) bind
to a state{} field by name (the widget's &val arg -> name_off), render with
KryBackend primitives (box outline + check / track + thumb + label), and on an
in-bounds mouse press flip the value back through the mount. The cartridge
owns the toggle (no host handler, unlike BUTTON) — the host just reads the
resulting state. Only state{} fields bind (what the host mounts).

These two fit the existing 28-byte node (path/label/id map to spare fields);
range/options widgets (Slider/Spinbox/Dropdown/Combobox) and by-value widgets
(Radio/TabBar) need a controls[] args section and are deferred.

Verified: krb_mount_test builds a CHECKBOX, mounts a value, and asserts an
in-bounds press flips 0->1 (and no-press leaves it); the cartridge frame
fixture now carries a Checkbox and asserts its value path lands in the string
table; make test green.
2026-08-13 06:27:36 -05:00
waozi 2b9e54f128 krb compiler: widen widget coverage (color literals, Line/Separator/Bevel/TextInRect, Picture)
The .kry->.krb slice only captured Background/Text/Rect/Button and collapsed
every non-theme color to opaque black. Broaden it:

- parse_color now understands hex (0xRRGGBBAA / 0xRRGGBB) and the raylib color
  sentinels (WHITE/BLACK/BLANK/RED/GREEN/BLUE/...), not just theme getters.
- New parsers map static widgets onto existing node types: Separator (themed
  rail RECT), Line (axis-aligned bounding RECT), Bevel (light-face RECT),
  TextInRect (TEXT). A shared node_rect() helper parses (Rectangle){...}.
- Picture becomes a first-class node type KRB_NODE_PICTURE=6 (additive; old
  loaders hit default:break). text_off carries the asset path, color the tint,
  style the UIPictureFit. KryBackend gains a texture() entry (implemented via
  KryLoadPictureTexture + KryPictureFitRect in the raylib backend, no-op in the
  null backend), and draw_node renders it. A depth-aware find_match_brace() is
  needed because PictureProps nests Rectangle/Vector2 braces.

Interactive stateful widgets (Slider/Toggle/Checkbox/TextField/Dropdown/etc.)
are deferred: they need host-side state + event capture. Verified: 19_pictures
compiles to 2 PICTURE nodes and kryon-preview cartridge renders the real
textures; all krait samples still compile; make test green.
2026-08-13 06:04:55 -05:00
waozi a9d7694dc9 krb: drop unused GROUP node and export enums for a clean v1
KRB_NODE_GROUP, KRB_EXPORT_LOCAL/R/RW, and KRB_FLAG_EXPORT_MASK were
defined but never emitted, set, or read. Per the no-dead-code rule, remove
them so the shipped v1 surface is honest: node types are BACKGROUND/TEXT/
RECT/BUTTON/DATA (type 0 reserved), and flags carry only SCALE_X/Y/W/H
(bits 0-1 reserved). The three opcodes stay (they are implemented and
host-appendable). KRB_FORMAT.md updated to match and to document DATA.
2026-08-12 19:12:13 -05:00
waozi 2c84504c6a Add krb: a packed, mmapable Kryon cartridge format
A .krb file is a little-endian image: a 32-byte header (magic "KRB\0",
version 1), a 28-byte VFS node table (group/background/text/rect/button/
data), a UTF-8 string table, a tiny program (OP_DRAW_TREE/OP_CALL_HOST/
OP_SET_I32), and a host-import name list. Behavior stays in C.

KrbLoad/KrbLoadFile validate and map the image in place; KrbDraw/KrbExec
walk it through a KryBackend; KrbMount/KrbBindMem map live C fields onto
paths so TEXT nodes draw live values; KrbBind wires host functions to
import slots. Format spec in docs/KRB_FORMAT.md.
2026-08-12 19:02:44 -05:00