Compare commits

...
Author SHA1 Message Date
waozi c26b7ec943 Fix web build: include <stddef.h> for NULL in platform_thread.c
platform_thread.c uses NULL but only included <stdlib.h> under _WIN32.
On native, <pthread.h> (pulled in by platform.h) transitively provides
NULL, so the build passed. Emscripten's stricter header setup under
-DUI_EMBEDDED_ONLY does not, causing:

  error: use of undeclared identifier 'NULL'

Add the standard <stddef.h> include unconditionally.
2026-07-26 10:58:16 -05:00
waozi 22afa3105d Make text input focus persistent and single-owner across frames 2026-07-25 21:23:45 -05:00
waozi 5db666b64e Update website code sample to verb-free Kry syntax
The Get Started example still showed the removed 'draw' verb. Switch it
to bare calls (WidgetText, app_draw_bottom_nav) to match the v0.1.7
language. inbe's own .kry files live in the separate inbe repo and are
updated there, not here.
2026-07-25 21:13:43 -05:00
github-actions[bot] 711a9c4be8 Update CHANGELOG for v0.1.7 2026-07-26 02:02:20 +00:00
waozi 73220d9c25 Bump version to v0.1.7 2026-07-25 21:00:24 -05:00
waozi d403c726a7 Remove native_widget_name compiler name-rewrite hack
kc silently rewrote a few widget call names (Text->DrawUIText,
TextButton->DrawUITextButton, CenteredColumn->GetUICenteredColumn,
ScrollEnd->EndUIScrollPage) inside emit_call. That was library behavior
baked into the compiler — exactly the kind of hack that shouldn't exist:
the compiler must not know widget names. Calls now pass through verbatim.

No source used the aliased names (examples already call the real
WidgetText/GetUICenteredColumn), so this is pure dead-code removal.
make test passes.
2026-07-25 17:07:58 -05:00
waozi 63a8c366a2 Finish removing Kry sugar verbs — language is now minimal
The previous pass removed the redundant call/assignment verbs (draw,
native, set, widget) and the widget keywords (text/rect/line/background/
swatch). This pass removes the remaining bespoke sugar so the statement
language is just declarations, assignments, calls, and control flow:

Removed (now fatal errors with migration hints):
- advance x by N   -> x += N
- clamp_min/max x N -> if (x < N) x = N
- c_rect name = .. -> name: Rectangle = (Rectangle){..}
- texture name = .. -> name: Texture2D = ..
- set_theme id mode -> SetCurrentTheme(id, mode)
- button label {..} -> if WidgetButton(x, y, w, h, label, style) {..}
- on key K {..}     -> if (UIKeyPressed(K)) {..}
- on key_down K {..}-> if (UIKeyDown(K)) {..}
- event/on expr {..}-> if (expr) {..}
- icon_button .. {..}-> if DrawUIIconButton((UIIconButton){..}) {..}

Also moved the background/set_theme fatal-error arms ahead of the
line_is_c_uninit_decl heuristic in the dispatcher, since the heuristic
was swallowing them as bogus 'TYPE NAME' C declarations.

What remains in parse_statement: control flow (if/else/for/while/switch/
case/default/guard/return/break/continue/goto/labels), declarations
(name :=, name: T =), assignments (incl. compound), bare calls, enum,
and the two escape hatches (c, unused). Rewrote the 9 example files that
used button/on-key (22 sites). Extended kc_syntax_test.sh to assert each
removed sugar keyword now errors. make clean && make all test passes.

KRY_LANGUAGE_PLAN.md updated to document the final minimal statement set.
2026-07-25 17:04:29 -05:00
waozi 236ea20a1a Remove redundant Kry verbs; widgets are now a library
The Kry statement language had a tangle of overlapping verbs (draw,
native, set, widget, text, rect, line, background, swatch) that all did
minor variants of the same thing: emit a call or assignment statement.
This removes the redundant ones and replaces the widget keywords with an
ordinary library of functions, so 'widget' is a convention (a function
that draws) rather than compiler syntax.

Removed statement verbs (now fatal errors with a migration hint):
- draw / widget  -> call the expression directly; bare call statements
  already wrap with PushUIInspectSource/PopUIInspectSource, so
  click-to-source keeps working with no keyword.
- native         -> call the expression directly.
- set            -> write the assignment/call directly.
- text/rect/line/background/swatch -> call the matching Widget* library
  function (WidgetText, WidgetRect, WidgetLine, WidgetBackground).

Kept keywords earn their place: button, on/event, icon_button,
set_theme, advance, clamp_min/max, c_rect, texture, c, unused, and all
control flow.

New widget library (include/ui_widgets.h, src/ui/ui_widgets.c):
WidgetText, WidgetRect, WidgetLine, WidgetBackground, WidgetButton —
ordinary C functions wrapping the existing DrawUI* primitives, with the
same defaults the removed keywords used. Included via kryon.h.

Rewrote all 17 example .kry files to the verb-free syntax (positional
args; named args deferred to a later phase since kc has no parameter
table). Updated kc_syntax_test.sh: the 'valid' screen and cross-file
tests no longer use removed verbs, and new tests assert that each
removed verb errors with a migration message.

Regenerated icon assets pick up the freebsd/macos platform PNGs added
earlier.

make clean && make all test passes (kc syntax, raylib compat, runtime).
2026-07-25 12:54:52 -05:00
waozi e4659ea31f Rework Platforms grid: add Windows, macOS, FreeBSD
Replace the Native and Network placeholder cards with concrete
targets that Kryon actually ships: Windows (native + WinINet assets),
macOS (native desktop builds), and FreeBSD (native/embedded). Native
and Network were not first-class runtime targets.

Add hand-drawn 16x16 pixel-art icons for FreeBSD (beastie devil head)
and macOS (graphite apple) to match the existing tux/droid/win/wasm
icon set, plus a generator script for reproducibility.
2026-07-25 10:15:50 -05:00
waozi 674af78687 Make text input focus exclusive across UITextField and UITextArea
UITextField and UITextArea tracked focus with separate, uncoordinated
globals (g_ui_text_field_drag_id vs g_ui_text_area_drag_id). Clicking one
type never cleared the other's focused flag, so two text inputs could
appear focused at once: e.g. focusing a habit's multiline description
left the title field's cursor blinking on the shared GetTime() phase.

Introduce a single text-focus owner (the address of the focused widget's
 flag). Each frame the owner resets; a widget keeps focus only
while it remains the owner, and claiming focus on click/drag displaces
any other text widget. This works across widget types without relying on
focus_id, which defaults to 0 and is shared when the caller leaves it
unset.

Also fixes the latent drag collision: with focus_id unset, the drag-down
branch (g_ui_text_*_drag_id == field.focus_id == 0) matched every field,
re-asserting focus on unrelated fields while the mouse was held.
2026-07-25 08:59:24 -05:00
github-actions[bot] 3f5d8254c3 Update CHANGELOG for v0.1.6 2026-07-25 13:34:48 +00:00
waozi 62c76fdb8e Bump version to v0.1.6 2026-07-25 08:33:12 -05:00
waozi c478df4896 Resolve tray icon from installed hicolor paths
GetDesktopTrayIconPath previously only checked next to the executable and
the caller-supplied (often CWD-relative) candidate paths. When the app is
launched from a menu, .desktop file, or AppImage, the CWD is typically the
home directory, so neither probe found the icon and the tray fell back to a
generic/blank icon.

Also probe the standard installed locations:
  - <exedir>/../share/icons/hicolor/<size>/apps/<icon>.png
  - /usr/local/share:/usr/share/icons/hicolor/<size>/apps/<icon>.png
    (default /usr/local/share:/usr/share)

Sizes are tried largest-first for the sharpest rendering.
2026-07-25 08:31:14 -05:00
waozi 19b1137657 Fix site card cursors, release CI, and IDE recent-projects grid
Website:
- Apply hand cursor to feature/platform/goal cards so hover feedback
  matches their clickable affordance.

Release CI (releases were broken since v0.1.4):
- Fix the root cause: vendored curl needs -lzstd/-lbrotli but the link
  line never got them. Query each codec library independently instead
  of one pkg-config call that collapses to empty if any package is
  missing, and install libzstd-dev/libbrotli-dev on the release runner.
- Auto-generate a CHANGELOG.md entry from commits since the last tag
  when a version.h bump has no hand-written entry, instead of failing
  the build. This makes releases fully automatic: bump version.h, push,
  get a tagged release with a proper changelog.

IDE start page:
- Render recent projects as a responsive grid (matching the examples
  grid) instead of a single full-width column.
2026-07-25 08:19:45 -05:00
waozi 07dba94d0e Trigger site deploy (previous run hit GitHub internal error) 2026-07-25 07:56:46 -05:00
39 changed files with 886 additions and 553 deletions

No files matched your search

