Compare commits
375
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83f32e3fb9 | ||
|
|
6e08dce906 | ||
|
|
164fcd6ae7 | ||
|
|
d2159bbf11 | ||
|
|
ede20eb0e6 | ||
|
|
62eff75d38 | ||
|
|
b76823e24d | ||
|
|
5351b21eaa | ||
|
|
ad7260022b | ||
|
|
307a502c2a | ||
|
|
5bb554f210 | ||
|
|
31dfd6ffee | ||
|
|
1e7281b398 | ||
|
|
d44ee89d25 | ||
|
|
782baebe8c | ||
|
|
0fcc01b608 | ||
|
|
0b781f6df5 | ||
|
|
a7fe153191 | ||
|
|
3078f2d0e7 | ||
|
|
681e601818 | ||
|
|
15020a797b | ||
|
|
7e575afd99 | ||
|
|
6ace0ff5f3 | ||
|
|
6f9d8d712b | ||
|
|
dc3a22d0f1 | ||
|
|
66fb62de40 | ||
|
|
537912b0a6 | ||
|
|
4f474cbca2 | ||
|
|
fcd6fba660 | ||
|
|
a5323ef901 | ||
|
|
ed82dcc42c | ||
|
|
7cedd937fa | ||
|
|
c4424493cb | ||
|
|
20bd5eda8d | ||
|
|
0cdcef3372 | ||
|
|
615680fb1c | ||
|
|
284df654ea | ||
|
|
39a09109d0 | ||
|
|
01b6788646 | ||
|
|
fa28b69ce4 | ||
|
|
05648b7b8d | ||
|
|
bc0a3999d0 | ||
|
|
d10e4eed9f | ||
|
|
dc494a739c | ||
|
|
556b23fe12 | ||
|
|
f4911cb9ef | ||
|
|
2b700da903 | ||
|
|
93081e4492 | ||
|
|
78b358fea7 | ||
|
|
2aae0190b2 | ||
|
|
45ceb27293 | ||
|
|
fdeb370090 | ||
|
|
3db6d5129c | ||
|
|
8f813a8d8e | ||
|
|
587a06bcbb | ||
|
|
81867525a6 | ||
|
|
e7f7a273b1 | ||
|
|
944aeea5f8 | ||
|
|
f8f5cd4c71 | ||
|
|
1483cfbf5a | ||
|
|
b7819e3a26 | ||
|
|
8b9bb98fa7 | ||
|
|
92a724e09d | ||
|
|
714db005e9 | ||
|
|
525e7aa1cb | ||
|
|
ff4e8cf868 | ||
|
|
2a7b71a178 | ||
|
|
cb8042d5b0 | ||
|
|
db4b0315ae | ||
|
|
b72e374421 | ||
|
|
2b348a5a9f | ||
|
|
fe302763a1 | ||
|
|
f1fb6ff277 | ||
|
|
db0ce0872a | ||
|
|
86ceaf1b1e | ||
|
|
67d9dcfac7 | ||
|
|
d20c5369e5 | ||
|
|
c8e5d51517 | ||
|
|
81f0f13c9e | ||
|
|
81ec1edda8 | ||
|
|
99bd4a01a9 | ||
|
|
de2e896de8 | ||
|
|
52502d81a6 | ||
|
|
7dc8315f99 | ||
|
|
dbff6b764f | ||
|
|
bee43bffab | ||
|
|
cce6e637ee | ||
|
|
85b088aa76 | ||
|
|
b407fdfe16 | ||
|
|
d845213e8b | ||
|
|
dfea82942f | ||
|
|
e6c21aaa70 | ||
|
|
ceb5090614 | ||
|
|
67b07202b4 | ||
|
|
93abb65661 | ||
|
|
0a1dab897b | ||
|
|
7877a4d2ed | ||
|
|
7bc838d67a | ||
|
|
cafd406e89 | ||
|
|
882b5e546f | ||
|
|
41687a5e48 | ||
|
|
b3fdfc0d7b | ||
|
|
37282eaf81 | ||
|
|
6f5f8f56d4 | ||
|
|
1e4bd1c822 | ||
|
|
daa855fd0f | ||
|
|
84f44c6278 | ||
|
|
b56768dda5 | ||
|
|
6d9702870a | ||
|
|
d11c4b0b5a | ||
|
|
cde2f3a6fb | ||
|
|
3d2d0d8ca1 | ||
|
|
554ce05ba5 | ||
|
|
e7fde24712 | ||
|
|
9e37e529b9 | ||
|
|
bdaf0a9745 | ||
|
|
b1da39b72c | ||
|
|
c875d7d94f | ||
|
|
e39d9365d4 | ||
|
|
1402697e20 | ||
|
|
f2559ee56c | ||
|
|
0efd236bd5 | ||
|
|
55e0789b79 | ||
|
|
f8d8c7fd1a | ||
|
|
0b2c447d5d | ||
|
|
f4fefc7264 | ||
|
|
da6a472139 | ||
|
|
f087c0654d | ||
|
|
42a500fe08 | ||
|
|
d931161592 | ||
|
|
2dda6f2f4a | ||
|
|
831edacc8d | ||
|
|
59e8dd103a | ||
|
|
9d24c42f96 | ||
|
|
22f055ffd1 | ||
|
|
2151e61414 | ||
|
|
e9fe1e17e0 | ||
|
|
84bd26de20 | ||
|
|
cb6faf430d | ||
|
|
c1be0cb82d | ||
|
|
6b59bc6109 | ||
|
|
ddcf455dd3 | ||
|
|
8672d9f305 | ||
|
|
3b92292e19 | ||
|
|
91d96a4983 | ||
|
|
f17bc26987 | ||
|
|
12e0fa3c6b | ||
|
|
6bad9e7e27 | ||
|
|
81ceb3fb25 | ||
|
|
722aaf47fa | ||
|
|
d35b412a96 | ||
|
|
c1054a459d | ||
|
|
89dc220fda | ||
|
|
2423b97a0c | ||
|
|
afca3f5a4e | ||
|
|
cdd60b6150 | ||
|
|
6f40008742 | ||
|
|
8952cbf3af | ||
|
|
14c8223acc | ||
|
|
f2e86d9f0d | ||
|
|
17ab1e4675 | ||
|
|
acedfad749 | ||
|
|
6a0591086a | ||
|
|
96a30719ba | ||
|
|
6de42cbfd8 | ||
|
|
c670587788 | ||
|
|
62ce822082 | ||
|
|
5cd9b4b119 | ||
|
|
ff6887ba83 | ||
|
|
f817374347 | ||
|
|
f32d3e21ed | ||
|
|
3728aad465 | ||
|
|
be0a923587 | ||
|
|
69067bfc9f | ||
|
|
fa70f7f54b | ||
|
|
3a06ea6004 | ||
|
|
ccec103ebc | ||
|
|
3eb82d33b4 | ||
|
|
442c868b66 | ||
|
|
6b9c0d2e8c | ||
|
|
9f91ae1298 | ||
|
|
63efd66b78 | ||
|
|
5f7fd9c615 | ||
|
|
9353a4ec8e | ||
|
|
6c6c7dcaad | ||
|
|
2276b7372f | ||
|
|
da646a749c | ||
|
|
301c1e693b | ||
|
|
b44b946979 | ||
|
|
d01d8c702f | ||
|
|
4622c9a374 | ||
|
|
86e90c248b | ||
|
|
9dac516149 | ||
|
|
a502700ed0 | ||
|
|
5a7eb4d38f | ||
|
|
1982f978b1 | ||
|
|
b8ca07feca | ||
|
|
577681423a | ||
|
|
fdc1854acb | ||
|
|
89bbaf58c8 | ||
|
|
7ebedf9360 | ||
|
|
807e3fde58 | ||
|
|
412ee357cd | ||
|
|
e2df69c01b | ||
|
|
058c277359 | ||
|
|
9f6bf22b33 | ||
|
|
d5473a3233 | ||
|
|
76b21a607e | ||
|
|
1b9c9e4ed5 | ||
|
|
763adefcc2 | ||
|
|
dc811b61c0 | ||
|
|
f9cd8b2353 | ||
|
|
b81a2bdb72 | ||
|
|
db8ae1486e | ||
|
|
3abe06995c | ||
|
|
37d1443a2d | ||
|
|
501402bd71 | ||
|
|
6db6f02b66 | ||
|
|
aa27c7e07a | ||
|
|
44e969d284 | ||
|
|
6db4f0eebc | ||
|
|
3f4ee655b8 | ||
|
|
274d68b9e2 | ||
|
|
ba73453d6d | ||
|
|
15d1247b23 | ||
|
|
e41e5bceaf | ||
|
|
2748599ba2 | ||
|
|
e6e40d68be | ||
|
|
af3936f684 | ||
|
|
21e263c521 | ||
|
|
a7197d7f48 | ||
|
|
9f470e6a94 | ||
|
|
e491d932de | ||
|
|
567245d415 | ||
|
|
b4469c12ba | ||
|
|
895078118b | ||
|
|
a25d72b15e | ||
|
|
ebd2d35d4a | ||
|
|
e32ca8414a | ||
|
|
ef34928096 | ||
|
|
4376871a38 | ||
|
|
4ab5b277aa | ||
|
|
481913395f | ||
|
|
edc6cb6269 | ||
|
|
90b6f7660d | ||
|
|
2d43dd2f47 | ||
|
|
7c8b79f151 | ||
|
|
07222de4f8 | ||
|
|
44fe2fcbfe | ||
|
|
1c5ad13152 | ||
|
|
69eb7b3629 | ||
|
|
02c07c823e | ||
|
|
5829318c66 | ||
|
|
56e10300ae | ||
|
|
2f11e1e773 | ||
|
|
50a7479148 | ||
|
|
ca90d232ed | ||
|
|
d1d6c7a6ec | ||
|
|
c2ea589251 | ||
|
|
ef5d313e16 | ||
|
|
a1a5f13e3e | ||
|
|
4f0d1874cc | ||
|
|
c89e034ef4 | ||
|
|
b3910fa403 | ||
|
|
d84db61262 | ||
|
|
cf0f2b57db | ||
|
|
2005611f2b | ||
|
|
115a104457 | ||
|
|
0397d5e6c1 | ||
|
|
2b9e54f128 | ||
|
|
455d20a554 | ||
|
|
a242ab5263 | ||
|
|
ecb4ad24e6 | ||
|
|
6cdace69b0 | ||
|
|
a9d7694dc9 | ||
|
|
a49f6f617c | ||
|
|
5b15a1272b | ||
|
|
e5fa60bb2f | ||
|
|
22a8651f06 | ||
|
|
4a3ab5cd7d | ||
|
|
2c84504c6a | ||
|
|
8ebaef6276 | ||
|
|
5202861d6e | ||
|
|
e48c7c2272 | ||
|
|
995e4ed4c4 | ||
|
|
ed512eae71 | ||
|
|
f8d011e615 | ||
|
|
d60cd4303e | ||
|
|
1757df0a5e | ||
|
|
5dd8d3a78b | ||
|
|
e8eb0dd789 | ||
|
|
d1fd6d2b75 | ||
|
|
9059b22970 | ||
|
|
d3c27ee04d | ||
|
|
a7cefee47d | ||
|
|
b394221990 | ||
|
|
65a850fbf1 | ||
|
|
6c0f79c53e | ||
|
|
7358262243 | ||
|
|
2bb8640279 | ||
|
|
92ae0b4786 | ||
|
|
fb9bc415a7 | ||
|
|
32f0109e8d | ||
|
|
843180a5b2 | ||
|
|
6010639c35 | ||
|
|
c9b8e27e4c | ||
|
|
193a199648 | ||
|
|
56cb7a8c15 | ||
|
|
3a6111c6ec | ||
|
|
0d360a0160 | ||
|
|
eb8c1d359a | ||
|
|
20fdb362dc | ||
|
|
9bac0fcf2e | ||
|
|
efd52b8020 | ||
|
|
95b55c42d1 | ||
|
|
8e34522b24 | ||
|
|
0956fd6324 | ||
|
|
5d39c65d0e | ||
|
|
8e10f118cf | ||
|
|
17dd1ccb96 | ||
|
|
c981753b57 | ||
|
|
b4e464a9fe | ||
|
|
3d79830e33 | ||
|
|
6cd3fa2343 | ||
|
|
ada8f69e18 | ||
|
|
b3dc811fc7 | ||
|
|
2ad9f418ca | ||
|
|
0dcd68f83b | ||
|
|
8f6578386f | ||
|
|
84bb98f7e2 | ||
|
|
4b4ad2bed0 | ||
|
|
7e79000fd9 | ||
|
|
1f89ed90d2 | ||
|
|
d07078d2b2 | ||
|
|
36b35d06d7 | ||
|
|
1c4bd145d9 | ||
|
|
cd51d7d9ca | ||
|
|
eb1609258a | ||
|
|
f186368ee0 | ||
|
|
c9def75ed8 | ||
|
|
3c7fb872f6 | ||
|
|
d84359c52f | ||
|
|
901c8a7918 | ||
|
|
f04b247dcb | ||
|
|
1a9b24af68 | ||
|
|
a9385412e0 | ||
|
|
d795a317a6 | ||
|
|
90e759af65 | ||
|
|
b6beb0b3c6 | ||
|
|
3fcdaff8d0 | ||
|
|
100db2f4fd | ||
|
|
d31e3bc1a0 | ||
|
|
e935cfcf91 | ||
|
|
5e81ffb130 | ||
|
|
594923638a | ||
|
|
6be2e1bbff | ||
|
|
6cad5a86c4 | ||
|
|
478be8d74a | ||
|
|
46834e5234 | ||
|
|
0f19f70821 | ||
|
|
231b8d6da7 | ||
|
|
c218841c75 | ||
|
|
e6bb5e7372 | ||
|
|
75d694ddb2 | ||
|
|
8a0a09bc03 | ||
|
|
415cb18fdd | ||
|
|
7e8f316eb5 | ||
|
|
f6907efcdd | ||
|
|
9106c55e1e | ||
|
|
2e7f91fa46 | ||
|
|
b26a549ade | ||
|
|
44f269945c | ||
|
|
6087348f56 | ||
|
|
f179f5c632 | ||
|
|
bc801c9c79 |
No files matched your search
@@ -0,0 +1,68 @@
|
||||
name: Automatic Release Version
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: [CI]
|
||||
types: [completed]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
actions: write
|
||||
|
||||
concurrency:
|
||||
group: kryon-auto-release
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
bump-and-release:
|
||||
if: >-
|
||||
github.event.workflow_run.conclusion == 'success' &&
|
||||
github.event.workflow_run.event == 'push' &&
|
||||
github.event.workflow_run.head_branch == 'master'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
ref: ${{ github.event.workflow_run.head_sha }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Skip an already released commit
|
||||
id: guard
|
||||
run: |
|
||||
if git tag --points-at HEAD --list 'v*' | grep -q .; then
|
||||
echo 'release=false' >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo 'release=true' >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Resolve next version
|
||||
if: steps.guard.outputs.release == 'true'
|
||||
id: version
|
||||
run: |
|
||||
current=$(make -s version)
|
||||
if git rev-parse -q --verify "refs/tags/$current" >/dev/null; then
|
||||
version=$(scripts/bump-version.sh patch)
|
||||
else
|
||||
version=$current
|
||||
fi
|
||||
echo "tag=$version" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Commit version
|
||||
if: steps.guard.outputs.release == 'true'
|
||||
run: |
|
||||
git config user.name 'github-actions[bot]'
|
||||
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
||||
git add include/kryon_version.h
|
||||
if ! git diff --cached --quiet; then
|
||||
git commit -m "release: bump version to ${{ steps.version.outputs.tag }}"
|
||||
git push origin HEAD:master
|
||||
fi
|
||||
|
||||
- name: Start release workflow
|
||||
if: steps.guard.outputs.release == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: >-
|
||||
gh workflow run release.yml --ref master
|
||||
-f version=${{ steps.version.outputs.tag }}
|
||||
-f prerelease=false
|
||||
@@ -0,0 +1,85 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
# Cancel a superseded run on the same ref.
|
||||
concurrency:
|
||||
group: ci-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test-linux:
|
||||
name: Build and test (Linux)
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Install Packages
|
||||
run: |
|
||||
set -euo pipefail
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake libssl-dev pkg-config \
|
||||
zlib1g-dev libzstd-dev libbrotli-dev \
|
||||
libglib2.0-dev libgtk-3-dev \
|
||||
libsdl2-dev libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make clean CMAKE=/usr/bin/cmake
|
||||
make all CMAKE=/usr/bin/cmake
|
||||
|
||||
- name: Test
|
||||
run: make test CMAKE=/usr/bin/cmake
|
||||
|
||||
- name: Text input latency gate
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make perf-text-input CMAKE=/usr/bin/cmake | grep '^{' | tee text-input-perf.jsonl
|
||||
cat text-input-perf.jsonl >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
- name: Upload text input measurements
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: text-input-perf-linux
|
||||
path: text-input-perf.jsonl
|
||||
if-no-files-found: error
|
||||
|
||||
test-freebsd:
|
||||
name: Build and test (FreeBSD)
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Build and test on FreeBSD VM
|
||||
uses: vmactions/freebsd-vm@v1
|
||||
with:
|
||||
usesh: true
|
||||
mem: 4096
|
||||
prepare: |
|
||||
set -eu
|
||||
pkg install -y gmake cmake pkgconf \
|
||||
sdl2 libdrm mesa-libs gtk3 \
|
||||
curl openssl zstd brotli \
|
||||
git go
|
||||
run: |
|
||||
set -eu
|
||||
gmake clean
|
||||
gmake all
|
||||
gmake test
|
||||
if ! gmake perf-text-input; then
|
||||
echo "FreeBSD text-input measurements are non-gating during calibration" >&2
|
||||
fi
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
@@ -43,15 +43,21 @@ jobs:
|
||||
- name: Build Site
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make docs-site CMAKE=/usr/bin/cmake
|
||||
make docs-site CMAKE=/usr/bin/cmake SITE_BUILD_DIR=build/site
|
||||
test -f build/site/index.html
|
||||
test -f build/site/api.html
|
||||
test -f build/site/ide.html
|
||||
test -f build/site/ide.js
|
||||
test -f build/site/ide-tools/k2ir.js
|
||||
test -f build/site/ide-tools/k2ir.wasm
|
||||
test -f build/site/ide-tools/k2b.js
|
||||
test -f build/site/ide-tools/k2b.wasm
|
||||
test -f build/site/icons/kryon.png
|
||||
test -f build/site/icons/c.png
|
||||
test ! -f build/site/API.md
|
||||
|
||||
- name: Upload Site Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: kryon-site
|
||||
path: build/site
|
||||
@@ -81,6 +87,7 @@ jobs:
|
||||
test -n "$auth_token" || { echo "::error::NETLIFY_AUTH_TOKEN is empty or missing"; exit 1; }
|
||||
test -n "$site_id" || { echo "::error::NETLIFY_SITE_ID is empty or missing; use the Netlify Site ID, not the site URL"; exit 1; }
|
||||
netlify deploy \
|
||||
--no-build \
|
||||
--dir build/site \
|
||||
--alias "pr-${{ github.event.pull_request.number }}" \
|
||||
--message "Preview ${{ github.event.pull_request.number }}" \
|
||||
@@ -114,6 +121,7 @@ jobs:
|
||||
test -n "$auth_token" || { echo "::error::NETLIFY_AUTH_TOKEN is empty or missing"; exit 1; }
|
||||
test -n "$site_id" || { echo "::error::NETLIFY_SITE_ID is empty or missing; use the Netlify Site ID, not the site URL"; exit 1; }
|
||||
netlify deploy \
|
||||
--no-build \
|
||||
--dir build/site \
|
||||
--prod \
|
||||
--message "Production ${{ github.sha }}" \
|
||||
|
||||
@@ -33,7 +33,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
@@ -51,6 +51,11 @@ jobs:
|
||||
v[0-9]*.[0-9]*.[0-9]*) ;;
|
||||
*) echo "Version must look like v0.1.0" >&2; exit 1 ;;
|
||||
esac
|
||||
header_tag="$(sed -n 's/^#define KRYON_VERSION_STRING "\([^"]*\)".*/\1/p' include/kryon_version.h)"
|
||||
if [ "$tag" != "$header_tag" ]; then
|
||||
echo "Requested $tag but include/kryon_version.h contains $header_tag" >&2
|
||||
exit 1
|
||||
fi
|
||||
if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
|
||||
echo "Tag $tag already exists; nothing to release."
|
||||
echo "tag=" >> "$GITHUB_OUTPUT"
|
||||
@@ -130,7 +135,7 @@ jobs:
|
||||
echo "tag=$tag" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
ref: ${{ steps.ref.outputs.tag }}
|
||||
submodules: recursive
|
||||
@@ -140,7 +145,7 @@ jobs:
|
||||
run: |
|
||||
set -euo pipefail
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake libssl-dev pkg-config zlib1g-dev libzstd-dev libbrotli-dev libsdl2-dev libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev
|
||||
sudo apt-get install -y build-essential cmake libssl-dev pkg-config zlib1g-dev libzstd-dev libbrotli-dev libglib2.0-dev libgtk-3-dev libsdl2-dev libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev
|
||||
|
||||
- name: Build And Test
|
||||
run: |
|
||||
@@ -158,17 +163,40 @@ jobs:
|
||||
test -n "$archive"
|
||||
echo "KRYON_STATIC_ARCHIVE=$archive" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Package Every Kryon Tool
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make dist-tools CMAKE=/usr/bin/cmake VERSION="${{ steps.ref.outputs.tag }}"
|
||||
make check-tools-package CMAKE=/usr/bin/cmake VERSION="${{ steps.ref.outputs.tag }}"
|
||||
archive="$(find dist -maxdepth 1 -type f -name 'kryon-*-tools-*.tar.gz' | head -n 1)"
|
||||
test -n "$archive"
|
||||
echo "KRYON_TOOLS_ARCHIVE=$archive" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Write Checksums
|
||||
run: |
|
||||
sha256sum "$KRYON_STATIC_ARCHIVE" "$KRYON_TOOLS_ARCHIVE" > SHA256SUMS
|
||||
|
||||
- name: Upload Static Library Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: kryon-static-library-${{ steps.ref.outputs.tag }}
|
||||
path: ${{ env.KRYON_STATIC_ARCHIVE }}
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Upload Tools Artifact
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: kryon-tools-${{ steps.ref.outputs.tag }}
|
||||
path: ${{ env.KRYON_TOOLS_ARCHIVE }}
|
||||
if-no-files-found: error
|
||||
|
||||
- name: Publish GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
tag_name: ${{ steps.ref.outputs.tag }}
|
||||
name: Kryon ${{ steps.ref.outputs.tag }}
|
||||
prerelease: ${{ github.event_name == 'workflow_dispatch' && inputs.prerelease || false }}
|
||||
files: ${{ env.KRYON_STATIC_ARCHIVE }}
|
||||
files: |
|
||||
${{ env.KRYON_STATIC_ARCHIVE }}
|
||||
${{ env.KRYON_TOOLS_ARCHIVE }}
|
||||
SHA256SUMS
|
||||
@@ -0,0 +1,110 @@
|
||||
name: renderers
|
||||
|
||||
# Build downloadable KRB renderers for every platform: the headless
|
||||
# renderer (krb-run) as native binaries, and the web player (krb-web)
|
||||
# as static files any site can host.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
tags: ["v*"]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
native:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { os: ubuntu-latest, cc: cc, suffix: linux-x86_64, build_dir: build/linux-x86_64 }
|
||||
- { os: ubuntu-latest, cc: x86_64-w64-mingw32-gcc, suffix: windows-x86_64, build_dir: build/linux-x86_64 }
|
||||
- { os: macos-latest, cc: /usr/bin/clang, suffix: macos-arm64, build_dir: build/macos-arm64 }
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install mingw (windows cross)
|
||||
if: matrix.suffix == 'windows-x86_64'
|
||||
run: sudo apt-get update && sudo apt-get install -y mingw-w64
|
||||
- name: Install GNU make (macOS)
|
||||
if: runner.os == 'macOS'
|
||||
run: brew install make
|
||||
- name: Build krb-run
|
||||
run: |
|
||||
target="${{ matrix.build_dir }}/bin/krb-run"
|
||||
if [ "${{ runner.os }}" = macOS ]; then
|
||||
env -u MAKE -u MAKEFLAGS -u MFLAGS -u MAKEFILES \
|
||||
CC=${{ matrix.cc }} /opt/homebrew/bin/gmake -e -f ./Makefile "$target" \
|
||||
KRY_SW_SRCS="src/krb/krb.c src/backend/kry_backend.c src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend_rec.c"
|
||||
else
|
||||
make "$target" CC=${{ matrix.cc }} \
|
||||
KRY_SW_SRCS="src/krb/krb.c src/backend/kry_backend.c src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend_rec.c"
|
||||
fi
|
||||
[ "${{ matrix.suffix }}" = windows-x86_64 ] && target="$target.exe"
|
||||
cp "$target" build/krb-run
|
||||
- name: Rename
|
||||
run: cp build/krb-run krb-run-${{ matrix.suffix }}${{ matrix.suffix == 'windows-x86_64' && '.exe' || '' }}
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: krb-run-${{ matrix.suffix }}
|
||||
path: krb-run-${{ matrix.suffix }}*
|
||||
|
||||
web:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: mymindstorm/setup-emsdk@v14
|
||||
with:
|
||||
version: latest
|
||||
- name: Build web player
|
||||
run: make krb-web
|
||||
- name: Package
|
||||
run: |
|
||||
mkdir -p krb-player-web && cp build/linux-x86_64/web/krb-web/* krb-player-web/
|
||||
cp examples/02_buttons.kry /tmp/ 2>/dev/null || true
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: krb-player-web
|
||||
path: krb-player-web/
|
||||
|
||||
exactness:
|
||||
# Cross-engine byte-exactness needs no GL (SDL dummy + software).
|
||||
# The native pixel-compare vs the inbe C build additionally needs a
|
||||
# working screenshot pipeline: xvfb-run, as inbe's own CI does.
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Build tools
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libsdl2-dev
|
||||
make build/linux-x86_64/bin/k2b build/linux-x86_64/bin/krb-run build/linux-x86_64/bin/krb-sdl build/linux-x86_64/tests/krb_logic_test build/linux-x86_64/tests/krb_asset_test KRY_SW_SRCS="src/krb/krb.c src/backend/kry_backend.c src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend_rec.c"
|
||||
- name: Cross-engine exactness
|
||||
run: sh tests/krb_exact_test.sh .
|
||||
- name: Unit tests
|
||||
run: |
|
||||
build/linux-x86_64/tests/krb_logic_test
|
||||
build/linux-x86_64/tests/krb_asset_test
|
||||
# Native gate: once inbe CI checks out kryon master as its vendor,
|
||||
# run tests/krb_exact_native_test.sh per ported screen under xvfb:
|
||||
# xvfb-run -a ./inbe --screenshot native.png --screenshot-scene language ...
|
||||
|
||||
release:
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
needs: [native, web]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
- run: |
|
||||
mkdir rel && cp -r krb-run-* krb-player-web rel/
|
||||
- uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
files: rel/*
|
||||
@@ -5,6 +5,7 @@
|
||||
*~
|
||||
*.tmp
|
||||
.zcode
|
||||
.kryon-ide-state
|
||||
|
||||
# Build output
|
||||
build/
|
||||
|
||||
@@ -13,3 +13,6 @@
|
||||
[submodule "vendor/clay"]
|
||||
path = vendor/clay
|
||||
url = https://github.com/nicbarker/clay.git
|
||||
[submodule "vendor/box2d"]
|
||||
path = vendor/box2d
|
||||
url = https://github.com/erincatto/box2d.git
|
||||
@@ -1,4 +1,4 @@
|
||||
# Native make shim. The canonical build is the GNU Makefile.
|
||||
# Native BSD make shim. The canonical build is the GNU Makefile.
|
||||
GMAKE ?= gmake
|
||||
|
||||
.MAIN: all
|
||||
+593
-4
@@ -1,4 +1,593 @@
|
||||
# Changelog
|
||||
## v0.1.16 - 2026-08-18
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.16
|
||||
- Ci: include kry_sw_png in the renderer KRY_SW_SRCS overrides
|
||||
- Build: link kry_sw_png into the KRB logic and asset tests
|
||||
- Build: link kry_sw_png into the KRB logic and asset tests
|
||||
- Tray+notify: SetDesktopTrayIcon emblem swap, action-capable notifications
|
||||
- Kry_sw: decode PNG assets for texture draws
|
||||
- Ui: build and test the secondary window paths
|
||||
|
||||
## v0.1.15 - 2026-08-18
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.15
|
||||
- Ci: run workflow actions on Node 24 runtimes
|
||||
|
||||
## v0.1.14 - 2026-08-18
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.14
|
||||
- Ui: make retained frames work without a render context
|
||||
- Test: trace and stress retained text input
|
||||
- Ui: select all text on double click
|
||||
- Test: cover click then tab field traversal
|
||||
- Correct secondary window texture orientation
|
||||
- Ui: route retained focus traversal
|
||||
- Build: always index static runtime archives
|
||||
- Runtime: enforce one app instance by default
|
||||
- Synchronize shared secondary window textures
|
||||
- Runtime: pace event-driven UI frames
|
||||
- Kryui: window flags and min size on the k2g AppConfig
|
||||
- Present secondary window textures without readback
|
||||
- Ui: keep font atlases immutable while typing
|
||||
- K2g: host bridge, enums, switch and full for headers
|
||||
- Render SDL secondary windows with shared GL contexts
|
||||
- Disable unsafe Linux secondary SDL windows
|
||||
|
||||
## v0.1.13 - 2026-08-18
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.13
|
||||
- Web: build the current KRB compiler sources
|
||||
- Build: avoid case-colliding makefiles
|
||||
- Ci: invoke Homebrew GNU make directly
|
||||
- Ci: pin the macOS renderer compiler
|
||||
- Ci: ignore macOS make compatibility preload
|
||||
- Ci: reset inherited make flags on macOS
|
||||
- Web: link shared KIR parser into IDE tools
|
||||
- Ci: prevent recursive macOS renderer build
|
||||
- Ci: install renderer toolchain dependencies
|
||||
- Ci: build renderer targets from complete checkouts
|
||||
- Ui: enforce cross-lowering text input latency
|
||||
- Avoid fixed buffer when canonicalizing tray icon path
|
||||
- Pass absolute icon path to AppIndicator
|
||||
- Resolve tray icon theme path for GNOME
|
||||
- Ui: complete retained text editing actions
|
||||
- Revert "Fix C-style local declarations in k2c"
|
||||
- Test: cover legacy k2c declarations
|
||||
- Ui: retain mouse and keyboard text selection
|
||||
- Fix C-style local declarations in k2c
|
||||
- Ui: rebuild font atlases only between frames
|
||||
- Add SDL auxiliary windows for Wayland
|
||||
- K2c: preserve anonymous enum declarations
|
||||
|
||||
## v0.1.12 - 2026-08-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Fix AppIndicator icon lookup on Wayland
|
||||
- Ui: retain selected font for deferred text
|
||||
- Release: bump version to v0.1.12
|
||||
- Go: expose retained declarative UI
|
||||
- Ui: add retained declarative tree and typed events
|
||||
|
||||
## v0.1.11 - 2026-08-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.11
|
||||
- Ui: make text rendering event efficient
|
||||
|
||||
## v0.1.10 - 2026-08-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.10
|
||||
- Ui: add fixed-subset font sources
|
||||
|
||||
## v0.1.9 - 2026-08-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Ui: copy font type string in RegisterUIFontSource
|
||||
- Ui: raise font raster tier cache from 4 to 8 slots
|
||||
- Ui: sample system theme from CSS before initializing GTK in-process
|
||||
- Release: bump version to v0.1.9
|
||||
- Build: log missing SDL2 DPI query once instead of every frame
|
||||
|
||||
### Fixed
|
||||
|
||||
- Text entry stays responsive when an app mixes its regular UI font with emoji or icon fonts, even when the fallback is registered first.
|
||||
- Typing and redrawing text no longer repeatedly scans the full font atlas for every glyph.
|
||||
- UI text uses exact-size font rasters, and idle windows can sleep until the next input event.
|
||||
|
||||
## v0.1.8 - 2026-08-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Release: bump version to v0.1.8
|
||||
- Ci: install Go on FreeBSD
|
||||
- Build: link FreeBSD curl codec dependencies
|
||||
- Go: add reusable grid cell editor
|
||||
- Build: search FreeBSD ports libraries
|
||||
- Test: build capability cartridge fixture
|
||||
- Ci: install GTK for Go binding smoke tests
|
||||
- Build: apply GIO notification include flags
|
||||
- Ui: finalize deferred overlays at frame end
|
||||
- Ci: install and link GIO notifications
|
||||
- Release: automate versions and publish all tools
|
||||
- Go: support arm64 native linking
|
||||
- Ui: persist line selection and expose pictures
|
||||
- Go: expose theme style selection
|
||||
- Ui: add scroll-safe multiline text selection
|
||||
- Ui: use neutral colors for tables
|
||||
- Go: add secure password fields
|
||||
- Go: expose text area focus state
|
||||
- Go: expose tab key compatibility constant
|
||||
- Go: complete raylib drawing compatibility helpers
|
||||
- Go: expose toolkit collection and dialog widgets
|
||||
- Go: expose window focus activation
|
||||
- Go: pin text editor state across cgo calls
|
||||
- Go: add native runtime and stateful controls
|
||||
- Go: own the kryui runtime bindings
|
||||
- K2ir: strip block comments while reading lines
|
||||
- Krb caps: reference host backends — storage, audio
|
||||
- Krb: plan-08 capability registry
|
||||
- KrbAutoMount: state initializers render without a host
|
||||
- Examples: profile and habit-edit screens — 11 cartridge screens
|
||||
- Kir_parse: skip plain # comments in TOP mode
|
||||
- Examples: statistics screen cartridge
|
||||
- Native exactness gate: PASSES for the language screen
|
||||
- Dropdown: measured native shape — rounded fill+border r3, diamond indicator
|
||||
- Language screen: truncating advances + native dropdown shape — structural 1530 -> 241
|
||||
- Native exactness comparator: AA-only vs structural classification
|
||||
- Atlas: sub-pixel advances; language cartridge from traced values
|
||||
- Atlas: raylib's ascent-shifted glyph offsets + per-mille UI scale
|
||||
- K2b atlas: fix GetCodepointBitmapBox extents; tier collection and UI-scale plumbing
|
||||
- Kry_sw: ui_text.c advance rounding; krb-sdl: deterministic single-frame dump
|
||||
- K2b atlas: raylib-identical glyph rasterization
|
||||
- Language cartridge: matched to the native reference frame
|
||||
- Screenshots: working native capture — pre-swap read + self-written PNG
|
||||
- Tests: arm the pre-swap capture in the native harness
|
||||
- Screenshots: ES2-safe capture — armed EndDrawing reads pre-swap
|
||||
- Tests: harden the xwd-path kill (TERM, then KILL)
|
||||
- LoadImageFromScreen: front-end override reading the front buffer
|
||||
- Tests: xwd-based native capture for software GL
|
||||
- K2c: initializer items take no inspect wrapper
|
||||
- K2c: multi-line array initializers
|
||||
- Tests: native exactness runs the app from the repo root
|
||||
- K2g: .kry -> Go backend on the shared Kir frontend
|
||||
- Krb v2: animated geometry — WHM session screen runs live in-cartridge
|
||||
- Examples: practice config screen cartridge (sliders, spinboxes)
|
||||
- Examples: habits screen cartridge (bound streak counters)
|
||||
- Krb v2: screen navigation — the whole app in one cartridge
|
||||
- Examples: manual screen cartridge (scrolling guide + breath circle)
|
||||
- Ci: exactness job — cross-engine byte-identity + krb unit tests
|
||||
- Examples: settings screen cartridge (scroll + dropdowns + checkboxes)
|
||||
- TakeScreenshot: use absolute paths as-is
|
||||
- Tests: native-comparison exactness harness (stage 2)
|
||||
- Tests: cross-engine screenshot-exactness harness
|
||||
- K2b: fix guard single-term parsing, positional ButtonProps, dropdown height
|
||||
- K2b: arithmetic expressions in guard conditions
|
||||
- Krb v2: dropdown controls
|
||||
- Krb v2: text input — TEXTINPUT node + typed-codepoint vtable path
|
||||
- Krb v2: scroll containers
|
||||
- K2b+engines: KFA1 glyph atlas — antialiased Noto text in cartridges
|
||||
- K2b: else branches and state-vs-state guard comparisons
|
||||
- K2b: decode png/jpg/bmp/webp and embed as cartridge pixels
|
||||
- Style tokens: fixed-pixel corner radii, not size fractions
|
||||
- Renderers: web player opens any .krb + CI builds per-platform downloads
|
||||
- K2b: embed referenced assets into the cartridge
|
||||
- Krb v2: embedded asset section + texture_rgba blit
|
||||
- Material style: subtle control rounding instead of full pills
|
||||
- K2b: compile .kry state updates and if-guards into v2 VM programs
|
||||
- Scene_inspect: set SO_REUSEADDR so quick restarts rebind
|
||||
- Kry_json: expose kry_json_type
|
||||
- Docs: KRB_FORMAT.md rewritten as an exact byte-level specification
|
||||
- Scene: live JSON inspection server
|
||||
- Krb v2: in-cartridge logic VM + circle/ring geometry nodes
|
||||
- Scene/property/signal/transform: drop the Kry/Kryon prefix from the public API
|
||||
- Scene: recycle removed node slots through a freelist
|
||||
- Test: host default style follows the MATERIAL default
|
||||
- Scene: application-defined node kinds with property callbacks
|
||||
- Krb-sdl: SDL2 desktop host for KRB cartridges
|
||||
- K2c: fix one-line control blocks, char literals, and locals named c
|
||||
- Krb-web: native web engine — kry_sw compiled to wasm, blitted to ImageData
|
||||
- System_theme web: snprintf not app copy_text
|
||||
- System_theme: web prefers-color-scheme detection; default source SYSTEM on web
|
||||
- Krb: kry_sw software rasterizer engine + headless conformance harness
|
||||
- Kir: 'c:' is a typed decl, not the raw-C 'c' keyword
|
||||
- Desktop_tray: drop GTK type-cast macros - they expand to gtk_*_get_type() calls the dlopen shim does not forward
|
||||
- Ksync: harden crypto, exports, JSON, delete, and sync transport
|
||||
- K2c: fix braced and bare-default switch cases
|
||||
- Kryon-app.sh: project.kryon target runner with default_target support
|
||||
- Ui_text: per-size raster tier cache (4 tiers) instead of single base raster
|
||||
- Docs: plan 11 — renderer engines for KRB cartridges
|
||||
- K2c: join multi-line initializers on '::' global declarations
|
||||
- Theme: default to MATERIAL on all platforms for now
|
||||
- System_theme: read the GTK palette straight from the theme's gtk.css when the process has no GTK
|
||||
- Theme: platform default source/mode helpers (system theme on desktop)
|
||||
- Ui_window: WIP center flag, drag/right-click/click-position queries, X11 move hook
|
||||
- Mem: diagnostics; ui_text: single-tier font rasters; tray: lazy GTK
|
||||
- K2b: report call kinds the KRB vocabulary cannot express
|
||||
- Site: add Discord and Telegram community links
|
||||
- Widgets: PickerDialog; Spinbox value text + wrap; public ButtonRow height
|
||||
- Ui_window: Windows/macOS compile the no-op stubs
|
||||
- Guide overlay: Android back key closes the guide
|
||||
- Kry_term: drop downstream tool name from the feed comment (boundary check)
|
||||
- Kry_term: KryTermFeedOutput - harness text printed into the terminal
|
||||
- Kry_http: streaming partial reads (kry_http_partial) + locked write callback
|
||||
- Ui_window: include stddef.h so the android/web stubs see NULL
|
||||
- Kry_sfs: the live engine as a synthetic file system + real input injection
|
||||
- Ui_window: extra OS windows rendered with the regular UI widgets
|
||||
- Kt: drop the 'target ide' fork of krait
|
||||
- Kryon owns the transport, not the vendor: drop kry_zai
|
||||
- Notification/android: declare GetAndroidApp
|
||||
- K2c: emit '#define' constants in the generated header
|
||||
- Kry_http: no-curl stub signature must match the header (const mismatch broke PLATFORM_WEB)
|
||||
- Web present shim: take the GL context before hiding the canvas (display:none canvases cannot create contexts in some engines)
|
||||
- Kry std: kry_json, kry_http, kry_zai — the AI-harness foundation
|
||||
- Web present shim: ?kryonpresent=debug forces activation and reports state via document.title
|
||||
- Web: kryon-web-present.js — 2D-canvas present mode for WebKitGTK+software GL
|
||||
- Add cross-platform notification helpers
|
||||
- Kc is fully gone: CHANGELOG/docs/comments now say k2c
|
||||
- Theme_picker: switch width matches the retro toggle's content minimum
|
||||
- Ui_dpi: web viewport is already CSS pixels — don't reapply devicePixelRatio
|
||||
- Kir joiner: adjacent string literals on continuation lines join
|
||||
- Kir joiner: '} #else_if COND {' region chains complete as statements
|
||||
- Kry_signal.h: last kc comment says k2c
|
||||
- Remove the last kc remnants
|
||||
- K2c: #private functions are file-static with forward prototypes
|
||||
- K2c: resolve bare function references passed as call arguments ('set_cb(name)' / 'f(a, name)'), and grow LOWER_TEXT_MAX with KIR_TEXT_MAX so long initializers stop truncating mid-identifier.
|
||||
- K2c: guard statements, array params, alias-call stem matching, init rewrites
|
||||
- Kir joiner + k2c name-resolution fixes
|
||||
- Kir joiner: three continuation bugs
|
||||
- Kir: compute the body '#if' kind once — parse_cond_start strips the trailing '{' in place, so the second parse in the emission branch saw no brace and every body '#if' lowered to '#elif'.
|
||||
- Kir+k2c: '#if' regions lower to C preprocessor conditionals
|
||||
- Tests: default tool paths to the canonical per-platform bin dir
|
||||
- K2c: array-typed parameters emit C syntax ('T name[N]')
|
||||
- Kir: parse K&R '} else {' as close + else re-open
|
||||
- Vendor.mk: fix K2C path export (make ate the sed $ anchors)
|
||||
- Remove legacy build/bin tool aliases; export canonical K2C for consumers
|
||||
- Kir: the '#if' region skip runs before import capture
|
||||
- Kir+k2c: top-level 'static name: T = init' globals; skip captures in unevaluated '#if MACRO {' blocks
|
||||
- Kir+k2c: capture the 'args' header directive; C-style params pass through
|
||||
- Kir+k2c: '#private' imports include in the .c only
|
||||
- Kir: ':=' classifies as DECL before the raw-'c' escape hatch
|
||||
- Kir+k2c: named enums ('Name :: enum { ... }' -> typedef enum)
|
||||
- K2c: angled includes stay angled; extension-less header imports append .h
|
||||
- K2c_project: drop IDE name from comment (boundary rule)
|
||||
- K2c: emit kryon_project.h/.c (app-host ABI) + main() from Kir
|
||||
- K2b: migrate to the shared Kir frontend — one frontend, two backends
|
||||
- K2c: #global variables have external linkage; header order typedefs->enums->globals->structs
|
||||
- K2c: colon functions keep their bare C names; bare-ref resolution only in assignment-RHS
|
||||
- K2c: don't rewrite member-access calls (x->fn(...) / x.fn(...))
|
||||
- K2c: krait's full IDE corpus compiles — all 8 generated files, zero errors
|
||||
- K2c: emit #extern prototypes with alias-stripped args
|
||||
- Kir+k2c: typedefs with names, enum commas, type emission order, ternary/&& joins
|
||||
- Kir+k2c: '#type' typedefs; angle-bracket includes don't join
|
||||
- Kir: enum constants joined by comma-continuation close their enum
|
||||
- Kir: fix duplicate anonymous enum (use int for enum_return)
|
||||
- Kir: pointer types don't continue lines; #enum nests inside structs
|
||||
- Kir+k2c: join operator continuations; alias-strip array sizes
|
||||
- K2c: cross-module call resolution via a whole-program symbol table
|
||||
- Kir: '#'-directive lines are header lines (never join their braces)
|
||||
- Kir: join multi-line compound literals (expression braces)
|
||||
- K2c: resolve module-local function calls to their full C names
|
||||
- Kir+k2c: fix UB alias-strip (src==dst snprintf), emit #enum blocks
|
||||
- Kir+k2c: struct fields converted to C declarators; '#' comments skipped in bodies
|
||||
- Kir+k2c: fix block-brace depth tracking + alias rewrite in body statements
|
||||
- Kir+k2c: struct types (Name :: struct), return types stop at '{'
|
||||
- K2c: emit #include for module imports (alias :: #import "path" -> #include "path.h")
|
||||
- Kir+k2c: return types, #extern prototypes, #global vars, module prefixes, alias stripping
|
||||
- K2c: Kir is the only pipeline — delete the entire legacy compiler
|
||||
- K2c --kir: PushUIInspectSource wrapping for call statements + ui_inspect.h include
|
||||
- K2c: Kir→C lowering skeleton (--kir flag, structurally valid output)
|
||||
- Extract Kir parser into shared kir_parse.c (prerequisite for k2c/k2b backends)
|
||||
- K2ir: parse app{} metadata (title/size/fps/theme/frame/init/scene/shutdown)
|
||||
- K2ir: multi-line statement joining (paren/bracket/string depth tracking)
|
||||
- K2ir: classify mutations (count++) as EXPR not UNKNOWN
|
||||
- Rename kc to k2c (kry-to-C compiler)
|
||||
- Archive libkryon.a under the platform-tagged build dir
|
||||
- Improve site text readability
|
||||
- Add Kryon browser IDE
|
||||
- Improve Kryon site button contrast
|
||||
- Fix CI links and platform icons
|
||||
- Guard KryScenePhysicsDestroy call so physics-off builds link
|
||||
- Teach k2ir about imports and externs
|
||||
- Add k2ir tool scaffold
|
||||
- Add initial KIR core
|
||||
- Document KIR compiler roadmap
|
||||
- Fix per-codepoint font fallback switching typefaces for covered glyphs
|
||||
- K2b: standalone .kry->.krb compiler, fully independent of kc
|
||||
- Krb: controls[] section + range widgets (Slider, VerticalSlider, Spinbox)
|
||||
- Krb: interactive Checkbox + Toggle widgets (value-bound, self-contained toggle)
|
||||
- Krb compiler: widen widget coverage (color literals, Line/Separator/Bevel/TextInRect, Picture)
|
||||
- Kc: parse top-level 'frame NAME {}' as a hook function definition
|
||||
- Scene_property.h: refer to "an IDE inspector" instead of naming Krait
|
||||
- Build: make 2D physics (Box2D) optional via KRYON_WITH_PHYSICS
|
||||
- Kryon.h: expose embedded_assets.h through the umbrella
|
||||
- Krb: drop unused GROUP node and export enums for a clean v1
|
||||
- Krb: implement F32 field read/write and float text formatting
|
||||
- Expose kry_term and krb in kryon.h; document the cartridge API
|
||||
- Add krb cartridge tests
|
||||
- Kryon-preview: render .kry/.krb to PNG via a cartridge subcommand
|
||||
- Kc: emit a krb cartridge from .kry (--emit-krb); route codegen via the AST
|
||||
- Add krb: a packed, mmapable Kryon cartridge format
|
||||
- Add kry_term: a PTY terminal for IDE hosts
|
||||
- Add kry_backend: a draw/input vtable for non-raylib cartridge hosts
|
||||
- UI text: resolve font sources from embedded assets before the filesystem
|
||||
- UI: preserve ui_scale across SaveUIFrameState/RestoreUIFrameState
|
||||
- Raylib build: purge stale .o/.a from vendored sources before recompiling
|
||||
- Add Column/Row layout nodes with flexbox-style auto-positioning
|
||||
- Add raylib rename-check post-build step to fix symbol collision
|
||||
- Phase 6: TileMap + AudioSource nodes (all 12 Game2D kinds now implemented)
|
||||
- Phase 5: animation system (keyframe tracks, AnimationPlayer, AnimatedSprite2D)
|
||||
- Phase 4: Box2D v3 physics integration
|
||||
- Fix scale-domain mixing in title bar, toast, and text centering
|
||||
- Use best available DPI estimate, not just device density
|
||||
- Invalidate DPI cache when device density changes
|
||||
- Add device density hook, fix dropdown resize, widen theme spacing
|
||||
- Add kc signal language support, example, and property/signal tests
|
||||
- Add property model and signal bus for the scene tree
|
||||
- Add kc scene-tree language support, example, and tests
|
||||
- Implement built-in scene nodes: Node2D, Camera2D, Sprite2D
|
||||
- Add retained scene tree foundation and rename UI Sprite to Picture
|
||||
- Allow custom value text on Slider widget
|
||||
- Fix pane tab hit testing
|
||||
- Add UI font init control
|
||||
- Tune tree view file label color
|
||||
- Keep UI keyboard input state backend-independent
|
||||
- Canonicalize widget API
|
||||
- Clean material toggle rendering
|
||||
- Document and enforce canonical app api
|
||||
- Fix sprite example syntax
|
||||
- Clean kryon app api
|
||||
- Add Material theme style widgets
|
||||
- Restore stable tool targets
|
||||
- Preserve icon texture colors
|
||||
- Use host-specific root build directories
|
||||
- Add GTK file dialog backend
|
||||
- Document default Ksync transport APIs
|
||||
- Avoid native Ksync transport warnings
|
||||
- Add default Ksync transport helpers
|
||||
- Kc: extract C emission into kc_codegen.c, heal project split
|
||||
- Kc: extract defer lowering into kc_defer.c
|
||||
- Kc: extract symbol resolution + expression rewrite into kc_resolve.c
|
||||
- Kc: extract KryFile/KryFunction mutators into kc_ir.c
|
||||
- Kc: extract diagnostics + error recovery into kc_diag.c
|
||||
- Kc: extract pure leaf helpers into kc_util.c
|
||||
- Kc: delete _funcs.txt and dedupe function-name helper
|
||||
- Own theme picker labels and expose text drawing helpers
|
||||
- Force retro UI style
|
||||
- Retain dropdown overlay clip bounds
|
||||
- Fix UI transition declaration
|
||||
- Add clean node measurement constructors
|
||||
- Route node measurement through widget ops
|
||||
- Store measurement data on widget nodes
|
||||
- Measure widget nodes generically
|
||||
- Move UI runtime to declarative nodes
|
||||
- Fix classic system focus and material buttons
|
||||
- Simplify theme style selection
|
||||
- Centralize native theme defaults
|
||||
- Add selectable native UI styles
|
||||
- Fix text context menu overlay handling
|
||||
- Add text input context menus
|
||||
- Stabilize UI cursor ownership
|
||||
- Route cursor shape requests through UI intent
|
||||
- Fix layout-aware shortcuts and bulk paste
|
||||
- Adapt syntax colors to dark themes
|
||||
- Fix cascading tree input capture
|
||||
- Remove bundled C IDE
|
||||
- Keep standalone IDE changelog name-neutral
|
||||
- Support standalone KITE IDE
|
||||
- Add nonblocking IDE console
|
||||
- Run kt scenarios visually by target
|
||||
- Expand kt project scenario tests
|
||||
- Add kt test runner
|
||||
- Fix IDE source clipboard fallback
|
||||
- Polish IDE chrome and clipboard fallback
|
||||
- Add IDE console panel
|
||||
- Add IDE problems panel tabs
|
||||
- Normalize kc source paths in generated output
|
||||
- Add shared font subsetting target
|
||||
- Add dynamic font fallback loading
|
||||
- Avoid Windows API name collisions
|
||||
- Define NULL for platform thread helpers
|
||||
- Add compiler diagnostics and UI text backend fixes
|
||||
- Fix Kryon IDE preview input and source selection
|
||||
- Isolate text input selection ownership
|
||||
- Rename Lyra sync APIs to Ksync
|
||||
- Rename Lyra sync APIs to Ksync
|
||||
- Phase 3 (foundation): type-aware AST classification of declarations
|
||||
- Phase 2 (partial): fix defer leaking across switch cases
|
||||
- Phase 1: build the AST alongside the existing path
|
||||
- Phase 0: harden the kc syntax oracle + add parser plan
|
||||
- Add kryon-app dev-backend for local sync development
|
||||
- Fix click-to-source for widgets used in if conditions
|
||||
- Add `defer` to the Kry language
|
||||
- Make text input focus persistent and single-owner across frames
|
||||
- Update website code sample to verb-free Kry syntax
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- Automatic patch releases after successful `master` CI, with retry-safe
|
||||
version resolution and explicit minor/major bump tooling.
|
||||
- Checksummed native tools archives containing every Kryon command-line binary
|
||||
alongside the existing static SDK and cross-platform renderer downloads.
|
||||
- CI and standalone Kryon builds now install/link the GIO notification
|
||||
dependency explicitly instead of discovering its compile flags only.
|
||||
- Linux and FreeBSD CI install GTK development metadata required by the Go
|
||||
desktop-tray bindings exercised by generated-code smoke tests.
|
||||
- Memory diagnostics: `KryonMemReport(tag)` / `KryonMemDebugEnabled()` print
|
||||
RSS/high-water marks and the glibc arena breakdown to stderr when
|
||||
`KRYON_MEM_DEBUG` is set; `UIFontMemoryReport(tag)` prints per-font
|
||||
rasterization stats under the same switch.
|
||||
|
||||
### Changed
|
||||
|
||||
- UI source fonts rasterize once per font at the DPI-scaled base size instead
|
||||
of caching up to eight per-size rasterizations, and one lazily built large
|
||||
tier keeps big text crisp. New codepoints re-rasterize at most once per
|
||||
frame per font, so a locale list in native scripts no longer triggers a
|
||||
rebuild storm. Freed atlas build buffers are returned to the OS
|
||||
(`malloc_trim` on glibc). Idle heap use of font-heavy apps drops
|
||||
accordingly.
|
||||
- Optional GTK dependency for the GTK_STATUS_ICON tray backend: apps can
|
||||
define `KRYON_TRAY_GTK_DL` to resolve GTK through the new `gtk_dl` shim
|
||||
(`dlopen("libgtk-3.so.0")` in the tray thread) instead of linking GTK.
|
||||
Applications that skip the tray then never map libgtk-3 or its
|
||||
gdk/pango/cairo dependency chain.
|
||||
- PTY terminal (`KryTerm`) for IDE hosts: spawn `$SHELL`, write keys, poll
|
||||
a screen grid, resize with `TIOCSWINSZ`. Basic CSI cursor and erase.
|
||||
- First krb cartridge slice: `k2c --emit-krb` packs widget calls into a
|
||||
mmapable `.krb` (VFS nodes, string table, `OP_DRAW_TREE`, host import
|
||||
names). `KrbLoad` / `KrbBind` / `KrbDraw` walk the image through a small
|
||||
`KryBackend` table. `kryon-preview cartridge` renders a `.kry` or `.krb`
|
||||
without building an app host. C emit still walks the reconstructed AST;
|
||||
existing C projects are unchanged.
|
||||
- `k2c --emit-krb` also writes a C host (`*.krb.c` / `*.krb.h`): state
|
||||
becomes `KrbBindMem` paths, button `if` bodies become bind functions,
|
||||
and `Screen_krb_draw` / `Screen_krb_press` are the C ABI. `02_buttons`
|
||||
clicks increment a mounted `click_count`.
|
||||
- Mount live C memory into a cartridge: `KrbMount` / `KrbBindMem` plus
|
||||
`OP_CALL_HOST` and `OP_SET_I32`. A TEXT node whose name is a mounted path
|
||||
draws the live value. Raylib builds now drop copied vendor `.o` files so
|
||||
the backend rename header actually applies.
|
||||
- Add `defer` to the Kry language: `defer STMT` runs `STMT` at the enclosing
|
||||
block's exit (fall-through, `return`, `break`, `continue`), in reverse
|
||||
registration order across nested scopes. A compile-time transform that
|
||||
splices the statement into the generated C at every exit point — no runtime
|
||||
cost. `goto` out of a deferred scope is left to explicit cleanup.
|
||||
- Resolve qualified type references across modules. Writing
|
||||
`alias.Type` after `alias :: #import "mod/path"` now produces the bare C type
|
||||
name in every position — parameter lists, return types, struct fields, local
|
||||
declarations, and `#global` declarations — instead of emitting `alias.Type`
|
||||
verbatim (a C syntax error) or wrongly module-prefixing it. Structs and enums
|
||||
use their declared name across translation units, so the alias prefix is
|
||||
dropped. Qualified *calls* (`alias.fn(...)`) still rewrite to `module_fn(...)`
|
||||
as before. The first multi-module `.kry` program (state + draw + host) now
|
||||
compiles, links, and runs end to end.
|
||||
- Remove the fixed per-function body cap. `k2c` previously rejected any function
|
||||
whose generated body exceeded a fixed 512-statement cap with
|
||||
"generated body is too large", which blocks large UI draw functions.
|
||||
`KryFunction.body`/`body_line` are now heap arrays that grow geometrically
|
||||
(via `grow_body`), and the `apply_defers` splice pass allocates its working
|
||||
buffers sized to the body. A 1,500-statement function compiles cleanly.
|
||||
Verified clean under ASAN/UBSAN/LeakSanitizer; the previously-leaked
|
||||
`file->functions`/`routes` arrays are now freed on exit.
|
||||
- Collect multiple parse errors instead of aborting on the first. Parsing now
|
||||
installs a per-statement recovery boundary: a malformed statement records a
|
||||
diagnostic and parsing continues with the next, so a file with several errors
|
||||
reports all of them (Krait's problems pane becomes useful while editing).
|
||||
A file that previously reported one error and exited now reports every
|
||||
recoverable error in source order. Fatal conditions (out of memory, CLI
|
||||
misuse) still abort as before, and any diagnostics already recorded are
|
||||
flushed first. Examples and valid code are unaffected (byte-identical).
|
||||
- Standalone `.kry` apps can own their frame loop. The `app{}` block now
|
||||
accepts `init`, `frame`, and `shutdown` hooks naming `.kry` functions; when
|
||||
`frame` is set, `k2c` emits a `main()` that calls `init()` once, `frame()`
|
||||
each iteration, and `shutdown()` at exit — without bracketing drawing, so the
|
||||
program calls `BeginDrawing`/`BeginUIFrame`/`EndDrawing` itself and can host
|
||||
nested render-texture passes and inspection overlays like a hand-written C
|
||||
app. This is the entry point Krait uses. Without hooks the
|
||||
existing single-screen `app{}`/`screen` dialect is unchanged (byte-identical).
|
||||
- Add the Kry standard platform library: `kry_process` (spawn a shell command
|
||||
with non-blocking stdout/stderr polling, used for builds and consoles),
|
||||
`kry_filesystem` (directory iteration, stat/mtime, recursive mkdir, realpath,
|
||||
text read/write), and `kry_dylib` (dlopen/dlsym/dlclose for loading a built
|
||||
app host). Declared in `kryon.h` and implemented under `src/kry_std/`, so they
|
||||
are linked into `libkryon.a` and callable directly from `.kry` via `#extern`.
|
||||
These lift Krait's inline POSIX surface into a reusable library so the
|
||||
`.kry`-written IDE can spawn `make kryon-host`, walk the project tree, and
|
||||
`dlopen` the resulting `app_host.so`. Windows has stub implementations.
|
||||
- Move the self-hosted IDE rewrite in Kry into the standalone IDE repository,
|
||||
Krait (`kryonlabs/krait`): `app.kry` owns the window loop via the new
|
||||
`app{}` hooks; `state.kry`, `start_page.kry`, `project.kry`, `tree.kry`, and
|
||||
`editor.kry` implement the start page, project-open flow (file dialog +
|
||||
`kry_fs`), a file-tree sidebar (`kry_fs_list_dir` +
|
||||
`UICascadingTreeViewNode`), and a read-only source viewer (`kry_fs_read_file`
|
||||
+ `UITextAreaNode`). Krait transpiles those modules in one `k2c` invocation
|
||||
and links the generated C against `libkryon.a` + raylib.
|
||||
- Krait gains an editable editor with multi-tab open files, Ctrl+S save
|
||||
(`kry_fs_write_file`), dirty markers, and Ctrl+Z/Ctrl+Y undo/redo
|
||||
(heap-snapshot ring), plus a live-preview pane (`preview.kry`) that runs
|
||||
`make kryon-host` via `kry_process`, `dlopen`s the resulting `app_host.so`
|
||||
via `kry_dylib`, and renders the host into a `RenderTexture` — the full
|
||||
non-blocking build + hot-reload loop, written in Kry.
|
||||
- Add the Krait console and problems panels in Kry (`console.kry`,
|
||||
`problems.kry`): an interactive shell that runs typed commands via
|
||||
`kry_process` and drains output each frame, and a diagnostics parser that
|
||||
splits `path:line:col: message` lines from build output into a problems
|
||||
list, shown in a bottom panel that auto-opens when a build reports errors.
|
||||
- Compile kryon library objects with `-fPIC` so they link into PIE executables
|
||||
and `dlopen`'d app hosts on distros that default to PIE.
|
||||
|
||||
### Changed
|
||||
|
||||
- Remove the bundled C IDE. Kryon now builds only the library, compiler, and
|
||||
tooling; the Kry-written IDE, Krait (`kryonlabs/krait`), lives in its own
|
||||
repository and vendors Kryon as a submodule.
|
||||
- Rename the app command `kryon-app` to `kryon`. There is now a single
|
||||
`kryon` command for building, packaging, running, previewing, and the local
|
||||
Ksync backend. `scripts/kryon-app.sh` → `scripts/kryon.sh`; the Makefile
|
||||
installs `$(BINDIR)/kryon`; `kt` execs `kryon` for app runs and `krait` for
|
||||
the `ide` target (freeing the bare `kryon` name for the build tool). App
|
||||
`project.kryon` target entries that call `sh vendor/kryon/scripts/kryon.sh`
|
||||
are updated in downstream apps.
|
||||
- Add a `value_text_override` parameter to `DrawUISlider`, `UISliderNode`, and
|
||||
`Slider`. When non-NULL it replaces the default numeric value label, letting
|
||||
callers render custom value text (for example, named steps). This is a
|
||||
breaking signature change: all callers must add the new argument (NULL keeps
|
||||
the previous behavior).
|
||||
- Fix copy/cut/paste/select-all in the Krait source editor. `UITextAreaNode`
|
||||
had its own generic clipboard handler that raced Krait's
|
||||
`editor_handle_source_clipboard` on the same one-shot keypress, so Ctrl+C/V
|
||||
worked inconsistently. The generic handler is removed; Krait now owns the
|
||||
source-editor clipboard (it has the byte-cap, line-copy fallback, and status
|
||||
messages). The stale `!textarea_changed` guard that silently skipped paste is
|
||||
dropped too.
|
||||
- Raise the clipboard size caps so large selections copy and paste in full.
|
||||
The kryon UI buffer (`g_clipboard_text`) grew from 4096 to 1 MiB, and the
|
||||
vendored raylib SDL `GetClipboardText` buffer (`MAX_CLIPBOARD_BUFFER_LENGTH`,
|
||||
a fixed 1024 that truncated pastes to 1019 bytes + `...`) is overridden to the
|
||||
same 1 MiB via a `-D` flag passed through `RAY_RAYLIB_CONFIG` — no vendored
|
||||
raylib source is edited. Both caps are now symmetric and above the editor's
|
||||
512 KiB source buffer, which becomes the real ceiling.
|
||||
- Make hot-reload (and run targets) non-blocking. Krait ran the app-host build
|
||||
as a synchronous `popen`+`fread` on the UI thread, freezing the window for the
|
||||
whole compile. Builds now use the same `fork`+`pipe`+`waitpid(WNOHANG)` pattern
|
||||
as the console runner (`editor_build_start`/`editor_build_poll`), drained each
|
||||
frame from the main loop; the app host is `dlopen`ed on the poll that observes
|
||||
a successful exit. The reload poll is lowered from 2.0s to 0.5s so a finished
|
||||
build is picked up promptly, and builds are serialized with the console.
|
||||
- Split the screen-header (title bar) widgets out of `modal.c` into a new
|
||||
`src/ui/ui_titlebar.c`, leaving `modal.c` holding only modal/dialog code.
|
||||
Removed an orphaned empty scrollbar section marker.
|
||||
- Consolidate duplicated helpers: the three byte-identical `clampi` copies in
|
||||
`guide.c`, `modal.c`, and `theme_picker.c` now use the shared `ui_clampi`.
|
||||
Add shared `ui_draw_box_background`, `ui_caret_blink_visible`, and
|
||||
`ui_open_url` helpers, replacing inlined copies in the text widgets and links.
|
||||
- Correct the README preview-projects section: Krait previews `.kry` by
|
||||
rebuilding and `dlopen`ing an app host, not by rendering source directly.
|
||||
- Remove the empty leftover `src/editor/` directory; the C editor lived under
|
||||
the command tree before the Krait migration.
|
||||
- Add CI workflow (`.github/workflows/ci.yml`) that builds and runs `make test`
|
||||
on push and pull request for Linux and FreeBSD. Tests previously only ran at
|
||||
release time.
|
||||
- Extract the UTF-8 codec and text-buffer helpers from `ui.c` into a new
|
||||
`src/ui/ui_text_edit.c`, with a `tests/ui_text_edit_test.c` covering the
|
||||
insert/delete/offset logic.
|
||||
|
||||
## v0.1.7 - 2026-07-26
|
||||
|
||||
### Changed
|
||||
@@ -21,11 +610,11 @@
|
||||
- Restyle docs site with refined modern-retro theme
|
||||
- Add Kryon IDE start page and fix preview inspection
|
||||
- Improve Kry language and generic APIs
|
||||
- Support uninitialized C locals in kc
|
||||
- Allow args locals in kc functions
|
||||
- Support uninitialized C locals in k2c
|
||||
- Allow args locals in k2c functions
|
||||
- Add Kryon platform thread primitives
|
||||
- Support local enum blocks in kc
|
||||
- Support bitwise compound assignments in kc
|
||||
- Support local enum blocks in k2c
|
||||
- Support bitwise compound assignments in k2c
|
||||
- Guard Kry compile-time expansion recursion
|
||||
- Add runtime asset sync API
|
||||
- Support Kry multidimensional arrays
|
||||
|
||||
@@ -1,36 +1,5 @@
|
||||
CC ?= cc
|
||||
AR ?= ar
|
||||
BUILD_DIR ?= build
|
||||
PREFIX ?= $(HOME)/.local
|
||||
SITE_DIR ?= docs/site
|
||||
SITE_BUILD_DIR ?= $(BUILD_DIR)/site
|
||||
VERSION_FILE ?= include/kryon_version.h
|
||||
KRYON_VERSION_STRING := $(shell sed -n 's/^#define KRYON_VERSION_STRING "\([^"]*\)".*/\1/p' $(VERSION_FILE) 2>/dev/null)
|
||||
VERSION ?= $(if $(strip $(KRYON_VERSION_STRING)),$(KRYON_VERSION_STRING),$(shell git describe --tags --always --dirty 2>/dev/null || printf '%s' 0.0.0))
|
||||
DIST_DIR ?= dist
|
||||
STATIC_DIST_ROOT := $(BUILD_DIR)/dist/kryon-$(VERSION)-static
|
||||
STATIC_DIST_ARCHIVE := $(DIST_DIR)/kryon-$(VERSION)-static.tar.gz
|
||||
KC = $(BUILD_DIR)/bin/kc
|
||||
KI = $(BUILD_DIR)/bin/kryon
|
||||
KRYON_APP = $(BUILD_DIR)/bin/kryon-app
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
INSTALL ?= install
|
||||
CFLAGS ?= -Wall -Wextra -O2
|
||||
CPPFLAGS_BASE = -Iinclude -I$(KRYON_DIR)/vendor/clay
|
||||
ICON_DIR ?= icons language payments platforms tiles pfp
|
||||
ICON_FILES = $(foreach dir,$(ICON_DIR),$(wildcard $(dir)/*.png))
|
||||
ICON_ASSETS_C = src/ui/ui_icon_assets.c
|
||||
EMBED_ASSETS ?= themes fonts/noto
|
||||
EMBED_ASSET_FILES = $(shell find $(EMBED_ASSETS) -type f 2>/dev/null)
|
||||
EMBED_ASSETS_C = $(BUILD_DIR)/embedded_asset_data.c
|
||||
KRYON_COMPAT_GENERATOR = tools/generate-kryon-compat.sh
|
||||
KRYON_BOUNDARY_CHECK = tools/check-kryon-boundaries.sh
|
||||
KRYON_COMPAT_SYMBOL_CHECK = tools/check-raylib-compat-symbols.sh
|
||||
KRYON_COMPAT_HEADER = include/kryon_compat.generated.h
|
||||
KRYON_BACKEND_RENAME_HEADER = $(BUILD_DIR)/generated/raylib_backend_rename.h
|
||||
KRYON_RAYLIB_WRAPPERS_C = $(BUILD_DIR)/generated/kryon_raylib_wrappers.c
|
||||
KRYON_RAYLIB_GENERATED_PUBLIC_HEADER ?= $(KRYON_COMPAT_HEADER)
|
||||
KRYON_RAYLIB_BACKEND_RENAME_HEADER ?= $(KRYON_BACKEND_RENAME_HEADER)
|
||||
UNAME_S := $(shell uname -s 2>/dev/null)
|
||||
UNAME_M := $(shell uname -m 2>/dev/null)
|
||||
ifeq ($(UNAME_M),amd64)
|
||||
@@ -47,7 +16,90 @@ else ifeq ($(UNAME_S),Darwin)
|
||||
else
|
||||
KRYON_PLATFORM := $(UNAME_S)
|
||||
endif
|
||||
BUILD_ROOT ?= build
|
||||
BUILD_DIR ?= $(BUILD_ROOT)/$(KRYON_PLATFORM)-$(KRYON_ARCH)
|
||||
PREFIX ?= $(HOME)/.local
|
||||
SITE_DIR ?= docs/site
|
||||
SITE_BUILD_DIR ?= $(BUILD_DIR)/site
|
||||
VERSION_FILE ?= include/kryon_version.h
|
||||
KRYON_VERSION_STRING := $(shell sed -n 's/^#define KRYON_VERSION_STRING "\([^"]*\)".*/\1/p' $(VERSION_FILE) 2>/dev/null)
|
||||
VERSION ?= $(if $(strip $(KRYON_VERSION_STRING)),$(KRYON_VERSION_STRING),$(shell git describe --tags --always --dirty 2>/dev/null || printf '%s' 0.0.0))
|
||||
DIST_DIR ?= dist
|
||||
STATIC_DIST_ROOT := $(BUILD_DIR)/dist/kryon-$(VERSION)-static
|
||||
STATIC_DIST_ARCHIVE := $(DIST_DIR)/kryon-$(VERSION)-static.tar.gz
|
||||
TOOLS_DIST_ROOT := $(BUILD_DIR)/dist/kryon-$(VERSION)-tools-$(KRYON_PLATFORM)-$(KRYON_ARCH)
|
||||
TOOLS_DIST_ARCHIVE := $(DIST_DIR)/kryon-$(VERSION)-tools-$(KRYON_PLATFORM)-$(KRYON_ARCH).tar.gz
|
||||
K2C = $(BUILD_DIR)/bin/k2c
|
||||
K2G = $(BUILD_DIR)/bin/k2g
|
||||
K2IR = $(BUILD_DIR)/bin/k2ir
|
||||
K2B = $(BUILD_DIR)/bin/k2b
|
||||
KT = $(BUILD_DIR)/bin/kt
|
||||
KRYON_PREVIEW = $(BUILD_DIR)/bin/kryon-preview
|
||||
KRYON_CMD = $(BUILD_DIR)/bin/kryon
|
||||
KRB_RUN = $(BUILD_DIR)/bin/krb-run
|
||||
KRB_SDL = $(BUILD_DIR)/bin/krb-sdl
|
||||
KRY_SW_TEST = $(BUILD_DIR)/tests/kry_sw_test
|
||||
KRB_LOGIC_TEST = $(BUILD_DIR)/tests/krb_logic_test
|
||||
KRB_ASSET_TEST = $(BUILD_DIR)/tests/krb_asset_test
|
||||
KRB_CAPS_TEST = $(BUILD_DIR)/tests/krb_caps_test
|
||||
EMCC ?= emcc
|
||||
KRB_WEB_DIR = $(BUILD_DIR)/web/krb-web
|
||||
KRB_WEB = $(KRB_WEB_DIR)/index.html
|
||||
KRB_WEB_KRY ?= examples/02_buttons.kry
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
INSTALL ?= install
|
||||
CFLAGS ?= -Wall -Wextra -O2
|
||||
CPPFLAGS_BASE = -Iinclude -I$(KRYON_DIR)/vendor/clay $(KRYON_PHYSICS_CPPFLAGS)
|
||||
ICON_DIR ?= icons language payments platforms tiles pfp
|
||||
ICON_FILES = $(foreach dir,$(ICON_DIR),$(wildcard $(dir)/*.png))
|
||||
ICON_ASSETS_C = src/ui/ui_icon_assets.c
|
||||
# Default embedded assets: themes + the regular UI font. The CJK Noto faces
|
||||
# (JP/KR/SC/TC, ~22 MB) are intentionally NOT embedded by default — nothing in
|
||||
# the default UI loads them. Apps that need CJK can override:
|
||||
# make EMBED_ASSETS="themes fonts/noto"
|
||||
EMBED_ASSETS ?= themes fonts/noto/NotoSans-Regular.ttf
|
||||
EMBED_ASSET_FILES = $(shell find $(EMBED_ASSETS) -type f 2>/dev/null)
|
||||
EMBED_ASSETS_C = $(BUILD_DIR)/embedded_asset_data.c
|
||||
FONT_SUBSET_OUT_DIR ?= $(BUILD_DIR)/fonts/subset
|
||||
FONT_SUBSET_SOURCE_DIR ?= $(KRYON_DIR)/fonts/noto
|
||||
FONT_SUBSET_PREFIX ?= App
|
||||
FONT_SUBSET_CORPUS ?=
|
||||
KRYON_COMPAT_GENERATOR = tools/generate-kryon-compat.sh
|
||||
KRYON_BOUNDARY_CHECK = tools/check-kryon-boundaries.sh
|
||||
KRYON_COMPAT_SYMBOL_CHECK = tools/check-raylib-compat-symbols.sh
|
||||
KRYON_COMPAT_HEADER = include/kryon_compat.generated.h
|
||||
KRYON_BACKEND_RENAME_HEADER = $(BUILD_DIR)/generated/raylib_backend_rename.h
|
||||
KRYON_RAYLIB_WRAPPERS_C = $(BUILD_DIR)/generated/kryon_raylib_wrappers.c
|
||||
KRYON_NULL_BACKEND_C = $(BUILD_DIR)/generated/kryon_null_backend.c
|
||||
KRYON_RAYLIB_GENERATED_PUBLIC_HEADER ?= $(KRYON_COMPAT_HEADER)
|
||||
KRYON_RAYLIB_BACKEND_RENAME_HEADER ?= $(KRYON_BACKEND_RENAME_HEADER)
|
||||
|
||||
# Graphics/input backend. The kryon surface (kryon_compat.generated.h) is
|
||||
# backend-neutral; the concrete implementation is selected at link time here.
|
||||
# raylib -> generated raylib forwarders + libraylib.a (default, unchanged)
|
||||
# canvas -> src/backend/canvas_backend.c (HTML5 Canvas2D; no raylib)
|
||||
# null -> generated zero-return stubs (no-ops; for headless tests)
|
||||
KRYON_BACKEND ?= raylib
|
||||
ifeq ($(KRYON_BACKEND),raylib)
|
||||
KRYON_BACKEND_SRCS = $(KRYON_RAYLIB_WRAPPERS_C)
|
||||
else ifeq ($(KRYON_BACKEND),canvas)
|
||||
KRYON_BACKEND_SRCS = src/backend/canvas_backend.c
|
||||
else ifeq ($(KRYON_BACKEND),null)
|
||||
KRYON_BACKEND_SRCS = $(KRYON_NULL_BACKEND_C)
|
||||
else
|
||||
$(error Unknown KRYON_BACKEND '$(KRYON_BACKEND)' (expected raylib, canvas, or null))
|
||||
endif
|
||||
|
||||
# Link inputs for the selected backend: only raylib needs libraylib.a and the
|
||||
# window/GL system libraries it was built with; null and canvas carry their
|
||||
# own (or none), so KRYON_BACKEND=null links headless with no raylib at all.
|
||||
ifeq ($(KRYON_BACKEND),raylib)
|
||||
KRYON_BACKEND_LIBS = $(RAYLIB_A)
|
||||
KRYON_BACKEND_LDLIBS ?= $(RAY_LDLIBS)
|
||||
else
|
||||
KRYON_BACKEND_LIBS =
|
||||
KRYON_BACKEND_LDLIBS ?=
|
||||
endif
|
||||
RAYLIB_DIR ?= $(KRYON_DIR)/vendor/raylib/src
|
||||
RAYLIB_BUILD_DIR ?= $(BUILD_DIR)/raylib
|
||||
RAYLIB_A ?= $(RAYLIB_BUILD_DIR)/libraylib.a
|
||||
@@ -62,10 +114,16 @@ CURL_CODEC_LDLIBS ?= $(strip \
|
||||
$(shell pkg-config --libs libbrotlidec 2>/dev/null) \
|
||||
$(shell pkg-config --libs libbrotlicommon 2>/dev/null) \
|
||||
$(shell pkg-config --libs libzstd 2>/dev/null))
|
||||
ifeq ($(KRYON_PLATFORM),freebsd)
|
||||
# pkg-config omits its default library directory, but the FreeBSD linker
|
||||
# does not search the ports prefix automatically.
|
||||
CURL_CODEC_LDLIBS := -L/usr/local/lib $(CURL_CODEC_LDLIBS)
|
||||
endif
|
||||
KRYON_ZLIB_LDLIB ?= -lz
|
||||
RAY_SDL_INCLUDE_DIR ?= $(shell pkg-config --variable=includedir sdl2 2>/dev/null | sed 's,/SDL2$$,,')
|
||||
RAY_RAYLIB_CONFIG ?= -DSUPPORT_SCREEN_CAPTURE=0 -DSUPPORT_COMPRESSION_API=0 -DSUPPORT_AUTOMATION_EVENTS=0 -DSUPPORT_CLIPBOARD_IMAGE=0 -DSUPPORT_FILEFORMAT_BMP=0 -DSUPPORT_FILEFORMAT_GIF=0 -DSUPPORT_FILEFORMAT_QOI=0 -DSUPPORT_FILEFORMAT_DDS=0 -DSUPPORT_FILEFORMAT_TTF=1
|
||||
RAY_RAYLIB_CONFIG ?= -DSUPPORT_SCREEN_CAPTURE=0 -DSUPPORT_COMPRESSION_API=0 -DSUPPORT_AUTOMATION_EVENTS=0 -DSUPPORT_CLIPBOARD_IMAGE=0 -DSUPPORT_FILEFORMAT_BMP=0 -DSUPPORT_FILEFORMAT_GIF=0 -DSUPPORT_FILEFORMAT_QOI=0 -DSUPPORT_FILEFORMAT_DDS=0 -DSUPPORT_FILEFORMAT_TTF=1 -DMAX_CLIPBOARD_BUFFER_LENGTH=1048576
|
||||
APP_RAYLIB_CONFIG ?= $(filter-out -DSUPPORT_MODULE_RAUDIO=0 -DSUPPORT_FILEFORMAT_PNG=0 -DSUPPORT_FILEFORMAT_JPG=0 -DSUPPORT_FILEFORMAT_OGG=0 -DSUPPORT_FILEFORMAT_MP3=0,$(RAY_RAYLIB_CONFIG)) -DSUPPORT_MODULE_RAUDIO=1 -DSUPPORT_FILEFORMAT_JPG=1 -DSUPPORT_FILEFORMAT_OGG=1 -DSUPPORT_FILEFORMAT_MP3=1
|
||||
KRYON_STATIC_PACKAGE_EXTERNAL_LIBS ?= $(RAY_LDLIBS) $(KRYON_OPENSSL_SSL_LDLIB) $(KRYON_OPENSSL_CRYPTO_LDLIB) -lpthread -lm
|
||||
KRYON_STATIC_PACKAGE_EXTERNAL_LIBS ?= $(RAY_LDLIBS) $(KRYON_OPENSSL_SSL_LDLIB) $(KRYON_OPENSSL_CRYPTO_LDLIB) $(KRYON_ZLIB_LDLIB) -lpthread -lm
|
||||
KRYON_STATIC_PACKAGE_LIBS ?= -lkryon -lraylib -loqs -lcurl -lcmark-gfm-extensions -lcmark-gfm $(KRYON_STATIC_PACKAGE_EXTERNAL_LIBS)
|
||||
KRYON_STATIC_PACKAGE_CFLAGS ?= -I$${includedir} -DHAS_LIBOQS=1 -DHAS_LIBCURL=1 -DCURL_STATICLIB -DKRYON_HAS_CMARK_GFM=1
|
||||
|
||||
@@ -75,7 +133,9 @@ ifneq ($(NIX_CFLAGS_COMPILE),)
|
||||
endif
|
||||
|
||||
CPPFLAGS += $(CPPFLAGS_BASE)
|
||||
ARFLAGS ?= rcs
|
||||
# GNU make defines ARFLAGS=rv by default. A Kryon static library must carry
|
||||
# an index so downstream C/Go linkers can resolve every runtime module.
|
||||
ARFLAGS = rcs
|
||||
KRYON_DIR ?= .
|
||||
KRYON_VENDOR_BUILD_DIR ?= $(BUILD_DIR)/vendor
|
||||
include mk/vendor.mk
|
||||
@@ -84,10 +144,20 @@ include mk/raylib.mk
|
||||
CPPFLAGS += -DHAS_LIBOQS=1 $(KRYON_LIBOQS_INCLUDE) \
|
||||
-DHAS_LIBCURL=1 $(KRYON_CURL_CFLAGS) \
|
||||
$(KRYON_MARKDOWN_CFLAGS)
|
||||
CPPFLAGS += $(KRYON_NOTIFICATION_CPPFLAGS) $(KRYON_NOTIFICATION_CFLAGS)
|
||||
LDLIBS += $(KRYON_NOTIFICATION_LDLIBS)
|
||||
|
||||
SRCS := $(shell find src -type f -name '*.c' | LC_ALL=C sort)
|
||||
|
||||
SRCS += $(EMBED_ASSETS_C) $(KRYON_RAYLIB_WRAPPERS_C)
|
||||
SRCS += $(EMBED_ASSETS_C) $(KRYON_BACKEND_SRCS)
|
||||
|
||||
# Drop the Box2D physics sources when physics is disabled (UI-only builds).
|
||||
# Keep in sync with KRYON_PHYSICS_SRCS in mk/vendor.mk.
|
||||
KRYON_PHYSICS_SRCS_REL := src/scene/physics_world.c src/scene/node_body2d.c \
|
||||
src/scene/node_area2d.c src/scene/node_collision_shape2d.c
|
||||
ifeq ($(KRYON_WITH_PHYSICS),0)
|
||||
SRCS := $(filter-out $(KRYON_PHYSICS_SRCS_REL),$(SRCS))
|
||||
endif
|
||||
|
||||
SYSTEM_THEME_PKG := $(shell if pkg-config --exists gtk+-3.0 2>/dev/null; then printf '%s' gtk+-3.0; fi)
|
||||
ifneq ($(strip $(SYSTEM_THEME_PKG)),)
|
||||
@@ -97,9 +167,10 @@ endif
|
||||
|
||||
OBJS = $(patsubst src/%.c,$(BUILD_DIR)/%.o,$(filter src/%,$(SRCS))) \
|
||||
$(patsubst $(BUILD_DIR)/%.c,$(BUILD_DIR)/%.o,$(filter $(BUILD_DIR)/%,$(SRCS)))
|
||||
LIB = libkryon.a
|
||||
LYRA_ACCOUNT_TEST = $(BUILD_DIR)/tests/lyra_account_test
|
||||
LYRA_SYNC_TEST = $(BUILD_DIR)/tests/lyra_sync_test
|
||||
LIB = $(BUILD_DIR)/libkryon.a
|
||||
KSYNC_ACCOUNT_TEST = $(BUILD_DIR)/tests/ksync_account_test
|
||||
KSYNC_SYNC_TEST = $(BUILD_DIR)/tests/ksync_sync_test
|
||||
KSYNC_CRYPTO_TEST = $(BUILD_DIR)/tests/ksync_crypto_test
|
||||
TRANSITION_TEST = $(BUILD_DIR)/tests/transition_test
|
||||
FILE_DIALOG_BACKEND_TEST = $(BUILD_DIR)/tests/file_dialog_backend_test
|
||||
MARKDOWN_TEST = $(BUILD_DIR)/tests/markdown_test
|
||||
@@ -107,54 +178,102 @@ RAYLIB_COMPAT_TEST = $(BUILD_DIR)/tests/raylib_compat_test
|
||||
UI_TK_TEST = $(BUILD_DIR)/tests/ui_tk_test
|
||||
PREVIEW_TEST = $(BUILD_DIR)/tests/preview_test
|
||||
PLATFORM_THREAD_TEST = $(BUILD_DIR)/tests/platform_thread_test
|
||||
RAYLIB_COMPAT_LDLIBS ?= $(RAY_LDLIBS) -lpthread -lm $(if $(filter linux,$(KRYON_PLATFORM)),-ldl -lrt,)
|
||||
UI_TEXT_EDIT_TEST = $(BUILD_DIR)/tests/ui_text_edit_test
|
||||
UI_TREE_API_TEST = $(BUILD_DIR)/tests/ui_tree_api_test
|
||||
UI_WINDOW_TEST = $(BUILD_DIR)/tests/ui_window_test
|
||||
UI_WINDOW_SDL_CHECK = $(BUILD_DIR)/check/ui_window_sdl.o
|
||||
TEXT_INPUT_PERF_TEST = $(BUILD_DIR)/tests/text_input_perf_test
|
||||
SCENE_TREE_TEST = $(BUILD_DIR)/tests/scene_tree_test
|
||||
SCENE_PROPERTY_TEST = $(BUILD_DIR)/tests/scene_property_test
|
||||
ANIMATION_TEST = $(BUILD_DIR)/tests/animation_test
|
||||
KIR_TEST = $(BUILD_DIR)/tests/kir_test
|
||||
K2IR_TEST = $(BUILD_DIR)/tests/k2ir.ok
|
||||
KRB_WALK_TEST = $(BUILD_DIR)/tests/krb_walk_test
|
||||
KRB_MOUNT_TEST = $(BUILD_DIR)/tests/krb_mount_test
|
||||
KRY_TERM_TEST = $(BUILD_DIR)/tests/kry_term_test
|
||||
KRY_JSON_TEST = $(BUILD_DIR)/tests/kry_json_test
|
||||
KRY_HTTP_TEST = $(BUILD_DIR)/tests/kry_http_test
|
||||
SFS_TEST = $(BUILD_DIR)/tests/sfs_test
|
||||
RAYLIB_COMPAT_LDLIBS ?= $(KRYON_BACKEND_LDLIBS) -lpthread -lm $(if $(filter linux,$(KRYON_PLATFORM)),-ldl -lrt,)
|
||||
|
||||
.PHONY: all clean run tools examples-run font-assets docs-site test bsd-check kryon-compat kryon-compat-check kryon-boundary-check version release-check dist-static check-static-package install install-static
|
||||
.PHONY: all clean tools examples-run font-assets font-subsets docs-site test perf-text-input bsd-check kryon-compat kryon-compat-check kryon-boundary-check version release-check dist-static check-static-package dist-tools check-tools-package install install-static k2c k2g krb-web krb-sdl
|
||||
|
||||
all: $(LIB) $(KC) $(KI) $(KRYON_APP)
|
||||
k2c: $(K2C)
|
||||
k2g: $(K2G)
|
||||
|
||||
run: $(KI)
|
||||
@if [ -n "$(PROJECT)" ]; then \
|
||||
project_path=$$(cd "$(PROJECT)" && pwd); \
|
||||
KRYON_INSPECT=1 KRYON_PROJECT_ROOT="$$project_path" $(KI) "$$project_path"; \
|
||||
elif [ -n "$(ARGS)" ]; then \
|
||||
project_path=$$(cd "$(ARGS)" && pwd); \
|
||||
KRYON_INSPECT=1 KRYON_PROJECT_ROOT="$$project_path" $(KI) "$$project_path"; \
|
||||
elif [ -n "$(KRYON_PROJECT)" ]; then \
|
||||
project_path=$$(cd "$(KRYON_PROJECT)" && pwd); \
|
||||
KRYON_INSPECT=1 KRYON_PROJECT_ROOT="$$project_path" $(KI) "$$project_path"; \
|
||||
else \
|
||||
project_path=$$(pwd); \
|
||||
KRYON_INSPECT=1 KRYON_PROJECT_ROOT="$$project_path" $(KI); \
|
||||
fi
|
||||
all: $(LIB) $(K2C) $(K2G) $(K2IR) $(K2B) $(KT) $(KRYON_PREVIEW) $(KRYON_CMD)
|
||||
|
||||
tools: $(KC) $(KI) $(KRYON_APP)
|
||||
tools: $(K2C) $(K2G) $(K2IR) $(K2B) $(KT) $(KRYON_PREVIEW) $(KRYON_CMD) $(KRB_RUN) $(KRB_SDL)
|
||||
|
||||
install: $(KI) $(KRYON_APP)
|
||||
install: $(KT) $(KRYON_CMD)
|
||||
mkdir -p $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -m 755 $(KI) $(DESTDIR)$(BINDIR)/kryon
|
||||
$(INSTALL) -m 755 $(KRYON_APP) $(DESTDIR)$(BINDIR)/kryon-app
|
||||
$(INSTALL) -m 755 $(KT) $(DESTDIR)$(BINDIR)/kt
|
||||
$(INSTALL) -m 755 $(KRYON_CMD) $(DESTDIR)$(BINDIR)/kryon
|
||||
|
||||
examples-run:
|
||||
@$(MAKE) -C examples run
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR) $(LIB)
|
||||
rm -rf $(BUILD_DIR)
|
||||
$(MAKE) -C examples web-clean
|
||||
|
||||
# SDL2 desktop host: kry_sw renders, SDL2 owns window/input/presentation.
|
||||
# Uses pkg-config sdl2 (on omega: PKG_CONFIG_PATH=~/.local/sdl2/lib/pkgconfig).
|
||||
KRB_SDL_CFLAGS = $(shell PKG_CONFIG_PATH=$(HOME)/.local/sdl2/lib/pkgconfig:$(PKG_CONFIG_PATH) pkg-config --cflags sdl2 2>/dev/null)
|
||||
KRB_SDL_LDLIBS = $(shell PKG_CONFIG_PATH=$(HOME)/.local/sdl2/lib/pkgconfig:$(PKG_CONFIG_PATH) pkg-config --libs sdl2 2>/dev/null)
|
||||
|
||||
krb-sdl: $(KRB_SDL)
|
||||
|
||||
$(KRB_SDL): cmd/krb-sdl/main.c cmd/krb-run/png_write.c cmd/krb-run/png_write.h $(KRY_SW_SRCS) $(KRY_SW_HDRS) | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) -Iinclude -Icmd/krb-run $(KRB_SDL_CFLAGS) -o $@ \
|
||||
cmd/krb-sdl/main.c cmd/krb-run/png_write.c $(KRY_SW_SRCS) \
|
||||
$(KRB_SDL_LDLIBS) -lm
|
||||
|
||||
# Native web host for KRB cartridges: kry_sw rasterizer compiled to wasm,
|
||||
# blitted to ImageData (pixel-identical to the native headless renderer).
|
||||
# Needs emcc on PATH (e.g. `source ~/emsdk/emsdk_env.sh`).
|
||||
krb-web: $(KRY_SW_SRCS) $(KRY_SW_HDRS) cmd/krb-web/main.c cmd/krb-web/shell.html | $(KRB_WEB_DIR)
|
||||
$(EMCC) -Wall -Wextra -Os -Iinclude \
|
||||
-sEXPORTED_FUNCTIONS=_krb_web_mouse,_krb_web_button,_krb_web_wheel,_krb_web_text,_krb_web_start,_main \
|
||||
-sEXPORTED_RUNTIME_METHODS=FS \
|
||||
-sALLOW_MEMORY_GROWTH=1 \
|
||||
--shell-file cmd/krb-web/shell.html \
|
||||
-o $(KRB_WEB) \
|
||||
cmd/krb-web/main.c $(KRY_SW_SRCS)
|
||||
@echo "krb-web player: serve $(KRB_WEB_DIR) (e.g. python3 -m http.server -d $(KRB_WEB_DIR))"
|
||||
|
||||
$(KRB_WEB_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
docs-site:
|
||||
rm -rf $(SITE_BUILD_DIR)
|
||||
mkdir -p $(SITE_BUILD_DIR)
|
||||
cp -R $(SITE_DIR)/. $(SITE_BUILD_DIR)/
|
||||
cp -R icons platforms language $(SITE_BUILD_DIR)/
|
||||
cp -R $(SITE_DIR)/cursors $(SITE_BUILD_DIR)/
|
||||
sh scripts/build-site-web-ide.sh $(SITE_BUILD_DIR)
|
||||
sh scripts/render-api-html.sh docs/API.md $(SITE_DIR)/api-template.html $(SITE_BUILD_DIR)/api.html
|
||||
rm -f $(SITE_BUILD_DIR)/api-template.html
|
||||
|
||||
test: kryon-compat-check kryon-boundary-check $(KC) $(LYRA_ACCOUNT_TEST) $(LYRA_SYNC_TEST) $(TRANSITION_TEST) $(FILE_DIALOG_BACKEND_TEST) $(MARKDOWN_TEST) $(RAYLIB_COMPAT_TEST) $(UI_TK_TEST) $(PREVIEW_TEST) $(PLATFORM_THREAD_TEST)
|
||||
sh tests/kc_syntax_test.sh $(KC)
|
||||
$(LYRA_ACCOUNT_TEST)
|
||||
$(LYRA_SYNC_TEST)
|
||||
test: kryon-compat-check kryon-boundary-check $(K2C) $(K2G) $(K2IR) $(K2B) $(KT) $(KSYNC_ACCOUNT_TEST) $(KSYNC_SYNC_TEST) $(KSYNC_CRYPTO_TEST) $(TRANSITION_TEST) $(FILE_DIALOG_BACKEND_TEST) $(MARKDOWN_TEST) $(RAYLIB_COMPAT_TEST) $(UI_TK_TEST) $(PREVIEW_TEST) $(PLATFORM_THREAD_TEST) $(UI_TEXT_EDIT_TEST) $(UI_TREE_API_TEST) $(SCENE_TREE_TEST) $(SCENE_PROPERTY_TEST) $(ANIMATION_TEST) $(KIR_TEST) $(K2IR_TEST) $(KRB_WALK_TEST) $(KRB_MOUNT_TEST) $(KRY_SW_TEST) $(KRB_LOGIC_TEST) $(KRB_ASSET_TEST) $(KRB_CAPS_TEST) $(KRB_RUN) $(KRY_TERM_TEST) $(KRY_JSON_TEST) $(KRY_HTTP_TEST) $(SFS_TEST) $(UI_WINDOW_TEST) $(UI_WINDOW_SDL_CHECK)
|
||||
sh tests/k2c_syntax_test.sh $(K2C)
|
||||
sh tests/k2g_syntax_test.sh $(K2G)
|
||||
sh tests/kt_cli_test.sh $(KT)
|
||||
sh tests/krb_cartridge_test.sh $(K2B) $(KRB_WALK_TEST) .
|
||||
sh tests/krb_engine_test.sh $(K2B) $(KRB_RUN) .
|
||||
$(KRY_SW_TEST)
|
||||
mkdir -p $(BUILD_DIR)/capstore
|
||||
mkdir -p $(BUILD_DIR)/tests/caps-fixture
|
||||
$(K2B) --root examples -o $(BUILD_DIR)/tests/caps-fixture examples/02_buttons.kry
|
||||
KRB_CAP_STORE_DIR=$(BUILD_DIR)/capstore $(KRB_CAPS_TEST) $(BUILD_DIR)/tests/caps-fixture/02_buttons.krb
|
||||
$(KRB_MOUNT_TEST)
|
||||
$(KRY_TERM_TEST)
|
||||
$(KRY_JSON_TEST)
|
||||
$(KRY_HTTP_TEST)
|
||||
$(SFS_TEST)
|
||||
$(KSYNC_ACCOUNT_TEST)
|
||||
$(KSYNC_SYNC_TEST)
|
||||
$(KSYNC_CRYPTO_TEST)
|
||||
$(TRANSITION_TEST)
|
||||
$(FILE_DIALOG_BACKEND_TEST)
|
||||
$(MARKDOWN_TEST)
|
||||
@@ -162,6 +281,11 @@ test: kryon-compat-check kryon-boundary-check $(KC) $(LYRA_ACCOUNT_TEST) $(LYRA_
|
||||
$(UI_TK_TEST)
|
||||
$(PREVIEW_TEST)
|
||||
$(PLATFORM_THREAD_TEST)
|
||||
$(UI_TEXT_EDIT_TEST)
|
||||
$(UI_TREE_API_TEST)
|
||||
$(UI_WINDOW_TEST)
|
||||
$(KIR_TEST)
|
||||
@cat $(K2IR_TEST)
|
||||
|
||||
bsd-check:
|
||||
$(MAKE) clean
|
||||
@@ -183,26 +307,42 @@ kryon-compat-check: | $(BUILD_DIR)
|
||||
kryon-boundary-check:
|
||||
sh $(KRYON_BOUNDARY_CHECK) .
|
||||
|
||||
$(LIB): $(OBJS) | $(KRYON_COMPAT_HEADER) $(KRYON_LIBOQS_A) $(KRYON_CURL_PROTOCOL_CHECK) $(KRYON_MARKDOWN_DEPS)
|
||||
$(LIB): $(OBJS) | $(BUILD_DIR) $(KRYON_COMPAT_HEADER) $(KRYON_LIBOQS_A) $(KRYON_CURL_PROTOCOL_CHECK) $(KRYON_MARKDOWN_DEPS) $(KRYON_PHYSICS_DEPS)
|
||||
rm -f $@
|
||||
$(AR) $(ARFLAGS) $@ $(OBJS)
|
||||
|
||||
KC_SRCS := cmd/kc/kc.c cmd/kc/kc_macros.c
|
||||
K2C_SRCS := $(sort $(wildcard cmd/k2c/*.c)) cmd/kir/kir.c cmd/kir/kir_parse.c
|
||||
K2C_HDRS := cmd/k2c/k2c_lower.h cmd/kir/kir.h cmd/kir/kir_parse.h
|
||||
|
||||
$(KC): $(KC_SRCS) cmd/kc/kc_internal.h | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) -o $@ $(KC_SRCS)
|
||||
$(K2C): $(K2C_SRCS) $(K2C_HDRS) | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) -Icmd/kir -o $@ $(K2C_SRCS)
|
||||
|
||||
$(KRYON_APP): scripts/kryon-app.sh | $(BUILD_DIR)/bin
|
||||
cp scripts/kryon-app.sh $@
|
||||
chmod 755 $@
|
||||
K2G_SRCS := $(sort $(wildcard cmd/k2g/*.c)) cmd/kir/kir.c cmd/kir/kir_parse.c
|
||||
$(K2G): $(K2G_SRCS) cmd/kir/kir.h cmd/kir/kir_parse.h | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) -Icmd/kir -o $@ $(K2G_SRCS)
|
||||
|
||||
$(KI): cmd/ki/main.c $(LIB) $(RAYLIB_A) $(KRYON_LIBOQS_A) $(KRYON_CURL_A) $(KRYON_MARKDOWN_DEPS) | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -Isrc/ui $(RAY_CFLAGS) -o $@ \
|
||||
cmd/ki/main.c \
|
||||
K2IR_SRCS := $(sort $(wildcard cmd/k2ir/*.c)) cmd/kir/kir.c cmd/kir/kir_parse.c
|
||||
$(K2IR): $(K2IR_SRCS) cmd/kir/kir.h cmd/kir/kir_parse.h | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) -Icmd/kir -o $@ $(K2IR_SRCS)
|
||||
|
||||
K2B_SRCS := $(sort $(wildcard cmd/k2b/*.c)) cmd/kir/kir.c cmd/kir/kir_parse.c
|
||||
$(K2B): $(K2B_SRCS) cmd/kir/kir.h cmd/kir/kir_parse.h | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) -Iinclude -Icmd/kir -o $@ $(K2B_SRCS) -lm
|
||||
|
||||
$(KT): cmd/kt/main.c | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS_BASE) -o $@ cmd/kt/main.c
|
||||
|
||||
$(KRYON_PREVIEW): cmd/kryon-preview/main.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ cmd/kryon-preview/main.c \
|
||||
-Wl,-export-dynamic \
|
||||
-Wl,--whole-archive $(LIB) -Wl,--no-whole-archive \
|
||||
$(RAYLIB_A) $(KRYON_LIBOQS_A) $(KRYON_CURL_LDLIBS) \
|
||||
$(KRYON_MARKDOWN_LDLIBS) \
|
||||
-Wl,-export-dynamic $(RAY_LDLIBS) $(LDLIBS) \
|
||||
$(CURL_CODEC_LDLIBS) -lz -lpthread -lm
|
||||
$(KRYON_BACKEND_LIBS) $(KRYON_PHYSICS_DEPS) $(KRYON_BACKEND_LDLIBS) $(KRYON_LIBOQS_A) \
|
||||
$(KRYON_CURL_LDLIBS) $(KRYON_MARKDOWN_LDLIBS) \
|
||||
$(CURL_CODEC_LDLIBS) $(LDLIBS) -lpthread -lm
|
||||
|
||||
$(KRYON_CMD): scripts/kryon.sh | $(BUILD_DIR)/bin
|
||||
cp scripts/kryon.sh $@
|
||||
chmod 755 $@
|
||||
|
||||
version:
|
||||
@printf '%s\n' '$(VERSION)'
|
||||
@@ -216,6 +356,11 @@ dist-static: release-check $(STATIC_DIST_ARCHIVE)
|
||||
check-static-package: $(STATIC_DIST_ARCHIVE)
|
||||
sh scripts/check-static-package.sh $(STATIC_DIST_ARCHIVE)
|
||||
|
||||
dist-tools: release-check $(TOOLS_DIST_ARCHIVE)
|
||||
|
||||
check-tools-package: $(TOOLS_DIST_ARCHIVE)
|
||||
sh scripts/check-tools-package.sh $(TOOLS_DIST_ARCHIVE)
|
||||
|
||||
install-static: $(STATIC_DIST_ARCHIVE)
|
||||
mkdir -p $(DESTDIR)$(PREFIX)
|
||||
tar -xzf $(STATIC_DIST_ARCHIVE) -C $(DESTDIR)$(PREFIX) --strip-components=1
|
||||
@@ -267,18 +412,39 @@ $(STATIC_DIST_ARCHIVE): $(LIB) $(RAYLIB_A) $(KRYON_LIBOQS_A) $(KRYON_CURL_A) $(K
|
||||
> $(STATIC_DIST_ROOT)/lib/cmake/kryon/KryonConfig.cmake
|
||||
tar -C $(BUILD_DIR)/dist -czf $@ kryon-$(VERSION)-static
|
||||
|
||||
$(LYRA_ACCOUNT_TEST): tests/lyra_account_test.c src/lyra/lyra_account.c include/lyra_account.h $(KRYON_LIBOQS_A) | $(BUILD_DIR)
|
||||
$(TOOLS_DIST_ARCHIVE): tools README.md LICENSE THIRD_PARTY_NOTICES.md scripts/check-tools-package.sh
|
||||
rm -rf $(TOOLS_DIST_ROOT)
|
||||
mkdir -p $(TOOLS_DIST_ROOT)/bin $(DIST_DIR)
|
||||
cp $(K2C) $(K2G) $(K2IR) $(K2B) $(KT) $(KRYON_PREVIEW) $(KRYON_CMD) $(KRB_RUN) $(KRB_SDL) $(TOOLS_DIST_ROOT)/bin/
|
||||
chmod 755 $(TOOLS_DIST_ROOT)/bin/*
|
||||
printf '%s\n' '$(VERSION)' > $(TOOLS_DIST_ROOT)/VERSION
|
||||
cp README.md LICENSE THIRD_PARTY_NOTICES.md $(TOOLS_DIST_ROOT)/
|
||||
printf '%s\n' \
|
||||
'{' \
|
||||
' "name": "kryon-tools",' \
|
||||
' "version": "$(VERSION)",' \
|
||||
' "target": "$(KRYON_PLATFORM)-$(KRYON_ARCH)",' \
|
||||
' "binaries": ["k2c", "k2g", "k2ir", "k2b", "kt", "kryon", "kryon-preview", "krb-run", "krb-sdl"]' \
|
||||
'}' > $(TOOLS_DIST_ROOT)/manifest.json
|
||||
tar -C $(BUILD_DIR)/dist -czf $@ $(notdir $(TOOLS_DIST_ROOT))
|
||||
|
||||
$(KSYNC_ACCOUNT_TEST): tests/ksync_account_test.c src/ksync/ksync_account.c src/ksync/ksync_crypto.c include/ksync_account.h include/ksync_crypto.h $(KRYON_LIBOQS_A) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -DHAS_LIBOQS=1 $(KRYON_LIBOQS_INCLUDE) \
|
||||
tests/lyra_account_test.c src/lyra/lyra_account.c \
|
||||
tests/ksync_account_test.c src/ksync/ksync_account.c src/ksync/ksync_crypto.c \
|
||||
$(KRYON_LIBOQS_A) -lm -o $@
|
||||
|
||||
$(LYRA_SYNC_TEST): tests/lyra_sync_test.c src/lyra/lyra_sync.c src/lyra/lyra_account.c include/lyra_sync.h include/lyra_account.h $(KRYON_LIBOQS_A) | $(BUILD_DIR)
|
||||
$(KSYNC_SYNC_TEST): tests/ksync_sync_test.c src/ksync/ksync_sync.c src/ksync/ksync_account.c src/ksync/ksync_crypto.c include/ksync_sync.h include/ksync_account.h include/ksync_crypto.h $(KRYON_LIBOQS_A) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -DHAS_LIBOQS=1 $(KRYON_LIBOQS_INCLUDE) \
|
||||
tests/lyra_sync_test.c src/lyra/lyra_sync.c src/lyra/lyra_account.c \
|
||||
tests/ksync_sync_test.c src/ksync/ksync_sync.c src/ksync/ksync_account.c \
|
||||
src/ksync/ksync_crypto.c \
|
||||
$(KRYON_LIBOQS_A) -lm -o $@
|
||||
|
||||
$(KSYNC_CRYPTO_TEST): tests/ksync_crypto_test.c src/ksync/ksync_crypto.c include/ksync_crypto.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/ksync_crypto_test.c src/ksync/ksync_crypto.c -o $@
|
||||
|
||||
$(TRANSITION_TEST): tests/transition_test.c src/ui/ui_transition.c include/ui_transition.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/transition_test.c src/ui/ui_transition.c -o $@
|
||||
@@ -291,24 +457,24 @@ $(MARKDOWN_TEST): tests/markdown_test.c src/markdown.c include/markdown.h $(KRYO
|
||||
|
||||
$(FILE_DIALOG_BACKEND_TEST): tests/file_dialog_backend_test.c src/file_dialog/file_dialog.c include/file_dialog.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/file_dialog_backend_test.c src/file_dialog/file_dialog.c -o $@
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/file_dialog_backend_test.c src/file_dialog/file_dialog.c $(LDLIBS) -o $@
|
||||
|
||||
$(RAYLIB_COMPAT_TEST): tests/raylib_compat_test.c $(LIB) $(RAYLIB_A) | $(BUILD_DIR)
|
||||
$(RAYLIB_COMPAT_TEST): tests/raylib_compat_test.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/raylib_compat_test.c \
|
||||
$(LIB) $(RAYLIB_A) $(RAYLIB_COMPAT_LDLIBS) \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(RAYLIB_COMPAT_LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(UI_TK_TEST): tests/ui_tk_test.c $(LIB) $(RAYLIB_A) | $(BUILD_DIR)
|
||||
$(UI_TK_TEST): tests/ui_tk_test.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/ui_tk_test.c \
|
||||
$(LIB) $(RAYLIB_A) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(PREVIEW_TEST): tests/preview_test.c $(LIB) $(RAYLIB_A) | $(BUILD_DIR)
|
||||
$(PREVIEW_TEST): tests/preview_test.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/preview_test.c \
|
||||
$(LIB) $(RAYLIB_A) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(PLATFORM_THREAD_TEST): tests/platform_thread_test.c src/platform/platform_thread.c include/platform.h | $(BUILD_DIR)
|
||||
@@ -316,6 +482,125 @@ $(PLATFORM_THREAD_TEST): tests/platform_thread_test.c src/platform/platform_thre
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/platform_thread_test.c \
|
||||
src/platform/platform_thread.c -lpthread -o $@
|
||||
|
||||
$(UI_TEXT_EDIT_TEST): tests/ui_text_edit_test.c src/ui/ui_text_edit.c include/kryon.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/ui_text_edit_test.c src/ui/ui_text_edit.c -o $@
|
||||
|
||||
$(UI_TREE_API_TEST): tests/ui_tree_api_test.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/ui_tree_api_test.c \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(UI_WINDOW_TEST): tests/ui_window_test.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/ui_window_test.c \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
# Compile-only coverage for the SDL secondary-window presenter (Wayland and
|
||||
# SDL-bundled platforms). The default Linux/FreeBSD build takes the X11 path,
|
||||
# so without this the UI_WINDOW_HAVE_SDL branch would rot uncompiled.
|
||||
$(UI_WINDOW_SDL_CHECK): src/ui/ui_window.c $(KRYON_COMPAT_HEADER) $(KRYON_BACKEND_RENAME_HEADER) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -DUI_WINDOW_HAVE_SDL \
|
||||
$(RAY_SDL_CFLAGS) $(RAY_GL_CFLAGS) -I$(RAY_SDL_INCLUDE_DIR) \
|
||||
-c $< -o $@
|
||||
|
||||
$(TEXT_INPUT_PERF_TEST): tests/text_input_perf_test.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/text_input_perf_test.c \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
perf-text-input: $(K2IR) $(K2C) $(K2G) $(K2B) $(TEXT_INPUT_PERF_TEST)
|
||||
sh tests/text_input_perf.sh . $(BUILD_DIR)
|
||||
|
||||
$(SCENE_TREE_TEST): tests/scene_tree_test.c $(LIB) $(KRYON_BACKEND_LIBS) $(KRYON_PHYSICS_DEPS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/scene_tree_test.c \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(KRYON_PHYSICS_DEPS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(SCENE_PROPERTY_TEST): tests/scene_property_test.c $(LIB) $(KRYON_BACKEND_LIBS) $(KRYON_PHYSICS_DEPS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/scene_property_test.c \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(KRYON_PHYSICS_DEPS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(ANIMATION_TEST): tests/animation_test.c $(LIB) $(KRYON_BACKEND_LIBS) $(KRYON_PHYSICS_DEPS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/animation_test.c \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(KRYON_PHYSICS_DEPS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(KIR_TEST): tests/kir_test.c cmd/kir/kir.c cmd/kir/kir.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CFLAGS) -Icmd/kir tests/kir_test.c cmd/kir/kir.c -o $@
|
||||
|
||||
$(K2IR_TEST): tests/k2ir_test.sh $(K2IR) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
TMPDIR=$(BUILD_DIR) sh tests/k2ir_test.sh $(K2IR) . > $@
|
||||
|
||||
$(KRB_WALK_TEST): tests/krb_walk_test.c src/krb/krb.c src/backend/kry_backend.c include/krb.h include/kry_backend.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/krb_walk_test.c src/krb/krb.c \
|
||||
src/backend/kry_backend.c -o $@
|
||||
|
||||
$(KRB_MOUNT_TEST): tests/krb_mount_test.c src/krb/krb.c src/backend/kry_backend.c include/krb.h include/kry_backend.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/krb_mount_test.c src/krb/krb.c \
|
||||
src/backend/kry_backend.c -o $@
|
||||
|
||||
KRY_SW_SRCS = src/krb/krb.c src/krb/krb_caps.c src/backend/kry_backend.c \
|
||||
src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend_rec.c
|
||||
KRY_SW_HDRS = include/krb.h include/kry_backend.h include/kry_sw.h \
|
||||
include/kry_backend_rec.h
|
||||
|
||||
$(KRB_RUN): cmd/krb-run/main.c cmd/krb-run/png_write.c cmd/krb-run/png_write.h $(KRY_SW_SRCS) $(KRY_SW_HDRS) | $(BUILD_DIR)/bin
|
||||
$(CC) $(CFLAGS) -Iinclude -Icmd/krb-run -o $@ cmd/krb-run/main.c \
|
||||
cmd/krb-run/png_write.c $(KRY_SW_SRCS) -lm
|
||||
|
||||
$(KRY_SW_TEST): tests/kry_sw_test.c src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend_rec.c src/backend/kry_backend.c include/kry_sw.h include/kry_backend_rec.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/kry_sw_test.c src/backend/kry_sw.c \
|
||||
src/backend/kry_sw_png.c \
|
||||
src/backend/kry_backend_rec.c src/backend/kry_backend.c -o $@ -lm
|
||||
|
||||
$(KRB_LOGIC_TEST): tests/krb_logic_test.c src/krb/krb.c src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend.c include/krb.h include/kry_sw.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/krb_logic_test.c src/krb/krb.c \
|
||||
src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend.c -o $@ -lm
|
||||
|
||||
$(KRB_ASSET_TEST): tests/krb_asset_test.c src/krb/krb.c src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend.c include/krb.h include/kry_sw.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/krb_asset_test.c src/krb/krb.c \
|
||||
src/backend/kry_sw.c src/backend/kry_sw_png.c src/backend/kry_backend.c -o $@ -lm
|
||||
|
||||
$(KRB_CAPS_TEST): tests/krb_caps_test.c src/krb/krb.c src/krb/krb_caps.c include/krb.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/krb_caps_test.c src/krb/krb.c \
|
||||
src/krb/krb_caps.c src/backend/kry_backend.c -o $@ -lm
|
||||
|
||||
$(KRY_TERM_TEST): tests/kry_term_test.c src/kry_std/kry_term.c include/kry_term.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/kry_term_test.c src/kry_std/kry_term.c -o $@
|
||||
|
||||
$(SFS_TEST): tests/sfs_test.c $(LIB) $(KRYON_BACKEND_LIBS) | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/sfs_test.c \
|
||||
$(LIB) $(KRYON_BACKEND_LIBS) $(RAYLIB_COMPAT_LDLIBS) $(LDLIBS) \
|
||||
-o $@
|
||||
|
||||
$(KRY_JSON_TEST): tests/kry_json_test.c src/kry_std/kry_json.c include/kry_json.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) tests/kry_json_test.c src/kry_std/kry_json.c -o $@
|
||||
|
||||
$(KRY_HTTP_TEST): tests/kry_http_test.c src/kry_std/kry_http.c src/platform/platform_thread.c include/kry_http.h include/platform.h | $(BUILD_DIR)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(KRYON_CURL_CFLAGS) tests/kry_http_test.c src/kry_std/kry_http.c src/platform/platform_thread.c $(KRYON_CURL_LDLIBS) $(KRYON_CURL_TRANSITIVE_LDLIBS) -o $@
|
||||
|
||||
|
||||
$(ICON_ASSETS_C): $(ICON_FILES) scripts/embed-icons.sh include/ui_icons.h
|
||||
sh scripts/embed-icons.sh "$(ICON_DIR)" $@
|
||||
|
||||
@@ -327,11 +612,11 @@ $(EMBED_ASSETS_C): $(EMBED_ASSET_FILES) scripts/embed-assets.sh include/embedded
|
||||
|
||||
$(BUILD_DIR)/%.o: src/%.c | $(BUILD_DIR) $(KRYON_LIBOQS_A) $(KRYON_CURL_PROTOCOL_CHECK) $(KRYON_MARKDOWN_DEPS)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c | $(BUILD_DIR) $(KRYON_LIBOQS_A) $(KRYON_CURL_PROTOCOL_CHECK) $(KRYON_MARKDOWN_DEPS)
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $@
|
||||
@@ -341,3 +626,10 @@ $(BUILD_DIR)/bin:
|
||||
|
||||
font-assets:
|
||||
@printf '%s\n' 'font assets are checked in or supplied by downstream apps'
|
||||
|
||||
font-subsets:
|
||||
@if [ -z "$(strip $(FONT_SUBSET_CORPUS))" ]; then \
|
||||
echo "Set FONT_SUBSET_CORPUS to one or more files/directories"; \
|
||||
exit 1; \
|
||||
fi
|
||||
sh scripts/subset-fonts.sh "$(FONT_SUBSET_OUT_DIR)" "$(FONT_SUBSET_SOURCE_DIR)" "$(FONT_SUBSET_PREFIX)" $(FONT_SUBSET_CORPUS)
|
||||
@@ -4,7 +4,7 @@ Kryon is a small C support library for raylib-style applications. It keeps a
|
||||
raylib-compatible public surface available through `kryon.h`, then adds the
|
||||
pieces shared by downstream apps: UI controls, Tk-style toolkit widgets, layout
|
||||
helpers, text rendering, themes, embedded assets, locale loading, file dialogs,
|
||||
desktop tray support, runtime asset downloads, and Lyra account/sync helpers.
|
||||
desktop tray support, runtime asset downloads, and Ksync account/sync helpers.
|
||||
|
||||
## Layout
|
||||
|
||||
@@ -66,11 +66,19 @@ paths are supplied at build time.
|
||||
|
||||
## Releases
|
||||
|
||||
Kryon releases are tag-driven. Run the `Release` GitHub Actions workflow with a
|
||||
version such as `v0.1.0`; the workflow validates the version, creates and pushes
|
||||
the annotated tag, checks out that tag, builds and tests Kryon, packages the
|
||||
static-library archive, uploads it as an artifact, and attaches it to the GitHub
|
||||
release. Pushing a `v*` tag manually uses the same build-and-publish path.
|
||||
Every successful CI run on `master` automatically advances the patch version,
|
||||
commits `include/kryon_version.h`, and starts the tag-driven `Release` workflow.
|
||||
The workflow validates the version, creates an annotated tag, builds and tests
|
||||
Kryon, and publishes both the static SDK and a checksummed native tools bundle.
|
||||
The tools bundle contains `k2c`, `k2g`, `k2ir`, `k2b`, `kt`, `kryon`,
|
||||
`kryon-preview`, `krb-run`, and `krb-sdl`. The renderer workflow also attaches
|
||||
the Linux, Windows, and macOS `krb-run` builds plus the web player to the same
|
||||
release.
|
||||
|
||||
Maintainers can still run `Release` manually for the checked-in version. Use
|
||||
`scripts/bump-version.sh minor` / `major` before pushing when a non-patch bump is
|
||||
required. Pushing a matching `v*` tag manually uses the same build-and-publish
|
||||
path; releases reject tags that disagree with the public version header.
|
||||
|
||||
## Integration
|
||||
|
||||
@@ -92,43 +100,58 @@ variables through to the vendored curl CMake build.
|
||||
|
||||
## App Builds
|
||||
|
||||
Kryon owns the app command surface through `kryon-app`. From an app repository:
|
||||
Kryon owns the app command surface through `kryon`. From an app repository:
|
||||
|
||||
```sh
|
||||
kryon-app build native
|
||||
kryon-app build web
|
||||
kryon-app build android-debug
|
||||
kryon-app package appimage
|
||||
kryon-app preview
|
||||
kryon build native
|
||||
kryon build web
|
||||
kryon build android-debug
|
||||
kryon package appimage
|
||||
kryon preview
|
||||
```
|
||||
|
||||
App `project.kryon` files should use `target` entries that call `kryon-app`
|
||||
For local development against a sync backend, run a Ksync server in the
|
||||
foreground. `dev-backend` locates the server source at `$KSYNC_DIR` or as a
|
||||
sibling checkout (`../ksync`), isolates its data under `<project>/.kryon/`, and
|
||||
prints the sync URL to point your app at. Tokens are regenerated each start,
|
||||
so it is for local development only:
|
||||
|
||||
```sh
|
||||
kryon dev-backend # serves http://127.0.0.1:8080
|
||||
```
|
||||
|
||||
App `project.kryon` files should use `target` entries that call `kryon`
|
||||
rather than embedding platform-specific build commands directly. Existing app
|
||||
Makefiles can remain as backend glue while repeated native, web, Android, and
|
||||
packaging logic moves into Kryon `mk/` fragments.
|
||||
|
||||
## Preview Projects
|
||||
|
||||
Kryon IDE can host richer project previews without requiring the project to be
|
||||
rewritten as `.kry` screens. A project can add `project.kryon` metadata such as
|
||||
`preview_size`, `preview_asset_root`, and `preview_scene`, then provide a
|
||||
`build_live` command that builds `build/kryon/live_preview.so`. The live module
|
||||
continues to expose the normal `CreateKryonLivePreview`/`AppHost` entry point,
|
||||
and can optionally expose `CreateKryonPreviewHost` for future scene/layer editing
|
||||
metadata. This keeps gameplay or simulation code in the app while letting Kryon
|
||||
IDE select scenes, draw interactive previews, and eventually edit shared preview
|
||||
layers.
|
||||
Krait, the standalone Kryon IDE (a separate `kryonlabs/krait` repo that vendors
|
||||
Kryon), previews `.kry` source by compiling it to an app host and loading it
|
||||
into the embedded viewport. On each source change Krait rebuilds the project's
|
||||
app host (`make kryon-host`, producing `build/kryon/app_host.so`), `dlopen`s
|
||||
it, and resolves `CreateAppHost`/`DestroyAppHost`. The build runs in the
|
||||
background (`fork` + non-blocking pipe, drained each frame) so the window stays
|
||||
responsive during the compile; once it finishes the new app host is loaded and
|
||||
the preview updates. Source changes are polled a few times per second. Kryon
|
||||
itself owns the preview host tooling (`kryon-preview`); it must not depend on
|
||||
Krait.
|
||||
|
||||
A project can add `project.kryon` metadata such as `preview_size`,
|
||||
`preview_asset_root`, and `preview_scene` to control the embedded viewport.
|
||||
|
||||
## Conventions
|
||||
|
||||
Kryon follows raylib-style C conventions where practical: lowercase module
|
||||
filenames, simple C structs, and public functions named like raylib APIs
|
||||
(`InitWindow`, `DrawTexture`, `BeginUIFrame`, `DrawUIButton`). Internal helpers
|
||||
(`InitWindow`, `DrawTexture`, `BeginUIFrame`, `UIButtonNode`). Internal helpers
|
||||
stay private to `src/` unless a downstream app needs the API in `include/`.
|
||||
|
||||
## Documentation
|
||||
|
||||
- `docs/API.md` documents the public API.
|
||||
- `docs/plans/` contains the KIR, C backend, and KRB cartridge roadmap.
|
||||
- `docs/site/` contains the static documentation website.
|
||||
- `docs/AGENTS.md` documents how downstream apps should use Kryon, including
|
||||
modal/input capture and submodule update rules.
|
||||
@@ -143,7 +166,30 @@ feature family.
|
||||
|
||||
## Kry Language Direction
|
||||
|
||||
`docs/KRY_LANGUAGE_PLAN.md` describes the migration path for making `.kry` a
|
||||
C-close, C-transpiled app language with direct C interoperability. The goal is
|
||||
for apps to move product UI and screen controllers into Kry while keeping native
|
||||
platform, storage, and performance-sensitive code in C.
|
||||
`docs/KRY_LANGUAGE_PLAN.md` describes the path for making `.kry` a C-close app
|
||||
language with two clean compiler outputs. Kry source lowers into KIR, a
|
||||
debuggable intermediate representation with source spans. From there `k2c`
|
||||
emits readable C for native apps, `k2g` emits Go source driving the cgo
|
||||
runtime binding, while `k2b` emits a portable `.krb`
|
||||
cartridge (`docs/KRB_FORMAT.md`) for renderers that implement the Kryon runtime
|
||||
contract. The intended tool set is Unix-shaped:
|
||||
|
||||
```text
|
||||
k2ir app.kry # .kry -> .kir
|
||||
k2c app.kry|app.kir
|
||||
k2g app.kry # .kry -> Go (cgo runtime)
|
||||
k2b app.kry|app.kir
|
||||
```
|
||||
|
||||
Go applications import the maintained cgo runtime from
|
||||
`github.com/waozixyz/kryon/go/kryui`. The binding lives in this repository so
|
||||
generated `k2g` code and handwritten Go hosts share one Kryon-owned surface;
|
||||
downstream applications must not carry private copies of it.
|
||||
|
||||
`k2g` output is compiled against that real runtime by the test suite. This is
|
||||
an executable compatibility gate, not only a textual generated-source check.
|
||||
|
||||
`k2c` and `k2b` accept either `.kry` or `.kir`; when given source, they run the
|
||||
KIR frontend internally. Native platform, storage, and performance-sensitive C
|
||||
code remains first-class through the C backend and through explicit KRB
|
||||
capabilities or host imports.
|
||||
@@ -0,0 +1,240 @@
|
||||
#include "k2b_atlas.h"
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include "../../vendor/raylib/src/external/stb_truetype.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ATLAS_W 512
|
||||
|
||||
static void
|
||||
put_u16(unsigned char *p, unsigned v)
|
||||
{
|
||||
p[0] = (unsigned char)v;
|
||||
p[1] = (unsigned char)(v >> 8);
|
||||
}
|
||||
|
||||
static void
|
||||
put_u32(unsigned char *p, unsigned long v)
|
||||
{
|
||||
p[0] = (unsigned char)v;
|
||||
p[1] = (unsigned char)(v >> 8);
|
||||
p[2] = (unsigned char)(v >> 16);
|
||||
p[3] = (unsigned char)(v >> 24);
|
||||
}
|
||||
|
||||
/* Layout: "KFA1" u32 | size_count u16 | per-size 16-byte records
|
||||
* (px u16 | glyphs u16 | w u16 | h u16 | table_off u32 | pixels_off u32),
|
||||
* per-glyph 18-byte records (cp u32 | x,y,w,h u16 | xoff,yoff i16 |
|
||||
* adv u16 in 1/256 px fixed point), then per-size RGBA8 white-on-alpha
|
||||
* bitmaps.
|
||||
*
|
||||
* Rasterization is raylib-identical: per-glyph
|
||||
* stbtt_GetCodepointBitmap at stbtt_ScaleForPixelHeight(size) with
|
||||
* advances from stbtt_GetCodepointHMetrics * scale — the same calls
|
||||
* rtext.c LoadFontData(FONT_DEFAULT) makes, so glyph coverage matches
|
||||
* the native renderer bit-for-bit. Glyphs row-pack first-fit. */
|
||||
unsigned char *
|
||||
k2b_bake_atlas(const char *ttf_path, const unsigned int *codepoints,
|
||||
int cp_count, const int *sizes, int size_count,
|
||||
unsigned *out_len)
|
||||
{
|
||||
unsigned char *ttf = NULL;
|
||||
long ttf_len;
|
||||
FILE *f;
|
||||
stbtt_fontinfo font;
|
||||
unsigned char *buf = NULL;
|
||||
unsigned buf_cap;
|
||||
unsigned buf_len;
|
||||
int s;
|
||||
|
||||
if(out_len != NULL)
|
||||
*out_len = 0;
|
||||
if(ttf_path == NULL || codepoints == NULL || cp_count <= 0 ||
|
||||
sizes == NULL || size_count <= 0)
|
||||
return NULL;
|
||||
f = fopen(ttf_path, "rb");
|
||||
if(f == NULL)
|
||||
return NULL;
|
||||
fseek(f, 0, SEEK_END);
|
||||
ttf_len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
ttf = malloc((size_t)ttf_len);
|
||||
if(ttf == NULL || fread(ttf, 1, (size_t)ttf_len, f) != (size_t)ttf_len) {
|
||||
fclose(f);
|
||||
free(ttf);
|
||||
return NULL;
|
||||
}
|
||||
fclose(f);
|
||||
if(!stbtt_InitFont(&font, ttf, 0)) {
|
||||
free(ttf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf_len = 6 + (unsigned)size_count * 16;
|
||||
buf_cap = buf_len + 4096;
|
||||
buf = malloc(buf_cap);
|
||||
if(buf == NULL) {
|
||||
free(ttf);
|
||||
return NULL;
|
||||
}
|
||||
put_u32(buf, 0x3141464Bu); /* "KFA1" */
|
||||
put_u16(buf + 4, (unsigned)size_count);
|
||||
|
||||
for(s = 0; s < size_count; s++) {
|
||||
int px = sizes[s];
|
||||
float scale = stbtt_ScaleForPixelHeight(&font, (float)px);
|
||||
int ascent = 0;
|
||||
int descent = 0;
|
||||
int line_gap = 0;
|
||||
|
||||
/* rtext.c line 730: offsetY += (int)(ascent*scale) — raylib's
|
||||
* glyph offset is line-top-relative, not baseline-relative */
|
||||
stbtt_GetFontVMetrics(&font, &ascent, &descent, &line_gap);
|
||||
unsigned char *raw_px;
|
||||
unsigned rec_bytes = (unsigned)cp_count * 18;
|
||||
unsigned table_off;
|
||||
unsigned pixels_off;
|
||||
int height;
|
||||
int i;
|
||||
|
||||
/* rec is recomputed after every realloc of buf */
|
||||
{
|
||||
int total_h = 1;
|
||||
int row_h = 0;
|
||||
int cur_x = 0;
|
||||
|
||||
for(i = 0; i < cp_count; i++) {
|
||||
int x0 = 0;
|
||||
int y0 = 0;
|
||||
int x1 = 0;
|
||||
int y1 = 0;
|
||||
int w;
|
||||
int h;
|
||||
|
||||
stbtt_GetCodepointBitmapBox(&font, (int)codepoints[i], scale,
|
||||
scale, &x0, &y0, &x1, &y1);
|
||||
w = x1 - x0;
|
||||
h = y1 - y0;
|
||||
if(w < 0)
|
||||
w = 0;
|
||||
if(h < 0)
|
||||
h = 0;
|
||||
if(cur_x + w > ATLAS_W) {
|
||||
total_h += row_h > 0 ? row_h : 1;
|
||||
row_h = 0;
|
||||
cur_x = 0;
|
||||
}
|
||||
cur_x += w + 1;
|
||||
if(h > row_h)
|
||||
row_h = h;
|
||||
}
|
||||
height = total_h + row_h + 1;
|
||||
}
|
||||
while(buf_len + rec_bytes + (unsigned)ATLAS_W * height * 4 >
|
||||
buf_cap) {
|
||||
unsigned char *nb = realloc(buf, buf_cap * 2);
|
||||
|
||||
if(nb == NULL)
|
||||
break;
|
||||
buf = nb;
|
||||
buf_cap *= 2;
|
||||
}
|
||||
if(buf_len + rec_bytes + (unsigned)ATLAS_W * height * 4 > buf_cap)
|
||||
continue;
|
||||
raw_px = calloc((size_t)ATLAS_W * height, 1);
|
||||
if(raw_px == NULL)
|
||||
continue;
|
||||
table_off = buf_len;
|
||||
{
|
||||
int row_y = 0;
|
||||
int row_h = 0;
|
||||
int cur_x = 0;
|
||||
unsigned char *tab = buf + table_off;
|
||||
|
||||
for(i = 0; i < cp_count; i++) {
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
int xoff = 0;
|
||||
int yoff = 0;
|
||||
int advance = 0;
|
||||
int lsb = 0;
|
||||
unsigned char *bm;
|
||||
unsigned char *g = tab + (unsigned)i * 18;
|
||||
|
||||
bm = stbtt_GetCodepointBitmap(&font, scale, scale,
|
||||
(int)codepoints[i], &w, &h,
|
||||
&xoff, &yoff);
|
||||
if(cur_x + w > ATLAS_W) {
|
||||
row_y += row_h > 0 ? row_h : 1;
|
||||
row_h = 0;
|
||||
cur_x = 0;
|
||||
}
|
||||
if(w > 0 && h > 0 && bm != NULL && w <= ATLAS_W &&
|
||||
row_y + h <= height && cur_x + w <= ATLAS_W) {
|
||||
int gy;
|
||||
|
||||
for(gy = 0; gy < h; gy++)
|
||||
memcpy(raw_px + (size_t)(row_y + gy) * ATLAS_W +
|
||||
cur_x, bm + (size_t)gy * w, (size_t)w);
|
||||
}
|
||||
stbtt_FreeBitmap(bm, NULL);
|
||||
stbtt_GetCodepointHMetrics(&font, (int)codepoints[i],
|
||||
&advance, &lsb);
|
||||
put_u32(g, codepoints[i]);
|
||||
put_u16(g + 4, (unsigned short)cur_x);
|
||||
put_u16(g + 6, (unsigned short)row_y);
|
||||
put_u16(g + 8, (unsigned short)(w > 0 ? w : 0));
|
||||
put_u16(g + 10, (unsigned short)(h > 0 ? h : 0));
|
||||
put_u16(g + 12, (unsigned short)(short)xoff);
|
||||
put_u16(g + 14,
|
||||
(unsigned short)(short)(yoff +
|
||||
(int)((float)ascent * scale)));
|
||||
put_u16(g + 16, (unsigned short)(int)((float)advance *
|
||||
scale * 256.0f + 0.5f));
|
||||
cur_x += w + 1;
|
||||
if(h > row_h)
|
||||
row_h = h;
|
||||
}
|
||||
buf_len += rec_bytes;
|
||||
}
|
||||
pixels_off = buf_len;
|
||||
{
|
||||
unsigned char *rgba = buf + pixels_off;
|
||||
long n = (long)ATLAS_W * height;
|
||||
long k;
|
||||
|
||||
for(k = 0; k < n; k++) {
|
||||
rgba[k * 4 + 0] = 0xff;
|
||||
rgba[k * 4 + 1] = 0xff;
|
||||
rgba[k * 4 + 2] = 0xff;
|
||||
rgba[k * 4 + 3] = raw_px[k];
|
||||
}
|
||||
buf_len += (unsigned)n * 4;
|
||||
}
|
||||
free(raw_px);
|
||||
{
|
||||
unsigned char *rec = buf + 6 + (unsigned)s * 16;
|
||||
|
||||
put_u16(rec, (unsigned)px);
|
||||
put_u16(rec + 2, (unsigned)cp_count);
|
||||
put_u16(rec + 4, ATLAS_W);
|
||||
put_u16(rec + 6, (unsigned)height);
|
||||
put_u16(rec + 2, (unsigned)cp_count);
|
||||
put_u16(rec + 4, ATLAS_W);
|
||||
put_u16(rec + 6, (unsigned)height);
|
||||
put_u32(rec + 8, table_off);
|
||||
put_u32(rec + 12, pixels_off);
|
||||
}
|
||||
}
|
||||
free(ttf);
|
||||
if(buf_len <= 6 + (unsigned)size_count * 16) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
if(out_len != NULL)
|
||||
*out_len = buf_len;
|
||||
return buf;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef K2B_ATLAS_H
|
||||
#define K2B_ATLAS_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* Bake a KFA1 glyph atlas (cartridge asset kind 1) from a TTF for the
|
||||
* given charset and pixel sizes. Returns malloc'd bytes and length, or
|
||||
* NULL when the font can't be loaded. Layout:
|
||||
* u32 'KFA1' | u16 size_count
|
||||
* per size: u16 px, u16 glyph_count, u16 w, u16 h, u32 table_off,
|
||||
* u32 pixels_off (offsets from buffer start)
|
||||
* glyph (16B): u32 cp | u16 x,y,w,h | i16 xoff,yoff | u16 advance
|
||||
* RGBA8 pixels, white with alpha coverage. */
|
||||
unsigned char *k2b_bake_atlas(const char *ttf_path,
|
||||
const unsigned int *codepoints, int cp_count,
|
||||
const int *sizes, int size_count,
|
||||
unsigned *out_len);
|
||||
|
||||
#endif
|
||||
+2882
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,23 @@
|
||||
#include "k2b_stb.h"
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STBI_NO_PSD
|
||||
#define STBI_NO_TGA
|
||||
#define STBI_NO_GIF
|
||||
#define STBI_NO_HDR
|
||||
#define STBI_NO_PIC
|
||||
#define STBI_NO_PNM
|
||||
#include "../../vendor/raylib/src/external/stb_image.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
k2b_decode_image(const char *file, unsigned char **rgba, int *w, int *h)
|
||||
{
|
||||
int n;
|
||||
|
||||
if(file == NULL || rgba == NULL || w == NULL || h == NULL)
|
||||
return -1;
|
||||
*rgba = stbi_load(file, w, h, &n, 4);
|
||||
return *rgba != NULL ? 0 : -1;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef K2B_STB_H
|
||||
#define K2B_STB_H
|
||||
|
||||
/* Image decoding for cartridge embedding, on the stb_image vendored with
|
||||
* raylib. Returns 0 and fills *rgba (malloc'd, top-down RGBA8 rows) on
|
||||
* success. */
|
||||
|
||||
int k2b_decode_image(const char *file, unsigned char **rgba, int *w, int *h);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* k2b util — small path/string helpers used by the codegen.
|
||||
*/
|
||||
#include "krb.h"
|
||||
#include "kir.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
void
|
||||
die(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "k2b: ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fputc('\n', stderr);
|
||||
va_end(ap);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
path_join(char *dst, size_t dst_size, const char *a, const char *b)
|
||||
{
|
||||
if(a == NULL || a[0] == '\0')
|
||||
snprintf(dst, dst_size, "%s", b);
|
||||
else if(a[strlen(a) - 1] == '/')
|
||||
snprintf(dst, dst_size, "%s%s", a, b);
|
||||
else
|
||||
snprintf(dst, dst_size, "%s/%s", a, b);
|
||||
}
|
||||
|
||||
void
|
||||
mkdir_parent(const char *path)
|
||||
{
|
||||
char tmp[KIR_PATH_MAX];
|
||||
size_t i;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", path);
|
||||
for(i = 1; i < strlen(tmp); i++) {
|
||||
if(tmp[i] != '/')
|
||||
continue;
|
||||
tmp[i] = '\0';
|
||||
if(mkdir(tmp, 0755) != 0 && errno != EEXIST)
|
||||
die("%s: mkdir failed: %s", tmp, strerror(errno));
|
||||
tmp[i] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
header_guard(char *dst, size_t dst_size, const char *rel)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
if(dst_size > 4) {
|
||||
dst[n++] = 'K';
|
||||
dst[n++] = '2';
|
||||
dst[n++] = 'B';
|
||||
dst[n++] = '_';
|
||||
}
|
||||
for(const char *p = rel; *p != '\0' && n + 1 < dst_size; p++) {
|
||||
char c = *p;
|
||||
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9'))
|
||||
dst[n++] = (c >= 'a' && c <= 'z') ? (char)(c - 'a' + 'A') : c;
|
||||
else
|
||||
dst[n++] = '_';
|
||||
}
|
||||
dst[n] = '\0';
|
||||
}
|
||||
|
||||
void
|
||||
strip_kry_ext(char *dst, size_t dst_size, const char *path)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(path == NULL) {
|
||||
if(dst_size > 0)
|
||||
dst[0] = '\0';
|
||||
return;
|
||||
}
|
||||
len = strlen(path);
|
||||
if(len > 4 && strcmp(path + len - 4, ".kry") == 0)
|
||||
len -= 4;
|
||||
if(len >= dst_size)
|
||||
len = dst_size - 1;
|
||||
memcpy(dst, path, len);
|
||||
dst[len] = '\0';
|
||||
}
|
||||
|
||||
void
|
||||
replace_path_basename(char *dst, size_t dst_size, const char *path,
|
||||
const char *base)
|
||||
{
|
||||
const char *slash = NULL;
|
||||
size_t dir_len;
|
||||
|
||||
if(dst_size == 0)
|
||||
return;
|
||||
for(const char *p = path; p != NULL && *p != '\0'; p++) {
|
||||
if(*p == '/' || *p == '\\')
|
||||
slash = p;
|
||||
}
|
||||
if(slash == NULL) {
|
||||
snprintf(dst, dst_size, "%s", base);
|
||||
return;
|
||||
}
|
||||
dir_len = (size_t)(slash - path + 1);
|
||||
if(dir_len >= dst_size)
|
||||
dir_len = dst_size - 1;
|
||||
memcpy(dst, path, dir_len);
|
||||
dst[dir_len] = '\0';
|
||||
snprintf(dst + dir_len, dst_size - dir_len, "%s", base);
|
||||
}
|
||||
|
||||
/* Path relative to root. Handles the common cases (path under root, or path
|
||||
* already relative); does not fully normalize, which is enough for emitting
|
||||
* cartridge output paths next to their source. */
|
||||
const char *
|
||||
relative_path(const char *root, const char *path)
|
||||
{
|
||||
static char rel[KIR_PATH_MAX];
|
||||
size_t n;
|
||||
|
||||
if(root == NULL || root[0] == '\0')
|
||||
return path;
|
||||
n = strlen(root);
|
||||
if(strncmp(path, root, n) == 0 && path[n] == '/')
|
||||
snprintf(rel, sizeof(rel), "%s", path + n + 1);
|
||||
else
|
||||
snprintf(rel, sizeof(rel), "%s", path);
|
||||
return rel;
|
||||
}
|
||||
|
||||
int
|
||||
is_ident_text(const char *text)
|
||||
{
|
||||
if(text == NULL || text[0] == '\0')
|
||||
return 0;
|
||||
if(!(isalpha((unsigned char)text[0]) || text[0] == '_'))
|
||||
return 0;
|
||||
for(const char *p = text + 1; *p != '\0'; p++) {
|
||||
if(!(isalnum((unsigned char)*p) || *p == '_'))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
c_string_literal(char *dst, size_t dst_size, const char *src)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
if(dst_size == 0)
|
||||
return;
|
||||
dst[n++] = '"';
|
||||
for(const char *p = src != NULL ? src : ""; *p != '\0' && n + 2 < dst_size; p++) {
|
||||
if(*p == '"' || *p == '\\') {
|
||||
if(n + 2 >= dst_size)
|
||||
break;
|
||||
dst[n++] = '\\';
|
||||
dst[n++] = *p;
|
||||
} else if(*p == '\n') {
|
||||
if(n + 2 >= dst_size)
|
||||
break;
|
||||
dst[n++] = '\\';
|
||||
dst[n++] = 'n';
|
||||
} else {
|
||||
dst[n++] = *p;
|
||||
}
|
||||
}
|
||||
if(n + 1 < dst_size)
|
||||
dst[n++] = '"';
|
||||
dst[n] = '\0';
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* k2b - .kry -> .krb cartridge compiler. Shares the Kir frontend with k2c:
|
||||
* every .kry parses into a KirProgram (kir_parse.c), then lowers to a .krb
|
||||
* cartridge + C host (k2b_krb.c). One frontend, two backends.
|
||||
*/
|
||||
#include "kir.h"
|
||||
#include "kir_parse.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void write_krb(const KirModule *m, const char *root, const char *out_dir,
|
||||
int no_main);
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: k2b [--no-main] --root DIR -o DIR file.kry ...\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *root = NULL;
|
||||
const char *out_dir = NULL;
|
||||
int no_main = 0;
|
||||
int i;
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "--root") == 0 && i + 1 < argc) {
|
||||
root = argv[++i];
|
||||
} else if(strcmp(argv[i], "-o") == 0 && i + 1 < argc) {
|
||||
out_dir = argv[++i];
|
||||
} else if(strcmp(argv[i], "--no-main") == 0) {
|
||||
no_main = 1;
|
||||
} else if(argv[i][0] == '-') {
|
||||
usage();
|
||||
return 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(root == NULL || out_dir == NULL || i >= argc) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
for(; i < argc; i++) {
|
||||
KirProgram *prog = kir_parse_file(argv[i], root);
|
||||
|
||||
if(prog == NULL) {
|
||||
fprintf(stderr, "k2b: failed to parse %s\n", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
for(int m = 0; m < prog->module_count; m++)
|
||||
write_krb(&prog->modules[m], root, out_dir, no_main);
|
||||
KirProgramFree(prog);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+1576
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,37 @@
|
||||
#ifndef K2C_LOWER_H
|
||||
#define K2C_LOWER_H
|
||||
|
||||
#include "kir.h"
|
||||
|
||||
/* Cross-module symbol table: for each parsed module (by its slash-path),
|
||||
* every function's .kry name -> full C name. Built by main after parsing all
|
||||
* inputs; used to resolve alias-qualified calls (start.draw_start_page(...)
|
||||
* -> ide_start_page_draw_start_page_kry_draw(...)). */
|
||||
typedef struct K2cModuleSyms {
|
||||
char module_stem[KIR_PATH_MAX]; /* source path minus .kry */
|
||||
char module_slash[KIR_PATH_MAX];
|
||||
struct {
|
||||
char kry[KIR_NAME_MAX];
|
||||
char c[KIR_NAME_MAX * 3];
|
||||
} fns[256];
|
||||
int fn_count;
|
||||
} K2cModuleSyms;
|
||||
|
||||
/* Lower a KirProgram to C source (.c/.h). restab/restab_count resolve
|
||||
* cross-module calls; pass NULL/0 to resolve same-module only. */
|
||||
void k2c_lower(const KirProgram *program, const char *root,
|
||||
const char *out_dir, const K2cModuleSyms *restab,
|
||||
int restab_count);
|
||||
|
||||
/* Build the symbol table entry for one program into out. */
|
||||
void k2c_build_syms(const KirProgram *program, K2cModuleSyms *out);
|
||||
|
||||
/* Full C name for a function (module prefix, colon naming, _kry_draw). */
|
||||
void k2c_function_c_name(const KirModule *m, const KirFunction *fn,
|
||||
char *dst, size_t dst_size);
|
||||
|
||||
/* k2c_project.c — kryon_project.h/.c (app-host ABI) after all files lower. */
|
||||
void k2c_write_project(KirProgram *const *progs, int prog_count,
|
||||
const char *root, const char *out_dir, int no_main);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* k2c_project.c — emit kryon_project.h/.c after all files lower. The
|
||||
* app-host ABI (CreateAppHost/DestroyAppHost + route table) consumed by
|
||||
* the preview tool and IDE host builds. Routes auto-collect from public
|
||||
* screens (screen/preview/page/frame/scene/fn keywords); explicit route{}
|
||||
* blocks are not captured by Kir yet.
|
||||
*/
|
||||
#include "k2c_lower.h"
|
||||
#include "kir.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
typedef struct K2cRoute {
|
||||
char id[KIR_NAME_MAX];
|
||||
char title[KIR_NAME_MAX];
|
||||
char group[KIR_NAME_MAX];
|
||||
char source_path[KIR_PATH_MAX];
|
||||
const KirModule *m;
|
||||
const KirFunction *fn;
|
||||
} K2cRoute;
|
||||
|
||||
#define K2C_ROUTE_MAX 512
|
||||
|
||||
static void
|
||||
mkdir_parent_local(const char *path)
|
||||
{
|
||||
char tmp[KIR_PATH_MAX];
|
||||
size_t i;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", path);
|
||||
for(i = 1; i < strlen(tmp); i++) {
|
||||
if(tmp[i] == '/') {
|
||||
tmp[i] = '\0';
|
||||
mkdir(tmp, 0755);
|
||||
tmp[i] = '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
c_str(char *dst, size_t dst_size, const char *src)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
dst[n++] = '"';
|
||||
for(const char *p = src != NULL ? src : "";
|
||||
*p != '\0' && n + 3 < dst_size; p++) {
|
||||
if(*p == '"' || *p == '\\') {
|
||||
dst[n++] = '\\';
|
||||
dst[n++] = *p;
|
||||
} else if(*p == '\n') {
|
||||
dst[n++] = '\\';
|
||||
dst[n++] = 'n';
|
||||
} else {
|
||||
dst[n++] = *p;
|
||||
}
|
||||
}
|
||||
if(n < dst_size)
|
||||
dst[n++] = '"';
|
||||
dst[n] = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
collect_routes(KirProgram *const *progs, int prog_count,
|
||||
K2cRoute *routes, int max_routes)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for(int i = 0; i < prog_count; i++) {
|
||||
const KirProgram *prog = progs[i];
|
||||
|
||||
if(prog == NULL)
|
||||
continue;
|
||||
for(int m = 0; m < prog->module_count; m++) {
|
||||
const KirModule *mod = &prog->modules[m];
|
||||
|
||||
for(int j = 0; j < mod->function_count; j++) {
|
||||
const KirFunction *fn = &mod->functions[j];
|
||||
|
||||
/* Legacy route rule: public AND not a colon function
|
||||
* (exact_name) — only screen/preview/page keyword screens
|
||||
* are routes; colon helpers stay callable but unrouted. */
|
||||
if(!fn->is_public || fn->is_colon || fn->name[0] == '\0')
|
||||
continue;
|
||||
if(count >= max_routes)
|
||||
return count;
|
||||
snprintf(routes[count].id, sizeof(routes[0].id), "%s",
|
||||
fn->name);
|
||||
snprintf(routes[count].title, sizeof(routes[0].title), "%s",
|
||||
fn->name);
|
||||
snprintf(routes[count].group, sizeof(routes[0].group),
|
||||
"Project");
|
||||
snprintf(routes[count].source_path,
|
||||
sizeof(routes[0].source_path), "%s",
|
||||
mod->source_path);
|
||||
routes[count].m = mod;
|
||||
routes[count].fn = fn;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void
|
||||
k2c_write_project(KirProgram *const *progs, int prog_count,
|
||||
const char *root, const char *out_dir, int no_main)
|
||||
{
|
||||
K2cRoute routes[K2C_ROUTE_MAX];
|
||||
char path[KIR_PATH_MAX];
|
||||
const KirModule *appmod = NULL;
|
||||
FILE *out;
|
||||
int count;
|
||||
|
||||
if(progs == NULL || prog_count <= 0)
|
||||
return;
|
||||
count = collect_routes(progs, prog_count, routes, K2C_ROUTE_MAX);
|
||||
|
||||
/* the one app{} module (for main()) */
|
||||
for(int i = 0; i < prog_count && appmod == NULL; i++) {
|
||||
if(progs[i] == NULL)
|
||||
continue;
|
||||
for(int m = 0; m < progs[i]->module_count; m++)
|
||||
if(progs[i]->modules[m].app.has_app) {
|
||||
appmod = &progs[i]->modules[m];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- kryon_project.h --- */
|
||||
snprintf(path, sizeof(path), "%s/kryon_project.h", out_dir);
|
||||
mkdir_parent_local(path);
|
||||
out = fopen(path, "wb");
|
||||
if(out == NULL)
|
||||
return;
|
||||
fprintf(out, "/* Generated by k2c from project Kry files. */\n");
|
||||
fprintf(out, "#ifndef K_KRYON_PROJECT_H\n#define K_KRYON_PROJECT_H\n\n");
|
||||
for(int i = 0; i < prog_count; i++) {
|
||||
const KirProgram *prog = progs[i];
|
||||
|
||||
if(prog == NULL)
|
||||
continue;
|
||||
for(int m = 0; m < prog->module_count; m++) {
|
||||
const KirModule *mod = &prog->modules[m];
|
||||
char stem[KIR_PATH_MAX];
|
||||
size_t n = strlen(mod->source_path);
|
||||
|
||||
if(n > 4 && strcmp(mod->source_path + n - 4, ".kry") == 0)
|
||||
n -= 4;
|
||||
if(n >= sizeof(stem))
|
||||
n = sizeof(stem) - 1;
|
||||
memcpy(stem, mod->source_path, n);
|
||||
stem[n] = '\0';
|
||||
fprintf(out, "#include \"%s.h\"\n", stem);
|
||||
}
|
||||
}
|
||||
fprintf(out, "\n#endif\n");
|
||||
fclose(out);
|
||||
|
||||
if(count <= 0)
|
||||
return;
|
||||
|
||||
/* --- kryon_project.c --- */
|
||||
snprintf(path, sizeof(path), "%s/kryon_project.c", out_dir);
|
||||
out = fopen(path, "wb");
|
||||
if(out == NULL)
|
||||
return;
|
||||
fprintf(out, "/* Generated by k2c from project Kry files. */\n");
|
||||
fprintf(out, "#include \"kryon_project.h\"\n");
|
||||
fprintf(out, "#include \"app_runtime.h\"\n\n");
|
||||
fprintf(out, "#if defined(__GNUC__) || defined(__clang__)\n");
|
||||
fprintf(out, "void *CreateApp(const char *project_path) __attribute__((weak));\n");
|
||||
fprintf(out, "void DestroyApp(void *app) __attribute__((weak));\n");
|
||||
fprintf(out, "void ApplyRoute(void *app, const AppRouteInfo *route) __attribute__((weak));\n");
|
||||
fprintf(out, "void BeginScreenDraw(void *app, Rectangle viewport) __attribute__((weak));\n");
|
||||
fprintf(out, "#endif\n\n");
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
char cname[KIR_NAME_MAX * 3];
|
||||
char wrapper[64];
|
||||
|
||||
snprintf(wrapper, sizeof(wrapper), "kryon_project_draw_%d", i);
|
||||
k2c_function_c_name(routes[i].m, routes[i].fn, cname, sizeof(cname));
|
||||
fprintf(out, "static void\n%s(void *app, Rectangle viewport)\n{\n",
|
||||
wrapper);
|
||||
fprintf(out, " if(BeginScreenDraw != 0)\n");
|
||||
fprintf(out, " BeginScreenDraw(app, viewport);\n");
|
||||
if(strstr(routes[i].fn->args, "Rectangle") != NULL)
|
||||
fprintf(out, " (void)app;\n %s(viewport);\n", cname);
|
||||
else if(routes[i].fn->args[0] != '\0')
|
||||
fprintf(out, " (void)viewport;\n %s(app);\n", cname);
|
||||
else
|
||||
fprintf(out, " (void)app;\n (void)viewport;\n %s();\n",
|
||||
cname);
|
||||
fprintf(out, "}\n\n");
|
||||
}
|
||||
|
||||
fprintf(out, "static const AppRouteInfo kryon_project_routes[%d];\n\n",
|
||||
count);
|
||||
fprintf(out, "static void\nkryon_project_enter(void *app, int index)\n{\n");
|
||||
fprintf(out, " if(ApplyRoute == 0 || index < 0 || index >= %d)\n",
|
||||
count);
|
||||
fprintf(out, " return;\n");
|
||||
fprintf(out, " ApplyRoute(app, &kryon_project_routes[index]);\n");
|
||||
fprintf(out, "}\n\n");
|
||||
|
||||
fprintf(out, "static const AppRouteInfo kryon_project_routes[] = {\n");
|
||||
for(int i = 0; i < count; i++) {
|
||||
char id[KIR_NAME_MAX * 2];
|
||||
char title[KIR_NAME_MAX * 2];
|
||||
char group[KIR_NAME_MAX * 2];
|
||||
char source[KIR_PATH_MAX * 2];
|
||||
char wrapper[64];
|
||||
|
||||
c_str(id, sizeof(id), routes[i].id);
|
||||
c_str(title, sizeof(title), routes[i].title);
|
||||
c_str(group, sizeof(group), routes[i].group);
|
||||
c_str(source, sizeof(source), routes[i].source_path);
|
||||
snprintf(wrapper, sizeof(wrapper), "kryon_project_draw_%d", i);
|
||||
fprintf(out, " {%s, %s, %s, %s, kryon_project_enter, %s},\n",
|
||||
id, group, title, source, wrapper);
|
||||
}
|
||||
fprintf(out, "};\n\n");
|
||||
fprintf(out, "static App kryon_project_runtime;\n");
|
||||
fprintf(out, "static AppHost kryon_project_host;\n\n");
|
||||
fprintf(out, "AppHost *\nCreateAppHost(int abi_version, const char *project_path)\n{\n");
|
||||
fprintf(out, " void *app = 0;\n");
|
||||
fprintf(out, " if(abi_version != APP_HOST_ABI_VERSION || CreateApp == 0)\n");
|
||||
fprintf(out, " return 0;\n");
|
||||
fprintf(out, " app = CreateApp(project_path);\n");
|
||||
fprintf(out, " if(app == 0)\n");
|
||||
fprintf(out, " return 0;\n");
|
||||
fprintf(out, " kryon_project_runtime.app = app;\n");
|
||||
fprintf(out, " kryon_project_runtime.routes = kryon_project_routes;\n");
|
||||
fprintf(out, " kryon_project_runtime.route_count = (int)(sizeof(kryon_project_routes) / sizeof(kryon_project_routes[0]));\n");
|
||||
fprintf(out, " kryon_project_runtime.selected_route = 0;\n");
|
||||
fprintf(out, " BindAppHost(&kryon_project_runtime, &kryon_project_host);\n");
|
||||
fprintf(out, " SetAppScreen(&kryon_project_host, 0);\n");
|
||||
fprintf(out, " return &kryon_project_host;\n}\n\n");
|
||||
fprintf(out, "void\nDestroyAppHost(AppHost *host)\n{\n");
|
||||
fprintf(out, " if(host == 0 || host != &kryon_project_host)\n");
|
||||
fprintf(out, " return;\n");
|
||||
fprintf(out, " if(DestroyApp != 0 && kryon_project_runtime.app != 0)\n");
|
||||
fprintf(out, " DestroyApp(kryon_project_runtime.app);\n");
|
||||
fprintf(out, " kryon_project_runtime = (App){0};\n");
|
||||
fprintf(out, " kryon_project_host = (AppHost){0};\n}\n");
|
||||
fclose(out);
|
||||
|
||||
/* --- main() (hook-driven, from KirAppMeta) --- */
|
||||
if(no_main || appmod == NULL)
|
||||
return;
|
||||
out = fopen(path, "ab");
|
||||
if(out == NULL)
|
||||
return;
|
||||
{
|
||||
int width = appmod->app.width > 0 ? appmod->app.width : 800;
|
||||
int height = appmod->app.height > 0 ? appmod->app.height : 600;
|
||||
int fps = appmod->app.fps > 0 ? appmod->app.fps : 60;
|
||||
char title[KIR_NAME_MAX * 2];
|
||||
|
||||
c_str(title, sizeof(title), appmod->app.title);
|
||||
fprintf(out, "\nint\nmain(void)\n{\n");
|
||||
fprintf(out, " InitWindow(%d, %d, %s);\n", width, height, title);
|
||||
fprintf(out, " SetTargetFPS(%d);\n", fps);
|
||||
if(appmod->app.font_examples)
|
||||
fprintf(out, " LoadExampleUIFont();\n");
|
||||
fprintf(out, " InitUI(%d, %d, GetUIScale());\n", width, height);
|
||||
if(appmod->app.theme[0] != '\0')
|
||||
fprintf(out, " SetCurrentTheme(%s, %d);\n",
|
||||
appmod->app.theme, appmod->app.dark_mode);
|
||||
if(appmod->app.init[0] != '\0') {
|
||||
char hook[KIR_NAME_MAX * 3];
|
||||
int found = 0;
|
||||
|
||||
for(int j = 0; j < appmod->function_count && !found; j++) {
|
||||
if(strcmp(appmod->functions[j].name, appmod->app.init) == 0) {
|
||||
k2c_function_c_name(appmod, &appmod->functions[j],
|
||||
hook, sizeof(hook));
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
fprintf(out, " %s();\n",
|
||||
found ? hook : appmod->app.init);
|
||||
}
|
||||
fprintf(out, " while(!WindowShouldClose())\n");
|
||||
if(appmod->app.frame[0] != '\0') {
|
||||
char hook[KIR_NAME_MAX * 3];
|
||||
int found = 0;
|
||||
|
||||
for(int j = 0; j < appmod->function_count && !found; j++) {
|
||||
if(strcmp(appmod->functions[j].name, appmod->app.frame) == 0) {
|
||||
k2c_function_c_name(appmod, &appmod->functions[j],
|
||||
hook, sizeof(hook));
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
fprintf(out, " %s();\n",
|
||||
found ? hook : appmod->app.frame);
|
||||
} else if(count > 0) {
|
||||
char cname[KIR_NAME_MAX * 3];
|
||||
|
||||
k2c_function_c_name(routes[0].m, routes[0].fn, cname,
|
||||
sizeof(cname));
|
||||
fprintf(out, " %s();\n", cname);
|
||||
} else {
|
||||
fprintf(out, " ;\n");
|
||||
}
|
||||
if(appmod->app.shutdown[0] != '\0') {
|
||||
char hook[KIR_NAME_MAX * 3];
|
||||
int found = 0;
|
||||
|
||||
for(int j = 0; j < appmod->function_count && !found; j++) {
|
||||
if(strcmp(appmod->functions[j].name, appmod->app.shutdown) == 0) {
|
||||
k2c_function_c_name(appmod, &appmod->functions[j],
|
||||
hook, sizeof(hook));
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
fprintf(out, " %s();\n",
|
||||
found ? hook : appmod->app.shutdown);
|
||||
}
|
||||
if(appmod->app.font_examples)
|
||||
fprintf(out, " UnloadExampleUIFont();\n");
|
||||
fprintf(out, " CloseWindow();\n");
|
||||
fprintf(out, " return 0;\n}\n");
|
||||
}
|
||||
fclose(out);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* k2c - .kry -> C compiler. Kir is the only pipeline: every .kry parses
|
||||
* into a KirProgram (kir_parse.c) and lowers to C (k2c_lower.c). All inputs
|
||||
* are parsed first so cross-module calls resolve through one symbol table.
|
||||
*/
|
||||
#include "kir.h"
|
||||
#include "kir_parse.h"
|
||||
#include "k2c_lower.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: k2c [--no-main] --root DIR -o DIR file.kry ...\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *root = NULL;
|
||||
const char *out_dir = NULL;
|
||||
int no_main = 0;
|
||||
KirProgram **progs;
|
||||
K2cModuleSyms *syms;
|
||||
int file_count;
|
||||
int i;
|
||||
int first_file = 0;
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "--root") == 0 && i + 1 < argc) {
|
||||
root = argv[++i];
|
||||
} else if(strcmp(argv[i], "-o") == 0 && i + 1 < argc) {
|
||||
out_dir = argv[++i];
|
||||
} else if(strcmp(argv[i], "--no-main") == 0) {
|
||||
no_main = 1;
|
||||
} else if(argv[i][0] == '-') {
|
||||
usage();
|
||||
return 1;
|
||||
} else {
|
||||
first_file = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(root == NULL || out_dir == NULL || first_file == 0) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
file_count = argc - first_file;
|
||||
progs = calloc((size_t)file_count, sizeof(*progs));
|
||||
syms = calloc((size_t)file_count, sizeof(*syms));
|
||||
if(progs == NULL || syms == NULL) {
|
||||
fprintf(stderr, "k2c: out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
/* Pass 1: parse every file, build the cross-module symbol table. */
|
||||
for(i = 0; i < file_count; i++) {
|
||||
progs[i] = kir_parse_file(argv[first_file + i], root);
|
||||
if(progs[i] == NULL) {
|
||||
fprintf(stderr, "k2c: failed to parse %s\n",
|
||||
argv[first_file + i]);
|
||||
return 1;
|
||||
}
|
||||
k2c_build_syms(progs[i], &syms[i]);
|
||||
}
|
||||
/* Pass 2: lower with full cross-module resolution. */
|
||||
for(i = 0; i < file_count; i++)
|
||||
k2c_lower(progs[i], root, out_dir, syms, file_count);
|
||||
k2c_write_project(progs, file_count, root, out_dir, no_main);
|
||||
for(i = 0; i < file_count; i++)
|
||||
KirProgramFree(progs[i]);
|
||||
free(progs);
|
||||
free(syms);
|
||||
return 0;
|
||||
}
|
||||
+1905
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,23 @@
|
||||
#ifndef K2G_LOWER_H
|
||||
#define K2G_LOWER_H
|
||||
|
||||
#include "kir.h"
|
||||
|
||||
/*
|
||||
* k2g_lower - Kir -> Go backend.
|
||||
*
|
||||
* Emits one .go file per module into out_dir, all in one Go package. The
|
||||
* generated code calls a Go kryon runtime through an `rt` value (import
|
||||
* path given by --runtime; the cgo binding package, e.g. app's kryui).
|
||||
*
|
||||
* v1 scope: the declarative app subset translates fully — state blocks,
|
||||
* app metadata (-> generated main unless --no-main), frames, widget calls,
|
||||
* and scalar expressions (compound literals, casts, state refs). Imperative
|
||||
* constructs are best-effort; anything unsupported is emitted as a
|
||||
* commented TODO line instead of silently miscompiling.
|
||||
*/
|
||||
void k2g_lower(const KirProgram *const *progs, int prog_count,
|
||||
const char *root, const char *out_dir, const char *pkg,
|
||||
const char *runtime_import, int no_main);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* k2g - .kry -> Go compiler. Shares the Kir frontend with k2c/k2b: every
|
||||
* .kry parses into a KirProgram (kir_parse.c), then lowers to Go source
|
||||
* (k2g_lower.c) that calls a Go kryon runtime (the cgo surface, like app's
|
||||
* kryui package). One frontend, three backends.
|
||||
*
|
||||
* usage: k2g [--no-main] [--pkg NAME] [--runtime IMPORT] --root DIR -o DIR file.kry ...
|
||||
*/
|
||||
#include "kir.h"
|
||||
#include "kir_parse.h"
|
||||
#include "k2g_lower.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: k2g [--no-main] [--pkg NAME] [--runtime IMPORT] "
|
||||
"--root DIR -o DIR file.kry ...\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *root = NULL;
|
||||
const char *out_dir = NULL;
|
||||
const char *pkg = "krygen";
|
||||
const char *runtime = "github.com/waozixyz/kryon/go/kryui";
|
||||
int no_main = 0;
|
||||
KirProgram **progs;
|
||||
int file_count;
|
||||
int i;
|
||||
int first_file = 0;
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "--root") == 0 && i + 1 < argc) {
|
||||
root = argv[++i];
|
||||
} else if(strcmp(argv[i], "-o") == 0 && i + 1 < argc) {
|
||||
out_dir = argv[++i];
|
||||
} else if(strcmp(argv[i], "--pkg") == 0 && i + 1 < argc) {
|
||||
pkg = argv[++i];
|
||||
} else if(strcmp(argv[i], "--runtime") == 0 && i + 1 < argc) {
|
||||
runtime = argv[++i];
|
||||
} else if(strcmp(argv[i], "--no-main") == 0) {
|
||||
no_main = 1;
|
||||
} else if(argv[i][0] == '-') {
|
||||
usage();
|
||||
return 1;
|
||||
} else {
|
||||
first_file = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(root == NULL || out_dir == NULL || first_file == 0) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
file_count = argc - first_file;
|
||||
progs = calloc((size_t)file_count, sizeof(*progs));
|
||||
if(progs == NULL) {
|
||||
fprintf(stderr, "k2g: out of memory\n");
|
||||
return 1;
|
||||
}
|
||||
for(i = 0; i < file_count; i++) {
|
||||
progs[i] = kir_parse_file(argv[first_file + i], root);
|
||||
if(progs[i] == NULL) {
|
||||
fprintf(stderr, "k2g: failed to parse %s\n", argv[first_file + i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
k2g_lower((const KirProgram *const *)progs, file_count, root, out_dir,
|
||||
pkg, runtime, no_main);
|
||||
for(i = 0; i < file_count; i++)
|
||||
KirProgramFree(progs[i]);
|
||||
free(progs);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* k2ir - emit a debuggable KIR text artifact from .kry source.
|
||||
* Thin wrapper around the shared kir_parse_file frontend.
|
||||
*/
|
||||
#include "kir.h"
|
||||
#include "kir_parse.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: k2ir --root DIR -o DIR file.kry ...\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *root = NULL;
|
||||
const char *out_dir = NULL;
|
||||
int i;
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "--root") == 0 && i + 1 < argc) {
|
||||
root = argv[++i];
|
||||
} else if(strcmp(argv[i], "-o") == 0 && i + 1 < argc) {
|
||||
out_dir = argv[++i];
|
||||
} else if(argv[i][0] == '-') {
|
||||
usage();
|
||||
return 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(root == NULL || out_dir == NULL || i >= argc) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
for(; i < argc; i++) {
|
||||
KirProgram *program = kir_parse_file(argv[i], root);
|
||||
if(program == NULL)
|
||||
return 1;
|
||||
/* Write the .kir dump using the module's source_path (relative to root)
|
||||
* so directory structure is preserved. */
|
||||
if(program->module_count > 0) {
|
||||
const char *src = program->modules[0].source_path;
|
||||
size_t slen = strlen(src);
|
||||
char stem[512];
|
||||
char out_path[1024];
|
||||
FILE *out;
|
||||
|
||||
if(slen > 4 && strcmp(src + slen - 4, ".kry") == 0)
|
||||
slen -= 4;
|
||||
if(slen >= sizeof(stem))
|
||||
slen = sizeof(stem) - 1;
|
||||
memcpy(stem, src, slen);
|
||||
stem[slen] = '\0';
|
||||
snprintf(out_path, sizeof(out_path), "%s/%s.kir", out_dir, stem);
|
||||
/* mkdir -p */
|
||||
{
|
||||
char tmp[1024];
|
||||
size_t j;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", out_path);
|
||||
for(j = 1; j < strlen(tmp); j++) {
|
||||
if(tmp[j] == '/') {
|
||||
tmp[j] = '\0';
|
||||
mkdir(tmp, 0755);
|
||||
tmp[j] = '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
out = fopen(out_path, "wb");
|
||||
if(out == NULL) {
|
||||
fprintf(stderr, "k2ir: %s: open failed\n", out_path);
|
||||
KirProgramFree(program);
|
||||
return 1;
|
||||
}
|
||||
KirProgramDump(program, out);
|
||||
fclose(out);
|
||||
}
|
||||
KirProgramFree(program);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
-4540
File diff suppressed because it is too large.
Load diff
@@ -1,105 +0,0 @@
|
||||
#ifndef KRYON_KC_INTERNAL_H
|
||||
#define KRYON_KC_INTERNAL_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
enum {
|
||||
KC_PATH_MAX = 1024,
|
||||
KC_TEXT_MAX = 1024 * 1024,
|
||||
KC_NAME_MAX = 128,
|
||||
KC_INCLUDE_MAX = 64,
|
||||
KC_USE_MAX = 32,
|
||||
KC_CALL_MAX = 64,
|
||||
KC_CONST_MAX = 64,
|
||||
KC_DEFINE_MAX = 64,
|
||||
KC_TYPE_MAX = 256,
|
||||
KC_RAW_MAX = 1024,
|
||||
KC_STATE_MAX = 128,
|
||||
KC_BODY_MAX = 512,
|
||||
KC_BODY_LINE_MAX = 1024,
|
||||
};
|
||||
|
||||
typedef struct KryFunction {
|
||||
char screen[KC_NAME_MAX];
|
||||
char args[512];
|
||||
char return_type[KC_NAME_MAX];
|
||||
char guard[KC_BODY_LINE_MAX];
|
||||
int exact_name;
|
||||
int is_public;
|
||||
int global_name;
|
||||
char calls[KC_CALL_MAX][512];
|
||||
char body[KC_BODY_MAX][KC_BODY_LINE_MAX];
|
||||
int body_line[KC_BODY_MAX];
|
||||
int call_count;
|
||||
int body_count;
|
||||
} KryFunction;
|
||||
|
||||
typedef struct KryFile {
|
||||
char *path;
|
||||
const char *root;
|
||||
char *text;
|
||||
char app_title[256];
|
||||
int app_width;
|
||||
int app_height;
|
||||
int app_fps;
|
||||
int app_font_examples;
|
||||
char app_theme[KC_NAME_MAX];
|
||||
int app_dark_mode;
|
||||
int no_main;
|
||||
char raw[KC_RAW_MAX][KC_BODY_LINE_MAX];
|
||||
char public_types[KC_TYPE_MAX][KC_BODY_LINE_MAX];
|
||||
char private_types[KC_TYPE_MAX][KC_BODY_LINE_MAX];
|
||||
char state[KC_STATE_MAX][KC_BODY_LINE_MAX];
|
||||
char public_globals[KC_STATE_MAX][KC_BODY_LINE_MAX];
|
||||
char globals[KC_STATE_MAX][KC_BODY_LINE_MAX];
|
||||
char includes[KC_INCLUDE_MAX][KC_PATH_MAX];
|
||||
char include_guards[KC_INCLUDE_MAX][KC_BODY_LINE_MAX];
|
||||
char const_names[KC_CONST_MAX][KC_NAME_MAX];
|
||||
char const_exprs[KC_CONST_MAX][KC_BODY_LINE_MAX];
|
||||
char define_names[KC_DEFINE_MAX][KC_NAME_MAX];
|
||||
char define_values[KC_DEFINE_MAX][KC_BODY_LINE_MAX];
|
||||
char define_guards[KC_DEFINE_MAX][KC_BODY_LINE_MAX];
|
||||
char module[KC_NAME_MAX];
|
||||
char module_file[KC_NAME_MAX];
|
||||
char use_aliases[KC_USE_MAX][KC_NAME_MAX];
|
||||
char use_modules[KC_USE_MAX][KC_NAME_MAX];
|
||||
KryFunction *functions;
|
||||
int raw_count;
|
||||
int public_type_count;
|
||||
int private_type_count;
|
||||
int state_count;
|
||||
int public_global_count;
|
||||
int global_count;
|
||||
int include_count;
|
||||
int const_count;
|
||||
int define_count;
|
||||
int use_count;
|
||||
int function_count;
|
||||
int function_cap;
|
||||
int current_line;
|
||||
KryFunction *current;
|
||||
} KryFile;
|
||||
|
||||
typedef struct KryMacroFrame {
|
||||
char condition[KC_BODY_LINE_MAX];
|
||||
char excluded[KC_BODY_LINE_MAX];
|
||||
} KryMacroFrame;
|
||||
|
||||
void add_raw_line(KryFile *file, const char *line);
|
||||
void add_type_line(KryFile *file, int is_public, const char *fmt, ...);
|
||||
void add_state_line(KryFile *file, const char *line);
|
||||
void expand_compile_expr(char *dst, size_t dst_size, const KryFile *file,
|
||||
const char *src);
|
||||
|
||||
void add_guard_line(KryFile *file, const char *guard, int is_public_type,
|
||||
int is_type, int is_state);
|
||||
void add_guard_end(KryFile *file, int is_public_type, int is_type,
|
||||
int is_state);
|
||||
void combine_compile_guards(char *dst, size_t dst_size, const char *left,
|
||||
const char *right);
|
||||
void current_macro_guard(char *dst, size_t dst_size,
|
||||
const KryMacroFrame *macros, int macro_count);
|
||||
void append_macro_excluded(char *dst, size_t dst_size, const char *current,
|
||||
const char *next);
|
||||
|
||||
#endif
|
||||
@@ -1,74 +0,0 @@
|
||||
#include "kc_internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
add_guard_line(KryFile *file, const char *guard, int is_public_type,
|
||||
int is_type, int is_state)
|
||||
{
|
||||
char line[KC_BODY_LINE_MAX];
|
||||
|
||||
if(guard == NULL || guard[0] == '\0')
|
||||
return;
|
||||
snprintf(line, sizeof(line), "#if %s", guard);
|
||||
if(is_type)
|
||||
add_type_line(file, is_public_type, "%s", line);
|
||||
else if(is_state)
|
||||
add_state_line(file, line);
|
||||
else
|
||||
add_raw_line(file, line);
|
||||
}
|
||||
|
||||
void
|
||||
add_guard_end(KryFile *file, int is_public_type, int is_type, int is_state)
|
||||
{
|
||||
if(is_type)
|
||||
add_type_line(file, is_public_type, "#endif");
|
||||
else if(is_state)
|
||||
add_state_line(file, "#endif");
|
||||
else
|
||||
add_raw_line(file, "#endif");
|
||||
}
|
||||
|
||||
void
|
||||
combine_compile_guards(char *dst, size_t dst_size, const char *left,
|
||||
const char *right)
|
||||
{
|
||||
const char *a = left != NULL ? left : "";
|
||||
const char *b = right != NULL ? right : "";
|
||||
|
||||
if(a[0] == '\0') {
|
||||
snprintf(dst, dst_size, "%s", b);
|
||||
} else if(b[0] == '\0') {
|
||||
snprintf(dst, dst_size, "%s", a);
|
||||
} else {
|
||||
snprintf(dst, dst_size, "(%s) && (%s)", a, b);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
current_macro_guard(char *dst, size_t dst_size, const KryMacroFrame *macros,
|
||||
int macro_count)
|
||||
{
|
||||
char guard[KC_BODY_LINE_MAX] = "";
|
||||
|
||||
for(int i = 0; i < macro_count; i++) {
|
||||
char next[KC_BODY_LINE_MAX];
|
||||
|
||||
combine_compile_guards(next, sizeof(next), guard,
|
||||
macros[i].condition);
|
||||
snprintf(guard, sizeof(guard), "%s", next);
|
||||
}
|
||||
snprintf(dst, dst_size, "%s", guard);
|
||||
}
|
||||
|
||||
void
|
||||
append_macro_excluded(char *dst, size_t dst_size, const char *current,
|
||||
const char *next)
|
||||
{
|
||||
if(current == NULL || current[0] == '\0')
|
||||
snprintf(dst, dst_size, "%s", next);
|
||||
else
|
||||
snprintf(dst, dst_size, "(%s) || (%s)", current, next);
|
||||
}
|
||||
-5429
File diff suppressed because it is too large.
Load diff
+390
@@ -0,0 +1,390 @@
|
||||
#include "kir.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void *
|
||||
kir_realloc_array(void *ptr, int *cap, int count, size_t elem_size)
|
||||
{
|
||||
void *next;
|
||||
int ncap;
|
||||
|
||||
if(count < *cap)
|
||||
return ptr;
|
||||
ncap = *cap == 0 ? 4 : *cap * 2;
|
||||
next = realloc(ptr, (size_t)ncap * elem_size);
|
||||
if(next == NULL)
|
||||
return NULL;
|
||||
memset((char *)next + (size_t)(*cap) * elem_size, 0,
|
||||
(size_t)(ncap - *cap) * elem_size);
|
||||
*cap = ncap;
|
||||
return next;
|
||||
}
|
||||
|
||||
static void
|
||||
kir_copy(char *dst, size_t dst_size, const char *src)
|
||||
{
|
||||
if(dst_size == 0)
|
||||
return;
|
||||
if(src == NULL)
|
||||
src = "";
|
||||
snprintf(dst, dst_size, "%s", src);
|
||||
}
|
||||
|
||||
KirProgram *
|
||||
KirProgramNew(void)
|
||||
{
|
||||
return calloc(1, sizeof(KirProgram));
|
||||
}
|
||||
|
||||
void
|
||||
KirProgramFree(KirProgram *program)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(program == NULL)
|
||||
return;
|
||||
for(i = 0; i < program->module_count; i++) {
|
||||
KirModule *m = &program->modules[i];
|
||||
int j;
|
||||
|
||||
for(j = 0; j < m->function_count; j++)
|
||||
free(m->functions[j].stmts);
|
||||
free(m->state_fields);
|
||||
free(m->imports);
|
||||
free(m->functions);
|
||||
free(m->defines);
|
||||
}
|
||||
free(program->modules);
|
||||
free(program);
|
||||
}
|
||||
|
||||
KirSourceSpan
|
||||
KirSpan(const char *path, int line, int column)
|
||||
{
|
||||
KirSourceSpan span;
|
||||
|
||||
memset(&span, 0, sizeof(span));
|
||||
kir_copy(span.path, sizeof(span.path), path);
|
||||
span.line = line;
|
||||
span.column = column;
|
||||
return span;
|
||||
}
|
||||
|
||||
KirModule *
|
||||
KirProgramAddModule(KirProgram *program, const char *name,
|
||||
const char *source_path, KirSourceSpan span)
|
||||
{
|
||||
KirModule *modules;
|
||||
KirModule *m;
|
||||
|
||||
if(program == NULL)
|
||||
return NULL;
|
||||
modules = kir_realloc_array(program->modules, &program->module_cap,
|
||||
program->module_count, sizeof(KirModule));
|
||||
if(modules == NULL)
|
||||
return NULL;
|
||||
program->modules = modules;
|
||||
m = &program->modules[program->module_count++];
|
||||
memset(m, 0, sizeof(*m));
|
||||
kir_copy(m->name, sizeof(m->name), name);
|
||||
kir_copy(m->source_path, sizeof(m->source_path), source_path);
|
||||
m->span = span;
|
||||
return m;
|
||||
}
|
||||
|
||||
KirStateField *
|
||||
KirModuleAddStateField(KirModule *module, const char *name, const char *type,
|
||||
const char *init, KirSourceSpan span)
|
||||
{
|
||||
KirStateField *fields;
|
||||
KirStateField *f;
|
||||
|
||||
if(module == NULL)
|
||||
return NULL;
|
||||
fields = kir_realloc_array(module->state_fields, &module->state_cap,
|
||||
module->state_count, sizeof(KirStateField));
|
||||
if(fields == NULL)
|
||||
return NULL;
|
||||
module->state_fields = fields;
|
||||
f = &module->state_fields[module->state_count++];
|
||||
memset(f, 0, sizeof(*f));
|
||||
kir_copy(f->name, sizeof(f->name), name);
|
||||
kir_copy(f->type, sizeof(f->type), type);
|
||||
kir_copy(f->init, sizeof(f->init), init);
|
||||
f->span = span;
|
||||
return f;
|
||||
}
|
||||
|
||||
KirImport *
|
||||
KirModuleAddImport(KirModule *module, KirImportKind kind, const char *name,
|
||||
const char *target, const char *signature, int required,
|
||||
KirSourceSpan span)
|
||||
{
|
||||
KirImport *imports;
|
||||
KirImport *imp;
|
||||
|
||||
if(module == NULL)
|
||||
return NULL;
|
||||
imports = kir_realloc_array(module->imports, &module->import_cap,
|
||||
module->import_count, sizeof(KirImport));
|
||||
if(imports == NULL)
|
||||
return NULL;
|
||||
module->imports = imports;
|
||||
imp = &module->imports[module->import_count++];
|
||||
memset(imp, 0, sizeof(*imp));
|
||||
imp->kind = kind;
|
||||
kir_copy(imp->name, sizeof(imp->name), name);
|
||||
kir_copy(imp->target, sizeof(imp->target), target);
|
||||
kir_copy(imp->signature, sizeof(imp->signature), signature);
|
||||
imp->required = required;
|
||||
imp->span = span;
|
||||
return imp;
|
||||
}
|
||||
|
||||
KirFunction *
|
||||
KirModuleAddFunction(KirModule *module, const char *name, const char *args,
|
||||
const char *return_type, int exported, KirSourceSpan span)
|
||||
{
|
||||
KirFunction *functions;
|
||||
KirFunction *fn;
|
||||
|
||||
if(module == NULL)
|
||||
return NULL;
|
||||
functions = kir_realloc_array(module->functions, &module->function_cap,
|
||||
module->function_count, sizeof(KirFunction));
|
||||
if(functions == NULL)
|
||||
return NULL;
|
||||
module->functions = functions;
|
||||
fn = &module->functions[module->function_count++];
|
||||
memset(fn, 0, sizeof(*fn));
|
||||
kir_copy(fn->name, sizeof(fn->name), name);
|
||||
kir_copy(fn->args, sizeof(fn->args), args);
|
||||
kir_copy(fn->return_type, sizeof(fn->return_type), return_type);
|
||||
fn->exported = exported;
|
||||
fn->span = span;
|
||||
return fn;
|
||||
}
|
||||
|
||||
void
|
||||
KirModuleAddGlobal(KirModule *module, const char *name, const char *type,
|
||||
const char *init, KirSourceSpan span)
|
||||
{
|
||||
KirGlobal *globals;
|
||||
|
||||
if(module == NULL)
|
||||
return;
|
||||
globals = kir_realloc_array(module->globals, &module->global_cap,
|
||||
module->global_count, sizeof(KirGlobal));
|
||||
if(globals == NULL)
|
||||
return;
|
||||
module->globals = globals;
|
||||
memset(&module->globals[module->global_count], 0, sizeof(KirGlobal));
|
||||
kir_copy(module->globals[module->global_count].name,
|
||||
sizeof(module->globals[0].name), name);
|
||||
kir_copy(module->globals[module->global_count].type,
|
||||
sizeof(module->globals[0].type), type);
|
||||
kir_copy(module->globals[module->global_count].init,
|
||||
sizeof(module->globals[0].init), init);
|
||||
module->globals[module->global_count].span = span;
|
||||
module->global_count++;
|
||||
}
|
||||
|
||||
void
|
||||
KirModuleAddStatic(KirModule *module, const char *name, const char *type,
|
||||
const char *init, KirSourceSpan span)
|
||||
{
|
||||
KirModuleAddGlobal(module, name, type, init, span);
|
||||
if(module != NULL && module->global_count > 0)
|
||||
module->globals[module->global_count - 1].is_static = 1;
|
||||
}
|
||||
|
||||
KirDefine *
|
||||
KirModuleAddDefine(KirModule *module, const char *name, const char *value,
|
||||
KirSourceSpan span)
|
||||
{
|
||||
KirDefine *defines;
|
||||
KirDefine *d;
|
||||
|
||||
if(module == NULL)
|
||||
return NULL;
|
||||
defines = kir_realloc_array(module->defines, &module->define_cap,
|
||||
module->define_count, sizeof(KirDefine));
|
||||
if(defines == NULL)
|
||||
return NULL;
|
||||
module->defines = defines;
|
||||
d = &module->defines[module->define_count++];
|
||||
memset(d, 0, sizeof(*d));
|
||||
kir_copy(d->name, sizeof(d->name), name);
|
||||
kir_copy(d->value, sizeof(d->value), value);
|
||||
d->span = span;
|
||||
return d;
|
||||
}
|
||||
|
||||
KirType *
|
||||
KirModuleAddType(KirModule *module, const char *name, KirSourceSpan span)
|
||||
{
|
||||
KirType *types;
|
||||
|
||||
if(module == NULL)
|
||||
return NULL;
|
||||
types = kir_realloc_array(module->types, &module->type_cap,
|
||||
module->type_count, sizeof(KirType));
|
||||
if(types == NULL)
|
||||
return NULL;
|
||||
module->types = types;
|
||||
memset(&module->types[module->type_count], 0, sizeof(KirType));
|
||||
kir_copy(module->types[module->type_count].name,
|
||||
sizeof(module->types[0].name), name);
|
||||
module->types[module->type_count].span = span;
|
||||
return &module->types[module->type_count++];
|
||||
}
|
||||
|
||||
KirStmt *
|
||||
KirFunctionAddStmt(KirFunction *fn, KirStmtKind kind, const char *text,
|
||||
const char *widget, KirSourceSpan span)
|
||||
{
|
||||
KirStmt *stmts;
|
||||
KirStmt *st;
|
||||
|
||||
if(fn == NULL)
|
||||
return NULL;
|
||||
stmts = kir_realloc_array(fn->stmts, &fn->stmt_cap, fn->stmt_count,
|
||||
sizeof(KirStmt));
|
||||
if(stmts == NULL)
|
||||
return NULL;
|
||||
fn->stmts = stmts;
|
||||
st = &fn->stmts[fn->stmt_count++];
|
||||
memset(st, 0, sizeof(*st));
|
||||
st->kind = kind;
|
||||
kir_copy(st->text, sizeof(st->text), text);
|
||||
kir_copy(st->widget, sizeof(st->widget), widget);
|
||||
st->span = span;
|
||||
return st;
|
||||
}
|
||||
|
||||
KirStmt *
|
||||
KirFunctionAddWidget(KirFunction *fn, const char *widget, const char *args,
|
||||
const char *text, KirSourceSpan span)
|
||||
{
|
||||
KirStmt *st = KirFunctionAddStmt(fn, KIR_STMT_WIDGET, text, widget, span);
|
||||
|
||||
if(st != NULL)
|
||||
kir_copy(st->args, sizeof(st->args), args);
|
||||
return st;
|
||||
}
|
||||
|
||||
const char *
|
||||
KirImportKindName(KirImportKind kind)
|
||||
{
|
||||
switch(kind) {
|
||||
case KIR_IMPORT_HEADER: return "header";
|
||||
case KIR_IMPORT_MODULE: return "module";
|
||||
case KIR_IMPORT_EXTERN: return "extern";
|
||||
case KIR_IMPORT_INTRINSIC: return "intrinsic";
|
||||
case KIR_IMPORT_CAPABILITY: return "capability";
|
||||
case KIR_IMPORT_HOST: return "host";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
KirStmtKindName(KirStmtKind kind)
|
||||
{
|
||||
switch(kind) {
|
||||
case KIR_STMT_BLOCK_OPEN: return "block_open";
|
||||
case KIR_STMT_BLOCK_CLOSE: return "block_close";
|
||||
case KIR_STMT_DECL: return "decl";
|
||||
case KIR_STMT_ASSIGN: return "assign";
|
||||
case KIR_STMT_EXPR: return "expr";
|
||||
case KIR_STMT_IF: return "if";
|
||||
case KIR_STMT_WHILE: return "while";
|
||||
case KIR_STMT_FOR: return "for";
|
||||
case KIR_STMT_SWITCH: return "switch";
|
||||
case KIR_STMT_CASE: return "case";
|
||||
case KIR_STMT_RETURN: return "return";
|
||||
case KIR_STMT_BREAK: return "break";
|
||||
case KIR_STMT_CONTINUE: return "continue";
|
||||
case KIR_STMT_GOTO: return "goto";
|
||||
case KIR_STMT_LABEL: return "label";
|
||||
case KIR_STMT_DEFER: return "defer";
|
||||
case KIR_STMT_UNUSED: return "unused";
|
||||
case KIR_STMT_RAW: return "raw";
|
||||
case KIR_STMT_WIDGET: return "widget";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
kir_dump_span(FILE *out, KirSourceSpan span)
|
||||
{
|
||||
fprintf(out, "%s:%d:%d", span.path, span.line, span.column);
|
||||
}
|
||||
|
||||
void
|
||||
KirProgramDump(const KirProgram *program, FILE *out)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(out == NULL)
|
||||
return;
|
||||
fprintf(out, "kir 1\n");
|
||||
if(program == NULL)
|
||||
return;
|
||||
for(i = 0; i < program->module_count; i++) {
|
||||
const KirModule *m = &program->modules[i];
|
||||
int j;
|
||||
|
||||
fprintf(out, "module %s source %s span ", m->name, m->source_path);
|
||||
kir_dump_span(out, m->span);
|
||||
fprintf(out, "\n");
|
||||
if(m->app.has_app) {
|
||||
fprintf(out, " app title %s size %dx%d fps %d theme %s "
|
||||
"dark %d font_examples %d frame %s init %s scene %s "
|
||||
"shutdown %s\n",
|
||||
m->app.title[0] ? m->app.title : "\"\"",
|
||||
m->app.width, m->app.height, m->app.fps,
|
||||
m->app.theme[0] ? m->app.theme : "",
|
||||
m->app.dark_mode, m->app.font_examples,
|
||||
m->app.frame[0] ? m->app.frame : "",
|
||||
m->app.init[0] ? m->app.init : "",
|
||||
m->app.scene[0] ? m->app.scene : "",
|
||||
m->app.shutdown[0] ? m->app.shutdown : "");
|
||||
}
|
||||
for(j = 0; j < m->import_count; j++) {
|
||||
const KirImport *imp = &m->imports[j];
|
||||
|
||||
fprintf(out, " import %s %s target %s required %d signature %s span ",
|
||||
KirImportKindName(imp->kind), imp->name, imp->target,
|
||||
imp->required, imp->signature);
|
||||
kir_dump_span(out, imp->span);
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
for(j = 0; j < m->state_count; j++) {
|
||||
const KirStateField *f = &m->state_fields[j];
|
||||
|
||||
fprintf(out, " state %s type %s init %s span ",
|
||||
f->name, f->type, f->init);
|
||||
kir_dump_span(out, f->span);
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
for(j = 0; j < m->function_count; j++) {
|
||||
const KirFunction *fn = &m->functions[j];
|
||||
int k;
|
||||
|
||||
fprintf(out, " function %s args %s return %s exported %d span ",
|
||||
fn->name, fn->args, fn->return_type, fn->exported);
|
||||
kir_dump_span(out, fn->span);
|
||||
fprintf(out, "\n");
|
||||
for(k = 0; k < fn->stmt_count; k++) {
|
||||
const KirStmt *st = &fn->stmts[k];
|
||||
|
||||
fprintf(out, " stmt %s widget %s args %s text %s span ",
|
||||
KirStmtKindName(st->kind), st->widget, st->args,
|
||||
st->text);
|
||||
kir_dump_span(out, st->span);
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* kir.h - Kryon intermediate representation.
|
||||
*
|
||||
* KIR is the shared compiler representation between .kry source and the C/KRB
|
||||
* backends. This module owns the tree shape, explicit allocation, source spans,
|
||||
* and deterministic dumps used by tools and tests.
|
||||
*/
|
||||
#ifndef KRYON_KIR_H
|
||||
#define KRYON_KIR_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
enum {
|
||||
KIR_PATH_MAX = 1024,
|
||||
KIR_NAME_MAX = 128,
|
||||
KIR_TEXT_MAX = 4096
|
||||
};
|
||||
|
||||
typedef enum KirImportKind {
|
||||
KIR_IMPORT_HEADER = 1,
|
||||
KIR_IMPORT_MODULE,
|
||||
KIR_IMPORT_EXTERN,
|
||||
KIR_IMPORT_INTRINSIC,
|
||||
KIR_IMPORT_CAPABILITY,
|
||||
KIR_IMPORT_HOST
|
||||
} KirImportKind;
|
||||
|
||||
typedef enum KirStmtKind {
|
||||
KIR_STMT_UNKNOWN = 0,
|
||||
KIR_STMT_BLOCK_OPEN,
|
||||
KIR_STMT_BLOCK_CLOSE,
|
||||
KIR_STMT_DECL,
|
||||
KIR_STMT_ASSIGN,
|
||||
KIR_STMT_EXPR,
|
||||
KIR_STMT_IF,
|
||||
KIR_STMT_WHILE,
|
||||
KIR_STMT_FOR,
|
||||
KIR_STMT_SWITCH,
|
||||
KIR_STMT_CASE,
|
||||
KIR_STMT_RETURN,
|
||||
KIR_STMT_BREAK,
|
||||
KIR_STMT_CONTINUE,
|
||||
KIR_STMT_GOTO,
|
||||
KIR_STMT_LABEL,
|
||||
KIR_STMT_DEFER,
|
||||
KIR_STMT_UNUSED,
|
||||
KIR_STMT_RAW,
|
||||
KIR_STMT_WIDGET
|
||||
} KirStmtKind;
|
||||
|
||||
typedef struct KirSourceSpan {
|
||||
char path[KIR_PATH_MAX];
|
||||
int line;
|
||||
int column;
|
||||
} KirSourceSpan;
|
||||
|
||||
typedef struct KirStateField {
|
||||
char name[KIR_NAME_MAX];
|
||||
char type[KIR_NAME_MAX];
|
||||
char init[KIR_TEXT_MAX];
|
||||
char guard[KIR_TEXT_MAX]; /* enclosing '#if' condition (expanded) */
|
||||
KirSourceSpan span;
|
||||
} KirStateField;
|
||||
|
||||
typedef struct KirImport {
|
||||
KirImportKind kind;
|
||||
char name[KIR_NAME_MAX];
|
||||
char target[KIR_PATH_MAX];
|
||||
char signature[KIR_TEXT_MAX];
|
||||
int required;
|
||||
char guard[KIR_TEXT_MAX]; /* enclosing '#if' condition (expanded) */
|
||||
KirSourceSpan span;
|
||||
} KirImport;
|
||||
|
||||
typedef struct KirStmt {
|
||||
KirStmtKind kind;
|
||||
char text[KIR_TEXT_MAX];
|
||||
char widget[KIR_NAME_MAX];
|
||||
char args[KIR_TEXT_MAX];
|
||||
KirSourceSpan span;
|
||||
} KirStmt;
|
||||
|
||||
typedef struct KirFunction {
|
||||
char name[KIR_NAME_MAX];
|
||||
char args[KIR_TEXT_MAX];
|
||||
char return_type[KIR_NAME_MAX];
|
||||
int exported;
|
||||
int is_extern;
|
||||
int is_colon; /* 'Name :: (...) {' form: C name has no _kry_draw suffix */
|
||||
int is_public; /* screen/preview/page keyword: a project route */
|
||||
char extern_target[KIR_NAME_MAX]; /* '#extern "pkg.Fn"' quoted symbol */
|
||||
char guard[KIR_TEXT_MAX]; /* enclosing '#if' condition (expanded) */
|
||||
KirSourceSpan span;
|
||||
KirStmt *stmts;
|
||||
int stmt_count;
|
||||
int stmt_cap;
|
||||
} KirFunction;
|
||||
|
||||
typedef struct KirGlobal {
|
||||
char name[KIR_NAME_MAX];
|
||||
char type[KIR_TEXT_MAX];
|
||||
char init[KIR_TEXT_MAX];
|
||||
int is_static; /* 'static name: T = init' — internal linkage */
|
||||
char guard[KIR_TEXT_MAX]; /* enclosing '#if' condition (expanded) */
|
||||
KirSourceSpan span;
|
||||
} KirGlobal;
|
||||
|
||||
/* A `Name :: #define value` module constant — emitted as a real C #define. */
|
||||
typedef struct KirDefine {
|
||||
char name[KIR_NAME_MAX];
|
||||
char value[KIR_TEXT_MAX];
|
||||
char guard[KIR_TEXT_MAX]; /* enclosing '#if' condition (expanded) */
|
||||
KirSourceSpan span;
|
||||
} KirDefine;
|
||||
|
||||
/* A `Name :: struct { fields }` type declaration. body holds the raw field
|
||||
* lines (one per line, no braces). */
|
||||
typedef struct KirType {
|
||||
char name[KIR_NAME_MAX];
|
||||
char body[KIR_TEXT_MAX * 2];
|
||||
int is_enum; /* 'Name :: enum' — emit typedef enum, not struct */
|
||||
char guard[KIR_TEXT_MAX]; /* enclosing '#if' condition (expanded) */
|
||||
KirSourceSpan span;
|
||||
} KirType;
|
||||
|
||||
typedef struct KirAppMeta {
|
||||
int has_app;
|
||||
char title[KIR_NAME_MAX];
|
||||
int width;
|
||||
int height;
|
||||
int fps;
|
||||
char theme[KIR_NAME_MAX];
|
||||
int dark_mode;
|
||||
int font_examples;
|
||||
char frame[KIR_NAME_MAX];
|
||||
char init[KIR_NAME_MAX];
|
||||
char scene[KIR_NAME_MAX];
|
||||
char shutdown[KIR_NAME_MAX];
|
||||
} KirAppMeta;
|
||||
|
||||
typedef struct KirModule {
|
||||
char name[KIR_NAME_MAX];
|
||||
char source_path[KIR_PATH_MAX];
|
||||
KirSourceSpan span;
|
||||
KirAppMeta app;
|
||||
KirGlobal *globals;
|
||||
int global_count;
|
||||
int global_cap;
|
||||
KirDefine *defines;
|
||||
int define_count;
|
||||
int define_cap;
|
||||
KirType *types;
|
||||
int type_count;
|
||||
int type_cap;
|
||||
KirStateField *state_fields;
|
||||
int state_count;
|
||||
int state_cap;
|
||||
KirImport *imports;
|
||||
int import_count;
|
||||
int import_cap;
|
||||
KirFunction *functions;
|
||||
int function_count;
|
||||
int function_cap;
|
||||
} KirModule;
|
||||
|
||||
typedef struct KirProgram {
|
||||
KirModule *modules;
|
||||
int module_count;
|
||||
int module_cap;
|
||||
} KirProgram;
|
||||
|
||||
KirProgram *KirProgramNew(void);
|
||||
void KirProgramFree(KirProgram *program);
|
||||
KirSourceSpan KirSpan(const char *path, int line, int column);
|
||||
KirModule *KirProgramAddModule(KirProgram *program, const char *name,
|
||||
const char *source_path, KirSourceSpan span);
|
||||
KirStateField *KirModuleAddStateField(KirModule *module, const char *name,
|
||||
const char *type, const char *init,
|
||||
KirSourceSpan span);
|
||||
KirImport *KirModuleAddImport(KirModule *module, KirImportKind kind,
|
||||
const char *name, const char *target,
|
||||
const char *signature, int required,
|
||||
KirSourceSpan span);
|
||||
KirFunction *KirModuleAddFunction(KirModule *module, const char *name,
|
||||
const char *args, const char *return_type,
|
||||
int exported, KirSourceSpan span);
|
||||
void KirModuleAddGlobal(KirModule *module, const char *name, const char *type,
|
||||
const char *init, KirSourceSpan span);
|
||||
void KirModuleAddStatic(KirModule *module, const char *name, const char *type,
|
||||
const char *init, KirSourceSpan span);
|
||||
KirDefine *KirModuleAddDefine(KirModule *module, const char *name,
|
||||
const char *value, KirSourceSpan span);
|
||||
KirType *KirModuleAddType(KirModule *module, const char *name,
|
||||
KirSourceSpan span);
|
||||
KirStmt *KirFunctionAddStmt(KirFunction *fn, KirStmtKind kind,
|
||||
const char *text, const char *widget,
|
||||
KirSourceSpan span);
|
||||
KirStmt *KirFunctionAddWidget(KirFunction *fn, const char *widget,
|
||||
const char *args, const char *text,
|
||||
KirSourceSpan span);
|
||||
const char *KirImportKindName(KirImportKind kind);
|
||||
const char *KirStmtKindName(KirStmtKind kind);
|
||||
void KirProgramDump(const KirProgram *program, FILE *out);
|
||||
|
||||
#endif /* KRYON_KIR_H */
|
||||
+1832
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,14 @@
|
||||
#ifndef KRYON_KIR_PARSE_H
|
||||
#define KRYON_KIR_PARSE_H
|
||||
|
||||
#include "kir.h"
|
||||
|
||||
/*
|
||||
* Parse a .kry source file into a KirProgram. Returns a heap-allocated
|
||||
* program (caller frees with KirProgramFree), or NULL on fatal error.
|
||||
* This is the shared Kir frontend used by k2ir (dump), k2c (C backend),
|
||||
* and k2b (krb backend).
|
||||
*/
|
||||
KirProgram *kir_parse_file(const char *path, const char *root);
|
||||
|
||||
#endif /* KRYON_KIR_PARSE_H */
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* krb-run — headless KRB cartridge runner (plan 11, phase 1).
|
||||
*
|
||||
* Loads a .krb, renders it once with the kry_sw software rasterizer
|
||||
* (optionally wrapped in the recording backend), and writes the frame as
|
||||
* a PNG and/or the vtable call stream as text. Golden files for engine
|
||||
* conformance are produced with --png/--record and compared by
|
||||
* tests/krb_engine_test.sh.
|
||||
*
|
||||
* Usage: krb-run [--png out.png] [--record out.txt] [--w W] [--h H] file.krb
|
||||
*/
|
||||
|
||||
#include "krb.h"
|
||||
#include "kry_backend_rec.h"
|
||||
#include "kry_sw.h"
|
||||
#include "png_write.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *png_path = NULL;
|
||||
const char *rec_path = NULL;
|
||||
const char *krb_path = NULL;
|
||||
int w = 800;
|
||||
int h = 600;
|
||||
int frames = 1;
|
||||
int i;
|
||||
KrbImage img;
|
||||
KrySw sw;
|
||||
KryBackendRec rec;
|
||||
long calls = -1;
|
||||
FILE *recf = NULL;
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "--png") == 0 && i + 1 < argc)
|
||||
png_path = argv[++i];
|
||||
else if(strcmp(argv[i], "--record") == 0 && i + 1 < argc)
|
||||
rec_path = argv[++i];
|
||||
else if(strcmp(argv[i], "--w") == 0 && i + 1 < argc)
|
||||
w = atoi(argv[++i]);
|
||||
else if(strcmp(argv[i], "--h") == 0 && i + 1 < argc)
|
||||
h = atoi(argv[++i]);
|
||||
else if(strcmp(argv[i], "--frames") == 0 && i + 1 < argc)
|
||||
frames = atoi(argv[++i]);
|
||||
else if(argv[i][0] != '-' && krb_path == NULL)
|
||||
krb_path = argv[i];
|
||||
else {
|
||||
fprintf(stderr,
|
||||
"usage: krb-run [--png out.png] [--record out.txt]"
|
||||
" [--w W] [--h H] file.krb\n");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if(krb_path == NULL) {
|
||||
fprintf(stderr, "krb-run: no cartridge given\n");
|
||||
return 2;
|
||||
}
|
||||
memset(&img, 0, sizeof(img));
|
||||
if(KrbLoadFile(&img, krb_path) != 0) {
|
||||
fprintf(stderr, "krb-run: load failed: %s\n", krb_path);
|
||||
return 1;
|
||||
}
|
||||
if(KrySwInit(&sw, NULL, w, h) != 0) {
|
||||
fprintf(stderr, "krb-run: rasterizer init failed\n");
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
const char *uis = getenv("KRB_RUN_UI_SCALE");
|
||||
|
||||
if(uis != NULL) {
|
||||
int pm = (int)(atof(uis) * 1000.0f + 0.5f);
|
||||
|
||||
if(pm > 0 && pm <= 8000)
|
||||
sw.scale = pm;
|
||||
}
|
||||
}
|
||||
if(getenv("KRB_RUN_THEME_LIGHT") != NULL) {
|
||||
KrySwSetTheme(&sw, KRY_THEME_BACKGROUND, 0xffffffffu);
|
||||
KrySwSetTheme(&sw, KRY_THEME_SURFACE, 0xfbfbfbffu);
|
||||
KrySwSetTheme(&sw, KRY_THEME_ICON, 0xd3d3d3ffu);
|
||||
KrySwSetTheme(&sw, KRY_THEME_TEXT, 0x00000000u | 0xffu);
|
||||
KrySwSetTheme(&sw, KRY_THEME_BUTTON, 0xffffffffu);
|
||||
}
|
||||
if(0) {
|
||||
fprintf(stderr, "krb-run: rasterizer init failed\n");
|
||||
return 1;
|
||||
}
|
||||
KrbAutoMount(&img);
|
||||
if(rec_path != NULL) {
|
||||
recf = fopen(rec_path, "w");
|
||||
if(recf == NULL) {
|
||||
fprintf(stderr, "krb-run: cannot write %s\n", rec_path);
|
||||
return 1;
|
||||
}
|
||||
KryBackendSelect(KryBackendRecBackend(&rec, recf, KrySwBackend(&sw)));
|
||||
} else {
|
||||
{
|
||||
const unsigned char *ad = NULL;
|
||||
unsigned al = 0;
|
||||
unsigned ak = 0;
|
||||
|
||||
if(KrbAssetFind(&img, "@atlas", &ad, &al, &ak, NULL, NULL) == 0 &&
|
||||
ak == 1)
|
||||
KrySwSetAtlas(&sw, ad, al);
|
||||
}
|
||||
KryBackendSelect(KrySwBackend(&sw));
|
||||
}
|
||||
{
|
||||
int f;
|
||||
|
||||
for(f = 0; f < frames; f++) {
|
||||
KrySwAdvance(&sw, 1.0f / 60.0f);
|
||||
KrbDraw(&img, 0, 0, w, h);
|
||||
}
|
||||
}
|
||||
if(recf != NULL) {
|
||||
fclose(recf);
|
||||
calls = KryBackendRecCalls(&rec);
|
||||
}
|
||||
if(png_path != NULL && krb_png_write(png_path, sw.pixels, sw.w, sw.h) != 0) {
|
||||
fprintf(stderr, "krb-run: cannot write %s\n", png_path);
|
||||
return 1;
|
||||
}
|
||||
KrbFree(&img);
|
||||
KrySwFree(&sw);
|
||||
printf("krb-run ok %s %dx%d calls=%ld\n", krb_path, w, h, calls);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Minimal PNG writer for krb-run: 8-bit RGBA, stored (uncompressed)
|
||||
* deflate blocks. No external dependencies, deterministic output.
|
||||
*/
|
||||
|
||||
#include "png_write.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static unsigned
|
||||
crc32_buf(const unsigned char *p, size_t n)
|
||||
{
|
||||
static unsigned table[256];
|
||||
static int built = 0;
|
||||
unsigned crc = 0xffffffffu;
|
||||
size_t i;
|
||||
|
||||
if(!built) {
|
||||
int i;
|
||||
for(i = 0; i < 256; i++) {
|
||||
unsigned c = (unsigned)i;
|
||||
int k;
|
||||
for(k = 0; k < 8; k++)
|
||||
c = (c & 1) ? 0xedb88320u ^ (c >> 1) : c >> 1;
|
||||
table[i] = c;
|
||||
}
|
||||
built = 1;
|
||||
}
|
||||
for(i = 0; i < n; i++)
|
||||
crc = table[(crc ^ p[i]) & 0xff] ^ (crc >> 8);
|
||||
return crc ^ 0xffffffffu;
|
||||
}
|
||||
|
||||
static void
|
||||
be32(unsigned char *p, unsigned v)
|
||||
{
|
||||
p[0] = (unsigned char)(v >> 24);
|
||||
p[1] = (unsigned char)(v >> 16);
|
||||
p[2] = (unsigned char)(v >> 8);
|
||||
p[3] = (unsigned char)v;
|
||||
}
|
||||
|
||||
static void
|
||||
png_chunk(FILE *f, const char *type, const unsigned char *data, size_t len)
|
||||
{
|
||||
unsigned char hdr[8];
|
||||
unsigned char *buf;
|
||||
unsigned crc;
|
||||
|
||||
buf = malloc(4 + len);
|
||||
if(buf == NULL)
|
||||
return;
|
||||
memcpy(buf, type, 4);
|
||||
if(len > 0 && data != NULL)
|
||||
memcpy(buf + 4, data, len);
|
||||
crc = crc32_buf(buf, 4 + len);
|
||||
be32(hdr, (unsigned)len);
|
||||
memcpy(hdr + 4, type, 4);
|
||||
fwrite(hdr, 1, 8, f);
|
||||
if(len > 0)
|
||||
fwrite(data, 1, len, f);
|
||||
be32(hdr, crc);
|
||||
fwrite(hdr, 1, 4, f);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static unsigned
|
||||
adler32_buf(const unsigned char *p, size_t n)
|
||||
{
|
||||
unsigned a = 1;
|
||||
unsigned b = 0;
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
a = (a + p[i]) % 65521u;
|
||||
b = (b + a) % 65521u;
|
||||
}
|
||||
return (b << 16) | a;
|
||||
}
|
||||
|
||||
int
|
||||
krb_png_write(const char *path, const unsigned char *rgba, int w, int h)
|
||||
{
|
||||
static const unsigned char sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
unsigned char ihdr[13];
|
||||
unsigned char tail[4];
|
||||
size_t rawlen = (size_t)h * (1 + (size_t)w * 4);
|
||||
unsigned char *raw;
|
||||
unsigned char *z;
|
||||
size_t zn = 0;
|
||||
size_t off = 0;
|
||||
size_t left;
|
||||
const unsigned char *src;
|
||||
FILE *f;
|
||||
int row;
|
||||
int ok = 0;
|
||||
|
||||
f = fopen(path, "wb");
|
||||
if(f == NULL)
|
||||
return -1;
|
||||
raw = malloc(rawlen);
|
||||
z = malloc(rawlen + (rawlen / 65535 + 1) * 5 + 16);
|
||||
if(raw == NULL || z == NULL)
|
||||
goto out;
|
||||
|
||||
for(row = 0; row < h; row++) {
|
||||
raw[off++] = 0; /* filter: none */
|
||||
memcpy(raw + off, rgba + (size_t)row * w * 4, (size_t)w * 4);
|
||||
off += (size_t)w * 4;
|
||||
}
|
||||
|
||||
z[zn++] = 0x78; /* zlib header, fastest */
|
||||
z[zn++] = 0x01;
|
||||
src = raw;
|
||||
left = rawlen;
|
||||
while(left > 0) {
|
||||
size_t chunk = left > 65535 ? 65535 : left;
|
||||
unsigned char bhdr[5];
|
||||
bhdr[0] = (left - chunk == 0) ? 1 : 0; /* BFINAL on last block */
|
||||
bhdr[1] = (unsigned char)(chunk & 0xff);
|
||||
bhdr[2] = (unsigned char)(chunk >> 8);
|
||||
bhdr[3] = (unsigned char)(~chunk & 0xff);
|
||||
bhdr[4] = (unsigned char)((~chunk >> 8) & 0xff);
|
||||
memcpy(z + zn, bhdr, 5);
|
||||
zn += 5;
|
||||
memcpy(z + zn, src, chunk);
|
||||
zn += chunk;
|
||||
src += chunk;
|
||||
left -= chunk;
|
||||
}
|
||||
be32(tail, adler32_buf(raw, rawlen));
|
||||
memcpy(z + zn, tail, 4);
|
||||
zn += 4;
|
||||
|
||||
fwrite(sig, 1, 8, f);
|
||||
be32(ihdr, (unsigned)w);
|
||||
be32(ihdr + 4, (unsigned)h);
|
||||
ihdr[8] = 8; /* bit depth */
|
||||
ihdr[9] = 6; /* RGBA */
|
||||
ihdr[10] = 0; /* deflate */
|
||||
ihdr[11] = 0; /* filter */
|
||||
ihdr[12] = 0; /* interlace */
|
||||
png_chunk(f, "IHDR", ihdr, 13);
|
||||
png_chunk(f, "IDAT", z, zn);
|
||||
png_chunk(f, "IEND", NULL, 0);
|
||||
ok = 1;
|
||||
out:
|
||||
free(raw);
|
||||
free(z);
|
||||
if(fclose(f) != 0)
|
||||
ok = 0;
|
||||
return ok ? 0 : -1;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef KRB_RUN_PNG_WRITE_H
|
||||
#define KRB_RUN_PNG_WRITE_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int krb_png_write(const char *path, const unsigned char *rgba, int w, int h);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* krb-sdl — SDL2 desktop host for KRB cartridges (plan 11, phase 7).
|
||||
*
|
||||
* Same shape as the web host: the kry_sw rasterizer produces the frame,
|
||||
* SDL2 owns the window, input, and presentation (streaming texture).
|
||||
* This is the template for the Android EGL host.
|
||||
*
|
||||
* Usage: krb-sdl [--png out.png] [--w W] [--h H] file.krb
|
||||
* --png renders exactly one frame, dumps it, and exits (for tests;
|
||||
* runs fine under SDL_VIDEODRIVER=dummy).
|
||||
*/
|
||||
|
||||
#include "krb.h"
|
||||
#include "kry_sw.h"
|
||||
#include "png_write.h"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
const char *png_path = NULL;
|
||||
const char *krb_path = NULL;
|
||||
int w = 800;
|
||||
int h = 600;
|
||||
int i;
|
||||
KrbImage img;
|
||||
KrySw sw;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *texture;
|
||||
|
||||
for(i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "--png") == 0 && i + 1 < argc)
|
||||
png_path = argv[++i];
|
||||
else if(strcmp(argv[i], "--w") == 0 && i + 1 < argc)
|
||||
w = atoi(argv[++i]);
|
||||
else if(strcmp(argv[i], "--h") == 0 && i + 1 < argc)
|
||||
h = atoi(argv[++i]);
|
||||
else if(argv[i][0] != '-' && krb_path == NULL)
|
||||
krb_path = argv[i];
|
||||
else {
|
||||
fprintf(stderr,
|
||||
"usage: krb-sdl [--png out.png] [--w W] [--h H]"
|
||||
" file.krb\n");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if(krb_path == NULL) {
|
||||
fprintf(stderr, "krb-sdl: no cartridge given\n");
|
||||
return 2;
|
||||
}
|
||||
memset(&img, 0, sizeof(img));
|
||||
if(KrbLoadFile(&img, krb_path) != 0) {
|
||||
fprintf(stderr, "krb-sdl: load failed: %s\n", krb_path);
|
||||
return 1;
|
||||
}
|
||||
if(KrySwInit(&sw, NULL, w, h) != 0) {
|
||||
fprintf(stderr, "krb-sdl: rasterizer init failed\n");
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
const unsigned char *ad = NULL;
|
||||
unsigned al = 0;
|
||||
unsigned ak = 0;
|
||||
|
||||
if(KrbAssetFind(&img, "@atlas", &ad, &al, &ak, NULL, NULL) == 0 &&
|
||||
ak == 1)
|
||||
KrySwSetAtlas(&sw, ad, al);
|
||||
}
|
||||
KrbAutoMount(&img);
|
||||
KryBackendSelect(KrySwBackend(&sw));
|
||||
|
||||
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
fprintf(stderr, "krb-sdl: SDL_Init: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
if(SDL_CreateWindowAndRenderer(w, h, SDL_WINDOW_RESIZABLE, &window,
|
||||
&renderer) != 0) {
|
||||
fprintf(stderr, "krb-sdl: window: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_SetWindowTitle(window, "krb-sdl");
|
||||
SDL_StartTextInput();
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");
|
||||
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32,
|
||||
SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||
if(texture == NULL) {
|
||||
fprintf(stderr, "krb-sdl: texture: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(png_path != NULL) {
|
||||
/* single deterministic frame for the exactness comparator */
|
||||
KrySwAdvance(&sw, 1.0f / 60.0f);
|
||||
KrbDraw(&img, 0, 0, w, h);
|
||||
SDL_UpdateTexture(texture, NULL, sw.pixels, sw.stride);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||
{
|
||||
unsigned char *buf = malloc((size_t)w * h * 4);
|
||||
SDL_Rect r = {0, 0, w, h};
|
||||
int ok;
|
||||
|
||||
if(buf == NULL)
|
||||
return 1;
|
||||
ok = SDL_RenderReadPixels(renderer, &r,
|
||||
SDL_PIXELFORMAT_RGBA32, buf,
|
||||
w * 4) == 0;
|
||||
if(ok)
|
||||
ok = krb_png_write(png_path, buf, w, h) == 0;
|
||||
free(buf);
|
||||
if(!ok) {
|
||||
fprintf(stderr, "krb-sdl: frame dump failed\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
printf("krb-sdl ok %s %dx%d\n", krb_path, w, h);
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
KrbFree(&img);
|
||||
KrySwFree(&sw);
|
||||
return 0;
|
||||
}
|
||||
for(;;) {
|
||||
SDL_Event ev;
|
||||
int running = 1;
|
||||
|
||||
while(SDL_PollEvent(&ev)) {
|
||||
if(ev.type == SDL_QUIT)
|
||||
running = 0;
|
||||
else if(ev.type == SDL_MOUSEMOTION)
|
||||
KrySwMouse(&sw, ev.motion.x, ev.motion.y);
|
||||
else if(ev.type == SDL_MOUSEBUTTONDOWN)
|
||||
KrySwButtonDown(&sw, 0);
|
||||
else if(ev.type == SDL_MOUSEBUTTONUP)
|
||||
KrySwButtonUp(&sw, 0);
|
||||
else if(ev.type == SDL_MOUSEWHEEL)
|
||||
KrySwWheel(&sw, ev.wheel.y * 50);
|
||||
else if(ev.type == SDL_TEXTINPUT)
|
||||
KrySwText(&sw, (unsigned)(unsigned char)ev.text.text[0]);
|
||||
else if(ev.type == SDL_KEYDOWN &&
|
||||
ev.key.keysym.sym == SDLK_BACKSPACE)
|
||||
KrySwText(&sw, 0x08);
|
||||
}
|
||||
if(!running)
|
||||
break;
|
||||
|
||||
KrySwAdvance(&sw, 1.0f / 60.0f);
|
||||
KrbDraw(&img, 0, 0, w, h);
|
||||
|
||||
if(SDL_UpdateTexture(texture, NULL, sw.pixels, sw.stride) != 0) {
|
||||
fprintf(stderr, "krb-sdl: update: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
if(png_path != NULL) {
|
||||
/* Test mode: read back through the SDL renderer — the same
|
||||
* pixels that reached the screen — and dump them. */
|
||||
unsigned char *buf = malloc((size_t)w * h * 4);
|
||||
SDL_Rect r = {0, 0, w, h};
|
||||
int ok;
|
||||
if(buf == NULL)
|
||||
return 1;
|
||||
ok = SDL_RenderReadPixels(renderer, &r,
|
||||
SDL_PIXELFORMAT_RGBA32, buf,
|
||||
w * 4) == 0;
|
||||
if(ok)
|
||||
ok = krb_png_write(png_path, buf, w, h) == 0;
|
||||
free(buf);
|
||||
if(!ok) {
|
||||
fprintf(stderr, "krb-sdl: frame dump failed\n");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
SDL_Delay(16);
|
||||
}
|
||||
|
||||
printf("krb-sdl ok %s %dx%d\n", krb_path, w, h);
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
KrbFree(&img);
|
||||
KrySwFree(&sw);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* krb-web — native web host for KRB cartridges (plan 11, phase 3).
|
||||
*
|
||||
* Compiles the KRB runtime + kry_sw software rasterizer to wasm with
|
||||
* emscripten. Pixel-identical to the native headless renderer: the frame
|
||||
* is blitted into an ImageData every tick. Cartridge is preloaded at
|
||||
* /app.krb (--preload-file); input comes from canvas events through the
|
||||
* exported krb_web_mouse / krb_web_button.
|
||||
*
|
||||
* Build: make krb-web KRB=examples/02_buttons.kry
|
||||
*/
|
||||
|
||||
#include "krb.h"
|
||||
#include "kry_sw.h"
|
||||
|
||||
#include <emscripten.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef KRB_WEB_CARTRIDGE
|
||||
#define KRB_WEB_CARTRIDGE "/app.krb"
|
||||
#endif
|
||||
|
||||
static KrbImage g_img;
|
||||
static KrySw g_sw;
|
||||
static int g_running;
|
||||
|
||||
#ifdef KRB_WEB_ONESHOT
|
||||
static int g_frames;
|
||||
#endif
|
||||
|
||||
static void
|
||||
frame(void)
|
||||
{
|
||||
KrySwAdvance(&g_sw, 1.0f / 60.0f);
|
||||
KrbDraw(&g_img, 0, 0, g_sw.w, g_sw.h);
|
||||
EM_ASM({
|
||||
var ptr = $0;
|
||||
var w = $1;
|
||||
var h = $2;
|
||||
var cv = Module.canvas;
|
||||
var ctx = cv.getContext('2d');
|
||||
if (!Module.krbImg || Module.krbImg.width !== w ||
|
||||
Module.krbImg.height !== h)
|
||||
Module.krbImg = ctx.createImageData(w, h);
|
||||
Module.krbImg.data.set(HEAPU8.subarray(ptr, ptr + w * h * 4));
|
||||
ctx.putImageData(Module.krbImg, 0, 0);
|
||||
}, g_sw.pixels, g_sw.w, g_sw.h);
|
||||
#ifdef KRB_WEB_ONESHOT
|
||||
if(++g_frames >= 1)
|
||||
emscripten_cancel_main_loop();
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/* The player waits for a cartridge: the shell writes the picked or
|
||||
* dropped file to KRB_WEB_CARTRIDGE in MEMFS and calls krb_web_start. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
krb_web_start(void)
|
||||
{
|
||||
memset(&g_img, 0, sizeof(g_img));
|
||||
if(g_sw.pixels != NULL)
|
||||
KrySwFree(&g_sw);
|
||||
if(KrbLoadFile(&g_img, KRB_WEB_CARTRIDGE) != 0) {
|
||||
fprintf(stderr, "krb-player: load failed: %s\n", KRB_WEB_CARTRIDGE);
|
||||
return 1;
|
||||
}
|
||||
if(KrySwInit(&g_sw, NULL, 800, 600) != 0)
|
||||
return 1;
|
||||
{
|
||||
const unsigned char *ad = NULL;
|
||||
unsigned al = 0;
|
||||
unsigned ak = 0;
|
||||
|
||||
if(KrbAssetFind(&g_img, "@atlas", &ad, &al, &ak, NULL, NULL) == 0 &&
|
||||
ak == 1)
|
||||
KrySwSetAtlas(&g_sw, ad, al);
|
||||
}
|
||||
KryBackendSelect(KrySwBackend(&g_sw));
|
||||
if(!g_running)
|
||||
emscripten_set_main_loop(frame, 0, 1);
|
||||
g_running = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
krb_web_mouse(int x, int y)
|
||||
{
|
||||
KrySwMouse(&g_sw, x, y);
|
||||
}
|
||||
|
||||
void
|
||||
krb_web_text(int cp)
|
||||
{
|
||||
KrySwText(&g_sw, (unsigned)cp);
|
||||
}
|
||||
|
||||
void
|
||||
krb_web_wheel(int dy)
|
||||
{
|
||||
KrySwWheel(&g_sw, dy);
|
||||
}
|
||||
|
||||
void
|
||||
krb_web_button(int button, int down)
|
||||
{
|
||||
if(down)
|
||||
KrySwButtonDown(&g_sw, button);
|
||||
else
|
||||
KrySwButtonUp(&g_sw, button);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/* Pre-js for the KRB_WEB_ONESHOT node build: stubs a canvas whose 2D
|
||||
* context records the blitted ImageData, so the wasm blit path can be
|
||||
* byte-compared against the native kry_sw frame without a browser. */
|
||||
var Module = {
|
||||
printErr: function(t) { console.error(t); },
|
||||
canvas: {
|
||||
getContext: function() {
|
||||
return {
|
||||
createImageData: function(w, h) {
|
||||
return { width: w, height: h,
|
||||
data: new Uint8ClampedArray(w * h * 4) };
|
||||
},
|
||||
putImageData: function(img) {
|
||||
if (globalThis.__krb_frame)
|
||||
return;
|
||||
globalThis.__krb_frame = Buffer.from(img.data);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
onRuntimeInitialized: function() {
|
||||
var FS = Module.FS;
|
||||
if (FS)
|
||||
console.error('FS root: ' + FS.readdir('/').join(','));
|
||||
},
|
||||
onExit: function() {
|
||||
if (!globalThis.__krb_frame) {
|
||||
console.error('node-capture: no frame captured');
|
||||
process.exit(1);
|
||||
}
|
||||
process.stdout.write(globalThis.__krb_frame);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>krb player</title>
|
||||
<style>
|
||||
html, body { margin: 0; height: 100%; background: #101014; color: #f0f0f2;
|
||||
font: 14px system-ui, sans-serif; display: flex;
|
||||
flex-direction: column; align-items: center;
|
||||
justify-content: center; gap: 12px; }
|
||||
canvas { image-rendering: pixelated; max-width: 96vw; max-height: 80vh; }
|
||||
#drop { border: 1px dashed #8a8a93; border-radius: 8px; padding: 14px 22px;
|
||||
cursor: pointer; }
|
||||
#drop.hot { border-color: #f0f0f2; background: #1c1c22; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="drop">drop a .krb cartridge here, or click to pick one</div>
|
||||
<input id="file" type="file" accept=".krb" hidden>
|
||||
<canvas id="krb" width="800" height="600"></canvas>
|
||||
<script>
|
||||
var Module = {
|
||||
canvas: document.getElementById('krb')
|
||||
};
|
||||
(function() {
|
||||
const canvas = Module.canvas;
|
||||
const drop = document.getElementById('drop');
|
||||
const input = document.getElementById('file');
|
||||
|
||||
function start(file) {
|
||||
file.arrayBuffer().then(function(buf) {
|
||||
Module.FS.writeFile('/app.krb', new Uint8Array(buf));
|
||||
drop.textContent = file.name + ' — drop another .krb to switch';
|
||||
Module._krb_web_start();
|
||||
});
|
||||
}
|
||||
drop.addEventListener('click', function() { input.click(); });
|
||||
input.addEventListener('change', function() {
|
||||
if (input.files.length > 0)
|
||||
start(input.files[0]);
|
||||
});
|
||||
['dragover', 'dragenter'].forEach(function(ev) {
|
||||
drop.addEventListener(ev, function(e) {
|
||||
e.preventDefault();
|
||||
drop.classList.add('hot');
|
||||
});
|
||||
});
|
||||
['dragleave', 'drop'].forEach(function(ev) {
|
||||
drop.addEventListener(ev, function(e) {
|
||||
e.preventDefault();
|
||||
drop.classList.remove('hot');
|
||||
});
|
||||
});
|
||||
drop.addEventListener('drop', function(e) {
|
||||
e.preventDefault();
|
||||
if (e.dataTransfer.files.length > 0)
|
||||
start(e.dataTransfer.files[0]);
|
||||
});
|
||||
function pos(e) {
|
||||
const r = canvas.getBoundingClientRect();
|
||||
return [Math.round((e.clientX - r.left) * canvas.width / r.width),
|
||||
Math.round((e.clientY - r.top) * canvas.height / r.height)];
|
||||
}
|
||||
window.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Backspace' && Module._krb_web_text) {
|
||||
e.preventDefault();
|
||||
Module._krb_web_text(8);
|
||||
}
|
||||
});
|
||||
window.addEventListener('keypress', function(e) {
|
||||
if (Module._krb_web_text && e.charCode > 31)
|
||||
Module._krb_web_text(e.charCode);
|
||||
});
|
||||
canvas.addEventListener('wheel', function(e) {
|
||||
e.preventDefault();
|
||||
if (Module._krb_web_wheel)
|
||||
Module._krb_web_wheel(Math.round(-e.deltaY / 2));
|
||||
}, { passive: false });
|
||||
canvas.addEventListener('mousemove', function(e) {
|
||||
if (Module._krb_web_mouse) {
|
||||
const p = pos(e);
|
||||
Module._krb_web_mouse(p[0], p[1]);
|
||||
}
|
||||
});
|
||||
canvas.addEventListener('mousedown', function(e) {
|
||||
if (Module._krb_web_button) {
|
||||
const p = pos(e);
|
||||
Module._krb_web_mouse(p[0], p[1]);
|
||||
Module._krb_web_button(0, 1);
|
||||
}
|
||||
});
|
||||
canvas.addEventListener('mouseup', function(e) {
|
||||
if (Module._krb_web_button) {
|
||||
const p = pos(e);
|
||||
Module._krb_web_mouse(p[0], p[1]);
|
||||
Module._krb_web_button(0, 0);
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{{{ SCRIPT }}}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,593 @@
|
||||
#include "kryon.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define KP_PATH_MAX 1024
|
||||
|
||||
typedef struct PreviewOptions {
|
||||
const char *command;
|
||||
const char *project;
|
||||
const char *source;
|
||||
const char *source_dir;
|
||||
const char *out;
|
||||
int width;
|
||||
int height;
|
||||
int count;
|
||||
} PreviewOptions;
|
||||
|
||||
typedef struct PreviewSession {
|
||||
void *dylib;
|
||||
AppHost *host;
|
||||
DestroyAppHostCallback destroy_host;
|
||||
unsigned long generation;
|
||||
} PreviewSession;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage:\n"
|
||||
" kryon-preview capture --project ROOT --source REL --output PNG [--width W --height H]\n"
|
||||
" kryon-preview reload --project ROOT --source REL [--count N --width W --height H]\n"
|
||||
" kryon-preview capture-all --project ROOT --source-dir DIR --out-dir DIR [--width W --height H]\n"
|
||||
" kryon-preview cartridge --source FILE.kry|FILE.krb --output PNG [--project ROOT] [--width W --height H]\n");
|
||||
}
|
||||
|
||||
static const char *
|
||||
arg_value(int argc, char **argv, int *i)
|
||||
{
|
||||
if(*i + 1 >= argc)
|
||||
return NULL;
|
||||
(*i)++;
|
||||
return argv[*i];
|
||||
}
|
||||
|
||||
static int
|
||||
parse_args(int argc, char **argv, PreviewOptions *opt)
|
||||
{
|
||||
memset(opt, 0, sizeof(*opt));
|
||||
opt->width = 640;
|
||||
opt->height = 480;
|
||||
opt->count = 2;
|
||||
if(argc < 2)
|
||||
return 0;
|
||||
opt->command = argv[1];
|
||||
for(int i = 2; i < argc; i++) {
|
||||
const char *value = NULL;
|
||||
|
||||
if(strcmp(argv[i], "--project") == 0) {
|
||||
value = arg_value(argc, argv, &i);
|
||||
if(value == NULL)
|
||||
return 0;
|
||||
opt->project = value;
|
||||
} else if(strcmp(argv[i], "--source") == 0) {
|
||||
value = arg_value(argc, argv, &i);
|
||||
if(value == NULL)
|
||||
return 0;
|
||||
opt->source = value;
|
||||
} else if(strcmp(argv[i], "--source-dir") == 0) {
|
||||
value = arg_value(argc, argv, &i);
|
||||
if(value == NULL)
|
||||
return 0;
|
||||
opt->source_dir = value;
|
||||
} else if(strcmp(argv[i], "--output") == 0 ||
|
||||
strcmp(argv[i], "--out-dir") == 0) {
|
||||
value = arg_value(argc, argv, &i);
|
||||
if(value == NULL)
|
||||
return 0;
|
||||
opt->out = value;
|
||||
} else if(strcmp(argv[i], "--width") == 0) {
|
||||
value = arg_value(argc, argv, &i);
|
||||
if(value == NULL)
|
||||
return 0;
|
||||
opt->width = atoi(value);
|
||||
} else if(strcmp(argv[i], "--height") == 0) {
|
||||
value = arg_value(argc, argv, &i);
|
||||
if(value == NULL)
|
||||
return 0;
|
||||
opt->height = atoi(value);
|
||||
} else if(strcmp(argv[i], "--count") == 0) {
|
||||
value = arg_value(argc, argv, &i);
|
||||
if(value == NULL)
|
||||
return 0;
|
||||
opt->count = atoi(value);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(opt->width <= 0)
|
||||
opt->width = 640;
|
||||
if(opt->height <= 0)
|
||||
opt->height = 480;
|
||||
if(opt->count <= 0)
|
||||
opt->count = 1;
|
||||
if(strcmp(opt->command, "capture") == 0)
|
||||
return opt->project != NULL && opt->source != NULL && opt->out != NULL;
|
||||
if(strcmp(opt->command, "reload") == 0)
|
||||
return opt->project != NULL && opt->source != NULL;
|
||||
if(strcmp(opt->command, "capture-all") == 0)
|
||||
return opt->project != NULL && opt->source_dir != NULL && opt->out != NULL;
|
||||
if(strcmp(opt->command, "cartridge") == 0)
|
||||
return opt->source != NULL && opt->out != NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
path_join(char *dst, size_t dst_size, const char *a, const char *b)
|
||||
{
|
||||
if(a == NULL || a[0] == '\0')
|
||||
snprintf(dst, dst_size, "%s", b != NULL ? b : "");
|
||||
else if(b == NULL || b[0] == '\0')
|
||||
snprintf(dst, dst_size, "%s", a);
|
||||
else
|
||||
snprintf(dst, dst_size, "%s/%s", a, b);
|
||||
}
|
||||
|
||||
static int
|
||||
has_suffix(const char *path, const char *suffix)
|
||||
{
|
||||
size_t path_len = strlen(path);
|
||||
size_t suffix_len = strlen(suffix);
|
||||
|
||||
return path_len >= suffix_len &&
|
||||
strcmp(path + path_len - suffix_len, suffix) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
copy_file(const char *src, const char *dst)
|
||||
{
|
||||
FILE *in = fopen(src, "rb");
|
||||
FILE *out;
|
||||
char buf[16384];
|
||||
size_t n;
|
||||
|
||||
if(in == NULL)
|
||||
return 0;
|
||||
out = fopen(dst, "wb");
|
||||
if(out == NULL) {
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
while((n = fread(buf, 1, sizeof(buf), in)) > 0) {
|
||||
if(fwrite(buf, 1, n, out) != n) {
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(ferror(in)) {
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
||||
fclose(out);
|
||||
fclose(in);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
mkdir_p(const char *path)
|
||||
{
|
||||
char tmp[KP_PATH_MAX];
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s", path);
|
||||
for(char *p = tmp + 1; *p != '\0'; p++) {
|
||||
if(*p != '/')
|
||||
continue;
|
||||
*p = '\0';
|
||||
if(mkdir(tmp, 0755) != 0 && errno != EEXIST)
|
||||
return 0;
|
||||
*p = '/';
|
||||
}
|
||||
return mkdir(tmp, 0755) == 0 || errno == EEXIST;
|
||||
}
|
||||
|
||||
static int
|
||||
build_host(const char *project)
|
||||
{
|
||||
char command[KP_PATH_MAX * 4];
|
||||
const char *kryon_dir = getenv("KRYON_DIR");
|
||||
int rc;
|
||||
|
||||
if(kryon_dir == NULL || kryon_dir[0] == '\0')
|
||||
kryon_dir = "/usr/home/wao/src/kryon";
|
||||
snprintf(command, sizeof(command),
|
||||
"cd '%s' && gmake kryon-host KRYON_DIR='%s' >/tmp/kryon-preview-build.log 2>&1",
|
||||
project, kryon_dir);
|
||||
rc = system(command);
|
||||
return rc != -1 && WIFEXITED(rc) && WEXITSTATUS(rc) == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
preview_close(PreviewSession *session)
|
||||
{
|
||||
if(session->destroy_host != NULL && session->host != NULL)
|
||||
session->destroy_host(session->host);
|
||||
if(session->dylib != NULL)
|
||||
kry_dylib_close(session->dylib);
|
||||
session->dylib = NULL;
|
||||
session->host = NULL;
|
||||
session->destroy_host = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
preview_open(PreviewSession *session, const char *project)
|
||||
{
|
||||
char host_path[KP_PATH_MAX];
|
||||
char copy_path[KP_PATH_MAX];
|
||||
CreateAppHostCallback create_host;
|
||||
|
||||
preview_close(session);
|
||||
if(!build_host(project)) {
|
||||
fprintf(stderr, "kryon-preview: host build failed, see /tmp/kryon-preview-build.log\n");
|
||||
return 0;
|
||||
}
|
||||
path_join(host_path, sizeof(host_path), project, "build/kryon/app_host.so");
|
||||
snprintf(copy_path, sizeof(copy_path), "%s.preview.%lu.so", host_path,
|
||||
++session->generation);
|
||||
if(!copy_file(host_path, copy_path)) {
|
||||
fprintf(stderr, "kryon-preview: could not copy %s\n", host_path);
|
||||
return 0;
|
||||
}
|
||||
session->dylib = kry_dylib_load(copy_path);
|
||||
if(session->dylib == NULL) {
|
||||
fprintf(stderr, "kryon-preview: load failed: %s\n",
|
||||
kry_dylib_error() != NULL ? kry_dylib_error() : copy_path);
|
||||
return 0;
|
||||
}
|
||||
create_host = (CreateAppHostCallback)kry_dylib_sym(session->dylib,
|
||||
"CreateAppHost");
|
||||
session->destroy_host =
|
||||
(DestroyAppHostCallback)kry_dylib_sym(session->dylib,
|
||||
"DestroyAppHost");
|
||||
if(create_host == NULL || session->destroy_host == NULL) {
|
||||
fprintf(stderr, "kryon-preview: host missing app symbols\n");
|
||||
preview_close(session);
|
||||
return 0;
|
||||
}
|
||||
session->host = create_host(APP_HOST_ABI_VERSION, project);
|
||||
if(session->host == NULL) {
|
||||
fprintf(stderr, "kryon-preview: host rejected ABI %d\n",
|
||||
APP_HOST_ABI_VERSION);
|
||||
preview_close(session);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
capture_source(PreviewSession *session, const char *source, const char *out,
|
||||
int width, int height)
|
||||
{
|
||||
RenderTexture2D target;
|
||||
Image image;
|
||||
int selected;
|
||||
int saved;
|
||||
|
||||
selected = SetAppScreenBySourcePath(session->host, source);
|
||||
if(!selected)
|
||||
SetAppScreen(session->host, 0);
|
||||
target = LoadRenderTexture(width, height);
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(GetThemeBackground());
|
||||
BeginUIFrame(width, height, 1.0f);
|
||||
DrawAppScreen(session->host, (Rectangle){0, 0, (float)width, (float)height});
|
||||
EndUIFrame();
|
||||
EndTextureMode();
|
||||
image = LoadImageFromTexture(target.texture);
|
||||
UnloadRenderTexture(target);
|
||||
if(image.data == NULL)
|
||||
return 0;
|
||||
ImageFlipVertical(&image);
|
||||
saved = ExportImage(image, out);
|
||||
UnloadImage(image);
|
||||
if(!selected)
|
||||
fprintf(stderr, "kryon-preview: %s delegates to app preview\n", source);
|
||||
return saved;
|
||||
}
|
||||
|
||||
static int
|
||||
run_capture(const PreviewOptions *opt)
|
||||
{
|
||||
PreviewSession session = {0};
|
||||
int ok;
|
||||
|
||||
if(!preview_open(&session, opt->project))
|
||||
return 1;
|
||||
ok = capture_source(&session, opt->source, opt->out,
|
||||
opt->width, opt->height);
|
||||
preview_close(&session);
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
|
||||
static int
|
||||
run_reload(const PreviewOptions *opt)
|
||||
{
|
||||
PreviewSession session = {0};
|
||||
|
||||
for(int i = 0; i < opt->count; i++) {
|
||||
if(!preview_open(&session, opt->project))
|
||||
return 1;
|
||||
if(!capture_source(&session, opt->source, "/tmp/kryon-preview-reload.png",
|
||||
opt->width, opt->height)) {
|
||||
preview_close(&session);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
preview_close(&session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
png_name(char *dst, size_t dst_size, const char *rel)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
for(const char *p = rel; *p != '\0' && n + 5 < dst_size; p++)
|
||||
dst[n++] = (*p == '/' || *p == '.') ? '_' : *p;
|
||||
memcpy(dst + n, ".png", 5);
|
||||
}
|
||||
|
||||
static int
|
||||
capture_all_dir(PreviewSession *session, const PreviewOptions *opt,
|
||||
const char *rel_dir, int *total)
|
||||
{
|
||||
char abs_dir[KP_PATH_MAX];
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
int ok = 1;
|
||||
|
||||
path_join(abs_dir, sizeof(abs_dir), opt->project, rel_dir);
|
||||
dir = opendir(abs_dir);
|
||||
if(dir == NULL)
|
||||
return 0;
|
||||
while((entry = readdir(dir)) != NULL) {
|
||||
char child_rel[KP_PATH_MAX];
|
||||
char child_abs[KP_PATH_MAX];
|
||||
struct stat st;
|
||||
|
||||
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
path_join(child_rel, sizeof(child_rel), rel_dir, entry->d_name);
|
||||
path_join(child_abs, sizeof(child_abs), opt->project, child_rel);
|
||||
if(stat(child_abs, &st) != 0)
|
||||
continue;
|
||||
if(S_ISDIR(st.st_mode)) {
|
||||
if(!capture_all_dir(session, opt, child_rel, total))
|
||||
ok = 0;
|
||||
} else if(S_ISREG(st.st_mode) && has_suffix(entry->d_name, ".kry")) {
|
||||
char file[KP_PATH_MAX];
|
||||
char out_path[KP_PATH_MAX];
|
||||
|
||||
png_name(file, sizeof(file), child_rel);
|
||||
path_join(out_path, sizeof(out_path), opt->out, file);
|
||||
(*total)++;
|
||||
if(!capture_source(session, child_rel, out_path,
|
||||
opt->width, opt->height)) {
|
||||
fprintf(stderr, "kryon-preview: capture failed: %s\n", child_rel);
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int
|
||||
run_capture_all(const PreviewOptions *opt)
|
||||
{
|
||||
PreviewSession session = {0};
|
||||
int total = 0;
|
||||
int ok;
|
||||
|
||||
if(!mkdir_p(opt->out))
|
||||
return 1;
|
||||
if(!preview_open(&session, opt->project))
|
||||
return 1;
|
||||
ok = capture_all_dir(&session, opt, opt->source_dir, &total);
|
||||
preview_close(&session);
|
||||
fprintf(stderr, "kryon-preview: captured=%d failed=%d\n", total, ok ? 0 : 1);
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
|
||||
static int
|
||||
file_exists(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
return path != NULL && stat(path, &st) == 0 && S_ISREG(st.st_mode);
|
||||
}
|
||||
|
||||
static int
|
||||
find_k2b(char *dst, size_t dst_size)
|
||||
{
|
||||
const char *kryon_dir = getenv("KRYON_DIR");
|
||||
const char *path;
|
||||
|
||||
if(kryon_dir != NULL && kryon_dir[0] != '\0') {
|
||||
snprintf(dst, dst_size, "%s/build/bin/k2b", kryon_dir);
|
||||
if(file_exists(dst))
|
||||
return 1;
|
||||
snprintf(dst, dst_size, "%s/build/linux-x86_64/bin/k2b", kryon_dir);
|
||||
if(file_exists(dst))
|
||||
return 1;
|
||||
}
|
||||
if(file_exists("build/bin/k2b")) {
|
||||
snprintf(dst, dst_size, "build/bin/k2b");
|
||||
return 1;
|
||||
}
|
||||
if(file_exists("build/linux-x86_64/bin/k2b")) {
|
||||
snprintf(dst, dst_size, "build/linux-x86_64/bin/k2b");
|
||||
return 1;
|
||||
}
|
||||
path = getenv("PATH");
|
||||
if(path != NULL) {
|
||||
char buf[KP_PATH_MAX];
|
||||
const char *start = path;
|
||||
|
||||
while(*start != '\0') {
|
||||
const char *colon = strchr(start, ':');
|
||||
size_t n = colon != NULL ? (size_t)(colon - start) : strlen(start);
|
||||
|
||||
if(n > 0 && n + 4 < sizeof(buf)) {
|
||||
memcpy(buf, start, n);
|
||||
buf[n] = '\0';
|
||||
path_join(dst, dst_size, buf, "k2b");
|
||||
if(file_exists(dst))
|
||||
return 1;
|
||||
}
|
||||
if(colon == NULL)
|
||||
break;
|
||||
start = colon + 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
compile_krb(const char *k2b, const char *project, const char *source,
|
||||
char *out_krb, size_t out_size)
|
||||
{
|
||||
char command[KP_PATH_MAX * 4];
|
||||
char out_dir[KP_PATH_MAX];
|
||||
char rel[KP_PATH_MAX];
|
||||
char src_abs[KP_PATH_MAX];
|
||||
int rc;
|
||||
|
||||
snprintf(out_dir, sizeof(out_dir), "%s/kryon-preview-krb",
|
||||
getenv("TMPDIR") != NULL ? getenv("TMPDIR") : "/tmp");
|
||||
snprintf(rel, sizeof(rel), "%s", source);
|
||||
if(has_suffix(rel, ".kry"))
|
||||
rel[strlen(rel) - 4] = '\0';
|
||||
path_join(out_krb, out_size, out_dir, rel);
|
||||
{
|
||||
size_t n = strlen(out_krb);
|
||||
if(n + 5 < out_size)
|
||||
memcpy(out_krb + n, ".krb", 5);
|
||||
}
|
||||
{
|
||||
char parent[KP_PATH_MAX];
|
||||
char *slash;
|
||||
|
||||
snprintf(parent, sizeof(parent), "%s", out_krb);
|
||||
slash = strrchr(parent, '/');
|
||||
if(slash != NULL) {
|
||||
*slash = '\0';
|
||||
if(!mkdir_p(parent))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(source[0] == '/')
|
||||
snprintf(src_abs, sizeof(src_abs), "%s", source);
|
||||
else
|
||||
path_join(src_abs, sizeof(src_abs), project, source);
|
||||
snprintf(command, sizeof(command),
|
||||
"'%s' --no-main --root '%s' -o '%s' '%s'",
|
||||
k2b, project, out_dir, src_abs);
|
||||
rc = system(command);
|
||||
if(!(rc != -1 && WIFEXITED(rc) && WEXITSTATUS(rc) == 0))
|
||||
return 0;
|
||||
return file_exists(out_krb);
|
||||
}
|
||||
|
||||
static int
|
||||
capture_cartridge(const char *krb_path, const char *out, int width, int height)
|
||||
{
|
||||
KrbImage img;
|
||||
RenderTexture2D target;
|
||||
Image image;
|
||||
int saved;
|
||||
|
||||
memset(&img, 0, sizeof(img));
|
||||
if(KrbLoadFile(&img, krb_path) != 0) {
|
||||
fprintf(stderr, "kryon-preview: could not load %s\n", krb_path);
|
||||
return 0;
|
||||
}
|
||||
target = LoadRenderTexture(width, height);
|
||||
BeginTextureMode(target);
|
||||
ClearBackground(GetThemeBackground());
|
||||
BeginUIFrame(width, height, 1.0f);
|
||||
KrbDraw(&img, 0, 0, width, height);
|
||||
EndUIFrame();
|
||||
EndTextureMode();
|
||||
KrbFree(&img);
|
||||
image = LoadImageFromTexture(target.texture);
|
||||
UnloadRenderTexture(target);
|
||||
if(image.data == NULL)
|
||||
return 0;
|
||||
ImageFlipVertical(&image);
|
||||
saved = ExportImage(image, out);
|
||||
UnloadImage(image);
|
||||
return saved;
|
||||
}
|
||||
|
||||
static int
|
||||
run_cartridge(const PreviewOptions *opt)
|
||||
{
|
||||
char krb_path[KP_PATH_MAX];
|
||||
const char *source = opt->source;
|
||||
|
||||
if(has_suffix(source, ".krb")) {
|
||||
if(source[0] == '/' || opt->project == NULL)
|
||||
snprintf(krb_path, sizeof(krb_path), "%s", source);
|
||||
else
|
||||
path_join(krb_path, sizeof(krb_path), opt->project, source);
|
||||
return capture_cartridge(krb_path, opt->out, opt->width, opt->height)
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
if(has_suffix(source, ".kry")) {
|
||||
char k2b[KP_PATH_MAX];
|
||||
const char *project = opt->project != NULL ? opt->project : ".";
|
||||
|
||||
if(!find_k2b(k2b, sizeof(k2b))) {
|
||||
fprintf(stderr, "kryon-preview: k2b not found for cartridge compile\n");
|
||||
return 1;
|
||||
}
|
||||
if(!compile_krb(k2b, project, source, krb_path, sizeof(krb_path))) {
|
||||
fprintf(stderr, "kryon-preview: k2b failed\n");
|
||||
return 1;
|
||||
}
|
||||
return capture_cartridge(krb_path, opt->out, opt->width, opt->height)
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
fprintf(stderr, "kryon-preview: cartridge source must be .kry or .krb\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
PreviewOptions opt;
|
||||
int rc;
|
||||
|
||||
if(!parse_args(argc, argv, &opt)) {
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
SetTraceLogLevel(LOG_WARNING);
|
||||
SetConfigFlags(FLAG_WINDOW_HIDDEN);
|
||||
InitWindow(opt.width, opt.height, "Kryon Preview");
|
||||
SetTargetFPS(60);
|
||||
InitUI(opt.width, opt.height, 1.0f);
|
||||
SetCurrentTheme(THEME_MONO, 0);
|
||||
setenv("KRYON_INSPECT", "1", 1);
|
||||
if(strcmp(opt.command, "capture") == 0)
|
||||
rc = run_capture(&opt);
|
||||
else if(strcmp(opt.command, "reload") == 0)
|
||||
rc = run_reload(&opt);
|
||||
else if(strcmp(opt.command, "cartridge") == 0)
|
||||
rc = run_cartridge(&opt);
|
||||
else
|
||||
rc = run_capture_all(&opt);
|
||||
CloseWindow();
|
||||
return rc;
|
||||
}
|
||||
+619
@@ -0,0 +1,619 @@
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define KT_LINE_MAX 4096
|
||||
#define KT_PATH_MAX 1024
|
||||
#define KT_MAX_TESTS 512
|
||||
|
||||
typedef struct KTOptions {
|
||||
int headless;
|
||||
int snap;
|
||||
int bless;
|
||||
const char *files[KT_MAX_TESTS];
|
||||
int file_count;
|
||||
} KTOptions;
|
||||
|
||||
typedef struct KTRun {
|
||||
const KTOptions *options;
|
||||
const char *argv0;
|
||||
char root[KT_PATH_MAX];
|
||||
char clip[KT_LINE_MAX];
|
||||
char target[16];
|
||||
FILE *log;
|
||||
pid_t visual_pid;
|
||||
int steps;
|
||||
int failures;
|
||||
} KTRun;
|
||||
|
||||
static void
|
||||
kt_usage(FILE *out)
|
||||
{
|
||||
fprintf(out,
|
||||
"usage: kt [-headless] [-snap] [-bless] [tests/file.kt ...]\n");
|
||||
fprintf(out,
|
||||
"commands: target open tap type key see shot wait mkdir write append copy paste mv exists notexists contains\n");
|
||||
fprintf(out, "without -headless, kt opens the target app by default; "
|
||||
"'target none' runs headless\n");
|
||||
}
|
||||
|
||||
static char *
|
||||
kt_trim(char *s)
|
||||
{
|
||||
char *end;
|
||||
|
||||
while(*s != '\0' && isspace((unsigned char)*s))
|
||||
s++;
|
||||
end = s + strlen(s);
|
||||
while(end > s && isspace((unsigned char)end[-1]))
|
||||
*--end = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_ends_with(const char *s, const char *suffix)
|
||||
{
|
||||
size_t n;
|
||||
size_t m;
|
||||
|
||||
if(s == NULL || suffix == NULL)
|
||||
return 0;
|
||||
n = strlen(s);
|
||||
m = strlen(suffix);
|
||||
return n >= m && strcmp(s + n - m, suffix) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_mkdir(const char *path)
|
||||
{
|
||||
if(mkdir(path, 0775) == 0)
|
||||
return 1;
|
||||
return errno == EEXIST;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_join(char *out, size_t out_size, const char *a, const char *b)
|
||||
{
|
||||
if(a == NULL || a[0] == '\0')
|
||||
a = ".";
|
||||
if(b == NULL)
|
||||
b = "";
|
||||
return snprintf(out, out_size, "%s/%s", a, b) < (int)out_size;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_parse_word(char **cursor, char *out, size_t out_size)
|
||||
{
|
||||
char *s = kt_trim(*cursor);
|
||||
size_t n = 0;
|
||||
|
||||
if(*s == '\0')
|
||||
return 0;
|
||||
while(*s != '\0' && !isspace((unsigned char)*s)) {
|
||||
if(n + 1 < out_size)
|
||||
out[n++] = *s;
|
||||
s++;
|
||||
}
|
||||
out[n] = '\0';
|
||||
*cursor = s;
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_parse_arg(char **cursor, char *out, size_t out_size, char *err,
|
||||
size_t err_size)
|
||||
{
|
||||
char *s = kt_trim(*cursor);
|
||||
size_t n = 0;
|
||||
|
||||
if(*s == '\0') {
|
||||
snprintf(err, err_size, "missing argument");
|
||||
return 0;
|
||||
}
|
||||
if(*s == '"') {
|
||||
s++;
|
||||
while(*s != '\0' && *s != '"') {
|
||||
if(*s == '\\' && s[1] != '\0')
|
||||
s++;
|
||||
if(n + 1 < out_size)
|
||||
out[n++] = *s;
|
||||
s++;
|
||||
}
|
||||
if(*s != '"') {
|
||||
snprintf(err, err_size, "unterminated string");
|
||||
return 0;
|
||||
}
|
||||
s++;
|
||||
if(*kt_trim(s) != '\0') {
|
||||
snprintf(err, err_size, "unexpected trailing text");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
while(*s != '\0' && !isspace((unsigned char)*s)) {
|
||||
if(n + 1 < out_size)
|
||||
out[n++] = *s;
|
||||
s++;
|
||||
}
|
||||
if(*kt_trim(s) != '\0') {
|
||||
snprintf(err, err_size, "unexpected trailing text");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
out[n] = '\0';
|
||||
*cursor = s;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_parse_tail(char **cursor, char *out, size_t out_size, char *err,
|
||||
size_t err_size)
|
||||
{
|
||||
char *s = kt_trim(*cursor);
|
||||
|
||||
if(*s == '\0') {
|
||||
snprintf(err, err_size, "missing argument");
|
||||
return 0;
|
||||
}
|
||||
return kt_parse_arg(&s, out, out_size, err, err_size);
|
||||
}
|
||||
|
||||
static int
|
||||
kt_safe_relpath(const char *path)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if(path == NULL || path[0] == '\0' || path[0] == '/')
|
||||
return 0;
|
||||
for(p = path; *p != '\0'; p++) {
|
||||
if((p == path || p[-1] == '/') && p[0] == '.' &&
|
||||
p[1] == '.' && (p[2] == '/' || p[2] == '\0'))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_project_path(KTRun *run, const char *rel, char *out, size_t out_size)
|
||||
{
|
||||
if(!kt_safe_relpath(rel))
|
||||
return 0;
|
||||
return kt_join(out, out_size, run->root, rel);
|
||||
}
|
||||
|
||||
static int
|
||||
kt_read_file(const char *path, char *out, size_t out_size)
|
||||
{
|
||||
FILE *f;
|
||||
size_t n;
|
||||
|
||||
f = fopen(path, "rb");
|
||||
if(f == NULL)
|
||||
return 0;
|
||||
n = fread(out, 1, out_size > 0 ? out_size - 1 : 0, f);
|
||||
if(out_size > 0)
|
||||
out[n] = '\0';
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_write_file(const char *path, const char *text, const char *mode)
|
||||
{
|
||||
FILE *f = fopen(path, mode);
|
||||
|
||||
if(f == NULL)
|
||||
return 0;
|
||||
if(text != NULL && fputs(text, f) == EOF) {
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
kt_tool_path(char *out, size_t out_size, const char *argv0,
|
||||
const char *tool)
|
||||
{
|
||||
const char *slash;
|
||||
size_t dir_len;
|
||||
|
||||
if(argv0 == NULL)
|
||||
argv0 = "";
|
||||
slash = strrchr(argv0, '/');
|
||||
if(slash == NULL) {
|
||||
snprintf(out, out_size, "%s", tool);
|
||||
return;
|
||||
}
|
||||
dir_len = (size_t)(slash - argv0);
|
||||
if(dir_len + 1 + strlen(tool) + 1 > out_size) {
|
||||
snprintf(out, out_size, "%s", tool);
|
||||
return;
|
||||
}
|
||||
memcpy(out, argv0, dir_len);
|
||||
out[dir_len] = '/';
|
||||
snprintf(out + dir_len + 1, out_size - dir_len - 1, "%s", tool);
|
||||
}
|
||||
|
||||
static int
|
||||
kt_start_visual(KTRun *run)
|
||||
{
|
||||
char tool[KT_PATH_MAX];
|
||||
|
||||
if(run->options == NULL || run->options->headless)
|
||||
return 1;
|
||||
if(run->visual_pid > 0)
|
||||
return 1;
|
||||
if(strcmp(run->target, "none") == 0)
|
||||
return 1;
|
||||
kt_tool_path(tool, sizeof(tool), run->argv0, "kryon");
|
||||
run->visual_pid = fork();
|
||||
if(run->visual_pid < 0)
|
||||
return 0;
|
||||
if(run->visual_pid == 0) {
|
||||
setenv("KRYON_PROJECT_ROOT", run->root, 1);
|
||||
execl(tool, tool, "--project", run->root, "run", "native",
|
||||
(char *)NULL);
|
||||
execlp("kryon", "kryon", "--project", run->root, "run", "native",
|
||||
(char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
usleep(800000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
kt_stop_visual(KTRun *run)
|
||||
{
|
||||
int status;
|
||||
|
||||
if(run->visual_pid <= 0)
|
||||
return;
|
||||
kill(run->visual_pid, SIGTERM);
|
||||
waitpid(run->visual_pid, &status, 0);
|
||||
run->visual_pid = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
kt_visual_step_delay(KTRun *run)
|
||||
{
|
||||
if(run->options != NULL && !run->options->headless &&
|
||||
run->visual_pid > 0)
|
||||
usleep(180000);
|
||||
}
|
||||
|
||||
static int
|
||||
kt_open_log(KTRun *run)
|
||||
{
|
||||
char path[KT_PATH_MAX];
|
||||
|
||||
if(!kt_join(path, sizeof(path), run->root, "logs"))
|
||||
return 0;
|
||||
if(!kt_mkdir(path))
|
||||
return 0;
|
||||
if(!kt_join(path, sizeof(path), run->root, "logs/kt.log"))
|
||||
return 0;
|
||||
run->log = fopen(path, "a");
|
||||
return run->log != NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
kt_log(KTRun *run, const char *file, int line_no, const char *cmd,
|
||||
const char *arg)
|
||||
{
|
||||
if(run->log == NULL)
|
||||
return;
|
||||
fprintf(run->log, "%s:%d: %s %s\n", file, line_no, cmd,
|
||||
arg != NULL ? arg : "");
|
||||
}
|
||||
|
||||
static int
|
||||
kt_run_command(KTRun *run, const char *file, int line_no, char *line)
|
||||
{
|
||||
char *cursor = line;
|
||||
char cmd[32];
|
||||
char arg[KT_LINE_MAX];
|
||||
char arg2[KT_LINE_MAX];
|
||||
char err[128];
|
||||
char path[KT_PATH_MAX];
|
||||
char path2[KT_PATH_MAX];
|
||||
char text[KT_LINE_MAX];
|
||||
char snapshots[KT_PATH_MAX];
|
||||
|
||||
if(!kt_parse_word(&cursor, cmd, sizeof(cmd)))
|
||||
return 1;
|
||||
if(strcmp(cmd, "target") == 0 || strcmp(cmd, "open") == 0 ||
|
||||
strcmp(cmd, "tap") == 0 ||
|
||||
strcmp(cmd, "type") == 0 || strcmp(cmd, "key") == 0 ||
|
||||
strcmp(cmd, "see") == 0 || strcmp(cmd, "shot") == 0 ||
|
||||
strcmp(cmd, "wait") == 0 ||
|
||||
strcmp(cmd, "copy") == 0 || strcmp(cmd, "exists") == 0 ||
|
||||
strcmp(cmd, "notexists") == 0 || strcmp(cmd, "mkdir") == 0) {
|
||||
if(!kt_parse_arg(&cursor, arg, sizeof(arg), err, sizeof(err))) {
|
||||
fprintf(stderr, "%s:%d: %s\n", file, line_no, err);
|
||||
return 0;
|
||||
}
|
||||
if(strcmp(cmd, "target") == 0) {
|
||||
if(strcmp(arg, "app") != 0 && strcmp(arg, "none") != 0) {
|
||||
fprintf(stderr, "%s:%d: unknown target: %s\n", file, line_no,
|
||||
arg);
|
||||
return 0;
|
||||
}
|
||||
snprintf(run->target, sizeof(run->target), "%s", arg);
|
||||
}
|
||||
if(strcmp(cmd, "open") == 0) {
|
||||
struct stat st;
|
||||
|
||||
if(stat(arg, &st) != 0 || !S_ISDIR(st.st_mode)) {
|
||||
fprintf(stderr, "%s:%d: open target is not a directory: %s\n",
|
||||
file, line_no, arg);
|
||||
return 0;
|
||||
}
|
||||
snprintf(run->root, sizeof(run->root), "%s", arg);
|
||||
if(run->log == NULL && !kt_open_log(run)) {
|
||||
fprintf(stderr, "%s:%d: could not open logs/kt.log\n", file,
|
||||
line_no);
|
||||
return 0;
|
||||
}
|
||||
if(!kt_start_visual(run)) {
|
||||
fprintf(stderr, "%s:%d: could not start Kryon visual runner\n",
|
||||
file, line_no);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(strcmp(cmd, "shot") == 0) {
|
||||
if(!kt_join(snapshots, sizeof(snapshots), run->root, "snapshots") ||
|
||||
!kt_mkdir(snapshots)) {
|
||||
fprintf(stderr, "%s:%d: could not create snapshots/\n", file,
|
||||
line_no);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(strcmp(cmd, "copy") == 0)
|
||||
snprintf(run->clip, sizeof(run->clip), "%s", arg);
|
||||
if(strcmp(cmd, "wait") == 0) {
|
||||
int ms = atoi(arg);
|
||||
|
||||
if(ms < 0)
|
||||
ms = 0;
|
||||
if(ms > 30000)
|
||||
ms = 30000;
|
||||
usleep((useconds_t)ms * 1000);
|
||||
}
|
||||
if(strcmp(cmd, "exists") == 0) {
|
||||
struct stat st;
|
||||
|
||||
if(!kt_project_path(run, arg, path, sizeof(path)) ||
|
||||
stat(path, &st) != 0) {
|
||||
fprintf(stderr, "%s:%d: path does not exist: %s\n", file,
|
||||
line_no, arg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(strcmp(cmd, "notexists") == 0) {
|
||||
struct stat st;
|
||||
|
||||
if(!kt_project_path(run, arg, path, sizeof(path)) ||
|
||||
stat(path, &st) == 0) {
|
||||
fprintf(stderr, "%s:%d: path exists: %s\n", file, line_no,
|
||||
arg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(strcmp(cmd, "mkdir") == 0) {
|
||||
if(!kt_project_path(run, arg, path, sizeof(path)) ||
|
||||
!kt_mkdir(path)) {
|
||||
fprintf(stderr, "%s:%d: could not create directory: %s\n",
|
||||
file, line_no, arg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
kt_log(run, file, line_no, cmd, arg);
|
||||
run->steps++;
|
||||
kt_visual_step_delay(run);
|
||||
return 1;
|
||||
}
|
||||
if(strcmp(cmd, "write") == 0 || strcmp(cmd, "append") == 0 ||
|
||||
strcmp(cmd, "contains") == 0) {
|
||||
if(!kt_parse_word(&cursor, arg, sizeof(arg))) {
|
||||
fprintf(stderr, "%s:%d: missing path\n", file, line_no);
|
||||
return 0;
|
||||
}
|
||||
if(!kt_parse_tail(&cursor, arg2, sizeof(arg2), err, sizeof(err))) {
|
||||
fprintf(stderr, "%s:%d: %s\n", file, line_no, err);
|
||||
return 0;
|
||||
}
|
||||
if(!kt_project_path(run, arg, path, sizeof(path))) {
|
||||
fprintf(stderr, "%s:%d: unsafe path: %s\n", file, line_no, arg);
|
||||
return 0;
|
||||
}
|
||||
if(strcmp(cmd, "contains") == 0) {
|
||||
if(!kt_read_file(path, text, sizeof(text)) ||
|
||||
strstr(text, arg2) == NULL) {
|
||||
fprintf(stderr, "%s:%d: file does not contain text: %s\n",
|
||||
file, line_no, arg);
|
||||
return 0;
|
||||
}
|
||||
} else if(!kt_write_file(path, arg2,
|
||||
strcmp(cmd, "append") == 0 ? "ab" : "wb")) {
|
||||
fprintf(stderr, "%s:%d: could not write file: %s\n", file, line_no,
|
||||
arg);
|
||||
return 0;
|
||||
}
|
||||
kt_log(run, file, line_no, cmd, arg);
|
||||
run->steps++;
|
||||
kt_visual_step_delay(run);
|
||||
return 1;
|
||||
}
|
||||
if(strcmp(cmd, "paste") == 0) {
|
||||
if(!kt_parse_arg(&cursor, arg, sizeof(arg), err, sizeof(err))) {
|
||||
fprintf(stderr, "%s:%d: %s\n", file, line_no, err);
|
||||
return 0;
|
||||
}
|
||||
if(run->clip[0] == '\0') {
|
||||
fprintf(stderr, "%s:%d: clipboard is empty\n", file, line_no);
|
||||
return 0;
|
||||
}
|
||||
if(!kt_project_path(run, arg, path, sizeof(path)) ||
|
||||
!kt_write_file(path, run->clip, "ab")) {
|
||||
fprintf(stderr, "%s:%d: could not paste into file: %s\n", file,
|
||||
line_no, arg);
|
||||
return 0;
|
||||
}
|
||||
kt_log(run, file, line_no, cmd, arg);
|
||||
run->steps++;
|
||||
kt_visual_step_delay(run);
|
||||
return 1;
|
||||
}
|
||||
if(strcmp(cmd, "mv") == 0) {
|
||||
if(!kt_parse_word(&cursor, arg, sizeof(arg))) {
|
||||
fprintf(stderr, "%s:%d: missing source path\n", file, line_no);
|
||||
return 0;
|
||||
}
|
||||
if(!kt_parse_tail(&cursor, arg2, sizeof(arg2), err, sizeof(err))) {
|
||||
fprintf(stderr, "%s:%d: %s\n", file, line_no, err);
|
||||
return 0;
|
||||
}
|
||||
if(!kt_project_path(run, arg, path, sizeof(path)) ||
|
||||
!kt_project_path(run, arg2, path2, sizeof(path2)) ||
|
||||
rename(path, path2) != 0) {
|
||||
fprintf(stderr, "%s:%d: could not move %s to %s\n", file, line_no,
|
||||
arg, arg2);
|
||||
return 0;
|
||||
}
|
||||
kt_log(run, file, line_no, cmd, arg);
|
||||
run->steps++;
|
||||
kt_visual_step_delay(run);
|
||||
return 1;
|
||||
}
|
||||
fprintf(stderr, "%s:%d: unknown command: %s\n", file, line_no, cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_run_file(const KTOptions *options, const char *argv0, const char *path)
|
||||
{
|
||||
FILE *f;
|
||||
KTRun run = {0};
|
||||
char line[KT_LINE_MAX];
|
||||
int line_no = 0;
|
||||
int ok = 1;
|
||||
|
||||
run.options = options;
|
||||
run.argv0 = argv0;
|
||||
snprintf(run.root, sizeof(run.root), ".");
|
||||
snprintf(run.target, sizeof(run.target), "app");
|
||||
if(!kt_open_log(&run)) {
|
||||
fprintf(stderr, "%s: could not open logs/kt.log\n", path);
|
||||
return 0;
|
||||
}
|
||||
f = fopen(path, "r");
|
||||
if(f == NULL) {
|
||||
fprintf(stderr, "%s: %s\n", path, strerror(errno));
|
||||
fclose(run.log);
|
||||
return 0;
|
||||
}
|
||||
while(fgets(line, sizeof(line), f) != NULL) {
|
||||
char *trimmed;
|
||||
|
||||
line_no++;
|
||||
trimmed = kt_trim(line);
|
||||
if(trimmed[0] == '\0' || trimmed[0] == '#')
|
||||
continue;
|
||||
if(!kt_run_command(&run, path, line_no, trimmed)) {
|
||||
ok = 0;
|
||||
run.failures++;
|
||||
}
|
||||
}
|
||||
if(run.log != NULL) {
|
||||
fprintf(run.log, "%s: %d steps, %d failures\n", path, run.steps,
|
||||
run.failures);
|
||||
fclose(run.log);
|
||||
}
|
||||
kt_stop_visual(&run);
|
||||
fclose(f);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int
|
||||
kt_compare_strings(const void *a, const void *b)
|
||||
{
|
||||
const char *const *sa = a;
|
||||
const char *const *sb = b;
|
||||
|
||||
return strcmp(*sa, *sb);
|
||||
}
|
||||
|
||||
static int
|
||||
kt_discover_tests(KTOptions *options)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char *names[KT_MAX_TESTS];
|
||||
int count = 0;
|
||||
|
||||
dir = opendir("tests");
|
||||
if(dir == NULL)
|
||||
return 0;
|
||||
while((entry = readdir(dir)) != NULL && count < KT_MAX_TESTS) {
|
||||
char path[KT_PATH_MAX];
|
||||
|
||||
if(!kt_ends_with(entry->d_name, ".kt"))
|
||||
continue;
|
||||
if(!kt_join(path, sizeof(path), "tests", entry->d_name))
|
||||
continue;
|
||||
names[count] = strdup(path);
|
||||
if(names[count] != NULL)
|
||||
count++;
|
||||
}
|
||||
closedir(dir);
|
||||
qsort(names, (size_t)count, sizeof(names[0]), kt_compare_strings);
|
||||
for(int i = 0; i < count; i++)
|
||||
options->files[options->file_count++] = names[i];
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
KTOptions options = {0};
|
||||
int ok = 1;
|
||||
|
||||
for(int i = 1; i < argc; i++) {
|
||||
if(strcmp(argv[i], "-headless") == 0) {
|
||||
options.headless = 1;
|
||||
} else if(strcmp(argv[i], "-snap") == 0) {
|
||||
options.snap = 1;
|
||||
} else if(strcmp(argv[i], "-bless") == 0) {
|
||||
options.bless = 1;
|
||||
} else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
||||
kt_usage(stdout);
|
||||
return 0;
|
||||
} else if(argv[i][0] == '-') {
|
||||
kt_usage(stderr);
|
||||
return 2;
|
||||
} else if(options.file_count < KT_MAX_TESTS) {
|
||||
options.files[options.file_count++] = argv[i];
|
||||
} else {
|
||||
fprintf(stderr, "kt: too many test files\n");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if(options.file_count == 0 && !kt_discover_tests(&options)) {
|
||||
fprintf(stderr, "kt: no tests supplied and no tests/*.kt found\n");
|
||||
return 2;
|
||||
}
|
||||
for(int i = 0; i < options.file_count; i++) {
|
||||
if(!kt_run_file(&options, argv[0], options.files[i]))
|
||||
ok = 0;
|
||||
}
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
+31
-9
@@ -6,9 +6,26 @@ how to update downstream projects without editing vendored copies by hand.
|
||||
|
||||
## Role
|
||||
|
||||
Kryon is a small immediate-mode UI layer on top of raylib. Applications should use
|
||||
Kryon for shared UI behavior instead of duplicating pointer capture, modal backdrop,
|
||||
button, tab, scroll, text input, theme, and DPI logic in each project.
|
||||
Kryon is a small native UI runtime with a Kryon-owned, raylib-style app API.
|
||||
The current default backend is raylib, but applications should not depend on
|
||||
raylib directly. Applications should use Kryon for shared UI behavior instead
|
||||
of duplicating pointer capture, modal backdrop, button, tab, scroll, text input,
|
||||
theme, and DPI logic in each project.
|
||||
|
||||
Do not add legacy wrappers or alias layers when the app API changes. Migrate
|
||||
Kryon itself first, then update downstream apps such as Inbe and Krait to the
|
||||
canonical names directly. Public app code should use names such as
|
||||
`DrawUIIconButton`, `DrawUITextField`, `DrawRectangle`, `GetMousePosition`,
|
||||
`IsKeyPressed`, and `KEY_*` through Kryon. Public widget construction uses
|
||||
Flutter-style widgets with raylib-style C names: `Background`, `Text`, `Rect`,
|
||||
`Button`, and `Picture`. Lower-level immediate drawing keeps verb names such as
|
||||
`DrawUIText` and `DrawRectangle`. Do not reintroduce duplicate public widget
|
||||
names such as `WidgetText`, `UIText`, or `UITextNode` for the same behavior.
|
||||
|
||||
Kryon owns live preview rendering, preview PNG capture, and hot-reload
|
||||
verification. Do not use Krait as the capture test harness for `.kry` files.
|
||||
Use Kryon-owned tooling directly, for example `kryon-preview`, to prove that a
|
||||
project source file renders, exports a PNG, and reloads safely.
|
||||
|
||||
Keep application code focused on product state and domain behavior. Move repeated UI
|
||||
interaction rules into Kryon when more than one screen or project needs them.
|
||||
@@ -21,6 +38,11 @@ screen-space UI frame. If the application uses a transformed UI camera, call
|
||||
invalid cameras before using them; a zero-initialized `Camera2D` is treated as
|
||||
`GetUIDefaultCamera()` so pointer input does not silently break.
|
||||
|
||||
After drawing all widgets, call `EndUIFrame()` before the backend's
|
||||
`EndDrawing()`. The closing call draws deferred overlays such as dropdowns and
|
||||
text-field context menus, then finalizes focus and inspection state. Applications
|
||||
must not reproduce those overlay or finalization steps themselves.
|
||||
|
||||
Beginning a frame resets per-frame interaction state:
|
||||
|
||||
- input blocking
|
||||
@@ -58,18 +80,18 @@ Use these APIs by responsibility:
|
||||
|
||||
Kryon modal helpers own backdrop capture:
|
||||
|
||||
- `DrawUIActionModal`
|
||||
- `DrawUIModal`
|
||||
- `DrawUIModal3Button`
|
||||
- `DrawUIModalFrame`
|
||||
- `UIActionModalNode`
|
||||
- `UIModalNode`
|
||||
- `UIModal3ButtonNode`
|
||||
- `UIModalFrameNode`
|
||||
|
||||
When an application uses one of those helpers, it should not add separate outside-click
|
||||
guards or duplicate backdrop blocking. The helper registers the modal bounds for the
|
||||
current frame and the next frame.
|
||||
|
||||
Prefer `DrawUIActionModal` for title, message, and action-button dialogs. It measures
|
||||
Prefer `UIActionModalNode` for title, message, and action-button dialogs. It measures
|
||||
button labels, fits text inside buttons, and wraps actions into multiple rows when
|
||||
localized labels do not fit. Prefer `DrawUIModalFrame` for custom modal content.
|
||||
localized labels do not fit. Prefer `UIModalFrameNode` for custom modal content.
|
||||
Use manual
|
||||
`SetUIModalCapture` only for specialized overlays that cannot use the shared modal
|
||||
frame.
|
||||
|
||||
+350
-158
@@ -5,6 +5,7 @@ Kryon is a lightweight C UI component library for embedded applications and runt
|
||||
## Table of Contents
|
||||
|
||||
- [Initialization](#initialization)
|
||||
- [Canonical App API](#canonical-app-api)
|
||||
- [Core Modules](#core-modules)
|
||||
- [Color](#color)
|
||||
- [Scaling](#scaling)
|
||||
@@ -23,6 +24,7 @@ Kryon is a lightweight C UI component library for embedded applications and runt
|
||||
- [Web Utilities](#web-utilities)
|
||||
- [UI Components](#ui-components)
|
||||
- [Buttons](#buttons)
|
||||
- [Pictures](#pictures)
|
||||
- [Text Input](#text-input)
|
||||
- [Navigation](#navigation)
|
||||
- [Modals](#modals)
|
||||
@@ -90,6 +92,107 @@ state, updates the layout view size, and begins a frame with
|
||||
void BeginUIFrame(int width, int height, float dpi);
|
||||
```
|
||||
|
||||
### `EndUIFrame`
|
||||
|
||||
Finish the current UI frame after all widgets have been drawn and before the
|
||||
backend drawing pass ends. This draws deferred overlays, including dropdowns and
|
||||
text-input context menus, and finalizes focus and inspection state.
|
||||
|
||||
```c
|
||||
void EndUIFrame(void);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Canonical App API
|
||||
|
||||
Kryon owns the public app-facing API. The default backend still implements much
|
||||
of the surface through raylib, but application and generated code should include
|
||||
Kryon headers and call Kryon-owned names directly. That keeps apps portable to
|
||||
future backends.
|
||||
|
||||
Use the raylib-style drawing, input, texture, window, and math names provided by
|
||||
Kryon, such as:
|
||||
|
||||
```c
|
||||
DrawRectangle(0, 0, view_width, view_height, GetThemeBackground());
|
||||
Vector2 mouse = GetMousePosition();
|
||||
if(IsKeyPressed(KEY_ESCAPE))
|
||||
CloseWindow();
|
||||
```
|
||||
|
||||
Use canonical widget drawing names when drawing a concrete widget immediately:
|
||||
|
||||
```c
|
||||
DrawUIIconButton(button);
|
||||
DrawUITextField(field);
|
||||
DrawUISlider(id, x, y, w, "Volume", 0, 100, &volume, "%");
|
||||
DrawUIOverlays();
|
||||
```
|
||||
|
||||
Normal application UI is declared between `BeginUI` and `EndUI`. Containers
|
||||
use one matching `End`, independent of their kind. Reconciliation, layout,
|
||||
input routing, updates, painting, and overlays are runtime-owned and are not
|
||||
application lifecycle calls:
|
||||
|
||||
```c
|
||||
BeginUI(Key("settings"));
|
||||
Column((ColumnProps){
|
||||
.bounds = {20, 20, 360, 420},
|
||||
.gap = 12,
|
||||
.padding = 16,
|
||||
.key = Key("settings/body"),
|
||||
});
|
||||
Text("Account", 0, 0, UI_TEXT_24, GetThemeText());
|
||||
TextField(account_field);
|
||||
Button(save_button);
|
||||
End();
|
||||
EndUI();
|
||||
|
||||
while(NextUIEvent(&event)) {
|
||||
if(event.key == Key("settings/save") &&
|
||||
event.kind == UI_EVENT_CLICK)
|
||||
SaveSettings();
|
||||
}
|
||||
```
|
||||
|
||||
Migrate callers to the current Kryon API directly so the backend boundary stays
|
||||
simple.
|
||||
|
||||
Cartridges (`.krb`) are portable Kryon render artifacts produced from KIR. The
|
||||
current runtime loads a packed node table plus a small program; the roadmap adds
|
||||
state schema, source maps, portable logic, capabilities, and explicit host
|
||||
imports. Load the image, bind host functions by import name when the cartridge
|
||||
declares them, and draw through `KryBackend`:
|
||||
|
||||
```c
|
||||
KrbImage img;
|
||||
KrbLoadFile(&img, "02_buttons.krb");
|
||||
KrbBind(&img, "primary_button", on_primary, app);
|
||||
KrbDraw(&img, 0, 0, width, height);
|
||||
KrbFree(&img);
|
||||
```
|
||||
|
||||
`k2b` is the cartridge compiler. It accepts `.kry` or `.kir`; `.kry` input is
|
||||
lowered through KIR before the KRB sections are written. `KryBackendDraw`
|
||||
implements the rendering table with the public Kryon draw/input API;
|
||||
`KryBackendNull` is the headless stand-in. Mount live C fields so a cartridge
|
||||
can read them as files:
|
||||
|
||||
```c
|
||||
KrbField fields[] = {
|
||||
{ "score", offsetof(App, score), KRB_I32, 4 },
|
||||
{ NULL }
|
||||
};
|
||||
KrbMount(&img, "/app", app, fields);
|
||||
KrbReadI32(&img, "/app/score", &n);
|
||||
```
|
||||
|
||||
`OP_CALL_HOST` and `OP_SET_I32` run from `KrbExec`. The portable path is
|
||||
designed around KIR-owned logic plus a capability/import table; native C apps
|
||||
should continue to use the C backend when direct library integration is the
|
||||
right target. See `docs/KRB_FORMAT.md`.
|
||||
|
||||
---
|
||||
|
||||
## Core Modules
|
||||
@@ -291,8 +394,20 @@ Font LoadUIFontFromMemory(const char *file_type, const unsigned char *font_data,
|
||||
Font LoadUIFontAsset(const char *path, int base_size);
|
||||
void UnloadUIFont(Font *font);
|
||||
void ClearUIFonts(void);
|
||||
void UIFontMemoryReport(const char *tag);
|
||||
```
|
||||
|
||||
`UIFontMemoryReport` prints per-font rasterization stats (codepoint counts,
|
||||
rasterized sizes, glyph counts) to stderr. It is a no-op unless
|
||||
`KRYON_MEM_DEBUG` is set in the environment.
|
||||
|
||||
Source fonts registered through `RegisterUIFontSource` rasterize their
|
||||
declared codepoints at each requested physical size and retain bounded size
|
||||
tiers. Their atlas coverage is immutable after registration: drawing or
|
||||
typing text never reallocates a font texture. Supply every codepoint the
|
||||
source is expected to render; omitting the list selects Kryon's standard UI
|
||||
coverage. `RegisterUIFixedFontSource` is an equivalent explicit name.
|
||||
|
||||
#### Text Measurement
|
||||
|
||||
```c
|
||||
@@ -301,13 +416,10 @@ int GetUITextHeight(const char *text, int font_size);
|
||||
int GetUITextLineHeight(int font_size);
|
||||
```
|
||||
|
||||
#### Text Drawing
|
||||
#### Text Widgets
|
||||
|
||||
```c
|
||||
void DrawUIText(const char *text, int x, int y, int font_size, Color color);
|
||||
void DrawScaledUIText(const char *text, int x, int y, int scale, Color color);
|
||||
void DrawCenteredUIText(const char *text, int center_x, int center_y, int font_size, Color color);
|
||||
void DrawUITextInRect(const char *text, Rectangle rect, int font_size, Color color);
|
||||
void Text(const char *text, int x, int y, int font_size, Color color);
|
||||
```
|
||||
|
||||
#### Vertical Centering
|
||||
@@ -353,14 +465,6 @@ Reflow layout for a given width.
|
||||
void ReflowUITextLayout(UITextLayout *layout, int max_width, int font_size, int line_height);
|
||||
```
|
||||
|
||||
#### `DrawUITextLayout`
|
||||
|
||||
Draw the layout.
|
||||
|
||||
```c
|
||||
void DrawUITextLayout(UITextLayout *layout, int x, int *y, int font_size, Color color);
|
||||
```
|
||||
|
||||
#### `GetUITextLayoutHeight` / `FreeUITextLayout`
|
||||
|
||||
```c
|
||||
@@ -402,11 +506,11 @@ Profile-picture PNGs in `pfp/` are embedded into the same icon catalog with
|
||||
`GetUIProfilePictureIconType`, and `GetUIProfilePictureIconName` to enumerate
|
||||
the standard profile-picture options.
|
||||
|
||||
Kryon also exposes stable `UI_LYRA_PROFILE_ICON_*` IDs and mapping helpers:
|
||||
Kryon also exposes stable `UI_KSYNC_PROFILE_ICON_*` IDs and mapping helpers:
|
||||
|
||||
```c
|
||||
UIIconType GetUIProfilePictureIconTypeForLyraID(int lyra_id);
|
||||
int GetUILyraIDForProfilePictureIconType(UIIconType type);
|
||||
UIIconType GetUIProfilePictureIconTypeForKsyncID(int ksync_id);
|
||||
int GetUIKsyncIDForProfilePictureIconType(UIIconType type);
|
||||
```
|
||||
|
||||
Use those IDs for server storage or sync payloads instead of generated
|
||||
@@ -469,6 +573,35 @@ Color GetThemeIcon(void);
|
||||
Color GetThemeLink(void);
|
||||
```
|
||||
|
||||
#### Theme Styles
|
||||
|
||||
Kryon supports two concrete widget styles plus a system selector:
|
||||
|
||||
```c
|
||||
typedef enum ThemeStyle {
|
||||
THEME_STYLE_SYSTEM = 0,
|
||||
THEME_STYLE_RETRO,
|
||||
THEME_STYLE_MATERIAL
|
||||
} ThemeStyle;
|
||||
|
||||
void SetThemeStyle(ThemeStyle style);
|
||||
ThemeStyle GetThemeStyle(void);
|
||||
ThemeStyle GetEffectiveThemeStyle(void);
|
||||
ThemeStyle GetDefaultPlatformThemeStyle(void);
|
||||
int GetDefaultThemeForThemeStyle(ThemeStyle style);
|
||||
const char *GetThemeStyleLabel(ThemeStyle style);
|
||||
```
|
||||
|
||||
`THEME_STYLE_SYSTEM` resolves to Material on Android builds and Retro elsewhere.
|
||||
Material uses Material 3 style tokens: 48px touch targets, rounded controls,
|
||||
state layers/ripple feedback, elevation shadows, and theme-derived Material color
|
||||
roles. Retro keeps the original beveled Kryon look.
|
||||
|
||||
```c
|
||||
UIStyleTokens GetUIStyleTokens(void);
|
||||
UIMaterialScheme GetUIMaterialScheme(void);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Locale
|
||||
@@ -504,59 +637,59 @@ int GetCurrentLocaleIndex(void);
|
||||
|
||||
### Sync
|
||||
|
||||
Lyra Sync is Kryon's common sync protocol layer. Kryon owns URL handling, token auth,
|
||||
Ksync Sync is Kryon's common sync protocol layer. Kryon owns URL handling, token auth,
|
||||
challenge/login, bearer requests, sync posting, account deletion, and small JSON
|
||||
helpers. Applications still own their local data model and provide callbacks to
|
||||
build sync payloads, apply sync responses, store auth tokens, and perform
|
||||
platform HTTP.
|
||||
helpers, and default platform transport. Applications still own their local data
|
||||
model and provide callbacks to build sync payloads, apply sync responses, and
|
||||
store auth tokens.
|
||||
|
||||
#### `LyraSyncResult`
|
||||
#### `KsyncSyncResult`
|
||||
|
||||
```c
|
||||
typedef enum LyraSyncResult {
|
||||
LYRA_SYNC_OK = 0,
|
||||
LYRA_SYNC_INVALID_URL,
|
||||
LYRA_SYNC_NO_ACCOUNT,
|
||||
LYRA_SYNC_PAYLOAD_FAILED,
|
||||
LYRA_SYNC_CHALLENGE_FAILED,
|
||||
LYRA_SYNC_SIGN_FAILED,
|
||||
LYRA_SYNC_REQUEST_FAILED,
|
||||
LYRA_SYNC_AUTH_FAILED
|
||||
} LyraSyncResult;
|
||||
typedef enum KsyncSyncResult {
|
||||
KSYNC_SYNC_OK = 0,
|
||||
KSYNC_SYNC_INVALID_URL,
|
||||
KSYNC_SYNC_NO_ACCOUNT,
|
||||
KSYNC_SYNC_PAYLOAD_FAILED,
|
||||
KSYNC_SYNC_CHALLENGE_FAILED,
|
||||
KSYNC_SYNC_SIGN_FAILED,
|
||||
KSYNC_SYNC_REQUEST_FAILED,
|
||||
KSYNC_SYNC_AUTH_FAILED
|
||||
} KsyncSyncResult;
|
||||
```
|
||||
|
||||
#### `LyraSyncConfig`
|
||||
#### `KsyncSyncConfig`
|
||||
|
||||
```c
|
||||
typedef struct LyraSyncConfig {
|
||||
typedef struct KsyncSyncConfig {
|
||||
const char *base_url;
|
||||
const LyraAccount *account;
|
||||
const KsyncAccount *account;
|
||||
const char *client_id;
|
||||
LyraSyncHttpRequestFn http_request;
|
||||
LyraSyncGetTextFn get_text;
|
||||
LyraSyncSetTextFn set_text;
|
||||
LyraSyncBuildPayloadFn build_payload;
|
||||
LyraSyncFreePayloadFn free_payload;
|
||||
LyraSyncApplyResponseFn apply_response;
|
||||
LyraSyncVoidFn purge_synced_deleted;
|
||||
LyraSyncLogFn log_http_failure;
|
||||
KsyncSyncHttpRequestFn http_request;
|
||||
KsyncSyncGetTextFn get_text;
|
||||
KsyncSyncSetTextFn set_text;
|
||||
KsyncSyncBuildPayloadFn build_payload;
|
||||
KsyncSyncFreePayloadFn free_payload;
|
||||
KsyncSyncApplyResponseFn apply_response;
|
||||
KsyncSyncVoidFn purge_synced_deleted;
|
||||
KsyncSyncLogFn log_http_failure;
|
||||
void *user;
|
||||
} LyraSyncConfig;
|
||||
} KsyncSyncConfig;
|
||||
```
|
||||
|
||||
`http_request` is platform-owned. Native apps can implement it with libcurl,
|
||||
Android apps can bridge through JNI, and web apps can bridge to JavaScript fetch.
|
||||
`http_request` can be app-provided, or set to `KsyncDefaultHttpRequest` for
|
||||
Kryon's built-in libcurl/JNI/fetch transport.
|
||||
`get_text` and `set_text` store `sync_auth_token` and
|
||||
`sync_auth_token_expires_at`.
|
||||
|
||||
#### URL Helpers
|
||||
|
||||
```c
|
||||
int IsLyraSyncURLValid(const char *url);
|
||||
int NormalizeLyraSyncURL(const char *input, char *out, size_t out_size);
|
||||
int JoinLyraSyncURL(char *out, size_t out_size,
|
||||
int IsKsyncSyncURLValid(const char *url);
|
||||
int NormalizeKsyncSyncURL(const char *input, char *out, size_t out_size);
|
||||
int JoinKsyncSyncURL(char *out, size_t out_size,
|
||||
const char *base_url, const char *path);
|
||||
int JoinLyraSyncWebSocketURL(char *out, size_t out_size,
|
||||
int JoinKsyncSyncWebSocketURL(char *out, size_t out_size,
|
||||
const char *base_url, const char *path);
|
||||
```
|
||||
|
||||
@@ -566,41 +699,71 @@ Remote sync URLs must be HTTPS. HTTP is accepted only for loopback hosts such as
|
||||
#### Buffer And JSON Helpers
|
||||
|
||||
```c
|
||||
int AppendLyraSyncBuffer(LyraSyncBuffer *buffer,
|
||||
int AppendKsyncSyncBuffer(KsyncSyncBuffer *buffer,
|
||||
const void *data, size_t bytes);
|
||||
int AppendLyraSyncBufferJSONString(LyraSyncBuffer *buffer,
|
||||
int AppendKsyncSyncBufferJSONString(KsyncSyncBuffer *buffer,
|
||||
const char *text);
|
||||
void FreeLyraSyncBuffer(LyraSyncBuffer *buffer);
|
||||
int FindLyraSyncJSONString(const char *json, const char *key,
|
||||
void FreeKsyncSyncBuffer(KsyncSyncBuffer *buffer);
|
||||
int FindKsyncSyncJSONString(const char *json, const char *key,
|
||||
char *out, size_t out_size);
|
||||
long long FindLyraSyncJSONInt64(const char *json, const char *key,
|
||||
long long FindKsyncSyncJSONInt64(const char *json, const char *key,
|
||||
long long fallback);
|
||||
```
|
||||
|
||||
These are intentionally small helpers for Lyra protocol payload construction and
|
||||
These are intentionally small helpers for Ksync protocol payload construction and
|
||||
simple response fields. Applications that already have a full JSON parser should
|
||||
keep using it for domain data.
|
||||
|
||||
#### Auth And Sync
|
||||
|
||||
```c
|
||||
void ClearLyraSyncAuthToken(const LyraSyncConfig *cfg);
|
||||
LyraSyncResult LoginLyraSync(const LyraSyncConfig *cfg);
|
||||
LyraSyncResult RunLyraSync(const LyraSyncConfig *cfg);
|
||||
LyraSyncResult RequestLyraSyncBearer(const LyraSyncConfig *cfg,
|
||||
void ClearKsyncSyncAuthToken(const KsyncSyncConfig *cfg);
|
||||
KsyncSyncResult LoginKsyncSync(const KsyncSyncConfig *cfg);
|
||||
KsyncSyncResult RunKsyncSync(const KsyncSyncConfig *cfg);
|
||||
KsyncSyncResult RequestKsyncSyncBearer(const KsyncSyncConfig *cfg,
|
||||
const char *method,
|
||||
const char *path,
|
||||
const char *body,
|
||||
char *out,
|
||||
size_t out_size);
|
||||
LyraSyncResult DeleteLyraSyncAccount(const LyraSyncConfig *cfg);
|
||||
const char *GetLyraSyncResultName(LyraSyncResult result);
|
||||
KsyncSyncResult DeleteKsyncSyncAccount(const KsyncSyncConfig *cfg);
|
||||
const char *GetKsyncSyncResultName(KsyncSyncResult result);
|
||||
```
|
||||
|
||||
`RunLyraSync` loads or refreshes an auth token, asks the app callback for
|
||||
`RunKsyncSync` loads or refreshes an auth token, asks the app callback for
|
||||
a local-first payload, posts it to `/api/v1/sync`, applies the response through
|
||||
the callback, and purges synced tombstones on success. `RequestLyraSyncBearer`
|
||||
is for app-specific Lyra endpoints that use the same account token.
|
||||
the callback, and purges synced tombstones on success. `RequestKsyncSyncBearer`
|
||||
is for app-specific Ksync endpoints that use the same account token.
|
||||
|
||||
#### Default Transport And Events
|
||||
|
||||
```c
|
||||
int KsyncDefaultHttpRequest(const char *method, const char *url,
|
||||
const char *body,
|
||||
const char *const *headers,
|
||||
int header_count,
|
||||
KsyncSyncBuffer *response,
|
||||
long *status, void *user);
|
||||
KsyncSyncResult KsyncRemoteEventWait(const KsyncSyncConfig *cfg,
|
||||
const char *path);
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
int KsyncWebSyncStart(const KsyncSyncConfig *cfg);
|
||||
int KsyncWebSyncPoll(KsyncSyncResult *result, int *changed);
|
||||
int KsyncWebRemoteEventsStart(const KsyncSyncConfig *cfg, const char *path);
|
||||
int KsyncWebRemoteEventsPoll(void);
|
||||
#endif
|
||||
```
|
||||
|
||||
`KsyncDefaultHttpRequest` provides the common platform HTTP transport. Native
|
||||
builds use libcurl, Android builds call `syncHttpRequest`/`syncWebSocketWait` on
|
||||
the activity through JNI, and web builds use JavaScript `fetch`.
|
||||
|
||||
`KsyncRemoteEventWait` waits for one Ksync WebSocket sync-change event using the
|
||||
stored bearer token. Web builds use the nonblocking `KsyncWebRemoteEventsStart`
|
||||
and `KsyncWebRemoteEventsPoll` pair instead.
|
||||
|
||||
`KsyncWebSyncStart` and `KsyncWebSyncPoll` run the same login/token/sync flow as
|
||||
`RunKsyncSync` without blocking the browser frame loop.
|
||||
|
||||
---
|
||||
|
||||
@@ -639,12 +802,6 @@ float GetUITransitionAlpha(const UITransition *transition);
|
||||
int StepUITransition(UITransition *transition, float delta_seconds);
|
||||
```
|
||||
|
||||
#### `DrawUITransitionFade`
|
||||
|
||||
```c
|
||||
void DrawUITransitionFade(const UITransition *transition, int width, int height, Color color);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Runtime Assets
|
||||
@@ -737,9 +894,39 @@ int SyncWebWindowSize(void);
|
||||
|
||||
## UI Components
|
||||
|
||||
### Pictures
|
||||
|
||||
```c
|
||||
typedef enum UIPictureFit {
|
||||
UI_PICTURE_FIT_STRETCH,
|
||||
UI_PICTURE_FIT_CONTAIN,
|
||||
UI_PICTURE_FIT_COVER
|
||||
} UIPictureFit;
|
||||
|
||||
typedef struct PictureProps {
|
||||
const char *asset_path;
|
||||
Rectangle bounds;
|
||||
Rectangle source;
|
||||
Vector2 origin;
|
||||
float rotation;
|
||||
Color tint;
|
||||
UIPictureFit fit;
|
||||
} PictureProps;
|
||||
|
||||
void Picture(PictureProps picture);
|
||||
```
|
||||
|
||||
Pictures are image-backed UI widget nodes. `asset_path` is resolved first as a
|
||||
runtime file path and then as an embedded asset path. `Picture` uses the
|
||||
full image with contain fitting and exposes source rect, origin,
|
||||
rotation, tint, and fit mode. The `Sprite2D` scene node shares the same
|
||||
texture cache (`KryLoadPictureTexture`) for world-space game sprites. Named
|
||||
`Picture` rather than `Image` because raylib already owns `Image` as a
|
||||
decoded-image-in-memory struct type.
|
||||
|
||||
### Buttons
|
||||
|
||||
#### `UIButton`
|
||||
#### `Button`
|
||||
|
||||
```c
|
||||
typedef struct {
|
||||
@@ -753,20 +940,20 @@ typedef struct {
|
||||
Color text;
|
||||
Color border;
|
||||
float radius;
|
||||
} UIButton;
|
||||
} UIButtonSpec;
|
||||
```
|
||||
|
||||
#### `DrawUIButton`
|
||||
#### `Button`
|
||||
|
||||
Draw and handle a button.
|
||||
|
||||
```c
|
||||
int DrawUIButton(UIButton button);
|
||||
int Button(UIButtonSpec button);
|
||||
```
|
||||
|
||||
**Returns:** 1 if clicked, 0 otherwise
|
||||
|
||||
#### `UIIconButton`
|
||||
#### `IconButton`
|
||||
|
||||
```c
|
||||
typedef struct {
|
||||
@@ -782,16 +969,16 @@ typedef struct {
|
||||
Color icon_color;
|
||||
Color border;
|
||||
float radius;
|
||||
} UIIconButton;
|
||||
} IconButton;
|
||||
```
|
||||
|
||||
#### `DrawUIIconButton`
|
||||
#### `UIIconButtonNode`
|
||||
|
||||
```c
|
||||
int DrawUIIconButton(UIIconButton button);
|
||||
int UIIconButtonNode(IconButton button);
|
||||
```
|
||||
|
||||
#### `UIHref`
|
||||
#### `Href`
|
||||
|
||||
```c
|
||||
typedef struct {
|
||||
@@ -803,15 +990,15 @@ typedef struct {
|
||||
int disabled;
|
||||
Color color;
|
||||
Color hover_color;
|
||||
} UIHref;
|
||||
} Href;
|
||||
```
|
||||
|
||||
#### `DrawUIHref`
|
||||
#### `UIHrefNode`
|
||||
|
||||
Draw and handle a text link using the current theme link color by default.
|
||||
|
||||
```c
|
||||
int DrawUIHref(UIHref link);
|
||||
int UIHrefNode(Href link);
|
||||
```
|
||||
|
||||
---
|
||||
@@ -847,7 +1034,7 @@ typedef struct {
|
||||
} UITextInput;
|
||||
```
|
||||
|
||||
#### `UITextField`
|
||||
#### `TextField`
|
||||
|
||||
```c
|
||||
typedef struct {
|
||||
@@ -863,14 +1050,14 @@ typedef struct {
|
||||
UITextInputFilter filter;
|
||||
void *filter_user_data;
|
||||
int *commit_pressed;
|
||||
} UITextField;
|
||||
} TextField;
|
||||
```
|
||||
|
||||
#### `DrawUITextInputControl` / `DrawUITextField`
|
||||
#### `UITextInputControlNode` / `TextField`
|
||||
|
||||
```c
|
||||
int DrawUITextInputControl(UITextInput input);
|
||||
int DrawUITextField(UITextField field);
|
||||
int UITextInputControlNode(UITextInput input);
|
||||
int TextField(TextField field);
|
||||
```
|
||||
|
||||
---
|
||||
@@ -899,10 +1086,9 @@ typedef struct {
|
||||
int side_margin;
|
||||
int bottom_margin;
|
||||
int max_button_width;
|
||||
} UIBottomNav;
|
||||
} BottomNav;
|
||||
|
||||
UIBottomNavResult DrawUIBottomNav(UIBottomNav nav);
|
||||
int GetUIBottomNavHeight(void);
|
||||
UIBottomNavResult UIBottomNavNode(BottomNav nav);
|
||||
```
|
||||
|
||||
#### Toolbar
|
||||
@@ -919,27 +1105,27 @@ typedef struct {
|
||||
int option_count;
|
||||
int *selected_index;
|
||||
// ... more fields
|
||||
} UIToolbar;
|
||||
} Toolbar;
|
||||
|
||||
UIToolbarResult DrawUIToolbar(UIToolbar toolbar);
|
||||
UIToolbarHeaderResult DrawUIToolbarHeader(UIToolbarHeader header);
|
||||
UIToolbarResult UIToolbarNode(Toolbar toolbar);
|
||||
UIToolbarHeaderResult UIToolbarHeaderNode(ToolbarHeader header);
|
||||
```
|
||||
|
||||
#### Sidebar Account Header
|
||||
|
||||
```c
|
||||
UISidebarAccountHeaderResult DrawUISidebarAccountHeader(UISidebarAccountHeader header);
|
||||
UIProfilePicturePickerResult DrawUIProfilePicturePickerModal(UIProfilePicturePickerModal modal);
|
||||
UISidebarAccountHeaderResult UISidebarAccountHeaderNode(SidebarAccountHeader header);
|
||||
UIProfilePicturePickerResult UIProfilePicturePickerNode(UIProfilePicturePickerModal modal);
|
||||
```
|
||||
|
||||
`DrawUISidebarAccountHeader` draws the standard account top area with banner,
|
||||
`UISidebarAccountHeaderNode` draws the standard account top area with banner,
|
||||
username, subtitle, friends summary, and pfp. `content_padding_x` overrides
|
||||
the internal horizontal inset while the header bounds can fill its parent. It
|
||||
returns separate click flags
|
||||
for pfp, username, and friends so applications keep ownership of route changes
|
||||
and persistence.
|
||||
|
||||
`DrawUIProfilePicturePickerModal` draws the shared pfp selection modal over the
|
||||
`UIProfilePicturePickerNode` draws the shared pfp selection modal over the
|
||||
standard built-in pfp icon set and writes the selected `UIIconType` when the
|
||||
user chooses one.
|
||||
|
||||
@@ -964,26 +1150,24 @@ typedef struct {
|
||||
int max_tab_width;
|
||||
int *scroll_offset;
|
||||
int focus_selected;
|
||||
} UITabBar;
|
||||
} TabBar;
|
||||
|
||||
int DrawUITabBar(UITabBar bar);
|
||||
int GetUITabBarHeight(void);
|
||||
int TabBar(TabBar bar);
|
||||
```
|
||||
|
||||
#### Dropdown
|
||||
|
||||
```c
|
||||
int DrawUIDropdownButton(int id, int x, int y, int w, int h,
|
||||
int Dropdown(int id, int x, int y, int w, int h,
|
||||
const char **options, int option_count, int *selected_index);
|
||||
int DrawUIDropdownMenu(int id);
|
||||
int UIDropdownCapturesClick(Vector2 point);
|
||||
void DrawUIOverlays(void);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Modals
|
||||
|
||||
#### `DrawUIActionModal`
|
||||
#### `UIActionModalNode`
|
||||
|
||||
Adaptive action modal for a title, message, optional close icon, and one to
|
||||
three action buttons.
|
||||
@@ -1002,9 +1186,9 @@ typedef struct {
|
||||
int action_count;
|
||||
Texture2D close_icon;
|
||||
int max_width;
|
||||
} UIModalSpec;
|
||||
} ModalProps;
|
||||
|
||||
int DrawUIActionModal(UIModalSpec modal);
|
||||
int UIActionModalNode(ModalProps modal);
|
||||
```
|
||||
|
||||
**Returns:** `-1` when the close icon is clicked, `0` for no action, or the
|
||||
@@ -1016,35 +1200,35 @@ inside the button, and the action row wraps to multiple rows when labels do not
|
||||
fit. Backdrop clicks are blocked automatically for the current frame and the next
|
||||
frame.
|
||||
|
||||
#### `DrawUIModal`
|
||||
#### `UIModalNode`
|
||||
|
||||
Simple two-button modal.
|
||||
|
||||
```c
|
||||
int DrawUIModal(const char *title, const char *message,
|
||||
int UIModalNode(const char *title, const char *message,
|
||||
const char *cancel_btn, const char *confirm_btn);
|
||||
```
|
||||
|
||||
**Returns:** 1 for cancel, 2 for confirm
|
||||
|
||||
Compatibility wrapper around `DrawUIActionModal`. It uses an adaptive width,
|
||||
reflows message text, fits button labels, and wraps actions when needed. Backdrop
|
||||
clicks are blocked automatically for the current frame and the next frame.
|
||||
Uses the same adaptive modal behavior as `UIActionModalNode`: adaptive width,
|
||||
reflowed message text, fitted button labels, wrapped actions when needed, and
|
||||
automatic backdrop capture for the current frame and the next frame.
|
||||
|
||||
#### `DrawUIModal3Button`
|
||||
#### `UIModal3ButtonNode`
|
||||
|
||||
Three-button modal.
|
||||
|
||||
```c
|
||||
int DrawUIModal3Button(const char *title, const char *message,
|
||||
int UIModal3ButtonNode(const char *title, const char *message,
|
||||
const char *left_btn, const char *middle_btn, const char *right_btn);
|
||||
```
|
||||
|
||||
Compatibility wrapper around `DrawUIActionModal`. It uses an adaptive width,
|
||||
reflows message text, fits button labels, and wraps actions when needed. Backdrop
|
||||
clicks are blocked automatically for the current frame and the next frame.
|
||||
Uses the same adaptive modal behavior as `UIActionModalNode`: adaptive width,
|
||||
reflowed message text, fitted button labels, wrapped actions when needed, and
|
||||
automatic backdrop capture for the current frame and the next frame.
|
||||
|
||||
#### `UIPanelFrame` / `DrawUIModalFrame`
|
||||
#### `UIPanelFrame` / `UIModalFrameNode`
|
||||
|
||||
```c
|
||||
typedef struct {
|
||||
@@ -1060,11 +1244,11 @@ typedef struct {
|
||||
int right_clicked;
|
||||
} UIPanelFrame;
|
||||
|
||||
UIPanelFrame DrawUIModalFrame(int width, int height, const char *title,
|
||||
UIPanelFrame UIModalFrameNode(int width, int height, const char *title,
|
||||
Texture2D left_icon, Texture2D right_icon);
|
||||
```
|
||||
|
||||
`DrawUIModalFrame` also updates the modal capture bounds automatically for the
|
||||
`UIModalFrameNode` also updates the modal capture bounds automatically for the
|
||||
current frame and the next frame.
|
||||
|
||||
---
|
||||
@@ -1130,11 +1314,11 @@ UIScrollPage BeginUIScrollPage(UIScrollPageSpec spec);
|
||||
void EndUIScrollPage(UIScrollPage page);
|
||||
```
|
||||
|
||||
#### Scrollbar
|
||||
#### Node Measurement
|
||||
|
||||
```c
|
||||
int DrawUIScrollbar(int x, int y, int viewport_h, int content_h,
|
||||
int *scroll_offset, int max_scroll);
|
||||
int UIGetNodeHeight(const UIWidgetNode *node);
|
||||
int UIGetNodeHeightById(int id);
|
||||
```
|
||||
|
||||
---
|
||||
@@ -1144,24 +1328,25 @@ int DrawUIScrollbar(int x, int y, int viewport_h, int content_h,
|
||||
#### Sliders
|
||||
|
||||
```c
|
||||
int DrawUISlider(int id, int x, int y, int w, const char *label,
|
||||
int min, int max, int *value, const char *suffix);
|
||||
int DrawUIVerticalSlider(int id, int x, int y, int h,
|
||||
int UISliderNode(int id, int x, int y, int w, const char *label,
|
||||
int min, int max, int *value, const char *suffix,
|
||||
const char *value_text_override);
|
||||
int UIVerticalSliderNode(int id, int x, int y, int h,
|
||||
int min, int max, int *value);
|
||||
```
|
||||
|
||||
#### Toggle Switch
|
||||
|
||||
```c
|
||||
int DrawUIToggleSwitch(int x, int y, int w, int h, int *value,
|
||||
int Toggle(int x, int y, int w, int h, int *value,
|
||||
const char *off_label, const char *on_label);
|
||||
```
|
||||
|
||||
#### Checkbox
|
||||
|
||||
```c
|
||||
int DrawUICheckboxToggle(int x, int y, const char *label, int *value);
|
||||
int DrawDisabledUICheckboxToggle(int x, int y, const char *label,
|
||||
int Checkbox(int x, int y, const char *label, int *value);
|
||||
int Checkbox(int x, int y, const char *label,
|
||||
int *value, int disabled);
|
||||
```
|
||||
|
||||
@@ -1189,9 +1374,9 @@ typedef struct {
|
||||
Color background;
|
||||
Color separator;
|
||||
Color default_text;
|
||||
} UIInfoRows;
|
||||
} InfoRows;
|
||||
|
||||
void DrawUIInfoRows(UIInfoRows rows);
|
||||
void UIInfoRowsNode(InfoRows rows);
|
||||
```
|
||||
|
||||
#### Button Rows
|
||||
@@ -1211,15 +1396,14 @@ typedef struct {
|
||||
int gap;
|
||||
const UIButtonRowItem *items;
|
||||
int count;
|
||||
} UIButtonRow;
|
||||
} ButtonRow;
|
||||
|
||||
int GetUIButtonRowHeight(UIButtonRow row);
|
||||
int DrawUIButtonRow(UIButtonRow row);
|
||||
int UIButtonRowNode(ButtonRow row);
|
||||
```
|
||||
|
||||
`GetUIButtonRowHeight` returns the full wrapped height needed for the row.
|
||||
`DrawUIButtonRow` measures labels, fits text inside each button, and wraps into
|
||||
additional rows when the configured width cannot hold every action on one line.
|
||||
`UIButtonRowNode` measures labels, stores the final height on its node, fits
|
||||
text inside each button, and wraps into additional rows when the configured
|
||||
width cannot hold every action on one line.
|
||||
|
||||
---
|
||||
|
||||
@@ -1238,11 +1422,11 @@ next frame. While a modal carried from the previous frame has not registered its
|
||||
bounds yet, all pointer input is captured. After registration, clicks outside the bounds
|
||||
are captured while controls inside the modal remain usable.
|
||||
|
||||
Built-in modal helpers (`DrawUIActionModal`, `DrawUIModal`,
|
||||
`DrawUIModal3Button`, `DrawUIModalFrame`) register their bounds automatically.
|
||||
Built-in modal helpers (`UIActionModalNode`, `UIModalNode`,
|
||||
`UIModal3ButtonNode`, `UIModalFrameNode`) register their bounds automatically.
|
||||
|
||||
Applications should use `DrawUIActionModal` for standard title/message/action
|
||||
dialogs and `DrawUIModalFrame` for custom modal content instead of manually
|
||||
Applications should use `UIActionModalNode` for standard title/message/action
|
||||
dialogs and `UIModalFrameNode` for custom modal content instead of manually
|
||||
drawing a backdrop and calling `SetUIModalCapture`. Manual capture remains
|
||||
available for specialized overlays, but the helpers keep modal bounds, backdrop,
|
||||
and input capture consistent across projects.
|
||||
@@ -1316,32 +1500,39 @@ void SetUIFocusTextInputActive(int active);
|
||||
### Focus Indicator
|
||||
|
||||
```c
|
||||
void DrawUIFocus(Rectangle bounds);
|
||||
void UIFocusNode(Rectangle bounds);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Utility Functions
|
||||
|
||||
### Bevel Drawing
|
||||
## Memory Diagnostics
|
||||
|
||||
```c
|
||||
void DrawUIBevel(int x, int y, int w, int h, Color light, Color dark);
|
||||
int KryonMemDebugEnabled(void);
|
||||
void KryonMemReport(const char *tag);
|
||||
```
|
||||
|
||||
Both are no-ops unless `KRYON_MEM_DEBUG` is set in the environment, so apps
|
||||
can call them at interesting points unconditionally. `KryonMemReport` prints
|
||||
the process RSS/high-water marks (Linux) and the glibc allocator arena
|
||||
breakdown to stderr. `UIFontMemoryReport` (Text section) reports per-font
|
||||
rasterization stats under the same switch.
|
||||
|
||||
## Utility Functions
|
||||
|
||||
### Icon Buttons
|
||||
|
||||
```c
|
||||
int GetUIIconButtonSize(UIIconSize size);
|
||||
int GetUIIconButtonPadding(UIIconSize size);
|
||||
int DrawUIIconBtn(int x, int y, UIIconSize size, Texture2D icon, int *hover);
|
||||
int DrawUIPaddedIconBtn(int x, int y, int size, int padding, Texture2D icon, int *hover);
|
||||
int UIIconBtnNode(int id, int x, int y, UIIconSize size, Texture2D icon, int *hover);
|
||||
int UIPaddedIconBtnNode(int id, int x, int y, int size, int padding, Texture2D icon, int *hover);
|
||||
```
|
||||
|
||||
### Generic Button
|
||||
|
||||
```c
|
||||
int DrawUIGenericButton(int x, int y, int w, int h, const char *label,
|
||||
int UIGenericButtonNode(int x, int y, int w, int h, const char *label,
|
||||
UIButtonStyle style, int disabled, int *hover);
|
||||
```
|
||||
|
||||
@@ -1426,7 +1617,7 @@ UIFrame frame = BeginUIFrameBox((Rectangle){40, 40, 320, 200}, 12, 12, 8);
|
||||
Rectangle row = UIFramePack(&frame, UI_SIDE_TOP, 32);
|
||||
|
||||
int selected = 0;
|
||||
DrawUIListBox((UIListBox){
|
||||
UIListBoxNode((ListBox){
|
||||
.bounds = row,
|
||||
.id = 10,
|
||||
.items = items,
|
||||
@@ -1447,14 +1638,14 @@ through the existing codepoint filter.
|
||||
|
||||
Feature families:
|
||||
|
||||
- Geometry: `BeginUIFrameBox`, `UIFramePack`, `UIGridCell`, `UIPlace`, `DrawUISeparator`
|
||||
- Menus: `DrawUIMenuBar`, `DrawUIPopupMenu`
|
||||
- Basic controls: `DrawUIRadioButton`, `DrawUIProgressBar`, `DrawUISpinbox`, `DrawUICombobox`, `DrawUILabelFrame`, `DrawUIImageBox`
|
||||
- Collections: `DrawUIListBox`, `DrawUITreeView`, `DrawUITableView`
|
||||
- Canvas: `BeginUICanvas`, `EndUICanvas`, `DrawUICanvasGrid`, `UICanvasHitTest`
|
||||
- Containers: `DrawUINotebook`, `DrawUIPanedView`, `DrawUICollapsible`
|
||||
- Dialogs/platform: `DrawUIMessageDialog`, `DrawUIConfirmDialog`, `DrawUIPromptDialog`, `DrawUIColorPicker`, `DispatchUIAccelerators`, clipboard helpers
|
||||
- Accessibility/debug: `DrawUIFocusDebugOverlay`
|
||||
- Geometry: `BeginUIFrameBox`, `UIFramePack`, `UIGridCell`, `UIPlace`, `UISeparatorNode`
|
||||
- Menus: `UIMenuBarNode`, `UIPopupMenuNode`
|
||||
- Basic controls: `Radio`, `Progress`, `Spinbox`, `Combobox`, `UILabelFrameNode`, `UIImageBoxNode`
|
||||
- Collections: `UIListBoxNode`, `UITreeViewNode`, `UITableViewNode`
|
||||
- Canvas: `BeginUICanvas`, `EndUICanvas`, `UICanvasGridNode`, `UICanvasHitTest`
|
||||
- Containers: `UINotebookNode`, `PanedView`, `Collapsible`
|
||||
- Dialogs/platform: `UIMessageDialogNode`, `UIConfirmDialogNode`, `UIPromptDialogNode`, `UIColorPickerNode`, `DispatchUIAccelerators`, clipboard helpers
|
||||
- Accessibility/debug: `UIFocusDebugOverlayNode`
|
||||
|
||||
Examples `09_geometry` through `18_accessibility` demonstrate these APIs.
|
||||
|
||||
@@ -1481,11 +1672,12 @@ int main(void) {
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), dpi);
|
||||
|
||||
// Draw UI
|
||||
if (DrawUIGenericButton(10, 10, 100, 36, "Click Me",
|
||||
if (UIGenericButtonNode(10, 10, 100, 36, "Click Me",
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, NULL)) {
|
||||
// Button clicked
|
||||
}
|
||||
|
||||
EndUIFrame();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Kryon App Build Plan
|
||||
|
||||
Goal: Kryon owns the repeatable build and packaging flow for every Kryon app.
|
||||
App repositories should provide app metadata, native sources, `.kry` sources, and
|
||||
assets. Kryon should provide the compiler, runtime, dependency builds, packaging
|
||||
helpers, IDE preview hooks, and diagnostics.
|
||||
Kryon owns the repeatable build and packaging flow for every Kryon app. App
|
||||
repositories provide app metadata, native sources, `.kry` sources, and assets.
|
||||
Kryon provides the compiler, runtime, dependency builds, packaging helpers,
|
||||
Krait preview hooks, and diagnostics through the `kryon` command.
|
||||
|
||||
## App Contract
|
||||
|
||||
@@ -23,7 +23,7 @@ should come from Kryon.
|
||||
|
||||
## Unified Commands
|
||||
|
||||
Kryon should expose one command surface for all apps:
|
||||
Kryon exposes one command surface for all apps:
|
||||
|
||||
- `kryon build native`
|
||||
- `kryon build web`
|
||||
@@ -40,7 +40,7 @@ Kryon should expose one command surface for all apps:
|
||||
- `kryon preview`
|
||||
- `kryon test`
|
||||
|
||||
Makefiles in app repos should become thin wrappers that call these commands.
|
||||
Makefiles in app repos are thin wrappers that call these commands.
|
||||
|
||||
## Build Ownership
|
||||
|
||||
@@ -79,7 +79,7 @@ Apps own:
|
||||
make fragments with normalized variables.
|
||||
5. Convert app Makefiles to compatibility shims, then remove duplicated app-side
|
||||
package/build rules.
|
||||
6. Make the IDE use the same build graph for preview/run so errors from manual
|
||||
6. Make Krait use the same build graph for preview/run so errors from manual
|
||||
build, auto preview, and package targets use one diagnostic format.
|
||||
7. Add template checks so new Kryon apps start with the unified layout.
|
||||
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
# Kryon Backends
|
||||
|
||||
How the graphics/input backend is selected, what a backend must implement, and
|
||||
how to add a new one. For the operational guide see `docs/AGENTS.md`; for the
|
||||
public API see `docs/API.md`.
|
||||
|
||||
## The surface and how selection works
|
||||
|
||||
Kryon's public graphics/input API is `include/kryon_compat.generated.h`:
|
||||
kryon owns the surface, and it currently tracks raylib's header verbatim so
|
||||
raylib-style code compiles unchanged. A backend is a translation unit (or set
|
||||
of them) that defines the surface's functions. No `raylib.h` include and no
|
||||
raylib build path may appear in `include/`, `src/`, `examples/`, or `tests/`
|
||||
(`make kryon-boundary-check`).
|
||||
|
||||
Backend selection is link-time, via the `KRYON_BACKEND` make variable:
|
||||
|
||||
- `raylib` (default) - generated forwarders (`build/generated/
|
||||
kryon_raylib_wrappers.c`) call into raylib, which is compiled with every
|
||||
symbol renamed `KryonRaylibBackend_*` (`build/generated/
|
||||
raylib_backend_rename.h`, applied in `mk/raylib.mk`). Applications can never
|
||||
bind raylib symbols directly.
|
||||
- `null` - generated zero-return stubs (`build/generated/kryon_null_backend.c`)
|
||||
so the library links and runs headless with no GPU or window. Injected input
|
||||
(below) still works, which is what drives headless widget tests.
|
||||
- `canvas` - HTML5 Canvas2D backend, no raylib (`src/backend/canvas_backend.c`).
|
||||
|
||||
Exactly one backend TU is compiled into `libkryon.a` (root `Makefile`), and
|
||||
`KRYON_BACKEND_LIBS`/`KRYON_BACKEND_LDLIBS` carry the backend's own link
|
||||
inputs (only raylib needs `libraylib.a` and its SDL/GL system libs). The
|
||||
downstream fragments (`mk/common.mk`, `mk/native.mk`, `mk/web.mk`) honor the
|
||||
same variable, so `make KRYON_BACKEND=null` produces binaries with no raylib
|
||||
in the link graph. The cross-build dist targets (`dist-linux`, `dist-windows`,
|
||||
Android, and `make dist-static`, whose pkg-config/cmake manifests hardcode
|
||||
raylib) are raylib-only today.
|
||||
|
||||
## The shared input front-end
|
||||
|
||||
Input is not the backend's job beyond polling. `src/backend/kry_input.c`
|
||||
defines the public input queries (`IsKeyPressed`, `IsKeyDown`,
|
||||
`IsMouseButton*`, `GetMouse*`, `GetCharPressed`, `GetKeyPressed`, ...) once for
|
||||
every backend, merging, in order:
|
||||
|
||||
1. synthetic input injection (`kry_inject.h` - headless tests and the
|
||||
synthetic file system),
|
||||
2. the keyboard enable/disable switch and keyboard platform callbacks
|
||||
(`SetKeyboardInputEnabled`, `SetKeyPlatformCallbacks` - non-raylib key
|
||||
sources such as an IME),
|
||||
3. the modal input override (`BeginKryonInputOverride`/`EndKryonInputOverride`
|
||||
- offscreen windows stealing the pointer),
|
||||
4. the backend's raw poll, via the `KryonBackendRaw_*` hooks declared in
|
||||
`include/kry_input.h`.
|
||||
|
||||
A backend implements only those raw hooks; it gets injection, overrides, and
|
||||
platform-key routing for free. The generated raylib wrappers forward the
|
||||
hooks; the generated null backend answers them with zeros.
|
||||
|
||||
## Shared surface functions
|
||||
|
||||
Pure-math surface symbols - `Fade`, `ColorLerp`, `CheckCollisionPointRec`,
|
||||
`CheckCollisionRecs`, `GetWorldToScreen2D`, `GetScreenToWorld2D`,
|
||||
`GetCodepointNext` - are backend-independent arithmetic (colors, rectangles,
|
||||
the Camera2D transform, UTF-8 decoding) and are defined once for every
|
||||
backend in `src/backend/kry_surface_math.c`. The generator skips them in both
|
||||
generated files; a new backend implements none of them. Without this the null
|
||||
backend's zero-return stubs would break pointer hit-testing, since
|
||||
`ui_mouse_world()` transforms the mouse position through
|
||||
`GetScreenToWorld2D` before any click test.
|
||||
|
||||
## What a backend must implement
|
||||
|
||||
The full surface is ~700 symbols, but kryon's own code, the tooling, and
|
||||
generated `.kry` apps call a much smaller subset. `sh
|
||||
tools/backend-required-symbols.sh` prints the exact list from current call
|
||||
sites (~100 symbols); keep it in sync when adding surface usage. Grouped:
|
||||
|
||||
- **Window/frame**: `InitWindow`, `CloseWindow`, `WindowShouldClose`,
|
||||
`IsWindowReady`, `SetConfigFlags`, `SetTargetFPS`, `SetWindowSize`,
|
||||
`BeginDrawing`, `EndDrawing`, `GetScreenWidth/Height`, `GetFrameTime`,
|
||||
`GetTime`, `GetWindowScaleDPI`, `SetTraceLogLevel`, `SetMouseCursor`.
|
||||
- **Input**: the `KryonBackendRaw_*` hooks above only.
|
||||
- **Drawing (immediate mode)**: `ClearBackground`, `DrawRectangle*`,
|
||||
`DrawCircle*`, `DrawLine*`, `DrawRing`, `DrawTriangle`, `DrawTexture`,
|
||||
`DrawTexturePro`, `DrawText` (default font), `BeginScissorMode`/
|
||||
`EndScissorMode`, `BeginMode2D`/`EndMode2D` (scene camera). Callers assume
|
||||
the backend batches internally (raylib/rlgl does); a backend without
|
||||
batching is correct but slow.
|
||||
- **Text**: `LoadFontFromMemory` (TTF with an explicit codepoint set),
|
||||
`UnloadFont`, `GetFontDefault`, `GetGlyphInfo`, `GetGlyphAtlasRec`,
|
||||
`GetGlyphIndex`, `SetTextureFilter` on the atlas. Layout, fallback, and
|
||||
glyph blits are kryon's (`ui_text.c`, `ui_text_backend.h`); the backend
|
||||
rasterizes glyphs into an atlas texture and reports metrics. `ui_text.c`
|
||||
detects a backend that silently returns the default font as load failure.
|
||||
- **Textures/images**: `LoadTexture`, `LoadTextureFromImage`,
|
||||
`LoadImageFromMemory`, `UnloadTexture`, `UnloadImage`,
|
||||
`LoadRenderTexture`, `BeginTextureMode`/`EndTextureMode`,
|
||||
`LoadImageFromTexture`, `ImageFlipVertical`, `ExportImage` (screenshot and
|
||||
`kryon-preview` PNG capture path), `GetImageColor`-class pixel access where
|
||||
used.
|
||||
- **Math/collision helpers**: `Fade`, `ColorLerp`, `CheckCollisionPointRec`,
|
||||
`CheckCollisionRecs`, `GetWorldToScreen2D`, `GetScreenToWorld2D`,
|
||||
`GetCodepointNext` already come from `src/backend/kry_surface_math.c`
|
||||
(above). Only `TextFormat`/`TraceLog` remain backend-supplied (the null
|
||||
backend implements them; raylib forwards).
|
||||
- **OS services** (may be no-ops on a given platform): `GetClipboardText`/
|
||||
`SetClipboardText`, `FileExists`, `DirectoryExists`, `GetDirectoryPath`,
|
||||
`MakeDirectory`, `LoadFileData/Text`, `UnloadFileData/Text`, `OpenURL`.
|
||||
- **Audio** (apps opt in; null-grade stubs are acceptable for UI-only
|
||||
backends): `LoadSound`/`UnloadSound`/`PlaySound`, `SetSoundVolume/Pitch`,
|
||||
music stream functions.
|
||||
|
||||
Everything else on the surface (3D, shaders, gestures, VR, ...) can be a
|
||||
zero-return stub exactly like the generated null backend.
|
||||
|
||||
## Struct-layout obligations
|
||||
|
||||
The surface passes `Font`, `Texture2D`, `Image`, `GlyphInfo`,
|
||||
`RenderTexture2D`, `Camera2D`, `Rectangle`, `Vector2`, `Color` by value with
|
||||
raylib's layouts, and kryon state stores them directly (font caches, frame
|
||||
camera, icon atlases). A backend must fill those structs with its own objects
|
||||
behind them. The standard pattern is a side table keyed by the integer
|
||||
`Texture2D.id`/`Font.texture.id` mapping to native handles; ids must be
|
||||
non-zero for loaded resources (0 means "invalid/default"). `src/ui/
|
||||
ui_text_backend.c` is the only place that reads `Font` fields directly
|
||||
(baseSize, glyphPadding, texture, readiness); respect those semantics.
|
||||
|
||||
## Adding a backend
|
||||
|
||||
1. Create `src/backend/<name>_backend.c` implementing the required subset
|
||||
above under the surface's public names, plus the `KryonBackendRaw_*` hooks.
|
||||
Everything not implemented should match the null backend's zero-return
|
||||
behavior so the library still links.
|
||||
2. Register it in the root `Makefile`'s `KRYON_BACKEND` block and in
|
||||
`mk/common.mk` (backend TU + link inputs), mirroring the existing entries.
|
||||
3. Prove it end-to-end: `make KRYON_BACKEND=<name> check`-style build of the
|
||||
library, one example app, and a headless test slice. The `.krb` cartridge
|
||||
interpreter (`src/krb/krb.c`) draws through the `KryBackend` vtable
|
||||
(`include/kry_backend.h`) and is a quick way to smoke-test drawing without
|
||||
the full UI stack.
|
||||
4. Do not patch vendor code or add `#ifdef <backend>` branches to `src/`;
|
||||
backend differences live behind the surface, `kry_input.h`, and
|
||||
`kry_backend.h`.
|
||||
|
||||
## Checks
|
||||
|
||||
- `make kryon-boundary-check` - no `raylib.h` includes or raylib paths in
|
||||
app-facing code.
|
||||
- `make kryon-compat-check` - generated surface/rename/wrappers are in sync
|
||||
with `vendor/raylib/src/raylib.h` and every raylib symbol has a rename plus
|
||||
a public wrapper or `KryonBackendRaw_*` hook.
|
||||
- `sh tools/backend-required-symbols.sh` - the live required-subset list a
|
||||
backend must cover.
|
||||
@@ -0,0 +1,266 @@
|
||||
# Kryon Cartridge Format (krb) — exact specification
|
||||
|
||||
A `.krb` file is Kryon's compact portable cartridge: everything a renderer
|
||||
needs to draw and run a UI, in one little-endian, mmapable binary. This
|
||||
document is normative. An implementation that follows it can parse and
|
||||
render any cartridge without kryon source code.
|
||||
|
||||
Reference implementation: `src/krb/krb.c` (runtime), `cmd/k2b` (compiler),
|
||||
`include/krb.h` (constants). Reference renderers: `src/backend/kry_sw.c`
|
||||
(software), `cmd/krb-run` (headless), `cmd/krb-web` (wasm), `cmd/krb-sdl`.
|
||||
|
||||
## 1. Encoding rules
|
||||
|
||||
- All multi-byte integers are **little-endian**, packed, no alignment
|
||||
padding inside records.
|
||||
- Strings are UTF-8, NUL-terminated, stored once in the string table;
|
||||
every string reference elsewhere is a `u16` **byte offset** into it.
|
||||
- Offsets into `prog[]` are `u32` **absolute** byte offsets from the start
|
||||
of the program section.
|
||||
- Colors are `u32` packed `0xRRGGBBAA`. Theme references: see §4.
|
||||
|
||||
## 2. File layout
|
||||
|
||||
One linear image, sections in this exact order, no gaps:
|
||||
|
||||
```
|
||||
offset size section
|
||||
0 32 header (28 used + 4 reserved)
|
||||
H 28 × node_count nodes[]
|
||||
N string_bytes strings[]
|
||||
S prog_bytes prog[]
|
||||
P 4 × import_count imports[] (u32 string offsets each)
|
||||
I 24 × control_count controls[]
|
||||
```
|
||||
|
||||
with `H = 32`, `N = H + 28 × node_count`, `S = N + string_bytes`,
|
||||
`P = S + prog_bytes`, `I = P + 4 × import_count`. A loader MUST reject the
|
||||
file when `file_size < I + 24 × control_count`.
|
||||
|
||||
## 3. Header (32 bytes)
|
||||
|
||||
| Offset | Size | Field | Value |
|
||||
|---|---|---|---|
|
||||
| 0 | 4 | magic | `0x0042524B` — bytes `4B 52 42 00` (`"KRB\0"`) |
|
||||
| 4 | 2 | version | `1` or `2` (see §7); a loader MUST reject other values |
|
||||
| 6 | 2 | flags | reserved, MUST be 0 |
|
||||
| 8 | 4 | node_count | number of node records |
|
||||
| 12 | 4 | string_bytes | size of string table in bytes |
|
||||
| 16 | 4 | prog_bytes | size of program section |
|
||||
| 20 | 4 | import_count | number of host-import name offsets |
|
||||
| 24 | 4 | control_count | number of control records |
|
||||
| 28 | 4 | reserved | MUST be 0 |
|
||||
|
||||
Additional loader requirements: `string_bytes > 0` and the byte at string
|
||||
offset `0` MUST be `0x00` (the empty string lives at offset 0).
|
||||
|
||||
## 4. Node record (28 bytes)
|
||||
|
||||
| Offset | Size | Field | Type | Meaning |
|
||||
|---|---|---|---|---|
|
||||
| 0 | 2 | id | u16 | node id (serial number; equals record index today) |
|
||||
| 2 | 2 | parent | i16 | parent node index, `-1` = root |
|
||||
| 4 | 2 | name_off | u16 | string offset (name / bound state path) |
|
||||
| 6 | 1 | type | u8 | node type, §4.1 |
|
||||
| 7 | 1 | flags | u8 | bit flags, §4.2 |
|
||||
| 8 | 2 | bind_slot | u16 | import slot or control index; `0xFFFF` = none |
|
||||
| 10 | 2 | x | i16 | x coordinate (meaning per type) |
|
||||
| 12 | 2 | y | i16 | y coordinate |
|
||||
| 14 | 2 | w | i16 | width / radius per type |
|
||||
| 16 | 2 | h | i16 | height / inner radius per type |
|
||||
| 18 | 4 | color | u32 | `0xRRGGBBAA` or theme reference |
|
||||
| 22 | 2 | text_off | u16 | string offset (label / asset path / format) |
|
||||
| 24 | 2 | font_size | u16 | pixels; `0` renders as 16 |
|
||||
| 26 | 1 | style | u8 | per-type substyle |
|
||||
| 27 | 1 | pad | u8 | reserved, MUST be 0 |
|
||||
|
||||
### 4.1 Node types
|
||||
|
||||
| Value | Name | x,y / w,h meaning | Drawn as |
|
||||
|---|---|---|---|
|
||||
| 0 | — | reserved | — |
|
||||
| 1 | BACKGROUND | w,h = size (see §8) | filled rect, the screen backdrop |
|
||||
| 2 | TEXT | x,y = top-left | text, `text_off` string, `font_size` |
|
||||
| 3 | RECT | x,y,w,h = bounds | filled rect |
|
||||
| 4 | BUTTON | bounds | filled rect + 1px border + centered label (`text_off`); import `bind_slot` fires on press-in-bounds. `style`: 0 primary (theme button color), 1 plain (theme surface), 2 danger (`0xB83B3BFF`) |
|
||||
| 5 | DATA | — | not drawn; state-field metadata |
|
||||
| 6 | PICTURE | bounds | texture; `text_off` = asset path, `color` = tint, `style` = fit (0 stretch, 1 contain, 2 cover) |
|
||||
| 7 | CHECKBOX | box at bounds; label at `x+w+4` | cartridge-owned toggle on mount path `name_off`; flips value on press-in-bounds |
|
||||
| 8 | TOGGLE | switch at bounds; label beside | same mount behavior as CHECKBOX |
|
||||
| 9 | CONTROL | bounds = widget bounds | range widget; `bind_slot` indexes controls[] |
|
||||
| 10 | CIRCLE | x,y = center; w = radius | filled circle |
|
||||
| 11 | RING | x,y = center; w = outer, h = inner radius | annulus |
|
||||
| 12 | SCROLL | bounds = viewport; `font_size` = content height; `name_off` = mount path of pixel offset | container: children (nodes with `parent` = this index) draw translated by `-offset` and clipped to the viewport; wheel over the viewport adjusts the mounted offset (clamped to `[0, content_h - h]`) |
|
||||
|
||||
### 4.2 Flags
|
||||
|
||||
| Bit | Mask | Name | Meaning |
|
||||
|---|---|---|---|
|
||||
| 0–1 | `0x03` | reserved | MUST be 0 |
|
||||
| 2 | `0x04` | SCALE_X | x is in UI-scale units (multiply by backend scale) |
|
||||
| 3 | `0x08` | SCALE_Y | same for y |
|
||||
| 4 | `0x10` | SCALE_W | same for w |
|
||||
| 5 | `0x20` | SCALE_H | same for h |
|
||||
|
||||
### 4.3 Colors and theme slots
|
||||
|
||||
A node `color` whose **top bit is set** (`color & 0x80000000 != 0`) is a
|
||||
theme reference: `slot = color & 0x7FFFFFFF`; the renderer asks the host
|
||||
backend for the slot color. Slots: `0` background, `1` text, `2` icon,
|
||||
`3` surface, `4` button; other slot values resolve to the backend default.
|
||||
|
||||
**Consequence (deliberate v1 constraint):** any *literal* color with a red
|
||||
channel ≥ `0x80` also has the top bit set and reads as a theme reference.
|
||||
Literal cartridge colors MUST keep R < `0x80`; use a theme slot for bright
|
||||
reds. (A future version may move the sentinel; until then this rule is
|
||||
normative.)
|
||||
|
||||
## 5. String table
|
||||
|
||||
`string_bytes` bytes of concatenated NUL-terminated UTF-8 strings. Offset 0
|
||||
is the empty string (the table starts with a `0x00` byte). A string
|
||||
reference is valid iff `offset < string_bytes - 1` and the byte at
|
||||
`offset` begins a complete string. Paths used as mount references (e.g.
|
||||
`"counter"`, `"app/score"`) are plain strings compared exactly.
|
||||
|
||||
## 6. Imports
|
||||
|
||||
`import_count` × `u32` string offsets naming host functions (today: button
|
||||
handlers). A node's `bind_slot` (when `< 0xFFFF`) selects the slot; the
|
||||
host binds each slot with `KrbBind`/`KrbBindSlot`. A slot with no bound
|
||||
function is skipped silently.
|
||||
|
||||
## 7. Control record (24 bytes)
|
||||
|
||||
Referenced by a CONTROL node's `bind_slot`.
|
||||
|
||||
| Offset | Size | Field | Type | Meaning |
|
||||
|---|---|---|---|---|
|
||||
| 0 | 1 | kind | u8 | 1 slider, 2 vslider, 3 spinbox (4/5 reserved) |
|
||||
| 1 | 1 | option_count | u8 | reserved for dropdown options, 0 |
|
||||
| 2 | 2 | id | u16 | widget id |
|
||||
| 4 | 4 | min | i32 | range minimum |
|
||||
| 8 | 4 | max | i32 | range maximum |
|
||||
| 12 | 4 | step | i32 | increment |
|
||||
| 16 | 2 | value_off | u16 | string offset: mount path of the value |
|
||||
| 18 | 2 | label_off | u16 | string offset: label |
|
||||
| 20 | 2 | options_off | u16 | reserved, 0 |
|
||||
| 22 | 2 | reserved | u16 | MUST be 0 |
|
||||
|
||||
Slider: held-drag maps the pointer position across the track to
|
||||
`[min, max]`. Spinbox: click left/right half decrements/increments by
|
||||
`step`, clamped to `[min, max]`. Dropdown (`kind 4`): `options_off`
|
||||
points at `option_count` consecutive NUL-terminated option strings;
|
||||
the bound `int` holds the selected index. Click toggles the popup;
|
||||
clicking a row writes the index and closes.
|
||||
|
||||
## 8. Program and execution semantics
|
||||
|
||||
`prog[]` is a byte stream executed in order by `KrbExec` once per frame.
|
||||
Opcodes:
|
||||
|
||||
| Op | Byte | Operands (in order) | Semantics |
|
||||
|---|---|---|---|
|
||||
| `OP_DRAW_TREE` | `0x01` | — | draw every node, in record order |
|
||||
| `OP_CALL_HOST` | `0x02` | u8 slot | call host function bound to slot |
|
||||
| `OP_SET_I32` | `0x03` | u16 path_off, i32 value | write mounted int |
|
||||
| `OP_PUSH_CONST` | `0x10` | i32 | push immediate |
|
||||
| `OP_PUSH_PATH` | `0x11` | u16 path_off | push mounted int at path (unmounted → 0) |
|
||||
| `OP_POP_STORE` | `0x12` | u16 path_off | pop → write mounted int at path |
|
||||
| `OP_ADD` | `0x13` | — | pop b, pop a, push `a + b` |
|
||||
| `OP_SUB` | `0x14` | — | push `a - b` |
|
||||
| `OP_MUL` | `0x15` | — | push `a * b` |
|
||||
| `OP_DIV` | `0x16` | — | push `b == 0 ? 0 : a / b` (C division) |
|
||||
| `OP_EQ`/`NE`/`LT`/`LE`/`GT`/`GE` | `0x17`–`0x1C` | — | pop b, pop a, push 1 or 0 |
|
||||
| `OP_JMP` | `0x1D` | u32 addr | set program counter to `addr` |
|
||||
| `OP_JZ` | `0x1E` | u32 addr | pop; if 0, set program counter to `addr` |
|
||||
| `OP_TIME` | `0x1F` | — | push `(int)(host time in seconds × 1000)` |
|
||||
| `OP_DRAW_NODE` | `0x20` | u16 node index | draw one node |
|
||||
|
||||
Rules:
|
||||
|
||||
- The VM stack is 16-deep int32 and persists across opcodes within one
|
||||
`KrbExec` pass. Push on overflow or pop on underflow is an error
|
||||
(execution fails).
|
||||
- Jump targets are absolute offsets into `prog[]`; a target outside
|
||||
`[0, prog_bytes]` makes the jump a no-op.
|
||||
- Any other opcode byte is an error; execution stops.
|
||||
- Drawing: node coordinates are relative to the current draw origin
|
||||
(0,0 for a full-frame pass). A SCALE_* flag replaces the raw i16 with
|
||||
`backend.scale_px(value)`. When `OP_DRAW_TREE` (or `OP_DRAW_NODE` on a
|
||||
BACKGROUND node) executes, a BACKGROUND node's w/h are overridden with the
|
||||
host screen size and its SCALE_W/H flags cleared.
|
||||
- Interaction (BUTTON, CHECKBOX, TOGGLE, CONTROL) is evaluated at draw
|
||||
time: "pointer pressed this frame" AND "pointer inside the node bounds"
|
||||
(post-transform). Bounds are exclusive on the right/bottom edges.
|
||||
|
||||
### Versions
|
||||
|
||||
- **v1** — opcodes `0x01`–`0x03`, node types 1–9. Render-first.
|
||||
- **v2** — adds opcodes `0x10`–`0x20` and node types 10–11. Loaders accept
|
||||
both; compilers should emit 2.
|
||||
|
||||
### Asset section (v2)
|
||||
|
||||
When header offset 28 (`asset_bytes`) is nonzero, an asset section follows
|
||||
`controls[]`: a `u32 asset_count`, then `asset_count` directory entries of
|
||||
20 bytes, then the blobs. Entry: `path_off u32@0` (string table),
|
||||
`data_off u32@4` (absolute file offset), `size u32@8`, `kind u16@12`
|
||||
(0 = raw RGBA8 pixels, 1 = glyph atlas), `w u16@14`, `h u16@16`,
|
||||
`reserved u16@18`. `asset_bytes` counts the whole section. A PICTURE node
|
||||
whose path matches an embedded raw-RGBA asset is rendered from cartridge
|
||||
pixels through the backend's optional `texture_rgba` (scaled, tinted);
|
||||
non-embedded paths fall back to host texture loading. The conventional
|
||||
name "@atlas" carries a KFA1 glyph atlas: `u32 "KFA1" | u16 size_count`,
|
||||
then per size a 16-byte record (`px u16 | glyphs u16 | w u16 | h u16 |
|
||||
table_off u32 | pixels_off u32`), then per-glyph 18-byte records
|
||||
(`cp u32 | x,y,w,h u16 | xoff,yoff i16 | advance u16` in 1/256-px fixed point,
|
||||
offsets into the
|
||||
size's RGBA8 white-on-alpha bitmap). Engines with atlas support render
|
||||
antialiased text with true advances; without it they fall back to their
|
||||
built-in font.
|
||||
|
||||
## 9. Limits (current implementation)
|
||||
|
||||
256 nodes, 8 KiB strings, 32 imports, 128 controls, 32 host binds,
|
||||
16 mount roots, 64 fields per mount, 16 MiB cartridge (raised from
|
||||
64 KiB to fit embedded atlases and images).
|
||||
|
||||
## 10. Host surface (what a renderer must provide)
|
||||
|
||||
A renderer implements the `KryBackend` table (see `include/kry_backend.h`):
|
||||
`clear`, `rect`, `text`, `measure_text`, `clip_push/pop`, `mouse`,
|
||||
`mouse_down`, `mouse_pressed`, `width`, `height`, `time`, `scale_px`,
|
||||
`theme_color`, `texture`, and optional `circle`/`ring` (v2 geometry; a
|
||||
renderer may leave them NULL, in which case CIRCLE/RING nodes are no-ops).
|
||||
Colors passed to the backend are already resolved literals. Assets are
|
||||
referenced by path; loading and caching are host-owned.
|
||||
|
||||
## 11. C memory as files (mounts)
|
||||
|
||||
Hosts map live memory onto string paths:
|
||||
|
||||
```c
|
||||
KrbField fields[] = {
|
||||
{ "score", offsetof(App, score), KRB_I32, 4 },
|
||||
{ "label", offsetof(App, label), KRB_CSTR, 16 },
|
||||
{ NULL }
|
||||
};
|
||||
KrbMount(&img, "/app", app, fields);
|
||||
KrbReadI32(&img, "/app/score", &n);
|
||||
/* or a single field: */
|
||||
KrbBindMem(&img, "counter", &counter, KRB_I32, 4);
|
||||
```
|
||||
|
||||
Field kinds: `KRB_I32 1`, `KRB_U32 2`, `KRB_F32 3`, `KRB_BOOL 4`,
|
||||
`KRB_CSTR 5`. Read/write is a typed memcpy. A TEXT node whose `name_off`
|
||||
string equals a mounted path renders the live value; its `text_off` string
|
||||
acts as a `printf` format when it contains `%`.
|
||||
|
||||
## 12. Tooling
|
||||
|
||||
- `k2b` compiles `.kry` → `.krb` (+ optional generated C host; `--no-main`
|
||||
omits the host `main`). Unsupported `.kry` calls are dropped and reported.
|
||||
- `krb-run` renders headless to PNG / a recorded call stream.
|
||||
- `krb-web` / `krb-sdl` are full hosts; `tests/golden` + `tests/krb_engine_test.sh`
|
||||
pin cross-engine byte-identical output.
|
||||
@@ -1,8 +1,35 @@
|
||||
# Kry Language
|
||||
|
||||
Kry is C-close app code for Kryon. `kc` emits readable `.c` and `.h` files
|
||||
that are compiled by the normal C toolchain; there is no VM, runtime package
|
||||
system, or hidden ownership model.
|
||||
Kry is C-close app code for Kryon. Source always lowers into KIR, a debuggable
|
||||
intermediate representation with source spans, resolved modules, state fields,
|
||||
functions, expressions, widget calls, and host/capability imports. Backends then
|
||||
consume KIR:
|
||||
|
||||
```text
|
||||
.kry -> KIR -> C
|
||||
.kry -> KIR -> KRB
|
||||
.kry -> KIR -> Go
|
||||
.kir -> C
|
||||
.kir -> KRB
|
||||
```
|
||||
|
||||
`k2c` emits readable `.c` and `.h` files for the normal C toolchain. `k2b`
|
||||
emits a portable `.krb` cartridge for renderers that implement the Kryon runtime
|
||||
contract. `k2g` emits Go source that drives a Go kryon runtime (the cgo
|
||||
surface binding — the same layer app uses), so Go-native apps can be written
|
||||
in .kry; it translates the declarative subset (state, app metadata, frames,
|
||||
widget calls), enums (untyped Go constants with C counter semantics),
|
||||
switch/case/default, C-style `for` headers, and `guard` (as a plain `if`;
|
||||
the body must return). `#extern "pkg.Fn"` declarations lower to a generated
|
||||
`<Guard>Host` interface plus `Set<Guard>Host`: every extern call in a frame
|
||||
becomes `host.Method(...)` on the embedding Go program, with numeric argument
|
||||
conversions so int/long/float widening always compiles. Unsupported
|
||||
imperative constructs (goto, raw C lines) still surface as TODO comments.
|
||||
`k2ir` exists for tooling, debugging, tests,
|
||||
and Krait inspection.
|
||||
Native C remains the direct path for platform, storage, and performance-sensitive
|
||||
code; portable cartridges call those services through explicit capabilities or
|
||||
host imports.
|
||||
|
||||
## Style
|
||||
|
||||
@@ -104,13 +131,39 @@ and control flow. There are no widget keywords and no bespoke sugar verbs:
|
||||
- plain function calls (any call used as a statement is a draw call and is
|
||||
automatically wrapped with source-inspection metadata for click-to-source).
|
||||
- `if`, `else if`, `else`, `while`, `for`, `switch`, `case`, `default`,
|
||||
labels, `goto`, `break`, `continue`, `guard`, and `return`.
|
||||
labels, `goto`, `break`, `continue`, `guard`, `defer`, and `return`.
|
||||
- `c line` for raw C glue and `unused expr` to silence unused-value warnings.
|
||||
|
||||
Widgets are ordinary library functions (WidgetText, WidgetRect, WidgetLine,
|
||||
WidgetBackground, WidgetButton) declared in `ui_widgets.h`; the compiler
|
||||
`defer STMT` schedules `STMT` to run when the enclosing block exits, replacing
|
||||
the cleanup-`goto` idiom:
|
||||
|
||||
```kry
|
||||
load_asset :: (path: const char*) -> Asset* {
|
||||
f := fopen(path, "rb")
|
||||
defer fclose(f)
|
||||
if f == nil {
|
||||
return nil # fclose runs here
|
||||
}
|
||||
...
|
||||
return parse(f) # fclose runs here too
|
||||
} # and here, on fall-through
|
||||
```
|
||||
|
||||
A deferred statement fires on scope exit however the block is left: by
|
||||
falling off the end, by `return`, or by `break`/`continue` that leaves the
|
||||
block. Multiple defers in one block run in reverse (last-registered-first)
|
||||
order, and defers in inner scopes run before those in outer scopes. A defer
|
||||
only fires if it was declared before the exit that triggers it.
|
||||
|
||||
`defer` is a compile-time transform: the statement is spliced into the
|
||||
generated C at every exit point of its scope, with no runtime cost. `goto`
|
||||
that jumps out of a deferred scope does not run the defer — use explicit
|
||||
cleanup labels if you mix the two.
|
||||
|
||||
Widgets are ordinary library functions (UIText, UIRect, Line,
|
||||
Background, UIButton) declared by Kryon; the compiler
|
||||
treats them exactly like any other call. Input handling is plain control
|
||||
flow: `if (UIKeyPressed(KEY_A)) { ... }`, `if (UIKeyDown(KEY_A)) { ... }`.
|
||||
flow: `if (IsKeyPressed(KEY_A)) { ... }`, `if (IsKeyDown(KEY_A)) { ... }`.
|
||||
Event-style blocks (`button ... {`, `on key ... {`, `event ... {`) and
|
||||
arithmetic/declaration sugar (`advance x by N`, `clamp_min`, `c_rect`,
|
||||
`texture`, `set_theme`) were removed in favor of their direct equivalents.
|
||||
@@ -0,0 +1,48 @@
|
||||
# Phase 01: KIR Source Of Truth
|
||||
|
||||
## Goal
|
||||
|
||||
Make KIR the canonical compiler representation between `.kry` source and every
|
||||
backend. No backend should parse `.kry` directly once this phase is complete.
|
||||
|
||||
## Current State
|
||||
|
||||
The native compiler path and the cartridge path are split. `k2c` owns the main
|
||||
`.kry -> C` behavior, while the new `k2b` path has its own parser and KRB
|
||||
emitter. This duplicates language understanding and lets the two outputs drift.
|
||||
|
||||
## Target Design
|
||||
|
||||
KIR represents the resolved program:
|
||||
|
||||
- modules, imports, app metadata, state fields, globals, functions, and exports
|
||||
- statements, expressions, widget calls, event handlers, and raw C edges
|
||||
- type names and storage/ABI attributes where Kry intentionally mirrors C
|
||||
- source file, line, and column spans for every load-bearing node
|
||||
- capability and host-import declarations used by portable cartridges
|
||||
|
||||
KIR should be readable enough for debugging and stable enough for tests, but it
|
||||
does not need to be optimized or clever.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Define private C structs for `KirProgram`, `KirModule`, `KirFunction`,
|
||||
`KirStmt`, `KirExpr`, `KirWidget`, `KirStateField`, and `KirImport`.
|
||||
2. Add ownership helpers that allocate, append, and free KIR trees explicitly.
|
||||
3. Add a deterministic text dump used by tests and Krait inspection.
|
||||
4. Add source-span storage to every node that can produce diagnostics or runtime
|
||||
inspector jumps.
|
||||
5. Keep KIR internal until `k2ir` has stable fixtures.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- A small `.kry` fixture can lower into KIR and dump deterministically.
|
||||
- Source spans survive through app, state, function, and widget nodes.
|
||||
- Existing `.kry` syntax tests still pass through the current compiler path
|
||||
while KIR is introduced.
|
||||
|
||||
## Risks
|
||||
|
||||
- Making KIR too abstract too early will slow migration.
|
||||
- Copying old text-emitter quirks into KIR will make the representation hard to
|
||||
use for portable logic later.
|
||||
@@ -0,0 +1,46 @@
|
||||
# Phase 02: Kry Frontend
|
||||
|
||||
## Goal
|
||||
|
||||
Replace line-oriented backend parsing with one frontend that parses `.kry`,
|
||||
resolves names, records diagnostics, and emits KIR.
|
||||
|
||||
## Current State
|
||||
|
||||
The compiler accepts substantial C-close syntax, module imports, app hooks,
|
||||
state blocks, globals, externs, and widget calls. Some of this is still
|
||||
recognized in emitter-shaped code instead of a shared frontend.
|
||||
|
||||
## Target Design
|
||||
|
||||
The frontend owns:
|
||||
|
||||
- lexical scanning, logical-line handling, and brace/paren/string tracking
|
||||
- module aliases and output basename metadata
|
||||
- state/app/function/global/extern declarations
|
||||
- statement classification and expression capture
|
||||
- source-aware widget call recognition
|
||||
- diagnostics that always include file, line, and column
|
||||
|
||||
Expressions may remain C-close text in the first frontend version, but they must
|
||||
be wrapped in KIR nodes with source spans and type hints where known.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Move parsing routines out of backend-specific files into a frontend module.
|
||||
2. Emit KIR from the parser instead of directly filling C-emitter structs.
|
||||
3. Port existing syntax diagnostics to the frontend.
|
||||
4. Resolve module aliases before backend emission.
|
||||
5. Add KIR fixture dumps for representative examples and failure cases.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- Existing `kc_syntax_test.sh` behavior remains unchanged.
|
||||
- KIR dumps cover app metadata, state, imports, functions, and widget calls.
|
||||
- Syntax errors are reported before either C or KRB backend runs.
|
||||
|
||||
## Risks
|
||||
|
||||
- Changing diagnostics too early may break current tests.
|
||||
- Treating expressions as opaque forever would block portable logic, so the
|
||||
frontend should preserve enough structure to refine them later.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Phase 03: k2ir Tool
|
||||
|
||||
## Goal
|
||||
|
||||
Add `k2ir`, a standalone `.kry -> .kir` tool for debugging, tests, Krait
|
||||
inspection, and backend handoff.
|
||||
|
||||
## Current State
|
||||
|
||||
There is no standalone KIR artifact. Tooling must infer compiler state from
|
||||
generated C, generated KRB, or ad hoc dumps.
|
||||
|
||||
## Target Design
|
||||
|
||||
`k2ir` reads one or more `.kry` files and writes deterministic `.kir` files:
|
||||
|
||||
```sh
|
||||
k2ir --root . -o build/kir app.kry modules/ui.kry
|
||||
```
|
||||
|
||||
The first `.kir` format should be text, line-oriented, source-mapped, and easy
|
||||
to diff. A binary or compact form can come later only after the structure is
|
||||
stable.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Add `cmd/k2ir/` using the shared frontend and KIR dump writer.
|
||||
2. Support `--root DIR`, `-o DIR`, and one or more `.kry` inputs.
|
||||
3. Write output paths matching source basenames under the output directory.
|
||||
4. Include source spans, symbols, state fields, functions, and imports.
|
||||
5. Add `make tools` integration once the tool is useful.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- `k2ir` emits deterministic output for examples.
|
||||
- Re-running `k2ir` on unchanged input produces byte-identical `.kir`.
|
||||
- Diagnostics match frontend errors and stop output for invalid files.
|
||||
|
||||
## Risks
|
||||
|
||||
- If `.kir` is over-specified before backend migration, every frontend change
|
||||
will churn fixtures.
|
||||
@@ -0,0 +1,44 @@
|
||||
# Phase 04: k2c Backend
|
||||
|
||||
## Goal
|
||||
|
||||
Make readable C generation consume KIR instead of parsing `.kry` directly.
|
||||
|
||||
## Current State
|
||||
|
||||
The native C path is the most complete path and must stay working. It also owns
|
||||
behavior that should move behind the KIR frontend.
|
||||
|
||||
## Target Design
|
||||
|
||||
`k2c` accepts either `.kry` or `.kir`:
|
||||
|
||||
```sh
|
||||
k2c --root . -o build/gen app.kry
|
||||
k2c --root . -o build/gen app.kir
|
||||
```
|
||||
|
||||
For `.kry`, `k2c` runs the frontend internally. For `.kir`, it loads the KIR
|
||||
artifact and emits the same C. Output stays simple, readable, and compatible
|
||||
with the existing C toolchain.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Split existing C emission into a KIR-to-C module.
|
||||
2. Keep generated symbol naming, headers, module prefixes, source inspection,
|
||||
and app hook behavior stable.
|
||||
3. Add `cmd/k2c/` with `.kry` and `.kir` input detection.
|
||||
4. Move the current `kc` command surface to call `k2c` internals or retire it
|
||||
after downstream build files are migrated.
|
||||
5. Remove duplicated frontend parsing from C emission.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- Existing syntax and generated-C tests pass.
|
||||
- `.kry -> C` and `.kry -> .kir -> C` produce equivalent output.
|
||||
- Downstream Krait builds still compile generated app hosts.
|
||||
|
||||
## Risks
|
||||
|
||||
- The current C backend is behaviorally important; migrate in thin slices and
|
||||
keep generated output diffs reviewable.
|
||||
@@ -0,0 +1,44 @@
|
||||
# Phase 05: k2b Backend
|
||||
|
||||
## Goal
|
||||
|
||||
Make KRB cartridge emission consume KIR instead of using a separate `.kry`
|
||||
parser.
|
||||
|
||||
## Current State
|
||||
|
||||
`cmd/k2b/` exists as a standalone experiment and can emit simple KRB files, but
|
||||
it duplicates parsing logic and still carries references to the old cartridge
|
||||
emission path.
|
||||
|
||||
## Target Design
|
||||
|
||||
`k2b` accepts either `.kry` or `.kir`:
|
||||
|
||||
```sh
|
||||
k2b --root . -o build/krb app.kry
|
||||
k2b --root . -o build/krb app.kir
|
||||
```
|
||||
|
||||
For `.kry`, it runs the shared frontend internally. For `.kir`, it writes KRB
|
||||
directly. KRB output uses KIR source spans for inspection and KIR event/function
|
||||
metadata for portable logic.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Remove the private k2b parser after KIR input is available.
|
||||
2. Port node, string, import, control, and state-field collection to KIR.
|
||||
3. Add source-map section planning without breaking current v1 readers.
|
||||
4. Update tests to call `k2b` directly, not old `k2c` flags.
|
||||
5. Keep raw `.krb` output deterministic for fixtures.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- Current KRB cartridge tests pass through `k2b`.
|
||||
- `.kry -> KRB` and `.kry -> .kir -> KRB` produce equivalent cartridges.
|
||||
- Krait can load cartridges emitted by the root Kryon `k2b`.
|
||||
|
||||
## Risks
|
||||
|
||||
- KRB currently represents only part of app behavior. Do not promise full
|
||||
portable execution until logic sections exist.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Phase 06: KRB Runtime
|
||||
|
||||
## Goal
|
||||
|
||||
Grow the KRB runtime from a render-first loader into a portable cartridge host.
|
||||
|
||||
## Current State
|
||||
|
||||
The runtime can load KRB bytes, read nodes/strings/imports/controls, mount C
|
||||
state fields, bind host functions, execute a tiny program, and draw through
|
||||
`KryBackend`.
|
||||
|
||||
## Target Design
|
||||
|
||||
The runtime should support:
|
||||
|
||||
- strict header and section validation
|
||||
- node rendering through backend-independent primitives
|
||||
- typed state schema and state reads/writes
|
||||
- source maps for inspector and diagnostics
|
||||
- event routing from nodes to logic functions or host imports
|
||||
- capability lookup and optional/required import reporting
|
||||
- asset lookup through runtime files or embedded cartridge assets
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Harden KRB validation around bounds, alignment, counts, and string offsets.
|
||||
2. Add section identifiers or versioned extension layout for new data.
|
||||
3. Add source-map section support.
|
||||
4. Add state schema section support independent of mounted C structs.
|
||||
5. Add event dispatch hooks that can call interpreted KIR logic first, then host
|
||||
imports when declared.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- Malformed cartridges fail with clear load errors.
|
||||
- Render-only v1 cartridges continue to draw.
|
||||
- Source maps can map a drawn node back to `.kry` file and line.
|
||||
- Missing required imports produce deterministic diagnostics.
|
||||
|
||||
## Risks
|
||||
|
||||
- Expanding the format without version discipline will make renderers fragile.
|
||||
@@ -0,0 +1,43 @@
|
||||
# Phase 07: Logic Execution
|
||||
|
||||
## Goal
|
||||
|
||||
Add portable logic to KRB without making native C the only source of behavior.
|
||||
|
||||
## Current State
|
||||
|
||||
KRB can draw a tree and call host imports, but arbitrary app logic still belongs
|
||||
to generated or host C.
|
||||
|
||||
## Target Design
|
||||
|
||||
Use interpreted KIR as the first portable logic path:
|
||||
|
||||
- event handlers point to KIR functions
|
||||
- KIR functions can read/write cartridge state
|
||||
- expressions, branches, locals, calls, and returns run in the runtime
|
||||
- source spans allow Krait to step and inspect execution
|
||||
- host capabilities are called through the import table
|
||||
|
||||
Bytecode or WASM can be added later after KIR semantics are proven.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Define the minimum executable KIR subset for UI event handlers.
|
||||
2. Implement a small interpreter over KIR function bodies.
|
||||
3. Add typed value storage for locals, arguments, and return values.
|
||||
4. Add state read/write operations.
|
||||
5. Add capability/import calls with strict signatures.
|
||||
6. Add Krait stepping hooks after the interpreter is stable.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- Button handlers can mutate cartridge state without generated C.
|
||||
- Simple arithmetic, branches, and function calls work in the interpreter.
|
||||
- Runtime errors report source locations.
|
||||
- Missing or mistyped imports fail before execution.
|
||||
|
||||
## Risks
|
||||
|
||||
- Interpreting opaque C expressions is impossible; the frontend must gradually
|
||||
structure expressions needed by portable logic.
|
||||
@@ -0,0 +1,46 @@
|
||||
# Phase 08: Capabilities And FFI
|
||||
|
||||
## Goal
|
||||
|
||||
Define how portable cartridges call platform services and app-specific native
|
||||
code without pretending arbitrary C is automatically portable.
|
||||
|
||||
## Current State
|
||||
|
||||
KRB has host import names and bind slots. It does not yet have a complete
|
||||
capability manifest, signatures, optional imports, or platform configuration.
|
||||
|
||||
## Target Design
|
||||
|
||||
KRB supports two import layers:
|
||||
|
||||
- standard capabilities, such as storage, files, HTTP, clipboard, dialogs,
|
||||
timers, audio, and notifications
|
||||
- app-specific host imports for native extensions controlled by the app shell
|
||||
|
||||
Imports are named, versioned, typed, and marked required or optional. Allowed
|
||||
boundary types are explicit: integers, floats, booleans, strings, bytes,
|
||||
handles, and records/arrays owned by KRB memory. Raw host pointers do not cross
|
||||
the portable boundary.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Define import signature encoding in KIR and KRB.
|
||||
2. Define required/optional import metadata and loader diagnostics.
|
||||
3. Add host registration APIs for capabilities and app imports.
|
||||
4. Add a small standard capability set, starting with logging, timers, storage,
|
||||
and simple files.
|
||||
5. Add platform config files that bind imports to native implementations.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- A cartridge requiring a missing capability fails clearly at load time.
|
||||
- Optional imports can be absent and queried by logic.
|
||||
- A native host can bind a test import and receive typed arguments.
|
||||
- The same cartridge can run against two different host implementations of the
|
||||
same capability.
|
||||
|
||||
## Risks
|
||||
|
||||
- Raw C ABI leakage would make KRB non-portable and unsafe.
|
||||
- Too broad a standard library too early will slow renderer implementations.
|
||||
@@ -0,0 +1,45 @@
|
||||
# Phase 09: Krait Integration
|
||||
|
||||
## Goal
|
||||
|
||||
Make Krait the primary developer surface for KIR inspection, KRB cartridge
|
||||
preview, portable diagnostics, and source-aware debugging.
|
||||
|
||||
## Current State
|
||||
|
||||
Krait can preview native app hosts and has a cartridge panel that currently
|
||||
shells out to the older KRB emission path. It can inspect nodes, strings,
|
||||
imports, and opcodes for loaded cartridges.
|
||||
|
||||
## Target Design
|
||||
|
||||
Krait should use root Kryon tooling:
|
||||
|
||||
- `k2ir` for compiler inspection and diagnostics
|
||||
- `k2b` for portable cartridge preview
|
||||
- `k2c` for native app-host preview
|
||||
- KRB runtime APIs for node/source-map inspection
|
||||
- interpreter hooks for stepping portable logic
|
||||
|
||||
Krait should not own KRB capture or rendering correctness. Kryon tooling owns
|
||||
preview rendering and PNG verification.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Replace Krait cartridge generation with `k2b`.
|
||||
2. Add a KIR panel that loads `.kir` or runs `k2ir` for the current source.
|
||||
3. Show KRB loader diagnostics, required imports, and capability availability.
|
||||
4. Use KRB source maps to jump from rendered nodes to `.kry` source.
|
||||
5. Add portable logic stepping once KRB runtime supports interpreted KIR.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- Krait can preview a KRB generated by root Kryon `k2b`.
|
||||
- Krait can show KIR for the current `.kry` file.
|
||||
- Missing imports are visible in the cartridge panel.
|
||||
- Source-click inspection works through KRB source maps.
|
||||
|
||||
## Risks
|
||||
|
||||
- Krait vendors Kryon, so source-of-truth changes must land in root Kryon first
|
||||
and then update the vendored submodule pointer.
|
||||
@@ -0,0 +1,48 @@
|
||||
# Phase 10: Migration And Validation
|
||||
|
||||
## Goal
|
||||
|
||||
Remove stale compiler assumptions, finish downstream migration, and validate the
|
||||
KIR-centered architecture end to end.
|
||||
|
||||
## Current State
|
||||
|
||||
Docs, tests, and Krait integration still contain old references to the direct
|
||||
compiler path and old cartridge emission flow.
|
||||
|
||||
## Target Design
|
||||
|
||||
The stable developer model is:
|
||||
|
||||
```text
|
||||
k2ir source.kry
|
||||
k2c source.kry|source.kir
|
||||
k2b source.kry|source.kir
|
||||
```
|
||||
|
||||
Kryon docs describe KIR as the source of truth, C as the native backend, and KRB
|
||||
as the portable cartridge backend. Downstream apps call current tools directly;
|
||||
there are no legacy wrappers or alias layers.
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
1. Update all Kryon tests to use `k2ir`, `k2c`, and `k2b`.
|
||||
2. Remove old cartridge flags and stale generated-host assumptions.
|
||||
3. Update examples and Makefiles to call the current tools.
|
||||
4. Update Krait's vendored Kryon pointer after root Kryon changes are committed.
|
||||
5. Add end-to-end checks for `.kry -> .kir -> C` and `.kry -> .kir -> KRB`.
|
||||
6. Audit docs and website text for stale compiler names and unsupported claims.
|
||||
|
||||
## Tests And Acceptance
|
||||
|
||||
- Full Kryon test suite passes.
|
||||
- Krait builds against the updated vendored Kryon.
|
||||
- `.kry -> C`, `.kry -> KRB`, `.kry -> .kir -> C`, and `.kry -> .kir -> KRB`
|
||||
are all covered by focused tests.
|
||||
- Documentation no longer points users at removed compiler paths.
|
||||
|
||||
## Risks
|
||||
|
||||
- Removing old entrypoints before downstream repositories are updated will break
|
||||
app builds. Follow the root-repository-first workflow and update vendors after
|
||||
root Kryon lands.
|
||||
@@ -0,0 +1,206 @@
|
||||
# Plan 11 — Renderer Engines for KRB Cartridges
|
||||
|
||||
Status: draft
|
||||
Depends on: 05-k2b, 06-krb-runtime
|
||||
|
||||
## Goal
|
||||
|
||||
A `.krb` cartridge must render and take input anywhere. That needs a family of
|
||||
**renderer engines** — one per platform family — behind the existing
|
||||
`KryBackend` vtable (`include/kry_backend.h`), plus a conformance suite that
|
||||
proves they all draw the same picture.
|
||||
|
||||
The KRB runtime (`src/krb/krb.c`) is already platform-agnostic C: it walks
|
||||
nodes, mounts state, and interprets `prog[]`. **Engines never touch cartridge
|
||||
internals** — they only implement the backend table. That boundary is the
|
||||
whole plan.
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
.krb cartridge
|
||||
|
|
||||
KrbLoad / KrbExec (portable C, no changes per platform)
|
||||
|
|
||||
KryBackend vtable (THE contract)
|
||||
+----------+-----------+------------------+
|
||||
| | | |
|
||||
raylib canvas kry_sw (software host-embedded
|
||||
engine engine rasterizer) (game engines, clay,
|
||||
(desktop) (web) - ESP32 framebuf test harness, null)
|
||||
| | - fallback
|
||||
OpenGL Canvas2D raw pixels
|
||||
```
|
||||
|
||||
Two tiers of engines:
|
||||
|
||||
- **Tier A — surface backends** (full `kryon_compat.generated.h` API, ~700
|
||||
symbols). Only worth it where an ecosystem exists: raylib today.
|
||||
- **Tier B — cartridge hosts** (implement `KryBackend` only, ~16 functions).
|
||||
This is where every new platform lands: web canvas, ESP32, SDL, LVGL,
|
||||
framebuffer, /dev/draw, embedded in another app.
|
||||
|
||||
Rule: **new platform = Tier B engine, never a fork of the runtime.**
|
||||
|
||||
## The contract (what we tighten first)
|
||||
|
||||
`KryBackend` today covers clear/rect/text/measure/clip/mouse/time/texture.
|
||||
Before writing engines, extend it once, carefully, so every engine can be
|
||||
written against a frozen target:
|
||||
|
||||
1. **Text**: add `font` handle + baked-glyph metrics (ascent/descent), not
|
||||
just `measure_text`. Engines that can't load fonts get a shared glyph
|
||||
atlas fed to them by the runtime (see phase 2).
|
||||
2. **Textures**: add `texture_free`, `texture_info` (w/h/format), and
|
||||
`texture_from_pixels` so the software rasterizer's output can be blitted
|
||||
by a GPU engine.
|
||||
3. **Redraw model**: add `present` and a dirty-rect hint. ESP32 and web both
|
||||
need "how much of the screen changed"; raylib ignores it.
|
||||
4. **Pixel format + capabilities query**: `kry_backend_caps` struct —
|
||||
target format (RGBA8 / RGB565), max texture size, has_gpu, memory budget.
|
||||
k2b already bakes theme-slot colors; cartridges get a **profile** field
|
||||
(see phase 6) that must match engine caps.
|
||||
|
||||
Everything else stays. The vtable version bumps once here, then freezes.
|
||||
|
||||
## Phases
|
||||
|
||||
### Phase 1 — Conformance harness (before any new engine)
|
||||
|
||||
You cannot have five engines without a golden-image test.
|
||||
|
||||
- `cmd/krb-run` (or extend `kryon-preview`): headless tool that loads a
|
||||
`.krb`, runs it against an engine for N frames with scripted input,
|
||||
dumps the framebuffer to PNG.
|
||||
- Golden tests: hash-compare per engine against committed reference PNGs
|
||||
(`tests/golden/*.png`). Tolerance only for antialiasing differences,
|
||||
and then only on text.
|
||||
- The **null backend grows into a recording backend**: it logs the vtable
|
||||
call stream (rect/text/clip sequences) and compares *call streams* between
|
||||
engines — catches logic divergence even where pixels differ.
|
||||
- Input injection via the existing `kry_input.c` Raw hooks, so the same
|
||||
script drives click/toggle/slider tests on every engine.
|
||||
|
||||
Deliverable: `make test-engines` that runs desktop raylib (offscreen) +
|
||||
null/Recording and fails on divergence.
|
||||
|
||||
### Phase 2 — `kry_sw`: the portable software rasterizer
|
||||
|
||||
The single most leveraged engine. Pure C, no libc beyond memcpy/malloc,
|
||||
renders into a caller-provided buffer:
|
||||
|
||||
- Targets: RGBA8 and **RGB565** (ESP32 panels), row-stride configurable.
|
||||
- Primitives: filled/outlined rects, rounded rects, lines, clip stack —
|
||||
everything KRB nodes emit today. No full 2D library; only what
|
||||
`draw_node` (krb.c:615) can ask for.
|
||||
- Text: **runtime-side glyph atlas**. k2b already owns fonts; extend the
|
||||
cartridge (or a sidecar section) with a pre-baked atlas: glyphs at one or
|
||||
two pixel densities, RGBA bitmap + metrics table. `kry_sw` blits glyphs;
|
||||
it never rasterizes outlines. This keeps the engine tiny and makes every
|
||||
other engine's font story trivial (atlas → texture).
|
||||
- Pictures: pre-decoded or DXT/raw in the cartridge; `kry_sw` does
|
||||
scaled blits only.
|
||||
- Dirty-rect tracking from day one (union of damaged regions per frame).
|
||||
|
||||
Where it lands: `src/backend/kry_sw.c`, exposed as both a `KryBackend`
|
||||
(Tier B) and optionally as blit-source for Tier A engines via
|
||||
`texture_from_pixels`.
|
||||
|
||||
Deliverable: Linux framebuffer host (`/dev/fb0`) as the proof — a real
|
||||
`krb-run --backend=fb` on the console.
|
||||
|
||||
### Phase 3 — Web engine (canvas)
|
||||
|
||||
`docs/BACKENDS.md` mentions a canvas backend that isn't really there.
|
||||
|
||||
- Tier B engine in the wasm module exporting the vtable; JavaScript shim
|
||||
(grow `web/kryon-web-present.js`) drives Canvas2D: rects via
|
||||
`fillRect`, text via `fillText` (fonts from the atlas or CSS), images
|
||||
via ImageBitmap.
|
||||
- Alternative under evaluation: compile `kry_sw` to wasm, render into
|
||||
`ImageData`, `putImageData` per dirty rect. Slower per-pixel but pixel-
|
||||
identical to native — start with this one for conformance parity, add
|
||||
the native-Canvas2D fast path second.
|
||||
- Build via existing `mk/web.mk`; cartridge fetched as a byte array,
|
||||
`KrbLoad` runs on the mmap-equivalent view (it's already a flat image,
|
||||
so a JS `ArrayBuffer` view works with a tiny loader shim).
|
||||
|
||||
Deliverable: `examples/` cartridge running in a browser, wired into the
|
||||
existing Netlify preview.
|
||||
|
||||
### Phase 4 — Android
|
||||
|
||||
- Keep the raylib NDK path for Tier A apps, but the cartridge story is
|
||||
Tier B: an `ANativeActivity` host app (~200 lines Java-free glue) that
|
||||
owns the window and calls a thin EGL engine — clear + `texture_from_pixels`
|
||||
blitting `kry_sw` output, or direct GLES rect/text draws if profiling
|
||||
demands it.
|
||||
- Input: map MotionEvent → `KryonBackendRaw_*` hooks (already shared via
|
||||
`kry_input.c`); text input via JNI IME callback.
|
||||
- Assets: cartridge + atlas in APK assets/, streamed into memory.
|
||||
|
||||
Deliverable: `mk/android.mk` builds a host APK that runs any example
|
||||
cartridge from assets.
|
||||
|
||||
### Phase 5 — ESP32 / embedded
|
||||
|
||||
The hardest and the best proof of the architecture.
|
||||
|
||||
- Engine = `kry_sw` with RGB565 target + a small SPI/panel flush function
|
||||
(dirty-rect DMA to the display). No GPU assumptions, no heap beyond a
|
||||
couple of framebuffers in PSRAM (or single-buffer + careful flush).
|
||||
- **Profiles** (phase 6) do the heavy lifting: the embedded cartridge is a
|
||||
separate k2b build — reduced node set, 16-bit colors baked at compile
|
||||
time, font atlas subsetted to used codepoints (k2b already walks the
|
||||
tree, so it knows the glyph set), no pictures above panel size.
|
||||
- Event loop: one frame on input or state change; deep-sleep-friendly.
|
||||
- Also validated on: nothing else. Embedded scope stays ESP32 + framebuffer
|
||||
until someone asks.
|
||||
|
||||
Deliverable: `examples/` breathing-timer-class cartridge on an ESP32-S3
|
||||
with an ILI9341-class panel, 30s of interaction on battery-reasonable
|
||||
behavior.
|
||||
|
||||
### Phase 6 — Profiles + asset pipeline (cross-cutting, lands with 3–5)
|
||||
|
||||
- **KRB profiles**: header flag (or k2b `--profile=embedded|web|desktop`)
|
||||
selecting color depth, atlas densities, max texture size, allowed node
|
||||
types. The loader checks engine caps (from the tightened vtable) and
|
||||
refuses mismatches loudly instead of garbling.
|
||||
- **Atlas/textures in the cartridge**: extend `KRB_FORMAT.md` with an assets
|
||||
section (or sidecar `.krb` + `.kra`) — pre-baked, pre-scaled, ready to
|
||||
blit. Engines never decode PNG/JPEG.
|
||||
- Version the vtable and the format together; both bump rarely.
|
||||
|
||||
### Phase 7 — Polish and long tail
|
||||
|
||||
- SDL2/SDL3 engine (Tier B, ~a day once `kry_sw` exists — good first
|
||||
contribution).
|
||||
- macOS/iOS via the same pattern as Android.
|
||||
- Plan 9 `/dev/draw` host — it's already named in BACKENDS.md; pure fun,
|
||||
low priority.
|
||||
- Documentation: BACKENDS.md gets one page per engine: build flags, caps,
|
||||
known divergences.
|
||||
|
||||
## Sequencing & rationale
|
||||
|
||||
1 → 2 → 3 in strict order: harness first (or engines can't be trusted),
|
||||
software rasterizer second (it *is* the web, embedded, and fallback engine),
|
||||
web third (cheapest visible win). 4 and 5 can proceed in either order once
|
||||
2 is solid; 6 items land incrementally alongside them.
|
||||
|
||||
The invariant across all of it: **`src/krb/krb.c` never grows an `#ifdef`**.
|
||||
Platform code lives in engines, engines live behind the vtable, and the
|
||||
conformance suite is the proof.
|
||||
|
||||
## Risks
|
||||
|
||||
- **Text quality divergence** between atlas-blitting engines (kry_sw, ESP32)
|
||||
and native-text engines (canvas `fillText`, raylib). Mitigation: prefer
|
||||
atlas-everywhere; native text is an opt-in fast path excluded from strict
|
||||
golden comparison.
|
||||
- **vtable churn** stranding engines. Mitigation: one breaking extension
|
||||
(phase 0 tightening), then additive-only with caps-gated entry points.
|
||||
- **ESP32 memory ceiling**: a node tree + atlas + framebuffer can exceed
|
||||
PSRAM on small modules. Mitigation: profiles + subsetted atlases; measure
|
||||
in phase 5 before promising panel sizes.
|
||||
+53
-19
@@ -11,28 +11,62 @@
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<header class="hero compact">
|
||||
<img class="hero-icon" src="icons/kryon.png" width="96" height="96" alt="Kryon">
|
||||
<h1>API</h1>
|
||||
<p class="tagline">Runtime and widget reference</p>
|
||||
</header>
|
||||
<header class="site-header">
|
||||
<div class="site-header-inner">
|
||||
<a class="brand" href="index.html">
|
||||
<img src="icons/kryon.png" alt="Kryon" width="22" height="22">
|
||||
<span>KRYON</span>
|
||||
</a>
|
||||
<nav class="header-nav" id="header-nav" aria-label="Primary">
|
||||
<a href="index.html#features">Features</a>
|
||||
<a href="index.html#why">Why</a>
|
||||
<a href="index.html#platforms">Platforms</a>
|
||||
<a href="index.html#start">Docs</a>
|
||||
<a href="api.html">API</a>
|
||||
<a class="is-external" href="https://krait.kryonlabs.com">Krait ↗</a>
|
||||
<a class="btn btn-primary" href="index.html#start">Get started</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav class="site-nav" aria-label="Primary">
|
||||
<a href="index.html">Home</a>
|
||||
<a href="index.html#features">Features</a>
|
||||
<a href="index.html#start">Start</a>
|
||||
<a href="api.html">API</a>
|
||||
</nav>
|
||||
|
||||
<main class="api-reference">
|
||||
<main class="wrap api-reference" style="padding: 32px 20px 60px;">
|
||||
<p class="section-eyebrow">Reference</p>
|
||||
<h1 style="margin-top: 0; font-size: 28px; border-bottom: 1px solid var(--line); padding-bottom: 10px;">API</h1>
|
||||
<p class="section-lead" style="margin-bottom: 28px;">Runtime and widget surface, rendered from the canonical <code>docs/API.md</code>.</p>
|
||||
{{ API_BODY }}
|
||||
</main>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="footer-inner">
|
||||
<div class="footer-brand">
|
||||
<img src="icons/kryon.png" alt="Kryon" width="20" height="20">
|
||||
<span>KRYON</span>
|
||||
</div>
|
||||
<div class="footer-cols">
|
||||
<div class="footer-col">
|
||||
<h4>Kryon</h4>
|
||||
<ul>
|
||||
<li><a href="index.html#features">Features</a></li>
|
||||
<li><a href="index.html#platforms">Platforms</a></li>
|
||||
<li><a href="api.html">API reference</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer-col">
|
||||
<h4>Ecosystem</h4>
|
||||
<ul>
|
||||
<li><a href="https://krait.kryonlabs.com">Krait IDE ↗</a></li>
|
||||
<li><a href="https://github.com/kryonlabs/kryon" target="_blank" rel="noopener">GitHub ↗</a></li>
|
||||
<li><a href="https://discord.gg/ep7gCWzHJD" target="_blank" rel="noopener">Discord ↗</a></li>
|
||||
<li><a href="https://t.me/kryonlabs_com" target="_blank" rel="noopener">Telegram ↗</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-bottom">
|
||||
<p>© 2026 Kryon Labs · <a href="https://waozi.xyz" target="_blank" rel="noopener">Made by Waozi</a></p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<footer>
|
||||
<p>© 2026 Kryon Labs | <a href="https://waozi.xyz" target="_blank" rel="noopener">Made by Waozi</a></p>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="highlight.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,90 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Kryon Web IDE</title>
|
||||
<meta name="description" content="Edit simple .kry files in the browser, compile with Kryon WASM tools, and preview the generated KRB cartridge.">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="icons/kryon.png">
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body class="ide-page">
|
||||
<header class="site-header">
|
||||
<div class="site-header-inner">
|
||||
<a class="brand" href="index.html">
|
||||
<img src="icons/kryon.png" alt="Kryon" width="22" height="22">
|
||||
<span>KRYON</span>
|
||||
</a>
|
||||
<nav class="header-nav" aria-label="Primary">
|
||||
<a href="index.html#features">Features</a>
|
||||
<a href="index.html#platforms">Platforms</a>
|
||||
<a href="api.html">API</a>
|
||||
<a class="btn btn-primary" href="ide.html">Web IDE</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="web-ide" data-kryon-web-ide>
|
||||
<section class="ide-shell">
|
||||
<div class="ide-toolbar">
|
||||
<div>
|
||||
<p class="section-eyebrow">Kryon Web IDE</p>
|
||||
<h1>Compile .kry in the browser</h1>
|
||||
</div>
|
||||
<div class="ide-actions">
|
||||
<button class="btn" type="button" data-action="load-sample">Sample</button>
|
||||
<button class="btn btn-primary" type="button" data-action="compile">Run</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ide-grid">
|
||||
<div class="ide-pane source-pane">
|
||||
<div class="pane-title">
|
||||
<span>app.kry</span>
|
||||
<span data-status>Loading compiler...</span>
|
||||
</div>
|
||||
<textarea spellcheck="false" data-source>#import "kryon.h"
|
||||
|
||||
app {
|
||||
title: "Kryon Web IDE"
|
||||
width: 800
|
||||
height: 520
|
||||
frame: App
|
||||
}
|
||||
|
||||
App :: () {
|
||||
Background((Color){249, 246, 235, 255})
|
||||
Rect(48, 42, 704, 390, (Color){255, 254, 249, 255})
|
||||
Text("Hello from .kry", 76, 86, UI_TEXT_24, (Color){31, 83, 102, 255})
|
||||
Text("This page runs k2ir and k2b as WebAssembly, then renders the KRB cartridge.", 76, 134, UI_TEXT_16, (Color){42, 59, 64, 255})
|
||||
Rect(76, 188, 292, 80, (Color){35, 101, 125, 255})
|
||||
Text("Portable preview", 104, 219, UI_TEXT_20, WHITE)
|
||||
Button((ButtonProps){.bounds = (Rectangle){76, 308, 184, 44}, .label = "Get started"})
|
||||
}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="ide-pane preview-pane">
|
||||
<div class="pane-title">
|
||||
<span>Live KRB Preview</span>
|
||||
<span data-preview-status>waiting</span>
|
||||
</div>
|
||||
<canvas width="800" height="520" data-preview></canvas>
|
||||
</div>
|
||||
|
||||
<div class="ide-pane artifact-pane">
|
||||
<div class="artifact-tabs" role="tablist" aria-label="Generated artifacts">
|
||||
<button type="button" class="is-active" data-tab="kir">kir</button>
|
||||
<button type="button" data-tab="krb">krb</button>
|
||||
<button type="button" data-tab="c">c</button>
|
||||
</div>
|
||||
<pre class="artifact-output"><code data-artifact></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<script src="ide-tools/k2ir.js"></script>
|
||||
<script src="ide-tools/k2b.js"></script>
|
||||
<script src="ide.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,310 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
var source = document.querySelector("[data-source]");
|
||||
var status = document.querySelector("[data-status]");
|
||||
var previewStatus = document.querySelector("[data-preview-status]");
|
||||
var canvas = document.querySelector("[data-preview]");
|
||||
var artifact = document.querySelector("[data-artifact]");
|
||||
var tabButtons = Array.prototype.slice.call(document.querySelectorAll("[data-tab]"));
|
||||
var compileButton = document.querySelector("[data-action='compile']");
|
||||
var sampleButton = document.querySelector("[data-action='load-sample']");
|
||||
var k2irMod = null;
|
||||
var k2bMod = null;
|
||||
var activeTab = "kir";
|
||||
var last = { kir: "", krb: "", c: "", bytes: null };
|
||||
var compileTimer = 0;
|
||||
|
||||
var sample = [
|
||||
"#import \"kryon.h\"",
|
||||
"",
|
||||
"app {",
|
||||
" title: \"Kryon Web IDE\"",
|
||||
" width: 800",
|
||||
" height: 520",
|
||||
" frame: App",
|
||||
"}",
|
||||
"",
|
||||
"App :: () {",
|
||||
" Background((Color){249, 246, 235, 255})",
|
||||
" Rect(48, 42, 704, 390, (Color){255, 254, 249, 255})",
|
||||
" Text(\"Hello from .kry\", 76, 86, UI_TEXT_24, (Color){31, 83, 102, 255})",
|
||||
" Text(\"This page runs k2ir and k2b as WebAssembly, then renders the KRB cartridge.\", 76, 134, UI_TEXT_16, (Color){42, 59, 64, 255})",
|
||||
" Rect(76, 188, 292, 80, (Color){35, 101, 125, 255})",
|
||||
" Text(\"Portable preview\", 104, 219, UI_TEXT_20, WHITE)",
|
||||
" Button((ButtonProps){.bounds = (Rectangle){76, 308, 184, 44}, .label = \"Get started\"})",
|
||||
"}"
|
||||
].join("\n");
|
||||
source.value = sample;
|
||||
|
||||
function setStatus(text) {
|
||||
if (status) status.textContent = text;
|
||||
}
|
||||
|
||||
function setPreviewStatus(text) {
|
||||
if (previewStatus) previewStatus.textContent = text;
|
||||
}
|
||||
|
||||
function ensureDir(mod, path) {
|
||||
var parts = path.split("/");
|
||||
var cur = "";
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
if (!parts[i]) continue;
|
||||
cur += "/" + parts[i];
|
||||
try {
|
||||
mod.FS.mkdir(cur);
|
||||
} catch (e) {
|
||||
if (!String(e).match(/File exists|ErrnoError/)) throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resetFs(mod) {
|
||||
["/work", "/work/src", "/work/out"].forEach(function(path) {
|
||||
try { mod.FS.rmdir(path); } catch (e) {}
|
||||
});
|
||||
ensureDir(mod, "/work/src");
|
||||
ensureDir(mod, "/work/out");
|
||||
}
|
||||
|
||||
function readMaybe(mod, path, binary) {
|
||||
try {
|
||||
return mod.FS.readFile(path, binary ? { encoding: "binary" } : { encoding: "utf8" });
|
||||
} catch (e) {
|
||||
return binary ? new Uint8Array(0) : "";
|
||||
}
|
||||
}
|
||||
|
||||
function readFirst(mod, paths, binary) {
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var value = readMaybe(mod, paths[i], binary);
|
||||
if (binary ? value.length > 0 : value !== "") return value;
|
||||
}
|
||||
return binary ? new Uint8Array(0) : "";
|
||||
}
|
||||
|
||||
function hex(bytes) {
|
||||
var out = [];
|
||||
for (var i = 0; i < bytes.length; i += 16) {
|
||||
var line = ("00000000" + i.toString(16)).slice(-8) + " ";
|
||||
for (var j = 0; j < 16; j++) {
|
||||
line += i + j < bytes.length ? ("0" + bytes[i + j].toString(16)).slice(-2) + " " : " ";
|
||||
}
|
||||
out.push(line);
|
||||
}
|
||||
return out.join("\n");
|
||||
}
|
||||
|
||||
function readU16(dv, off) {
|
||||
return dv.getUint16(off, true);
|
||||
}
|
||||
|
||||
function readI16(dv, off) {
|
||||
return dv.getInt16(off, true);
|
||||
}
|
||||
|
||||
function readU32(dv, off) {
|
||||
return dv.getUint32(off, true);
|
||||
}
|
||||
|
||||
function cstr(bytes, off, max) {
|
||||
var end = off;
|
||||
while (end < max && bytes[end] !== 0) end++;
|
||||
return new TextDecoder().decode(bytes.slice(off, end));
|
||||
}
|
||||
|
||||
function rgba(u32) {
|
||||
if ((u32 & 0x80000000) !== 0) {
|
||||
var slot = u32 & 0xff;
|
||||
if (slot === 1) return "rgb(42,59,64)";
|
||||
if (slot === 4) return "rgb(13,63,85)";
|
||||
return "rgb(247,244,236)";
|
||||
}
|
||||
return "rgba(" + (u32 & 255) + "," + ((u32 >> 8) & 255) + "," + ((u32 >> 16) & 255) + "," + (((u32 >> 24) & 255) / 255).toFixed(3) + ")";
|
||||
}
|
||||
|
||||
function decodeKrb(bytes) {
|
||||
if (!bytes || bytes.length < 32) throw new Error("KRB is empty");
|
||||
var dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||
if (readU32(dv, 0) !== 0x0042524b) throw new Error("KRB magic mismatch");
|
||||
var nodeCount = readU32(dv, 8);
|
||||
var stringBytes = readU32(dv, 12);
|
||||
var nodeOff = 32;
|
||||
var strOff = nodeOff + nodeCount * 28;
|
||||
var nodes = [];
|
||||
for (var i = 0; i < nodeCount; i++) {
|
||||
var off = nodeOff + i * 28;
|
||||
nodes.push({
|
||||
id: readU16(dv, off),
|
||||
parent: readI16(dv, off + 2),
|
||||
name: cstr(bytes, strOff + readU16(dv, off + 4), strOff + stringBytes),
|
||||
type: bytes[off + 6],
|
||||
flags: bytes[off + 7],
|
||||
bind: readU16(dv, off + 8),
|
||||
x: readI16(dv, off + 10),
|
||||
y: readI16(dv, off + 12),
|
||||
w: readI16(dv, off + 14),
|
||||
h: readI16(dv, off + 16),
|
||||
color: readU32(dv, off + 18),
|
||||
text: cstr(bytes, strOff + readU16(dv, off + 22), strOff + stringBytes),
|
||||
font: readU16(dv, off + 24) || 16,
|
||||
style: bytes[off + 26]
|
||||
});
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function coord(v, full, scaled) {
|
||||
return scaled ? Math.round(full * v / 10000) : v;
|
||||
}
|
||||
|
||||
function drawRound(ctx, x, y, w, h, r) {
|
||||
r = Math.max(0, Math.min(r, w / 2, h / 2));
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x + r, y);
|
||||
ctx.lineTo(x + w - r, y);
|
||||
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
|
||||
ctx.lineTo(x + w, y + h - r);
|
||||
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
|
||||
ctx.lineTo(x + r, y + h);
|
||||
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
|
||||
ctx.lineTo(x, y + r);
|
||||
ctx.quadraticCurveTo(x, y, x + r, y);
|
||||
ctx.closePath();
|
||||
}
|
||||
|
||||
function render(bytes) {
|
||||
var ctx = canvas.getContext("2d");
|
||||
var nodes = decodeKrb(bytes);
|
||||
var w = canvas.width;
|
||||
var h = canvas.height;
|
||||
ctx.clearRect(0, 0, w, h);
|
||||
ctx.fillStyle = "#f3f1ea";
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
nodes.forEach(function(n) {
|
||||
var x = coord(n.x, w, n.flags & 4);
|
||||
var y = coord(n.y, h, n.flags & 8);
|
||||
var nw = coord(n.w, w, n.flags & 16);
|
||||
var nh = coord(n.h, h, n.flags & 32);
|
||||
if (n.type === 1) {
|
||||
ctx.fillStyle = rgba(n.color);
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
} else if (n.type === 2) {
|
||||
ctx.fillStyle = rgba(n.color);
|
||||
ctx.font = "700 " + n.font + "px ui-monospace, Menlo, Consolas, monospace";
|
||||
ctx.fillText(n.text || n.name, x, y + n.font);
|
||||
} else if (n.type === 3) {
|
||||
ctx.fillStyle = rgba(n.color);
|
||||
ctx.fillRect(x, y, nw || 1, nh || 1);
|
||||
} else if (n.type === 4) {
|
||||
nw = nw || 160;
|
||||
nh = nh || 40;
|
||||
drawRound(ctx, x, y, nw, nh, 6);
|
||||
ctx.fillStyle = rgba(n.color);
|
||||
ctx.fill();
|
||||
ctx.strokeStyle = "#062536";
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#fff";
|
||||
ctx.font = "700 " + n.font + "px ui-monospace, Menlo, Consolas, monospace";
|
||||
ctx.fillText(n.text || n.name, x + 16, y + Math.round(nh / 2 + n.font / 3));
|
||||
} else if (n.type === 7 || n.type === 8 || n.type === 9) {
|
||||
ctx.strokeStyle = rgba(n.color);
|
||||
ctx.strokeRect(x, y, nw || 22, nh || 22);
|
||||
ctx.fillStyle = "#2a3b40";
|
||||
ctx.font = "700 " + n.font + "px ui-monospace, Menlo, Consolas, monospace";
|
||||
ctx.fillText(n.text || n.name, x + (nw || 28) + 8, y + n.font);
|
||||
}
|
||||
});
|
||||
setPreviewStatus(nodes.length + " nodes");
|
||||
}
|
||||
|
||||
function showArtifact() {
|
||||
artifact.textContent = last[activeTab] || "";
|
||||
}
|
||||
|
||||
function compile() {
|
||||
if (!k2irMod || !k2bMod) return;
|
||||
try {
|
||||
setStatus("compiling...");
|
||||
resetFs(k2irMod);
|
||||
k2irMod.FS.writeFile("/work/src/app.kry", source.value);
|
||||
k2irMod.callMain(["--root", "/work", "-o", "/work/out", "/work/src/app.kry"]);
|
||||
last.kir = readFirst(k2irMod, ["/work/out/app.kir", "/work/out/src/app.kir"], false);
|
||||
|
||||
resetFs(k2bMod);
|
||||
k2bMod.FS.writeFile("/work/src/app.kry", source.value);
|
||||
k2bMod.callMain(["--no-main", "--root", "/work", "-o", "/work/out", "/work/src/app.kry"]);
|
||||
last.bytes = readFirst(k2bMod, ["/work/out/app.krb", "/work/out/src/app.krb"], true);
|
||||
last.krb = "KRB bytes: " + last.bytes.length + "\n\n" + hex(last.bytes);
|
||||
last.c = readFirst(k2bMod, ["/work/out/app.krb.c", "/work/out/src/app.krb.c"], false);
|
||||
showArtifact();
|
||||
render(last.bytes);
|
||||
setStatus("compiled");
|
||||
} catch (e) {
|
||||
setStatus("error");
|
||||
setPreviewStatus("error");
|
||||
artifact.textContent = String(e && e.stack ? e.stack : e);
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleCompile() {
|
||||
window.clearTimeout(compileTimer);
|
||||
compileTimer = window.setTimeout(compile, 260);
|
||||
}
|
||||
|
||||
function loadInitialSource() {
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
var src = params.get("src");
|
||||
if (!src) {
|
||||
source.value = sample;
|
||||
return Promise.resolve();
|
||||
}
|
||||
setStatus("fetching source...");
|
||||
return fetch(src).then(function(res) {
|
||||
if (!res.ok) throw new Error("Could not fetch " + src + ": " + res.status);
|
||||
return res.text();
|
||||
}).then(function(text) {
|
||||
source.value = text;
|
||||
}).catch(function(err) {
|
||||
source.value = sample;
|
||||
artifact.textContent = String(err);
|
||||
});
|
||||
}
|
||||
|
||||
function boot() {
|
||||
if (typeof createK2irModule !== "function" || typeof createK2bModule !== "function") {
|
||||
setStatus("compiler unavailable");
|
||||
artifact.textContent = "The web compiler assets were not built.";
|
||||
return;
|
||||
}
|
||||
Promise.all([
|
||||
createK2irModule({ noInitialRun: true }),
|
||||
createK2bModule({ noInitialRun: true })
|
||||
]).then(function(mods) {
|
||||
k2irMod = mods[0];
|
||||
k2bMod = mods[1];
|
||||
return loadInitialSource();
|
||||
}).then(function() {
|
||||
setStatus("ready");
|
||||
compile();
|
||||
}).catch(function(err) {
|
||||
setStatus("error");
|
||||
artifact.textContent = String(err && err.stack ? err.stack : err);
|
||||
});
|
||||
}
|
||||
|
||||
tabButtons.forEach(function(btn) {
|
||||
btn.addEventListener("click", function() {
|
||||
activeTab = btn.getAttribute("data-tab");
|
||||
tabButtons.forEach(function(b) { b.classList.toggle("is-active", b === btn); });
|
||||
showArtifact();
|
||||
});
|
||||
});
|
||||
source.addEventListener("input", scheduleCompile);
|
||||
compileButton.addEventListener("click", compile);
|
||||
sampleButton.addEventListener("click", function() {
|
||||
source.value = sample;
|
||||
compile();
|
||||
});
|
||||
boot();
|
||||
})();
|
||||
+448
-143
@@ -3,178 +3,483 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Kryon - Native Cross-Platform App and Game Development</title>
|
||||
<meta name="description" content="Native cross-platform app and game development with .kry, human-readable C99 output, a full native widget toolkit, and an interactive AI-native IDE.">
|
||||
<title>Kryon — a UI runtime that's alive</title>
|
||||
<meta name="description" content="Kryon is a native declarative UI and app runtime. Write .kry, lower to debuggable KIR, and ship readable C99 or portable KRB cartridges.">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="https://kryonlabs.com/">
|
||||
<meta property="og:title" content="Kryon - Native Cross-Platform App and Game Development">
|
||||
<meta property="og:description" content="Native cross-platform app and game development with .kry, human-readable C99 output, a full native widget toolkit, and an interactive AI-native IDE.">
|
||||
<meta property="og:title" content="Kryon — a UI runtime that's alive">
|
||||
<meta property="og:description" content="Native declarative UI and app runtime. Write .kry, inspect KIR, ship C99 or portable KRB cartridges.">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:url" content="https://kryonlabs.com/">
|
||||
<meta name="twitter:title" content="Kryon - Native Cross-Platform App and Game Development">
|
||||
<meta name="twitter:description" content="Native cross-platform app and game development in .kry with readable C99 output.">
|
||||
<meta name="twitter:title" content="Kryon — a UI runtime that's alive">
|
||||
<meta name="twitter:description" content="Native declarative UI and app runtime. Write .kry, inspect KIR, ship C99 or KRB.">
|
||||
<meta name="twitter:site" content="@kryonlabs">
|
||||
<meta name="twitter:creator" content="@kryonlabs">
|
||||
<meta name="theme-color" content="#f3f1ea">
|
||||
<meta name="keywords" content="Kryon,declarative UI,native UI,C99,Flutter alternative,Godot alternative,Electron alternative,.kry,raylib-style,Krait,cross-platform,UI runtime,app runtime">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="icons/kryon.png">
|
||||
<link rel="apple-touch-icon" href="icons/kryon.png">
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "SoftwareApplication",
|
||||
"name": "Kryon",
|
||||
"description": "Native declarative UI and app runtime. Write .kry, inspect KIR, ship readable C99 or portable KRB cartridges.",
|
||||
"url": "https://kryonlabs.com",
|
||||
"applicationCategory": "DeveloperApplication",
|
||||
"operatingSystem": "Linux, Windows, macOS, Android, Browser, FreeBSD",
|
||||
"offers": {"@type": "Offer", "price": "0", "priceCurrency": "USD"},
|
||||
"author": {"@type": "Organization", "name": "Kryon Labs", "url": "https://kryonlabs.com"}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<header class="hero">
|
||||
<img class="hero-icon" src="icons/kryon.png" width="128" height="128" alt="Kryon">
|
||||
<h1>KRYON</h1>
|
||||
<p class="tagline">Native cross-platform app and game development</p>
|
||||
<p class="tagline-detail">Write .kry • Translate to readable C99 • Build visually with an AI-native IDE</p>
|
||||
</header>
|
||||
<header class="site-header">
|
||||
<div class="site-header-inner">
|
||||
<a class="brand" href="#top">
|
||||
<img src="icons/kryon.png" alt="Kryon" width="22" height="22">
|
||||
<span>KRYON</span>
|
||||
</a>
|
||||
<button class="menu-toggle" type="button" aria-label="Open site menu" aria-expanded="false" aria-controls="header-nav">Menu</button>
|
||||
<nav class="header-nav" id="header-nav" aria-label="Primary">
|
||||
<a href="#features">Features</a>
|
||||
<a href="#why">Why</a>
|
||||
<a href="#apps">Showcase</a>
|
||||
<a href="#platforms">Platforms</a>
|
||||
<a href="#start">Docs</a>
|
||||
<a href="/api">API</a>
|
||||
<a href="ide.html">Web IDE</a>
|
||||
<a class="is-external" href="https://krait.kryonlabs.com">Krait ↗</a>
|
||||
<a class="star-pill" href="https://github.com/kryonlabs/kryon" target="_blank" rel="noopener">★ <span class="count">GitHub</span></a>
|
||||
<a class="btn btn-primary" href="#start">Get started</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav class="site-nav" aria-label="Primary">
|
||||
<a href="#about">About</a>
|
||||
<a href="#goals">Goals</a>
|
||||
<a href="#features">Features</a>
|
||||
<a href="#philosophy">Philosophy</a>
|
||||
<a href="#platforms">Platforms</a>
|
||||
<a href="#start">Start</a>
|
||||
<a href="api.html">API</a>
|
||||
</nav>
|
||||
|
||||
<main>
|
||||
<section id="about">
|
||||
<h2>What is Kryon?</h2>
|
||||
<p>Kryon is a native app and game development stack built around .kry source files, a small runtime, and clean translation to human-readable C99.</p>
|
||||
<p>The Kryon IDE is built around the same source model: open a project or file path, edit .kry directly, see a live preview, and click a widget to jump back to the source line that generated it.</p>
|
||||
</section>
|
||||
|
||||
<section id="goals">
|
||||
<h2>Goals</h2>
|
||||
<div class="goal-list">
|
||||
<article class="goal">
|
||||
<h3>Native Cross-Platform</h3>
|
||||
<p>One source model for desktop, mobile, browser, and embedded targets, with platform behavior exposed as first-class Kryon features.</p>
|
||||
</article>
|
||||
<article class="goal">
|
||||
<h3>Readable C99</h3>
|
||||
<p>.kry translates to plain, inspectable C99 that can be built, debugged, and shipped by normal C toolchains.</p>
|
||||
</article>
|
||||
<article class="goal">
|
||||
<h3>Full Native UI</h3>
|
||||
<p>The widget toolkit should cover real product interfaces: layout, text, inputs, navigation, overlays, inspection, themes, and runtime assets.</p>
|
||||
</article>
|
||||
<article class="goal">
|
||||
<h3>AI-Native IDE</h3>
|
||||
<p>The IDE should make visual app and game development direct: live preview, source-aware inspection, diagnostics, and agent-assisted edits in one loop.</p>
|
||||
</article>
|
||||
<main id="top">
|
||||
<section class="hero">
|
||||
<div class="hero-inner">
|
||||
<span class="hero-eyebrow"><span class="dot"></span>Native declarative UI · KIR · C99 · KRB</span>
|
||||
<img class="hero-icon" src="icons/kryon.png" width="84" height="84" alt="Kryon">
|
||||
<h1>A UI runtime that's <span class="accent">alive</span>.</h1>
|
||||
<p class="hero-sub">One source model for desktop, mobile, browser, and embedded. Write <code>.kry</code>, lower to debuggable KIR, then ship readable C99 or portable KRB cartridges for Kryon renderers.</p>
|
||||
<div class="hero-cta">
|
||||
<a class="btn btn-primary" href="#start">Get started</a>
|
||||
<a class="btn" href="ide.html">Open Web IDE</a>
|
||||
<a class="btn" href="https://krait.kryonlabs.com">Try in Krait →</a>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section id="features">
|
||||
<h2>Core Features</h2>
|
||||
<div class="grid">
|
||||
<article class="feature">
|
||||
<img src="icons/text.png" width="48" height="48" alt="">
|
||||
<h3>Widget-Focused .kry</h3>
|
||||
<p>Pages and reusable widgets stay in concise source files with explicit typed variables and direct compiler errors for unknown syntax.</p>
|
||||
</article>
|
||||
<article class="feature">
|
||||
<img src="icons/c.png" width="48" height="48" alt="">
|
||||
<h3>Clean C Output</h3>
|
||||
<p>The compiler emits normal C and generated headers. Kry-to-Kry calls use compile-time modules, while C interop stays explicit.</p>
|
||||
</article>
|
||||
<article class="feature">
|
||||
<img src="icons/globe.png" width="48" height="48" alt="">
|
||||
<h3>Live Preview</h3>
|
||||
<p>Hot reload rebuilds real .kry output, keeps the last good state during compilation, and shows diagnostics when the build fails.</p>
|
||||
</article>
|
||||
<article class="feature">
|
||||
<img src="icons/wrench.png" width="48" height="48" alt="">
|
||||
<h3>Source-Aware Inspection</h3>
|
||||
<p>Preview widgets carry source metadata, so inspection clicks select the generated UI element and open the exact .kry line.</p>
|
||||
</article>
|
||||
<div class="hero-panel" aria-hidden="true">
|
||||
<div class="hero-panel-bar">
|
||||
<span class="tl"></span><span class="tl"></span><span class="tl"></span>
|
||||
<span class="title">app.kry — KIR — C/KRB</span>
|
||||
</div>
|
||||
</section>
|
||||
<section id="philosophy">
|
||||
<h2>Philosophy</h2>
|
||||
<ul class="philosophy-list">
|
||||
<li><strong>Everything visible is a widget</strong> - source, bounds, state, and inspection all belong to the widget tree.</li>
|
||||
<li><strong>Source stays primary</strong> - .kry files own screens and reusable UI pieces; C is the generated interop target.</li>
|
||||
<li><strong>The IDE is source-aware</strong> - file browser, source editor, live preview, inspector, diagnostics, and search stay tied to .kry files.</li>
|
||||
<li><strong>Default private API</strong> - only exported functions enter generated headers, keeping build boundaries small.</li>
|
||||
<li><strong>Native first</strong> - direct C, raylib-style calls, and predictable runtime behavior across targets.</li>
|
||||
</ul>
|
||||
</section>
|
||||
<div class="hero-panel-body">
|
||||
<div class="pane">
|
||||
<div class="pane-label">app.kry</div>
|
||||
<pre><code>#import "kryon.h"
|
||||
|
||||
<section id="platforms">
|
||||
<h2>Platforms</h2>
|
||||
<p>Kryon targets the same interface source at the environments apps actually ship to.</p>
|
||||
<div class="platform-grid">
|
||||
<article class="platform">
|
||||
<img src="platforms/tux.png" width="32" height="32" alt="">
|
||||
<h3>Linux</h3>
|
||||
<p>Native desktop builds.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/win.png" width="32" height="32" alt="">
|
||||
<h3>Windows</h3>
|
||||
<p>Native desktop and WinINet assets.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/macos.png" width="32" height="32" alt="">
|
||||
<h3>macOS</h3>
|
||||
<p>Native desktop builds.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/droid.png" width="32" height="32" alt="">
|
||||
<h3>Android</h3>
|
||||
<p>Mobile runtime support.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="language/wasm.png" width="32" height="32" alt="">
|
||||
<h3>Browser</h3>
|
||||
<p>WebAssembly runtime and previews.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/freebsd.png" width="32" height="32" alt="">
|
||||
<h3>FreeBSD</h3>
|
||||
<p>Native desktop and embedded targets.</p>
|
||||
</article>
|
||||
AppHome :: (app: InbeApp*) {
|
||||
y: int = ScaleUIPx(24)
|
||||
Text("Inner Breeze", ScaleUIPx(20), y, UI_TEXT_24)
|
||||
BottomNav(app->bottom_nav)
|
||||
}</code></pre>
|
||||
</div>
|
||||
<div class="pane">
|
||||
<div class="pane-label">portable pipeline</div>
|
||||
<pre><code>k2ir app.kry
|
||||
k2c app.kir # native C
|
||||
k2b app.kir # portable cartridge
|
||||
krait app.krb # inspect and render</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="start">
|
||||
<h2>Get Started</h2>
|
||||
<p>Build the runtime and tools:</p>
|
||||
<pre><code>git clone https://github.com/kryonlabs/kryon.git
|
||||
<section class="replaces">
|
||||
<div class="label">A full replacement for</div>
|
||||
<div class="pills">
|
||||
<span class="pill"><span class="x">×</span> Flutter</span>
|
||||
<span class="pill"><span class="x">×</span> Godot UI</span>
|
||||
<span class="pill"><span class="x">×</span> Electron</span>
|
||||
<span class="pill"><span class="x">×</span> agent harnesses</span>
|
||||
<span class="pill"><span class="x">×</span> heavy web frameworks</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="features">
|
||||
<p class="section-eyebrow">Features</p>
|
||||
<h2>One source, every platform</h2>
|
||||
<p class="section-lead">The runtime owns the whole UI lifecycle: build the widget tree, reconcile state, layout nodes, route input, render, and draw overlays. You describe intent; Kryon handles ordering, focus, inspection, and overlay behavior.</p>
|
||||
|
||||
<div class="tabs" data-tabs>
|
||||
<div class="tablist" role="tablist" aria-label="Kryon feature showcase">
|
||||
<button type="button" role="tab" id="tab-1" aria-selected="true" aria-controls="tp-1">Declarative .kry</button>
|
||||
<button type="button" role="tab" id="tab-2" aria-selected="false" aria-controls="tp-2" tabindex="-1">KIR pipeline</button>
|
||||
<button type="button" role="tab" id="tab-3" aria-selected="false" aria-controls="tp-3" tabindex="-1">Live preview</button>
|
||||
<button type="button" role="tab" id="tab-4" aria-selected="false" aria-controls="tp-4" tabindex="-1">Source-aware</button>
|
||||
</div>
|
||||
|
||||
<div class="tabpanel is-active" id="tp-1" role="tabpanel" aria-labelledby="tab-1">
|
||||
<h3>Declarative .kry source</h3>
|
||||
<p>Pages and reusable widgets stay in concise source files with explicit typed variables, node declarations, and direct compiler errors for unknown syntax.</p>
|
||||
<pre><code>#import "kryon.h"
|
||||
|
||||
Counter :: (state: *CounterState) {
|
||||
col {
|
||||
Text("Count: " + to_string(state->n))
|
||||
Button("Increment") {
|
||||
state->n += 1
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="tabpanel" id="tp-2" role="tabpanel" aria-labelledby="tab-2" hidden>
|
||||
<h3>One KIR, two outputs</h3>
|
||||
<p>The frontend resolves <code>.kry</code> into KIR once. <code>k2c</code> emits readable C for native apps; <code>k2b</code> emits portable KRB cartridges for renderers.</p>
|
||||
<pre><code>k2ir counter.kry
|
||||
k2c counter.kir
|
||||
k2b counter.kir</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="tabpanel" id="tp-3" role="tabpanel" aria-labelledby="tab-3" hidden>
|
||||
<h3>Live preview in Krait</h3>
|
||||
<p>Edit a <code>.kry</code> file and see the running app update inside the IDE. Krait compiles to an app host, loads it into the embedded viewport, and keeps preview state across reloads.</p>
|
||||
<pre><code># edit app.kry, save, watch it reload
|
||||
$ krait --dev run my-app</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="tabpanel" id="tp-4" role="tabpanel" aria-labelledby="tab-4" hidden>
|
||||
<h3>Source-aware inspection</h3>
|
||||
<p>Preview widgets carry source metadata, so an inspection click selects the generated UI element and opens the exact <code>.kry</code> line. The tree <em>is</em> the inspector.</p>
|
||||
<pre><code>// click a node in preview → jump to source
|
||||
AppHome: app.kry:7
|
||||
Text("Inner Breeze") app.kry:9
|
||||
BottomNav(...) app.kry:10</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="why">
|
||||
<p class="section-eyebrow">Why Kryon</p>
|
||||
<h2>Native first, alive by default</h2>
|
||||
<p class="section-lead">Everything visible is a node. Source stays primary. KIR keeps the compiler debuggable, C keeps native integration direct, and KRB opens a portable renderer path.</p>
|
||||
<div class="why-grid">
|
||||
<article class="why-card">
|
||||
<h3>Alive by default</h3>
|
||||
<p>Live preview, hot reload, and source-aware inspection are part of the runtime — not a bolted-on dev server.</p>
|
||||
</article>
|
||||
<article class="why-card">
|
||||
<h3>Everything is a node</h3>
|
||||
<p>Source, bounds, state, focus, and inspection all belong to the widget tree. One model for the whole UI.</p>
|
||||
</article>
|
||||
<article class="why-card">
|
||||
<h3>Source stays primary</h3>
|
||||
<p><code>.kry</code> files own screens and reusable UI pieces. KIR is the source-mapped compiler truth; C and KRB are outputs.</p>
|
||||
</article>
|
||||
<article class="why-card">
|
||||
<h3>Small native surface</h3>
|
||||
<p>Only exported functions enter generated headers, so build boundaries stay tiny and dependency-free.</p>
|
||||
</article>
|
||||
<article class="why-card">
|
||||
<h3>Predictable runtime</h3>
|
||||
<p>Direct C where native integration matters, portable KRB where renderer portability matters, and explicit imports between them.</p>
|
||||
</article>
|
||||
<article class="why-card">
|
||||
<h3>Real product UI</h3>
|
||||
<p>Layout, text, inputs, navigation, overlays, inspection, themes, and runtime assets — covered out of the box.</p>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="showcase">
|
||||
<p class="section-eyebrow">Compiler Pipeline</p>
|
||||
<h2>One frontend, native and portable backends</h2>
|
||||
<p class="section-lead">Kryon lowers <code>.kry</code> into debuggable KIR, then emits readable C for native applications or compact KRB cartridges for portable renderers.</p>
|
||||
<div class="showcase">
|
||||
<div class="col">
|
||||
<div class="col-head"><span>app.kry</span><span class="badge">source</span></div>
|
||||
<pre><code>#import "kryon.h"
|
||||
|
||||
Greeting :: (name: string) {
|
||||
row {
|
||||
Icon(ICON_ROCKET)
|
||||
Text("Hello, " + name)
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div class="col-head"><span>outputs</span><span class="badge">C / KRB</span></div>
|
||||
<pre><code>Greeting.kir
|
||||
source spans
|
||||
widget tree
|
||||
event logic
|
||||
imports
|
||||
|
||||
Greeting.c # native backend
|
||||
Greeting.krb # portable cartridge</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="apps">
|
||||
<p class="section-eyebrow">Showcase</p>
|
||||
<h2>Inner Breeze is a real app target</h2>
|
||||
<p class="section-lead">Inner Breeze is where Kryon is exercised as an application stack: calm practice flows, native packaging, web delivery, local-first history, and a UI large enough to keep the toolchain honest.</p>
|
||||
<div class="app-showcase">
|
||||
<div class="app-showcase-copy">
|
||||
<span class="app-kicker">Breathing, meditation, habits</span>
|
||||
<h3>Built to prove the workflow beyond demos</h3>
|
||||
<p>Use the live project as a reference point for Kryon and Krait work: app screens, generated C, platform packages, browser builds, and product polish all meet in one codebase.</p>
|
||||
<div class="app-actions">
|
||||
<a class="btn btn-primary" href="https://inbe.waozi.xyz" target="_blank" rel="noopener">Open Inner Breeze</a>
|
||||
<a class="btn" href="https://github.com/waozixyz/inbe" target="_blank" rel="noopener">View source</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="app-showcase-preview" aria-label="Inner Breeze app preview">
|
||||
<div class="phone-shell">
|
||||
<div class="phone-top"></div>
|
||||
<div class="phone-screen">
|
||||
<div class="breath-ring">
|
||||
<span></span>
|
||||
</div>
|
||||
<div class="breath-copy">
|
||||
<strong>Inner Breeze</strong>
|
||||
<span>guided breathing</span>
|
||||
</div>
|
||||
<div class="session-list">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="platforms">
|
||||
<p class="section-eyebrow">Platforms</p>
|
||||
<h2>One source, the targets apps ship to</h2>
|
||||
<p class="section-lead">The same interface source builds for the environments real apps ship to — no platform-specific forks of your UI code.</p>
|
||||
<div class="platform-grid">
|
||||
<article class="platform">
|
||||
<img src="platforms/droid.png" width="32" height="32" alt="">
|
||||
<h3>Android</h3>
|
||||
<p>Mobile runtime and KRB host capabilities.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/ios.png" width="32" height="32" alt="">
|
||||
<h3>iOS</h3>
|
||||
<p>Mobile renderer through the portable runtime contract.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/esp32.png" width="32" height="32" alt="">
|
||||
<h3>ESP32</h3>
|
||||
<p>Small KRB renderers with constrained capability sets.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/microcontroller.png" width="32" height="32" alt="">
|
||||
<h3>Microcontrollers</h3>
|
||||
<p>Embedded targets for draw primitives, input, timers, and storage.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/tux.png" width="32" height="32" alt="">
|
||||
<h3>Linux</h3>
|
||||
<p>Native C builds and KRB renderers.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/win.png" width="32" height="32" alt="">
|
||||
<h3>Windows</h3>
|
||||
<p>Native C builds and KRB renderers.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/macos.png" width="32" height="32" alt="">
|
||||
<h3>macOS</h3>
|
||||
<p>Native C builds and KRB renderers.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/freebsd.png" width="32" height="32" alt="">
|
||||
<h3>FreeBSD</h3>
|
||||
<p>Native desktop, servers, and embedded targets.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/plan9.png" width="32" height="32" alt="">
|
||||
<h3>Plan 9</h3>
|
||||
<p>Portable runtime target with a small native host layer.</p>
|
||||
</article>
|
||||
<article class="platform">
|
||||
<img src="platforms/browser.png" width="32" height="32" alt="">
|
||||
<h3>Browser</h3>
|
||||
<p>Browser renderer, WASM logic, and KRB preview.</p>
|
||||
</article>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="callout">
|
||||
<div class="callout-inner">
|
||||
<p class="section-eyebrow">Krait</p>
|
||||
<h2>Build it in Krait</h2>
|
||||
<p>Krait is the standalone first-party Kryon IDE — source editing, KIR inspection, KRB cartridge preview, live native preview, and diagnostics in one loop. It's written in <code>.kry</code>, so the IDE is its own research path.</p>
|
||||
<a class="btn btn-primary" href="https://krait.kryonlabs.com">Visit krait.kryonlabs.com →</a>
|
||||
<a class="btn" href="ide.html">Open Web IDE →</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="start">
|
||||
<p class="section-eyebrow">Get started</p>
|
||||
<h2>Build the runtime and tools</h2>
|
||||
<p class="section-lead">Kryon is free and open source. Clone, build, and install in a few commands.</p>
|
||||
<p>Build the runtime:</p>
|
||||
<pre><code>git clone https://github.com/kryonlabs/kryon.git
|
||||
cd kryon
|
||||
make
|
||||
make install</code></pre>
|
||||
<p>A simple .kry shape:</p>
|
||||
<pre><code>#import "kryon.h"
|
||||
<p>The clean compiler tool direction:</p>
|
||||
<pre><code>k2ir app.kry
|
||||
k2c app.kry # or app.kir
|
||||
k2b app.kry # or app.kir</code></pre>
|
||||
<p>A simple <code>.kry</code> shape:</p>
|
||||
<pre><code>#import "kryon.h"
|
||||
|
||||
AppHome :: (app: InbeApp*) {
|
||||
y: int = ScaleUIPx(24)
|
||||
|
||||
WidgetText("Inner Breeze", ScaleUIPx(20), y, UI_TEXT_24, GetThemeText())
|
||||
app_draw_bottom_nav(app)
|
||||
Text("Inner Breeze", ScaleUIPx(20), y, UI_TEXT_24)
|
||||
BottomNav(app->bottom_nav)
|
||||
}</code></pre>
|
||||
<p>Open a project or a single .kry file in the IDE:</p>
|
||||
<pre><code>kryon .
|
||||
kryon path/to/app.kry</code></pre>
|
||||
</section>
|
||||
<p>Open a project in Krait:</p>
|
||||
<pre><code>git clone https://github.com/kryonlabs/krait.git
|
||||
cd krait
|
||||
gmake run ARGS=/path/to/project</code></pre>
|
||||
|
||||
<section id="docs">
|
||||
<h2>Documentation</h2>
|
||||
<ul class="link-list">
|
||||
<li><a href="api.html">API reference</a> - runtime and widget surface</li>
|
||||
<li><a href="https://github.com/kryonlabs/kryon" target="_blank" rel="noopener">Source repository</a> - code, issues, and releases</li>
|
||||
</ul>
|
||||
</section>
|
||||
</main>
|
||||
<h2 id="docs" style="margin-top: 40px;">Documentation</h2>
|
||||
<ul class="link-list">
|
||||
<li><strong><a href="/api">API reference</a></strong> — runtime, node, and widget surface</li>
|
||||
<li><strong><a href="https://github.com/kryonlabs/kryon" target="_blank" rel="noopener">Source repository</a></strong> — code, issues, and releases</li>
|
||||
<li><strong><a href="https://github.com/kryonlabs/krait" target="_blank" rel="noopener">Krait repository</a></strong> — first-party IDE</li>
|
||||
<li><strong><a href="https://discord.gg/ep7gCWzHJD" target="_blank" rel="noopener">Discord</a></strong> — chat, help, and showcase</li>
|
||||
<li><strong><a href="https://t.me/kryonlabs_com" target="_blank" rel="noopener">Telegram</a></strong> — news and announcements</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section id="faq">
|
||||
<p class="section-eyebrow">FAQ</p>
|
||||
<h2>Questions</h2>
|
||||
<div class="faq">
|
||||
<details class="faq-item">
|
||||
<summary>What is Kryon? <span class="chev">›</span></summary>
|
||||
<div class="faq-a"><p>Kryon is a native app development stack built around <code>.kry</code> source files, debuggable KIR, readable C output, portable KRB cartridges, and a small runtime. You write intent; the runtime handles the UI lifecycle.</p></div>
|
||||
</details>
|
||||
<details class="faq-item">
|
||||
<summary>How is Kryon different from Flutter? <span class="chev">›</span></summary>
|
||||
<div class="faq-a"><p>Flutter ships a Dart VM and its own rendering layer. Kryon keeps native C as a first-class backend and adds KRB as a portable cartridge path with explicit host capabilities. The same source can target desktop, mobile, browser, and embedded renderers.</p></div>
|
||||
</details>
|
||||
<details class="faq-item">
|
||||
<summary>How is it different from Godot's UI? <span class="chev">›</span></summary>
|
||||
<div class="faq-a"><p>Godot is a game engine with UI controls. Kryon is a dedicated app UI runtime — the widget tree owns layout, input routing, focus, overlays, and source-aware inspection for building product interfaces, not just game HUDs.</p></div>
|
||||
</details>
|
||||
<details class="faq-item">
|
||||
<summary>What is a .kry file? <span class="chev">›</span></summary>
|
||||
<div class="faq-a"><p>A concise declarative source file describing pages and reusable widgets with explicit typed variables and node declarations. The frontend lowers each file into KIR, then backends emit readable C or portable KRB.</p></div>
|
||||
</details>
|
||||
<details class="faq-item">
|
||||
<summary>Is Kryon free? <span class="chev">›</span></summary>
|
||||
<div class="faq-a"><p>Yes — Kryon and Krait are free and open source, developed by Kryon Labs. Clone and build from <a href="https://github.com/kryonlabs/kryon" target="_blank" rel="noopener">github.com/kryonlabs/kryon</a>.</p></div>
|
||||
</details>
|
||||
<details class="faq-item">
|
||||
<summary>What platforms does it support? <span class="chev">›</span></summary>
|
||||
<div class="faq-a"><p>Linux, Windows, macOS, Android, the browser via WebAssembly, and FreeBSD — including embedded targets. One interface source builds for all of them.</p></div>
|
||||
</details>
|
||||
<details class="faq-item">
|
||||
<summary>What is Krait? <span class="chev">›</span></summary>
|
||||
<div class="faq-a"><p>Krait is the standalone first-party Kryon IDE — project workspace, <code>.kry</code> source editing, live preview, diagnostics, and source-aware inspection. It's built as a Kryon app. See <a href="https://krait.kryonlabs.com">krait.kryonlabs.com</a>.</p></div>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div class="footer-inner">
|
||||
<div class="footer-brand">
|
||||
<img src="icons/kryon.png" alt="Kryon" width="20" height="20">
|
||||
<span>KRYON</span>
|
||||
</div>
|
||||
<div class="footer-cols">
|
||||
<div class="footer-col">
|
||||
<h4>Kryon</h4>
|
||||
<ul>
|
||||
<li><a href="#features">Features</a></li>
|
||||
<li><a href="#why">Why Kryon</a></li>
|
||||
<li><a href="#platforms">Platforms</a></li>
|
||||
<li><a href="/api">API reference</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer-col">
|
||||
<h4>Ecosystem</h4>
|
||||
<ul>
|
||||
<li><a href="https://krait.kryonlabs.com">Krait IDE ↗</a></li>
|
||||
<li><a href="https://github.com/kryonlabs/kryon" target="_blank" rel="noopener">GitHub ↗</a></li>
|
||||
<li><a href="https://github.com/kryonlabs/krait" target="_blank" rel="noopener">Krait on GitHub ↗</a></li>
|
||||
<li><a href="#start">Get started</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="footer-col">
|
||||
<h4>Community</h4>
|
||||
<ul>
|
||||
<li><a href="https://discord.gg/ep7gCWzHJD" target="_blank" rel="noopener">Discord ↗</a></li>
|
||||
<li><a href="https://t.me/kryonlabs_com" target="_blank" rel="noopener">Telegram ↗</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer-bottom">
|
||||
<p>© 2026 Kryon Labs · <a href="https://waozi.xyz" target="_blank" rel="noopener">Made by Waozi</a></p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<footer>
|
||||
<p>© 2026 Kryon Labs | <a href="https://waozi.xyz" target="_blank" rel="noopener">Made by Waozi</a></p>
|
||||
</footer>
|
||||
</div>
|
||||
<script src="highlight.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
// mobile menu
|
||||
var toggle = document.querySelector(".menu-toggle");
|
||||
var nav = document.getElementById("header-nav");
|
||||
if (toggle && nav) {
|
||||
toggle.addEventListener("click", function() {
|
||||
var open = nav.classList.toggle("is-open");
|
||||
toggle.setAttribute("aria-expanded", open ? "true" : "false");
|
||||
});
|
||||
}
|
||||
|
||||
// feature tabs
|
||||
document.querySelectorAll("[data-tabs]").forEach(function(group) {
|
||||
var tabs = group.querySelectorAll("[role=tab]");
|
||||
tabs.forEach(function(tab) {
|
||||
tab.addEventListener("click", function() {
|
||||
tabs.forEach(function(t) {
|
||||
var sel = t === tab;
|
||||
t.setAttribute("aria-selected", sel ? "true" : "false");
|
||||
t.tabIndex = sel ? 0 : -1;
|
||||
});
|
||||
group.querySelectorAll(".tabpanel").forEach(function(p) {
|
||||
var active = p.id === tab.getAttribute("aria-controls");
|
||||
p.classList.toggle("is-active", active);
|
||||
if (active) p.removeAttribute("hidden");
|
||||
else p.setAttribute("hidden", "");
|
||||
});
|
||||
});
|
||||
tab.addEventListener("keydown", function(e) {
|
||||
var list = Array.prototype.slice.call(tabs);
|
||||
var i = list.indexOf(tab);
|
||||
if (e.key === "ArrowRight") { list[(i + 1) % list.length].focus(); e.preventDefault(); }
|
||||
if (e.key === "ArrowLeft") { list[(i - 1 + list.length) % list.length].focus(); e.preventDefault(); }
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+1155
-299
File diff suppressed because it is too large.
Load diff
@@ -17,22 +17,22 @@ state {
|
||||
}
|
||||
|
||||
screen FileDialogExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
if dlg_ready == 0 {
|
||||
InitFileDialog(&dlg)
|
||||
dlg_ready = 1
|
||||
}
|
||||
WidgetText("Kryon File Dialog", ScaleUIPx(32), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
WidgetText("Dialog backend and result state", ScaleUIPx(32), ScaleUIPx(66), UI_TEXT_16, GetThemeIcon())
|
||||
if WidgetButton(ScaleUIPx(32), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Open File", UI_BUTTON_STYLE_PRIMARY) {
|
||||
Text("Kryon File Dialog", ScaleUIPx(32), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Dialog backend and result state", ScaleUIPx(32), ScaleUIPx(66), UI_TEXT_16, GetThemeIcon())
|
||||
if GenericButton(101, ScaleUIPx(32), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Open File", UI_BUTTON_STYLE_PRIMARY, 0, NULL) {
|
||||
BeginLoadFileDialog(&dlg,"Open File")
|
||||
snprintf(status,sizeof(status),"Open file requested.")
|
||||
}
|
||||
if WidgetButton(ScaleUIPx(226), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Save File", UI_BUTTON_STYLE_SECONDARY) {
|
||||
if GenericButton(102, ScaleUIPx(226), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Save File", UI_BUTTON_STYLE_SECONDARY, 0, NULL) {
|
||||
BeginSaveFileDialog(&dlg,"Save File","untitled.kry")
|
||||
snprintf(status,sizeof(status),"Save file requested.")
|
||||
}
|
||||
if WidgetButton(ScaleUIPx(420), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Select Folder", UI_BUTTON_STYLE_SECONDARY) {
|
||||
if GenericButton(103, ScaleUIPx(420), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Select Folder", UI_BUTTON_STYLE_SECONDARY, 0, NULL) {
|
||||
BeginSelectFileDialogFolder(&dlg,"Select Folder")
|
||||
snprintf(status,sizeof(status),"Folder selection requested.")
|
||||
}
|
||||
@@ -44,7 +44,7 @@ screen FileDialogExample(viewport: Rectangle) {
|
||||
if dialog_result < 0 {
|
||||
snprintf(status,sizeof(status),"Dialog cancelled.")
|
||||
}
|
||||
WidgetText("Status", ScaleUIPx(32), ScaleUIPx(210), 18, GetThemeText())
|
||||
WidgetText(status, ScaleUIPx(32), ScaleUIPx(242), UI_TEXT_16, GetThemeText())
|
||||
WidgetText(last_path, ScaleUIPx(32), ScaleUIPx(274), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Status", ScaleUIPx(32), ScaleUIPx(210), 18, GetThemeText())
|
||||
Text(status, ScaleUIPx(32), ScaleUIPx(242), UI_TEXT_16, GetThemeText())
|
||||
Text(last_path, ScaleUIPx(32), ScaleUIPx(274), UI_TEXT_16, GetThemeIcon())
|
||||
}
|
||||
+25
-10
@@ -13,23 +13,38 @@ state {
|
||||
}
|
||||
|
||||
screen ButtonsExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
WidgetText("UI Buttons Example", ScaleUIPx(20), ScaleUIPx(20), UI_TEXT_24, GetThemeText())
|
||||
WidgetText("Click the buttons below to test interactions", ScaleUIPx(20), ScaleUIPx(54), UI_TEXT_16, GetThemeText())
|
||||
if WidgetButton(ScaleUIPx(20), ScaleUIPx(100), ScaleUIPx(200), ScaleUIPx(40), "Primary Button", UI_BUTTON_STYLE_PRIMARY) {
|
||||
Background(GetThemeBackground())
|
||||
Text("UI Buttons Example", ScaleUIPx(20), ScaleUIPx(20), UI_TEXT_24, GetThemeText())
|
||||
Text("Click the buttons below to test interactions", ScaleUIPx(20), ScaleUIPx(54), UI_TEXT_16, GetThemeText())
|
||||
if Button((ButtonProps){
|
||||
.bounds = {ScaleUIPx(20), ScaleUIPx(100), ScaleUIPx(200), ScaleUIPx(40)},
|
||||
.label = "Primary Button",
|
||||
.style = UI_BUTTON_STYLE_PRIMARY,
|
||||
.id = 101,
|
||||
}) {
|
||||
click_count++
|
||||
snprintf(last_action,sizeof(last_action),"Primary Button clicked.")
|
||||
}
|
||||
if WidgetButton(ScaleUIPx(20), ScaleUIPx(150), ScaleUIPx(200), ScaleUIPx(40), "Secondary Button", UI_BUTTON_STYLE_SECONDARY) {
|
||||
if Button((ButtonProps){
|
||||
.bounds = {ScaleUIPx(20), ScaleUIPx(150), ScaleUIPx(200), ScaleUIPx(40)},
|
||||
.label = "Secondary Button",
|
||||
.style = UI_BUTTON_STYLE_SECONDARY,
|
||||
.id = 102,
|
||||
}) {
|
||||
click_count++
|
||||
snprintf(last_action,sizeof(last_action),"Secondary Button clicked.")
|
||||
}
|
||||
if WidgetButton(ScaleUIPx(20), ScaleUIPx(200), ScaleUIPx(200), ScaleUIPx(40), "Danger Button", UI_BUTTON_STYLE_DANGER) {
|
||||
if Button((ButtonProps){
|
||||
.bounds = {ScaleUIPx(20), ScaleUIPx(200), ScaleUIPx(200), ScaleUIPx(40)},
|
||||
.label = "Danger Button",
|
||||
.style = UI_BUTTON_STYLE_DANGER,
|
||||
.id = 103,
|
||||
}) {
|
||||
click_count++
|
||||
snprintf(last_action,sizeof(last_action),"Danger Button clicked.")
|
||||
}
|
||||
WidgetText(TextFormat("Clicks:%d",click_count), ScaleUIPx(20), ScaleUIPx(260), UI_TEXT_16, GetThemeText())
|
||||
WidgetText(last_action, ScaleUIPx(20), ScaleUIPx(290), UI_TEXT_16, GetThemeText())
|
||||
WidgetText("Button Styles", ScaleUIPx(300), ScaleUIPx(100), 18, GetThemeText())
|
||||
WidgetText("Primary,secondary,and danger styles use the active theme.", ScaleUIPx(300), ScaleUIPx(130), 14, GetThemeIcon())
|
||||
Text(TextFormat("Clicks:%d",click_count), ScaleUIPx(20), ScaleUIPx(260), UI_TEXT_16, GetThemeText())
|
||||
Text(last_action, ScaleUIPx(20), ScaleUIPx(290), UI_TEXT_16, GetThemeText())
|
||||
Text("Button Styles", ScaleUIPx(300), ScaleUIPx(100), 18, GetThemeText())
|
||||
Text("Primary,secondary,and danger styles use the active theme.", ScaleUIPx(300), ScaleUIPx(130), 14, GetThemeIcon())
|
||||
}
|
||||
+119
-98
@@ -1,127 +1,148 @@
|
||||
#import "kryon.h"
|
||||
|
||||
app "Kryon Theme Example" {
|
||||
size 800 600
|
||||
size 900 680
|
||||
fps 60
|
||||
font examples
|
||||
theme THEME_SKY light
|
||||
}
|
||||
|
||||
state {
|
||||
theme_index: int = 0
|
||||
dark_mode: int = 0
|
||||
theme_source: int = THEME_SOURCE_SYSTEM
|
||||
theme_mode: int = THEME_MODE_SYSTEM
|
||||
theme_id: int = THEME_SKY
|
||||
theme_style: int = THEME_STYLE_SYSTEM
|
||||
menu_state: UIThemeSettingsState = {0}
|
||||
slider_value: int = 64
|
||||
toggle_value: int = 1
|
||||
check_value: int = 1
|
||||
text_value: [128] char = "Live Kryon text field"
|
||||
text_cursor: int = 21
|
||||
text_focused: int = 0
|
||||
combo_index: int = 1
|
||||
}
|
||||
|
||||
ThemeAt :: (index: int) -> ThemeId {
|
||||
if index == 0 {
|
||||
return THEME_SKY
|
||||
ClampInt :: (value: int, min_value: int, max_value: int) -> int {
|
||||
if value < min_value {
|
||||
return min_value
|
||||
}
|
||||
if index == 1 {
|
||||
return THEME_OCEAN
|
||||
if value > max_value {
|
||||
return max_value
|
||||
}
|
||||
if index == 2 {
|
||||
return THEME_FOREST
|
||||
}
|
||||
if index == 3 {
|
||||
return THEME_SUNSET
|
||||
}
|
||||
if index == 4 {
|
||||
return THEME_LAVENDER
|
||||
}
|
||||
if index == 5 {
|
||||
return THEME_CHERRY
|
||||
}
|
||||
if index == 6 {
|
||||
return THEME_DAWN
|
||||
}
|
||||
if index == 7 {
|
||||
return THEME_SAGE
|
||||
}
|
||||
if index == 8 {
|
||||
return THEME_INK
|
||||
}
|
||||
if index == 9 {
|
||||
return THEME_MONO
|
||||
}
|
||||
if index == 10 {
|
||||
return THEME_MINT
|
||||
}
|
||||
return THEME_COBALT
|
||||
return value
|
||||
}
|
||||
|
||||
ThemeSwatch :: (label: const char *, y: int, value: Color, label_color: Color) {
|
||||
x: int = ScaleUIPx(20)
|
||||
size: int = ScaleUIPx(56)
|
||||
WidgetRect(x, y, size, size, value, BLANK)
|
||||
WidgetRect(x, y, size, size, BLANK, label_color)
|
||||
WidgetText(label, x+size+ScaleUIPx(10), y+ScaleUIPx(10), UI_TEXT_16, label_color)
|
||||
ThemeDarkMode :: () -> int {
|
||||
if theme_mode == THEME_MODE_DARK {
|
||||
return 1
|
||||
}
|
||||
if theme_mode == THEME_MODE_LIGHT {
|
||||
return 0
|
||||
}
|
||||
return SystemThemePrefersDark() ? 1 : 0
|
||||
}
|
||||
|
||||
ThemeButton :: (label: const char *, x: int, y: int, w: int) -> int {
|
||||
h: int = ScaleUIPx(38)
|
||||
return DrawUIGenericButton(x,y,w,h,label,UI_BUTTON_STYLE_SECONDARY,0,NULL)
|
||||
ApplyThemeState :: () {
|
||||
theme_source = ClampInt(theme_source, THEME_SOURCE_APP, THEME_SOURCE_SYSTEM)
|
||||
theme_mode = ClampInt(theme_mode, THEME_MODE_SYSTEM, THEME_MODE_DARK)
|
||||
theme_style = ClampInt(theme_style, THEME_STYLE_SYSTEM, THEME_STYLE_MATERIAL)
|
||||
theme_id = ClampInt(theme_id, 0, THEME_COUNT - 1)
|
||||
SetThemeSource((ThemeSource)theme_source)
|
||||
SetThemeMode((ThemeMode)theme_mode)
|
||||
SetThemeStyle((ThemeStyle)theme_style)
|
||||
SetCurrentTheme(theme_id, ThemeDarkMode())
|
||||
}
|
||||
|
||||
ThemeLabel :: (label: const char *, value: const char *, y: int, size: int, text_color: Color) {
|
||||
WidgetText(TextFormat("%s%s",label,value), ScaleUIPx(20), y, size, text_color)
|
||||
TokenValue :: (label: const char *, value: int, x: int, y: int) {
|
||||
Text(TextFormat("%s %d", label, value), x, y, UI_TEXT_12, GetThemeIcon())
|
||||
}
|
||||
|
||||
ThemeSideLabel :: (label: const char *, value: const char *, y: int, text_color: Color) {
|
||||
WidgetText(TextFormat("%s%s",label,value), ScaleUIPx(320), y, UI_TEXT_16, text_color)
|
||||
}
|
||||
ControlDemo :: (x: int, y: int, w: int) {
|
||||
options: [3] const char * = {"One", "Two", "Three"}
|
||||
field_style := (UITextInputStyle){
|
||||
DarkenUIColor(GetThemeBackground(), 6),
|
||||
DarkenUIColor(GetThemeBackground(), 38),
|
||||
GetThemeButtonHover(),
|
||||
GetThemeText(),
|
||||
GetThemeText(),
|
||||
0.08f,
|
||||
ScaleUIPx(12),
|
||||
ScaleUIPx(8)
|
||||
}
|
||||
|
||||
ThemeSideInt :: (label: const char *, y: int, value: int, text_color: Color) {
|
||||
WidgetText(TextFormat("%s%d",label,value), ScaleUIPx(320), y, UI_TEXT_16, text_color)
|
||||
}
|
||||
Text("Live controls", x, y, UI_TEXT_24, GetThemeText())
|
||||
y += ScaleUIPx(46)
|
||||
Button((ButtonProps){
|
||||
.bounds = {x, y, ScaleUIPx(190), ScaleUIPx(44)},
|
||||
.label = "Primary",
|
||||
.style = UI_BUTTON_STYLE_PRIMARY,
|
||||
.id = 301,
|
||||
})
|
||||
Button((ButtonProps){
|
||||
.bounds = {x + ScaleUIPx(210), y, ScaleUIPx(190), ScaleUIPx(44)},
|
||||
.label = "Secondary",
|
||||
.style = UI_BUTTON_STYLE_SECONDARY,
|
||||
.id = 302,
|
||||
})
|
||||
y += ScaleUIPx(70)
|
||||
|
||||
ThemeRGB :: (label: const char *, y: int, value: Color, text_color: Color) {
|
||||
rgb_text: const char * = TextFormat("%s RGB:%d,%d,%d",label,value.r,value.g,value.b)
|
||||
WidgetText(rgb_text, ScaleUIPx(320), y, 14, text_color)
|
||||
TextField((TextFieldProps){{x, y, w, ScaleUIPx(44)}, text_value, sizeof(text_value),
|
||||
&text_cursor, &text_focused, 80, UI_TEXT_16, 303,
|
||||
field_style, NULL, NULL, NULL})
|
||||
y += ScaleUIPx(70)
|
||||
Dropdown(304, x, y, w, ScaleUIPx(44), options, 3, &combo_index)
|
||||
y += ScaleUIPx(72)
|
||||
Slider(305, x, y, w, "Slider", 0, 100, &slider_value, "", nil)
|
||||
y += ScaleUIPx(72)
|
||||
Toggle(306, x, y, ScaleUIPx(180), ScaleUIPx(48), &toggle_value, "Off", "On")
|
||||
Checkbox(307, x + ScaleUIPx(230), y + ScaleUIPx(12), "Checkbox", &check_value)
|
||||
}
|
||||
|
||||
screen ThemeExample(viewport: Rectangle) {
|
||||
current_theme: ThemeId = ThemeAt(theme_index)
|
||||
left_x: int = ScaleUIPx(300)
|
||||
right_x: int = ScaleUIPx(420)
|
||||
button_w: int = ScaleUIPx(112)
|
||||
mode_w: int = ScaleUIPx(232)
|
||||
SetCurrentTheme(current_theme, dark_mode)
|
||||
background: Color
|
||||
text_color: Color
|
||||
button: Color
|
||||
button_hover: Color
|
||||
circle: Color
|
||||
GetThemeCatalogColor(current_theme,dark_mode,"background",&background)
|
||||
GetThemeCatalogColor(current_theme,dark_mode,"text",&text_color)
|
||||
GetThemeCatalogColor(current_theme,dark_mode,"button",&button)
|
||||
GetThemeCatalogColor(current_theme,dark_mode,"button_hover",&button_hover)
|
||||
GetThemeCatalogColor(current_theme,dark_mode,"circle",&circle)
|
||||
WidgetBackground(background)
|
||||
ThemeLabel("Theme: ",GetThemeLabel(current_theme),ScaleUIPx(20),UI_TEXT_24,text_color)
|
||||
ThemeLabel("Mode:",dark_mode?"Dark":"Light",ScaleUIPx(50),UI_TEXT_16,text_color)
|
||||
if ThemeButton("Prev Theme", left_x, ScaleUIPx(18), button_w) {
|
||||
theme_index = (theme_index + 11) % 12
|
||||
ApplyThemeState()
|
||||
Background(GetThemeBackground())
|
||||
|
||||
margin: int = ScaleUIPx(26)
|
||||
panel_w: int = ScaleUIPx(310)
|
||||
right_x: int = margin + panel_w + ScaleUIPx(42)
|
||||
settings := (ThemeSettingsProps){
|
||||
.id_base = 101,
|
||||
.x = margin,
|
||||
.y = ScaleUIPx(64),
|
||||
.w = panel_w,
|
||||
.theme_source = &theme_source,
|
||||
.theme_mode = &theme_mode,
|
||||
.theme_id = &theme_id,
|
||||
.theme_style = &theme_style,
|
||||
.allow_system_source = 1,
|
||||
.allow_system_mode = 1,
|
||||
.palette_label = "Color palette",
|
||||
.source_system_label = "System colors",
|
||||
.style_label = "Widget style",
|
||||
.style_system_label = "System style"
|
||||
}
|
||||
if ThemeButton("Next Theme", right_x, ScaleUIPx(18), button_w) {
|
||||
theme_index = (theme_index + 1) % 12
|
||||
|
||||
Text("Kryon Native Theme State", margin, ScaleUIPx(24), UI_TEXT_24, GetThemeText())
|
||||
Text("Switch style and palette here; every control on the right uses Kryon live.", right_x, ScaleUIPx(30), UI_TEXT_16, GetThemeIcon())
|
||||
result: UIThemeSettingsResult = {0}
|
||||
ThemeSettings(settings, &menu_state, &result)
|
||||
|
||||
ControlDemo(right_x, ScaleUIPx(88), ScaleUIPx(420))
|
||||
|
||||
tokens := GetUIStyleTokens()
|
||||
token_y: int = ScaleUIPx(520)
|
||||
Text("Active style tokens", right_x, token_y, UI_TEXT_16, GetThemeText())
|
||||
token_y += ScaleUIPx(30)
|
||||
TokenValue("control alpha", tokens.control_alpha, right_x, token_y)
|
||||
TokenValue("panel alpha", tokens.panel_alpha, right_x + ScaleUIPx(150), token_y)
|
||||
token_y += ScaleUIPx(24)
|
||||
TokenValue("border alpha", tokens.border_alpha, right_x, token_y)
|
||||
TokenValue("shadow alpha", tokens.shadow_alpha, right_x + ScaleUIPx(150), token_y)
|
||||
token_y += ScaleUIPx(24)
|
||||
TokenValue("touch target", tokens.touch_target_min, right_x, token_y)
|
||||
TokenValue("shadow y", tokens.shadow_offset_y, right_x + ScaleUIPx(150), token_y)
|
||||
|
||||
if result.changed {
|
||||
ApplyThemeState()
|
||||
}
|
||||
if dark_mode {
|
||||
if ThemeButton("Light Mode", left_x, ScaleUIPx(64), mode_w) {
|
||||
dark_mode = 0
|
||||
}
|
||||
} else {
|
||||
if ThemeButton("Dark Mode", left_x, ScaleUIPx(64), mode_w) {
|
||||
dark_mode = 1
|
||||
}
|
||||
}
|
||||
ThemeSwatch("Background", ScaleUIPx(90), background, text_color)
|
||||
ThemeSwatch("Text", ScaleUIPx(160), text_color, text_color)
|
||||
ThemeSwatch("Button", ScaleUIPx(230), button, text_color)
|
||||
ThemeSwatch("Button Hover", ScaleUIPx(300), button_hover, text_color)
|
||||
ThemeSwatch("Circle", ScaleUIPx(370), circle, text_color)
|
||||
scope: const char * = GetThemeScopeName(current_theme,dark_mode)
|
||||
ThemeSideLabel("Scope:", scope, ScaleUIPx(120), text_color)
|
||||
ThemeSideInt("Theme ID:", ScaleUIPx(152), current_theme, text_color)
|
||||
ThemeRGB("Background", ScaleUIPx(200), background, text_color)
|
||||
ThemeRGB("Text", ScaleUIPx(224), text_color, text_color)
|
||||
}
|
||||
@@ -14,20 +14,20 @@ state {
|
||||
}
|
||||
|
||||
screen ModalExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
WidgetText("Modal capture example", 32, 32, UI_TEXT_24, GetThemeText())
|
||||
WidgetText("Open the modal and background clicks are blocked.", 32, 72, UI_TEXT_16, GetThemeIcon())
|
||||
if WidgetButton(32, 120, 220, 42, "Background Button", UI_BUTTON_STYLE_SECONDARY) {
|
||||
Background(GetThemeBackground())
|
||||
Text("Modal capture example", 32, 32, UI_TEXT_24, GetThemeText())
|
||||
Text("Open the modal and background clicks are blocked.", 32, 72, UI_TEXT_16, GetThemeIcon())
|
||||
if GenericButton(101, 32, 120, 220, 42, "Background Button", UI_BUTTON_STYLE_SECONDARY, 0, NULL) {
|
||||
background_clicks++
|
||||
}
|
||||
WidgetText(TextFormat("Background clicks:%d",background_clicks), 32, 176, UI_TEXT_16, GetThemeText())
|
||||
WidgetText(TextFormat("Last modal result:%s",last_label), 32, 204, UI_TEXT_16, GetThemeText())
|
||||
if WidgetButton(32, 240, 220, 42, "Open Modal", UI_BUTTON_STYLE_PRIMARY) {
|
||||
Text(TextFormat("Background clicks:%d",background_clicks), 32, 176, UI_TEXT_16, GetThemeText())
|
||||
Text(TextFormat("Last modal result:%s",last_label), 32, 204, UI_TEXT_16, GetThemeText())
|
||||
if GenericButton(102, 32, 240, 220, 42, "Open Modal", UI_BUTTON_STYLE_PRIMARY, 0, NULL) {
|
||||
modal_open = 1
|
||||
}
|
||||
if modal_open {
|
||||
actions: [3] UIModalAction = {{"Cancel",UI_BUTTON_STYLE_SECONDARY,0},{"Confirm",UI_BUTTON_STYLE_PRIMARY,0},{"Delete",UI_BUTTON_STYLE_DANGER,0}}
|
||||
result: int = DrawUIActionModal((UIModalSpec){"Adaptive Action Modal","Kryon measures action labels and blocks background clicks.",actions,3,420})
|
||||
result: int = ActionModal((ModalProps){"Adaptive Action Modal","Kryon measures action labels and blocks background clicks.",actions,3,420})
|
||||
if result == 1 {
|
||||
modal_open = 0
|
||||
snprintf(last_label,sizeof(last_label),"cancel")
|
||||
|
||||
+14
-14
@@ -12,24 +12,24 @@ state {
|
||||
}
|
||||
|
||||
screen ColorExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
colors: [5] Color = {GetThemeButton(),GetThemeButtonHover(),GetThemeCircle(),GetThemeSurface(),GetThemeLink()}
|
||||
base: Color = colors[color_index]
|
||||
light: Color = LightenUIColor(base,40)
|
||||
dark: Color = DarkenUIColor(base,40)
|
||||
WidgetText("Color Utilities", 50, 20, UI_TEXT_24, GetThemeText())
|
||||
WidgetRect(50, 70, 70, 70, base, BLANK)
|
||||
WidgetRect(50, 70, 70, 70, BLANK, GetThemeText())
|
||||
WidgetText("Original", 50+70+ScaleUIPx(10), 70+ScaleUIPx(10), UI_TEXT_16, GetThemeText())
|
||||
WidgetRect(50, 160, 70, 70, light, BLANK)
|
||||
WidgetRect(50, 160, 70, 70, BLANK, GetThemeText())
|
||||
WidgetText("Lightened", 50+70+ScaleUIPx(10), 160+ScaleUIPx(10), UI_TEXT_16, GetThemeText())
|
||||
WidgetRect(50, 250, 70, 70, dark, BLANK)
|
||||
WidgetRect(50, 250, 70, 70, BLANK, GetThemeText())
|
||||
WidgetText("Darkened", 50+70+ScaleUIPx(10), 250+ScaleUIPx(10), UI_TEXT_16, GetThemeText())
|
||||
WidgetText(TextFormat("Color %d/5 - SPACE cycles",color_index+1), 320, 82, 18, GetThemeText())
|
||||
WidgetText(TextFormat("RGB:%d,%d,%d",base.r,base.g,base.b), 320, 116, UI_TEXT_16, GetThemeText())
|
||||
if (UIKeyPressed(KEY_SPACE)) {
|
||||
Text("Color Utilities", 50, 20, UI_TEXT_24, GetThemeText())
|
||||
Rect(50, 70, 70, 70, base, BLANK)
|
||||
Rect(50, 70, 70, 70, BLANK, GetThemeText())
|
||||
Text("Original", 50+70+ScaleUIPx(10), 70+ScaleUIPx(10), UI_TEXT_16, GetThemeText())
|
||||
Rect(50, 160, 70, 70, light, BLANK)
|
||||
Rect(50, 160, 70, 70, BLANK, GetThemeText())
|
||||
Text("Lightened", 50+70+ScaleUIPx(10), 160+ScaleUIPx(10), UI_TEXT_16, GetThemeText())
|
||||
Rect(50, 250, 70, 70, dark, BLANK)
|
||||
Rect(50, 250, 70, 70, BLANK, GetThemeText())
|
||||
Text("Darkened", 50+70+ScaleUIPx(10), 250+ScaleUIPx(10), UI_TEXT_16, GetThemeText())
|
||||
Text(TextFormat("Color %d/5 - SPACE cycles",color_index+1), 320, 82, 18, GetThemeText())
|
||||
Text(TextFormat("RGB:%d,%d,%d",base.r,base.g,base.b), 320, 116, UI_TEXT_16, GetThemeText())
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
color_index = (color_index + 1) % 5
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -16,26 +16,26 @@ state {
|
||||
|
||||
screen ScalingExample(viewport: Rectangle) {
|
||||
SetUIScale(scales[scale_index])
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
box_size: int = ScaleUIPx(100)
|
||||
WidgetText(TextFormat("DPI Scale:%.1f",scales[scale_index]), 50, 20, 20, GetThemeText())
|
||||
WidgetRect(box_x, box_y, box_size, box_size, GetThemeButton(), GetThemeIcon())
|
||||
WidgetText("Scaled Box", box_x + 10, box_y + 10, UI_TEXT_16, GetThemeText())
|
||||
WidgetText(TextFormat("Base:100px Scaled:%dpx",box_size), 50, 60, UI_TEXT_16, GetThemeText())
|
||||
WidgetText("SPACE cycles DPI,arrows move box", 50, 90, UI_TEXT_16, GetThemeIcon())
|
||||
if (UIKeyDown(KEY_RIGHT)) {
|
||||
Text(TextFormat("DPI Scale:%.1f",scales[scale_index]), 50, 20, 20, GetThemeText())
|
||||
Rect(box_x, box_y, box_size, box_size, GetThemeButton(), GetThemeIcon())
|
||||
Text("Scaled Box", box_x + 10, box_y + 10, UI_TEXT_16, GetThemeText())
|
||||
Text(TextFormat("Base:100px Scaled:%dpx",box_size), 50, 60, UI_TEXT_16, GetThemeText())
|
||||
Text("SPACE cycles DPI,arrows move box", 50, 90, UI_TEXT_16, GetThemeIcon())
|
||||
if (IsKeyDown(KEY_RIGHT)) {
|
||||
box_x += 3
|
||||
}
|
||||
if (UIKeyDown(KEY_LEFT)) {
|
||||
if (IsKeyDown(KEY_LEFT)) {
|
||||
box_x -= 3
|
||||
}
|
||||
if (UIKeyDown(KEY_DOWN)) {
|
||||
if (IsKeyDown(KEY_DOWN)) {
|
||||
box_y += 3
|
||||
}
|
||||
if (UIKeyDown(KEY_UP)) {
|
||||
if (IsKeyDown(KEY_UP)) {
|
||||
box_y -= 3
|
||||
}
|
||||
if (UIKeyPressed(KEY_SPACE)) {
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
scale_index = (scale_index + 1) % 4
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ state {
|
||||
|
||||
LayoutInfo :: (label: const char *, value: int, x: int, y: int) {
|
||||
info: const char * = TextFormat("%s:%d",label,value)
|
||||
WidgetText(info, x, y, UI_TEXT_16, GetThemeText())
|
||||
Text(info, x, y, UI_TEXT_16, GetThemeText())
|
||||
}
|
||||
|
||||
WidthButton :: (label: const char *, x: int, y: int, value: int) -> int {
|
||||
@@ -21,15 +21,15 @@ WidthButton :: (label: const char *, x: int, y: int, value: int) -> int {
|
||||
if max_width == value {
|
||||
style = UI_BUTTON_STYLE_PRIMARY
|
||||
}
|
||||
return DrawUIGenericButton(x,y,ScaleUIPx(110),ScaleUIPx(34),label,style,0,NULL)
|
||||
return GenericButton(1000 + x + y, x,y,ScaleUIPx(110),ScaleUIPx(34),label,style,0,NULL)
|
||||
}
|
||||
|
||||
LayoutNote :: (label: const char *, x: int, y: int, color: Color) {
|
||||
WidgetText(label, x, y, UI_TEXT_16, color)
|
||||
Text(label, x, y, UI_TEXT_16, color)
|
||||
}
|
||||
|
||||
screen LayoutExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
side_padding: int = GetUIPageSidePadding()
|
||||
page_x: int = side_padding
|
||||
page_w: int = GetUIViewWidth() - side_padding * 2
|
||||
@@ -47,11 +47,11 @@ screen LayoutExample(viewport: Rectangle) {
|
||||
btn0_x = column_x + ScaleUIPx(16)
|
||||
btn1_x = column_x + ScaleUIPx(138)
|
||||
btn2_x = column_x + ScaleUIPx(260)
|
||||
WidgetText("Responsive layout", page_x, ScaleUIPx(16), UI_TEXT_24, GetThemeText())
|
||||
WidgetRect(page_x, y, page_w, guide_h, GetThemeSurface(), GetThemeIcon())
|
||||
WidgetLine(side_padding, y, side_padding, y+guide_h, GetThemeLink())
|
||||
WidgetLine(right_edge, y, right_edge, y+guide_h, GetThemeLink())
|
||||
WidgetRect(column_x, column_y, column_w, ScaleUIPx(360), GetThemeBackground(), GetThemeButton())
|
||||
Text("Responsive layout", page_x, ScaleUIPx(16), UI_TEXT_24, GetThemeText())
|
||||
Rect(page_x, y, page_w, guide_h, GetThemeSurface(), GetThemeIcon())
|
||||
Line(side_padding, y, side_padding, y+guide_h, GetThemeLink())
|
||||
Line(right_edge, y, right_edge, y+guide_h, GetThemeLink())
|
||||
Rect(column_x, column_y, column_w, ScaleUIPx(360), GetThemeBackground(), GetThemeButton())
|
||||
LayoutInfo("View width", GetUIViewWidth(), column_x+16, y+ScaleUIPx(54))
|
||||
LayoutInfo("Side padding", side_padding, column_x+16, y+ScaleUIPx(84))
|
||||
LayoutInfo("Column max", max_width, column_x+16, y+ScaleUIPx(114))
|
||||
|
||||
+12
-12
@@ -8,7 +8,7 @@ app "Kryon Geometry" {
|
||||
}
|
||||
|
||||
screen GeometryExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
SetUIViewSize(GetScreenWidth(),GetScreenHeight())
|
||||
shell: Rectangle = {40,42,GetUIViewWidth()-80,GetUIViewHeight()-84}
|
||||
frame: UIFrame = BeginUIFrameBox(shell,16,16,12)
|
||||
@@ -23,14 +23,14 @@ screen GeometryExample(viewport: Rectangle) {
|
||||
card3: Rectangle = UIGridCell(grid,1,1,1,2)
|
||||
badge: Rectangle = UIPlace(card1,14,42,92,28)
|
||||
action: Rectangle = UIPlace(footer,16,7,150,32)
|
||||
WidgetText("Geometry helpers", 40, 14, UI_TEXT_24, GetThemeText())
|
||||
Text("Geometry helpers", 40, 14, UI_TEXT_24, GetThemeText())
|
||||
DrawRectangleRec(shell,GetThemeSurface())
|
||||
DrawRectangleLinesEx(shell,1,GetThemeIcon())
|
||||
DrawRectangleRec(header,GetThemeButton())
|
||||
DrawRectangleRec(rail,DarkenUIColor(GetThemeSurface(),8))
|
||||
DrawUISeparator((Rectangle){rail.x+rail.width+6,rail.y,1,rail.height},1)
|
||||
WidgetText("Packed header", header.x+16, header.y+16, UI_TEXT_16, GetThemeText())
|
||||
WidgetText("Left rail", rail.x+16, rail.y+16, UI_TEXT_16, GetThemeText())
|
||||
Separator((Rectangle){rail.x+rail.width+6,rail.y,1,rail.height},1)
|
||||
Text("Packed header", header.x+16, header.y+16, UI_TEXT_16, GetThemeText())
|
||||
Text("Left rail", rail.x+16, rail.y+16, UI_TEXT_16, GetThemeText())
|
||||
DrawRectangleRec(card0,DarkenUIColor(GetThemeSurface(),12))
|
||||
DrawRectangleLinesEx(card0,1,GetThemeButton())
|
||||
DrawRectangleRec(card1,DarkenUIColor(GetThemeSurface(),16))
|
||||
@@ -39,13 +39,13 @@ screen GeometryExample(viewport: Rectangle) {
|
||||
DrawRectangleLinesEx(card2,1,GetThemeButton())
|
||||
DrawRectangleRec(card3,DarkenUIColor(GetThemeSurface(),22))
|
||||
DrawRectangleLinesEx(card3,1,GetThemeButton())
|
||||
WidgetText("UIGridCell 2-column span", card0.x+14, card0.y+18, UI_TEXT_16, GetThemeText())
|
||||
WidgetText("UIPlace badge", card1.x+14, card1.y+18, UI_TEXT_16, GetThemeText())
|
||||
Text("UIGridCell 2-column span", card0.x+14, card0.y+18, UI_TEXT_16, GetThemeText())
|
||||
Text("UIPlace badge", card1.x+14, card1.y+18, UI_TEXT_16, GetThemeText())
|
||||
DrawRectangleRec(badge,GetThemeButtonHover())
|
||||
WidgetText("badge", badge.x+18, badge.y+7, UI_TEXT_12, GetThemeText())
|
||||
WidgetText("cell 1,0", card2.x+14, card2.y+18, UI_TEXT_16, GetThemeText())
|
||||
WidgetText("wide footer cell", card3.x+14, card3.y+18, UI_TEXT_16, GetThemeText())
|
||||
DrawUISeparator((Rectangle){footer.x,footer.y-7,footer.width,1},0)
|
||||
Text("badge", badge.x+18, badge.y+7, UI_TEXT_12, GetThemeText())
|
||||
Text("cell 1,0", card2.x+14, card2.y+18, UI_TEXT_16, GetThemeText())
|
||||
Text("wide footer cell", card3.x+14, card3.y+18, UI_TEXT_16, GetThemeText())
|
||||
Separator((Rectangle){footer.x,footer.y-7,footer.width,1},0)
|
||||
DrawRectangleRec(action,GetThemeButton())
|
||||
WidgetText("placed action", action.x+14, action.y+9, UI_TEXT_12, GetThemeText())
|
||||
Text("placed action", action.x+14, action.y+9, UI_TEXT_12, GetThemeText())
|
||||
}
|
||||
@@ -13,13 +13,13 @@ state {
|
||||
}
|
||||
|
||||
screen MenusExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
file_items: [4] UIMenuItem = {{UI_MENU_COMMAND,"New","Ctrl+N",1,0,0,NULL,0},{UI_MENU_COMMAND,"Open","Ctrl+O",2,0,0,NULL,0},{UI_MENU_SEPARATOR,NULL,NULL,0,0,0,NULL,0},{UI_MENU_COMMAND,"Quit","Esc",3,0,0,NULL,0}}
|
||||
view_items: [3] UIMenuItem = {{UI_MENU_CHECK,"Show Grid","G",4,0,1,NULL,0},{UI_MENU_RADIO,"Compact",NULL,5,0,0,NULL,0},{UI_MENU_RADIO,"Comfortable",NULL,6,0,1,NULL,0}}
|
||||
menus: [2] UIMenu = {{{0},"File",file_items,4},{{0},"View",view_items,3}}
|
||||
result: UIMenuBarResult = DrawUIMenuBar(100,(Rectangle){0,0,GetScreenWidth(),34},menus,2,&open_menu)
|
||||
result: UIMenuBarResult = MenuBar(100,(Rectangle){0,0,GetScreenWidth(),34},menus,2,&open_menu)
|
||||
if result.activated_id != 0 {
|
||||
snprintf(status,sizeof(status),"Command %d",result.activated_id)
|
||||
}
|
||||
WidgetText(status, 40, 80, 20, GetThemeText())
|
||||
Text(status, 40, 80, 20, GetThemeText())
|
||||
}
|
||||
@@ -16,25 +16,25 @@ state {
|
||||
}
|
||||
|
||||
screen BasicControlsExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
WidgetText("Basic controls", 40, 40, UI_TEXT_24, GetThemeText())
|
||||
picked: int = DrawUIRadioButton((UIRadioButton){{40,90,160,28},"Choice A",1,radio==1,0})
|
||||
Background(GetThemeBackground())
|
||||
Text("Basic controls", 40, 40, UI_TEXT_24, GetThemeText())
|
||||
picked: int = Radio((RadioButtonProps){{40,90,160,28},"Choice A",1,radio==1,0})
|
||||
if picked {
|
||||
radio = picked
|
||||
}
|
||||
picked = DrawUIRadioButton((UIRadioButton){{40,124,160,28},"Choice B",2,radio==2,0})
|
||||
picked = Radio((RadioButtonProps){{40,124,160,28},"Choice B",2,radio==2,0})
|
||||
if picked {
|
||||
radio = picked
|
||||
}
|
||||
DrawUISpinbox((UISpinbox){{240,90,140,34},201,0,10,1,&spin,0})
|
||||
DrawUICombobox((UICombobox){{240,140,180,34},202,choices,3,&combo,0})
|
||||
DrawUIProgressBar((UIProgressBar){{40,210,380,28},0,100,progress,"Progress"})
|
||||
if (UIKeyPressed(KEY_RIGHT)) {
|
||||
Spinbox((SpinboxProps){{240,90,140,34},201,0,10,1,&spin,0})
|
||||
Combobox((ComboboxProps){{240,140,180,34},202,choices,3,&combo,0})
|
||||
Progress((ProgressBarProps){{40,210,380,28},0,100,progress,"Progress"})
|
||||
if (IsKeyPressed(KEY_RIGHT)) {
|
||||
if progress < 100 {
|
||||
progress += 5
|
||||
}
|
||||
}
|
||||
if (UIKeyPressed(KEY_LEFT)) {
|
||||
if (IsKeyPressed(KEY_LEFT)) {
|
||||
if progress > 0 {
|
||||
progress -= 5
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ state {
|
||||
}
|
||||
|
||||
screen CollectionsExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
tree: [4] UITreeItem = {{"Project",0,1,1,1},{"src",1,2,1,1},{"main.kry",2,3,0,1},{"README.md",1,4,0,1}}
|
||||
cols: [2] const char * = {"Name","Kind"}
|
||||
row0: [2] const char * = {"main.kry","Kry source"}
|
||||
row1: [2] const char * = {"README.md","Markdown"}
|
||||
rows: [2] UITableRow = {{row0,2},{row1,2}}
|
||||
DrawUIListBox((UIListBox){{40,60,180,180},301,items,4,&list_sel,&list_scroll,30})
|
||||
DrawUITreeView((UITreeView){{260,60,220,180},302,tree,4,&tree_sel,&tree_scroll,28})
|
||||
DrawUITableView((UITableView){{520,60,320,180},303,cols,2,rows,2,NULL,&row_sel,&sort_col,&table_scroll,28})
|
||||
WidgetText("Collections: list,tree,and table", 40, 280, 18, GetThemeText())
|
||||
ListBox((ListBoxProps){{40,60,180,180},301,items,4,&list_sel,&list_scroll,30})
|
||||
TreeView((TreeViewProps){{260,60,220,180},302,tree,4,&tree_sel,&tree_scroll,28})
|
||||
TableView((TableViewProps){{520,60,320,180},303,cols,2,rows,2,NULL,&row_sel,&sort_col,&table_scroll,28})
|
||||
Text("Collections: list,tree,and table", 40, 280, 18, GetThemeText())
|
||||
}
|
||||
@@ -15,13 +15,13 @@ state {
|
||||
}
|
||||
|
||||
screen TextEditorExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
DrawUITextArea((UITextArea){{40,70,520,180},text_value,sizeof(text_value),&cursor,&focused,&scroll,500,UI_TEXT_16,6,401,"Write here",UI_SYNTAX_NONE,{0},NULL,NULL})
|
||||
WidgetText("Ctrl/Cmd+C,X,and V work in the text area.", 40, 260, UI_TEXT_16, GetThemeText())
|
||||
if WidgetButton(40, 300, 110, 34, "Copy", UI_BUTTON_STYLE_SECONDARY) {
|
||||
Background(GetThemeBackground())
|
||||
TextArea((TextAreaProps){{40,70,520,180},text_value,sizeof(text_value),&cursor,&focused,&scroll,500,UI_TEXT_16,6,401,"Write here",UI_SYNTAX_NONE,{0},NULL,NULL})
|
||||
Text("Ctrl/Cmd+C,X,and V work in the text area.", 40, 260, UI_TEXT_16, GetThemeText())
|
||||
if GenericButton(101, 40, 300, 110, 34, "Copy", UI_BUTTON_STYLE_SECONDARY, 0, NULL) {
|
||||
SetUIClipboardTextValue(text_value)
|
||||
}
|
||||
if WidgetButton(170, 300, 110, 34, "Paste", UI_BUTTON_STYLE_SECONDARY) {
|
||||
if GenericButton(102, 170, 300, 110, 34, "Paste", UI_BUTTON_STYLE_SECONDARY, 0, NULL) {
|
||||
clip: const char * = GetUIClipboardTextValue()
|
||||
snprintf(text_value,sizeof(text_value),"%s",clip)
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ state {
|
||||
}
|
||||
|
||||
screen CanvasExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
Background(GetThemeBackground())
|
||||
canvas: UICanvasResult = BeginUICanvas((UICanvas){{40,50,620,420},&sx,&sy,&zoom})
|
||||
DrawUICanvasGrid((Rectangle){40,50,620,420},24,GetThemeButton())
|
||||
CanvasGrid((Rectangle){40,50,620,420},24,GetThemeButton())
|
||||
for i in 0..2 {
|
||||
DrawRectangleRec(shapes[i],i==selected?GetThemeButtonHover():GetThemeSurface())
|
||||
DrawRectangleLinesEx(shapes[i],2.0f,GetThemeIcon())
|
||||
|
||||
@@ -11,15 +11,15 @@ state {
|
||||
tab: int = 0
|
||||
split: int = 260
|
||||
open: int = 1
|
||||
tabs: [3] const char * = {"Files","Search","Output"}
|
||||
tabs: [3] const UITab = {{"Files"},{"Search"},{"Output"}}
|
||||
}
|
||||
|
||||
screen ContainersExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
DrawUINotebook((UINotebook){{40,50,680,400},tabs,3,&tab})
|
||||
DrawUIPanedView((UIPanedView){{40,100,680,280},501,1,&split,120,160})
|
||||
DrawUICollapsible((UICollapsible){{60,410,320,120},"Details",&open})
|
||||
Background(GetThemeBackground())
|
||||
TabBar((TabBarProps){{40,50,680,0},tabs,3,tab,0,0,0,NULL,1,NULL})
|
||||
PanedView((PanedViewProps){{40,100,680,280},501,1,&split,120,160})
|
||||
Collapsible((CollapsibleProps){{60,410,320,120},"Details",&open})
|
||||
if open {
|
||||
WidgetText("Collapsible content", 80, 455, UI_TEXT_16, GetThemeText())
|
||||
Text("Collapsible content", 80, 455, UI_TEXT_16, GetThemeText())
|
||||
}
|
||||
}
|
||||
@@ -16,24 +16,24 @@ state {
|
||||
}
|
||||
|
||||
screen DialogsExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
if WidgetButton(40, 60, 150, 34, "Message", UI_BUTTON_STYLE_PRIMARY) {
|
||||
Background(GetThemeBackground())
|
||||
if GenericButton(101, 40, 60, 150, 34, "Message", UI_BUTTON_STYLE_PRIMARY, 0, NULL) {
|
||||
dialog = 1
|
||||
}
|
||||
if WidgetButton(40, 104, 150, 34, "Confirm", UI_BUTTON_STYLE_PRIMARY) {
|
||||
if GenericButton(102, 40, 104, 150, 34, "Confirm", UI_BUTTON_STYLE_PRIMARY, 0, NULL) {
|
||||
dialog = 2
|
||||
}
|
||||
if WidgetButton(40, 148, 150, 34, "Prompt", UI_BUTTON_STYLE_PRIMARY) {
|
||||
if GenericButton(103, 40, 148, 150, 34, "Prompt", UI_BUTTON_STYLE_PRIMARY, 0, NULL) {
|
||||
dialog = 3
|
||||
}
|
||||
DrawUIColorPicker((Rectangle){240,60,320,160},&color)
|
||||
if dialog == 1 && DrawUIMessageDialog((UIMessageDialog){"Message","Hello from Kryon.","OK"}) > 0 {
|
||||
ColorPicker((Rectangle){240,60,320,160},&color)
|
||||
if dialog == 1 && MessageDialog((MessageDialogProps){"Message","Hello from Kryon.","OK"}) > 0 {
|
||||
dialog = 0
|
||||
}
|
||||
if dialog == 2 && DrawUIConfirmDialog((UIConfirmDialog){"Confirm","Continue?","No","Yes"}) != 0 {
|
||||
if dialog == 2 && ConfirmDialog((ConfirmDialogProps){"Confirm","Continue?","No","Yes"}) != 0 {
|
||||
dialog = 0
|
||||
}
|
||||
if dialog == 3 && DrawUIPromptDialog((UIPromptDialog){"Prompt",prompt,sizeof(prompt),&cursor,&focused,"Cancel","Save"}) != 0 {
|
||||
if dialog == 3 && PromptDialog((PromptDialogProps){"Prompt",prompt,sizeof(prompt),&cursor,&focused,"Cancel","Save"}) != 0 {
|
||||
dialog = 0
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,15 @@ state {
|
||||
}
|
||||
|
||||
screen KeyboardPlatformExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
WidgetText("Keyboard and clipboard", 40, 40, UI_TEXT_24, GetThemeText())
|
||||
WidgetText(message, 40, 90, UI_TEXT_16, GetThemeText())
|
||||
Background(GetThemeBackground())
|
||||
Text("Keyboard and clipboard", 40, 40, UI_TEXT_24, GetThemeText())
|
||||
Text(message, 40, 90, UI_TEXT_16, GetThemeText())
|
||||
if UIAcceleratorPressed((UIAccelerator){KEY_C,1,0,0,1}) {
|
||||
SetUIClipboardTextValue("Copied from Kryon")
|
||||
snprintf(message,sizeof(message),"Copied to clipboard")
|
||||
copied = 1
|
||||
}
|
||||
if copied {
|
||||
WidgetText("Clipboard updated.", 40, 130, UI_TEXT_16, GetThemeLink())
|
||||
Text("Clipboard updated.", 40, 130, UI_TEXT_16, GetThemeLink())
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,13 @@ state {
|
||||
}
|
||||
|
||||
screen AccessibilityExample(viewport: Rectangle) {
|
||||
WidgetBackground(GetThemeBackground())
|
||||
WidgetText("Accessibility overlay", 40, 40, UI_TEXT_24, GetThemeText())
|
||||
DrawUICheckboxToggle(40,90,"Show focus/debug overlay",&enabled)
|
||||
if WidgetButton(40, 140, 200, 40, "Focusable Button", UI_BUTTON_STYLE_PRIMARY) {
|
||||
Background(GetThemeBackground())
|
||||
Text("Accessibility overlay", 40, 40, UI_TEXT_24, GetThemeText())
|
||||
Checkbox(1801,40,90,"Show focus/debug overlay",&enabled)
|
||||
if GenericButton(101, 40, 140, 200, 40, "Focusable Button", UI_BUTTON_STYLE_PRIMARY, 0, NULL) {
|
||||
enabled = !enabled
|
||||
}
|
||||
if enabled {
|
||||
DrawUIFocus((Rectangle){36,136,208,48})
|
||||
Focus((Rectangle){36,136,208,48})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#module "example_pictures"
|
||||
#import "kryon.h"
|
||||
#import "kryon_example_font.h"
|
||||
|
||||
app "Kryon Pictures" {
|
||||
size 640 420
|
||||
fps 60
|
||||
font examples
|
||||
theme THEME_CHERRY 0
|
||||
}
|
||||
|
||||
screen main {
|
||||
Background(GetThemeBackground())
|
||||
Text("Pictures are image nodes", ScaleUIPx(32), ScaleUIPx(30),
|
||||
UI_TEXT_24, GetThemeText())
|
||||
Stack((ColumnProps){
|
||||
.bounds = {ScaleUIPx(32), ScaleUIPx(82), ScaleUIPx(260), ScaleUIPx(210)},
|
||||
.key = Key("picture-card"),
|
||||
})
|
||||
Rect(ScaleUIPx(32), ScaleUIPx(82), ScaleUIPx(260), ScaleUIPx(210),
|
||||
GetThemeSurface(), GetThemeButton())
|
||||
Picture((PictureProps){"tiles/tile.png",
|
||||
(Rectangle){ScaleUIPx(52),ScaleUIPx(104),ScaleUIPx(96),ScaleUIPx(96)},
|
||||
(Rectangle){0,0,0,0},(Vector2){0,0},0.0f,WHITE,
|
||||
UI_PICTURE_FIT_CONTAIN})
|
||||
Picture((PictureProps){"pfp/lotus.png",
|
||||
(Rectangle){ScaleUIPx(168),ScaleUIPx(104),ScaleUIPx(96),ScaleUIPx(96)},
|
||||
(Rectangle){0,0,0,0},(Vector2){0,0},0.0f,WHITE,
|
||||
UI_PICTURE_FIT_CONTAIN})
|
||||
Text("Pictures keep their node bounds for editing",
|
||||
ScaleUIPx(52), ScaleUIPx(226), UI_TEXT_12, GetThemeIcon())
|
||||
End()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#import "kryon.h"
|
||||
|
||||
# Inner Breeze language screen — values traced from the native app
|
||||
# (INBE_TEXT_TRACE, UI scale 1.125): title "Choose Language" fs24 at
|
||||
# phys (159,32); label "Language" fs16 at (45,273); dropdown; "Next"
|
||||
# fs12 at (230,377). Authored in logical units (phys/1.125).
|
||||
|
||||
state {
|
||||
language_index: int = 0
|
||||
}
|
||||
|
||||
app "Inner Breeze — Language" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeBackground())
|
||||
Text("Choose Language", ScaleUIPx(141), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Language", ScaleUIPx(40), ScaleUIPx(243), UI_TEXT_16, GetThemeText())
|
||||
Dropdown(260, ScaleUIPx(39), ScaleUIPx(266), 391, ScaleUIPx(41), "English;Portugues;Espanol;Deutsch;Francais", &language_index)
|
||||
Text("Next", ScaleUIPx(204), ScaleUIPx(335), UI_TEXT_12, GetThemeText())
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#module "example_scene"
|
||||
#import "kryon.h"
|
||||
#import "kryon_example_font.h"
|
||||
|
||||
app "Kryon Scene Tree" {
|
||||
size 640 420
|
||||
fps 60
|
||||
font examples
|
||||
theme THEME_SKY 0
|
||||
scene main
|
||||
}
|
||||
|
||||
sprite_id :: int #global #export
|
||||
|
||||
scene main {
|
||||
camera := NodeCreate(scene, 0, NODE_CAMERA2D, "camera")
|
||||
NodeSetProps(scene, camera, KryCamera2DPropsAlloc(1.0, 1))
|
||||
|
||||
sprite_id = NodeCreate(scene, 0, NODE_SPRITE2D, "player")
|
||||
NodeSetPosition(scene, sprite_id, 320.0, 210.0)
|
||||
NodeSetProps(scene, sprite_id, KrySprite2DPropsAlloc("tiles/tile.png", 96.0, 96.0))
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#import "kryon.h"
|
||||
|
||||
# Declarative port of inbe's settings screen (device tab), in the same
|
||||
# spirit as the language picker: scrollable setting rows with toggles,
|
||||
# a language dropdown, orientation dropdown, and a fullscreen checkbox.
|
||||
# Everything the cartridge cannot own yet (persisting, system calls)
|
||||
# stays host-side; the layout, widgets, and conditional rows are
|
||||
# cartridge-owned.
|
||||
|
||||
state {
|
||||
scroll_off: int = 0
|
||||
language_index: int = 0
|
||||
orientation_index: int = 0
|
||||
fullscreen: int = 0
|
||||
keep_screen_on: int = 1
|
||||
}
|
||||
|
||||
app "Inner Breeze — Settings" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeSurface())
|
||||
Text("Settings", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Device", ScaleUIPx(40), ScaleUIPx(80), UI_TEXT_16, GetThemeIcon())
|
||||
Scroll(ScaleUIPx(40), ScaleUIPx(110), ScaleUIPx(400), ScaleUIPx(480), ScaleUIPx(820), &scroll_off)
|
||||
Text("Language", ScaleUIPx(40), ScaleUIPx(120), UI_TEXT_16, GetThemeText())
|
||||
Dropdown(101, ScaleUIPx(40), ScaleUIPx(146), ScaleUIPx(340), ScaleUIPx(36), "System;English;Portugues;Espanol;Deutsch", &language_index)
|
||||
Text("Orientation", ScaleUIPx(40), ScaleUIPx(230), UI_TEXT_16, GetThemeText())
|
||||
Dropdown(103, ScaleUIPx(40), ScaleUIPx(256), ScaleUIPx(340), ScaleUIPx(36), "System;Portrait;Landscape;Sensor", &orientation_index)
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(340), "Fullscreen", &fullscreen)
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(380), "Keep screen on", &keep_screen_on)
|
||||
if (fullscreen == 1) {
|
||||
Text("Restarts the app to apply", ScaleUIPx(40), ScaleUIPx(420), UI_TEXT_16, GetThemeIcon())
|
||||
} else {
|
||||
Text("Uses the display the app started on", ScaleUIPx(40), ScaleUIPx(420), UI_TEXT_16, GetThemeIcon())
|
||||
}
|
||||
if (keep_screen_on == 1) {
|
||||
Text("The screen stays awake during sessions", ScaleUIPx(40), ScaleUIPx(460), UI_TEXT_16, GetThemeIcon())
|
||||
}
|
||||
EndScroll()
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#module "example_signals"
|
||||
#import "kryon.h"
|
||||
#import "kryon_example_font.h"
|
||||
|
||||
app "Kryon Signals" {
|
||||
size 640 420
|
||||
fps 60
|
||||
font examples
|
||||
theme THEME_CHERRY 0
|
||||
scene main
|
||||
}
|
||||
|
||||
emitter :: int = 0 #global #export
|
||||
receiver :: int = 0 #global #export
|
||||
|
||||
scene main {
|
||||
emitter = NodeCreate(scene, 0, NODE_NODE2D, "emitter")
|
||||
receiver = NodeCreate(scene, 0, NODE_NODE2D, "receiver")
|
||||
connect emitter.hit to receiver.on_hit
|
||||
emit emitter.hit
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#import "kryon.h"
|
||||
|
||||
# Declarative port of inbe's manual screen: a scrollable breathing
|
||||
# guide. Long-form text in a scroll container — the screen class that
|
||||
# habits/learn screens share.
|
||||
|
||||
state {
|
||||
scroll_off: int = 0
|
||||
}
|
||||
|
||||
app "Inner Breeze — Manual" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeSurface())
|
||||
Text("Manual", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Scroll(ScaleUIPx(24), ScaleUIPx(80), ScaleUIPx(432), ScaleUIPx(520), ScaleUIPx(1250), &scroll_off)
|
||||
Text("Welcome to Inner Breeze", ScaleUIPx(24), ScaleUIPx(90), UI_TEXT_16, GetThemeText())
|
||||
Text("Inner Breeze guides breathing practices with gentle visual and audio cues.", ScaleUIPx(24), ScaleUIPx(120), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Box breathing", ScaleUIPx(24), ScaleUIPx(180), UI_TEXT_16, GetThemeText())
|
||||
Text("Inhale, hold, exhale, hold — four equal phases traced around a square.", ScaleUIPx(24), ScaleUIPx(210), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Start with four seconds per phase and lengthen gradually.", ScaleUIPx(24), ScaleUIPx(260), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Wim Hof method", ScaleUIPx(24), ScaleUIPx(320), UI_TEXT_16, GetThemeText())
|
||||
Text("Thirty deep breaths, a retention hold, and a recovery breath.", ScaleUIPx(24), ScaleUIPx(350), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Always practice seated and never in or near water.", ScaleUIPx(24), ScaleUIPx(400), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Meditation", ScaleUIPx(24), ScaleUIPx(460), UI_TEXT_16, GetThemeText())
|
||||
Text("Follow the expanding ring; the pause between breaths is the practice.", ScaleUIPx(24), ScaleUIPx(490), UI_TEXT_16, GetThemeIcon())
|
||||
DrawCircleV((Vector2){ScaleUIPx(240), ScaleUIPx(640)}, ScaleUIPx(60), (Color){0x2d, 0x4d, 0x7b, 0xff})
|
||||
DrawRing((Vector2){ScaleUIPx(240), ScaleUIPx(640)}, ScaleUIPx(66), ScaleUIPx(76), 0.0f, 360.0f, 0, (Color){0x70, 0x90, 0xc0, 0xff})
|
||||
Text("Habits", ScaleUIPx(24), ScaleUIPx(760), UI_TEXT_16, GetThemeText())
|
||||
Text("Small daily marks build streaks; missing one day is fine, two is a pattern.", ScaleUIPx(24), ScaleUIPx(790), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Scroll for more", ScaleUIPx(24), ScaleUIPx(1180), UI_TEXT_16, GetThemeIcon())
|
||||
EndScroll()
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#module "example_physics"
|
||||
#import "kryon.h"
|
||||
#import "kryon_example_font.h"
|
||||
|
||||
app "Kryon Physics" {
|
||||
size 640 420
|
||||
fps 60
|
||||
font examples
|
||||
theme THEME_SKY 0
|
||||
scene main
|
||||
}
|
||||
|
||||
#enum {
|
||||
GROUND_X = 320
|
||||
GROUND_Y = 380
|
||||
BOX_X = 320
|
||||
BOX_Y = 60
|
||||
}
|
||||
|
||||
scene main {
|
||||
ScenePhysicsCreate(scene, 0.0, 980.0)
|
||||
|
||||
ground := NodeCreate(scene, 0, NODE_BODY2D, "ground")
|
||||
NodeSetProps(scene, ground, KryBody2DPropsAlloc(KRY_BODY2D_STATIC))
|
||||
NodeSetPosition(scene, ground, GROUND_X, GROUND_Y)
|
||||
ground_shape := NodeCreate(scene, ground, NODE_COLLISION_SHAPE2D, "ground_shape")
|
||||
NodeSetProps(scene, ground_shape, KryCollisionShape2DPropsAlloc(KRY_SHAPE2D_BOX, 400.0, 32.0))
|
||||
|
||||
box := NodeCreate(scene, 0, NODE_BODY2D, "box")
|
||||
NodeSetProps(scene, box, KryBody2DPropsAlloc(KRY_BODY2D_DYNAMIC))
|
||||
NodeSetPosition(scene, box, BOX_X, BOX_Y)
|
||||
box_shape := NodeCreate(scene, box, NODE_COLLISION_SHAPE2D, "box_shape")
|
||||
NodeSetProps(scene, box_shape, KryCollisionShape2DPropsAlloc(KRY_SHAPE2D_BOX, 48.0, 48.0))
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#module "example_animation"
|
||||
#import "kryon.h"
|
||||
#import "kryon_example_font.h"
|
||||
|
||||
app "Kryon Animation" {
|
||||
size 640 420
|
||||
fps 60
|
||||
font examples
|
||||
theme THEME_SKY 0
|
||||
scene main
|
||||
}
|
||||
|
||||
#enum {
|
||||
CENTER_X = 320
|
||||
CENTER_Y = 210
|
||||
}
|
||||
|
||||
#global sprite_id :: int #export
|
||||
#global player_id :: int #export
|
||||
|
||||
scene main {
|
||||
sprite_id = NodeCreate(scene, 0, NODE_SPRITE2D, "mover")
|
||||
NodeSetPosition(scene, sprite_id, CENTER_X, CENTER_Y)
|
||||
NodeSetProps(scene, sprite_id, KrySprite2DPropsAlloc("tiles/tile.png", 64.0, 64.0))
|
||||
|
||||
player_id = NodeCreate(scene, 0, NODE_TIMER, "animator")
|
||||
props := KryAnimationPlayerPropsAlloc()
|
||||
NodeSetProps(scene, player_id, props)
|
||||
|
||||
anim := &props->anims[0]
|
||||
snprintf(anim->name, sizeof(anim->name), "bob")
|
||||
anim->duration = 2.0
|
||||
anim->loop = 1
|
||||
anim->track_count = 1
|
||||
track := &anim->tracks[0]
|
||||
track->target = sprite_id
|
||||
snprintf(track->property, sizeof(track->property), "position")
|
||||
track->component = 1
|
||||
track->interp = KRY_ANIM_INTERP_LINEAR
|
||||
track->keyframe_count = 2
|
||||
track->keyframes[0].time = 0.0
|
||||
track->keyframes[0].value = 160.0
|
||||
track->keyframes[1].time = 2.0
|
||||
track->keyframes[1].value = 260.0
|
||||
props->anim_count = 1
|
||||
props->current = 0
|
||||
props->playing = 1
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#import "kryon.h"
|
||||
|
||||
# Inner Breeze as ONE cartridge: three screens (language, settings,
|
||||
# manual) with cartridge-owned navigation. NavButton writes the screen
|
||||
# id to the `screen` state; each screen's widgets live under an
|
||||
# if (screen == N) guard. No host C anywhere.
|
||||
|
||||
state {
|
||||
screen: int = 0
|
||||
language_index: int = 0
|
||||
orientation_index: int = 0
|
||||
fullscreen: int = 0
|
||||
lang_scroll: int = 0
|
||||
set_scroll: int = 0
|
||||
man_scroll: int = 0
|
||||
}
|
||||
|
||||
app "Inner Breeze" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeSurface())
|
||||
if (screen == 0) {
|
||||
Text("Language", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Choose your language", ScaleUIPx(40), ScaleUIPx(250), UI_TEXT_16, GetThemeIcon())
|
||||
Dropdown(260, ScaleUIPx(40), ScaleUIPx(290), ScaleUIPx(340), ScaleUIPx(36), "English;Portugues;Espanol;Deutsch;Francais", &language_index)
|
||||
if (language_index == 0) {
|
||||
Text("Perfect for a calm start", ScaleUIPx(40), ScaleUIPx(380), UI_TEXT_16, GetThemeIcon())
|
||||
} else {
|
||||
Text("Otimo para um comeco calmo", ScaleUIPx(40), ScaleUIPx(380), UI_TEXT_16, GetThemeIcon())
|
||||
}
|
||||
NavButton("Next", ScaleUIPx(190), ScaleUIPx(430), ScaleUIPx(100), ScaleUIPx(40), &screen, 1)
|
||||
} else {
|
||||
if (screen == 1) {
|
||||
Text("Settings", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Device", ScaleUIPx(40), ScaleUIPx(80), UI_TEXT_16, GetThemeIcon())
|
||||
Scroll(ScaleUIPx(40), ScaleUIPx(110), ScaleUIPx(400), ScaleUIPx(440), ScaleUIPx(560), &set_scroll)
|
||||
Text("Language", ScaleUIPx(40), ScaleUIPx(120), UI_TEXT_16, GetThemeText())
|
||||
Dropdown(101, ScaleUIPx(40), ScaleUIPx(146), ScaleUIPx(340), ScaleUIPx(36), "System;English;Portugues", &language_index)
|
||||
Text("Orientation", ScaleUIPx(40), ScaleUIPx(230), UI_TEXT_16, GetThemeText())
|
||||
Dropdown(103, ScaleUIPx(40), ScaleUIPx(256), ScaleUIPx(340), ScaleUIPx(36), "System;Portrait;Landscape", &orientation_index)
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(340), "Fullscreen", &fullscreen)
|
||||
EndScroll()
|
||||
NavButton("Manual", ScaleUIPx(60), ScaleUIPx(570), ScaleUIPx(100), ScaleUIPx(40), &screen, 2)
|
||||
NavButton("Back", ScaleUIPx(320), ScaleUIPx(570), ScaleUIPx(100), ScaleUIPx(40), &screen, 0)
|
||||
} else {
|
||||
Text("Manual", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Scroll(ScaleUIPx(24), ScaleUIPx(80), ScaleUIPx(432), ScaleUIPx(470), ScaleUIPx(700), &man_scroll)
|
||||
Text("Welcome to Inner Breeze", ScaleUIPx(24), ScaleUIPx(90), UI_TEXT_16, GetThemeText())
|
||||
Text("Breathing practices with gentle visual and audio cues.", ScaleUIPx(24), ScaleUIPx(120), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Box breathing: four equal phases around a square.", ScaleUIPx(24), ScaleUIPx(190), UI_TEXT_16, GetThemeIcon())
|
||||
DrawCircleV((Vector2){ScaleUIPx(240), ScaleUIPx(330)}, ScaleUIPx(50), (Color){0x2d, 0x4d, 0x7b, 0xff})
|
||||
DrawRing((Vector2){ScaleUIPx(240), ScaleUIPx(330)}, ScaleUIPx(56), ScaleUIPx(64), 0.0f, 360.0f, 0, (Color){0x70, 0x90, 0xc0, 0xff})
|
||||
Text("Always practice seated and never near water.", ScaleUIPx(24), ScaleUIPx(440), UI_TEXT_16, GetThemeIcon())
|
||||
Text("Habits build streaks; missing one day is fine.", ScaleUIPx(24), ScaleUIPx(510), UI_TEXT_16, GetThemeIcon())
|
||||
EndScroll()
|
||||
NavButton("Back", ScaleUIPx(190), ScaleUIPx(570), ScaleUIPx(100), ScaleUIPx(40), &screen, 1)
|
||||
}
|
||||
}
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#import "kryon.h"
|
||||
|
||||
# Declarative port of inbe's habits screen: a scrollable list of habit
|
||||
# rows, each with a completion checkbox, a name, and a live streak
|
||||
# counter bound to state (TextFormat bound-text nodes re-render the
|
||||
# mounted ints every frame).
|
||||
|
||||
state {
|
||||
scroll_off: int = 0
|
||||
breathe_done: int = 1
|
||||
breathe_streak: int = 12
|
||||
stretch_done: int = 0
|
||||
stretch_streak: int = 3
|
||||
water_done: int = 1
|
||||
water_streak: int = 47
|
||||
journal_done: int = 0
|
||||
journal_streak: int = 0
|
||||
}
|
||||
|
||||
app "Inner Breeze — Habits" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeSurface())
|
||||
Text("Habits", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Today", ScaleUIPx(40), ScaleUIPx(80), UI_TEXT_16, GetThemeIcon())
|
||||
Scroll(ScaleUIPx(40), ScaleUIPx(110), ScaleUIPx(400), ScaleUIPx(490), ScaleUIPx(560), &scroll_off)
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(120), "Breathe 10 min", &breathe_done)
|
||||
TextFormat("Streak: %d days", breathe_streak, ScaleUIPx(250), ScaleUIPx(120), UI_TEXT_16, GetThemeIcon())
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(180), "Stretch", &stretch_done)
|
||||
TextFormat("Streak: %d days", stretch_streak, ScaleUIPx(250), ScaleUIPx(180), UI_TEXT_16, GetThemeIcon())
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(240), "Drink water", &water_done)
|
||||
TextFormat("Streak: %d days", water_streak, ScaleUIPx(250), ScaleUIPx(240), UI_TEXT_16, GetThemeIcon())
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(300), "Journal", &journal_done)
|
||||
TextFormat("Streak: %d days", journal_streak, ScaleUIPx(250), ScaleUIPx(300), UI_TEXT_16, GetThemeIcon())
|
||||
if (breathe_done == 1) {
|
||||
Text("Done for today", ScaleUIPx(40), ScaleUIPx(150), UI_TEXT_16, GetThemeIcon())
|
||||
}
|
||||
if (water_streak > 40) {
|
||||
Text("Almost two months strong", ScaleUIPx(40), ScaleUIPx(360), UI_TEXT_16, GetThemeIcon())
|
||||
}
|
||||
EndScroll()
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#module "example_tilemap"
|
||||
#import "kryon.h"
|
||||
#import "kryon_example_font.h"
|
||||
|
||||
app "Kryon Tilemap" {
|
||||
size 640 420
|
||||
fps 60
|
||||
font examples
|
||||
theme THEME_SKY 0
|
||||
scene main
|
||||
}
|
||||
|
||||
#enum {
|
||||
MAP_W = 10
|
||||
MAP_H = 6
|
||||
}
|
||||
|
||||
map_data :: [MAP_W * MAP_H] int #global #export
|
||||
|
||||
scene main {
|
||||
i := 0
|
||||
while i < MAP_W * MAP_H {
|
||||
map_data[i] = ((i + i / MAP_W) % 3) + 1
|
||||
i = i + 1
|
||||
}
|
||||
tiles := NodeCreate(scene, 0, NODE_TILEMAP, "tiles")
|
||||
NodeSetPosition(scene, tiles, 64.0, 64.0)
|
||||
props := KryTileMapPropsAlloc("tiles/tile.png", 32, 32, 4, MAP_W, MAP_H)
|
||||
props->tiles = map_data
|
||||
NodeSetProps(scene, tiles, props)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#import "kryon.h"
|
||||
|
||||
# Declarative port of inbe's practice config screen (Wim Hof tab):
|
||||
# sliders and spinboxes for rounds/breaths/hold, the pattern preview,
|
||||
# and the start button — exercising the CONTROL node range widgets.
|
||||
|
||||
state {
|
||||
rounds: int = 3
|
||||
breaths: int = 30
|
||||
hold: int = 60
|
||||
recovery: int = 15
|
||||
}
|
||||
|
||||
app "Inner Breeze — Practice" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeSurface())
|
||||
Text("Wim Hof", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Rounds", ScaleUIPx(40), ScaleUIPx(100), UI_TEXT_16, GetThemeText())
|
||||
TextFormat("x%d", rounds, ScaleUIPx(380), ScaleUIPx(100), UI_TEXT_16, GetThemeIcon())
|
||||
Slider(1, ScaleUIPx(40), ScaleUIPx(126), ScaleUIPx(340), "Rounds", 1, 10, &rounds)
|
||||
Text("Breaths per round", ScaleUIPx(40), ScaleUIPx(190), UI_TEXT_16, GetThemeText())
|
||||
TextFormat("%d", breaths, ScaleUIPx(380), ScaleUIPx(190), UI_TEXT_16, GetThemeIcon())
|
||||
Slider(2, ScaleUIPx(40), ScaleUIPx(216), ScaleUIPx(340), "Breaths", 20, 50, &breaths)
|
||||
Text("Retention hold (s)", ScaleUIPx(40), ScaleUIPx(280), UI_TEXT_16, GetThemeText())
|
||||
Spinbox(3, ScaleUIPx(40), ScaleUIPx(306), ScaleUIPx(160), ScaleUIPx(12), ScaleUIPx(240), 30, 120, 5, &hold)
|
||||
Text("Recovery (s)", ScaleUIPx(40), ScaleUIPx(380), UI_TEXT_16, GetThemeText())
|
||||
Spinbox(4, ScaleUIPx(40), ScaleUIPx(406), ScaleUIPx(160), ScaleUIPx(12), ScaleUIPx(240), 10, 30, 5, &recovery)
|
||||
DrawCircleV((Vector2){ScaleUIPx(240), ScaleUIPx(520)}, ScaleUIPx(46), (Color){0x2d, 0x4d, 0x7b, 0xff})
|
||||
DrawRing((Vector2){ScaleUIPx(240), ScaleUIPx(520)}, ScaleUIPx(52), ScaleUIPx(60), 0.0f, 360.0f, 0, (Color){0x70, 0x90, 0xc0, 0xff})
|
||||
Text("Start", ScaleUIPx(225), ScaleUIPx(510), UI_TEXT_16, GetThemeText())
|
||||
Button((ButtonProps){"Begin practice", (Rectangle){ScaleUIPx(140), ScaleUIPx(590), ScaleUIPx(200), ScaleUIPx(40)}, (Rectangle){0,0,0,0}, (Vector2){0,0}, 0.0f, WHITE, 0}, "start")
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#import "kryon.h"
|
||||
|
||||
# Declarative port of inbe's Wim Hof session screen: a live breathing
|
||||
# animation driven entirely by the cartridge's VM. TIME (ms) -> phase ->
|
||||
# triangle wave -> animated ring radius via AnimNode/OP_NODE_SET, with
|
||||
# breath counts and phase text bound to state.
|
||||
|
||||
state {
|
||||
started: int = -1
|
||||
elapsed: int = 0
|
||||
phase_step: int = 0
|
||||
tri: int = 0
|
||||
radius: int = 40
|
||||
breath: int = 1
|
||||
breaths_per_round: int = 30
|
||||
growing: int = 1
|
||||
}
|
||||
|
||||
app "Inner Breeze — WHM Session" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeSurface())
|
||||
if (started < 0) {
|
||||
started = TIME
|
||||
}
|
||||
elapsed = TIME - started
|
||||
phase_step = elapsed / 500
|
||||
tri = phase_step % 2
|
||||
if (tri == 0) {
|
||||
radius = 40
|
||||
} else {
|
||||
radius = 90
|
||||
}
|
||||
breath = phase_step / 2
|
||||
breath += 1
|
||||
if (breath > breaths_per_round) {
|
||||
breath = breaths_per_round
|
||||
}
|
||||
Text("Wim Hof Session", ScaleUIPx(70), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
TextFormat("Breath %d of %d", breath, ScaleUIPx(70), ScaleUIPx(70), UI_TEXT_16, GetThemeIcon())
|
||||
if (tri == 0) {
|
||||
Text("Breathe in", ScaleUIPx(200), ScaleUIPx(560), UI_TEXT_16, GetThemeText())
|
||||
} else {
|
||||
Text("Breathe out", ScaleUIPx(200), ScaleUIPx(560), UI_TEXT_16, GetThemeText())
|
||||
}
|
||||
DrawCircleV((Vector2){ScaleUIPx(240), ScaleUIPx(300)}, ScaleUIPx(36), (Color){0x2d, 0x4d, 0x7b, 0xff})
|
||||
DrawRing((Vector2){ScaleUIPx(240), ScaleUIPx(300)}, 44, ScaleUIPx(90), 0.0f, 360.0f, 0, (Color){0x70, 0x90, 0xc0, 0xff})
|
||||
AnimNode("ring0", "w", &radius)
|
||||
AnimNode("ring0", "h", &radius)
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
# Inner Breeze statistics screen cartridge
|
||||
#import "kryon.h"
|
||||
|
||||
|
||||
state {
|
||||
sessions: int = 24
|
||||
minutes: int = 186
|
||||
streak: int = 6
|
||||
best: int = 41
|
||||
bar1: int = 30
|
||||
bar2: int = 55
|
||||
bar3: int = 20
|
||||
bar4: int = 70
|
||||
bar5: int = 45
|
||||
bar6: int = 60
|
||||
bar7: int = 35
|
||||
}
|
||||
|
||||
app "Inner Breeze — Statistics" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeBackground())
|
||||
Text("Statistics", ScaleUIPx(141), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Sessions", ScaleUIPx(52), ScaleUIPx(88), UI_TEXT_12, GetThemeIcon())
|
||||
TextFormat("%d", sessions, ScaleUIPx(52), ScaleUIPx(102), UI_TEXT_16, GetThemeText())
|
||||
Text("Minutes", ScaleUIPx(184), ScaleUIPx(88), UI_TEXT_12, GetThemeIcon())
|
||||
TextFormat("%d", minutes, ScaleUIPx(184), ScaleUIPx(102), UI_TEXT_16, GetThemeText())
|
||||
Text("Streak", ScaleUIPx(316), ScaleUIPx(88), UI_TEXT_12, GetThemeIcon())
|
||||
TextFormat("%d days", streak, ScaleUIPx(316), ScaleUIPx(102), UI_TEXT_16, GetThemeText())
|
||||
Text("Best round", ScaleUIPx(52), ScaleUIPx(160), UI_TEXT_12, GetThemeIcon())
|
||||
TextFormat("%d breaths", best, ScaleUIPx(52), ScaleUIPx(174), UI_TEXT_16, GetThemeText())
|
||||
Text("This week", ScaleUIPx(52), ScaleUIPx(240), UI_TEXT_16, GetThemeText())
|
||||
Rect(ScaleUIPx(52), ScaleUIPx(270), ScaleUIPx(16), bar1, GetThemeButton())
|
||||
Rect(ScaleUIPx(76), ScaleUIPx(270), ScaleUIPx(16), bar2, GetThemeButton())
|
||||
Rect(ScaleUIPx(100), ScaleUIPx(270), ScaleUIPx(16), bar3, GetThemeButton())
|
||||
Rect(ScaleUIPx(124), ScaleUIPx(270), ScaleUIPx(16), bar4, GetThemeButton())
|
||||
Rect(ScaleUIPx(148), ScaleUIPx(270), ScaleUIPx(16), bar5, GetThemeButton())
|
||||
Rect(ScaleUIPx(172), ScaleUIPx(270), ScaleUIPx(16), bar6, GetThemeButton())
|
||||
Rect(ScaleUIPx(196), ScaleUIPx(270), ScaleUIPx(16), bar7, GetThemeButton())
|
||||
Text("M T W T F S S", ScaleUIPx(50), ScaleUIPx(340), UI_TEXT_12, GetThemeIcon())
|
||||
Text("Totals update after each session", ScaleUIPx(52), ScaleUIPx(400), UI_TEXT_12, GetThemeIcon())
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# Inner Breeze profile screen cartridge
|
||||
#import "kryon.h"
|
||||
|
||||
# The native's profile screen: avatar circle, name, handle, stats row
|
||||
# (streak / sessions / best), and action rows. Values bound to state.
|
||||
|
||||
state {
|
||||
streak: int = 12
|
||||
sessions: int = 24
|
||||
best: int = 41
|
||||
}
|
||||
|
||||
app "Inner Breeze Profile" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeBackground())
|
||||
DrawCircleV((Vector2){ScaleUIPx(200), ScaleUIPx(70)}, ScaleUIPx(36), GetThemeButton())
|
||||
DrawRing((Vector2){ScaleUIPx(200), ScaleUIPx(70)}, ScaleUIPx(40), ScaleUIPx(44), 0.0f, 360.0f, 0, GetThemeIcon())
|
||||
Text("Wao", ScaleUIPx(196), ScaleUIPx(128), UI_TEXT_24, GetThemeText())
|
||||
Text("local profile", ScaleUIPx(184), ScaleUIPx(158), UI_TEXT_12, GetThemeIcon())
|
||||
Text("Streak", ScaleUIPx(60), ScaleUIPx(210), UI_TEXT_12, GetThemeIcon())
|
||||
TextFormat("%d days", streak, ScaleUIPx(60), ScaleUIPx(224), UI_TEXT_16, GetThemeText())
|
||||
Text("Sessions", ScaleUIPx(200), ScaleUIPx(210), UI_TEXT_12, GetThemeIcon())
|
||||
TextFormat("%d", sessions, ScaleUIPx(200), ScaleUIPx(224), UI_TEXT_16, GetThemeText())
|
||||
Text("Best", ScaleUIPx(340), ScaleUIPx(210), UI_TEXT_12, GetThemeIcon())
|
||||
TextFormat("%d", best, ScaleUIPx(340), ScaleUIPx(224), UI_TEXT_16, GetThemeText())
|
||||
Text("Sync", ScaleUIPx(40), ScaleUIPx(300), UI_TEXT_16, GetThemeText())
|
||||
Text("Not configured", ScaleUIPx(200), ScaleUIPx(300), UI_TEXT_12, GetThemeIcon())
|
||||
Text("Export data", ScaleUIPx(40), ScaleUIPx(350), UI_TEXT_16, GetThemeText())
|
||||
Text("Import data", ScaleUIPx(40), ScaleUIPx(400), UI_TEXT_16, GetThemeText())
|
||||
Button((ButtonProps){"Sign out", (Rectangle){ScaleUIPx(150), ScaleUIPx(460), ScaleUIPx(180), ScaleUIPx(40)}, (Rectangle){0,0,0,0}, (Vector2){0,0}, 0.0f, WHITE, 1}, "signout")
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
# Inner Breeze habit-edit screen cartridge
|
||||
#import "kryon.h"
|
||||
|
||||
# The native's habit editor: name field, schedule checkboxes, reminder
|
||||
# dropdown, interval spinbox, save button.
|
||||
|
||||
state {
|
||||
name: char[64] = "Meditate"
|
||||
mon: int = 1
|
||||
tue: int = 1
|
||||
wed: int = 0
|
||||
thu: int = 1
|
||||
fri: int = 0
|
||||
sat: int = 0
|
||||
sun: int = 0
|
||||
reminder_index: int = 1
|
||||
interval: int = 1
|
||||
}
|
||||
|
||||
app "Inner Breeze Habit Edit" {
|
||||
size 480 640
|
||||
fps 60
|
||||
frame main
|
||||
}
|
||||
|
||||
frame main {
|
||||
BeginDrawing()
|
||||
ClearBackground(GetThemeBackground())
|
||||
BeginUIFrame(GetScreenWidth(), GetScreenHeight(), GetUIScale())
|
||||
Background(GetThemeBackground())
|
||||
Text("Edit habit", ScaleUIPx(155), ScaleUIPx(28), UI_TEXT_24, GetThemeText())
|
||||
Text("Name", ScaleUIPx(40), ScaleUIPx(90), UI_TEXT_16, GetThemeText())
|
||||
TextField(ScaleUIPx(40), ScaleUIPx(116), ScaleUIPx(340), ScaleUIPx(36), &name)
|
||||
Text("Days", ScaleUIPx(40), ScaleUIPx(180), UI_TEXT_16, GetThemeText())
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(206), "Mon", &mon)
|
||||
Checkbox(0, ScaleUIPx(140), ScaleUIPx(206), "Tue", &tue)
|
||||
Checkbox(0, ScaleUIPx(240), ScaleUIPx(206), "Wed", &wed)
|
||||
Checkbox(0, ScaleUIPx(340), ScaleUIPx(206), "Thu", &thu)
|
||||
Checkbox(0, ScaleUIPx(40), ScaleUIPx(240), "Fri", &fri)
|
||||
Checkbox(0, ScaleUIPx(140), ScaleUIPx(240), "Sat", &sat)
|
||||
Checkbox(0, ScaleUIPx(240), ScaleUIPx(240), "Sun", &sun)
|
||||
if (mon + tue + wed + thu + fri + sat + sun < 1) {
|
||||
Text("Pick at least one day", ScaleUIPx(40), ScaleUIPx(280), UI_TEXT_12, GetThemeIcon())
|
||||
} else {
|
||||
Text("Schedule looks good", ScaleUIPx(40), ScaleUIPx(280), UI_TEXT_12, GetThemeIcon())
|
||||
}
|
||||
Text("Reminder", ScaleUIPx(40), ScaleUIPx(320), UI_TEXT_16, GetThemeText())
|
||||
Dropdown(9, ScaleUIPx(40), ScaleUIPx(346), ScaleUIPx(340), ScaleUIPx(36), "Off;Morning;Evening", &reminder_index)
|
||||
Text("Repeat every", ScaleUIPx(40), ScaleUIPx(400), UI_TEXT_16, GetThemeText())
|
||||
Spinbox(4, ScaleUIPx(40), ScaleUIPx(426), ScaleUIPx(160), ScaleUIPx(12), ScaleUIPx(240), 1, 7, 1, &interval)
|
||||
Button((ButtonProps){"Save", (Rectangle){ScaleUIPx(150), ScaleUIPx(500), ScaleUIPx(180), ScaleUIPx(40)}, (Rectangle){0,0,0,0}, (Vector2){0,0}, 0.0f, WHITE, 0}, "save")
|
||||
EndUIFocus()
|
||||
EndDrawing()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
# Native make shim. The canonical build is the GNU Makefile.
|
||||
# Native BSD make shim. The canonical build is the GNU Makefile.
|
||||
GMAKE ?= gmake
|
||||
|
||||
.MAIN: all
|
||||
+71
-17
@@ -3,8 +3,27 @@
|
||||
CC ?= cc
|
||||
CFLAGS_BASE ?= -Wall -Wextra -O2
|
||||
CFLAGS = $(CFLAGS_BASE) -I. -I../include
|
||||
LDFLAGS = -L.. -lkryon
|
||||
LDFLAGS = -L$(KRYON_BUILD_DIR) -lkryon
|
||||
UNAME_S := $(shell uname -s)
|
||||
UNAME_M := $(shell uname -m)
|
||||
ifeq ($(UNAME_M),amd64)
|
||||
KRYON_ARCH := x86_64
|
||||
else
|
||||
KRYON_ARCH := $(UNAME_M)
|
||||
endif
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
KRYON_PLATFORM := linux
|
||||
else ifeq ($(UNAME_S),FreeBSD)
|
||||
KRYON_PLATFORM := freebsd
|
||||
else ifeq ($(UNAME_S),Darwin)
|
||||
KRYON_PLATFORM := macos
|
||||
else
|
||||
KRYON_PLATFORM := $(UNAME_S)
|
||||
endif
|
||||
# kryon archives libkryon.a under its platform-tagged build dir (not the repo root),
|
||||
# so the host platform must be derived the same way as kryon's own Makefile.
|
||||
KRYON_BUILD_DIR := ../build/$(KRYON_PLATFORM)-$(KRYON_ARCH)
|
||||
KRYON_LIB := $(KRYON_BUILD_DIR)/libkryon.a
|
||||
GL_X11_PKG_LIBS := $(shell pkg-config --libs gl x11 2>/dev/null || printf '%s' '-L/usr/local/lib -lGL -lX11')
|
||||
GTK_PKG_CFLAGS := $(shell pkg-config --cflags gtk+-3.0 2>/dev/null)
|
||||
GTK_PKG_LIBS := $(shell pkg-config --libs gtk+-3.0 2>/dev/null)
|
||||
@@ -16,14 +35,25 @@ RAY_GL_LDLIBS ?= $(shell pkg-config --libs libdrm gbm egl glesv2 2>/dev/null)
|
||||
RAY_CFLAGS ?= $(strip $(RAY_SDL_CFLAGS) $(RAY_GL_CFLAGS))
|
||||
RAY_LDLIBS ?= $(strip $(RAY_SDL_LDLIBS) $(RAY_GL_LDLIBS))
|
||||
RAY_SDL_INCLUDE_DIR ?= $(shell pkg-config --variable=includedir sdl2 2>/dev/null | sed 's,/SDL2$$,,')
|
||||
EXAMPLE_SYSTEM_LDLIBS := $(RAY_LDLIBS) $(GL_X11_PKG_LIBS) $(GTK_PKG_LIBS) -lm -lpthread
|
||||
# Backend selection mirroring the root Makefile; examples link libkryon.a
|
||||
# (built with the same KRYON_BACKEND below) plus the backend's own libs.
|
||||
KRYON_BACKEND ?= raylib
|
||||
ifeq ($(KRYON_BACKEND),raylib)
|
||||
EXAMPLE_BACKEND_LIBS = $(RAYLIB_A)
|
||||
EXAMPLE_BACKEND_LDLIBS = $(RAY_LDLIBS)
|
||||
else
|
||||
EXAMPLE_BACKEND_LIBS =
|
||||
EXAMPLE_BACKEND_LDLIBS =
|
||||
endif
|
||||
EXAMPLE_SYSTEM_LDLIBS := $(EXAMPLE_BACKEND_LDLIBS) $(GL_X11_PKG_LIBS) $(GTK_PKG_LIBS) -lm -lpthread
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
EXAMPLE_SYSTEM_LDLIBS += -ldl -lrt
|
||||
endif
|
||||
KRYON_DIR := ..
|
||||
FONT_OUTPUTS := $(wildcard ../fonts/noto/*.ttf ../fonts/noto/*.otf)
|
||||
BUILD_DIR ?= ../build/examples
|
||||
KC ?= ../build/bin/kc
|
||||
K2C ?= ../build/bin/k2c
|
||||
K2B ?= ../build/bin/k2b
|
||||
CODEGEN_DIR := $(BUILD_DIR)/codegen
|
||||
BIN_DIR := $(BUILD_DIR)/bin
|
||||
RAYLIB_BUILD_DIR := $(BUILD_DIR)/raylib-native
|
||||
@@ -43,8 +73,20 @@ WEB_SHELL := web_shell.html
|
||||
EXAMPLES_WEB_SITE_DIR ?= ../build/site/examples
|
||||
include ../mk/raylib.mk
|
||||
KRYON_LIBRARY_SRCS := $(shell find ../src -type f -name '*.c' | LC_ALL=C sort)
|
||||
KRYON_WEB_SRCS := $(filter-out ../src/file_dialog/file_dialog.c,$(KRYON_LIBRARY_SRCS)) $(WEB_EMBED_ASSETS_C) $(KRYON_RAYLIB_WRAPPERS_C)
|
||||
KRYON_ALL_WEB_SRCS := $(KRYON_LIBRARY_SRCS) $(WEB_EMBED_ASSETS_C) $(KRYON_RAYLIB_WRAPPERS_C)
|
||||
ifeq ($(KRYON_BACKEND),raylib)
|
||||
KRYON_EXAMPLES_WEB_BACKEND_C := $(KRYON_RAYLIB_WRAPPERS_C)
|
||||
KRYON_EXAMPLES_WEB_BACKEND_LIBS := $(WEB_RAYLIB_A)
|
||||
else ifeq ($(KRYON_BACKEND),canvas)
|
||||
KRYON_EXAMPLES_WEB_BACKEND_C := ../src/backend/canvas_backend.c
|
||||
KRYON_EXAMPLES_WEB_BACKEND_LIBS :=
|
||||
else ifeq ($(KRYON_BACKEND),null)
|
||||
KRYON_EXAMPLES_WEB_BACKEND_C := $(KRYON_NULL_BACKEND_C)
|
||||
KRYON_EXAMPLES_WEB_BACKEND_LIBS :=
|
||||
else
|
||||
$(error Unknown KRYON_BACKEND '$(KRYON_BACKEND)' (expected raylib, canvas, or null))
|
||||
endif
|
||||
KRYON_WEB_SRCS := $(filter-out ../src/file_dialog/file_dialog.c,$(KRYON_LIBRARY_SRCS)) $(WEB_EMBED_ASSETS_C) $(KRYON_EXAMPLES_WEB_BACKEND_C)
|
||||
KRYON_ALL_WEB_SRCS := $(KRYON_LIBRARY_SRCS) $(WEB_EMBED_ASSETS_C) $(KRYON_EXAMPLES_WEB_BACKEND_C)
|
||||
WEB_CFLAGS := -Wall -Wextra -std=gnu99 -O0 -DPLATFORM_WEB -DGRAPHICS_API_OPENGL_ES2 -D_DEFAULT_SOURCE -DSUPPORT_MODULE_RAUDIO=1 -DSUPPORT_FILEFORMAT_JPG=1 -DSUPPORT_FILEFORMAT_OGG=1 -DSUPPORT_FILEFORMAT_MP3=1 -DUI_EMBEDDED_ONLY=1 -DHAS_LIBOQS=1 -I$(KRYON_WEB_LIBOQS_BUILD_DIR)/include
|
||||
WEB_LDFLAGS := -sUSE_GLFW=3 -sALLOW_MEMORY_GROWTH=1 -sASYNCIFY -sINITIAL_MEMORY=134217728 -sSTACK_SIZE=8388608 -sGLOBAL_BASE=16777216
|
||||
WEB_PRELOAD_FLAGS ?= $(if $(wildcard $(EMSCRIPTEN_FILE_PACKAGER)),--preload-file ../fonts/noto@fonts/noto,)
|
||||
@@ -56,23 +98,24 @@ ifneq ($(NIX_CFLAGS_COMPILE),)
|
||||
CFLAGS += $(NIX_CFLAGS_COMPILE)
|
||||
endif
|
||||
|
||||
LDFLAGS += $(RAYLIB_A) $(EXAMPLE_SYSTEM_LDLIBS)
|
||||
LDFLAGS += $(EXAMPLE_BACKEND_LIBS) $(EXAMPLE_SYSTEM_LDLIBS)
|
||||
|
||||
EXAMPLES = 01_file_dialog 02_buttons 03_theme 04_modal 05_color 06_scaling 07_layout \
|
||||
09_geometry 10_menus 11_basic_controls 12_collections 13_text_editor \
|
||||
14_canvas 15_containers 16_dialogs 17_keyboard_platform 18_accessibility
|
||||
14_canvas 15_containers 16_dialogs 17_keyboard_platform 18_accessibility \
|
||||
19_pictures 20_scene 21_signals 22_physics 23_animation 24_tilemap
|
||||
EXAMPLE_BINS := $(addprefix $(BIN_DIR)/,$(EXAMPLES))
|
||||
|
||||
.PHONY: all clean run list font-assets web web-clean
|
||||
.SECONDARY: $(addprefix $(CODEGEN_DIR)/,$(addsuffix .c,$(EXAMPLES))) $(addprefix $(CODEGEN_DIR)/,$(addsuffix .h,$(EXAMPLES)))
|
||||
|
||||
all: ../libkryon.a $(KC) $(EXAMPLE_BINS)
|
||||
all: $(KRYON_LIB) $(K2C) $(EXAMPLE_BINS) $(BIN_DIR)/02_buttons_krb
|
||||
|
||||
../libkryon.a:
|
||||
@$(MAKE) -C ..
|
||||
$(KRYON_LIB):
|
||||
@$(MAKE) -C .. KRYON_BACKEND=$(KRYON_BACKEND)
|
||||
|
||||
$(KC):
|
||||
@$(MAKE) -C .. build/bin/kc
|
||||
$(K2C):
|
||||
@$(MAKE) -C .. build/bin/k2c
|
||||
|
||||
font-assets:
|
||||
@printf '%s\n' 'font assets are checked in'
|
||||
@@ -83,11 +126,20 @@ $(CODEGEN_DIR):
|
||||
$(BIN_DIR):
|
||||
@mkdir -p $@
|
||||
|
||||
$(CODEGEN_DIR)/%.c $(CODEGEN_DIR)/%.h: %.kry $(KC) | $(CODEGEN_DIR)
|
||||
$(CODEGEN_DIR)/%.c $(CODEGEN_DIR)/%.h: %.kry $(K2C) | $(CODEGEN_DIR)
|
||||
@echo "Generating $*..."
|
||||
@$(KC) --root . -o $(CODEGEN_DIR) $<
|
||||
@$(K2B) --root . -o $(CODEGEN_DIR) $<
|
||||
|
||||
$(BIN_DIR)/%: $(CODEGEN_DIR)/%.c ../libkryon.a $(RAYLIB_A) $(FONT_OUTPUTS) | $(BIN_DIR)
|
||||
$(CODEGEN_DIR)/02_buttons.krb.c $(CODEGEN_DIR)/02_buttons.krb.h: 02_buttons.kry $(K2C) | $(CODEGEN_DIR)
|
||||
@echo "Generating 02_buttons cartridge..."
|
||||
@$(K2B) --root . -o $(CODEGEN_DIR) $<
|
||||
|
||||
$(BIN_DIR)/02_buttons_krb: $(CODEGEN_DIR)/02_buttons.krb.c $(KRYON_LIB) $(EXAMPLE_BACKEND_LIBS) $(FONT_OUTPUTS) | $(BIN_DIR)
|
||||
@echo "Building $@..."
|
||||
@$(CC) $(CFLAGS) -o $@ $(CODEGEN_DIR)/02_buttons.krb.c $(LDFLAGS)
|
||||
@echo "Built: $@"
|
||||
|
||||
$(BIN_DIR)/%: $(CODEGEN_DIR)/%.c $(KRYON_LIB) $(EXAMPLE_BACKEND_LIBS) $(FONT_OUTPUTS) | $(BIN_DIR)
|
||||
@echo "Building $@..."
|
||||
@$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
|
||||
@echo "Built: $@"
|
||||
@@ -102,7 +154,7 @@ $(BUILD_DIR):
|
||||
$(WEB_EMBED_ASSETS_C): $(WEB_EMBED_ASSET_FILES) ../scripts/embed-assets.sh ../include/embedded_assets.h | $(BUILD_DIR)
|
||||
sh ../scripts/embed-assets.sh $@ ../themes
|
||||
|
||||
$(EXAMPLES_WEB_SITE_DIR)/%/index.html: $(CODEGEN_DIR)/%.c $(FONT_OUTPUTS) $(WEB_RAYLIB_A) $(KRYON_WEB_LIBOQS_A) $(WEB_EMBED_ASSETS_C) $(WEB_SHELL)
|
||||
$(EXAMPLES_WEB_SITE_DIR)/%/index.html: $(CODEGEN_DIR)/%.c $(FONT_OUTPUTS) $(KRYON_EXAMPLES_WEB_BACKEND_LIBS) $(KRYON_WEB_LIBOQS_A) $(WEB_EMBED_ASSETS_C) $(WEB_SHELL)
|
||||
@echo "Building web example $*..."
|
||||
@mkdir -p $(dir $@)
|
||||
$(WEB_CC) $(WEB_CFLAGS) \
|
||||
@@ -110,7 +162,7 @@ $(EXAMPLES_WEB_SITE_DIR)/%/index.html: $(CODEGEN_DIR)/%.c $(FONT_OUTPUTS) $(WEB_
|
||||
-o $(dir $@)/index.js \
|
||||
$< \
|
||||
$(if $(filter 01_file_dialog,$*),$(KRYON_ALL_WEB_SRCS),$(KRYON_WEB_SRCS)) \
|
||||
$(WEB_RAYLIB_A) \
|
||||
$(KRYON_EXAMPLES_WEB_BACKEND_LIBS) \
|
||||
$(KRYON_WEB_LIBOQS_A) \
|
||||
$(WEB_LDFLAGS) \
|
||||
$(WEB_PRELOAD_FLAGS)
|
||||
@@ -151,6 +203,7 @@ run:
|
||||
@echo " 15) dialogs"
|
||||
@echo " 16) keyboard_platform"
|
||||
@echo " 17) accessibility"
|
||||
@echo " 18) pictures"
|
||||
@echo ""
|
||||
@read -p "Enter example number: " num; \
|
||||
case "$$num" in \
|
||||
@@ -171,6 +224,7 @@ run:
|
||||
15) example="16_dialogs";; \
|
||||
16) example="17_keyboard_platform";; \
|
||||
17) example="18_accessibility";; \
|
||||
18) example="19_pictures";; \
|
||||
*) example=;; \
|
||||
esac; \
|
||||
if [ -n "$$example" ]; then \
|
||||
|
||||
Loaded 100 of 342 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user