Commit Graph
30 Commits
Author SHA1 Message Date
waozi 2726d54f72 Advance Kry compile-time checks and expression KIR 2026-08-19 18:12:26 -03:00
waozi 1d5292704a k2b: lower Combobox to a KRB_CTRL_COMBOBOX control
Combobox((ComboboxProps){...}) previously had no lowering, so the
KRB_CTRL_COMBOBOX kind could never appear in a cartridge. k2b now
parses the Props literal (positional or designated) and emits the
control; the cartridge runtime routes it to the dropdown renderer,
exactly mirroring the C widget, which forwards to DrawUIDropdown.

Option lists can now come from .kry string-array variables (state or
local 'name: [N] const char* = {...}'), registered as joined 'a;b;c'
lists and usable by both Combobox and Dropdown lowering, not just from
inline literals.
2026-08-18 16:13:04 -03:00
waozi bc0a3999d0 ui: enforce cross-lowering text input latency 2026-08-17 20:26:30 -03:00
waozi 99bd4a01a9 ui: finalize deferred overlays at frame end 2026-08-17 12:20:36 -03:00
waozi 41687a5e48 KrbAutoMount: state initializers render without a host
DATA nodes now carry their initializer (ints in x, CSTRs via text),
and KrbAutoMount(img) binds them into malloc'd slots. krb-run and
krb-sdl both call it, so bound counters, checkbox defaults, and
TextField contents render identically with or without generated
host binds. Cross-engine 11/11 byte-identical; suites green,
goldens regenerated.
2026-08-17 08:15:25 -03:00
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 d11c4b0b5a atlas: raylib's ascent-shifted glyph offsets + per-mille UI scale
The instrumented ui_text.c run pinned the native tier facts: ui
scale 1.125 (title tier base=27px for a 24 logical size), advances
w=9/adv=10 for 'L' — and glyph offsetY of +6 where raw stbtt gives
-15. raylib rtext.c line 730 adds (int)(ascent*scale) to every
offsetY: glyph offsets are line-top-relative. k2b_atlas now applies
the same shift; per-glyph values match the app trace exactly
('L' off=(1,6), 'a' (0,10)).

kry_sw's UI scale is per-mille (1.125 isn't expressible in integer
percent) with the same (int)(px*s+0.5) rounding as ScaleUIPx; the
native harness threads KRB_EXACT_UI_SCALE. The language cartridge
is now authored in logical units.

Native parity: 6423 -> 5765/307200; glyph positions track the
native within ~1-2px per element. Remaining: fractional-advance
storage (raylib keeps float advanceX; the u16 truncation drifts
~0.5px/glyph) and the title's measured width, under investigation.
Cross-engine: 8/8 byte-identical, suites green, goldens updated.
2026-08-17 06:56:02 -03:00
waozi cde2f3a6fb k2b atlas: fix GetCodepointBitmapBox extents; tier collection and UI-scale plumbing
Three fixes:
- stbtt_GetCodepointBitmapBox returns coordinates (x0,y0,x1,y1), not
  width/height — the measurement pass used raw coordinates, computing
  bogus buffer heights and silently clamping most glyphs away. This
  was the real cause of the missing text with inbe's subset font and
  the krb-sdl/krb-run cross-engine 'noise'.
- Atlas size collection now excludes SCROLL nodes (their font_size
  field carries content height — a 1250px 'font tier' blew the
  cartridge cap on scroll screens 21-24).
- Optional physical-scale plumbing: K2B_UI_SCALE bakes tiers at
  physical sizes, krb.c passes font sizes through scale_px,
  KRB_RUN_UI_SCALE sets the kry_sw UI scale, and the native harness
  threads KRB_EXACT_UI_SCALE (default 1).