+46 -3
View File
@@ -38,7 +38,7 @@ jobs:
fetch-depth: 0
submodules: recursive
- name: Validate Version
- name: Resolve Version
id: version
run: |
set -euo pipefail
@@ -51,7 +51,6 @@ jobs:
v[0-9]*.[0-9]*.[0-9]*) ;;
*) echo "Version must look like v0.1.0" >&2; exit 1 ;;
esac
grep -q "^## $tag " CHANGELOG.md
if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
echo "Tag $tag already exists; nothing to release."
echo "tag=" >> "$GITHUB_OUTPUT"
@@ -59,6 +58,50 @@ jobs:
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- name: Ensure CHANGELOG Entry
if: steps.version.outputs.tag != ''
run: |
set -euo pipefail
tag="${{ steps.version.outputs.tag }}"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# If the entry already exists (hand-written by a maintainer), use it as-is.
if grep -q "^## $tag " CHANGELOG.md; then
echo "CHANGELOG entry for $tag already present."
exit 0
fi
# Otherwise generate one from commits since the most recent tag.
prev_tag="$(git describe --tags --abbrev=0 2>/dev/null || true)"
date="$(date +%Y-%m-%d)"
range="${prev_tag:+$prev_tag..}HEAD"
range="${range:-HEAD}"
{
printf '## %s - %s\n\n' "$tag" "$date"
printf '### Changed\n\n'
git log "$range" --no-merges --pretty=format:'- %s' \
| sed -E 's/^- ([a-z])/- \u\1/'
printf '\n\n'
} > /tmp/new_entry.md
# Insert the generated block immediately after the "# Changelog" heading.
cp CHANGELOG.md CHANGELOG.md.bak
awk -v entry=/tmp/new_entry.md '
FNR==1 && /^# Changelog/ {
print
while ((getline line < entry) > 0) print line
next
}
{ print }
' CHANGELOG.md.bak > CHANGELOG.md
rm -f CHANGELOG.md.bak
git add CHANGELOG.md
git commit -m "Update CHANGELOG for $tag" || echo "No CHANGELOG changes to commit."
git push origin "HEAD:${GITHUB_REF_NAME}"
- name: Create And Push Tag
if: steps.version.outputs.tag != ''
run: |
@@ -97,7 +140,7 @@ jobs:
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y build-essential cmake libssl-dev pkg-config zlib1g-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 libsdl2-dev libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev
- name: Build And Test
run: |
+69
View File
@@ -1,4 +1,73 @@
# Changelog
## v0.1.7 - 2026-07-26
### Changed
- Bump version to v0.1.7
- Remove native_widget_name compiler name-rewrite hack
- Finish removing Kry sugar verbs — language is now minimal
- Remove redundant Kry verbs; widgets are now a library
- Rework Platforms grid: add Windows, macOS, FreeBSD
- Make text input focus exclusive across UITextField and UITextArea
## v0.1.6 - 2026-07-25
### Changed
- Bump version to v0.1.6
- Resolve tray icon from installed hicolor paths
- Fix site card cursors, release CI, and IDE recent-projects grid
- Trigger site deploy (previous run hit GitHub internal error)
- 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
- Add Kryon platform thread primitives
- Support local enum blocks in kc
- Support bitwise compound assignments in kc
- Guard Kry compile-time expansion recursion
- Add runtime asset sync API
- Support Kry multidimensional arrays
- Raise Kry type block capacity
- Add Kry named enum syntax
- Add Kry switch syntax
- Update Kryon site goals
- Add Kry web intrinsics
- Add Kry anonymous block scopes
- Add top-level Kry extern declarations
- Add Jai-style Kry defines
- Add Kry top-level macro translation
- Add Kry type aliases
- Allow Kry type-only modules
- Generate project headers from Kry files
- Guard Kry text shorthand parsing
- Respect Kry locals when resolving function values
- Limit Kry function value rewriting
- Resolve Kry function values in expressions
- Add exact C exports for Kry modules
- Make Kry modules the only import path
- Support path-based Kry module use
- Fix IDE preview toolbar and text state
- Tighten leading continuation parsing
- Support leading expression continuations in Kry
- Add native Kry enum blocks
- Support break statements in Kry
- Add native Kry struct declarations
- Support multiline Kry function declarations
- Rewrite nil in Kry static initializers
- Add Jai-style Kry compile-time macros
- Support multiline Kry state initializers
- Use Jai-style typed Kry declarations
- Keep postfix operators on one Kry line
- Support multiline Kry block headers
- Support operator line continuations in Kry
- Support multiline Kry statements
- Add Kry while statements
- Allow app locals in Kry functions
- Lift Kry function limits
- Add flat Kry modules
## v0.1.5 - 2026-07-21
+4 -1
View File
@@ -58,7 +58,10 @@ RAY_GL_CFLAGS ?= $(shell pkg-config --cflags libdrm gbm egl glesv2 2>/dev/null)
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))
CURL_CODEC_LDLIBS != pkg-config --libs libbrotlidec libbrotlicommon libzstd 2>/dev/null || true
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))
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
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
+44 -292
View File
@@ -472,38 +472,16 @@ emit_source_pop(KryFile *file)
add_body_line(file, 0, " PopUIInspectSource();");
}
static const char *
native_widget_name(const char *name)
{
if(strcmp(name, "CenteredColumn") == 0)
return "GetUICenteredColumn";
if(strcmp(name, "ScrollEnd") == 0)
return "EndUIScrollPage";
if(strcmp(name, "Text") == 0)
return "DrawUIText";
if(strcmp(name, "TextButton") == 0)
return "DrawUITextButton";
return name;
}
static void
emit_call(KryFile *file, const char *prefix, const char *expr,
const char *suffix)
{
char name[KC_NAME_MAX];
const char *open = strchr(expr, '(');
size_t n;
if(open == NULL) {
add_body(file, "%s%s%s", prefix, expr, suffix);
return;
}
n = (size_t)(open - expr);
if(n >= sizeof(name))
n = sizeof(name) - 1;
memcpy(name, expr, n);
name[n] = '\0';
add_body(file, "%s%s%s%s", prefix, native_widget_name(name), open, suffix);
/*
* Calls pass through verbatim. The compiler does not rewrite function
* names: a widget is whatever library function the source calls, and
* source-inspection wrapping is applied uniformly to statement calls.
*/
add_body(file, "%s%s%s", prefix, expr, suffix);
}
static void
@@ -2181,10 +2159,6 @@ line_starts_block_statement(const char *line)
starts_word(line, "switch") ||
starts_word(line, "for") ||
starts_word(line, "while") ||
starts_word(line, "button") ||
starts_word(line, "event") ||
starts_word(line, "on") ||
starts_word(line, "icon_button") ||
starts_word(line, "c") ||
line_is_hash_compile(line) ||
starts_else_if(line) ||
@@ -2274,8 +2248,6 @@ line_can_accept_leading_continuation(const char *line)
{
return line != NULL &&
(starts_word(line, "return") ||
starts_word(line, "draw") ||
starts_word(line, "widget") ||
line_is_inferred_decl((char *)line) ||
find_typed_decl_colon((char *)line) != NULL ||
line_is_assignment_statement(line));
@@ -2701,135 +2673,36 @@ parse_statement(KryFile *file, int line_no, char *line)
} else if(starts_word(line, "let")) {
die("%s:%d: 'let' syntax was removed; use 'name: type = value'",
file->path, line_no);
} else if(starts_word(line, "background")) {
die("%s:%d: 'background' widget keyword was removed; call WidgetBackground(color) instead",
file->path, line_no);
} else if(starts_word(line, "set_theme")) {
die("%s:%d: 'set_theme' was removed; call SetCurrentTheme(id, mode) directly",
file->path, line_no);
} else if(line_is_inferred_decl(line)) {
emit_inferred_decl(file, line_no, line, 0);
} else if(line_is_typed_decl(line)) {
emit_typed_decl(file, line_no, line);
} else if(line_is_c_uninit_decl(line)) {
add_body(file, " %s;", line);
} else if(starts_word(line, "background")) {
char *q = trim(line + strlen("background"));
if(q[0] == '\0')
die("%s:%d: expected background color", file->path, line_no);
add_body(file,
" DrawRectangleRec((Rectangle){0, 0, GetUIViewWidth(), GetUIViewHeight()}, %s);",
q);
} else if(starts_word(line, "set_theme")) {
char *q = trim(line + strlen("set_theme"));
char theme[KC_NAME_MAX];
char *mode;
if(!parse_ident(&q, theme, sizeof(theme)))
die("%s:%d: expected theme id", file->path, line_no);
mode = trim(q);
if(mode[0] == '\0')
mode = "0";
add_body(file, " SetCurrentTheme(%s, %s);", theme, mode);
} else if(starts_statement_word(line, "text")) {
char *q = trim(line + strlen("text"));
char label[512];
char x[128] = "0";
char y[128] = "0";
char size[128] = "UI_TEXT_16";
char color[256] = "GetThemeText()";
if(!parse_label_token(&q, label, sizeof(label)))
die("%s:%d: expected text label", file->path, line_no);
q = trim(q);
read_prop_value(q, "x", x, sizeof(x));
read_prop_value(q, "y", y, sizeof(y));
read_prop_value(q, "size", size, sizeof(size));
read_prop_value(q, "color", color, sizeof(color));
emit_source_push(file, line_no);
add_body(file, " DrawUIText(%s, %s, %s, %s, %s);",
label[0] == '"' ? label : label, x, y, size, color);
emit_source_pop(file);
die("%s:%d: 'text' widget keyword was removed; call WidgetText(label, x, y, size, color) instead",
file->path, line_no);
} else if(starts_word(line, "rect")) {
char *q = trim(line + strlen("rect"));
char x[128] = "0";
char y[128] = "0";
char w[128] = "0";
char h[128] = "0";
char fill[256] = "GetThemeSurface()";
char border[256] = "";
if(strchr(q, '=') != NULL)
die("%s:%d: rect draws a rectangle; use 'var name: Rectangle = {...}' for declarations",
file->path, line_no);
if(!read_prop_value(q, "x", x, sizeof(x)) ||
!read_prop_value(q, "y", y, sizeof(y)) ||
!read_prop_value(q, "w", w, sizeof(w)) ||
!read_prop_value(q, "h", h, sizeof(h)))
die("%s:%d: rect requires x:, y:, w:, and h:", file->path,
line_no);
read_prop_value(q, "fill", fill, sizeof(fill));
read_prop_value(q, "border", border, sizeof(border));
add_body(file,
" DrawRectangleRec((Rectangle){%s, %s, %s, %s}, %s);",
x, y, w, h, fill);
if(border[0] != '\0')
add_body(file,
" DrawRectangleLinesEx((Rectangle){%s, %s, %s, %s}, 1, %s);",
x, y, w, h, border);
die("%s:%d: 'rect' widget keyword was removed; call WidgetRect(x, y, w, h, fill, border) instead",
file->path, line_no);
} else if(starts_word(line, "line")) {
char *q = trim(line + strlen("line"));
char x1[128] = "0";
char y1[128] = "0";
char x2[128] = "0";
char y2[128] = "0";
char color[256] = "GetThemeText()";
read_prop_value(q, "x1", x1, sizeof(x1));
read_prop_value(q, "y1", y1, sizeof(y1));
read_prop_value(q, "x2", x2, sizeof(x2));
read_prop_value(q, "y2", y2, sizeof(y2));
read_prop_value(q, "color", color, sizeof(color));
add_body(file, " DrawLine(%s, %s, %s, %s, %s);",
x1, y1, x2, y2, color);
die("%s:%d: 'line' widget keyword was removed; call WidgetLine(x1, y1, x2, y2, color) instead",
file->path, line_no);
} else if(starts_word(line, "swatch")) {
char *q = trim(line + strlen("swatch"));
char label[512];
char x[128] = "0";
char y[128] = "0";
char size[128] = "ScaleUIPx(48)";
char color[256] = "GetThemeButton()";
char text_color[256] = "GetThemeText()";
if(!parse_label_token(&q, label, sizeof(label)))
die("%s:%d: expected swatch label", file->path, line_no);
q = trim(q);
read_prop_value(q, "x", x, sizeof(x));
read_prop_value(q, "y", y, sizeof(y));
read_prop_value(q, "size", size, sizeof(size));
read_prop_value(q, "color", color, sizeof(color));
read_prop_value(q, "text_color", text_color, sizeof(text_color));
add_body(file,
" DrawRectangleRec((Rectangle){%s, %s, %s, %s}, %s);",
x, y, size, size, color);
add_body(file,
" DrawRectangleLinesEx((Rectangle){%s, %s, %s, %s}, 1, %s);",
x, y, size, size, text_color);
add_body(file, " DrawUIText(%s, (%s) + (%s) + ScaleUIPx(10), (%s) + ScaleUIPx(10), UI_TEXT_16, %s);",
label, x, size, y, text_color);
die("%s:%d: 'swatch' widget keyword was removed; draw a rect + text with WidgetRect/WidgetText instead",
file->path, line_no);
} else if(starts_word(line, "on key_down")) {
char *q = trim(line + strlen("on key_down"));
size_t n = strlen(q);
if(n == 0 || q[n - 1] != '{')
die("%s:%d: expected key_down block ending with {",
file->path, line_no);
q[n - 1] = '\0';
add_body(file, " if(UIKeyDown(%s)) {", trim(q));
die("%s:%d: 'on key_down' was removed; use 'if (UIKeyDown(KEY)) {'",
file->path, line_no);
} else if(starts_word(line, "on key")) {
char *q = trim(line + strlen("on key"));
size_t n = strlen(q);
if(n == 0 || q[n - 1] != '{')
die("%s:%d: expected key block ending with {", file->path,
line_no);
q[n - 1] = '\0';
add_body(file, " if(UIKeyPressed(%s)) {", trim(q));
die("%s:%d: 'on key' was removed; use 'if (UIKeyPressed(KEY)) {'",
file->path, line_no);
} else if(starts_else_if(line)) {
char *q = starts_word(line, "else if")
? trim(line + strlen("else if"))
@@ -2887,17 +2760,15 @@ parse_statement(KryFile *file, int line_no, char *line)
if(q[0] == '\0')
die("%s:%d: expected assignment", file->path, line_no);
if(strchr(q, '(') != NULL)
emit_source_push(file, line_no);
add_body(file, " %s;", q);
if(strchr(q, '(') != NULL)
emit_source_pop(file);
die("%s:%d: 'set' was removed; write the assignment directly: %s",
file->path, line_no, q);
} else if(starts_word(line, "native")) {
char *q = trim(line + strlen("native"));
if(q[0] == '\0')
die("%s:%d: expected native expression", file->path, line_no);
add_body(file, " %s;", q);
die("%s:%d: 'native' was removed; call it directly: %s",
file->path, line_no, q);
} else if(starts_word(line, "unused")) {
char *q = trim(line + strlen("unused"));
@@ -2925,66 +2796,21 @@ parse_statement(KryFile *file, int line_no, char *line)
if(q[0] == '\0')
die("%s:%d: expected expression", file->path, line_no);
emit_source_push(file, line_no);
emit_call(file, " ", q, ";");
emit_source_pop(file);
die("%s:%d: 'draw'/'widget' was removed; call it directly: %s",
file->path, line_no, q);
} else if(starts_word(line, "advance")) {
char *q = trim(line + strlen("advance"));
char name[KC_NAME_MAX];
if(!parse_ident(&q, name, sizeof(name)))
die("%s:%d: expected variable name", file->path, line_no);
q = trim(q);
if(!starts_word(q, "by"))
die("%s:%d: expected 'by' in advance statement", file->path,
line_no);
q = trim(q + strlen("by"));
if(q[0] == '\0')
die("%s:%d: expected advance expression", file->path, line_no);
add_body(file, " %s += %s;", name, q);
die("%s:%d: 'advance x by N' was removed; write 'x += N' directly",
file->path, line_no);
} else if(starts_word(line, "clamp_min") ||
starts_word(line, "clamp_max")) {
int is_min = starts_word(line, "clamp_min");
char *q = trim(line + strlen(is_min ? "clamp_min" : "clamp_max"));
char name[KC_NAME_MAX];
if(!parse_ident(&q, name, sizeof(name)))
die("%s:%d: expected variable name", file->path, line_no);
q = trim(q);
if(q[0] == '\0')
die("%s:%d: expected clamp expression", file->path, line_no);
add_body(file, " if(%s %c %s) {", name, is_min ? '<' : '>', q);
add_body(file, " %s = %s;", name, q);
add_body(file, " }");
die("%s:%d: 'clamp_min/max' was removed; write 'if (x < N) x = N' directly",
file->path, line_no);
} else if(starts_word(line, "c_rect")) {
char *q = trim(line + strlen("c_rect"));
char name[KC_NAME_MAX];
if(!parse_ident(&q, name, sizeof(name)))
die("%s:%d: expected rectangle name", file->path, line_no);
q = trim(q);
if(*q != '=')
die("%s:%d: expected '=' in rect statement", file->path,
line_no);
q = trim(q + 1);
if(q[0] == '\0')
die("%s:%d: expected rectangle expression list", file->path,
line_no);
add_body(file, " Rectangle %s = (Rectangle){%s};", name, q);
die("%s:%d: 'c_rect' was removed; declare with 'name: Rectangle = (Rectangle){...}'",
file->path, line_no);
} else if(starts_word(line, "texture")) {
char *q = trim(line + strlen("texture"));
char name[KC_NAME_MAX];
if(!parse_ident(&q, name, sizeof(name)))
die("%s:%d: expected texture name", file->path, line_no);
q = trim(q);
if(*q != '=')
die("%s:%d: expected '=' in texture statement", file->path,
line_no);
q = trim(q + 1);
if(q[0] == '\0')
die("%s:%d: expected texture expression", file->path, line_no);
add_body(file, " Texture2D %s = %s;", name, q);
die("%s:%d: 'texture' was removed; declare with 'name: Texture2D = ...'",
file->path, line_no);
} else if(starts_word(line, "enum")) {
char *q = trim(line + strlen("enum"));
size_t n = strlen(q);
@@ -3074,88 +2900,14 @@ parse_statement(KryFile *file, int line_no, char *line)
die("%s:%d: expected while condition", file->path, line_no);
add_body(file, " while(%s) {", q);
} else if(starts_word(line, "button")) {
char *q = trim(line + strlen("button"));
size_t n = strlen(q);
char hit[KC_NAME_MAX];
char label[512];
char x[128] = "0";
char y[128] = "0";
char w[128] = "ScaleUIPx(120)";
char h[128] = "ScaleUIPx(34)";
char style[128] = "UI_BUTTON_STYLE_PRIMARY";
if(n == 0 || q[n - 1] != '{')
die("%s:%d: expected button arguments ending with {", file->path,
line_no);
q[n - 1] = '\0';
q = trim(q);
if(strchr(q, '(') != NULL && q[0] != '"') {
snprintf(hit, sizeof(hit), "__kry_hit_%d", line_no);
add_body_line(file, 0, " int %s;", hit);
emit_source_push(file, line_no);
add_body_line(file, 0, " %s = DrawUIGenericButton(%s);", hit, q);
emit_source_pop(file);
add_body_line(file, 0, " if(%s) {", hit);
return;
}
if(!parse_label_token(&q, label, sizeof(label)))
die("%s:%d: expected button label", file->path, line_no);
q = trim(q);
read_prop_value(q, "x", x, sizeof(x));
read_prop_value(q, "y", y, sizeof(y));
read_prop_value(q, "w", w, sizeof(w));
read_prop_value(q, "h", h, sizeof(h));
read_prop_value(q, "style", style, sizeof(style));
snprintf(hit, sizeof(hit), "__kry_hit_%d", line_no);
add_body_line(file, 0, " int %s;", hit);
emit_source_push(file, line_no);
add_body_line(file, 0,
" %s = DrawUIGenericButton(%s, %s, %s, %s, %s, %s, 0, NULL);",
hit, x, y, w, h, label, style);
emit_source_pop(file);
add_body_line(file, 0, " if(%s) {", hit);
die("%s:%d: 'button' block keyword was removed; use 'if WidgetButton(x, y, w, h, label, style) {'",
file->path, line_no);
} else if(starts_word(line, "event") || starts_word(line, "on")) {
char *q = starts_word(line, "event")
? trim(line + strlen("event"))
: trim(line + strlen("on"));
size_t n = strlen(q);
char hit[KC_NAME_MAX];
if(n == 0 || q[n - 1] != '{')
die("%s:%d: expected event expression ending with {", file->path,
line_no);
q[n - 1] = '\0';
q = trim(q);
snprintf(hit, sizeof(hit), "__kry_hit_%d", line_no);
add_body_line(file, 0, " int %s;", hit);
emit_source_push(file, line_no);
{
char prefix[KC_NAME_MAX + 8];
snprintf(prefix, sizeof(prefix), " %s = ", hit);
emit_call(file, prefix, q, ";");
file->current->body_line[file->current->body_count - 1] = 0;
}
emit_source_pop(file);
add_body_line(file, 0, " if(%s) {", hit);
die("%s:%d: 'event'/'on' block keyword was removed; use 'if (expr) {' with a bool-returning call",
file->path, line_no);
} else if(starts_word(line, "icon_button")) {
char *q = trim(line + strlen("icon_button"));
size_t n = strlen(q);
char hit[KC_NAME_MAX];
if(n == 0 || q[n - 1] != '{')
die("%s:%d: expected icon_button arguments ending with {",
file->path, line_no);
q[n - 1] = '\0';
q = trim(q);
snprintf(hit, sizeof(hit), "__kry_hit_%d", line_no);
add_body_line(file, 0, " int %s;", hit);
emit_source_push(file, line_no);
add_body_line(file, 0,
" %s = DrawUIIconButton((UIIconButton){%s});",
hit, q);
emit_source_pop(file);
add_body_line(file, 0, " if(%s) {", hit);
die("%s:%d: 'icon_button' block keyword was removed; use 'if DrawUIIconButton((UIIconButton){...}) {'",
file->path, line_no);
} else if(line[strlen(line) - 1] == ')' && strchr(line, '(') != NULL &&
find_assignment_op(line) == NULL) {
emit_source_push(file, line_no);
+16 -11
View File
@@ -4582,6 +4582,14 @@ draw_start_page(Rectangle content, EditorProject *project,
*new_project_requested = 1;
y += ScaleUIPx(44) + ScaleUIPx(22);
/* Recent projects and examples share a responsive card grid. */
int cards_cols = col_w / (ScaleUIPx(200) + gap);
if(cards_cols < 1)
cards_cols = 1;
if(cards_cols > 3)
cards_cols = 3;
int cards_col_w = (col_w - gap * (cards_cols - 1)) / cards_cols;
DrawUIText("Recent Projects", x0, y, UI_TEXT_16, GetThemeIcon());
y += ScaleUIPx(26);
if(recent == NULL || recent->count == 0) {
@@ -4590,9 +4598,14 @@ draw_start_page(Rectangle content, EditorProject *project,
y += ScaleUIPx(24);
} else {
for(int i = 0; i < recent->count; i++) {
if(y + card_h > bottom_limit)
int col = i % cards_cols;
int row = i / cards_cols;
int card_x = x0 + col * (cards_col_w + gap);
int card_y = y + row * (card_h + gap);
if(card_y + card_h > bottom_limit)
break;
if(draw_start_card(x0, y, col_w, card_h,
if(draw_start_card(card_x, card_y, cards_col_w, card_h,
path_basename(recent->paths[i]),
recent->paths[i])) {
editor_open_project(project, recent->paths[i], recent,
@@ -4600,8 +4613,8 @@ draw_start_page(Rectangle content, EditorProject *project,
if(sidebar != NULL)
memset(sidebar, 0, sizeof(*sidebar));
}
y += card_h + gap;
}
y += ((recent->count + cards_cols - 1) / cards_cols) * (card_h + gap);
}
y += ScaleUIPx(10);
@@ -4610,8 +4623,6 @@ draw_start_page(Rectangle content, EditorProject *project,
char ex_paths[EDITOR_MAX_EXAMPLES][EDITOR_PATH_CAP];
char ex_titles[EDITOR_MAX_EXAMPLES][EDITOR_EXAMPLE_TITLE_CAP];
int ex_count = 0;
int cards_cols;
int cards_col_w;
DrawUIText("Examples", x0, y, UI_TEXT_16, GetThemeIcon());
y += ScaleUIPx(26);
@@ -4627,12 +4638,6 @@ draw_start_page(Rectangle content, EditorProject *project,
GetThemeIcon());
return;
}
cards_cols = col_w / (ScaleUIPx(200) + gap);
if(cards_cols < 1)
cards_cols = 1;
if(cards_cols > 3)
cards_cols = 3;
cards_col_w = (col_w - gap * (cards_cols - 1)) / cards_cols;
for(int i = 0; i < ex_count; i++) {
int col = i % cards_cols;
int row = i / cards_cols;
+16 -4
View File
@@ -95,10 +95,22 @@ session_entry :: (app: InbeApp*) #export {
- `#pragma "text"` and `#error "message"` emit guarded C preprocessor
directives for compiler and platform integration.
Kry statements use C-like expressions with cleaner declaration syntax:
Kry statements are deliberately minimal — declarations, assignments, calls,
and control flow. There are no widget keywords and no bespoke sugar verbs:
- `name := expr` for inferred locals.
- `name: Type = expr` or `name: Type` for typed locals.
- plain function calls, assignments, `if`, `while`, `for`, `switch`, `case`,
`default`, labels, `goto`, `break`, `continue`, and `return`.
- `native expr` and `c line` remain explicit escape hatches for low-level glue.
- `name = expr` assignments (including compound `+=`, `%=`, `&=`, ...).
- 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`.
- `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
treats them exactly like any other call. Input handling is plain control
flow: `if (UIKeyPressed(KEY_A)) { ... }`, `if (UIKeyDown(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.
+15 -10
View File
@@ -113,6 +113,16 @@
<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>
@@ -124,14 +134,9 @@
<p>WebAssembly runtime and previews.</p>
</article>
<article class="platform">
<img src="icons/gear.png" width="32" height="32" alt="">
<h3>Native</h3>
<p>Small C runtime and generated sources.</p>
</article>
<article class="platform">
<img src="icons/link.png" width="32" height="32" alt="">
<h3>Network</h3>
<p>Ready for path-based remote control.</p>
<img src="platforms/freebsd.png" width="32" height="32" alt="">
<h3>FreeBSD</h3>
<p>Native desktop and embedded targets.</p>
</article>
</div>
</section>
@@ -149,8 +154,8 @@ make install</code></pre>
AppHome :: (app: InbeApp*) {
y: int = ScaleUIPx(24)
draw DrawUIText("Inner Breeze", ScaleUIPx(20), y, UI_TEXT_24, GetThemeText())
draw app_draw_bottom_nav(app)
WidgetText("Inner Breeze", ScaleUIPx(20), y, UI_TEXT_24, GetThemeText())
app_draw_bottom_nav(app)
}</code></pre>
<p>Open a project or a single .kry file in the IDE:</p>
<pre><code>kryon .
+2
View File
@@ -277,6 +277,7 @@ section > p {
0 1px 0 var(--button-highlight),
inset 1px 1px 0 var(--button-inset),
0 2px 10px rgba(0, 0, 0, 0.04);
cursor: url("cursors/hand.png") 6 1, pointer;
transition: background-color 0.14s ease, transform 0.08s ease, box-shadow 0.14s ease;
}
@@ -326,6 +327,7 @@ section > p {
color: inherit;
text-decoration: none;
box-sizing: border-box;
cursor: url("cursors/hand.png") 6 1, pointer;
transition: background-color 0.14s ease, transform 0.08s ease, box-shadow 0.14s ease;
}
+19 -19
View File
@@ -17,34 +17,34 @@ state {
}
screen FileDialogExample(viewport: Rectangle) {
background GetThemeBackground()
WidgetBackground(GetThemeBackground())
if dlg_ready == 0 {
InitFileDialog(&dlg)
set dlg_ready = 1
dlg_ready = 1
}
text "Kryon File Dialog" x: ScaleUIPx(32) y: ScaleUIPx(28) size: UI_TEXT_24 color: GetThemeText()
text "Dialog backend and result state" x: ScaleUIPx(32) y: ScaleUIPx(66) size: UI_TEXT_16 color: GetThemeIcon()
button "Open File" x: ScaleUIPx(32) y: ScaleUIPx(116) w: ScaleUIPx(180) h: ScaleUIPx(42) style: UI_BUTTON_STYLE_PRIMARY {
set BeginLoadFileDialog(&dlg,"Open File")
set snprintf(status,sizeof(status),"Open file requested.")
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) {
BeginLoadFileDialog(&dlg,"Open File")
snprintf(status,sizeof(status),"Open file requested.")
}
button "Save File" x: ScaleUIPx(226) y: ScaleUIPx(116) w: ScaleUIPx(180) h: ScaleUIPx(42) style: UI_BUTTON_STYLE_SECONDARY {
set BeginSaveFileDialog(&dlg,"Save File","untitled.kry")
set snprintf(status,sizeof(status),"Save file requested.")
if WidgetButton(ScaleUIPx(226), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Save File", UI_BUTTON_STYLE_SECONDARY) {
BeginSaveFileDialog(&dlg,"Save File","untitled.kry")
snprintf(status,sizeof(status),"Save file requested.")
}
button "Select Folder" x: ScaleUIPx(420) y: ScaleUIPx(116) w: ScaleUIPx(180) h: ScaleUIPx(42) style: UI_BUTTON_STYLE_SECONDARY {
set BeginSelectFileDialogFolder(&dlg,"Select Folder")
set snprintf(status,sizeof(status),"Folder selection requested.")
if WidgetButton(ScaleUIPx(420), ScaleUIPx(116), ScaleUIPx(180), ScaleUIPx(42), "Select Folder", UI_BUTTON_STYLE_SECONDARY) {
BeginSelectFileDialogFolder(&dlg,"Select Folder")
snprintf(status,sizeof(status),"Folder selection requested.")
}
dialog_result: int = UpdateFileDialog(&dlg)
if dialog_result == 1 {
set snprintf(last_path,sizeof(last_path),"%s",GetFileDialogPath(&dlg))
set snprintf(status,sizeof(status),"Selected: %s",last_path)
snprintf(last_path,sizeof(last_path),"%s",GetFileDialogPath(&dlg))
snprintf(status,sizeof(status),"Selected: %s",last_path)
}
if dialog_result < 0 {
set snprintf(status,sizeof(status),"Dialog cancelled.")
snprintf(status,sizeof(status),"Dialog cancelled.")
}
text "Status" x: ScaleUIPx(32) y: ScaleUIPx(210) size: 18 color: GetThemeText()
text status x: ScaleUIPx(32) y: ScaleUIPx(242) size: UI_TEXT_16 color: GetThemeText()
text last_path x: ScaleUIPx(32) y: ScaleUIPx(274) size: UI_TEXT_16 color: GetThemeIcon()
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())
}
+16 -16
View File
@@ -13,23 +13,23 @@ state {
}
screen ButtonsExample(viewport: Rectangle) {
background GetThemeBackground()
text "UI Buttons Example" x: ScaleUIPx(20) y: ScaleUIPx(20) size: UI_TEXT_24 color: GetThemeText()
text "Click the buttons below to test interactions" x: ScaleUIPx(20) y: ScaleUIPx(54) size: UI_TEXT_16 color: GetThemeText()
button "Primary Button" x: ScaleUIPx(20) y: ScaleUIPx(100) w: ScaleUIPx(200) h: ScaleUIPx(40) style: UI_BUTTON_STYLE_PRIMARY {
set click_count++
set snprintf(last_action,sizeof(last_action),"Primary Button clicked.")
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) {
click_count++
snprintf(last_action,sizeof(last_action),"Primary Button clicked.")
}
button "Secondary Button" x: ScaleUIPx(20) y: ScaleUIPx(150) w: ScaleUIPx(200) h: ScaleUIPx(40) style: UI_BUTTON_STYLE_SECONDARY {
set click_count++
set snprintf(last_action,sizeof(last_action),"Secondary Button clicked.")
if WidgetButton(ScaleUIPx(20), ScaleUIPx(150), ScaleUIPx(200), ScaleUIPx(40), "Secondary Button", UI_BUTTON_STYLE_SECONDARY) {
click_count++
snprintf(last_action,sizeof(last_action),"Secondary Button clicked.")
}
button "Danger Button" x: ScaleUIPx(20) y: ScaleUIPx(200) w: ScaleUIPx(200) h: ScaleUIPx(40) style: UI_BUTTON_STYLE_DANGER {
set click_count++
set snprintf(last_action,sizeof(last_action),"Danger Button clicked.")
if WidgetButton(ScaleUIPx(20), ScaleUIPx(200), ScaleUIPx(200), ScaleUIPx(40), "Danger Button", UI_BUTTON_STYLE_DANGER) {
click_count++
snprintf(last_action,sizeof(last_action),"Danger Button clicked.")
}
text TextFormat("Clicks:%d",click_count) x: ScaleUIPx(20) y: ScaleUIPx(260) size: UI_TEXT_16 color: GetThemeText()
text last_action x: ScaleUIPx(20) y: ScaleUIPx(290) size: UI_TEXT_16 color: GetThemeText()
text "Button Styles" x: ScaleUIPx(300) y: ScaleUIPx(100) size: 18 color: GetThemeText()
text "Primary,secondary,and danger styles use the active theme." x: ScaleUIPx(300) y: ScaleUIPx(130) size: 14 color: GetThemeIcon()
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())
}
+29 -27
View File
@@ -52,7 +52,9 @@ ThemeAt :: (index: int) -> ThemeId {
ThemeSwatch :: (label: const char *, y: int, value: Color, label_color: Color) {
x: int = ScaleUIPx(20)
size: int = ScaleUIPx(56)
swatch label x: x y: y size: size color: value text_color: label_color
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)
}
ThemeButton :: (label: const char *, x: int, y: int, w: int) -> int {
@@ -61,20 +63,20 @@ ThemeButton :: (label: const char *, x: int, y: int, w: int) -> int {
}
ThemeLabel :: (label: const char *, value: const char *, y: int, size: int, text_color: Color) {
text TextFormat("%s%s",label,value) x: ScaleUIPx(20) y: y size: size color: text_color
WidgetText(TextFormat("%s%s",label,value), ScaleUIPx(20), y, size, text_color)
}
ThemeSideLabel :: (label: const char *, value: const char *, y: int, text_color: Color) {
text TextFormat("%s%s",label,value) x: ScaleUIPx(320) y: y size: UI_TEXT_16 color: text_color
WidgetText(TextFormat("%s%s",label,value), ScaleUIPx(320), y, UI_TEXT_16, text_color)
}
ThemeSideInt :: (label: const char *, y: int, value: int, text_color: Color) {
text TextFormat("%s%d",label,value) x: ScaleUIPx(320) y: y size: UI_TEXT_16 color: text_color
WidgetText(TextFormat("%s%d",label,value), ScaleUIPx(320), y, UI_TEXT_16, text_color)
}
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)
text rgb_text x: ScaleUIPx(320) y: y size: 14 color: text_color
WidgetText(rgb_text, ScaleUIPx(320), y, 14, text_color)
}
screen ThemeExample(viewport: Rectangle) {
@@ -83,43 +85,43 @@ screen ThemeExample(viewport: Rectangle) {
right_x: int = ScaleUIPx(420)
button_w: int = ScaleUIPx(112)
mode_w: int = ScaleUIPx(232)
native SetCurrentTheme(current_theme, dark_mode)
SetCurrentTheme(current_theme, dark_mode)
background: Color
text_color: Color
button: Color
button_hover: Color
circle: Color
set GetThemeCatalogColor(current_theme,dark_mode,"background",&background)
set GetThemeCatalogColor(current_theme,dark_mode,"text",&text_color)
set GetThemeCatalogColor(current_theme,dark_mode,"button",&button)
set GetThemeCatalogColor(current_theme,dark_mode,"button_hover",&button_hover)
set GetThemeCatalogColor(current_theme,dark_mode,"circle",&circle)
background background
draw ThemeLabel("Theme: ",GetThemeLabel(current_theme),ScaleUIPx(20),UI_TEXT_24,text_color)
draw ThemeLabel("Mode:",dark_mode?"Dark":"Light",ScaleUIPx(50),UI_TEXT_16,text_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) {
set theme_index = (theme_index + 11) % 12
theme_index = (theme_index + 11) % 12
}
if ThemeButton("Next Theme", right_x, ScaleUIPx(18), button_w) {
set theme_index = (theme_index + 1) % 12
theme_index = (theme_index + 1) % 12
}
if dark_mode {
if ThemeButton("Light Mode", left_x, ScaleUIPx(64), mode_w) {
set dark_mode = 0
dark_mode = 0
}
} else {
if ThemeButton("Dark Mode", left_x, ScaleUIPx(64), mode_w) {
set dark_mode = 1
dark_mode = 1
}
}
draw ThemeSwatch("Background", ScaleUIPx(90), background, text_color)
draw ThemeSwatch("Text", ScaleUIPx(160), text_color, text_color)
draw ThemeSwatch("Button", ScaleUIPx(230), button, text_color)
draw ThemeSwatch("Button Hover", ScaleUIPx(300), button_hover, text_color)
draw ThemeSwatch("Circle", ScaleUIPx(370), circle, text_color)
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)
draw ThemeSideLabel("Scope:", scope, ScaleUIPx(120), text_color)
draw ThemeSideInt("Theme ID:", ScaleUIPx(152), current_theme, text_color)
draw ThemeRGB("Background", ScaleUIPx(200), background, text_color)
draw ThemeRGB("Text", ScaleUIPx(224), text_color, text_color)
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)
}
+15 -15
View File
@@ -14,31 +14,31 @@ state {
}
screen ModalExample(viewport: Rectangle) {
background GetThemeBackground()
text "Modal capture example" x: 32 y: 32 size: UI_TEXT_24 color: GetThemeText()
text "Open the modal and background clicks are blocked." x: 32 y: 72 size: UI_TEXT_16 color: GetThemeIcon()
button "Background Button" x: 32 y: 120 w: 220 h: 42 style: UI_BUTTON_STYLE_SECONDARY {
set background_clicks++
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_clicks++
}
text TextFormat("Background clicks:%d",background_clicks) x: 32 y: 176 size: UI_TEXT_16 color: GetThemeText()
text TextFormat("Last modal result:%s",last_label) x: 32 y: 204 size: UI_TEXT_16 color: GetThemeText()
button "Open Modal" x: 32 y: 240 w: 220 h: 42 style: UI_BUTTON_STYLE_PRIMARY {
set modal_open = 1
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) {
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})
if result == 1 {
set modal_open = 0
set snprintf(last_label,sizeof(last_label),"cancel")
modal_open = 0
snprintf(last_label,sizeof(last_label),"cancel")
}
if result == 2 {
set modal_open = 0
set snprintf(last_label,sizeof(last_label),"confirm")
modal_open = 0
snprintf(last_label,sizeof(last_label),"confirm")
}
if result == 3 {
set modal_open = 0
set snprintf(last_label,sizeof(last_label),"delete")
modal_open = 0
snprintf(last_label,sizeof(last_label),"delete")
}
}
}
+15 -9
View File
@@ -12,18 +12,24 @@ state {
}
screen ColorExample(viewport: Rectangle) {
background GetThemeBackground()
WidgetBackground(GetThemeBackground())
colors: [5] Color = {GetThemeButton(),GetThemeButtonHover(),GetThemeCircle(),GetThemeSurface(),GetThemeLink()}
base: Color = colors[color_index]
light: Color = LightenUIColor(base,40)
dark: Color = DarkenUIColor(base,40)
text "Color Utilities" x: 50 y: 20 size: UI_TEXT_24 color: GetThemeText()
swatch "Original" x: 50 y: 70 size: 70 color: base text_color: GetThemeText()
swatch "Lightened" x: 50 y: 160 size: 70 color: light text_color: GetThemeText()
swatch "Darkened" x: 50 y: 250 size: 70 color: dark text_color: GetThemeText()
text TextFormat("Color %d/5 - SPACE cycles",color_index+1) x: 320 y: 82 size: 18 color: GetThemeText()
text TextFormat("RGB:%d,%d,%d",base.r,base.g,base.b) x: 320 y: 116 size: UI_TEXT_16 color: GetThemeText()
on key KEY_SPACE {
set color_index = (color_index + 1) % 5
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)) {
color_index = (color_index + 1) % 5
}
}
+17 -17
View File
@@ -15,27 +15,27 @@ state {
}
screen ScalingExample(viewport: Rectangle) {
set SetUIScale(scales[scale_index])
background GetThemeBackground()
SetUIScale(scales[scale_index])
WidgetBackground(GetThemeBackground())
box_size: int = ScaleUIPx(100)
text TextFormat("DPI Scale:%.1f",scales[scale_index]) x: 50 y: 20 size: 20 color: GetThemeText()
rect x: box_x y: box_y w: box_size h: box_size fill: GetThemeButton() border: GetThemeIcon()
text "Scaled Box" x: box_x + 10 y: box_y + 10 size: UI_TEXT_16 color: GetThemeText()
text TextFormat("Base:100px Scaled:%dpx",box_size) x: 50 y: 60 size: UI_TEXT_16 color: GetThemeText()
text "SPACE cycles DPI,arrows move box" x: 50 y: 90 size: UI_TEXT_16 color: GetThemeIcon()
on key_down KEY_RIGHT {
set box_x += 3
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)) {
box_x += 3
}
on key_down KEY_LEFT {
set box_x -= 3
if (UIKeyDown(KEY_LEFT)) {
box_x -= 3
}
on key_down KEY_DOWN {
set box_y += 3
if (UIKeyDown(KEY_DOWN)) {
box_y += 3
}
on key_down KEY_UP {
set box_y -= 3
if (UIKeyDown(KEY_UP)) {
box_y -= 3
}
on key KEY_SPACE {
set scale_index = (scale_index + 1) % 4
if (UIKeyPressed(KEY_SPACE)) {
scale_index = (scale_index + 1) % 4
}
}
+21 -21
View File
@@ -13,23 +13,23 @@ state {
LayoutInfo :: (label: const char *, value: int, x: int, y: int) {
info: const char * = TextFormat("%s:%d",label,value)
text info x: x y: y size: UI_TEXT_16 color: GetThemeText()
WidgetText(info, x, y, UI_TEXT_16, GetThemeText())
}
WidthButton :: (label: const char *, x: int, y: int, value: int) -> int {
style: int = UI_BUTTON_STYLE_SECONDARY
if max_width == value {
set style = UI_BUTTON_STYLE_PRIMARY
style = UI_BUTTON_STYLE_PRIMARY
}
return DrawUIGenericButton(x,y,ScaleUIPx(110),ScaleUIPx(34),label,style,0,NULL)
}
LayoutNote :: (label: const char *, x: int, y: int, color: Color) {
text label x: x y: y size: UI_TEXT_16 color: color
WidgetText(label, x, y, UI_TEXT_16, color)
}
screen LayoutExample(viewport: Rectangle) {
background GetThemeBackground()
WidgetBackground(GetThemeBackground())
side_padding: int = GetUIPageSidePadding()
page_x: int = side_padding
page_w: int = GetUIViewWidth() - side_padding * 2
@@ -43,27 +43,27 @@ screen LayoutExample(viewport: Rectangle) {
btn0_x: int = column_x + ScaleUIPx(16)
btn1_x: int = column_x + ScaleUIPx(138)
btn2_x: int = column_x + ScaleUIPx(260)
set GetUICenteredColumn(max_width,side_padding,&column_x,&column_w)
set btn0_x = column_x + ScaleUIPx(16)
set btn1_x = column_x + ScaleUIPx(138)
set btn2_x = column_x + ScaleUIPx(260)
text "Responsive layout" x: page_x y: ScaleUIPx(16) size: UI_TEXT_24 color: GetThemeText()
rect x: page_x y: y w: page_w h: guide_h fill: GetThemeSurface() border: GetThemeIcon()
line x1: side_padding y1: y x2: side_padding y2: y+guide_h color: GetThemeLink()
line x1: right_edge y1: y x2: right_edge y2: y+guide_h color: GetThemeLink()
rect x: column_x y: column_y w: column_w h: ScaleUIPx(360) fill: GetThemeBackground() border: GetThemeButton()
draw LayoutInfo("View width", GetUIViewWidth(), column_x+16, y+ScaleUIPx(54))
draw LayoutInfo("Side padding", side_padding, column_x+16, y+ScaleUIPx(84))
draw LayoutInfo("Column max", max_width, column_x+16, y+ScaleUIPx(114))
GetUICenteredColumn(max_width,side_padding,&column_x,&column_w)
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())
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))
if WidthButton("Narrow", btn0_x, btn_y, 360) {
set max_width = 360
max_width = 360
}
if WidthButton("Medium", btn1_x, btn_y, 560) {
set max_width = 560
max_width = 560
}
if WidthButton("Wide", btn2_x, btn_y, 720) {
set max_width = 720
max_width = 720
}
draw LayoutNote("Resize the preview/window or choose a width.", column_x+16, y+ScaleUIPx(240), GetThemeText())
draw LayoutNote("The column stays centered and clamped.", column_x+16, y+ScaleUIPx(272), GetThemeIcon())
LayoutNote("Resize the preview/window or choose a width.", column_x+16, y+ScaleUIPx(240), GetThemeText())
LayoutNote("The column stays centered and clamped.", column_x+16, y+ScaleUIPx(272), GetThemeIcon())
}
+27 -27
View File
@@ -8,8 +8,8 @@ app "Kryon Geometry" {
}
screen GeometryExample(viewport: Rectangle) {
background GetThemeBackground()
set SetUIViewSize(GetScreenWidth(),GetScreenHeight())
WidgetBackground(GetThemeBackground())
SetUIViewSize(GetScreenWidth(),GetScreenHeight())
shell: Rectangle = {40,42,GetUIViewWidth()-80,GetUIViewHeight()-84}
frame: UIFrame = BeginUIFrameBox(shell,16,16,12)
header: Rectangle = UIFramePack(&frame,UI_SIDE_TOP,54)
@@ -23,29 +23,29 @@ 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)
text "Geometry helpers" x: 40 y: 14 size: UI_TEXT_24 color: GetThemeText()
draw DrawRectangleRec(shell,GetThemeSurface())
draw DrawRectangleLinesEx(shell,1,GetThemeIcon())
draw DrawRectangleRec(header,GetThemeButton())
draw DrawRectangleRec(rail,DarkenUIColor(GetThemeSurface(),8))
draw DrawUISeparator((Rectangle){rail.x+rail.width+6,rail.y,1,rail.height},1)
text "Packed header" x: header.x+16 y: header.y+16 size: UI_TEXT_16 color: GetThemeText()
text "Left rail" x: rail.x+16 y: rail.y+16 size: UI_TEXT_16 color: GetThemeText()
draw DrawRectangleRec(card0,DarkenUIColor(GetThemeSurface(),12))
draw DrawRectangleLinesEx(card0,1,GetThemeButton())
draw DrawRectangleRec(card1,DarkenUIColor(GetThemeSurface(),16))
draw DrawRectangleLinesEx(card1,1,GetThemeButton())
draw DrawRectangleRec(card2,DarkenUIColor(GetThemeSurface(),18))
draw DrawRectangleLinesEx(card2,1,GetThemeButton())
draw DrawRectangleRec(card3,DarkenUIColor(GetThemeSurface(),22))
draw DrawRectangleLinesEx(card3,1,GetThemeButton())
text "UIGridCell 2-column span" x: card0.x+14 y: card0.y+18 size: UI_TEXT_16 color: GetThemeText()
text "UIPlace badge" x: card1.x+14 y: card1.y+18 size: UI_TEXT_16 color: GetThemeText()
draw DrawRectangleRec(badge,GetThemeButtonHover())
text "badge" x: badge.x+18 y: badge.y+7 size: UI_TEXT_12 color: GetThemeText()
text "cell 1,0" x: card2.x+14 y: card2.y+18 size: UI_TEXT_16 color: GetThemeText()
text "wide footer cell" x: card3.x+14 y: card3.y+18 size: UI_TEXT_16 color: GetThemeText()
draw DrawUISeparator((Rectangle){footer.x,footer.y-7,footer.width,1},0)
draw DrawRectangleRec(action,GetThemeButton())
text "placed action" x: action.x+14 y: action.y+9 size: UI_TEXT_12 color: GetThemeText()
WidgetText("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())
DrawRectangleRec(card0,DarkenUIColor(GetThemeSurface(),12))
DrawRectangleLinesEx(card0,1,GetThemeButton())
DrawRectangleRec(card1,DarkenUIColor(GetThemeSurface(),16))
DrawRectangleLinesEx(card1,1,GetThemeButton())
DrawRectangleRec(card2,DarkenUIColor(GetThemeSurface(),18))
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())
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)
DrawRectangleRec(action,GetThemeButton())
WidgetText("placed action", action.x+14, action.y+9, UI_TEXT_12, GetThemeText())
}
+3 -3
View File
@@ -13,13 +13,13 @@ state {
}
screen MenusExample(viewport: Rectangle) {
background GetThemeBackground()
WidgetBackground(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)
if result.activated_id != 0 {
set snprintf(status,sizeof(status),"Command %d",result.activated_id)
snprintf(status,sizeof(status),"Command %d",result.activated_id)
}
text status x: 40 y: 80 size: 20 color: GetThemeText()
WidgetText(status, 40, 80, 20, GetThemeText())
}
+12 -12
View File
@@ -16,27 +16,27 @@ state {
}
screen BasicControlsExample(viewport: Rectangle) {
background GetThemeBackground()
text "Basic controls" x: 40 y: 40 size: UI_TEXT_24 color: GetThemeText()
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})
if picked {
set radio = picked
radio = picked
}
set picked = DrawUIRadioButton((UIRadioButton){{40,124,160,28},"Choice B",2,radio==2,0})
picked = DrawUIRadioButton((UIRadioButton){{40,124,160,28},"Choice B",2,radio==2,0})
if picked {
set radio = picked
radio = picked
}
draw DrawUISpinbox((UISpinbox){{240,90,140,34},201,0,10,1,&spin,0})
draw DrawUICombobox((UICombobox){{240,140,180,34},202,choices,3,&combo,0})
draw DrawUIProgressBar((UIProgressBar){{40,210,380,28},0,100,progress,"Progress"})
on key KEY_RIGHT {
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)) {
if progress < 100 {
set progress += 5
progress += 5
}
}
on key KEY_LEFT {
if (UIKeyPressed(KEY_LEFT)) {
if progress > 0 {
set progress -= 5
progress -= 5
}
}
}
+5 -5
View File
@@ -19,14 +19,14 @@ state {
}
screen CollectionsExample(viewport: Rectangle) {
background GetThemeBackground()
WidgetBackground(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}}
draw DrawUIListBox((UIListBox){{40,60,180,180},301,items,4,&list_sel,&list_scroll,30})
draw DrawUITreeView((UITreeView){{260,60,220,180},302,tree,4,&tree_sel,&tree_scroll,28})
draw DrawUITableView((UITableView){{520,60,320,180},303,cols,2,rows,2,NULL,&row_sel,&sort_col,&table_scroll,28})
text "Collections: list,tree,and table" x: 40 y: 280 size: 18 color: GetThemeText()
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())
}
+7 -7
View File
@@ -15,14 +15,14 @@ state {
}
screen TextEditorExample(viewport: Rectangle) {
background GetThemeBackground()
draw 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})
text "Ctrl/Cmd+C,X,and V work in the text area." x: 40 y: 260 size: UI_TEXT_16 color: GetThemeText()
button "Copy" x: 40 y: 300 w: 110 h: 34 style: UI_BUTTON_STYLE_SECONDARY {
set SetUIClipboardTextValue(text_value)
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) {
SetUIClipboardTextValue(text_value)
}
button "Paste" x: 170 y: 300 w: 110 h: 34 style: UI_BUTTON_STYLE_SECONDARY {
if WidgetButton(170, 300, 110, 34, "Paste", UI_BUTTON_STYLE_SECONDARY) {
clip: const char * = GetUIClipboardTextValue()
set snprintf(text_value,sizeof(text_value),"%s",clip)
snprintf(text_value,sizeof(text_value),"%s",clip)
}
}
+6 -6
View File
@@ -16,15 +16,15 @@ state {
}
screen CanvasExample(viewport: Rectangle) {
background GetThemeBackground()
WidgetBackground(GetThemeBackground())
canvas: UICanvasResult = BeginUICanvas((UICanvas){{40,50,620,420},&sx,&sy,&zoom})
draw DrawUICanvasGrid((Rectangle){40,50,620,420},24,GetThemeButton())
DrawUICanvasGrid((Rectangle){40,50,620,420},24,GetThemeButton())
for i in 0..2 {
draw DrawRectangleRec(shapes[i],i==selected?GetThemeButtonHover():GetThemeSurface())
draw DrawRectangleLinesEx(shapes[i],2.0f,GetThemeIcon())
DrawRectangleRec(shapes[i],i==selected?GetThemeButtonHover():GetThemeSurface())
DrawRectangleLinesEx(shapes[i],2.0f,GetThemeIcon())
}
if canvas.active && IsMouseButtonReleased(MOUSE_BUTTON_LEFT) {
set selected = UICanvasHitTest(canvas.world,shapes,2)
selected = UICanvasHitTest(canvas.world,shapes,2)
}
draw EndUICanvas((UICanvas){{40,50,620,420},&sx,&sy,&zoom})
EndUICanvas((UICanvas){{40,50,620,420},&sx,&sy,&zoom})
}
+5 -5
View File
@@ -15,11 +15,11 @@ state {
}
screen ContainersExample(viewport: Rectangle) {
background GetThemeBackground()
draw DrawUINotebook((UINotebook){{40,50,680,400},tabs,3,&tab})
draw DrawUIPanedView((UIPanedView){{40,100,680,280},501,1,&split,120,160})
draw DrawUICollapsible((UICollapsible){{60,410,320,120},"Details",&open})
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})
if open {
text "Collapsible content" x: 80 y: 455 size: UI_TEXT_16 color: GetThemeText()
WidgetText("Collapsible content", 80, 455, UI_TEXT_16, GetThemeText())
}
}
+11 -11
View File
@@ -16,24 +16,24 @@ state {
}
screen DialogsExample(viewport: Rectangle) {
background GetThemeBackground()
button "Message" x: 40 y: 60 w: 150 h: 34 style: UI_BUTTON_STYLE_PRIMARY {
set dialog = 1
WidgetBackground(GetThemeBackground())
if WidgetButton(40, 60, 150, 34, "Message", UI_BUTTON_STYLE_PRIMARY) {
dialog = 1
}
button "Confirm" x: 40 y: 104 w: 150 h: 34 style: UI_BUTTON_STYLE_PRIMARY {
set dialog = 2
if WidgetButton(40, 104, 150, 34, "Confirm", UI_BUTTON_STYLE_PRIMARY) {
dialog = 2
}
button "Prompt" x: 40 y: 148 w: 150 h: 34 style: UI_BUTTON_STYLE_PRIMARY {
set dialog = 3
if WidgetButton(40, 148, 150, 34, "Prompt", UI_BUTTON_STYLE_PRIMARY) {
dialog = 3
}
draw DrawUIColorPicker((Rectangle){240,60,320,160},&color)
DrawUIColorPicker((Rectangle){240,60,320,160},&color)
if dialog == 1 && DrawUIMessageDialog((UIMessageDialog){"Message","Hello from Kryon.","OK"}) > 0 {
set dialog = 0
dialog = 0
}
if dialog == 2 && DrawUIConfirmDialog((UIConfirmDialog){"Confirm","Continue?","No","Yes"}) != 0 {
set dialog = 0
dialog = 0
}
if dialog == 3 && DrawUIPromptDialog((UIPromptDialog){"Prompt",prompt,sizeof(prompt),&cursor,&focused,"Cancel","Save"}) != 0 {
set dialog = 0
dialog = 0
}
}
+7 -7
View File
@@ -13,15 +13,15 @@ state {
}
screen KeyboardPlatformExample(viewport: Rectangle) {
background GetThemeBackground()
text "Keyboard and clipboard" x: 40 y: 40 size: UI_TEXT_24 color: GetThemeText()
text message x: 40 y: 90 size: UI_TEXT_16 color: GetThemeText()
WidgetBackground(GetThemeBackground())
WidgetText("Keyboard and clipboard", 40, 40, UI_TEXT_24, GetThemeText())
WidgetText(message, 40, 90, UI_TEXT_16, GetThemeText())
if UIAcceleratorPressed((UIAccelerator){KEY_C,1,0,0,1}) {
set SetUIClipboardTextValue("Copied from Kryon")
set snprintf(message,sizeof(message),"Copied to clipboard")
set copied = 1
SetUIClipboardTextValue("Copied from Kryon")
snprintf(message,sizeof(message),"Copied to clipboard")
copied = 1
}
if copied {
text "Clipboard updated." x: 40 y: 130 size: UI_TEXT_16 color: GetThemeLink()
WidgetText("Clipboard updated.", 40, 130, UI_TEXT_16, GetThemeLink())
}
}
+6 -6
View File
@@ -12,13 +12,13 @@ state {
}
screen AccessibilityExample(viewport: Rectangle) {
background GetThemeBackground()
text "Accessibility overlay" x: 40 y: 40 size: UI_TEXT_24 color: GetThemeText()
draw DrawUICheckboxToggle(40,90,"Show focus/debug overlay",&enabled)
button "Focusable Button" x: 40 y: 140 w: 200 h: 40 style: UI_BUTTON_STYLE_PRIMARY {
set enabled = !enabled
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) {
enabled = !enabled
}
if enabled {
draw DrawUIFocus((Rectangle){36,136,208,48})
DrawUIFocus((Rectangle){36,136,208,48})
}
}
+1
View File
@@ -26,6 +26,7 @@
#include "ui.h"
#include "ui_text_layout.h"
#include "ui_transition.h"
#include "ui_widgets.h"
#include "locale.h"
#include "lyra_account.h"
#include "lyra_sync.h"
+2 -2
View File
@@ -3,7 +3,7 @@
#define KRYON_VERSION_MAJOR 0
#define KRYON_VERSION_MINOR 1
#define KRYON_VERSION_PATCH 5
#define KRYON_VERSION_STRING "v0.1.5"
#define KRYON_VERSION_PATCH 7
#define KRYON_VERSION_STRING "v0.1.7"
#endif /* KRYON_VERSION_H */
+3 -1
View File
@@ -96,8 +96,10 @@ typedef enum {
UI_ICON_TYPE_PLATFORMS_DISCORD,
UI_ICON_TYPE_PLATFORMS_DROID,
UI_ICON_TYPE_PLATFORMS_FDROID,
UI_ICON_TYPE_PLATFORMS_FREEBSD,
UI_ICON_TYPE_PLATFORMS_GITHUB,
UI_ICON_TYPE_PLATFORMS_ITCH,
UI_ICON_TYPE_PLATFORMS_MACOS,
UI_ICON_TYPE_PLATFORMS_PLAYSTORE,
UI_ICON_TYPE_PLATFORMS_SRHT,
UI_ICON_TYPE_PLATFORMS_TELEGRAM,
@@ -108,7 +110,7 @@ typedef enum {
UI_ICON_TYPE_TILES_TILE3,
UI_ICON_TYPE_TILES_TILE4,
UI_ICON_TYPE_COUNT = 103
UI_ICON_TYPE_COUNT = 105
} UIIconType;
#endif /* UI_ICON_TYPES_H */
+42
View File
@@ -0,0 +1,42 @@
#ifndef UI_WIDGETS_H
#define UI_WIDGETS_H
/*
* Widget library — ordinary C functions that provide the verb-free
* widget vocabulary for .kry source files.
*
* These exist so that .kry code can call Text(...), Rect(...), Line(...),
* Background(...), and Button(...) as plain function calls instead of
* through special-case compiler keywords. The compiler (kc) treats them
* exactly like any other call; there is no built-in widget syntax.
*
* Every function here lowers to the existing immediate-mode draw calls
* (DrawUIText, DrawRectangleRec, DrawLine, DrawUIGenericButton). Defaults
* match what the removed keyword forms used to provide.
*/
#include "ui_color.h" /* Color */
#include "ui_controls.h" /* DrawUIGenericButton, UIButtonStyle */
#include "ui_layout.h" /* GetUIViewWidth, GetUIViewHeight */
#include "theme.h" /* GetThemeText, GetThemeBackground, ... */
/* Draw a piece of text. Mirrors the old `text` keyword. */
void WidgetText(const char *label, int x, int y, int font_size, Color color);
/* Draw a filled rectangle, with an optional 1px border when border is
* non-transparent. Mirrors the old `rect` keyword. */
void WidgetRect(int x, int y, int w, int h, Color fill, Color border);
/* Draw a line. Mirrors the old `line` keyword. */
void WidgetLine(int x1, int y1, int x2, int y2, Color color);
/* Clear the whole view with a background color. Mirrors the old
* `background` keyword. */
void WidgetBackground(Color color);
/* Draw a button and return 1 if it was clicked this frame, 0 otherwise.
* Mirrors the old `button` keyword's positional form. */
int WidgetButton(int x, int y, int w, int h, const char *label,
UIButtonStyle style);
#endif /* UI_WIDGETS_H */
Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

+137
View File
@@ -0,0 +1,137 @@
#!/usr/bin/env python3
"""Generate 16x16 pixel-art RGBA PNGs for FreeBSD and macOS platform icons.
The existing kryon platform icons (tux/droid/win/wasm) are flat, sharp
pixel-art with transparent backgrounds. This hand-crafts two more in that
style using raw RGBA pixel grids and encodes them as PNGs via the stdlib
(no PIL dependency).
"""
import struct
import zlib
TRANSPARENT = (0, 0, 0, 0)
def encode_png(path, pixels, width, height):
"""Encode a width*height RGBA pixel list (row-major) into a PNG file."""
raw = bytearray()
for y in range(height):
raw.append(0) # filter type 0 (None) per scanline
for x in range(width):
r, g, b, a = pixels[y * width + x]
raw += bytes((r, g, b, a))
def chunk(tag, data):
c = tag + data
return struct.pack(">I", len(data)) + c + struct.pack(">I", zlib.crc32(c) & 0xFFFFFFFF)
sig = b"\x89PNG\r\n\x1a\n"
ihdr = struct.pack(">IIBBBBB", width, height, 8, 6, 0, 0, 0) # 8-bit, colour type 6 (RGBA)
idat = zlib.compress(bytes(raw), 9)
with open(path, "wb") as f:
f.write(sig)
f.write(chunk(b"IHDR", ihdr))
f.write(chunk(b"IDAT", idat))
f.write(chunk(b"IEND", b""))
def grid(rows):
"""Build a flat pixel list from an array of strings. Each char maps to a color.
' ' or '.' = transparent. Other chars are looked up in the palette passed
via a closure: we return (palette, pixels).
"""
width = max(len(r) for r in rows)
out = []
for row in rows:
row = row.ljust(width)
out.append(row)
return out, width
# ---- FreeBSD: a stylized red "beastie" devil head, horns + eyes ----
# Palette
R = (205, 45, 45, 255) # beastie red body
RD = (155, 28, 28, 255) # darker red shade
W = (245, 245, 245, 255) # eye white
K = (25, 18, 18, 255) # outline / pupil
# 16x16. Bold horned silhouette with a pointed chin and two clear eyes.
# Horns sweep up-and-out, head fills the middle, chin tapers at bottom.
freebsd = [
"................",
"...RR......RR...",
"..RRRR....RRRR..",
"..RRRRR..RRRRR..",
".RRRRRRRRRRRRRR.",
".RRRRRRRRRRRRRR.",
"RRRRRRRRRRRRRRRR",
"RRWWRRRRRRRRWWRR",
"RRWWRRRRRRRRWWRR",
"RRRRRRRRRRRRRRRR",
"RRRRRRRRRRRRRRRR",
".RRRRRRRRRRRRRR.",
".RRRRRRRRRRRRRR.",
"..RRRRRRRRRRRR..",
"...RRRRRRRRRR...",
".....RRRRRR.....",
]
# ---- macOS: a graphite apple silhouette with a bite + leaf ----
G = (58, 58, 62, 255) # graphite body
GD = (35, 35, 40, 255) # deeper shade
L = (110, 170, 75, 255) # leaf green
# 16x16. Classic apple: notch at top center where the leaf stem sits,
# leaf leaning right from the notch, bite notch on the upper-right side.
macos = [
"................",
"......LLL.......",
".....LL.........",
"................",
"....GGGGGGG.....",
"...GGGGGGGGG.G..",
"..GGGGGGGGGGGG..",
".GGGGGGGGGGGGG..",
".GGGGGGGGGGGGG..",
".GGGGGGGGGGGGG..",
".GGGGGGGGGGGGG..",
".GGGGGGGGGGGGG..",
"..GGGGGGGGGGG...",
"..GGGGGGGGGGG...",
"...GGGGGGGGG....",
"....GGGGGGG.....",
]
def render(rows, palette):
flat = []
for row in rows:
for ch in row:
flat.append(palette.get(ch, TRANSPARENT))
return flat
fb_palette = {"R": R, "D": RD, "W": W, "K": K}
mac_palette = {"G": G, "D": GD, "L": L}
def main():
import os
here = os.path.dirname(os.path.abspath(__file__))
root = os.path.dirname(here)
platforms = os.path.join(root, "platforms")
fb_rows, fb_w = grid(freebsd)
encode_png(os.path.join(platforms, "freebsd.png"),
render(fb_rows, fb_palette), fb_w, len(fb_rows))
print("wrote platforms/freebsd.png (%dx%d)" % (fb_w, len(fb_rows)))
mac_rows, mac_w = grid(macos)
encode_png(os.path.join(platforms, "macos.png"),
render(mac_rows, mac_palette), mac_w, len(mac_rows))
print("wrote platforms/macos.png (%dx%d)" % (mac_w, len(mac_rows)))
if __name__ == "__main__":
main()
+76 -9
View File
@@ -310,10 +310,30 @@ QuitDesktopTrayMain(gpointer user_data)
return G_SOURCE_REMOVE;
}
static int
IconFileExistsAt(char *buf, size_t bufsize, const char *dir, const char *subdir)
{
int n;
n = snprintf(buf, bufsize, "%s", dir);
if(n < 0 || (size_t)n >= bufsize)
return 0;
if(subdir != NULL) {
n = snprintf(buf + strlen(buf), bufsize - strlen(buf), "/%s", subdir);
if(n < 0 || (size_t)n >= bufsize - strlen(buf))
return 0;
}
n = snprintf(buf + strlen(buf), bufsize - strlen(buf), "/%s.png", TrayIconName);
if(n < 0 || (size_t)n >= bufsize - strlen(buf))
return 0;
return g_file_test(buf, G_FILE_TEST_IS_REGULAR) ? 1 : 0;
}
static const char *
GetDesktopTrayIconPath(void)
{
static char path[512];
static char exe_dir[384];
static const char *const exe_links[] = {
#if defined(__FreeBSD__)
"/proc/curproc/file",
@@ -323,23 +343,34 @@ GetDesktopTrayIconPath(void)
#endif
NULL
};
/* Standard hicolor sizes, largest first (sharpest rendering). */
static const char *const hicolor_sizes[] = {
"512x512", "256x256", "192x192", "128x128", "96x96", "64x64", "48x48",
"32x32", "24x24", "16x16", "scalable", NULL
};
exe_dir[0] = '\0';
for(int i = 0; exe_links[i] != NULL; i++) {
ssize_t len = readlink(exe_links[i], path, sizeof(path) - 128);
if(len > 0 && (size_t)len < sizeof(path) - 128) {
ssize_t len = readlink(exe_links[i], exe_dir, sizeof(exe_dir) - 1);
if(len > 0 && (size_t)len < sizeof(exe_dir) - 1) {
char *slash;
path[len] = '\0';
slash = strrchr(path, '/');
exe_dir[len] = '\0';
slash = strrchr(exe_dir, '/');
if(slash != NULL) {
slash[1] = '\0';
strncat(path, TrayIconName, sizeof(path) - strlen(path) - 1);
strncat(path, ".png", sizeof(path) - strlen(path) - 1);
if(g_file_test(path, G_FILE_TEST_IS_REGULAR))
return path;
*slash = '\0';
break;
}
exe_dir[0] = '\0';
}
}
/* 1. Icon next to the executable (e.g. portable/AppImage layout). */
if(exe_dir[0] != '\0') {
if(IconFileExistsAt(path, sizeof(path), exe_dir, NULL))
return path;
}
/* 2. Caller-supplied candidate paths (often CWD-relative). */
if(TrayIconPaths != NULL) {
for(int i = 0; TrayIconPaths[i] != NULL; i++) {
if(g_file_test(TrayIconPaths[i], G_FILE_TEST_IS_REGULAR))
@@ -347,6 +378,42 @@ GetDesktopTrayIconPath(void)
}
}
/* 3. Installed hicolor theme icons relative to the executable
* (<exedir>/../share/icons/hicolor/<size>/apps/<icon>.png). This is where
* the icon actually ships when installed via a package/AppImage. */
if(exe_dir[0] != '\0') {
for(int i = 0; hicolor_sizes[i] != NULL; i++) {
char apps_dir[448];
int n = snprintf(apps_dir, sizeof(apps_dir),
"%s/../share/icons/hicolor/%s/apps",
exe_dir, hicolor_sizes[i]);
if(n > 0 && (size_t)n < sizeof(apps_dir) &&
IconFileExistsAt(path, sizeof(path), apps_dir, NULL))
return path;
}
}
/* 4. System data dirs ($XDG_DATA_DIRS, default /usr/local/share:/usr/share). */
{
const char *data_dirs = getenv("XDG_DATA_DIRS");
char buf[512];
if(data_dirs == NULL || data_dirs[0] == '\0')
data_dirs = "/usr/local/share:/usr/share";
snprintf(buf, sizeof(buf), "%s", data_dirs);
char *tok = strtok(buf, ":");
while(tok != NULL) {
for(int i = 0; hicolor_sizes[i] != NULL; i++) {
char apps_dir[512];
int n = snprintf(apps_dir, sizeof(apps_dir),
"%s/icons/hicolor/%s/apps", tok, hicolor_sizes[i]);
if(n > 0 && (size_t)n < sizeof(apps_dir) &&
IconFileExistsAt(path, sizeof(path), apps_dir, NULL))
return path;
}
tok = strtok(NULL, ":");
}
}
return NULL;
}
+2
View File
@@ -1,5 +1,7 @@
#include "platform.h"
#include <stddef.h>
#if defined(_WIN32)
#include <stdlib.h>
+81
View File
@@ -59,6 +59,22 @@ typedef struct UITextSelection {
static UITextSelection g_ui_text_area_selection = {0};
static UITextSelection g_ui_text_field_selection = {0};
static int g_ui_text_field_drag_id = 0;
/* Identity of the widget that currently owns text input focus, recorded as the
* address of its `focused` flag. Ownership is PERSISTENT across frames: it does
* not reset at frame start, it only changes when a text input is clicked (or
* explicitly claimed). This guarantees that at most one text input (UITextField
* or UITextArea) is ever treated as focused, so at most one blinking caret can
* ever be drawn - the UI layer owns focus, never trusting stale per-widget
* flags. Works across widget types without relying on focus_id (which defaults
* to 0 and is shared when unset). */
static int *g_ui_text_focus_owner = NULL;
/* Frame counter and the frame on which the current owner last confirmed it is
* still alive. If the owner has not run for a frame, ownership is considered
* released (the user navigated away from that screen / the widget is gone),
* which lets a new screen's autofocus adopt cleanly. */
static unsigned long g_ui_text_focus_frame = 0;
static unsigned long g_ui_text_focus_owner_frame = 0;
static int *g_ui_text_focus_owner_this_frame = NULL;
#define UI_TEXT_INPUT_QUEUE_MAX 64
static int g_ui_text_input_codepoints[UI_TEXT_INPUT_QUEUE_MAX];
@@ -807,6 +823,16 @@ BeginUIFocus(void)
g_ui_focus_count = 0;
g_ui_focus_tab_dir = 0;
g_ui_focus_frame_open = 1;
/* Advance the frame counter and release ownership if the current owner did
* not render last frame (the user navigated away or the widget is gone).
* This lets a new screen's autofocus adopt cleanly, while still preventing
* two live widgets from both showing a caret within a single frame. */
g_ui_text_focus_frame++;
if(g_ui_text_focus_owner != NULL &&
g_ui_text_focus_owner_frame != g_ui_text_focus_frame - 1 &&
g_ui_text_focus_owner_frame != g_ui_text_focus_frame)
g_ui_text_focus_owner = NULL;
g_ui_text_focus_owner_this_frame = NULL;
if(UIKeyPressed(KEY_TAB))
g_ui_focus_tab_dir = (UIKeyDown(KEY_LEFT_SHIFT) || UIKeyDown(KEY_RIGHT_SHIFT)) ? -1 : 1;
}
@@ -867,6 +893,55 @@ RegisterUIFocus(int id, Rectangle bounds)
return g_ui_focus_active_id == id;
}
static void
ClaimUITextFocus(int *focused)
{
if(focused == NULL)
return;
/* Displace any previous owner first by clearing its flag, so its caret
* disappears immediately this frame even though it has not re-run yet. */
if(g_ui_text_focus_owner != NULL && g_ui_text_focus_owner != focused)
*g_ui_text_focus_owner = 0;
g_ui_text_focus_owner = focused;
g_ui_text_focus_owner_this_frame = focused;
g_ui_text_focus_owner_frame = g_ui_text_focus_frame;
*focused = 1;
}
static int
IsUITextFocusOwner(int *focused)
{
/* Strict single-owner enforcement. A text input is focused if and only if
* it is the recorded owner. Ownership survives across frames (so a stale
* per-widget `focused` flag can never revive a caret that another input
* owns) but is auto-released if the owner stops rendering (navigation
* away), letting a new screen autofocus cleanly. Within one frame, only the
* first widget to claim/adopt wins; every other text input is denied. */
if(focused == NULL)
return 0;
if(g_ui_text_focus_owner == focused) {
g_ui_text_focus_owner_this_frame = focused;
g_ui_text_focus_owner_frame = g_ui_text_focus_frame;
return 1;
}
/* Already owned by someone else this frame: deny and clear stale flag. */
if(g_ui_text_focus_owner_this_frame != NULL) {
*focused = 0;
return 0;
}
/* No owner yet this frame. Allow adoption only if the app set this widget's
* flag (autofocus / programmatic SetUIFocus). First adoption wins; any
* later widget with a stale flag is denied above. */
if(*focused != 0 && g_ui_text_focus_owner == NULL) {
g_ui_text_focus_owner = focused;
g_ui_text_focus_owner_this_frame = focused;
g_ui_text_focus_owner_frame = g_ui_text_focus_frame;
return 1;
}
*focused = 0;
return 0;
}
int
IsUIFocusActive(int id)
{
@@ -1975,6 +2050,7 @@ DrawUITextArea(UITextArea area)
first_line_y = GetUIControlTextY("Hg", (int)area.bounds.y + padding_y,
line_h, font);
focused = *area.focused != 0;
focused = IsUITextFocusOwner(area.focused) ? focused : 0;
scroll_y = area.scroll_y != NULL ? *area.scroll_y : 0;
if(area.focus_id > 0 && RegisterUIFocus(area.focus_id, area.bounds)) {
@@ -1998,6 +2074,7 @@ DrawUITextArea(UITextArea area)
int double_click_slop = ScaleUIPx(6);
focused = 1;
ClaimUITextFocus(area.focused);
clicked_cursor = ui_text_area_cursor_from_point(area.text, font, line_gap,
(int)area.bounds.x + padding_x, (int)area.bounds.y + padding_y,
(int)mouse_world.x, (int)mouse_world.y, scroll_y);
@@ -2046,6 +2123,7 @@ DrawUITextArea(UITextArea area)
if(scroll_y < 0)
scroll_y = 0;
focused = 1;
ClaimUITextFocus(area.focused);
*area.cursor_position = ui_text_area_cursor_from_point(area.text, font, line_gap,
(int)area.bounds.x + padding_x, (int)area.bounds.y + padding_y,
(int)mouse_world.x, (int)mouse_world.y, scroll_y);
@@ -2378,6 +2456,7 @@ DrawUITextField(UITextField field)
font = field.font > 0 ? field.font : GetUIFontSize();
padding_x = field.style.padding_x > 0 ? field.style.padding_x : ScaleUIPx(10);
focused = *field.focused != 0;
focused = IsUITextFocusOwner(field.focused) ? focused : 0;
if(field.focus_id > 0 && RegisterUIFocus(field.focus_id, field.bounds)) {
focused = 1;
@@ -2393,6 +2472,7 @@ DrawUITextField(UITextField field)
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
if(mouse_inside && !captured) {
focused = 1;
ClaimUITextFocus(field.focused);
*field.cursor_position = ui_text_cursor_from_x(
field.text, font, (int)field.bounds.x + padding_x,
(int)mouse_world.x);
@@ -2408,6 +2488,7 @@ DrawUITextField(UITextField field)
if(g_ui_text_field_drag_id == field.focus_id &&
IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
focused = 1;
ClaimUITextFocus(field.focused);
*field.cursor_position = ui_text_cursor_from_x(
field.text, font, (int)field.bounds.x + padding_x,
(int)mouse_world.x);
+18 -1
View File
@@ -4849,6 +4849,14 @@ static const unsigned char ui_icon_platforms_fdroid[] = {
0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
};
static const unsigned char ui_icon_platforms_freebsd[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff,
0x61, 0x00, 0x00, 0x00, 0x4e, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0x63, 0x60, 0xa0, 0x26, 0x38, 0xab, 0xab, 0xfb, 0x1f, 0x84, 0xc9, 0x92, 0x87, 0x49, 0xe2, 0x52, 0x44, 0x48, 0x1e, 0x43, 0x01,
0xb2, 0x22, 0x7c, 0x72, 0x38, 0x15, 0x10, 0x83, 0xa9, 0x63, 0x00, 0xb9, 0x9a, 0xe1, 0x86, 0xc0, 0x18, 0x5f, 0xbf, 0x7e, 0x05, 0x63, 0x42, 0x1a, 0xd0, 0xd5, 0x51, 0xcf, 0x00, 0x8a, 0xbd, 0x30,
0x20, 0x01, 0x49, 0xbd, 0x74, 0x40, 0x8e, 0x21, 0x44, 0xe5, 0x07, 0x92, 0x34, 0x13, 0x63, 0x10, 0x36, 0xb5, 0x00, 0x40, 0xbb, 0x9d, 0x6c, 0xa7, 0xb1, 0x0a, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x49,
0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
};
static const unsigned char ui_icon_platforms_github[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x08, 0x06, 0x00, 0x00, 0x00, 0x73, 0x7a, 0x7a,
0xf4, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, 0x01, 0x06, 0x49, 0x44, 0x41, 0x54, 0x58, 0x85, 0xcd, 0x57, 0xdb, 0x16, 0xc3, 0x20, 0x08, 0x83,
@@ -4877,6 +4885,13 @@ static const unsigned char ui_icon_platforms_itch[] = {
0x84, 0x1c, 0xc0, 0x07, 0x38, 0xb5, 0x9e, 0x72, 0x92, 0x81, 0xe5, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
};
static const unsigned char ui_icon_platforms_macos[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff,
0x61, 0x00, 0x00, 0x00, 0x3b, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0x63, 0x60, 0xa0, 0x15, 0xc8, 0x5b, 0xe5, 0xfd, 0x1f, 0x86, 0xc9, 0xd6, 0xcc, 0x30, 0x20, 0xc0, 0xca, 0xca, 0xee, 0x3f, 0x2e,
0x4c, 0x91, 0x66, 0x64, 0x43, 0xb0, 0x1a, 0x46, 0x8c, 0x66, 0x9c, 0xae, 0x21, 0x55, 0xf3, 0xa8, 0x01, 0x38, 0xa2, 0x94, 0x22, 0xcd, 0x54, 0x31, 0x80, 0x94, 0x84, 0x44, 0xd5, 0xa4, 0x0c, 0x00,
0x7d, 0xf9, 0xeb, 0x2f, 0xbe, 0x77, 0xe0, 0x55, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
};
static const unsigned char ui_icon_platforms_playstore[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff,
0x61, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, 0x00, 0xc1, 0x49, 0x44, 0x41, 0x54, 0x38, 0x8d, 0x63, 0x4c, 0x9a, 0xf5, 0xff, 0xff, 0x1f, 0xe3,
@@ -5066,8 +5081,10 @@ const UIIconAsset ui_icon_assets[] = {
{UI_ICON_TYPE_PLATFORMS_DISCORD, "platforms_discord", ui_icon_platforms_discord, 180u},
{UI_ICON_TYPE_PLATFORMS_DROID, "platforms_droid", ui_icon_platforms_droid, 170u},
{UI_ICON_TYPE_PLATFORMS_FDROID, "platforms_fdroid", ui_icon_platforms_fdroid, 268u},
{UI_ICON_TYPE_PLATFORMS_FREEBSD, "platforms_freebsd", ui_icon_platforms_freebsd, 135u},
{UI_ICON_TYPE_PLATFORMS_GITHUB, "platforms_github", ui_icon_platforms_github, 332u},
{UI_ICON_TYPE_PLATFORMS_ITCH, "platforms_itch", ui_icon_platforms_itch, 344u},
{UI_ICON_TYPE_PLATFORMS_MACOS, "platforms_macos", ui_icon_platforms_macos, 116u},
{UI_ICON_TYPE_PLATFORMS_PLAYSTORE, "platforms_playstore", ui_icon_platforms_playstore, 263u},
{UI_ICON_TYPE_PLATFORMS_SRHT, "platforms_srht", ui_icon_platforms_srht, 233u},
{UI_ICON_TYPE_PLATFORMS_TELEGRAM, "platforms_telegram", ui_icon_platforms_telegram, 182u},
@@ -5079,4 +5096,4 @@ const UIIconAsset ui_icon_assets[] = {
{UI_ICON_TYPE_TILES_TILE4, "tiles_tile4", ui_icon_tiles_tile4, 205u},
};
const unsigned int ui_icon_asset_count = 102u;
const unsigned int ui_icon_asset_count = 104u;
+2
View File
@@ -95,8 +95,10 @@ const char *ui_icon_names[] = {
"platforms_discord.png", /* UI_ICON_TYPE_PLATFORMS_DISCORD */
"platforms_droid.png", /* UI_ICON_TYPE_PLATFORMS_DROID */
"platforms_fdroid.png", /* UI_ICON_TYPE_PLATFORMS_FDROID */
"platforms_freebsd.png", /* UI_ICON_TYPE_PLATFORMS_FREEBSD */
"platforms_github.png", /* UI_ICON_TYPE_PLATFORMS_GITHUB */
"platforms_itch.png", /* UI_ICON_TYPE_PLATFORMS_ITCH */
"platforms_macos.png", /* UI_ICON_TYPE_PLATFORMS_MACOS */
"platforms_playstore.png", /* UI_ICON_TYPE_PLATFORMS_PLAYSTORE */
"platforms_srht.png", /* UI_ICON_TYPE_PLATFORMS_SRHT */
"platforms_telegram.png", /* UI_ICON_TYPE_PLATFORMS_TELEGRAM */
+39
View File
@@ -0,0 +1,39 @@
#include "ui_widgets.h"
#include "kryon_compat.generated.h" /* DrawRectangleRec, DrawRectangleLinesEx, DrawLine, BLANK, Rectangle */
void
WidgetText(const char *label, int x, int y, int font_size, Color color)
{
DrawUIText(label, x, y, font_size, color);
}
void
WidgetRect(int x, int y, int w, int h, Color fill, Color border)
{
DrawRectangleRec((Rectangle){x, y, w, h}, fill);
/* A border alpha of 0 means "no border", matching the old `rect`
* keyword which only drew the outline when a border: prop was given. */
if(border.a != 0)
DrawRectangleLinesEx((Rectangle){x, y, w, h}, 1, border);
}
void
WidgetLine(int x1, int y1, int x2, int y2, Color color)
{
DrawLine(x1, y1, x2, y2, color);
}
void
WidgetBackground(Color color)
{
DrawRectangleRec((Rectangle){0, 0, GetUIViewWidth(), GetUIViewHeight()},
color);
}
int
WidgetButton(int x, int y, int w, int h, const char *label,
UIButtonStyle style)
{
return DrawUIGenericButton(x, y, w, h, label, style, 0, NULL);
}
+50 -6
View File
@@ -26,10 +26,10 @@ screen valid {
value := first + second
unused second
InitializeThing()
draw DrawThing()
DrawThing()
value = 1
first, second = second, first
native NativeThing()
NativeThing()
c #if 0
c #endif
for int i = 0; i < 2; i++ {
@@ -229,7 +229,7 @@ cat > "$work/src/ui/panel.kry" <<'EOF'
#import "thing.h"
draw :: (app: void*) {
native (void)app
unused app
}
EOF
@@ -479,11 +479,11 @@ cat > "$work/src/ui/panel.kry" <<'EOF'
#import "thing.h"
draw :: (app: void*) {
native (void)app
unused app
}
panel_c_entry :: (app: void*) #export {
native (void)app
unused app
}
EOF
@@ -560,7 +560,7 @@ grep -q 'unknown top-level statement: import "src/ui/panel.kry"' "$err"
cat > "$work/src/preview.kry" <<'EOF'
preview stage_preview(viewport: Rectangle) {
background BLACK
WidgetBackground(BLACK)
}
EOF
@@ -880,6 +880,50 @@ fi
grep -q "'do' syntax was removed" "$err"
grep -Eq 'bad_do\.kry:2:1: error:' "$err"
# Removed widget verbs: draw, native, set, widget must now error with a
# migration hint, mirroring the let/var/do removals above.
for verb in draw native set widget; do
cat > "$work/src/bad_${verb}.kry" <<EOF
screen bad {
${verb} InitializeThing()
}
EOF
if "$kc" --no-main --root "$work" -o "$out" "$work/src/bad_${verb}.kry" >"$err" 2>&1; then
echo "removed ${verb} statement was accepted" >&2
exit 1
fi
grep -q "was removed" "$err"
grep -Eq "bad_${verb}\.kry:2:1: error:" "$err"
done
# Removed sugar keywords (second pass): each must error with a migration hint.
# Each has distinct syntax, so they get bespoke test cases.
check_removed() {
# $1 = short name, $2 = .kry body, $3 = expected error substring
cat > "$work/src/bad_$1.kry" <<EOF
screen bad {
$2
}
EOF
if "$kc" --no-main --root "$work" -o "$out" "$work/src/bad_$1.kry" >"$err" 2>&1; then
echo "removed $1 statement was accepted" >&2
exit 1
fi
grep -q "$3" "$err"
grep -Eq "bad_$1\.kry:2:1: error:" "$err"
}
check_removed advance ' advance x by 1' "advance"
check_removed clamp_min ' clamp_min x 1' "clamp_min"
check_removed clamp_max ' clamp_max x 1' "clamp_max"
check_removed c_rect ' c_rect r = 0,0,1,1' "c_rect"
check_removed texture ' texture t = 0' "texture"
check_removed set_theme ' set_theme THEME_SKY light' "set_theme"
check_removed button ' button "x" x: 0 y: 0 {' "button"
check_removed event ' event foo() {' "event"
check_removed icon_button ' icon_button 0 {' "icon_button"
check_removed on_key ' on key KEY_A {' "on key"
check_removed on_key_down ' on key_down KEY_A {' "on key_down"
cat > "$work/src/bad_goto.kry" <<'EOF'
screen bad {
goto