Cross-engine exactness restored: 8/8 screens byte-identical
kry_sw == SDL. Native parity holds at 6423/307200 (98.0%); the
remaining delta is the native app's effective font tier for the
title (measured advances imply a physical size above 24 at
480x640), to be pinned by instrumenting ui_text.c once rather
than sweeping scales.
2026-08-17 06:36:20 -03:00
waozi 554ce05ba5 k2b atlas: raylib-identical glyph rasterization
stbtt_PackFontRange replaced with per-glyph
stbtt_GetCodepointBitmap at stbtt_ScaleForPixelHeight plus
stbtt_GetCodepointHMetrics-scaled advances — the exact calls raylib's
rtext.c LoadFontData(FONT_DEFAULT) makes — row-packed first-fit with
bounds clamps. With KRB_EXACT_FONT pointing at inbe's subset face the
language screen reaches 6133/307200 differing pixels (98.0%): the
residual is raylib's DrawTextEx quad-sampling at glyph edges, not the
raster itself.
2026-08-17 06:12:59 -03:00
waozi 0b2c447d5d krb v2: animated geometry — WHM session screen runs live in-cartridge
New VM pieces: OP_MOD, and OP_NODE_SET (pops an i16 and patches a
node's x/y/w/h through a mutable node overlay allocated on first
use). TIME is now a first-class term in expressions. The k2b program
compiler was restructured around an ordered instruction stream
(updates, draws, guard/else brackets interleaved in source order) so
conditional assignments compile correctly — previously both branches
of an if always ran, last-write-wins. Updates accept full
term-or-term-arith-term right sides including % and TIME.

examples/26_inbe_whm_session.kry: the Wim Hof session as a cartridge —
TIME -> elapsed -> phase -> triangle wave -> animated ring radius via
AnimNode('ring0','w',&radius), breath counter with clamp, in/out
phase text. Verified across frames: t=0/600ms/5s produce the exact
expected phase, radius, and breath values. Eight exactness screens
byte-identical kry_sw == SDL.
2026-08-16 23:35:48 -03:00
waozi da6a472139 examples: habits screen cartridge (bound streak counters)
TextFormat now compiles to bound TEXT nodes correctly: the dispatch
was missing entirely, and the value/x/y/font/color args sit one slot
over from plain Text. Habits screen: scrollable rows with completion
checkboxes, live 'Streak: %d days' counters bound to state, and
conditional status lines. Engine goldens refreshed (the file held a
pre-atlas hash). All six exactness screens byte-identical kry_sw ==
SDL.
2026-08-16 23:12:49 -03:00
waozi f087c0654d krb v2: screen navigation — the whole app in one cartridge
KRB_FLAG_NAV buttons write a screen id to a state path on press
(cartridge-owned navigation; no host import). k2b compiles
NavButton(label, x, y, w, h, &state.screen, id). Screens are guarded
node ranges over one state field; examples/23_inbe_app.kry is Inner
Breeze as a single 6 MB cartridge — language, settings, and manual
screens with dropdowns, scroll, checkboxes, and the breath ring,
navigable end to end (verified: Next/Manual/Back transitions via
injected clicks). Scroll containers now draw a 1px outline instead
of a filled rect. All five exactness screens byte-identical
kry_sw == SDL.
2026-08-16 23:01:39 -03:00
waozi 2dda6f2f4a examples: settings screen cartridge (scroll + dropdowns + checkboxes)
Declarative port of inbe's settings/device tab: scroll container with
clamped wheel offset, language and orientation dropdowns, fullscreen
and keep-screen-on checkboxes, conditional hint rows via if/else.
k2b's Scroll() now parses ScaleUIPx content heights (atoi gave 0, so
the wheel clamp never engaged). Cross-engine exactness extended to
this screen: kry_sw == SDL byte-identical.
2026-08-16 22:54:18 -03:00
waozi 22f055ffd1 k2b: fix guard single-term parsing, positional ButtonProps, dropdown height
parse_term now returns consumed length (single-term guards like
'if (x == 0)' previously fell through to nothing while arithmetic
forms worked by accident). ButtonProps positional initializers
(label-first, Rectangle bounds) parse alongside the designated form.
Dropdown accepts an optional height argument.

examples/20_inbe_language.kry: a faithful declarative Inner Breeze
language-picker screen — title, bordered locale dropdown with five
options, if/else hint text, Next button — compiles to a cartridge
that renders complete in every engine with its embedded atlas.
2026-08-16 22:18:33 -03:00
waozi 2151e61414 k2b: arithmetic expressions in guard conditions
Each side of an if comparison is now term or term arith term
(path or integer, + - * /), compiled to the VM stack machine:
if (a + 1 < b - 2) emits PUSH/PUSH/ADD, PUSH/PUSH/SUB, LT, JZ.
2026-08-16 22:12:56 -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 84bd26de20 krb v2: text input — TEXTINPUT node + typed-codepoint vtable path
New node type 13: bounded field drawing the mounted CSTR with a
blinking caret when focused (click to focus). Typed input flows through
the new optional KryBackend.text_key (codepoints, 0x08 backspace):
kry_sw queues via KrySwText (drained per frame by Advance), the raylib
surface backend maps GetCharPressed, SDL maps SDL_TEXTINPUT/BACKSPACE,
krb-web exports krb_web_text from keypress events. UTF-8 runes append
and strip correctly. k2b compiles TextField(x,y,w,h,&state.field).

Verified: click-focus, typing with backspace, and that unfocused
fields ignore keys.
2026-08-16 22:06:53 -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 6b59bc6109 k2b: else branches and state-vs-state guard comparisons
'if (a > b) { ... } else { ... }' now compiles to compare + JZ/JMP
with true and false node ranges; the right side of a comparison can
be another mounted state path (PUSH_PATH) or an integer literal
(PUSH_CONST). Verified both branches with mounted and unmounted
state.
2026-08-16 21:46:10 -03:00
waozi ddcf455dd3 k2b: decode png/jpg/bmp/webp and embed as cartridge pixels
stb_image (vendored with raylib) decodes referenced Picture() files at
compile time; decoded RGBA8 goes in as kind 0 and renders through
texture_rgba in every engine. KRAW stays for hand-made raw pixels;
undecodable files (wav/ogg/fonts) remain opaque kind 2 blobs for
host-side unpacking. Verified: png cartridge renders after the source
file is deleted.
2026-08-16 21:42:09 -03:00
waozi 91d96a4983 k2b: embed referenced assets into the cartridge
k2b now packs what a cartridge references, making it self-contained:

- Every Picture() path resolvable under --root is embedded at emit
  time. .kraw files (KRAW magic + u16 w,h + RGBA8 pixels) go in as
  kind 0 and render through texture_rgba in every engine; any other
  file (png, wav, ogg, fonts) is embedded verbatim as a kind 2 opaque
  blob for host-side decoding via KrbAssetFind — sounds and arbitrary
  assets ride in the same section, unpackable by the application.
- The recorder backend forwards+logs texture_rgba (a NULL entry on
  the wrapper silently forced the host-path fallback).

Verified end-to-end: a cartridge whose tile.kraw is deleted after
build still renders the picture, scaled and tinted, purely from
embedded bytes (texture_rgba 2x2 -> 8x8 in the recorded stream).
2026-08-16 21:34:46 -03:00
waozi 6bad9e7e27 k2b: compile .kry state updates and if-guards into v2 VM programs
Cartridges stop needing host C for simple per-frame logic:

- k2b collects '<path> =/+=/-= N', '++', '--' statements from frame
  bodies and simple 'if (<path> <cmp> <int>)' guards over widget
  ranges, and emits them as VM opcodes: state updates run first, then
  one OP_DRAW_NODE per drawable node with guarded ranges wrapped in
  compare + JZ. Render-only cartridges still emit a single
  OP_DRAW_TREE (golden output unchanged).
- parse_color now understands (Color){r,g,b,a} literals everywhere
  (Rect etc.), not just in the circle parser.
- KrbExec JZ bug fixes: the jump-if-zero polarity was inverted, and a
  taken jump was clobbered by the executor epilogue. Both were masked
  by the hand-written test compiling its guard in positive form; a
  k2b-compiled cartridge exposed them.
- krb-run --frames N runs the cartridge N frames (advancing time and
  press edges) for observing state-dependent behavior headlessly.

Verified end-to-end: a .kry with counter += 1 and an if (counter < 4)
guard compiles to a 35-byte program; the guarded rect renders on
frames where the condition holds and disappears after, with the
counter mount showing 1+N.
2026-08-16 21:17:50 -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 ccec103ebc k2b: report call kinds the KRB vocabulary cannot express
A cartridge that comes out thin (inbe's pet screen: an egg widget,
locale text, Paragraphs) was silently missing everything k2b cannot
lower. The builder now tracks dropped call kinds per file and prints
one stderr line: 'k2b: <file>: N call kinds not in KRB: Paragraph x2
draw_egg x1 ...' - pet_screen.kry reports seven, which is the honest
content of the gap.
2026-08-16 07:52:09 -05:00
waozi 577681423a kc is fully gone: CHANGELOG/docs/comments now say k2c
- k2b drops its KC_* macro aliases (56 uses) for the KIR_* names.
- CHANGELOG, plan docs, examples README, scene-source comments all say
  k2c; the removed 512-statement cap entry no longer names the dead
  KC_BODY_MAX constant.
- k2c_lower: fix '&&' within '||' precedence in the member-access skip
  and three scope_stack[scope_top++] sequence-point UBs that -Wextra
  on the Android host build surfaced.
2026-08-14 21:00:34 -05:00
waozi e2df69c01b Remove the last kc remnants
- docs/KC_PARSER_PLAN.md: the pre-split kc parser plan — the parser it
  describes is deleted; the shipped architecture (kir frontend, k2c/k2b
  backends) lives in the sources.
- stale build/*/bin/kc binaries from before the rename.
- Comments/variable names still saying 'kc' in scene_tree.h,
  kry_animation.h, kryon-preview, k2b, krait's GNUmakefile/native_krb.c.
  CHANGELOG history entries keep the name each release actually shipped
  with.
2026-08-14 17:05:04 -05:00
waozi e41e5bceaf k2b: migrate to the shared Kir frontend — one frontend, two backends
k2b drops its private raw-.kry parser (k2b_parse.c + k2b.h deleted). It now
parses via kir_parse_file() — the SAME frontend k2c uses — and lowers
KirModule to .krb + C host:
- collect_state consumes structured KirStateField {name,type,init} directly
  (the decl-string re-parsing is gone); array types convert to C declarator
  order in the emitted host globals.
- collect_widgets tracks block depth on the fly (KirStmt has no depth field)
  for button-handler capture.
- app metadata comes from KirAppMeta; module/no_main flow through params.
- Makefile: k2b links kir.c + kir_parse.c.

Verified: 02_buttons.kry -> 12 nodes, magic 4b524200 (identical output);
krb_cartridge_test + make test green; kryon-preview cartridge renders.
2026-08-14 09:24:09 -05:00
waozi b3910fa403 Add initial KIR core 2026-08-13 11:17:39 -03:00
waozi 2005611f2b k2b: standalone .kry->.krb compiler, fully independent of kc
Split the cartridge compiler out of kc into its own CLI, k2b. kc is now
purely .kry -> .c; k2b is .kry -> .krb and links no kc code.

cmd/k2b/ (new):
- k2b_parse.c: a raw-.kry reader (state{} / app{} / screen|frame|fn|Name ::
  function bodies) with multi-line statement joining (paren/bracket/string
  depth, so widget calls join but block braces don't) and statement
  classification + depth for button-handler capture.
- k2b_krb.c: the cartridge codegen moved out of kc_krb.c, adapted to the new
  parser: extract_call() locates the widget call in bare / 'if Widget(...)' /
  'x := Widget(...)' forms, and collect_widgets captures button handlers from
  the 'if Button(...) {' statement directly.
- k2b_util.c + main.c: self-contained path/string utils + CLI entry.

kc cleanup: drop --emit-krb + write_krb (kc.c, kc_internal.h), delete
kc_krb.c. Makefile gains a K2B target (and legacy build/bin/k2b); the cartridge
test and kryon-preview cartridge use k2b.

Faithful: 02_buttons matches kc exactly (12 nodes, 3 imports); 03_theme
additionally captures two real Button calls kc had been missing. make test
green; kryon-preview cartridge renders via k2b.
2026-08-13 08:04:50 -05:00