diff --git a/CHANGELOG.md b/CHANGELOG.md index 87cfe9610..9d4d93051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,7 @@ same Kryon as the app, or the build names the export both define. Then: - `zx2native` desktop UI executables link the real SDL2/GPU/Cairo desktop host library (`libkryon-desktop.so`, registered as `kryon-desktop.library`) instead of the headless CPU-only `libkryon-pixmap.so` (`kryon-pixmap.library`), which is removed: `zx_window_host.zi` now exports both `App.Show` (`ZxWindow*Host`) and full `App.Run` (`frames_zx` loop, Cairo/Pango/FreeType text measurement & raster, SDL2 window/input/clipboard/clock/theme/service) capabilities, `CairoTextOpen` lazily creates a 1×1 measurement surface so headless `MeasureGlyphWidth` calls work without opening a window, and `desktop_runtime.zi` prefers hardware-accelerated SDL2 renderers on real GPU desktops (falling back cleanly to software on `llvmpipe`/`softpipe` or `LIBGL_ALWAYS_SOFTWARE=1`). Linking tradeoff: pure/console/file/clock `zx2native` ELFs remain static, whereas graphical desktop `zx2native` executables dynamically link `libkryon-desktop.so` (SDL2/Cairo/X11) so portable `.zx` bundles run at native speed on the platform's real SDL2/GPU stack. -- Kryon enforces `main` on desktop UI programs: a desktop entry without `main :: () -> s32` (opening its window through `kryon/app`) fails with a migration error; `KRYON_FRAME_ENTRY=1` keeps frame-mode fixtures building until their host capabilities move into `kryon/app`. Capture builds (`kryon` preview, `run --png`) bind the entry's `Frame` even for a program entry, so fixtures stay drawing modules, and `App.Frame` carries the `viewport` its draw runs in. +- `main` is the only Kryon UI program entry: the program declares `main` and runs its window through `kryon/app` (`App.Run(window, Frame)`), and an entry without `main :: () -> s32` fails the build with a migration error. The Frame program export is removed with no compat path: the `frame_entry` binding, the old `desktop_run`/`canvas_run`/`dom_run`/`terminal_run`/`pixmap_run`/`zx_run` host programs and the `KRYON_FRAME_ENTRY` escape are gone, every fixture and example runs as a program, `App.Frame` carries the `viewport` its draw runs in, and quitting is `WindowQuit()` from `Window` instead of a Frame return value. - A program entry builds on non-desktop C backends without carrying desktop modules: terminal, canvas, dom and pixmap builds define `KRYON_NO_DESKTOP_HOST`, and `kryon/app` then maps `App.Show`/`App.Run` to `app_unsupported` on Linux C targets, so `kryon run shot` links a program entry (which imports `kryon/app`) without the desktop window and accessibility libraries. diff --git a/Makefile b/Makefile index 8d9b2563d..68ea8a3b9 100644 --- a/Makefile +++ b/Makefile @@ -197,7 +197,6 @@ project-test: project-toolchain build/bin/kryon @env -u DISPLAY -u WAYLAND_DISPLAY python3 tests/project_artifact_test.py @env -u DISPLAY -u WAYLAND_DISPLAY python3 tests/project_host_test.py @env -u DISPLAY -u WAYLAND_DISPLAY python3 tests/project_entry_test.py - @env -u DISPLAY -u WAYLAND_DISPLAY python3 tests/frame_entry_binding_test.py @$(MAKE) --no-print-directory templates-test # This native-link regression uses GTK development libraries, supplied by @@ -1281,11 +1280,6 @@ window-runtime-test: $(ZI2C_BIN) test: window-runtime-test -.PHONY: application-entry-test -application-entry-test: $(ZI2C_BIN) - ZIRAN_BIN="$(ZIRAN_BIN)" sh tests/application_entry_test.sh - -test: application-entry-test # Cross-build and execute the Windows SDL/Cairo host on a private Wine display. .PHONY: windows-desktop-host-test diff --git a/docs/BACKENDS.md b/docs/BACKENDS.md index ba1e07887..532b2c395 100644 --- a/docs/BACKENDS.md +++ b/docs/BACKENDS.md @@ -49,10 +49,10 @@ in the application. | Profile backend | Ziran entry | Presentation | | --- | --- | --- | -| `terminal` | `src/backend/terminal_run.zi` | 80 × 24 terminal cells via `terminal.zi` | -| `desktop` | `src/backend/desktop_run.zi` | SDL2 window with Cairo raster | -| `canvas` | `src/backend/canvas_run.zi` | Canvas2D page with Emscripten and Asyncify | -| `dom` | `src/backend/dom_run.zi` | HTML elements with browser layout and CSS | +| `terminal` | `frames_terminal.zi` | 80 × 24 terminal cells via `terminal.zi` | +| `desktop` | `frames_desktop.zi` | SDL2 window with Cairo raster | +| `canvas` | `frames_web.zi` | Canvas2D page with Emscripten and Asyncify | +| `dom` | `frames_dom.zi` | HTML elements with browser layout and CSS | | `android` | app `src/main.zi` → `android_run.zi` | Android NativeActivity package with direct `ANativeWindow` pixel presentation | The small application surface selects the host from the compile-time target. @@ -88,9 +88,10 @@ backend = "dom" ``` Run `ziran tool kryon build --profile web`. The C99 profile produces a -self-contained `build/-web.html`. It calls the app's exported -`Frame(session: Session, viewport: Rectangle) -> s32` with the viewport in -CSS pixels. Submit the retained widgets with their ordinary package APIs. +self-contained `build/-web.html`. The app's `main` runs +`App.Run(window, draw)`, and the DOM frame loop calls `draw` with an +`App.Frame` whose viewport is in CSS pixels. Submit the retained widgets +with their ordinary package APIs. Give widgets stable `key` values to retain their HTML elements as labels and sibling order change. Changing a node's parent, widget kind or tag creates a new element. Close widget scopes with `kryon/tree`'s `End(session)`. @@ -807,10 +808,12 @@ for ownership, lifecycle, capability requirements and local test targets. ## Custom application entry -Applications that own their frame lifecycle import `kryon/application_entry` -and export `KryonApplicationMain(argc: s32, argv: **u8) -> s32` with -`#program_export "KryonApplicationMain"`. The adapter owns `main`: native -hosts forward their exact command line and browser hosts pass `(0, null)`. -The callback retains initialization, frame scheduling and shutdown policy; -Android's NativeActivity host can call the same native entry. Do not define -an additional application `main` when importing this adapter. +`main` is the only program entry. An application that owns its frame +lifecycle defines `main` itself and drives the host APIs directly (open the +desktop runtime, poll and draw), instead of handing its frames to +`App.Run`. `#program_export` stays a Ziran language feature for exporting +plain C-ABI symbols to foreign hosts; Kryon has no frame-entry binding, so +a UI program always enters through `main`. Android's NativeActivity package +keeps `android_run.zi`: the generated `src/main.zi` delegates to +`AndroidRunMain`, which owns Android's looper, window and lifecycle, while +the application's `main` drives it through `App.Run` (`kryon/app`). diff --git a/docs/CHEATSHEET.md b/docs/CHEATSHEET.md index dabaecc6f..9b663b0bc 100644 --- a/docs/CHEATSHEET.md +++ b/docs/CHEATSHEET.md @@ -1,7 +1,8 @@ # Kryon cheat sheet -Kryon is a Ziran UI library: Kryon calls the app's `Frame` every frame, which -declares every widget from the app's state; widgets report what the user did. +Kryon is a Ziran UI library: the app's `main` runs `App.Run(window, Frame)` +from `kryon/app`, and Kryon calls `Frame` every frame, which declares every +widget from the app's state; widgets report what the user did. `make cheatsheet-test` builds, shoots and drives every `// file:` block below. ## Start and see @@ -82,6 +83,7 @@ NoteCountText :: () -> string { return ifx note_count == 0 then "No notes yet" e ```zi // file: src/app.zi +App :: #import "kryon/app"; Button :: #import "kryon/button"; Card :: #import "kryon/card"; // .variant .clickable -> .opened .activated; then End CSS :: #import "css/Css"; // StyleClass, CssSheetParse, CssSheetInstall @@ -106,12 +108,13 @@ draft: TextField.State; no_menu: []Dropdown.Option; sheet: CSS.CssSheet; NOTE_CSS :: "Card.note { border-radius: 14px; gap: 4px; }"; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport if !started { draft.bytes = draft_bytes[:]; dark = Theme.CurrentTheme().dark; started = true if CSS.CssSheetParse(*sheet, NOTE_CSS, "app.css", CSS.CssNoImports) { unused CSS.CssSheetInstall(*sheet, CSS.CssDefaultEnvironment(), null) } } screen := Layout.Draw(session, Layout.Props.{.bounds = viewport}) - if !screen.opened { return 0 } + if !screen.opened { return } AppBar(session) body := Layout.Draw(session, Layout.Props.{.gap = Layout.Gap(.ThemeMetricSpace3), .gap_override = true, .padding = Layout.Gap(.ThemeMetricSpace4), .padding_override = true}) @@ -120,8 +123,8 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 } +main :: () -> s32 { return App.Run(App.Window.{.title = "Notes"}, Frame) } AppBar :: (session: Session) { height := Theme.CurrentThemeMetric(.ThemeMetricControlHeightLarge) + Theme.CurrentThemeMetric(.ThemeMetricSpace3) bar := TitleBar.Draw(session, TitleBar.Props.{.bounds = .{height = height}, .title = "Notes", .strong_title = true, .trailing_width = 120}, no_menu) diff --git a/docs/FEATURE_MATRIX.html b/docs/FEATURE_MATRIX.html index e7c5c20e3..8942d3da9 100644 --- a/docs/FEATURE_MATRIX.html +++ b/docs/FEATURE_MATRIX.html @@ -27,9 +27,9 @@ li{margin:.25rem 0}

Application hosts

- - - + + +
BackendImplementationInput and presentation verificationCurrent status
Terminalsrc/backend/terminal_run.ziPrivate PTY project test covers ASCII, UTF-8, invalid input, and escape sequences✅ supported
Desktopsrc/backend/desktop_run.ziPrivate Xvfb project test covers image capture, keyboard, UTF-8 text, and wheel input✅ supported on the tested Linux host
Web Canvassrc/backend/canvas_run.ziHeadless Chromium checks Canvas2D pixels, clips, input, textures, fonts, lifecycle, WebAudio, and file behavior✅ supported through Emscripten on the tested browser
Terminalsrc/backend/frames_terminal.ziPrivate PTY project test covers ASCII, UTF-8, invalid input, and escape sequences✅ supported
Desktopsrc/backend/frames_desktop.ziPrivate Xvfb project test covers image capture, keyboard, UTF-8 text, and wheel input✅ supported on the tested Linux host
Web Canvassrc/backend/frames_web.ziHeadless Chromium checks Canvas2D pixels, clips, input, textures, fonts, lifecycle, WebAudio, and file behavior✅ supported through Emscripten on the tested browser
Androidapp src/main.zi + src/backend/android_run.zitests/ziran_android_device_test.sh checks the device text, lifecycle, and inset protocol with the Java side stubbed; a manual emulator run verifies install, rendering, touch, and back✅ supported through NativeActivity with direct ANativeWindow pixel presentation

The desktop project test (make desktop-project-test) uses a private Xvfb display. The Canvas2D project test runs in make test and launches only private headless Chromium. make zx-window-test covers bare-window bundles through the native desktop player and host library. Code generation alone does not establish platform execution.

diff --git a/docs/FEATURE_MATRIX.md b/docs/FEATURE_MATRIX.md index 8686f1e2c..6af5391c4 100644 --- a/docs/FEATURE_MATRIX.md +++ b/docs/FEATURE_MATRIX.md @@ -20,9 +20,9 @@ for a target; it does not prove that every native host runs on that target. | Backend | Implementation | Input and presentation verification | Current status | | --- | --- | --- | --- | -| Terminal | `src/backend/terminal_run.zi` | Private PTY project test covers ASCII, UTF-8, invalid input, and escape sequences | ✅ supported | -| Desktop | `src/backend/desktop_run.zi` | Private Xvfb project test covers image capture, keyboard, UTF-8 text, and wheel input | ✅ supported on the tested Linux host | -| Web Canvas | `src/backend/canvas_run.zi` | Headless Chromium checks Canvas2D pixels, clips, input, textures, fonts, lifecycle, WebAudio, and file behavior | ✅ supported through Emscripten on the tested browser | +| Terminal | `src/backend/frames_terminal.zi` | Private PTY project test covers ASCII, UTF-8, invalid input, and escape sequences | ✅ supported | +| Desktop | `src/backend/frames_desktop.zi` | Private Xvfb project test covers image capture, keyboard, UTF-8 text, and wheel input | ✅ supported on the tested Linux host | +| Web Canvas | `src/backend/frames_web.zi` | Headless Chromium checks Canvas2D pixels, clips, input, textures, fonts, lifecycle, WebAudio, and file behavior | ✅ supported through Emscripten on the tested browser | | Android | app `src/main.zi` + `src/backend/android_run.zi` | `tests/ziran_android_device_test.sh` checks the device text, lifecycle, and inset protocol with the Java side stubbed; a manual emulator run verifies install, rendering, touch, and back | ✅ supported through NativeActivity with direct ANativeWindow pixel presentation | The desktop project test (`make desktop-project-test`) uses a private Xvfb diff --git a/docs/FRAME_REPLAY.md b/docs/FRAME_REPLAY.md index b76366b39..f54187083 100644 --- a/docs/FRAME_REPLAY.md +++ b/docs/FRAME_REPLAY.md @@ -20,23 +20,26 @@ profile is used unless `--profile NAME` selects another desktop C99 profile. Register `previews` in `[package] module_roots`, for example `module_roots = ["src", "previews"]`. Each fixture is a uniquely named module -at `previews/.zi`. Its entry is the same frame export used by the -default desktop host: +at `previews/.zi`. Its entry is an ordinary program: `main` runs +`App.Run` with the module that draws the screen: ```zi +App :: #import "kryon/app"; Button :: #import "kryon/button"; #import "kryon/geometry" #import "kryon/session" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport unused Button.Draw(session, .{.key = cast(u64)7, .bounds = .{16.0, 16.0, viewport.width - 32.0, 36.0}, .label = "Save"}) - return 0 } + +main :: () -> s32 { return App.Run(App.Window.{.title = "save_button"}, Frame) } ``` -Return zero after composing the frame. Fixture code can import the project's +Compose the frame from ordinary widget calls. Fixture code can import the project's ordinary view modules and assets. Use explicit sample data and the supplied viewport. The preview runs offscreen with the native Cairo renderer, neutral input, zero frame time and a fixed light or dark palette with reduced motion. diff --git a/docs/site/demo/src/preview_entry.zi b/docs/site/demo/src/preview_entry.zi index 635202c51..61d262036 100644 --- a/docs/site/demo/src/preview_entry.zi +++ b/docs/site/demo/src/preview_entry.zi @@ -1,4 +1,5 @@ Scroll :: #import "kryon/scroll"; +App :: #import "kryon/app_types"; #import "kryon/geometry" #import "kryon/input_protocol" #import "kryon/session" @@ -53,7 +54,7 @@ Tick :: () -> s32 { scroll := Scroll.Draw(preview_session, Scroll.Props.{.key = 190000001, .bounds = viewport, .content_height = cast(s32)height, .scroll_offset = preview_scroll}) preview_scroll = scroll.scroll_offset - if Frame(preview_session, scroll.content) != 0 { return 1 } + App.CallDraw(Frame, preview_session.slot, preview_session.epoch, scroll.content) if scroll.opened { End(preview_session) } if EndFrame(preview_session) != FrameStatus.FrameOk { return 1 } for index: 0..TreeCount(preview_session) - 1 { diff --git a/examples/actionmodal/actionmodal.zi b/examples/actionmodal/actionmodal.zi index 67da9538c..3ffd8ecbb 100644 --- a/examples/actionmodal/actionmodal.zi +++ b/examples/actionmodal/actionmodal.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -43,14 +44,15 @@ clicks: s32; dismissed: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "ActionModal", .size = 23}) disabled := example_input.disabled @@ -63,15 +65,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if Button.Draw(session, Button.Props.{.bounds = .{height = 44}, .label = "Open dialog again"}) == 1 { dismissed = false } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "actionmodal"}, Frame) } diff --git a/examples/alert/alert.zi b/examples/alert/alert.zi index 81d7f9c55..b24018ccc 100644 --- a/examples/alert/alert.zi +++ b/examples/alert/alert.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Alert :: #import "kryon/alert"; Button :: #import "kryon/button"; Text :: #import "kryon/text"; @@ -7,24 +8,26 @@ Layout :: #import "kryon/layout"; #import "kryon/session" state: Alert.AlertState; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Alert", .size = 28}) Alert.Draw(session, Alert.Props.{.disabled = example_disabled, .bounds = .{height = 180}, .title = "Changes saved", .description = "Your settings are up to date.", .dismissible = true}, *state) if Button.Draw(session, Button.Props.{.disabled = example_disabled, .bounds = .{width = 160, height = 40}, .label = "Show alert"}) != 0 { state.dismissed = false } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "alert"}, Frame) } diff --git a/examples/avatar/avatar.zi b/examples/avatar/avatar.zi index dd0971b9f..0cec7d0e1 100644 --- a/examples/avatar/avatar.zi +++ b/examples/avatar/avatar.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Avatar :: #import "kryon/avatar"; Layout :: #import "kryon/layout"; #import "kryon/tree" @@ -6,11 +7,12 @@ Text :: #import "kryon/text"; #import "kryon/session" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Avatar", .size = 28}) row := Layout.Row(session, Layout.Props.{.gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) if row.opened { @@ -21,15 +23,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { names := string.["Ada Lovelace", "Grace Hopper", "Katherine Johnson", "Alan Turing"] Avatar.AvatarGroup(session, Avatar.AvatarGroupProps.{.bounds = .{height = 56}, .size = 48.0, .max_visible = 3}, names[:]) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "avatar"}, Frame) } diff --git a/examples/badge/badge.zi b/examples/badge/badge.zi index 4d401890f..543fd044b 100644 --- a/examples/badge/badge.zi +++ b/examples/badge/badge.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Badge :: #import "kryon/badge"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -6,25 +7,27 @@ Layout :: #import "kryon/layout"; #import "kryon/session" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Badge", .size = 28}) for i: cast(s32)0..4 { Badge.Draw(session, Badge.Props.{.disabled = example_disabled, .bounds = .{width = 140, height = 36}, .text = "Ready", .tone = cast(Badge.BadgeTone)i, .dot = true, .solid = i % 2 == 0}) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "badge"}, Frame) } diff --git a/examples/bandchart/bandchart.zi b/examples/bandchart/bandchart.zi index b6e614bf3..b50235967 100644 --- a/examples/bandchart/bandchart.zi +++ b/examples/bandchart/bandchart.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -69,14 +70,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "BandChart", .size = 23}) disabled := example_input.disabled scene: s32 = 5 @@ -88,15 +90,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { bands[0] = .{.low = 4.0, .high = 9.0, .has_low = true, .has_high = true} unused Charts.BandChart(session, Charts.BandChartProps.{.bounds = bounds, .semantic_label = "Values and a target band", .slots = 8, .min_value = 0.0, .max_value = 12.0, .top_label = "12", .bottom_label = "0", .font = 14, .good_color = .{35, 115, 92, 255}, .other_color = .{180, 125, 70, 255}, .band_color = .{131, 181, 160, 80}, .grid_color = .{180, 200, 210, 150}, .text_color = StyleTokenColor("text"), .label_fill = StyleTokenColor("surface")}, points[:], bands[:]) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "bandchart"}, Frame) } diff --git a/examples/banner/banner.zi b/examples/banner/banner.zi index ad4855f40..2a158e5d2 100644 --- a/examples/banner/banner.zi +++ b/examples/banner/banner.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Banner :: #import "kryon/banner"; Button :: #import "kryon/button"; Text :: #import "kryon/text"; @@ -11,11 +12,12 @@ DemoTheme :: #import "kryon/Theme"; state: Banner.BannerState; initialized: bool; requested: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Banner", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -26,15 +28,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if requested { Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 180}, .text = "Update requested"}) } if Button.Draw(session, Button.Props.{.disabled = example_disabled, .bounds = .{width = 160, height = 40}, .label = "Show banner"}) != 0 { state.open = true; requested = false } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "banner"}, Frame) } diff --git a/examples/box/box.zi b/examples/box/box.zi index 455706e4c..321c4dfcc 100644 --- a/examples/box/box.zi +++ b/examples/box/box.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -43,14 +44,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { return bounds } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Box", .size = 23}) disabled := example_input.disabled @@ -62,15 +64,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "box"}, Frame) } diff --git a/examples/breadcrumb/breadcrumb.zi b/examples/breadcrumb/breadcrumb.zi index 6310f02ba..b7a023b49 100644 --- a/examples/breadcrumb/breadcrumb.zi +++ b/examples/breadcrumb/breadcrumb.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Breadcrumb :: #import "kryon/breadcrumb"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -6,25 +7,27 @@ Layout :: #import "kryon/layout"; #import "kryon/session" active: s32 = 2; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Breadcrumb", .size = 28}) items := Breadcrumb.BreadcrumbItem.[.{.label = "Home"}, .{.label = "Projects"}, .{.label = "Kryon"}] result := Breadcrumb.Draw(session, Breadcrumb.Props.{.disabled = example_disabled, .bounds = .{height = 44}, .active_index = active}, items[:]) if result.changed { active = result.activated_index } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "breadcrumb"}, Frame) } diff --git a/examples/button/button.zi b/examples/button/button.zi index dc61be1b2..bf03d2b00 100644 --- a/examples/button/button.zi +++ b/examples/button/button.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Layout :: #import "kryon/layout"; Text :: #import "kryon/text"; @@ -10,11 +11,12 @@ Text :: #import "kryon/text"; clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Button", .size = 28}) // Every tone in every emphasis, two to a row. grid := Layout.Grid(session, GridProps.{.columns = 2, .gap = Layout.Gap(.ThemeMetricSpace3)}) @@ -32,15 +34,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = FormatInteger(cast(s64)clicks, digits[:])}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "button"}, Frame) } diff --git a/examples/buttongroup/buttongroup.zi b/examples/buttongroup/buttongroup.zi index 0ee4be0ff..f46cceb7c 100644 --- a/examples/buttongroup/buttongroup.zi +++ b/examples/buttongroup/buttongroup.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; ButtonGroup :: #import "kryon/button_group"; Text :: #import "kryon/text"; @@ -8,11 +9,12 @@ Layout :: #import "kryon/layout"; state: ButtonGroup.ButtonGroupState; active: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Button group", .size = 28}) items := Button.Props.[.{.label = "Left"}, .{.label = "Center"}, .{.label = "Right"}] for index: 0..cast(s32)items.count - 1 { items[index].disabled = example_disabled } @@ -20,15 +22,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if result.activated_index >= 0 { active = result.activated_index } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = items[active].label}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "buttongroup"}, Frame) } diff --git a/examples/candlechart/candlechart.zi b/examples/candlechart/candlechart.zi index aa882567b..9c4d1d6c5 100644 --- a/examples/candlechart/candlechart.zi +++ b/examples/candlechart/candlechart.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -71,14 +72,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "CandleChart", .size = 23}) disabled := example_input.disabled scene: s32 = 4 @@ -90,15 +92,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } Charts.CandleChart(session, Charts.CandleChartProps.{.bounds = bounds, .visible_count = 8, .semantic_label = "Example candles and volume", .up_color = .{35, 115, 92, 255}, .down_color = .{185, 65, 67, 255}, .grid_color = .{180, 200, 210, 150}}, bars[:], Charts.CandleRangeFor(bars[:], 8)) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "candlechart"}, Frame) } diff --git a/examples/card/card.zi b/examples/card/card.zi index be5b0e40e..7f5d0ad96 100644 --- a/examples/card/card.zi +++ b/examples/card/card.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -44,14 +45,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { return bounds } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Card", .size = 23}) variants: [3]Card.CardVariant = .{.CardFilled, .CardElevated, .CardOutlined} for index: cast(s32)0..2 { @@ -63,15 +65,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "card"}, Frame) } diff --git a/examples/carousel/carousel.zi b/examples/carousel/carousel.zi index 5704663de..4b66952df 100644 --- a/examples/carousel/carousel.zi +++ b/examples/carousel/carousel.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Carousel :: #import "kryon/carousel"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,11 +9,12 @@ Layout :: #import "kryon/layout"; state: Carousel.CarouselState; opened: s32 = -1; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Carousel", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -23,15 +25,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if result >= 0 { opened = result } if opened >= 0 { Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = items[opened].label}) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "carousel"}, Frame) } diff --git a/examples/checkbox/checkbox.zi b/examples/checkbox/checkbox.zi index 3a0853771..02831a38c 100644 --- a/examples/checkbox/checkbox.zi +++ b/examples/checkbox/checkbox.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -43,29 +44,31 @@ checked: bool = true; reminder: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Checkbox", .size = 23}) disabled := example_input.disabled checked = Checkbox.Draw(session, Checkbox.Props.{.bounds = .{height = 44}, .label = "Remember my choice", .checked = checked, .disabled = disabled}).checked reminder = Checkbox.Draw(session, Checkbox.Props.{.bounds = .{height = 44}, .label = "Use a gentle reminder", .disabled = disabled, .checked = reminder}).checked unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "checkbox"}, Frame) } diff --git a/examples/checklist/checklist.zi b/examples/checklist/checklist.zi index 496f5e1c9..1bd538b34 100644 --- a/examples/checklist/checklist.zi +++ b/examples/checklist/checklist.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; OnboardingChecklist :: #import "kryon/onboarding_checklist"; Layout :: #import "kryon/layout"; #import "kryon/tree" @@ -7,25 +8,27 @@ Text :: #import "kryon/text"; #import "kryon/onboarding_checklist_task" done: [3]bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Onboarding checklist", .size = 28}) tasks := OnboardingChecklistTask.[.{.id = 1, .title = "Create a project", .done = done[0]}, .{.id = 2, .title = "Add a component", .done = done[1]}, .{.id = 3, .title = "Run the app", .done = done[2]}] result := OnboardingChecklist.Draw(session, OnboardingChecklist.Props.{.disabled = example_disabled, .bounds = .{height = 224}, .title = "Get started", .tasks = tasks[:]}) if result.toggled_index >= 0 && result.toggled_index < 3 { done[result.toggled_index] = !done[result.toggled_index] } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "checklist"}, Frame) } diff --git a/examples/chip/chip.zi b/examples/chip/chip.zi index aaf75d801..80c7b9cb0 100644 --- a/examples/chip/chip.zi +++ b/examples/chip/chip.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Chip :: #import "kryon/chip"; Flow :: #import "kryon/flow"; Text :: #import "kryon/text"; @@ -13,11 +14,12 @@ tags: [3]bool = .[true, true, true]; filter_names: [4]string = .["All", "Design", "Code", "Docs"]; tag_names: [3]string = .["Draft", "Shared", "Pinned"]; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Chip", .size = 28}) filter_row := Flow.Draw(session, Flow.Props.{.gap = 8}) if filter_row.opened { @@ -36,15 +38,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "chip"}, Frame) } diff --git a/examples/collapsible/collapsible.zi b/examples/collapsible/collapsible.zi index 5c7860770..bc1ff9a94 100644 --- a/examples/collapsible/collapsible.zi +++ b/examples/collapsible/collapsible.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -51,14 +52,15 @@ no_headers: []Collapsible.CollapsibleHeader; example_motion: TransitionMotionState; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Collapsible", .size = 23}) disabled := example_input.disabled now := cast(float64)CaptureFrameInput(session).elapsed_ms / 1000.0 @@ -73,15 +75,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { TreePopScope(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "collapsible"}, Frame) } diff --git a/examples/colorpicker/colorpicker.zi b/examples/colorpicker/colorpicker.zi index 328d83723..678c18d00 100644 --- a/examples/colorpicker/colorpicker.zi +++ b/examples/colorpicker/colorpicker.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -39,14 +40,15 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion color: [4]float32 = .{0.18, 0.52, 0.68, 1.0}; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "ColorPicker", .size = 23}) disabled := example_input.disabled @@ -55,15 +57,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { props.values = color color = ColorPicker.Draw(session, props).values unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "colorpicker"}, Frame) } diff --git a/examples/column/column.zi b/examples/column/column.zi index b51bf5e73..f64bf1e0f 100644 --- a/examples/column/column.zi +++ b/examples/column/column.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Column", .size = 23}) disabled := example_input.disabled scene: s32 = 36 @@ -80,15 +82,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "column"}, Frame) } diff --git a/examples/commandpalette/commandpalette.zi b/examples/commandpalette/commandpalette.zi index 7b9d8eaa8..b8f18413a 100644 --- a/examples/commandpalette/commandpalette.zi +++ b/examples/commandpalette/commandpalette.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -101,14 +102,15 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "CommandPalette", .size = 23}) disabled := example_input.disabled scene: s32 = 2 @@ -154,15 +156,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { palette := CommandPalette.Draw(session, props, *palette_state) if palette.close_requested || palette.chosen_index >= 0 { palette_open = false } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "commandpalette"}, Frame) } diff --git a/examples/confirmbutton/confirmbutton.zi b/examples/confirmbutton/confirmbutton.zi index cb770c671..4d643754c 100644 --- a/examples/confirmbutton/confirmbutton.zi +++ b/examples/confirmbutton/confirmbutton.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; ConfirmButton :: #import "kryon/confirm_button"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,11 +9,12 @@ Layout :: #import "kryon/layout"; state: ConfirmButton.ConfirmButtonState; confirmed: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Confirm button", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -22,15 +24,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if confirmed { label = "Item deleted" } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = label}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "confirmbutton"}, Frame) } diff --git a/examples/confirmpopover/confirmpopover.zi b/examples/confirmpopover/confirmpopover.zi index c53967f26..fd01dbc54 100644 --- a/examples/confirmpopover/confirmpopover.zi +++ b/examples/confirmpopover/confirmpopover.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -98,14 +99,15 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "ConfirmPopover", .size = 23}) disabled := example_input.disabled scene: s32 = 4 @@ -143,15 +145,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { confirmed := ConfirmPopover.Draw(session, props, *confirm_state) if gallery_live && (confirmed.closed || confirmed.confirmed || confirmed.cancelled) { live_confirm_open = false } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "confirmpopover"}, Frame) } diff --git a/examples/contextmenu/contextmenu.zi b/examples/contextmenu/contextmenu.zi index 908b247fb..acff3fc53 100644 --- a/examples/contextmenu/contextmenu.zi +++ b/examples/contextmenu/contextmenu.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -43,14 +44,15 @@ dismissed: bool; b: Rectangle; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "ContextMenu", .size = 23}) b = Rectangle.{viewport.x + 24.0, viewport.y + 64.0, viewport.width - 48.0, 44.0} disabled := example_input.disabled @@ -65,15 +67,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if result.activated_id > 0 { clicks += 1 } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "contextmenu"}, Frame) } diff --git a/examples/copybutton/copybutton.zi b/examples/copybutton/copybutton.zi index 33937dfd5..d1ebc9076 100644 --- a/examples/copybutton/copybutton.zi +++ b/examples/copybutton/copybutton.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; CopyButton :: #import "kryon/copy_button"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -7,25 +8,27 @@ Layout :: #import "kryon/layout"; #import "kryon/frame_snapshot" state: CopyButton.CopyButtonState; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Copy button", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 CopyButton.Draw(session, CopyButton.Props.{.button = .{.disabled = example_disabled, .bounds = .{width = 240, height = 44}, .label = "Copy website address"}, .text = "https://github.com/kryonlabs/kryon", .now = cast(float32)now, .success_label = "Copied", .failure_label = "Copy failed"}, *state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "copybutton"}, Frame) } diff --git a/examples/countdown/countdown.zi b/examples/countdown/countdown.zi index eaf4c21b2..4c87a69ba 100644 --- a/examples/countdown/countdown.zi +++ b/examples/countdown/countdown.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Countdown :: #import "kryon/countdown"; Text :: #import "kryon/text"; @@ -10,11 +11,12 @@ DemoTheme :: #import "kryon/Theme"; state: Countdown.CountdownState; ends_at: float64; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Countdown", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -26,15 +28,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Countdown.Draw(session, props, *state) if Button.Draw(session, Button.Props.{.disabled = example_disabled, .bounds = .{width = 160, height = 40}, .label = "Restart"}) != 0 { ends_at = now + 90.0 } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "countdown"}, Frame) } diff --git a/examples/counter/counter.zi b/examples/counter/counter.zi index 76561e14d..fe292b34d 100644 --- a/examples/counter/counter.zi +++ b/examples/counter/counter.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Text :: #import "kryon/text"; #import "kryon/geometry" @@ -6,13 +7,16 @@ Text :: #import "kryon/text"; count: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport width := viewport.width - 40.0 digits: [24]u8 Text.Draw(session, Text.Props.{.bounds = .{viewport.x + 20.0, viewport.y + 20.0, width, 64.0}, .text = FormatInteger(cast(s64)count, digits[:]), .size = 40}) if Button.Draw(session, Button.Props.{.bounds = .{viewport.x + 20.0, viewport.y + 104.0, width, 44.0}, .label = "Increment"}) != 0 { count += 1 } - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "counter"}, Frame) } diff --git a/examples/dashboard/previews/default.zi b/examples/dashboard/previews/default.zi index 97c6c33e9..1a3f614af 100644 --- a/examples/dashboard/previews/default.zi +++ b/examples/dashboard/previews/default.zi @@ -1,8 +1,11 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "dashboard" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - return DashboardFrame(session, viewport) +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + DashboardFrame(session, frame.viewport) } + +main :: () -> s32 { return App.Run(App.Window.{.title = "dashboard"}, Frame) } diff --git a/examples/dashboard/previews/empty.zi b/examples/dashboard/previews/empty.zi index 0a174eb7e..fbc8454f4 100644 --- a/examples/dashboard/previews/empty.zi +++ b/examples/dashboard/previews/empty.zi @@ -1,14 +1,17 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "dashboard" preview_ready: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { if !preview_ready { preview_ready = true DashboardSetFixture("empty") } - return DashboardFrame(session, viewport) + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + DashboardFrame(session, frame.viewport) } + +main :: () -> s32 { return App.Run(App.Window.{.title = "empty"}, Frame) } diff --git a/examples/dashboard/previews/error.zi b/examples/dashboard/previews/error.zi index d06efdfff..7de88e425 100644 --- a/examples/dashboard/previews/error.zi +++ b/examples/dashboard/previews/error.zi @@ -1,14 +1,17 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "dashboard" preview_ready: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { if !preview_ready { preview_ready = true DashboardSetFixture("error") } - return DashboardFrame(session, viewport) + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + DashboardFrame(session, frame.viewport) } + +main :: () -> s32 { return App.Run(App.Window.{.title = "error"}, Frame) } diff --git a/examples/dashboard/previews/loading.zi b/examples/dashboard/previews/loading.zi index 3439972bf..9576f5f8e 100644 --- a/examples/dashboard/previews/loading.zi +++ b/examples/dashboard/previews/loading.zi @@ -1,14 +1,17 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "dashboard" preview_ready: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { if !preview_ready { preview_ready = true DashboardSetFixture("loading") } - return DashboardFrame(session, viewport) + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + DashboardFrame(session, frame.viewport) } + +main :: () -> s32 { return App.Run(App.Window.{.title = "loading"}, Frame) } diff --git a/examples/dashboard/previews/responsive.zi b/examples/dashboard/previews/responsive.zi index 53073674d..7fec48d84 100644 --- a/examples/dashboard/previews/responsive.zi +++ b/examples/dashboard/previews/responsive.zi @@ -1,4 +1,5 @@ // See examples/dashboard/README.md for the native preview and ZX commands. +App :: #import "kryon/app"; CSS :: #import "css/Css"; Box :: #import "kryon/box"; Button :: #import "kryon/button"; @@ -141,9 +142,10 @@ Ledger :: (session: Session) { unused End(session) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - if !Install(viewport) { print("responsive styles failed\n"); return 1 } +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport + if !Install(viewport) { print("responsive styles failed\n"); return } unused Box.Draw(session, Box.Props.{.key = 1, .bounds = viewport, .fill = ColorFromPacked(0x0d1420ff)}) bounds := viewport if bounds.width > 1480.0 { @@ -151,7 +153,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { bounds.width = 1480.0 } page := Layout.Draw(session, .{.bounds = bounds, .key = 2, .class_name = CSS.StyleClass("dashboard")}) - if !page.opened { return 1 } + if !page.opened { return } Label(session, Rectangle.{0.0, 0.0, 0.0, 20.0}, 3, "AUTOTRADE · OFFLINE RESEARCH", "eyebrow") Page.Heading(session, .{.key = 4, .text = "Strategy DNA", .bounds = .{0.0, 0.0, 0.0, 50.0}, .level = 1, .class_name = CSS.StyleClass("title")}) @@ -167,5 +169,6 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } if show_costs { Label(session, Rectangle.{0.0, 0.0, 0.0, 20.0}, 44, "Fees included in net P&L", "muted") } unused End(session) - return 0 } + +main :: () -> s32 { return App.Run(App.Window.{.title = "responsive dashboard"}, Frame) } diff --git a/examples/dashboard/previews/settings.zi b/examples/dashboard/previews/settings.zi index d75a4c993..a47d6c1b6 100644 --- a/examples/dashboard/previews/settings.zi +++ b/examples/dashboard/previews/settings.zi @@ -1,14 +1,17 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "dashboard" preview_ready: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { if !preview_ready { preview_ready = true DashboardSetFixture("settings") } - return DashboardFrame(session, viewport) + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + DashboardFrame(session, frame.viewport) } + +main :: () -> s32 { return App.Run(App.Window.{.title = "settings"}, Frame) } diff --git a/examples/dashboard/src/app.zi b/examples/dashboard/src/app.zi index b745a3bd2..0af75abc2 100644 --- a/examples/dashboard/src/app.zi +++ b/examples/dashboard/src/app.zi @@ -1,9 +1,12 @@ // Dashboard starter entry point. +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "dashboard" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - return DashboardFrame(session, viewport) +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + DashboardFrame(session, frame.viewport) } + +main :: () -> s32 { return App.Run(App.Window.{.title = "Dashboard"}, Frame) } diff --git a/examples/dashboard/src/dashboard.zi b/examples/dashboard/src/dashboard.zi index 5c85329c3..214a5e27f 100644 --- a/examples/dashboard/src/dashboard.zi +++ b/examples/dashboard/src/dashboard.zi @@ -492,7 +492,7 @@ SettingsModal :: (session: Session) { } } -DashboardFrame :: (session: Session, viewport: Rectangle) -> s32 { +DashboardFrame :: (session: Session, viewport: Rectangle) { EnsureInitialized() snapshot := CaptureFrameInput(session) unused EnsureDashboardTheme(dark_theme, compact_density, false, viewport.width) @@ -510,5 +510,4 @@ DashboardFrame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } if settings_open { SettingsModal(session) } - return 0 } diff --git a/examples/demo/time_picker_demo.zi b/examples/demo/time_picker_demo.zi index 1a0203674..03054a9d2 100644 --- a/examples/demo/time_picker_demo.zi +++ b/examples/demo/time_picker_demo.zi @@ -2,6 +2,7 @@ // disabled, and in a small form, in light and dark palettes. The picker // keeps its popup, columns and keyboard column itself; this app keeps only // the times. desktop_time_picker.zi runs it in a window. +App :: #import "kryon/app"; Box :: #import "kryon/box"; SegmentedControl :: #import "kryon/segmented_control"; Text :: #import "kryon/text"; @@ -104,8 +105,9 @@ FastText :: (output: []u8) -> string { return TextView(output[0:length]) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport want: s32 = ifx dark then 1 else 0 if installed != want { unused SystemPaletteInstall(SystemPaletteFallback(dark)) @@ -164,5 +166,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Label(session, TextView(last_change[0:last_change_length]), Rectangle.{x, y, width, 20.0}, 14, false) } - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "time_picker_demo"}, Frame) } diff --git a/examples/discreteslider/discreteslider.zi b/examples/discreteslider/discreteslider.zi index 3224a8ecb..657c1ef36 100644 --- a/examples/discreteslider/discreteslider.zi +++ b/examples/discreteslider/discreteslider.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -50,14 +51,15 @@ Label :: (session: Session, value: string, y: float32 = 76.0) { Text.Draw(session, Text.Props.{.bounds = GalleryBounds(Rectangle.{28.0, y, 420.0, 38.0}), .text = value}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "DiscreteSlider", .size = 23}) disabled := example_input.disabled @@ -65,15 +67,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { digits: [16]u8 Label(session, FormatInteger(cast(s64)discrete, digits[:]), 180.0) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "discreteslider"}, Frame) } diff --git a/examples/dismissibleoverlay/dismissibleoverlay.zi b/examples/dismissibleoverlay/dismissibleoverlay.zi index 1e3ca00d4..5c3cabb51 100644 --- a/examples/dismissibleoverlay/dismissibleoverlay.zi +++ b/examples/dismissibleoverlay/dismissibleoverlay.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -53,14 +54,15 @@ Label :: (session: Session, value: string, y: float32 = 76.0) { b: Rectangle; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "DismissibleOverlay", .size = 23}) b = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 44.0}) disabled := example_input.disabled @@ -73,15 +75,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if overlay.closed { dismissed = true } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "dismissibleoverlay"}, Frame) } diff --git a/examples/dpad/dpad.zi b/examples/dpad/dpad.zi index 344e2ab7e..14f5cde9a 100644 --- a/examples/dpad/dpad.zi +++ b/examples/dpad/dpad.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; DirectionPad :: #import "kryon/direction_pad"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,11 +9,12 @@ Layout :: #import "kryon/layout"; #import "std/number_text" steps: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace3), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Direction pad", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -27,15 +29,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "dpad"}, Frame) } diff --git a/examples/dropdown/dropdown.zi b/examples/dropdown/dropdown.zi index b50c2093a..8ab717d30 100644 --- a/examples/dropdown/dropdown.zi +++ b/examples/dropdown/dropdown.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -39,14 +40,15 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion choice: s32 = 1; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Dropdown", .size = 23}) disabled := example_input.disabled @@ -54,15 +56,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { options[0].label = "Morning"; options[1].label = "Afternoon"; options[2].label = "Evening" choice = Dropdown.Draw(session, Dropdown.Props.{.bounds = .{height = 44}, .selected_index = choice, .disabled = disabled}, options[:]).selected_index unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "dropdown"}, Frame) } diff --git a/examples/emptystate/emptystate.zi b/examples/emptystate/emptystate.zi index 5f2d30118..32e7ecc03 100644 --- a/examples/emptystate/emptystate.zi +++ b/examples/emptystate/emptystate.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; EmptyState :: #import "kryon/empty_state"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -6,11 +7,12 @@ Layout :: #import "kryon/layout"; #import "kryon/session" created: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Empty state", .size = 28}) if !created { props: EmptyState.Props = .{.disabled = example_disabled, .bounds = .{height = 224}, .title = "No projects yet", .description = "Create your first project.", .action = "Create project"} @@ -18,15 +20,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if result.action { created = true } } else { Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 180}, .text = "Project created"}) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "emptystate"}, Frame) } diff --git a/examples/fieldset/fieldset.zi b/examples/fieldset/fieldset.zi index 0d5bda066..0924e7bb5 100644 --- a/examples/fieldset/fieldset.zi +++ b/examples/fieldset/fieldset.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -45,14 +46,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Fieldset", .size = 23}) disabled := example_input.disabled @@ -68,15 +70,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "fieldset"}, Frame) } diff --git a/examples/flow/flow.zi b/examples/flow/flow.zi index 15b51231f..7ac1d31b0 100644 --- a/examples/flow/flow.zi +++ b/examples/flow/flow.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -45,14 +46,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { return bounds } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Flow", .size = 23}) disabled := example_input.disabled @@ -63,15 +65,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "flow"}, Frame) } diff --git a/examples/gallery/src/app.zi b/examples/gallery/src/app.zi index 9a10d7875..8f309588c 100644 --- a/examples/gallery/src/app.zi +++ b/examples/gallery/src/app.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Box :: #import "kryon/box"; Checkbox :: #import "kryon/checkbox"; ListBox :: #import "kryon/list_box"; @@ -50,9 +51,10 @@ PrepareGalleryInput :: (session: Session) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - if Shot.CatalogShotActive() { return Shot.CatalogShotFrame(session, viewport) } +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport + if Shot.CatalogShotActive() { Shot.CatalogShotFrame(session, viewport); return } snapshot := CaptureFrameInput(session) SetGalleryPreview(Rectangle.{0.0, 0.0, 480.0, viewport.height - 88.0}, true, cast(float32)snapshot.elapsed_ms / 1000.0, GalleryTheme.CurrentTheme().motion.reduced_motion) @@ -61,7 +63,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if embedded { Text.Draw(session, Text.Props.{.key = 9001, .bounds = .{24.0, 12.0, 432.0, 36.0}, .text = GallerySceneName(scene), .size = 23}) DrawScene(session) - return 0 + return } restore_focus := navigation_focus_pending navigation_focus_pending = false @@ -101,9 +103,10 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { disabled_controls = Checkbox.Draw(session, Checkbox.Props.{.key = 9004, .bounds = .{24.0, controls_y, 208.0, 40.0}, .label = "Disabled", .checked = disabled_controls}).checked dark = Toggle.Draw(session, Toggle.Props.{.key = 9005, .bounds = .{344.0, controls_y, 96.0, 40.0}, .label = "Dark", .value = dark}).value if controls_scope { End(session) } - return 0 } DrawScene :: (session: Session) { ComposeGallery(session, scene, disabled_controls) } + +main :: () -> s32 { return App.Run(App.Window.{.title = "app"}, Frame) } diff --git a/examples/gallery/src/catalog_shot.zi b/examples/gallery/src/catalog_shot.zi index a185ea232..320281caf 100644 --- a/examples/gallery/src/catalog_shot.zi +++ b/examples/gallery/src/catalog_shot.zi @@ -18,7 +18,6 @@ CatalogShotConfigure :: (scene: s32, dark: bool) { CatalogShotActive :: () -> bool { return shot_active } -#program_export CatalogShotFrame :: (session: Session, viewport: Rectangle) -> s32 { SetGalleryPreview(viewport, false, 0.0, true) InstallGalleryPalette(shot_dark) diff --git a/examples/gallery/templates/frame.zi b/examples/gallery/templates/frame.zi index 865d98822..bba7d03ab 100644 --- a/examples/gallery/templates/frame.zi +++ b/examples/gallery/templates/frame.zi @@ -1,9 +1,11 @@ // @declarations +App :: #import "kryon/app"; #import "palette" #import "preview_protocol" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := PreviewInputRead() InstallCatalogPalette(example_input.theme == 2) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) @@ -11,5 +13,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Text(session, Text.Props.{.key = 9001, .bounds = .{viewport.x + 24.0, viewport.y + 12.0, viewport.width - 48.0, 36.0}, .text = "// @title", .size = 23}) disabled := example_input.disabled // @example - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "frame"}, Frame) } diff --git a/examples/grid/grid.zi b/examples/grid/grid.zi index af8c2b1b6..ff8b1342a 100644 --- a/examples/grid/grid.zi +++ b/examples/grid/grid.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Grid", .size = 23}) disabled := example_input.disabled scene: s32 = 40 @@ -80,15 +82,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "grid"}, Frame) } diff --git a/examples/gridmulti/gridmulti.zi b/examples/gridmulti/gridmulti.zi index 4df4fc9b8..73ec56316 100644 --- a/examples/gridmulti/gridmulti.zi +++ b/examples/gridmulti/gridmulti.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; GridMulti :: #import "kryon/grid_multi"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,26 +9,28 @@ Layout :: #import "kryon/layout"; selected: [6]bool; cursor: s32; anchor: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Grid multi", .size = 28}) items := GridMulti.GridMultiItem.[.{.label = "Documents"}, .{.label = "Pictures"}, .{.label = "Music"}, .{.label = "Videos"}, .{.label = "Projects"}, .{.label = "Downloads"}] result := GridMulti.Draw(session, GridMulti.Props.{.disabled = example_disabled, .bounds = .{height = 224}, .cell_width = 110, .cell_height = 64, .gap = 12, .cursor = cursor, .anchor = anchor}, items[:], selected[:]) cursor = result.cursor anchor = result.anchor unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "gridmulti"}, Frame) } diff --git a/examples/group/group.zi b/examples/group/group.zi index 99e8c2321..08a5af208 100644 --- a/examples/group/group.zi +++ b/examples/group/group.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Group", .size = 23}) disabled := example_input.disabled scene: s32 = 39 @@ -80,15 +82,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "group"}, Frame) } diff --git a/examples/guidedtour/guidedtour.zi b/examples/guidedtour/guidedtour.zi index 9cfdc3d13..579fcdc05 100644 --- a/examples/guidedtour/guidedtour.zi +++ b/examples/guidedtour/guidedtour.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -98,14 +99,15 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "GuidedTour", .size = 23}) // The tour spans the whole view, above the page column. unused End(session) @@ -145,15 +147,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } tour := GuidedTour.Draw(session, props, *tour_state) if gallery_live { live_tour_step = tour.step } - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "guidedtour"}, Frame) } diff --git a/examples/holdbutton/holdbutton.zi b/examples/holdbutton/holdbutton.zi index 8ebc95f03..f0b1fb6f2 100644 --- a/examples/holdbutton/holdbutton.zi +++ b/examples/holdbutton/holdbutton.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; HoldButton :: #import "kryon/hold_button"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,11 +9,12 @@ Layout :: #import "kryon/layout"; state: HoldButton.HoldButtonState; fired: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Hold button", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -22,15 +24,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if fired { label = "Confirmed" } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = label}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "holdbutton"}, Frame) } diff --git a/examples/hovercard/hovercard.zi b/examples/hovercard/hovercard.zi index b3b154d6d..fd2fb22c9 100644 --- a/examples/hovercard/hovercard.zi +++ b/examples/hovercard/hovercard.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -97,14 +98,15 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "HoverCard", .size = 23}) disabled := example_input.disabled scene: s32 = 3 @@ -144,15 +146,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { card := HoverCard.Draw(session, props, *hover_state) hover_state_bounds = card.bounds unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "hovercard"}, Frame) } diff --git a/examples/image/image.zi b/examples/image/image.zi index 626b67da0..a009339bb 100644 --- a/examples/image/image.zi +++ b/examples/image/image.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -46,14 +47,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { scene_image: string = "assets/pfp.webp"; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Image", .size = 23}) disabled := example_input.disabled scene_image = "assets/pfp.webp" @@ -67,15 +69,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Text.Draw(session, Text.Props.{.bounds = .{height = 26}, .text = "Cover fit / rounded corners / smooth scaling", .size = 12}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "image"}, Frame) } diff --git a/examples/inlineedit/inlineedit.zi b/examples/inlineedit/inlineedit.zi index b785db38a..16cf5bdb2 100644 --- a/examples/inlineedit/inlineedit.zi +++ b/examples/inlineedit/inlineedit.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -70,15 +71,16 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport gallery_input: TextField.Input example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "InlineEdit", .size = 23}) disabled := example_input.disabled scene: s32 = 2 @@ -93,15 +95,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { .input = gallery_input, .disabled = disabled, .focus_visible = true, .height = 42.0, .font_size = 17.0}, *inline_state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "inlineedit"}, Frame) } diff --git a/examples/joystick/joystick.zi b/examples/joystick/joystick.zi index 3435471b7..87d58dfc7 100644 --- a/examples/joystick/joystick.zi +++ b/examples/joystick/joystick.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Joystick :: #import "kryon/joystick"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,11 +9,12 @@ Layout :: #import "kryon/layout"; #import "std/number_text" steps: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace3), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Joystick", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -27,15 +29,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "joystick"}, Frame) } diff --git a/examples/kanban/kanban.zi b/examples/kanban/kanban.zi index 2a20105ae..f444dd91f 100644 --- a/examples/kanban/kanban.zi +++ b/examples/kanban/kanban.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -94,14 +95,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Kanban", .size = 23}) disabled := example_input.disabled scene: s32 = 1 @@ -135,15 +137,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if gesture.moved && gesture.lane >= 0 && gesture.identity >= 700 && gesture.identity < 703 { card_lanes[cast(s32)gesture.identity - 700] = gesture.lane } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "kanban"}, Frame) } diff --git a/examples/keycap/keycap.zi b/examples/keycap/keycap.zi index 523f6cbd9..a61ed7d26 100644 --- a/examples/keycap/keycap.zi +++ b/examples/keycap/keycap.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Keycap :: #import "kryon/keycap"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -6,24 +7,26 @@ Layout :: #import "kryon/layout"; #import "kryon/session" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Keycap", .size = 28}) Keycap.Draw(session, Keycap.Props.{.disabled = example_disabled, .bounds = .{width = 160, height = 44}, .keys = "Ctrl+K"}) Keycap.Draw(session, Keycap.Props.{.disabled = example_disabled, .bounds = .{width = 160, height = 44}, .keys = "Shift+Enter"}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "keycap"}, Frame) } diff --git a/examples/linechart/linechart.zi b/examples/linechart/linechart.zi index e1418939f..6a288802a 100644 --- a/examples/linechart/linechart.zi +++ b/examples/linechart/linechart.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -71,14 +72,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "LineChart", .size = 23}) disabled := example_input.disabled scene: s32 = 2 @@ -88,15 +90,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if scene == 2 { Charts.LineChart(session, props, values[:], Charts.ChartRangeFor(values[:])) } else { Charts.LineChartCompare(session, props, values[:], previous[:], Charts.ChartRangeForBoth(values[:], previous[:])) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "linechart"}, Frame) } diff --git a/examples/linechartcompare/linechartcompare.zi b/examples/linechartcompare/linechartcompare.zi index ca359b4e6..cad22f3cd 100644 --- a/examples/linechartcompare/linechartcompare.zi +++ b/examples/linechartcompare/linechartcompare.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -71,14 +72,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "LineChartCompare", .size = 23}) disabled := example_input.disabled scene: s32 = 3 @@ -88,15 +90,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if scene == 2 { Charts.LineChart(session, props, values[:], Charts.ChartRangeFor(values[:])) } else { Charts.LineChartCompare(session, props, values[:], previous[:], Charts.ChartRangeForBoth(values[:], previous[:])) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "linechartcompare"}, Frame) } diff --git a/examples/link/link.zi b/examples/link/link.zi index a50aef0a7..955c664a0 100644 --- a/examples/link/link.zi +++ b/examples/link/link.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -39,28 +40,30 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Link", .size = 23}) disabled := example_input.disabled if Link.Draw(session, Link.Props.{.bounds = .{height = 44}, .text = "Read the documentation", .link = "https://kryonlabs.com/docs.html", .disabled = disabled}).activated { clicks += 1 } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "link"}, Frame) } diff --git a/examples/listbox/listbox.zi b/examples/listbox/listbox.zi index 4f4fab4ba..d502c9806 100644 --- a/examples/listbox/listbox.zi +++ b/examples/listbox/listbox.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; ListBox :: #import "kryon/list_box"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,25 +9,27 @@ Layout :: #import "kryon/layout"; choice: s32; selected: [3]bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "List box", .size = 28}) items := ListBox.ListBoxItem.[.{.label = "Morning walk"}, .{.label = "Read a chapter"}, .{.label = "Make something"}] choice = ListBox.Draw(session, ListBox.Props.{.disabled = example_disabled, .bounds = .{height = 100}, .row_height = 32, .selected_index = choice}, items[:]).selected_index ListBox.ListBoxMulti(session, ListBox.ListBoxMultiProps.{.disabled = example_disabled, .bounds = .{height = 100}, .row_height = 32}, items[:], selected[:]) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "listbox"}, Frame) } diff --git a/examples/listitem/listitem.zi b/examples/listitem/listitem.zi index e3fe89afd..4b75d108f 100644 --- a/examples/listitem/listitem.zi +++ b/examples/listitem/listitem.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Layout :: #import "kryon/layout"; ListItem :: #import "kryon/list_item"; Text :: #import "kryon/text"; @@ -8,10 +9,11 @@ Text :: #import "kryon/text"; // A settings list: an avatar row, a switch row, a badge row and a chevron row. notifications: bool = true; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport list := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace3), .padding_override = true}) - if !list.opened { return 0 } + if !list.opened { return } unused ListItem.Draw(session, ListItem.Props.{.title = "Ada Lovelace", .subtitle = "Account and profile", .leading_name = "Ada Lovelace", .trailing = .ListTrailingChevron, .disabled = example_disabled}) row := ListItem.Draw(session, ListItem.Props.{.title = "Notifications", .trailing = .ListTrailingSwitch, @@ -22,15 +24,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused ListItem.Draw(session, ListItem.Props.{.title = "Storage", .subtitle = "4.2 GB of 15 GB", .trailing = .ListTrailingText, .trailing_text = "28%", .disabled = example_disabled}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "listitem"}, Frame) } diff --git a/examples/loading/loading.zi b/examples/loading/loading.zi index f04d0d07f..c68cdae2d 100644 --- a/examples/loading/loading.zi +++ b/examples/loading/loading.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; LoadingIndicator :: #import "kryon/loading_indicator"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,25 +9,27 @@ Layout :: #import "kryon/layout"; DemoTheme :: #import "kryon/Theme"; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Loading indicator", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 LoadingIndicator.Draw(session, LoadingIndicator.Props.{.bounds = .{height = 180}, .now = ifx (example_reduced_motion || DemoTheme.CurrentTheme().motion.reduced_motion) then 0.0 else now, .scale = 1.0}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "loading"}, Frame) } diff --git a/examples/loadingscreen/loadingscreen.zi b/examples/loadingscreen/loadingscreen.zi index 560a8c15a..27b4a2ad0 100644 --- a/examples/loadingscreen/loadingscreen.zi +++ b/examples/loadingscreen/loadingscreen.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; LoadingScreen :: #import "kryon/loading_screen"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; @@ -8,25 +9,27 @@ Layout :: #import "kryon/layout"; DemoTheme :: #import "kryon/Theme"; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Loading screen", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 LoadingScreen.Draw(session, LoadingScreen.Props.{.bounds = .{height = 320}, .title = "Opening project", .detail = "Loading files", .now = now, .scale = 1.0, .reduced_motion = (example_reduced_motion || DemoTheme.CurrentTheme().motion.reduced_motion)}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "loadingscreen"}, Frame) } diff --git a/examples/menu/menu.zi b/examples/menu/menu.zi index 0aa5e9fa4..c86490304 100644 --- a/examples/menu/menu.zi +++ b/examples/menu/menu.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -46,14 +47,15 @@ menu_initialized: bool; b: Rectangle; example_motion: TransitionMotionState; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Menu", .size = 23}) b = Rectangle.{viewport.x + 24.0, viewport.y + 64.0, viewport.width - 48.0, 44.0} disabled := example_input.disabled @@ -65,15 +67,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if !menu_initialized { Menu.MenuStateInit(*menu_state); menu_state.open_index = 0; menu_initialized = true } if Menu.Draw(session, Menu.Props.{.motion = *example_motion, .now = now, .reduced_motion = example_input.reduced_motion, .bounds = b}, groups[:], *menu_state).activated_id > 0 { clicks += 1 } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "menu"}, Frame) } diff --git a/examples/modalframe/modalframe.zi b/examples/modalframe/modalframe.zi index 46d60c88b..7d5fcaaf5 100644 --- a/examples/modalframe/modalframe.zi +++ b/examples/modalframe/modalframe.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -55,14 +56,15 @@ Label :: (session: Session, value: string, y: float32 = 76.0) { b: Rectangle; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "ModalFrame", .size = 23}) b = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 44.0}) disabled := example_input.disabled @@ -76,15 +78,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if modal.dismissed || modal.right_clicked { dismissed = true; clicks += 1 } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "modalframe"}, Frame) } diff --git a/examples/moneyfield/moneyfield.zi b/examples/moneyfield/moneyfield.zi index 0e08ba585..94ff34f92 100644 --- a/examples/moneyfield/moneyfield.zi +++ b/examples/moneyfield/moneyfield.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -70,15 +71,16 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport gallery_input: TextField.Input example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "MoneyField", .size = 23}) disabled := example_input.disabled scene: s32 = 4 @@ -96,15 +98,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { .negative_style = .MoneyNegativeParentheses, .locale = .MoneyLocaleDot, .disabled = disabled, .height = 42.0}, *money_state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "moneyfield"}, Frame) } diff --git a/examples/navigationbar/navigationbar.zi b/examples/navigationbar/navigationbar.zi index fa054b430..ae8b88976 100644 --- a/examples/navigationbar/navigationbar.zi +++ b/examples/navigationbar/navigationbar.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -41,14 +42,15 @@ nav: s32; example_motion: TransitionMotionState; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "NavigationBar", .size = 23}) disabled := example_input.disabled now := cast(float64)CaptureFrameInput(session).elapsed_ms / 1000.0 @@ -61,15 +63,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { moved := Navigation.Draw(session, Navigation.Props.{.motion = *example_motion, .now = now, .reduced_motion = example_input.reduced_motion, .bounds = .{height = 44}, .compact = true, .fit_items = true}, items[:]) if moved.clicked_index >= 0 { nav = moved.clicked_index } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "navigationbar"}, Frame) } diff --git a/examples/navigationbarconfig/navigationbarconfig.zi b/examples/navigationbarconfig/navigationbarconfig.zi index a31b1a241..f6264ae3d 100644 --- a/examples/navigationbarconfig/navigationbarconfig.zi +++ b/examples/navigationbarconfig/navigationbarconfig.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -61,14 +62,15 @@ dismissed: bool; b: Rectangle; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "NavigationBarConfig", .size = 23}) b = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 44.0}) disabled := example_input.disabled @@ -86,15 +88,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if config.action != 0 { dismissed = true; clicks += 1 } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "navigationbarconfig"}, Frame) } diff --git a/examples/onetimecode/onetimecode.zi b/examples/onetimecode/onetimecode.zi index 41f1296c9..675e18ec6 100644 --- a/examples/onetimecode/onetimecode.zi +++ b/examples/onetimecode/onetimecode.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -70,15 +71,16 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport gallery_input: TextField.Input example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "OneTimeCode", .size = 23}) disabled := example_input.disabled scene: s32 = 1 @@ -98,15 +100,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { .backspace = gallery_input.backspace, .delete_forward = gallery_input.delete_forward, .escape = gallery_input.escape, .style = code_style}, *one_time_state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "onetimecode"}, Frame) } diff --git a/examples/page/page.zi b/examples/page/page.zi index 62466fcd9..8a524540d 100644 --- a/examples/page/page.zi +++ b/examples/page/page.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ quiet: bool; details: bool = true; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) column := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !column.opened { return 0 } + if !column.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Page Section Heading ParagraphText", .size = 23}) disabled := example_input.disabled @@ -70,15 +72,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "page"}, Frame) } diff --git a/examples/panedview/panedview.zi b/examples/panedview/panedview.zi index 4dc576078..f07916947 100644 --- a/examples/panedview/panedview.zi +++ b/examples/panedview/panedview.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -46,14 +47,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { split: s32 = 210; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "PanedView", .size = 23}) disabled := example_input.disabled @@ -62,15 +64,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused Box.Draw(session, Box.Props.{.bounds = panes.first, .fill = .{230, 239, 242, 255}, .radius = 8.0}) unused Box.Draw(session, Box.Props.{.bounds = panes.second, .fill = .{222, 237, 235, 255}, .radius = 8.0}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "panedview"}, Frame) } diff --git a/examples/plotbars/plotbars.zi b/examples/plotbars/plotbars.zi index 1daad0ecd..c1256b026 100644 --- a/examples/plotbars/plotbars.zi +++ b/examples/plotbars/plotbars.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -69,14 +70,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Plot · bars", .size = 23}) disabled := example_input.disabled scene: s32 = 1 @@ -84,15 +86,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Prepare(session, scene) unused Plot.Plot(session, Plot.PlotProps.{.bounds = bounds, .semantic_label = "Eight example values", .scale_min = 0.0, .scale_max = 12.0, .mode = cast(Plot.PlotMode)scene}, values[:]) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "plotbars"}, Frame) } diff --git a/examples/plotlines/plotlines.zi b/examples/plotlines/plotlines.zi index f5fc36565..ba1f078b3 100644 --- a/examples/plotlines/plotlines.zi +++ b/examples/plotlines/plotlines.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -69,14 +70,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Plot · lines", .size = 23}) disabled := example_input.disabled scene: s32 = 0 @@ -84,15 +86,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Prepare(session, scene) unused Plot.Plot(session, Plot.PlotProps.{.bounds = bounds, .semantic_label = "Eight example values", .scale_min = 0.0, .scale_max = 12.0, .mode = cast(Plot.PlotMode)scene}, values[:]) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "plotlines"}, Frame) } diff --git a/examples/popup/popup.zi b/examples/popup/popup.zi index bb3bccb42..53ddc481e 100644 --- a/examples/popup/popup.zi +++ b/examples/popup/popup.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ Label :: (session: Session, value: string, y: float32 = 76.0) { Text.Draw(session, Text.Props.{.bounds = GalleryBounds(Rectangle.{28.0, y, 420.0, 38.0}), .text = value}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Popup", .size = 23}) disabled := example_input.disabled @@ -65,15 +67,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Label(session, "A floating panel", 120.0) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "popup"}, Frame) } diff --git a/examples/press/press.zi b/examples/press/press.zi index 6b70101bb..84c06b3ee 100644 --- a/examples/press/press.zi +++ b/examples/press/press.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Press", .size = 23}) disabled := example_input.disabled @@ -70,15 +72,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } Text.Draw(session, Text.Props.{.bounds = .{height = 38}, .text = "Press is an invisible interaction area"}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "press"}, Frame) } diff --git a/examples/progress/progress.zi b/examples/progress/progress.zi index f40fd236f..a5ed438dc 100644 --- a/examples/progress/progress.zi +++ b/examples/progress/progress.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -37,28 +38,30 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Progress", .size = 23}) disabled := example_input.disabled Progress.Draw(session, Progress.Props.{.bounds = .{height = 44}, .value = 64, .max = 100, .label = "64%"}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "progress"}, Frame) } diff --git a/examples/progressring/progressring.zi b/examples/progressring/progressring.zi index 051c9969b..55dc0c75d 100644 --- a/examples/progressring/progressring.zi +++ b/examples/progressring/progressring.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; ProgressRing :: #import "kryon/progress_ring"; Text :: #import "kryon/text"; @@ -10,11 +11,12 @@ DemoTheme :: #import "kryon/Theme"; state: ProgressRing.ProgressRingState; value: float32 = 0.25; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Progress ring", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -23,15 +25,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { ProgressRing.Draw(session, props, *state) if Button.Draw(session, Button.Props.{.disabled = example_disabled, .bounds = .{width = 160, height = 40}, .label = "Advance"}) != 0 { value += 0.25; if value > 1.0 { value = 0.0 } } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "progressring"}, Frame) } diff --git a/examples/radio/radio.zi b/examples/radio/radio.zi index 49a486bb4..0e0db7938 100644 --- a/examples/radio/radio.zi +++ b/examples/radio/radio.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -41,29 +42,31 @@ checked: bool = true; balanced: bool = true; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Radio", .size = 23}) disabled := example_input.disabled if Radio.Draw(session, Radio.Props.{.bounds = .{height = 44}, .label = "Balanced", .checked = balanced, .disabled = disabled}) == 1 { balanced = true } if Radio.Draw(session, Radio.Props.{.bounds = .{height = 44}, .label = "Compact", .disabled = disabled, .checked = !balanced}) == 1 { balanced = false } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "radio"}, Frame) } diff --git a/examples/reorder/reorder.zi b/examples/reorder/reorder.zi index 8846e11bb..b37ecbdaf 100644 --- a/examples/reorder/reorder.zi +++ b/examples/reorder/reorder.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -46,18 +47,19 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { order: [3]s32 = .{0, 1, 2}; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Reorder", .size = 23}) // Reorder takes its rows' rects: they stack in the area the column gives it. area := Layout.Stack(session, Layout.Props.{.bounds = .{height = 200}}) - if !area.opened { unused End(session); return 0 } + if !area.opened { unused End(session); return } list := area.bounds disabled := example_input.disabled @@ -77,15 +79,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } unused End(session) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "reorder"}, Frame) } diff --git a/examples/row/row.zi b/examples/row/row.zi index 4b5371277..c665441d9 100644 --- a/examples/row/row.zi +++ b/examples/row/row.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Row", .size = 23}) disabled := example_input.disabled scene: s32 = 37 @@ -80,15 +82,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "row"}, Frame) } diff --git a/examples/screen/screen.zi b/examples/screen/screen.zi index 67bb579c6..fa98895d2 100644 --- a/examples/screen/screen.zi +++ b/examples/screen/screen.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Screen", .size = 23}) disabled := example_input.disabled scene: s32 = 48 @@ -80,15 +82,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "screen"}, Frame) } diff --git a/examples/scroll/scroll.zi b/examples/scroll/scroll.zi index a79ee5967..88aae0b2b 100644 --- a/examples/scroll/scroll.zi +++ b/examples/scroll/scroll.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -39,14 +40,15 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion scroll: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Scroll", .size = 23}) disabled := example_input.disabled @@ -59,15 +61,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "scroll"}, Frame) } diff --git a/examples/scrubfield/scrubfield.zi b/examples/scrubfield/scrubfield.zi index 48e012c55..e8047323d 100644 --- a/examples/scrubfield/scrubfield.zi +++ b/examples/scrubfield/scrubfield.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -70,15 +71,16 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport gallery_input: TextField.Input example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "ScrubField", .size = 23}) disabled := example_input.disabled scene: s32 = 3 @@ -94,15 +96,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { .input = gallery_input, .fine_divisor = 10.0, .coarse_multiplier = 5.0, .disabled = disabled, .height = 42.0}, *scrub_state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "scrubfield"}, Frame) } diff --git a/examples/segmentedcontrol/segmentedcontrol.zi b/examples/segmentedcontrol/segmentedcontrol.zi index 871ef38e8..44ed5b731 100644 --- a/examples/segmentedcontrol/segmentedcontrol.zi +++ b/examples/segmentedcontrol/segmentedcontrol.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -39,14 +40,15 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion segment: s32 = 1; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "SegmentedControl", .size = 23}) disabled := example_input.disabled @@ -54,15 +56,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { options[0].label = "Day"; options[1].label = "Week"; options[2].label = "Month" segment = SegmentedControl.Draw(session, SegmentedControl.Props.{.bounds = .{height = 44}, .selected_index = segment, .has_selection = true, .disabled = disabled}, options[:]).selected_index unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "segmentedcontrol"}, Frame) } diff --git a/examples/selectable/selectable.zi b/examples/selectable/selectable.zi index ce23da378..45756791e 100644 --- a/examples/selectable/selectable.zi +++ b/examples/selectable/selectable.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -41,29 +42,31 @@ selected: bool = true; another: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Selectable", .size = 23}) disabled := example_input.disabled selected = Selectable.Draw(session, Selectable.Props.{.bounds = .{height = 44}, .label = "Selected item", .selected = selected, .disabled = disabled}).selected another = Selectable.Draw(session, Selectable.Props.{.bounds = .{height = 44}, .label = "Another item", .disabled = disabled, .selected = another}).selected unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "selectable"}, Frame) } diff --git a/examples/separator/separator.zi b/examples/separator/separator.zi index 3d7e26b41..3ea287cd3 100644 --- a/examples/separator/separator.zi +++ b/examples/separator/separator.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -45,14 +46,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Separator and Bullet", .size = 23}) disabled := example_input.disabled @@ -65,15 +67,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "separator"}, Frame) } diff --git a/examples/shape/shape.zi b/examples/shape/shape.zi index 1f232eb80..ef50fb704 100644 --- a/examples/shape/shape.zi +++ b/examples/shape/shape.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -38,14 +39,15 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion color: [4]float32 = .{0.18, 0.52, 0.68, 1.0}; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Circle Ring Triangle Line", .size = 23}) disabled := example_input.disabled @@ -54,15 +56,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused Shape.Triangle(session, Shape.TriangleProps.{.first = .{292.0, 166.0}, .second = .{330.0, 90.0}, .third = .{368.0, 166.0}, .color = .{30, 115, 138, 255}}) unused Shape.Draw(session, Shape.Props.{.start = .{28.0, 220.0}, .end = .{432.0, 220.0}, .thickness = 2.0, .color = .{30, 115, 138, 255}}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "shape"}, Frame) } diff --git a/examples/shared/widget_context.zi b/examples/shared/widget_context.zi index 5df7ddf51..a385b6367 100644 --- a/examples/shared/widget_context.zi +++ b/examples/shared/widget_context.zi @@ -34,8 +34,7 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion diff --git a/examples/sheet/sheet.zi b/examples/sheet/sheet.zi index 201137d78..848648733 100644 --- a/examples/sheet/sheet.zi +++ b/examples/sheet/sheet.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -98,14 +99,15 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Sheet", .size = 23}) disabled := example_input.disabled scene: s32 = 1 @@ -141,15 +143,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { sheet := Sheet.Draw(session, props, *sheet_state) if gallery_live && sheet.close_requested { live_sheet_open = false } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "sheet"}, Frame) } diff --git a/examples/shortcutrecorder/shortcutrecorder.zi b/examples/shortcutrecorder/shortcutrecorder.zi index fe9046e11..d7c9d01aa 100644 --- a/examples/shortcutrecorder/shortcutrecorder.zi +++ b/examples/shortcutrecorder/shortcutrecorder.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -70,15 +71,16 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport gallery_input: TextField.Input example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "ShortcutRecorder", .size = 23}) disabled := example_input.disabled scene: s32 = 5 @@ -93,15 +95,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { .disabled = disabled, .height = 42.0, .font_size = 16.0, .width = bounds.width}, *shortcut_state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "shortcutrecorder"}, Frame) } diff --git a/examples/skeleton/skeleton.zi b/examples/skeleton/skeleton.zi index 01687cfe7..917231637 100644 --- a/examples/skeleton/skeleton.zi +++ b/examples/skeleton/skeleton.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Layout :: #import "kryon/layout"; Skeleton :: #import "kryon/skeleton"; Text :: #import "kryon/text"; @@ -8,27 +9,29 @@ Text :: #import "kryon/text"; // A card's shape while its content loads: an avatar, two lines and a block. seconds: float64; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport if !example_reduced_motion { seconds += 1.0 / 60.0 } column := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .padding_override = true, .gap = 10, .gap_override = true}) - if !column.opened { return 0 } + if !column.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 40}, .text = "Skeleton", .size = 28}) Skeleton.Draw(session, Skeleton.Props.{.shape = .SkeletonCircle, .now = seconds}) Skeleton.Draw(session, Skeleton.Props.{.shape = .SkeletonLine, .now = seconds}) Skeleton.Draw(session, Skeleton.Props.{.shape = .SkeletonLine, .now = seconds, .bounds = .{width = column.content.width * 0.6}}) Skeleton.Draw(session, Skeleton.Props.{.shape = .SkeletonBlock, .now = seconds}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "skeleton"}, Frame) } diff --git a/examples/slider/slider.zi b/examples/slider/slider.zi index 12805b7a7..97de977ad 100644 --- a/examples/slider/slider.zi +++ b/examples/slider/slider.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -47,29 +48,31 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { amount: float32 = 65.0; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Slider", .size = 23}) disabled := example_input.disabled amount = Slider.Draw(session, Slider.Props.{.bounds = .{height = 80}, .label = "Volume", .value = amount, .max = 100.0, .disabled = disabled}).value Progress.Draw(session, Progress.Props.{.bounds = .{height = 16}, .value = cast(s32)amount, .max = 100}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "slider"}, Frame) } diff --git a/examples/spinbox/spinbox.zi b/examples/spinbox/spinbox.zi index 25f094c3a..3d8ddd51d 100644 --- a/examples/spinbox/spinbox.zi +++ b/examples/spinbox/spinbox.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -39,29 +40,31 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion minutes: s32 = 25; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Spinbox", .size = 23}) disabled := example_input.disabled digits: [16]u8 minutes = Spinbox.Draw(session, Spinbox.Props.{.bounds = .{height = 44}, .label = "Minutes", .value = minutes, .min = 0, .max = 60, .value_text = FormatInteger(cast(s64)minutes, digits[:]), .disabled = disabled}).value unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "spinbox"}, Frame) } diff --git a/examples/stack/stack.zi b/examples/stack/stack.zi index dd0fae0c0..fe839e3c0 100644 --- a/examples/stack/stack.zi +++ b/examples/stack/stack.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -48,14 +49,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { clicks: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Stack", .size = 23}) disabled := example_input.disabled scene: s32 = 38 @@ -80,15 +82,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "stack"}, Frame) } diff --git a/examples/stylepicker/stylepicker.zi b/examples/stylepicker/stylepicker.zi index c661bf997..85251e6e6 100644 --- a/examples/stylepicker/stylepicker.zi +++ b/examples/stylepicker/stylepicker.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -46,14 +47,15 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Modern style", .size = 23}) card := Card.Draw(session, Card.Props.{}) if card.opened { @@ -62,15 +64,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } Text.Draw(session, Text.Props.{.bounds = .{height = 38}, .text = "Colors and light/dark remain customizable."}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "stylepicker"}, Frame) } diff --git a/examples/svgicon/svgicon.zi b/examples/svgicon/svgicon.zi index 993f273c3..aba15b620 100644 --- a/examples/svgicon/svgicon.zi +++ b/examples/svgicon/svgicon.zi @@ -1,26 +1,29 @@ +App :: #import "kryon/app"; SvgIcon :: #import "kryon/svg_icon"; Text :: #import "kryon/text"; Layout :: #import "kryon/layout"; #import "kryon/tree" #import "kryon/geometry" #import "kryon/session" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "SVG icon", .size = 28}) SvgIcon.Draw(session, SvgIcon.Props.{.bounds = .{width = 96, height = 96}, .shape = "S1.7rr:M3 12L9 18L21 6", .color = .{38, 154, 98, 255}}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "svgicon"}, Frame) } diff --git a/examples/swipearea/swipearea.zi b/examples/swipearea/swipearea.zi index a98a5c3aa..c85e925bf 100644 --- a/examples/swipearea/swipearea.zi +++ b/examples/swipearea/swipearea.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Box :: #import "kryon/box"; Joystick :: #import "kryon/joystick"; Text :: #import "kryon/text"; @@ -10,11 +11,12 @@ Layout :: #import "kryon/layout"; #import "std/number_text" swipes: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Swipe area", .size = 28}) input := CaptureFrameInput(session) now := cast(float64)input.elapsed_ms / 1000.0 @@ -34,15 +36,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { digits: [24]u8 Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 36}, .text = FormatInteger(cast(s64)swipes, digits[:])}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "swipearea"}, Frame) } diff --git a/examples/tabbar/tabbar.zi b/examples/tabbar/tabbar.zi index d867af077..e2188e6f5 100644 --- a/examples/tabbar/tabbar.zi +++ b/examples/tabbar/tabbar.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -41,14 +42,15 @@ tab: s32 = 1; example_motion: TransitionMotionState; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TabBar", .size = 23}) disabled := example_input.disabled now := cast(float64)CaptureFrameInput(session).elapsed_ms / 1000.0 @@ -57,15 +59,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { tabs[0].label = "Overview"; tabs[1].label = "Notes"; tabs[2].label = "Files" tab = TabBar.Draw(session, TabBar.Props.{.motion = *example_motion, .now = now, .reduced_motion = example_input.reduced_motion, .bounds = .{height = 44}, .selected_index = tab, .disabled = disabled}, tabs[:]).selected_index unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "tabbar"}, Frame) } diff --git a/examples/tableview/tableview.zi b/examples/tableview/tableview.zi index b434118d4..780be0b70 100644 --- a/examples/tableview/tableview.zi +++ b/examples/tableview/tableview.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -121,14 +122,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TableView", .size = 23}) disabled := example_input.disabled scene: s32 = 2 @@ -162,15 +164,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { table_selection = -1; table_column = -1 } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "tableview"}, Frame) } diff --git a/examples/taginput/taginput.zi b/examples/taginput/taginput.zi index 9cf59e920..52627697c 100644 --- a/examples/taginput/taginput.zi +++ b/examples/taginput/taginput.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -74,15 +75,16 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport gallery_input: TextField.Input example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TagInput", .size = 23}) disabled := example_input.disabled scene: s32 = 0 @@ -101,15 +103,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { .disabled = disabled, .input = gallery_input, .style = tag_style}, *tag_state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "taginput"}, Frame) } diff --git a/examples/text/text.zi b/examples/text/text.zi index 89bb6df5c..b11fc5c3d 100644 --- a/examples/text/text.zi +++ b/examples/text/text.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Layout :: #import "kryon/layout"; Text :: #import "kryon/text"; #import "kryon/tree" @@ -5,25 +6,27 @@ Text :: #import "kryon/text"; #import "kryon/session" #import "kryon/text_selection" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport TextSelectionEnable() page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Text", .size = 28}) Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 56}, .text = "Make room for good ideas", .size = 24}) Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 144}, .text = "Select and copy this text. Unicode works here too: café, Ω, é.", .size = 18, .selectable = true}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "text"}, Frame) } diff --git a/examples/textarea/textarea.zi b/examples/textarea/textarea.zi index e9d3be46b..962e98c9c 100644 --- a/examples/textarea/textarea.zi +++ b/examples/textarea/textarea.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -146,14 +147,15 @@ Prepare :: (session: Session, scene: s32) -> SceneInput { return SceneInput.{field_input, area_input} } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TextArea", .size = 23}) disabled := example_input.disabled scene: s32 = 2 @@ -161,15 +163,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { area_input := input.area EditArea(session, .{height = 188}, disabled, area_input) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "textarea"}, Frame) } diff --git a/examples/textfield/textfield.zi b/examples/textfield/textfield.zi index 79da92a1b..726c798c9 100644 --- a/examples/textfield/textfield.zi +++ b/examples/textfield/textfield.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -149,14 +150,15 @@ Prepare :: (session: Session, scene: s32) -> SceneInput { return SceneInput.{field_input, area_input} } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TextField", .size = 23}) disabled := example_input.disabled scene: s32 = 1 @@ -165,15 +167,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { EditField(session, .{height = 44}, disabled, false, field_input) EditField(session, .{height = 44}, disabled, true, field_input) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "textfield"}, Frame) } diff --git a/examples/tilemap/tilemap.zi b/examples/tilemap/tilemap.zi index 81966952b..beca4aa3f 100644 --- a/examples/tilemap/tilemap.zi +++ b/examples/tilemap/tilemap.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Text :: #import "kryon/text"; TileMap :: #import "kryon/tile_map"; Layout :: #import "kryon/layout"; @@ -6,26 +7,28 @@ Layout :: #import "kryon/layout"; #import "kryon/session" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Tile map", .size = 28}) tiles := string.["assets/pfp.webp"] names := string.["Portrait"] cells := s32.[0, -1, 0, -1, 0, -1, 0, -1, 0] TileMap.Draw(session, TileMap.Props.{.bounds = .{height = 224}, .columns = 3, .rows = 3, .tiles = tiles[:], .names = names[:], .layers = cells[:], .layer_count = 1, .label = "Picture tiles", .pixel_snap = true}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "tilemap"}, Frame) } diff --git a/examples/timeline/timeline.zi b/examples/timeline/timeline.zi index b434731d3..516985517 100644 --- a/examples/timeline/timeline.zi +++ b/examples/timeline/timeline.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Text :: #import "kryon/text"; Timeline :: #import "kryon/timeline"; Layout :: #import "kryon/layout"; @@ -6,24 +7,26 @@ Layout :: #import "kryon/layout"; #import "kryon/session" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Timeline", .size = 28}) Timeline.Draw(session, Timeline.Props.{.disabled = example_disabled, .bounds = .{height = 100}, .title = "Project created", .time = "09:00", .description = "The workspace is ready."}) Timeline.Draw(session, Timeline.Props.{.disabled = example_disabled, .bounds = .{height = 100}, .title = "First component added", .time = "09:15", .description = "Button is available to use.", .last = true}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "timeline"}, Frame) } diff --git a/examples/timepicker/timepicker.zi b/examples/timepicker/timepicker.zi index 784ad6128..c2d50a3aa 100644 --- a/examples/timepicker/timepicker.zi +++ b/examples/timepicker/timepicker.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -39,28 +40,30 @@ SetGalleryViewport :: (view: Rectangle, live: bool, now: float32, reduced_motion time_value: s32 = 570; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TimePicker", .size = 23}) disabled := example_input.disabled time_value = TimePicker.Draw(session, TimePicker.Props.{.bounds = .{height = 44}, .label = "Start time", .value = time_value, .now = 570, .disabled = disabled}).value unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "timepicker"}, Frame) } diff --git a/examples/titlebar/titlebar.zi b/examples/titlebar/titlebar.zi index 7f72f7522..f1aa4b0cd 100644 --- a/examples/titlebar/titlebar.zi +++ b/examples/titlebar/titlebar.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -42,28 +43,30 @@ clicks: s32; no_options: []Dropdown.Option; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TitleBar", .size = 23}) disabled := example_input.disabled if TitleBar.Draw(session, TitleBar.Props.{.bounds = .{height = 44}, .title = "Library", .leading_label = "Back", .has_leading_action = true}, no_options).clicked_leading { clicks += 1 } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "titlebar"}, Frame) } diff --git a/examples/toast/toast.zi b/examples/toast/toast.zi index dc64cfe3e..c5802f5a5 100644 --- a/examples/toast/toast.zi +++ b/examples/toast/toast.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -44,28 +45,30 @@ GalleryBounds :: (bounds: Rectangle) -> Rectangle { return bounds } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Toast", .size = 23}) disabled := example_input.disabled unused Toast.Draw(session, Toast.Props.{.viewport = GalleryBounds(Rectangle.{0.0, 0.0, 480.0, 280.0}), .message = "Your changes have been saved", .seconds = 4.0, .now_seconds = 1.0}) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "toast"}, Frame) } diff --git a/examples/toggle/toggle.zi b/examples/toggle/toggle.zi index f1396398e..7da6a1f30 100644 --- a/examples/toggle/toggle.zi +++ b/examples/toggle/toggle.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -41,29 +42,31 @@ toggled: bool = true; quiet: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Toggle", .size = 23}) disabled := example_input.disabled toggled = Toggle.Draw(session, Toggle.Props.{.bounds = .{height = 44}, .label = "Notifications", .value = toggled, .disabled = disabled}).value quiet = Toggle.Draw(session, Toggle.Props.{.bounds = .{height = 44}, .label = "Quiet mode", .disabled = disabled, .value = quiet}).value unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "toggle"}, Frame) } diff --git a/examples/toolbar/toolbar.zi b/examples/toolbar/toolbar.zi index fc8d7e804..1282fca64 100644 --- a/examples/toolbar/toolbar.zi +++ b/examples/toolbar/toolbar.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -42,14 +43,15 @@ clicks: s32; no_options: []Dropdown.Option; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Toolbar", .size = 23}) disabled := example_input.disabled @@ -57,15 +59,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { actions[0].label = "New note"; actions[1].label = "Share"; actions[1].disabled = disabled if Toolbar.Draw(session, Toolbar.Props.{.height = 48}, no_options, actions[:]).clicked_action >= 0 { clicks += 1 } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "toolbar"}, Frame) } diff --git a/examples/tooltip/tooltip.zi b/examples/tooltip/tooltip.zi index ef6769053..d51918f7d 100644 --- a/examples/tooltip/tooltip.zi +++ b/examples/tooltip/tooltip.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -95,14 +96,15 @@ Prepare :: (session: Session, scene: s32) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "Tooltip", .size = 23}) disabled := example_input.disabled scene: s32 = 0 @@ -137,15 +139,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } unused Tooltip.Draw(session, props, *tooltip_state) unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "tooltip"}, Frame) } diff --git a/examples/transition/transition.zi b/examples/transition/transition.zi index 56fe64d06..ed9afb1b8 100644 --- a/examples/transition/transition.zi +++ b/examples/transition/transition.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Box :: #import "kryon/box"; Button :: #import "kryon/button"; Text :: #import "kryon/text"; @@ -11,12 +12,13 @@ DemoTheme :: #import "kryon/Theme"; state: TransitionState; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport input := CaptureFrameInput(session) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace5), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.disabled = example_disabled, .bounds = .{height = 40}, .text = "Transition", .size = 28}) if Button.Draw(session, Button.Props.{.disabled = example_disabled, .bounds = .{width = 180, height = 44}, .label = "Animate fade"}) != 0 { state = TransitionStart(0.6) } state = TransitionAdvance(state, (ifx (example_reduced_motion || DemoTheme.CurrentTheme().motion.reduced_motion) then 1.0 else cast(float32)input.delta_ms / 1000.0)).state @@ -28,15 +30,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "transition"}, Frame) } diff --git a/examples/treeview/treeview.zi b/examples/treeview/treeview.zi index 9ef4edd08..4e22f7179 100644 --- a/examples/treeview/treeview.zi +++ b/examples/treeview/treeview.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "kryon/geometry" #import "kryon/session" #import "kryon/frame_snapshot" @@ -97,14 +98,15 @@ Prepare :: (session: Session, scene: s32) { bounds = GalleryBounds(Rectangle.{24.0, 64.0, 432.0, 208.0}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport example_input := WidgetInput(session) SetGalleryViewport(viewport, true, example_input.now, example_input.reduced_motion) Box.Draw(session, Box.Props.{.bounds = viewport, .fill = StyleTokenColor("canvas")}) page := Layout.Draw(session, Layout.Props.{.bounds = viewport, .padding = Layout.Gap(.ThemeMetricSpace6), .gap = Layout.Gap(.ThemeMetricSpace4), .gap_override = true}) - if !page.opened { return 0 } + if !page.opened { return } Text.Draw(session, Text.Props.{.bounds = .{height = 36}, .text = "TreeView", .size = 23}) disabled := example_input.disabled scene: s32 = 0 @@ -121,15 +123,16 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { result := Trees.TreeView(session, Trees.TreeViewProps.{.bounds = bounds, .selected_id = tree_selection, .scroll_offset = tree_scroll, .row_height = 36, .disabled = disabled}, tree_items[:]) tree_selection = result.selected_id; tree_scroll = result.scroll_offset unused End(session) - return 0 + return } example_disabled: bool; example_reduced_motion: bool; -// Hosts publish these options before the unchanged application entry point. -#program_export +// The gallery host calls this before drawing the example's frames. SetExampleOptions :: (disabled: bool, reduced_motion: bool) { example_disabled = disabled example_reduced_motion = reduced_motion } + +main :: () -> s32 { return App.Run(App.Window.{.title = "treeview"}, Frame) } diff --git a/mk/ziran-project.mk b/mk/ziran-project.mk index f866e19d2..b24cf060e 100644 --- a/mk/ziran-project.mk +++ b/mk/ziran-project.mk @@ -49,10 +49,6 @@ ifeq ($(PROJECT_CODEGEN),c99) PROGRAM := $(PROJECT_BUILD_DIR)/$(PROJECT_NAME)-$(PROJECT_PROFILE).html endif endif -HOST_MODULE := $(PROJECT_BACKEND)_run -ifneq ($(filter $(PROJECT_BACKEND)/$(PROJECT_CODEGEN),desktop/zx canvas/zx),) -HOST_MODULE := zx_run -endif # The program's name for its window, page and menu entry: the install name or # else the package name. The kryon tool passes it as KRYON_PROGRAM_TITLE, read # only as a shell variable, so the text cannot change a recipe. Native and ZX @@ -61,7 +57,6 @@ endif PROGRAM_TITLE_FILE := $(if $(filter %.html,$(PROGRAM)),,$(if $(filter %.zx,$(PROGRAM)),$(PROGRAM:.zx=.title),$(PROGRAM).title)) PAGE_SHELL := $(if $(BROWSER_BACKEND),$(GEN_DIR)/page-shell.html) PAGE_SHELL_SOURCE := $(KRYON_DIR)/mk/$(if $(filter zx,$(PROJECT_CODEGEN)),zx,$(PROJECT_BACKEND))-shell.html -HOST_ID := $(ZIRAN_PACKAGE_ID)_$(HOST_MODULE) PROJECT_CONFIG_FILES := ziran.toml ziran.lock # The test driver is test code: a build includes it only when # KRYON_TEST_DRIVER is set in its environment, as it is when the program runs @@ -72,6 +67,12 @@ ZIRAN_MODULE_ARGS := --project $(if $(KRYON_TEST_DRIVER),--define KRYON_TEST_DRI ifeq ($(PROJECT_BACKEND),dom) ZIRAN_MODULE_ARGS += --define KRYON_DOM endif +ifeq ($(PROJECT_BACKEND),terminal) +ZIRAN_MODULE_ARGS += --define KRYON_TERMINAL +endif +ifeq ($(PROJECT_BACKEND),pixmap) +ZIRAN_MODULE_ARGS += --define KRYON_PIXMAP +endif ifeq ($(PROJECT_BACKEND)/$(PROJECT_CODEGEN),desktop/c99) ifeq ($(shell uname -s),Linux) # The desktop host needs Linux settings even when the frame IR has no target OS. @@ -80,11 +81,10 @@ endif endif ifeq ($(filter $(PROJECT_BACKEND),desktop),) # A non-desktop C build (terminal, canvas, dom, pixmap) hosts no desktop -# window, and its capture never calls App.Run; kryon/app then maps the -# program's window calls to app_unsupported so it carries no desktop modules. +# window; kryon/app then maps the program's window calls to app_unsupported +# so it carries no desktop modules. ZIRAN_MODULE_ARGS += --define KRYON_NO_DESKTOP_HOST endif -HOST := $(KRYON_DIR)/src/backend/$(HOST_MODULE).zi ifneq ($(PROJECT_HOST),) PROJECT_HOST_PATH := $(realpath $(PROJECT_HOST)) ifeq ($(filter $(CURDIR)/%,$(PROJECT_HOST_PATH)),) @@ -92,10 +92,11 @@ $(error the profile host must stay inside the project directory) endif HOST := $(PROJECT_HOST) HOST_ID := $(basename $(notdir $(PROJECT_HOST))) +HOST_ROOT_SOURCES := $(HOST) # Ziran's byte-pointer argv has the C argv layout. GCC's hosted-main # spelling warning does not apply to that generated entry signature. HOST_CFLAGS := -Wno-main -endif +else APP_SOURCES := $(shell find . -type d \( -name build -o -name .git -o -name vendor \) -prune -o -type f -name '*.zi' -print) UI_SOURCES := $(shell find $(KRYON_DIR)/src/ui -type f -name '*.zi') HOST_SOURCES := $(wildcard $(KRYON_DIR)/src/backend/$(PROJECT_BACKEND)*.zi $(KRYON_DIR)/src/backend/avif*.zi) @@ -106,61 +107,32 @@ endif ifneq ($(filter $(PROJECT_BACKEND),desktop canvas),) HOST_SOURCES += $(KRYON_DIR)/src/ui/frame_input_provider.zi endif -HOST_ROOT_SOURCES := $(HOST) -ifeq ($(PROJECT_HOST),) -# Bind the host frame through Ziran's generic capability API. -# The selected source remains one ordinary module with its own filename. +# Every entry is a program: it declares `main` and opens its window through +# kryon/app, which selects the host for the compiled target. PROJECT_ENTRY_MODULE := $(basename $(notdir $(PROJECT_ENTRY))) ifeq ($(PROJECT_ENTRY_MODULE),module) PROJECT_ENTRY_MODULE := $(notdir $(patsubst %/,%,$(dir $(PROJECT_ENTRY)))) endif -# A program entry owns `main` and opens its window through kryon/app, which -# selects the host for the compiled target. A frame entry declares Frame and -# the profile's host owns main. PROJECT_PROGRAM := $(shell grep -Eqs '^main[[:space:]]*::' '$(PROJECT_ENTRY)' && echo program) -# Capture builds (kryon preview / run --png) render a fixture's or the -# entry's Frame even when it declares a main; fixtures are drawing modules, -# not programs. -PROJECT_CAPTURE := $(PROJECT_CAPTURE) -ifeq ($(PROJECT_CAPTURE),) -ifeq ($(PROJECT_BACKEND),dom) -ifneq ($(PROJECT_PROGRAM),) -$(error backend dom needs an exported Frame rather than main) -endif -endif -# A desktop or portable UI program declares main; frame entries are being -# retired. The deprecated KRYON_FRAME_ENTRY=1 escape keeps not-yet-migrated -# frame-mode fixtures building until their host capabilities move into -# kryon/app (see plans/enforce-main-ui-programs.md). -ifneq ($(filter $(PROJECT_BACKEND),desktop),) ifeq ($(PROJECT_PROGRAM),) -ifeq ($(KRYON_FRAME_ENTRY),) -$(error $(PROJECT_ENTRY) has no main. Kryon UI programs declare one: add `main :: () -> s32` that runs App.Run from kryon/app, as docs/APPS.md shows. A frame entry still builds during the migration with KRYON_FRAME_ENTRY=1) -endif -endif -endif +$(error $(PROJECT_ENTRY) has no main. Kryon programs declare one: add `main :: () -> s32` that runs App.Run from kryon/app, as docs/APPS.md shows) endif # Track the export annotation belonging to main, rather than unrelated exports. # Every make version reads \# in an assignment as a literal number sign. PROJECT_HASH := \# PROJECT_EXPORTED_MAIN := $(shell awk '/^$(PROJECT_HASH)program_export([[:space:]]*("main")?[[:space:]]*;?[[:space:]]*)$$/ { exported=1; next } /^main[[:space:]]*::/ { if (exported) print "main"; exit } !/^[[:space:]]*($$|\/\/|$(PROJECT_HASH))/ { exported=0 }' '$(PROJECT_ENTRY)') -ifneq ($(PROJECT_CAPTURE),) -# A capture renders Frame even for a program entry. -PROJECT_FRAME_BIND := --bind $(ZIRAN_PACKAGE_ID)_frame_entry:ProjectFrame=$(PROJECT_ENTRY_MODULE):Frame -HOST_ROOT_SOURCES += $(PROJECT_ENTRY) $(KRYON_DIR)/src/backend/frame_entry.zi -else ifneq ($(PROJECT_PROGRAM),) ifeq ($(PROJECT_CODEGEN),zx) # A portable program's bundle is its own main, which kryon/app gives the # window ZX bundles have; the profile's player runs it. HOST_ID := $(PROJECT_ENTRY_MODULE) -PROJECT_FRAME_BIND := +PROJECT_ENTRY_LINK := HOST_ROOT_SOURCES := $(PROJECT_ENTRY) else ifneq ($(PROJECT_CODEGEN),c99) $(error a program entry ($(PROJECT_ENTRY) declares main) needs codegen c99 or zx) else ifneq ($(PROJECT_EXPORTED_MAIN),) # An exported main already supplies the process entry; do not add another. HOST_ID := $(PROJECT_ENTRY_MODULE) -PROJECT_FRAME_BIND := +PROJECT_ENTRY_LINK := HOST_ROOT_SOURCES := $(PROJECT_ENTRY) else # The generated host is the process entry; it only calls the program's main. @@ -168,13 +140,9 @@ PROGRAM_HOST := $(GEN_DIR)/program-host/kryon_program_host.zi HOST := $(PROGRAM_HOST) HOST_ID := kryon_program_host # Its folder is a module path, so the host is saved under its own name. -PROJECT_FRAME_BIND := --module-path $(dir $(PROGRAM_HOST)) +PROJECT_ENTRY_LINK := --module-path $(dir $(PROGRAM_HOST)) HOST_ROOT_SOURCES := $(PROGRAM_HOST) $(PROJECT_ENTRY) endif -else -PROJECT_FRAME_BIND := --bind $(ZIRAN_PACKAGE_ID)_frame_entry:ProjectFrame=$(PROJECT_ENTRY_MODULE):Frame -HOST_ROOT_SOURCES += $(PROJECT_ENTRY) $(KRYON_DIR)/src/backend/frame_entry.zi -endif endif ifeq ($(PROJECT_CODEGEN)/$(PROJECT_BACKEND),zx/canvas) # Portable app IR is identical on desktop and web. Only the renderer shell @@ -195,7 +163,7 @@ HOST_ROOT_SOURCES += $(KRYON_DIR)/src/backend/canvas_raster.zi endif # Browser hosts resolve the app's packages like native ones; every saved # module is lowered because the browser runtime calls into the page. -IR_COMMAND := $(ZIRAN) ir $(ZIRAN_MODULE_ARGS) $(PROJECT_FRAME_BIND) $(WEB_TARGET) --define PLATFORM_WEB \ +IR_COMMAND := $(ZIRAN) ir $(ZIRAN_MODULE_ARGS) $(PROJECT_ENTRY_LINK) $(WEB_TARGET) --define PLATFORM_WEB \ --entry $(HOST_ID):main -o $(IR_DIR) $(HOST_ROOT_SOURCES) C_COMMAND := $(ZIRAN_DIR)/build/bin/zi2c --define PLATFORM_WEB \ --root $(IR_DIR) -o $(C_DIR) $(IR_DIR)/*.zir @@ -203,7 +171,7 @@ C_COMMAND := $(ZIRAN_DIR)/build/bin/zi2c --define PLATFORM_WEB \ else # A program selects its kryon/app host by compiled target, so a C program's # IR names the native C target; a ZX program's and frame IR stay portable. -IR_COMMAND := $(ZIRAN) ir $(ZIRAN_MODULE_ARGS) $(PROJECT_FRAME_BIND) $(if $(PROJECT_PROGRAM),$(if $(filter c99,$(PROJECT_CODEGEN)),--target=c)) $(if $(filter c99,$(PROJECT_CODEGEN)),--define POSIX_THREADS) --entry $(HOST_ID):main -o $(IR_DIR) $(HOST_ROOT_SOURCES) +IR_COMMAND := $(ZIRAN) ir $(ZIRAN_MODULE_ARGS) $(PROJECT_ENTRY_LINK) $(if $(filter c99,$(PROJECT_CODEGEN)),--target=c --define POSIX_THREADS) --entry $(HOST_ID):main -o $(IR_DIR) $(HOST_ROOT_SOURCES) C_COMMAND := $(ZIRAN) build --target=c --entry $(HOST_ID):main \ --root $(IR_DIR) -o $(C_DIR) $(IR_DIR)/*.zir endif @@ -468,7 +436,7 @@ endif # Check the complete bound graph through the same IR route as a build. check: toolchain $(PROGRAM_HOST) - $(ZIRAN) ir $(ZIRAN_MODULE_ARGS) $(PROJECT_FRAME_BIND) -o $(GEN_DIR)/check-ir --entry $(HOST_ID):main $(if $(filter c99,$(PROJECT_CODEGEN)),$(if $(BROWSER_BACKEND),$(WEB_TARGET) --define PLATFORM_WEB,$(if $(PROJECT_PROGRAM),--target=c))) $(HOST_ROOT_SOURCES) + $(ZIRAN) ir $(ZIRAN_MODULE_ARGS) $(PROJECT_ENTRY_LINK) -o $(GEN_DIR)/check-ir --entry $(HOST_ID):main $(if $(filter c99,$(PROJECT_CODEGEN)),$(if $(BROWSER_BACKEND),$(WEB_TARGET) --define PLATFORM_WEB,--target=c)) $(HOST_ROOT_SOURCES) # `ziran install` copies the built program to PREFIX/bin and describes it to # the desktop. The KRYON_INSTALL_* values come from [tool.kryon.install] and diff --git a/plans/enforce-main-ui-programs.md b/plans/enforce-main-ui-programs.md index fba4dd083..2890e80a1 100644 --- a/plans/enforce-main-ui-programs.md +++ b/plans/enforce-main-ui-programs.md @@ -1,135 +1,54 @@ -# Enforce `main` for Kryon UI programs +# Enforce `main` for Kryon UI programs (landed) -Owner direction: a Kryon UI program should not be a special Frame-entry file -that only a host can start. Every UI program is an ordinary Ziran program: -it declares `main`, and the #program_export host-binding machinery -disappears. Expected to reduce the codebase. +Owner direction: a Kryon UI program must not be a special Frame-entry file +that only a host can start. Every UI program is an ordinary Ziran program +whose `main` runs `App.Run(window, Frame)` from `kryon/app`; `Frame` stays an +ordinary function the app passes to its own run call. The owner superseded +the original phased plan and ordered the whole Frame-entry mechanism removed +at once, and that removal has landed on master. No phased work remains. -## Why (the bug that surfaced this) - -Opening the Wasm target for a Frame-entry UI file (voyki `src/app.zi`) shows -`app.zi has no main; it's a module. Run a program that imports it.` — -ziran-vscode `targets.cjs` `mainLine()` (line ~330) matches only -`^main\s*::\s*\(`; `buildWasm` (line ~633) fails the target when hasMain is -false; `buildArgs` (line ~365) always passes `--entry :main` for -wasm. The message is factually right for the compiler (wasm needs an entry) -but wrong for the user: a Frame-entry UI file is a program in Kryon's model, -and `run.cjs` already routes `kryon/app` programs to the Kryon preview notice -(`KRYON_PROGRAM_NOTICE`, run.cjs line 15). The real fix is upstream: remove -the Frame-entry program model so UI programs have `main` and every target -builds like any other program. - -## Entry contract (phase 1) - -Chosen contract (the one `docs/APPS.md` already blesses): +## Landed contract ```zi App :: #import "kryon/app"; main :: () -> s32 { window := App.Window.{ .title = "App", .width = 960, .height = 600 } - return App.Run(window, Draw) + return App.Run(window, Frame) } -Draw :: (frame: App.Frame) { /* widgets; App.Quit() exits the loop */ } +Frame :: (frame: App.Frame) { /* widgets; WindowQuit() from "Window" exits */ } ``` -Alternatives rejected: +- `main` is the only program entry. A project entry without `main ::` fails + the build with a migration message pointing at this contract. +- The Frame program export is gone entirely: no compat alias, no second + entry mode, no `--bind frame_entry:ProjectFrame=...`, no + `KRYON_FRAME_ENTRY` escape, no capture-only Frame exemption. +- `#program_export` itself stays a Ziran language feature for plain native + C-ABI exports (window, notification and Cairo modules export functions, + not programs). Removing it from the language is a Ziran-side decision, + out of scope here. +- Quitting is a window operation (`WindowQuit` in `Window`), not a Frame + return value; a Frame that draws nothing cannot fail the program. -- `main :: (argc: s32, argv: **u8) -> s32` — no Kryon host needs argv today; - the compiler already adapts a parameterless entry. Rejected: extra surface. -- Compiler-synthesized `main` from `Frame` — keeps the special case but moves - it into the compiler, which must never know Kryon. Rejected. -- Keep Frame and only add the wasm entry — leaves two program models and the - confusing editor story. Rejected. +## What landed -Backends and phases: +- `kryon/app` dispatches each target to its frame loop: `frames_desktop`, + `frames_web`, `frames_dom`, `frames_zx`, `frames_terminal`, + `frames_pixmap`, `frames_android`; the old `desktop_run`, `canvas_run`, + `dom_run`, `terminal_run`, `pixmap_run`, `zx_run` and `frame_entry` + host modules are deleted. +- `mk/ziran-project.mk` bundles the program's own `main` for portable ZX + builds and wraps plain C mains with a generated `kryon_program_host`. +- `Window` (`src/ui/window.zi`) supplies the window controls programs need + (close interception, hide/show, quit), so tests and apps run as programs. +- Templates, examples, docs and the whole test suite use the `main` + + `App.Run` shape; `docs/CHEATSHEET.md`, `docs/APPS.md`, + `docs/PROJECTS.md`, `docs/BACKENDS.md` and `docs/FRAME_REPLAY.md` state + the rule. +- ziran-vscode lost its `KRYON_PROGRAM_NOTICE` special path, so Kryon UI + programs build and run like any other Ziran program with `main`. -| Backend | Program path today | Phase | -|---|---|---| -| desktop c99 + portable zx | yes (`App.Run` -> `frames_desktop`, `zx_window`) | enforce now | -| web canvas | yes (`page_window`/`frames_web`) but fixtures use frame-mode host capabilities (`RequestWindowClose`) | phase 2 | -| terminal, dom, pixmap(shot), android | no app-side run helper; hosts own the loop | phase 2/3 | - -Owner direction: the Frame program export is removed entirely — no compat -alias, no second entry mode, no `#program_export` UI program path. The only -migration aid is the phase 1 build error pointing at `main`. -`#program_export` itself stays a Ziran language feature for plain native C -exports (window, notification and Cairo modules export functions, not -programs); removing it from the language would be a Ziran-side change -outside this plan. - -## Phase 1 (this change, kryonlabs/kryon) - -- `mk/ziran-project.mk`: a desktop/portable project entry without `main ::` - fails the build with a migration message, except capture builds - (`kryon preview`/`run --png`, `PROJECT_CAPTURE=1`) and the deprecated - `KRYON_FRAME_ENTRY=1` escape hatch for fixtures that still need frame-mode - host capabilities. -- `src/project/cli_linux.zi`: capture builds pass `PROJECT_CAPTURE=1` - (replaces the `PROJECT_PROGRAM=` override). -- `templates/{app,web,pages,tui}`: scaffolds gain `main` + `App.Run`; Frame - bodies stay where captures or the terminal profile still read them. -- Tests that build desktop profiles from Frame-only fixtures pass - `KRYON_FRAME_ENTRY=1` until phase 2 ports them. -- Docs: `docs/APPS.md` and `docs/PROJECTS.md` state the rule and the ladder. - -## Phase 2 (capability ports) - -1. Program-mode close interception and input-driven quit for desktop - (`App.Quit`, window close request) so `tests/window_desktop_test.py` and - `tests/desktop_project_test.py` port off frame mode. -2. Canvas program capabilities (page close/route probes) so - `canvas_project_test.py` and `page_route_project_test.py` port. -3. `App.RunTerminal`, `App.RunDom`, shot capture through the program loop; - extend enforcement to web/terminal/dom/pixmap; drop `KRYON_FRAME_ENTRY`. -4. Android glue follows the terminal/dom shape. - -## Phase 3 (the deletions — the codebase reduction) - -Once no consumer builds a Frame-entry program: - -- delete `src/backend/frame_entry.zi` (13 lines) and the `--bind - ...frame_entry:ProjectFrame=...` machinery (mk lines ~146-149, 444); -- delete the hosts' `main`+`Frame` bodies (desktop_run 45, canvas_run 81, - dom_run 48, terminal_run 245, pixmap_run 37, zx_run 171, android_run ~400 - lines shrink to thin loop modules behind `App.Run*`); -- the end state has one program model: every Kryon UI file declares `main`. - A Frame entry then fails the build with the phase 1 migration error - (pointing at `main` and docs/APPS.md) — no compat alias, no - `KRYON_FRAME_ENTRY` escape, no capture-only exemption; -- capture rework: plain `kryon run shot` (no `--png`) only ever reaches the - frame-entry path, so it disappears with Frame — either render a program's - `Draw` once through a generated host or drop the bare form; `--png` - capture (`PROJECT_CAPTURE=1`) already runs program entries and stays; -- ziran-vscode: no special casing needed; the wasm/native targets unify on - the hasMain path (`targets.cjs`), `isKryonProgram` keeps only the - `kryon/app` import check (preview.cjs lines 70-76, run.cjs line 196); the - never-added wasm special case (~20 lines) is avoided. - -## Consumers (Frame-entry UI files across ~/Projects: 171) - -- 130 kryonlabs/kryon (examples are preview fixtures on the capture path; - about 10 test fixtures and 4 templates are the migration surface) -- 8 waozixyz/games (voyki, katalis, arcade, choano, wurm) -- 6 waozixyz/apps (werk, photos, relay) -- 4 harness/harmony (client/security/src/app.zi and plugins) -- 23 others (benchmarks, taskmgr, explorer, browser, packages, archives) - -Voyki migrates in phase 1. Others migrate per repository by bumping their -Kryon pin; pinned consumers (harmony pins c728654) are unaffected until they -choose to move. - -## Net delta - -Phase 1 is a small net addition (roughly +60 lines: error block, capture -flag, template mains, docs) because the deletions are phase 3. The end state -removes 1,000+ lines of frame-entry host/bind code across the two repos and -deletes the editor special case before it is written. - -## Tests - -Per migrated area: `make test-focus TEST=tests/` (watch, desktop -project, native assets, canvas, page route, window), `make` module check, -`make push-check` before pushing; voyki: `ziran lock`, -`kryon build --profile desktop`, `kryon run shot`, then commit and push. +Live consumers migrate in their own repositories by bumping their Kryon pin; +ARCHIVE repositories stay frozen. diff --git a/scripts/export-gallery-zx.py b/scripts/export-gallery-zx.py index b869e3adb..36f198853 100644 --- a/scripts/export-gallery-zx.py +++ b/scripts/export-gallery-zx.py @@ -10,14 +10,6 @@ import tomllib import gallery -def scoped(package, module): - """Name a module loaded through `--module-path PACKAGE=DIR`, as Ziran does.""" - digest = 1469598103934665603 - for byte in package.encode(): - digest = ((digest ^ byte) * 1099511628211) & 0xffffffffffffffff - return f'p{digest:016x}_{module}' - - def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--output', type=Path, default=gallery.ROOT / 'build/gallery-zx') @@ -96,10 +88,9 @@ def main(): app.write_text(source) bundle = output / (entry['id'] + '.zx') bundle.parent.mkdir(parents=True, exist_ok=True) - subprocess.run([compiler, 'bundle', *paths, '--entry', scoped('kryon', 'zx_run') + ':main', - '--bind', scoped('kryon', 'frame_entry') + ':ProjectFrame=app:Frame', + subprocess.run([compiler, 'bundle', *paths, '--entry', 'app:main', '--asset-dir', 'assets=' + str(gallery.PROJECT / 'assets'), - '-o', str(bundle), str(gallery.ROOT / 'src/backend/zx_run.zi'), str(app)], + '-o', str(bundle), str(app)], cwd=gallery.PROJECT, env=compile_env, check=True) index.append({**entry, 'bundle': bundle.relative_to(output).as_posix()}) print('Exported ' + entry['id'] + ': ' + entry['name'], flush=True) diff --git a/scripts/gallery.py b/scripts/gallery.py index c3ecd7db1..9f6130e7d 100644 --- a/scripts/gallery.py +++ b/scripts/gallery.py @@ -204,10 +204,10 @@ def prepare(only=None, *, catalog=None, site=SITE, examples=None): if not following: break wanted |= following used += '\n' + '\n'.join(declarations[key] for key in following) - native_code = imports_code + '\n#import "widget_context"\n#import "palette"\n' + native_code = 'App :: #import "kryon/app";\n' + imports_code + '\n#import "widget_context"\n#import "palette"\n' native_code += '\n\n'.join(value for key, value in declarations.items() if key in wanted) + '\n\n' - frame = template[template.index('#program_export'):] - frame = frame.replace('// @title', name).replace('PreviewInputRead()', 'WidgetInput(session)') + frame = template[template.index('Frame ::'):] + frame = frame.replace('// @title', name).replace('PreviewInputRead()', 'WidgetInput(session)').replace('.title = "frame"', '.title = "' + slug + '"') frame = frame.replace(' // @example', setup_code + textwrap.indent(textwrap.dedent(preamble_code).strip(), ' ') + '\n' + textwrap.indent(textwrap.dedent(fragment).strip(), ' ')) write(entry, native_code + frame) code = entry.read_text() @@ -290,11 +290,11 @@ def prepare(only=None, *, catalog=None, site=SITE, examples=None): alias = 'Usage' + str(len(render_modules)) module_name = 'usage_' + Path(path).stem code = (ROOT / path).read_text() - write(output / (module_name + '.zi'), code.replace('#program_export\n', '')) + write(output / (module_name + '.zi'), re.sub(r'\nmain :: \(\) -> s32 \{ return App\.Run\(App\.Window\.\{\.title = "[^"]*"\}, Frame\) \}(?:\n|\Z)', '\n', code)) imports.append(f'{alias} :: #import "{module_name}";') render_modules[path] = alias alias = render_modules[path] - dispatch.append(f" if scene == {entry['index']} {{ {alias}.SetExampleOptions(disabled, catalog_reduced_motion); unused {alias}.Frame(session, catalog_viewport); return }}") + dispatch.append(f" if scene == {entry['index']} {{ {alias}.SetExampleOptions(disabled, catalog_reduced_motion); App.CallDraw({alias}.Frame, session.slot, session.epoch, catalog_viewport); return }}") # This directory contains generated examples only. Drop sources whose # module or example is no longer part of this build. expected = {Path(site) / entry['code'] for entry in entries} @@ -310,7 +310,7 @@ def prepare(only=None, *, catalog=None, site=SITE, examples=None): else: result += f" if index == {entry['index']} {{ return {json.dumps(text, ensure_ascii=False)} }}\n" return result + ' return ""\n}\n' - registry = '#import "kryon/geometry"\n#import "kryon/session"\n#import "palette"\n' + '\n'.join(imports) + '\n' + registry = 'App :: #import "kryon/app_types";\n#import "kryon/geometry"\n#import "kryon/session"\n#import "palette"\n' + '\n'.join(imports) + '\n' registry += 'catalog_viewport: Rectangle = .{0.0, 0.0, 480.0, 320.0};\n' registry += f'GallerySceneCount :: {len(entries)};\n' registry += 'GalleryCompilerSearch :: () -> string {\n return #string GALLERY_COMPILER_SEARCH\n' + '\n'.join(compiler_paths(modules)) + '\nGALLERY_COMPILER_SEARCH\n}\n' diff --git a/scripts/generate_android_sources.py b/scripts/generate_android_sources.py index 47ab507fa..70c8ff007 100644 --- a/scripts/generate_android_sources.py +++ b/scripts/generate_android_sources.py @@ -101,8 +101,8 @@ kryon = args.kryon.resolve() entry = (root / args.entry).resolve() if not entry.is_file() or entry.suffix != ".zi": parser.error(f"selected application entry is not a Zi source: {entry}") -needs_frame = args.host is None and args.codegen == "c99" -if needs_frame and not args.package_id: +needs_program = args.host is None and args.codegen == "c99" +if needs_program and not args.package_id: parser.error("--package-id is required unless ZIRAN_PACKAGE_ID is supplied by ziran tool kryon") entry_module = entry.parent.name if entry.stem == "module" else entry.stem sources = sorted((root / "src").rglob("*.zi")) @@ -117,10 +117,10 @@ host_roots = [ root / "src/android_glue.zi", ] bindings = [] -if needs_frame: - host_roots.extend([entry, kryon / "src/backend/frame_entry.zi"]) +if needs_program: + host_roots.append(entry) bindings = ["--bind", - f"{args.package_id}_frame_entry:ProjectFrame={entry_module}:Frame"] + f"{args.package_id}_android_run:AndroidProgramMain={entry_module}:main"] for path in host_roots: if not path.is_file(): raise SystemExit(f"Missing host source {path}; run scripts/android_scaffold.py") @@ -191,7 +191,7 @@ if bundled_fonts is True or bundled_fonts == "true": frame_mode = android_options.get("frame_mode", "adaptive") if frame_mode not in ("adaptive", "events"): parser.error("[tool.kryon.android] frame_mode must be 'adaptive' or 'events'") -if frame_mode == "events" and needs_frame: +if frame_mode == "events" and needs_program: defines.extend(["--define", "KRYON_ANDROID_EVENT_FRAMES"]) if args.codegen == "zx": defines.extend(["--define", "KRYON_ZX_APP", "--define", "BUNDLE_NATIVE_RENDERER"]) diff --git a/src/backend/android_bundle_run.zi b/src/backend/android_bundle_run.zi index ac5bbed11..297b6dd0f 100644 --- a/src/backend/android_bundle_run.zi +++ b/src/backend/android_bundle_run.zi @@ -45,6 +45,18 @@ AndroidBundleHost :: struct { text_session: Session hosted: bool media_slot: s32 + // The portable bundle owns its event loop; this state carries the + // player's wait callback between its frames. + frames: s32 + reuse: bool + frame_reuse: bool + quiet_frames: s32 + was_paused: bool + next_frame_ms: s64 + swap_pending: bool + first_pending: bool + selected: [4096]u8 + selected_count: s32 } android_bundle_hosts: [2]AndroidBundleHost; @@ -196,6 +208,7 @@ AndroidBundleOpen :: (host: *AndroidBundleHost, data: string, } Player.PlayerUseTextEditor(*host.player, AndroidBundleEditorPresent, AndroidBundleEditorRequest, cast(*void)host) + Player.PlayerUseWait(*host.player, AndroidBundleWait, cast(*void)host) return true } @@ -210,7 +223,7 @@ AndroidBundlePresent :: () -> bool { } AndroidBundleDraw :: (host: *AndroidBundleHost, session: Session, - viewport: AndroidViewport, bounds: Rectangle, zoom: float32, reuse: bool) -> bool { + viewport: AndroidViewport, bounds: Rectangle, zoom: float32) -> bool { width := viewport.x + viewport.width height := viewport.y + viewport.height if !AndroidNativeSurfaceSize(*width, *height) || @@ -234,32 +247,18 @@ AndroidBundleDraw :: (host: *AndroidBundleHost, session: Session, if AndroidTextInputKeyPressed(257) { key = 257 } codepoint := AndroidTextInputCharacter() while codepoint != 0 { - if host.hosted { unused TypedCodepointSend(session, codepoint) } - else { Player.PlayerTyped(*host.player, codepoint) } + unused TypedCodepointSend(session, codepoint) codepoint = AndroidTextInputCharacter() } pointer := PollPointer() secondary := PollSecondaryPointer() - if host.hosted { - typed: [1024]u8 - text := TypedTextTake(session, typed[:]) - ok = BundleAppFrame(*host.app, bounds, pointer, secondary, key, 0, 0.0, - text, cast(float64)Clock.MonotonicMilliseconds() / 1000.0) - host.player.keyboard = host.app.app.keyboard - host.player.failed = host.app.failed - } else { - host.text_session = session - host.raster.x = bounds.x - host.raster.y = bounds.y - ok = Player.PlayerFrameNative(*host.player, Player.Input.{ - .width = cast(s32)bounds.width, .height = cast(s32)bounds.height, - .x = pointer.x - bounds.x, .y = pointer.y - bounds.y, - .down = pointer.down, .pressed = pointer.pressed, - .released = pointer.released, .secondary_down = secondary.down, - .secondary_pressed = secondary.pressed, - .secondary_released = secondary.released, .key = key}) - } + typed: [1024]u8 + text := TypedTextTake(session, typed[:]) + ok = BundleAppFrame(*host.app, bounds, pointer, secondary, key, 0, 0.0, + text, cast(float64)Clock.MonotonicMilliseconds() / 1000.0) + host.player.keyboard = host.app.app.keyboard + host.player.failed = host.app.failed if !ok { AndroidNativeLog(ifx host.player.failed then "Android portable VM failed" else "Android guest frame rejected") } FrameInputEnd(session) AndroidTouchFrameEnd() @@ -267,33 +266,144 @@ AndroidBundleDraw :: (host: *AndroidBundleHost, session: Session, return ok && AndroidBundlePresent() } -AndroidBundleRunMain :: () -> s32 { - AndroidNativeLog("Android portable host starting") - AndroidJniKeepHostThread() - defer { AndroidJniReleaseHostThread() } - AndroidProcessPrepare() - - input_session := SessionOpen() - if !SessionValid(input_session) { AndroidNativeLog("Android input session failed"); return 1 } - defer { CloseSession(input_session) } - AndroidTextInputOpen(input_session) - defer { AndroidTextInputClose(input_session) } - - android_bundle_data[0] = AndroidBundleRead("app.zx") - if android_bundle_data[0].count == 0 { AndroidNativeLog("Android app.zx asset is missing"); return 1 } - defer { - AndroidBundleClose(*android_bundle_hosts[0]) - AndroidBundleClose(*android_bundle_hosts[1]) - AndroidBundleFree(android_bundle_data[0]) - AndroidBundleFree(android_bundle_data[1]) - android_bundle_data[0] = "" - android_bundle_data[1] = "" - android_bundle_active = 0 +// Finishes the portable frame the bundle just drew: input bracketing, the +// pixel flush and the window's next present. +AndroidBundleFrameEnd :: (host: *AndroidBundleHost, session: Session) -> bool { + FrameInputEnd(session) + AndroidTouchFrameEnd() + PixmapEndInto() + present := AndroidBundlePresent() + if present && host.first_pending { + host.first_pending = false + AndroidNotifyFirstFrame() } - android_bundle_hosts[0].media_slot = 0 - android_bundle_hosts[1].media_slot = 1 - if !AndroidBundleOpen(*android_bundle_hosts[0], android_bundle_data[0]) { AndroidNativeLog("Android app.zx failed to open"); return 1 } + AndroidTextInputFrame(session, host.player.keyboard) + return present +} +// The portable bundle's wait callback: presents the previous frame, paces, +// then prepares the next frame's surface and fills its input record. +// Android owns the window, lifecycle and pixels; the bundle owns its loop. +AndroidBundleWait :: (context: *void, input: *Player.Input) -> bool { + host := cast(*AndroidBundleHost)context + session := host.text_session + if host.frames > 0 { + host.quiet_frames = ifx host.frame_reuse then host.quiet_frames + 1 else 0 + host.reuse = true + host.next_frame_ms = Clock.MonotonicMilliseconds() + + ifx host.quiet_frames >= 2 then cast(s64)100 else cast(s64)16 + if !AndroidBundleFrameEnd(host, session) { return false } + } + width: s32 + height: s32 + loop { + now := Clock.MonotonicMilliseconds() + timeout := ifx host.next_frame_ms > now then cast(s32)(host.next_frame_ms - now) else 0 + if timeout > 1000 { timeout = 1000 } + unused AndroidNativePoll(timeout) + if AndroidNativeDestroyRequested() { return false } + if AndroidNativePaused() || !AndroidNativeWindowReady() || + !AndroidNativeSurfaceSize(*width, *height) { + if !host.was_paused && host.media.state == 2 { + AndroidBundleMediaPausePlayback(*host.media) + } + host.was_paused = true + AndroidTextInputFrame(session, false) + host.reuse = false + host.quiet_frames = 0 + host.next_frame_ms = Clock.MonotonicMilliseconds() + 1000 + continue + } + break + } + host.was_paused = false + host.selected_count = AndroidBundleTakeFile(host.selected[:]).count + if host.selected_count > 0 { + // The loop ends here; the runner swaps the selected bundle in. + host.swap_pending = true + return false + } + if AndroidNativeTakeResized() || AndroidTakeGraphicsInvalidate() != 0 || + AndroidNativeTakeRedraw() { host.frame_reuse = false } + viewport: AndroidViewport + SyncAndroidViewport(*viewport) + if viewport.ready == 0 || viewport.width <= 0 || viewport.height <= 0 { + viewport.x = 0; viewport.y = 0 + viewport.width = width; viewport.height = height + } + zoom := AndroidLayoutZoom() + AndroidTouchSetZoom(zoom) + bounds := Rectangle.{cast(float32)viewport.x / zoom, + cast(float32)viewport.y / zoom, cast(float32)viewport.width / zoom, + cast(float32)viewport.height / zoom} + if !AndroidNativeEnsurePixels(viewport.x + viewport.width, + viewport.y + viewport.height) || !PixmapScale(zoom, zoom) || + !PixmapResumeInto(viewport.x + viewport.width, viewport.y + viewport.height, + AndroidNativePixels(), true) { AndroidNativeLog("Android pixmap surface failed"); return false } + // These VM frames replay their paint; the caller clears their canvas. + AndroidNativeFill(cast(u32)0xff000000) + ClearAndroidFrame(viewport, cast(u32)0xfff8fafc) + AndroidBundleMediaTick(*host.media, host.media_slot) + AndroidTextInputBeginFrame(session) + if !AndroidTouchFrameInputBegin(session, zoom) { + AndroidNativeLog("Android frame input failed") + PixmapEndInto() + return false + } + + key := AndroidTouchTakeKey() + if AndroidTextInputKeyPressed(259) { key = 259 } + if AndroidTextInputKeyPressed(257) { key = 257 } + codepoint := AndroidTextInputCharacter() + while codepoint != 0 { + Player.PlayerTyped(*host.player, codepoint) + codepoint = AndroidTextInputCharacter() + } + pointer := PollPointer() + secondary := PollSecondaryPointer() + host.frame_reuse = host.reuse + host.frames += 1 + input.* = Player.Input.{ + .width = cast(s32)bounds.width, .height = cast(s32)bounds.height, + .x = pointer.x - bounds.x, .y = pointer.y - bounds.y, + .down = pointer.down, .pressed = pointer.pressed, + .released = pointer.released, .secondary_down = secondary.down, + .secondary_pressed = secondary.pressed, + .secondary_released = secondary.released, .key = key} + return true +} + +// Swaps the active bundle to a selected file when it is valid. +AndroidBundleSwapTo :: (path: string, input_session: Session) { + incoming := AndroidBundleRead(path) + candidate_index := 1 - android_bundle_active + candidate := *android_bundle_hosts[candidate_index] + accepted := incoming.count > 0 && AndroidBundleOpen(candidate, incoming, + *android_bundle_hosts[android_bundle_active]) + if accepted { + active := *android_bundle_hosts[android_bundle_active] + old_session := ifx active.hosted then active.app.app.session else input_session + AndroidTextInputClose(old_session) + AndroidBundleClose(active) + AndroidBundleFree(android_bundle_data[android_bundle_active]) + android_bundle_data[android_bundle_active] = "" + android_bundle_data[candidate_index] = incoming + android_bundle_active = candidate_index + new_session := ifx candidate.hosted then candidate.app.app.session else input_session + AndroidTextInputOpen(new_session) + AndroidBundleResult(true) + } else { + AndroidBundleClose(candidate) + active := *android_bundle_hosts[android_bundle_active] + unused AndroidBundleImagesRegister(*active.images, + ifx active.media_slot == 0 then 384 else 512) + AndroidBundleFree(incoming) + print("kryon: selected ZX is invalid or needs unavailable services\n") + AndroidBundleResult(false) + } +} + +AndroidBundleRunHosted :: (input_session: Session) -> s32 { ok := true first_frame := true reuse := false @@ -309,39 +419,12 @@ AndroidBundleRunMain :: () -> s32 { selected: [4096]u8 path := AndroidBundleTakeFile(selected[:]) - if path.count > 0 { - incoming := AndroidBundleRead(path) - candidate_index := 1 - android_bundle_active - candidate := *android_bundle_hosts[candidate_index] - accepted := incoming.count > 0 && AndroidBundleOpen(candidate, incoming, - *android_bundle_hosts[android_bundle_active]) - if accepted { - active := *android_bundle_hosts[android_bundle_active] - old_session := ifx active.hosted then active.app.app.session else input_session - AndroidTextInputClose(old_session) - AndroidBundleClose(active) - AndroidBundleFree(android_bundle_data[android_bundle_active]) - android_bundle_data[android_bundle_active] = "" - android_bundle_data[candidate_index] = incoming - android_bundle_active = candidate_index - new_session := ifx candidate.hosted then candidate.app.app.session else input_session - AndroidTextInputOpen(new_session) - AndroidBundleResult(true) - } else { - AndroidBundleClose(candidate) - active := *android_bundle_hosts[android_bundle_active] - unused AndroidBundleImagesRegister(*active.images, - ifx active.media_slot == 0 then 384 else 512) - AndroidBundleFree(incoming) - print("kryon: selected ZX is invalid or needs unavailable services\n") - AndroidBundleResult(false) - } - } + if path.count > 0 { AndroidBundleSwapTo(path, input_session) } width: s32 height: s32 active := *android_bundle_hosts[android_bundle_active] - session := ifx active.hosted then active.app.app.session else input_session + session := active.app.app.session paused := AndroidNativePaused() || !AndroidNativeWindowReady() || !AndroidNativeSurfaceSize(*width, *height) if paused { @@ -371,7 +454,7 @@ AndroidBundleRunMain :: () -> s32 { cast(float32)viewport.y / zoom, cast(float32)viewport.width / zoom, cast(float32)viewport.height / zoom} AndroidTextInputBeginFrame(session) - ok = AndroidBundleDraw(active, session, viewport, bounds, zoom, reuse) + ok = AndroidBundleDraw(active, session, viewport, bounds, zoom) AndroidTextInputFrame(session, active.player.keyboard) if ok && first_frame { first_frame = false @@ -390,6 +473,74 @@ AndroidBundleRunMain :: () -> s32 { return ifx ok && !active.player.failed then 0 else 1 } +// The portable bundle runs its own event loop inside PlayerRun; the wait +// callback above prepares each frame. A file selection ends that loop and +// the runner swaps the selected bundle in. +AndroidBundleRunPortable :: (input_session: Session) -> s32 { + ok := true + while ok && !AndroidNativeDestroyRequested() { + host := *android_bundle_hosts[android_bundle_active] + host.text_session = input_session + host.frames = 0 + host.reuse = false + host.frame_reuse = false + host.quiet_frames = 0 + host.was_paused = false + host.first_pending = true + host.next_frame_ms = Clock.MonotonicMilliseconds() + host.swap_pending = false + ok = Player.PlayerRun(*host.player) + if !ok { + // The VM failed inside a prepared frame; release its bracketing. + FrameInputEnd(input_session) + AndroidTouchFrameEnd() + PixmapEndInto() + unused AndroidJniFinishActivity() + break + } + if host.swap_pending { + AndroidBundleSwapTo(TextFromBytes(host.selected[0:host.selected_count]), + input_session) + continue + } + break + } + return ifx ok && !android_bundle_hosts[android_bundle_active].player.failed then 0 else 1 +} + +AndroidBundleRunMain :: () -> s32 { + AndroidNativeLog("Android portable host starting") + AndroidJniKeepHostThread() + defer { AndroidJniReleaseHostThread() } + AndroidProcessPrepare() + + input_session := SessionOpen() + if !SessionValid(input_session) { AndroidNativeLog("Android input session failed"); return 1 } + defer { CloseSession(input_session) } + AndroidTextInputOpen(input_session) + defer { AndroidTextInputClose(input_session) } + + android_bundle_data[0] = AndroidBundleRead("app.zx") + if android_bundle_data[0].count == 0 { AndroidNativeLog("Android app.zx asset is missing"); return 1 } + defer { + AndroidBundleClose(*android_bundle_hosts[0]) + AndroidBundleClose(*android_bundle_hosts[1]) + AndroidBundleFree(android_bundle_data[0]) + AndroidBundleFree(android_bundle_data[1]) + android_bundle_data[0] = "" + android_bundle_data[1] = "" + android_bundle_active = 0 + } + android_bundle_hosts[0].media_slot = 0 + android_bundle_hosts[1].media_slot = 1 + if !AndroidBundleOpen(*android_bundle_hosts[0], android_bundle_data[0]) { AndroidNativeLog("Android app.zx failed to open"); return 1 } + + if android_bundle_hosts[android_bundle_active].hosted { + return AndroidBundleRunHosted(input_session) + } + return AndroidBundleRunPortable(input_session) +} + #program_export android_main :: (app: *NativeAndroidApp) { if app == null { return } diff --git a/src/backend/android_run.zi b/src/backend/android_run.zi index 157c18c9d..a68f27b72 100644 --- a/src/backend/android_run.zi +++ b/src/backend/android_run.zi @@ -14,7 +14,6 @@ #import "android_process" #import "android_surface" #import "android_touch" - #import "frame_entry" #import "frame_texture_android" #import "std/byte_text_linux" #import "drawing_props" @@ -41,9 +40,23 @@ using FrameStatus; + App :: #import "app_types"; + android_log :: #system_library "log"; AndroidLogWrite :: (priority: s32, tag: *u8, text: *u8) -> s32 #foreign android_log "__android_log_write"; + // The program's main. Generated sources bind it to the selected entry + // module's `main`; the program opens its window through kryon/app, whose + // Android branch hands the frame callback back to this host. + host_api :: #system_library "host_api"; + AndroidProgramMain :: () -> s32 #foreign host_api; + + active_draw: App.Draw; + + AndroidUseDraw :: (draw: App.Draw) { + active_draw = draw + } + AndroidError :: (message: string) -> s32 { output: [256]u8 length: s32 = cast(s32)message.count @@ -149,11 +162,8 @@ if BeginFrame(session, cast(u64)1, bounds) != cast(FrameStatus)FrameOk { AndroidFrameFailure(session, "the frame could not begin") ok = false - } else if Frame(session, bounds) != 0 { - unused AndroidError("kryon: the application's frame failed") - TreeCancel(session) - ok = false } else { + App.CallDraw(active_draw, session.slot, session.epoch, bounds) // Compose against the last presented pixels; route changes // may capture them before the queued paint replaces them. if !reuse { @@ -219,7 +229,14 @@ AndroidJniKeepHostThread() defer { AndroidJniReleaseHostThread() } AndroidProcessPrepare() + // The program's main opens its window through kryon/app, which runs + // the frame loop below on this activity thread. + unused AndroidProgramMain() + } + // The Android frame loop App.Run runs: the session, the widget tree's + // frames, input, IME, damage presentation and pacing. + AndroidFrameLoop :: () { session: Session = SessionOpen() if !SessionValid(session) { unused AndroidError("kryon: could not open a UI session") diff --git a/src/backend/app.zi b/src/backend/app.zi index 6c19b3b9c..f76871613 100644 --- a/src/backend/app.zi +++ b/src/backend/app.zi @@ -5,16 +5,28 @@ // in the checked program. using Types :: #import "app_types"; -#if TARGET == .C && OS == .WINDOWS || TARGET == .C && OS == .LINUX && !#defined(KRYON_NO_DESKTOP_HOST) { +#if TARGET == .C && OS == .ANDROID || TARGET == .C && #defined(ANDROID_BUILD) || TARGET == .C && #defined(PLATFORM_ANDROID) || TARGET == .C && #defined(__ANDROID__) { + Bare :: #import "app_unsupported"; + Frames :: #import "frames_android"; +} else #if TARGET == .C && OS == .WINDOWS || TARGET == .C && OS == .LINUX && !#defined(KRYON_NO_DESKTOP_HOST) { Bare :: #import "desktop_window"; Frames :: #import "frames_desktop"; +} else #if TARGET == .C && #defined(KRYON_DOM) { + Bare :: #import "app_unsupported"; + Frames :: #import "frames_dom"; } else #if TARGET == .C && OS == .WEB { Bare :: #import "page_window"; Frames :: #import "frames_web"; } else #if TARGET == .ZX { // The installed desktop player hosts a bundle's window. Bare :: #import "zx_window"; - Frames :: #import "app_unsupported"; + Frames :: #import "frames_zx"; +} else #if TARGET == .C && #defined(KRYON_TERMINAL) { + Bare :: #import "app_unsupported"; + Frames :: #import "frames_terminal"; +} else #if TARGET == .C && #defined(KRYON_PIXMAP) { + Bare :: #import "app_unsupported"; + Frames :: #import "frames_pixmap"; } else { Bare :: #import "app_unsupported"; Frames :: #import "app_unsupported"; diff --git a/src/backend/application_entry.zi b/src/backend/application_entry.zi deleted file mode 100644 index c31336fcd..000000000 --- a/src/backend/application_entry.zi +++ /dev/null @@ -1,17 +0,0 @@ -// Process-entry adapter for applications with a custom frame lifecycle. -// The application exports KryonApplicationMain; the selected host supplies -// arguments on native targets and an empty command line in a browser. -application_host :: #system_library "host_api"; -KryonApplicationMain :: (argc: s32, argv: **u8) -> s32 #foreign application_host; - -#if #defined(PLATFORM_WEB) { - #program_export - main :: () -> s32 { - return KryonApplicationMain(0, null) - } -} else { - #program_export - main :: (argc: s32, argv: **u8) -> s32 { - return KryonApplicationMain(argc, argv) - } -} diff --git a/src/backend/bundle_player.zi b/src/backend/bundle_player.zi index 94f62bd60..958bebd0f 100644 --- a/src/backend/bundle_player.zi +++ b/src/backend/bundle_player.zi @@ -21,11 +21,16 @@ Input :: struct { down: bool; pressed: bool; released: bool; secondary_down: bool; secondary_pressed: bool; secondary_released: bool; modifiers: s32; key: s32; wheel: float32; + closed: bool } PlayerEditorPresent :: #type (context: *void, identity: u64, value: string, cursor: s32, anchor: s32, flags: s32) -> void; PlayerEditorRequest :: #type (context: *void, identity: u64, output: []u8) -> TextRequest; +// Prepares one frame's input: presents the previous frame, waits for the +// frame budget, and fills the window events and size. Returning false ends +// the bundle's loop. +PlayerWait :: #type (context: *void, input: *Input) -> bool; Player :: struct { - fields: [13]HostField; names: [27]Name; bindings: [128]HostBinding; + fields: [14]HostField; names: [29]Name; bindings: [128]HostBinding; bundle: *void; instance: *void; input: Input; codepoints: [256]s32; typed_count: s32; typed_at: s32; platform: HostCall; context: *void; closed: bool; keyboard: bool; @@ -40,9 +45,12 @@ Player :: struct { editor_request_bytes: [65536]u8 editor_fields: [5]HostField renderer_active: bool + wait: PlayerWait + wait_context: *void + wait_ready: bool } Supported :: (module: string, function: string) -> bool { - if ModuleName(module,"zx_run") { return function=="ReadBundleInput" || function=="TakeBundleCodepoint" || function=="BundleTextInputHost" || function=="BundleFrameFinishedHost" || function=="BundleFrameCursorHost" || function=="BundleFrameReusableHost" || function=="BundleTextEditorHost" || function=="BundleTextRequestHost" } + if ModuleName(module,"frames_zx") { return function=="ReadBundleInput" || function=="TakeBundleCodepoint" || function=="BundleTextInputHost" || function=="BundleFrameFinishedHost" || function=="BundleFrameCursorHost" || function=="BundleFrameReusableHost" || function=="BundleTextEditorHost" || function=="BundleTextRequestHost" } if ModuleName(module,"font_metrics") { return function=="MeasureGlyphWidth" || function=="MeasureGlyphLineHeight" } if ModuleName(module,"raster_text") { return function=="RasterText" || function=="RasterTextClipped" || function=="RasterTextRotated" } if ModuleName(module,"raster_shape") { return function=="RasterRoundedRectangle" || function=="RasterRoundedRectangleOutline" } @@ -125,13 +133,18 @@ PlayerCall :: (context: *void, module_name: *u8, function_name: *u8, result.kind = HostInteger; result.integer = 0; return 1 } if function=="ReadBundleInput" && count==0 { + ok := !player.closed && player.wait_ready && player.wait != null + player.typed_count = 0; player.typed_at = 0 + if ok { ok = player.wait(player.wait_context, *player.input) } + if !ok { player.closed = true } input:=player.input player.fields[0].value.integer = cast(s64)input.width; player.fields[1].value.integer = cast(s64)input.height player.fields[2].value.real = cast(float64)input.x; player.fields[3].value.real = cast(float64)input.y player.fields[4].value.integer = cast(s64)input.down; player.fields[5].value.integer = cast(s64)input.pressed; player.fields[6].value.integer = cast(s64)input.released player.fields[7].value.integer = cast(s64)input.secondary_down; player.fields[8].value.integer = cast(s64)input.secondary_pressed; player.fields[9].value.integer = cast(s64)input.secondary_released player.fields[10].value.integer = cast(s64)input.modifiers; player.fields[11].value.integer = cast(s64)input.key; player.fields[12].value.real = cast(float64)input.wheel - result.kind = HostRecord; result.type_name = *player.names[26].bytes[0]; result.fields = *player.fields[0]; result.field_count = cast(usize)13; return 1 + player.fields[13].value.integer = cast(s64)player.closed + result.kind = HostRecord; result.type_name = *player.names[28].bytes[0]; result.fields = *player.fields[0]; result.field_count = cast(usize)14; return 1 } if function=="TakeBundleCodepoint" && count==0 { result.kind = HostInteger @@ -239,34 +252,31 @@ PlayerUseRenderer :: (player: *Player, renderer: HostCall, context: *void) -> bo return true } -// The caller opens and presents its normal platform frame around this call. +// Selects who prepares each frame's input. Without a wait callback the +// bundle's loop stops before its first frame. #program_export -PlayerFrameNative :: (player: *Player, input: Input) -> bool { - if player.instance == null || player.closed || !player.renderer_active || - input.width <= 0 || input.height <= 0 { return false } - player.input = input - player.typed_at = 0 +PlayerUseWait :: (player: *Player, wait: PlayerWait, context: *void) -> bool { + if player.bundle == null || wait == null { return false } + player.wait = wait + player.wait_context = context + player.wait_ready = true + return true +} + +// Runs the bundle's main once. The bundle's own loop reads one frame's +// input through the wait callback at a time and returns when the callback +// ends it; the caller presents each finished frame's pixels there. +#program_export +PlayerRun :: (player: *Player) -> bool { + if player.instance == null || player.closed || !player.wait_ready { return false } result: s64 has_result: s32 player.failed = RunBundleInstance(player.instance, *result, *has_result) == 0 - ok := !player.failed && (has_result == 0 || result == 0) + ok := !player.failed + if ok && has_result != 0 && result != 0 { player.closed = true } player.typed_count = 0 - if !ok { player.closed = true } return ok } -#if !#defined(BUNDLE_NATIVE_RENDERER) { - #program_export - PlayerFrame :: (player: *Player, input: Input, width: s32, height: s32, pixels: []u32) -> bool { - if player.instance==null || player.closed || input.width<=0 || input.height<=0 { return false } - if !PixmapScale(cast(float32)width/cast(float32)input.width,cast(float32)height/cast(float32)input.height) || !PixmapBeginInto(4279242768,width,height,pixels,true) { return false } - player.input = input; player.typed_at = 0 - result: s64; has_result: s32 - ok:=RunBundleInstance(player.instance,*result,*has_result)!=0 && (has_result==0 || result==0) - player.typed_count = 0; PixmapEndInto() - if !ok { player.closed = true }; return ok - } - -} // Optional native editor callbacks belong to this player instance only. PlayerUseTextEditor :: (player: *Player, present: PlayerEditorPresent, diff --git a/src/backend/bundle_player_shared.zi b/src/backend/bundle_player_shared.zi index 4bb3cd5ca..985bdb4b4 100644 --- a/src/backend/bundle_player_shared.zi +++ b/src/backend/bundle_player_shared.zi @@ -70,7 +70,7 @@ InputField :: (player: *Player, index: s32, name: string, return true } PrepareInput :: (player: *Player) -> bool { - return CopyCString("BundleInput", player.names[26].bytes[:]) && + return CopyCString("BundleInput", player.names[28].bytes[:]) && InputField(player, 0, "width", "s32", HostInteger) && InputField(player, 1, "height", "s32", HostInteger) && InputField(player, 2, "x", "float32", HostReal) && @@ -83,7 +83,8 @@ PrepareInput :: (player: *Player) -> bool { InputField(player, 9, "secondary_released", "bool", HostInteger) && InputField(player, 10, "modifiers", "s32", HostInteger) && InputField(player, 11, "key", "s32", HostInteger) && - InputField(player, 12, "wheel", "float32", HostReal) + InputField(player, 12, "wheel", "float32", HostReal) && + InputField(player, 13, "closed", "bool", HostInteger) } #if !#defined(BUNDLE_NATIVE_RENDERER) { diff --git a/src/backend/canvas_run.zi b/src/backend/canvas_run.zi deleted file mode 100644 index ef4ce7dc5..000000000 --- a/src/backend/canvas_run.zi +++ /dev/null @@ -1,81 +0,0 @@ -#if OS == .WEB && !#defined(KRYON_HOSTED_UI) { -#import "secondary_pointer" -#import "frame_snapshot" -#import "frame_entry" -#import "canvas_host" -#import "canvas_frame" -#import "geometry" -#import "session" -#import "tree" -#import "tree_draw" -#import "tree_input" - -using FrameStatus; - -libc :: #system_library "libc"; -CanvasWrite :: (fd: s32, input: *u8, count: usize) -> isize #foreign libc "write"; - -CanvasError :: (message: string) -> s32 { - output: [256]u8 - length: s32 = cast(s32)message.count - if length > 254 { length = 254 } - index: s32 = 0 - while index < length { - output[index] = message[index] - index += 1 - } - output[index] = cast(u8)10 - CanvasWrite(2, *output[0], cast(usize)(length + 1)) - return 1 -} - -DrawCanvasFrame :: (session: Session, viewport: Rectangle) -> bool { - if !CanvasFrameInputBegin(session) { return false } - defer { FrameInputEnd(session) } - BeginCanvasFrame() - pointer: PointerFrame = PollPointer() - TreePointerUpdate(session, pointer) - TreeSecondaryPointerUpdate(session, PollSecondaryPointer()) - PointerWheelSend(session, pointer.x, pointer.y, CanvasWheelMove()) - CanvasSampleScroll(session, pointer, CanvasWheelMove()) - if BeginFrame(session, cast(u64)1, viewport) != cast(FrameStatus)FrameOk { - EndCanvasFrame() - return false - } - if Frame(session, viewport) != 0 { - TreeCancel(session) - EndCanvasFrame() - return false - } - if EndCanvasUiFrame(session) != cast(FrameStatus)FrameOk { - EndCanvasFrame() - return false - } - CanvasCursor(session) - return EndCanvasFrame() -} - -#program_export -main :: () -> s32 { - if !OpenCanvas() { - CloseCanvas() - return CanvasError("kryon: could not open the browser canvas") - } - session: Session = SessionOpen() - if !SessionValid(session) { - CloseCanvas() - return CanvasError("kryon: could not open a UI session") - } - ok: bool = true - while ok && PollCanvas() { - key, modifiers := CanvasInputTake(session) - KeyboardModifiersSend(session, modifiers) - if key != 0 { KeyboardSend(session, key) } - ok = DrawCanvasFrame(session, CanvasViewport()) - } - CloseSession(session) - CloseCanvas() - if ok { return 0 } - return CanvasError("kryon: browser frame rendering failed") -} -} diff --git a/src/backend/desktop_loop.zi b/src/backend/desktop_loop.zi index 277d6d78b..979bd6412 100644 --- a/src/backend/desktop_loop.zi +++ b/src/backend/desktop_loop.zi @@ -1,8 +1,8 @@ // The desktop frame loop every desktop host runs: the window's events, the -// app's frame and presenting. desktop_run is the default host; a program can -// pass its frame directly to Run. A host that runs frames registers the -// widget tree's frame driver first (TreeFrameUse, see frame_driver); without -// one the window only clears and presents. +// app's frame and presenting. A program's main passes its frame to App.Run +// (kryon/app), whose frames_desktop host calls Run. A host that runs frames +// registers the widget tree's frame driver first (TreeFrameUse, see +// frame_driver); without one the window only clears and presents. #import "secondary_pointer" #import "desktop_accessibility" #import "cairo_raster" diff --git a/src/backend/desktop_run.zi b/src/backend/desktop_run.zi deleted file mode 100644 index c0c024db6..000000000 --- a/src/backend/desktop_run.zi +++ /dev/null @@ -1,46 +0,0 @@ -// The default desktop host: the app's frames in a 960x600 window. -Desktop :: #import "desktop_loop"; -#import "frame_entry" -#import "tree_frame" -#import "desktop_theme" -#if OS == .LINUX { - using Access :: #import "desktop_accessibility_linux"; -} - -#if #defined(KRYON_TEST_DRIVER) { - Inspect :: #import "test_driver_engine"; - Theme :: #import "theme"; - Env :: #import "std/environment_linux"; - Raster :: #import "cairo_raster"; - Titles :: #import "program_title"; - - RunPreview :: (path: string) -> s32 { - theme_bytes: [8]u8 - scratch: [16]u8 - theme := Env.EnvironmentRead("KRYON_PREVIEW_THEME", theme_bytes[:]).value - width := Env.EnvironmentRange("KRYON_PREVIEW_WIDTH", 1, 4096, scratch[:]) - height := Env.EnvironmentRange("KRYON_PREVIEW_HEIGHT", 1, 4096, scratch[:]) - if Env.EnvironmentRead("SDL_VIDEODRIVER", scratch[:]).value != "dummy" || - !Raster.CaptureRequested() || (theme != "light" && theme != "dark") || - !width.is_ok || !height.is_ok { - return Desktop.DesktopError("kryon: invalid headless capture settings; use kryon preview") - } - unused Theme.InstallDefaultTheme(theme == "dark", true) - return Desktop.RunTitled(Frame, cast(s32)width.value, cast(s32)height.value, Titles.ProgramTitle(), - .{.background = DesktopThemeBackground}, .{.tree = Inspect.TestDriverWriteTree, .path = path}) - } -} - -#program_export -main :: () -> s32 { - unused TreeFrameUse() - #if #defined(KRYON_TEST_DRIVER) { - path_bytes: [4096]u8 - path := Env.EnvironmentRead("KRYON_PREVIEW_TREE", path_bytes[:]) - if path.is_ok { return RunPreview(path.value) } - } - #if OS == .LINUX { - Access.DesktopAccessibilityUse() - } - return Desktop.Run(Frame, appearance = .{.background = DesktopThemeBackground}) -} diff --git a/src/backend/desktop_zx.zi b/src/backend/desktop_zx.zi index 8571d9cf8..4f3cf004f 100644 --- a/src/backend/desktop_zx.zi +++ b/src/backend/desktop_zx.zi @@ -48,8 +48,8 @@ PlayerReadlink :: (path: *u8, output: *u8, count: u64) -> s64 #foreign libc "rea Name :: struct { bytes: [128]u8 } Player :: struct { editor_fields: [5]HostField - fields: [13]HostField - names: [27]Name + fields: [14]HostField + names: [29]Name // A raw bundle has no UI session; this one receives the window's ordered // keys and text, and the bundle reads one key and its modifiers a frame. input: Session @@ -57,6 +57,14 @@ Player :: struct { modifiers: s32 media: BundleMedia closed: bool + // The bundle owns its event loop. Between its frames the player finishes + // the previous one, paces, and takes the window's next events; the input + // record's stop flag ends the loop. + frames: s32 + ui: bool + reload_due: bool + reload_at: s64 + watch_path: string } Names :: #import "bundle_names"; @@ -72,7 +80,7 @@ Supported :: (module: string, function: string) -> bool { function == "VideoSeekHost" || function == "VideoSpeedHost" || function == "VideoVolumeHost" || function == "VideoLeaseHost" || function == "VideoFrameHost" || function == "VideoMessageHost" } - if ModuleName(module, "zx_run") { + if ModuleName(module, "frames_zx") { return function == "ReadBundleInput" || function == "TakeBundleCodepoint" || function == "BundleTextInputHost" || function == "BundleFrameFinishedHost" || function == "BundleFrameReusableHost" || function == "BundleFrameCursorHost" || @@ -263,6 +271,38 @@ PlayerCall :: (context: *void, module_name: *u8, function_name: *u8, } } if function == "ReadBundleInput" && count == 0 { + ok := true + // Between frames: finish the previous one, then pace and take the + // window's next events. A capture renders two frames and stops. + if player.frames > 0 { + ok = EndDesktopFrame() + if ok && !CaptureRequested() { PauseDesktop() } + } + if ok && !CaptureRequested() { ok = PollDesktop() } + if ok && CaptureRequested() && player.frames >= 2 { ok = false } + if ok && !CaptureRequested() && player.watch_path != "" { + now := MonotonicMilliseconds() + if now >= player.reload_at { + player.reload_at = now + 1000 + player.reload_due = true + ok = false + } + } + if !ok { + player.closed = true + player.fields[13].value.integer = 1 + result.kind = HostRecord + result.type_name = *player.names[28].bytes[0] + result.fields = *player.fields[0] + result.field_count = cast(usize)14 + return 1 + } + key, modifiers := DesktopInputTake(player.input) + player.key = key + player.modifiers = modifiers + BundleMediaTick(*player.media) + BeginDesktopFrame() + SetRasterBackground(BundleThemeBackground) viewport := DesktopViewport() pointer := PollPointer() secondary := PollSecondaryPointer() @@ -280,10 +320,12 @@ PlayerCall :: (context: *void, module_name: *u8, function_name: *u8, player.fields[11].value.integer = cast(s64)player.key player.key = 0 player.fields[12].value.real = cast(float64)DesktopWheelMove() + player.fields[13].value.integer = 0 + player.frames += 1 result.kind = HostRecord - result.type_name = *player.names[26].bytes[0] + result.type_name = *player.names[28].bytes[0] result.fields = *player.fields[0] - result.field_count = cast(usize)13 + result.field_count = cast(usize)14 return 1 } if function == "TakeBundleCodepoint" && count == 0 { @@ -432,15 +474,14 @@ BundleThemeBackground :: (refresh: bool) -> u32 { return UiTheme.CurrentBackground() } -RunFrame :: (instance: *void, player: *Player) -> bool { - BundleMediaTick(*player.media) - BeginDesktopFrame() - SetRasterBackground(BundleThemeBackground) +// Runs the bundle's main once. A UI bundle's main is its whole event loop; +// it returns when the window closed or a frame failed. +RunUIBundle :: (instance: *void, player: *Player) -> bool { result: s64 has_result: s32 if RunBundleInstance(instance, *result, *has_result) == 0 { return false } if has_result != 0 && result != 0 { player.closed = true } - return EndDesktopFrame() + return true } CollectBindings :: (bundle: *void, player: *Player, grants: []HostBinding, @@ -452,6 +493,7 @@ CollectBindings :: (bundle: *void, player: *Player, grants: []HostBinding, module_name := TextFromCString(module) function_name := TextFromCString(function) binding := HostBinding.{.module = module, .function = function} + if ModuleName(module_name, "frames_zx") { player.ui = true } if Supported(module_name, function_name) { binding.call = PlayerCall binding.context = cast(*void)player @@ -712,6 +754,7 @@ RunFrameBundle :: (bundle_path: string, opened_bundle: *void, check: bool, } player: Player player.media.bundle = bundle + player.watch_path = pointer_path instance, ok := OpenInstance(bundle, *player, grants, check) if check { return ifx ok then 0 else 1 } if !ok { @@ -727,12 +770,11 @@ RunFrameBundle :: (bundle_path: string, opened_bundle: *void, check: bool, ok = ExtractAssets(bundle, assets_root) && ChangeDirectory(*temporary[0]) == 0 } } - // Kryon's frame host (zx_run) and a Frame export are drawn each frame. - // Any other entry is a program: it runs once and prints its result, as - // `ziran run` does for a console bundle. - program := !ModuleName(TextFromCString(BundleEntryModule(bundle)), "zx_run") && - TextFromCString(BundleEntryFunction(bundle)) != "Frame" - if ok && !check && program { + // A UI bundle declares the frames_zx loop's host capabilities: its main + // runs the whole event loop and the player pumps the window between its + // frames. Any other entry is a program that runs once and prints its + // result, as `ziran run` does for a console bundle. + if !player.ui { result: s64 has_result: s32 ok = RunBundleInstance(instance, *result, *has_result) != 0 @@ -750,22 +792,18 @@ RunFrameBundle :: (bundle_path: string, opened_bundle: *void, check: bool, } if ok { if CaptureRequested() { - ok = RunFrame(instance, *player) - if ok && !player.closed { ok = RunFrame(instance, *player) } + ok = RunUIBundle(instance, *player) if ok { ok = CaptureConfigured() } } else { - next_check: s64 - while ok && !player.closed && PollDesktop() { - key, modifiers := DesktopInputTake(player.input) - player.key = key - player.modifiers = modifiers - now := MonotonicMilliseconds() - if pointer_path != "" && now >= next_check { - next_check = now + 1000 + running := true + while ok && running { + ok = RunUIBundle(instance, *player) + if ok && player.reload_due { + player.reload_due = false Reload(pointer_path, *current, *bundle, *instance, *player, *assets_root, temporary[:]) + } else { + running = false } - ok = RunFrame(instance, *player) - if ok { PauseDesktop() } } } } diff --git a/src/backend/frame_entry.zi b/src/backend/frame_entry.zi deleted file mode 100644 index 1390f6aad..000000000 --- a/src/backend/frame_entry.zi +++ /dev/null @@ -1,10 +0,0 @@ -// The project build binds this capability to the selected source module. -#import "session" -#import "geometry" - -host_api :: #system_library "host_api"; -ProjectFrame :: (session: Session, viewport: Rectangle) -> s32 #foreign host_api; - -Frame :: (session: Session, viewport: Rectangle) -> s32 { - return ProjectFrame(session, viewport) -} diff --git a/src/backend/frames_android.zi b/src/backend/frames_android.zi new file mode 100644 index 000000000..66f0ee0a4 --- /dev/null +++ b/src/backend/frames_android.zi @@ -0,0 +1,12 @@ +// The Android frame loop App.Run runs: NativeActivity's window and frames. +App :: #import "app_types"; +Android :: #import "android_run"; + +// Runs the program's frames on the activity's own thread until the activity +// is destroyed. The window fills the screen; Android owns its size. +Run :: (window: App.Window, draw: App.Draw) -> s32 { + unused window + Android.AndroidUseDraw(draw) + Android.AndroidFrameLoop() + return 0 +} diff --git a/src/backend/frames_desktop.zi b/src/backend/frames_desktop.zi index e35b968e3..b80798444 100644 --- a/src/backend/frames_desktop.zi +++ b/src/backend/frames_desktop.zi @@ -9,6 +9,29 @@ using Geometry :: #import "geometry"; #if OS == .LINUX { using Access :: #import "desktop_accessibility_linux"; } +#if #defined(KRYON_TEST_DRIVER) { + Inspect :: #import "test_driver_engine"; + Theme :: #import "theme"; + Env :: #import "std/environment_linux"; + Raster :: #import "cairo_raster"; + Titles :: #import "program_title"; + + RunPreview :: (path: string) -> s32 { + theme_bytes: [8]u8 + scratch: [16]u8 + theme := Env.EnvironmentRead("KRYON_PREVIEW_THEME", theme_bytes[:]).value + width := Env.EnvironmentRange("KRYON_PREVIEW_WIDTH", 1, 4096, scratch[:]) + height := Env.EnvironmentRange("KRYON_PREVIEW_HEIGHT", 1, 4096, scratch[:]) + if Env.EnvironmentRead("SDL_VIDEODRIVER", scratch[:]).value != "dummy" || + !Raster.CaptureRequested() || (theme != "light" && theme != "dark") || + !width.is_ok || !height.is_ok { + return Desktop.DesktopError("kryon: invalid headless capture settings; use kryon preview") + } + unused Theme.InstallDefaultTheme(theme == "dark", true) + return Desktop.RunTitled(DrawFrame, cast(s32)width.value, cast(s32)height.value, Titles.ProgramTitle(), + .{.background = DesktopThemeBackground}, .{.tree = Inspect.TestDriverWriteTree, .path = path}) + } +} active_draw: App.Draw; @@ -24,10 +47,15 @@ Run :: (window: App.Window, draw: App.Draw) -> s32 { #if OS == .LINUX { Access.DesktopAccessibilityUse() } + active_draw = draw + #if #defined(KRYON_TEST_DRIVER) { + path_bytes: [4096]u8 + path := Env.EnvironmentRead("KRYON_PREVIEW_TREE", path_bytes[:]) + if path.is_ok { return RunPreview(path.value) } + } width := window.width height := window.height if width <= 0 { width = 960 } if height <= 0 { height = 600 } - active_draw = draw return Desktop.RunTitled(DrawFrame, width, height, window.title, .{.background = DesktopThemeBackground}) } diff --git a/src/backend/dom_run.zi b/src/backend/frames_dom.zi similarity index 75% rename from src/backend/dom_run.zi rename to src/backend/frames_dom.zi index abb319caf..9187aead8 100644 --- a/src/backend/dom_run.zi +++ b/src/backend/frames_dom.zi @@ -1,15 +1,19 @@ +// The DOM page's frame loop App.Run runs: the browser document host, +// sessions and the widget tree. +App :: #import "app_types"; Dom :: #import "dom"; Web :: #import "std/web"; #import "dom_tree" #import "dom_metrics" #import "dom_raster" -#import "frame_entry" -#import "geometry" +using SessionModule :: #import "session"; +using Geometry :: #import "geometry"; #import "paint_queue" -#import "session" #import "tree" #import "tree_draw" +active_draw: App.Draw; + DomError :: (reason: string) -> s32 { scope := Web.WebScope() defer Web.WebEnd(scope) @@ -18,8 +22,9 @@ DomError :: (reason: string) -> s32 { return 1 } -#program_export -main :: () -> s32 { +// Runs the program's frames in the page until it closes. +Run :: (window: App.Window, draw: App.Draw) -> s32 { + unused window if !DomTreeOpen() { return DomError("Kryon DOM could not open the document") } defer DomTreeClose() if !DomMetricsOpen() { return DomError("Kryon DOM could not open browser font metrics") } @@ -27,16 +32,14 @@ main :: () -> s32 { session := SessionOpen() if !SessionValid(session) { return DomError("Kryon DOM could not open a UI session") } defer { unused CloseSession(session) } + active_draw = draw while !Dom.dom_close_requested { DomTreeInput(session) viewport := DomViewport() if BeginFrame(session, cast(u64)1, viewport) != FrameStatus.FrameOk { return DomError(FrameFailureAt(session).message) } - if Frame(session, viewport) != 0 { - TreeCancel(session) - return DomError("Kryon DOM application Frame returned an error") - } + App.CallDraw(active_draw, session.slot, session.epoch, viewport) if CommitFrame(session) != FrameStatus.FrameOk { return DomError(FrameFailureAt(session).message) } diff --git a/src/backend/pixmap_run.zi b/src/backend/frames_pixmap.zi similarity index 56% rename from src/backend/pixmap_run.zi rename to src/backend/frames_pixmap.zi index 3f7996962..6d6c8858b 100644 --- a/src/backend/pixmap_run.zi +++ b/src/backend/frames_pixmap.zi @@ -1,34 +1,34 @@ -#import "session" -#import "frame_entry" -#import "geometry" +// The headless raster frame loop App.Run runs: two retained frames (the +// second after any layout the first settled) and the second as a PPM image: +// +// kryon run shot > frame.ppm +App :: #import "app_types"; +using SessionModule :: #import "session"; +using Geometry :: #import "geometry"; #import "pixmap" #import "tree" #import "tree_draw" using FrameStatus; -// Runs the application headlessly for two frames, the second after any -// layout the first settled, and prints that frame as a PPM image: -// -// kryon run shot > frame.ppm -#program_export -main :: () -> s32 { +active_draw: App.Draw; + +// Runs the program's frames headlessly and prints the second as a PPM image. +Run :: (window: App.Window, draw: App.Draw) -> s32 { + unused window session: Session = SessionOpen() if !SessionValid(session) { return 1 } defer { PixmapCloseWorkers(); CloseSession(session) } viewport: Rectangle = Rectangle.{0.0, 0.0, cast(float32)PixmapWidth, cast(float32)PixmapHeight} + active_draw = draw frame: s32 = 0 while frame < 2 { PixmapBegin(cast(u32)PixmapBackground) if BeginFrame(session, cast(u64)1, viewport) != cast(FrameStatus)FrameOk { return 1 } - result: s32 = Frame(session, viewport) - if result != 0 { - TreeCancel(session) - return result - } + App.CallDraw(active_draw, session.slot, session.epoch, viewport) if EndFrame(session) != cast(FrameStatus)FrameOk { return 1 } frame += 1 } diff --git a/src/backend/terminal_run.zi b/src/backend/frames_terminal.zi similarity index 92% rename from src/backend/terminal_run.zi rename to src/backend/frames_terminal.zi index 36fef3b36..cc6e84bc0 100644 --- a/src/backend/terminal_run.zi +++ b/src/backend/frames_terminal.zi @@ -1,7 +1,9 @@ +// The terminal frame loop App.Run runs: the application's frames on the +// alternate screen, keyed input and presentation. +App :: #import "app_types"; #import "byte_text_linux" -#import "session" -#import "frame_entry" -#import "geometry" +using SessionModule :: #import "session"; +using Geometry :: #import "geometry"; #import "terminal" #import "terminal_keys" #import "tree" @@ -31,6 +33,8 @@ TerminalState :: struct { original: [128]u8 } +active_draw: App.Draw; + WriteControl :: (value: string) -> bool { bytes: [64]u8 if value.count > 64 { return false } @@ -75,19 +79,16 @@ LeaveTerminal :: (state: *TerminalState) { state.active = false } -// The application supplies Frame(session, viewport). The Kryon host owns -// entry, screen storage, rendering effects, and presentation. +// The application's draw builds the frame. The terminal host owns entry, +// screen storage, rendering effects, and presentation. RenderFrame :: (session: Session, viewport: Rectangle, interactive: bool) -> s32 { TerminalBegin(80, 24) if BeginFrame(session, cast(u64)1, viewport) != cast(FrameStatus)FrameOk { return 1 } - result: s32 = Frame(session, viewport) - if result != 0 { - TreeCancel(session) - return result - } + App.CallDraw(active_draw, session.slot, session.epoch, viewport) + result: s32 = 0 if EndFrame(session) != cast(FrameStatus)FrameOk { result = 1 } if result == 0 && interactive && !WriteControl("\x1b[2J\x1b[H") { result = 1 @@ -96,8 +97,10 @@ RenderFrame :: (session: Session, viewport: Rectangle, interactive: bool) -> s32 return result } -#program_export -main :: () -> s32 { +// Runs the program's frames in the terminal until it closes. The window's +// title and size are the host terminal's own; the loop keys on raw input. +Run :: (window: App.Window, draw: App.Draw) -> s32 { + unused window session: Session = SessionOpen() if !SessionValid(session) { return 1 } viewport: Rectangle = Rectangle.{0.0, 0.0, 80.0, 24.0} @@ -107,6 +110,7 @@ main :: () -> s32 { CloseSession(session) return 1 } + active_draw = draw result: s32 = RenderFrame(session, viewport, interactive) if interactive { input: TerminalPollDescriptor diff --git a/src/backend/frames_zx.zi b/src/backend/frames_zx.zi new file mode 100644 index 000000000..f5ed4b305 --- /dev/null +++ b/src/backend/frames_zx.zi @@ -0,0 +1,182 @@ +// The portable frame loop App.Run runs inside a ZX bundle: the bundle owns +// its loop and reads one window event record a frame, while the reusable +// player owns the window, pacing and pixels. +App :: #import "app_types"; +#import "geometry" +using SessionModule :: #import "session"; +#import "tree" +#import "tree_draw" +#import "frame_motion" +MotionClock :: #import "clock"; +#import "tree_input" +#import "cursor" +#import "widget_kind" +using WidgetKind; +#import "text_host" +#import "text_request" +#import "text_input_platform" +Clock :: #import "frame_clock"; + +host_api :: #system_library "host_api"; +BundleInput :: struct { + width: s32 + height: s32 + x: float32 + y: float32 + down: bool + pressed: bool + released: bool + secondary_down: bool + secondary_pressed: bool + secondary_released: bool + modifiers: s32 + key: s32 + wheel: float32 + // The player set this frame's stop flag: the window closed or the + // scripted run finished. Run leaves the loop after presenting it. + closed: bool +} +ReadBundleInput :: () -> BundleInput #foreign host_api; +TakeBundleCodepoint :: () -> s32 #foreign host_api; +BundleTextInputHost :: (focused: bool) #foreign host_api; +// The frame's resolved cursor: the host applies it before the next frame. +BundleFrameCursorHost :: (shape: s32, asset_path: string, width: s32, + height: s32, hotspot_x: s32, hotspot_y: s32, hidden: bool) #foreign host_api; +BundleFrameFinishedHost :: (unchanged: bool) #foreign host_api; +BundleFrameReusableHost :: () -> bool #foreign host_api; +BundleTextEditorHost :: (identity: u64, value: string, cursor: s32, + anchor: s32, flags: s32) #foreign host_api; +BundleTextRequestHost :: (identity: u64) -> TextRequest #foreign host_api; + +using FrameStatus; + +active_draw: App.Draw; +bundle_session: Session; +bundle_started: bool; +bundle_activity: Clock.FrameActivity; +bundle_last_x: float32; bundle_last_y: float32; +bundle_last_width: s32; bundle_last_height: s32; bundle_last_modifiers: s32; + +bundle_editor_identity: u64; +bundle_editor_bytes: [65536]u8; +bundle_editor_count: s32; +bundle_editor_cursor: s32; +bundle_editor_anchor: s32; +bundle_editor_flags: s32; + +BundleEditorPresent :: (session: Session, index: s32, value: string, + cursor: s32, anchor: s32, secure: bool, numeric: bool, read_only: bool, + edited: bool) { + if !TextInputOwnerMatches(bundle_session, session) { return } + node := TreeSubmittedNodeAt(session, index) + if read_only || !node.selected || node.disabled || !node.has_text || + value.count > bundle_editor_bytes.count { return } + for at: 0..value.count - 1 { bundle_editor_bytes[at] = value[at] } + bundle_editor_count = cast(s32)value.count + bundle_editor_identity = node.identity_generation + // On an edit frame the caller still owns the preceding value. Native + // editors defer acknowledgement until the next value is submitted. + bundle_editor_cursor = ifx edited then 0 else cursor + bundle_editor_anchor = ifx edited then 0 else anchor + bundle_editor_flags = (ifx secure then 1 else 0) | (ifx numeric then 2 else 0) | + (ifx node.kind == WidgetKindTextArea then 4 else 0) | (ifx edited then 8 else 0) +} + +BundleEditorRequest :: () { + request := BundleTextRequestHost(bundle_editor_identity) + if !request.pending || bundle_editor_identity == 0 { return } + for index: cast(s32)1..TreeCount(bundle_session) - 1 { + node := TreeNodeAt(bundle_session, index) + if node.identity_generation == bundle_editor_identity && node.selected && + TreeInputAllowedAt(bundle_session, index) && + (!TreeHasFocus(bundle_session) || TreeFocusedAt(bundle_session, index)) { + unused TextRequestSend(bundle_session, index, request.value, + request.replace, request.cursor, request.anchor) + return + } + } +} + +// Runs the program's frames in the player's window until the player closes +// it. A bundle frame's result reaches the player through the finished-host +// call; a failed frame closes the window instead of returning a status. +Run :: (window: App.Window, draw: App.Draw) -> s32 { + unused window + if !bundle_started { + bundle_session = SessionOpen() + if !SessionValid(bundle_session) { return 1 } + bundle_started = true + TextHostInstall(BundleEditorPresent) + } + active_draw = draw + result: s32 = 0 + running := true + while running { + BundleEditorRequest() + bundle_editor_identity = 0 + bundle_editor_count = 0 + bundle_editor_cursor = 0; bundle_editor_anchor = 0; bundle_editor_flags = 0 + input := ReadBundleInput() + if input.closed { break } + active := input.down || input.pressed || input.released || + input.secondary_down || input.secondary_pressed || input.secondary_released || + input.key != 0 || input.wheel != 0.0 || + input.x != bundle_last_x || input.y != bundle_last_y || + input.width != bundle_last_width || input.height != bundle_last_height || + input.modifiers != bundle_last_modifiers + bundle_last_x = input.x; bundle_last_y = input.y + bundle_last_width = input.width; bundle_last_height = input.height + bundle_last_modifiers = input.modifiers + viewport := Rectangle.{0.0, 0.0, + cast(float32)input.width, cast(float32)input.height} + pointer := PointerFrame.{input.x, input.y, input.down, + input.pressed, input.released} + secondary := SecondaryPointerFrame.{input.secondary_down, + input.secondary_pressed, input.secondary_released} + TreePointerUpdate(bundle_session, pointer) + TreeSecondaryPointerUpdate(bundle_session, secondary) + PointerWheelSend(bundle_session, input.x, input.y, input.wheel) + KeyboardModifiersSend(bundle_session, input.modifiers) + if input.key != 0 { KeyboardSend(bundle_session, input.key) } + codepoint := TakeBundleCodepoint() + while codepoint != 0 { + active = true + TypedCodepointSend(bundle_session, codepoint) + codepoint = TakeBundleCodepoint() + } + SetFrameMotionTime(bundle_session, cast(float64)MotionClock.Milliseconds() / 1000.0) + if BeginFrame(bundle_session, cast(u64)1, viewport) != cast(FrameStatus)FrameOk { + return 1 + } + App.CallDraw(active_draw, bundle_session.slot, bundle_session.epoch, viewport) + finished := EndFrameRetained(bundle_session, BundleFrameReusableHost(), Clock.Observe(*bundle_activity, active)) + if finished.status != cast(FrameStatus)FrameOk { return 1 } + // A platform sees only committed, still-focused field identities. + if bundle_editor_identity != 0 { + found := false + for index: cast(s32)1..TreeCount(bundle_session) - 1 { + node := TreeNodeAt(bundle_session, index) + if node.identity_generation == bundle_editor_identity && node.selected && + TreeInputAllowedAt(bundle_session, index) && + (!TreeHasFocus(bundle_session) || TreeFocusedAt(bundle_session, index)) { + found = true + // Reopening an OS keyboard needs a fresh hit on the actual + // committed guest field, including clipping/overlay routing. + if input.pressed && TreeHitAt(bundle_session, input.x, input.y) == index { + bundle_editor_flags = bundle_editor_flags | 16 + } + break + } + } + if !found { bundle_editor_identity = 0; bundle_editor_count = 0; bundle_editor_cursor = 0; bundle_editor_anchor = 0 } + } + BundleTextEditorHost(bundle_editor_identity, TextView(bundle_editor_bytes[:bundle_editor_count]), + bundle_editor_cursor, bundle_editor_anchor, bundle_editor_flags) + BundleFrameFinishedHost(finished.paint_unchanged) + props := CursorResolve(bundle_session, TreeCursor(bundle_session)) + BundleFrameCursorHost(props.shape, props.asset_path, props.width, props.height, + props.hotspot_x, props.hotspot_y, props.hidden) + BundleTextInputHost(TreeTextInputActive(bundle_session)) + } + return result +} diff --git a/src/backend/pixmap_gles.zi b/src/backend/pixmap_gles.zi index c4f89454b..653042555 100644 --- a/src/backend/pixmap_gles.zi +++ b/src/backend/pixmap_gles.zi @@ -59,12 +59,13 @@ target: u32; width: s32; height: s32; failed: bool; -seen_revision: u64; present_width: s32; present_height: s32; presented: bool; images: [P.PixmapImageLimit]u32; image_revisions: [P.PixmapImageLimit]u64; +image_widths: [P.PixmapImageLimit]s32; +image_heights: [P.PixmapImageLimit]s32; staging: Vec(u32); no_flush: PixmapGpuFlushCall; @@ -89,27 +90,50 @@ DropImage :: (slot: s64) { image_revisions[slot] = 0 } -ImageTexture :: (slot: s32) -> u32 { - if slot < 0 || slot >= P.PixmapImageLimit { return 0 } - if images[slot] != 0 { return images[slot] } - image_width := P.pixmap_image_widths[slot]; image_height := P.pixmap_image_heights[slot] - count := cast(s64)image_width * image_height - // Staging keeps the capacity of its largest upload, which a smaller image - // reuses. A bound below that capacity would refuse the smaller image and - // drop the whole presenter to software. - limit := ifx staging.capacity > count then staging.capacity else count - if image_width <= 0 || image_height <= 0 || count > P.PixmapSourceCount(slot) || - !VecResizeBounded(staging, count, limit) { return 0 } +// Premultiplies COUNT pixels of SLOT into staging. Opaque and empty pixels +// skip the arithmetic, and an animated figure is almost entirely one of them. +Premultiply :: (slot: s32, count: s64) { for index: 0..count - 1 { pixel := P.PixmapSourcePixel(slot, index); alpha := pixel >> 24 + if alpha == 255 { staging[index] = pixel; continue } + if alpha == 0 { staging[index] = 0; continue } red := ((pixel >> 16) & cast(u32)255) * alpha / cast(u32)255 green := ((pixel >> 8) & cast(u32)255) * alpha / cast(u32)255 blue := (pixel & cast(u32)255) * alpha / cast(u32)255 staging[index] = (alpha << 24) | (red << 16) | (green << 8) | blue } - id := NewTexture(image_width, image_height, cast(*void)*staging[0]) - if id != 0 { images[slot] = id; image_revisions[slot] = P.pixmap_image_revisions[slot] } - return id +} + +// One texture per image slot. A changed revision refills the existing +// texture, so an animated image never reallocates GPU storage; only a real +// size change drops it. +ImageTexture :: (slot: s32) -> u32 { + if slot < 0 || slot >= P.PixmapImageLimit { return 0 } + image_width := P.pixmap_image_widths[slot]; image_height := P.pixmap_image_heights[slot] + count := cast(s64)image_width * image_height + if image_width <= 0 || image_height <= 0 || count > P.PixmapSourceCount(slot) { return 0 } + revision := P.pixmap_image_revisions[slot] + if images[slot] != 0 { + if image_revisions[slot] == revision { return images[slot] } + if image_widths[slot] != image_width || image_heights[slot] != image_height { DropImage(slot) } + } + // Staging keeps the capacity of its largest upload, which a smaller image + // reuses. A bound below that capacity would refuse the smaller image and + // drop the whole presenter to software. + limit := ifx staging.capacity > count then staging.capacity else count + if !VecResizeBounded(staging, count, limit) { return 0 } + Premultiply(slot, count) + if images[slot] == 0 { + images[slot] = NewTexture(image_width, image_height, cast(*void)*staging[0]) + if images[slot] == 0 { return 0 } + } else { + G.BindTexture(Texture2DTarget, images[slot]) + UploadRectangle(Texture2DTarget, 0, 0, 0, image_width, image_height, + Rgba, ByteType, cast(*void)*staging[0]) + } + image_widths[slot] = image_width; image_heights[slot] = image_height + image_revisions[slot] = revision + return images[slot] } Flush :: () { unused Draw() } @@ -187,13 +211,7 @@ Draw :: () -> bool { Rgba, ByteType, cast(*void)*pixmap_gpu_staged[upload.start]) } if pixmap_gpu_batches.count > 0 { - revision := P.PixmapImageRevision() - if revision != seen_revision { - seen_revision = revision - for slot: 0..images.count - 1 { - if images[slot] != 0 && image_revisions[slot] != P.pixmap_image_revisions[slot] { DropImage(slot) } - } - } + P.PixmapSyncBitmaps() // The composition is drawn straight into the window surface; the // offscreen target is only the snapshot Read() publishes. G.BindFramebuffer(0x8ca9, 0) @@ -272,6 +290,9 @@ Close :: (current: bool) { } VecFree(staging) program = 0; vertices = 0; atlas = 0; framebuffer = 0; target = 0 - width = 0; height = 0; seen_revision = 0; failed = false + width = 0; height = 0; failed = false + for slot: 0..image_widths.count - 1 { + image_widths[slot] = 0; image_heights[slot] = 0 + } present_width = 0; present_height = 0; presented = false } diff --git a/src/backend/zx_run.zi b/src/backend/zx_run.zi deleted file mode 100644 index 7c8c31304..000000000 --- a/src/backend/zx_run.zi +++ /dev/null @@ -1,171 +0,0 @@ -// One retained frame of a portable application. The reusable native player -// owns the window; widgets, layout and state execute in the bundle instance. -#import "frame_entry" -#import "geometry" -#import "session" -#import "tree" -#import "tree_draw" -#import "frame_motion" -MotionClock :: #import "clock"; -#import "tree_input" -#import "cursor" -#import "widget_kind" -#import "text_host" -#import "text_request" -#import "text_input_platform" -Clock :: #import "frame_clock"; - -host_api :: #system_library "host_api"; -BundleInput :: struct { - width: s32 - height: s32 - x: float32 - y: float32 - down: bool - pressed: bool - released: bool - secondary_down: bool - secondary_pressed: bool - secondary_released: bool - modifiers: s32 - key: s32 - wheel: float32 -} -ReadBundleInput :: () -> BundleInput #foreign host_api; -TakeBundleCodepoint :: () -> s32 #foreign host_api; -BundleTextInputHost :: (focused: bool) #foreign host_api; -// The frame's resolved cursor: the host applies it before the next frame. -BundleFrameCursorHost :: (shape: s32, asset_path: string, width: s32, - height: s32, hotspot_x: s32, hotspot_y: s32, hidden: bool) #foreign host_api; -BundleFrameFinishedHost :: (unchanged: bool) #foreign host_api; -BundleFrameReusableHost :: () -> bool #foreign host_api; -BundleTextEditorHost :: (identity: u64, value: string, cursor: s32, - anchor: s32, flags: s32) #foreign host_api; -BundleTextRequestHost :: (identity: u64) -> TextRequest #foreign host_api; - -using FrameStatus; -using WidgetKind; -bundle_session: Session; -bundle_started: bool; -bundle_activity: Clock.FrameActivity; -bundle_last_x: float32; bundle_last_y: float32; -bundle_last_width: s32; bundle_last_height: s32; bundle_last_modifiers: s32; - -bundle_editor_identity: u64; -bundle_editor_bytes: [65536]u8; -bundle_editor_count: s32; -bundle_editor_cursor: s32; -bundle_editor_anchor: s32; -bundle_editor_flags: s32; - -BundleEditorPresent :: (session: Session, index: s32, value: string, - cursor: s32, anchor: s32, secure: bool, numeric: bool, read_only: bool, - edited: bool) { - if !TextInputOwnerMatches(bundle_session, session) { return } - node := TreeSubmittedNodeAt(session, index) - if read_only || !node.selected || node.disabled || !node.has_text || - value.count > bundle_editor_bytes.count { return } - for at: 0..value.count - 1 { bundle_editor_bytes[at] = value[at] } - bundle_editor_count = cast(s32)value.count - bundle_editor_identity = node.identity_generation - // On an edit frame the caller still owns the preceding value. Native - // editors defer acknowledgement until the next value is submitted. - bundle_editor_cursor = ifx edited then 0 else cursor - bundle_editor_anchor = ifx edited then 0 else anchor - bundle_editor_flags = (ifx secure then 1 else 0) | (ifx numeric then 2 else 0) | - (ifx node.kind == WidgetKindTextArea then 4 else 0) | (ifx edited then 8 else 0) -} - -BundleEditorRequest :: () { - request := BundleTextRequestHost(bundle_editor_identity) - if !request.pending || bundle_editor_identity == 0 { return } - for index: cast(s32)1..TreeCount(bundle_session) - 1 { - node := TreeNodeAt(bundle_session, index) - if node.identity_generation == bundle_editor_identity && node.selected && - TreeInputAllowedAt(bundle_session, index) && - (!TreeHasFocus(bundle_session) || TreeFocusedAt(bundle_session, index)) { - unused TextRequestSend(bundle_session, index, request.value, - request.replace, request.cursor, request.anchor) - return - } - } -} - -#program_export -main :: () -> s32 { - if !bundle_started { - bundle_session = SessionOpen() - if !SessionValid(bundle_session) { return 1 } - bundle_started = true - TextHostInstall(BundleEditorPresent) - } - BundleEditorRequest() - bundle_editor_identity = 0 - bundle_editor_count = 0 - bundle_editor_cursor = 0; bundle_editor_anchor = 0; bundle_editor_flags = 0 - input := ReadBundleInput() - active := input.down || input.pressed || input.released || - input.secondary_down || input.secondary_pressed || input.secondary_released || - input.key != 0 || input.wheel != 0.0 || - input.x != bundle_last_x || input.y != bundle_last_y || - input.width != bundle_last_width || input.height != bundle_last_height || - input.modifiers != bundle_last_modifiers - bundle_last_x = input.x; bundle_last_y = input.y - bundle_last_width = input.width; bundle_last_height = input.height - bundle_last_modifiers = input.modifiers - viewport := Rectangle.{0.0, 0.0, - cast(float32)input.width, cast(float32)input.height} - pointer := PointerFrame.{input.x, input.y, input.down, - input.pressed, input.released} - secondary := SecondaryPointerFrame.{input.secondary_down, - input.secondary_pressed, input.secondary_released} - TreePointerUpdate(bundle_session, pointer) - TreeSecondaryPointerUpdate(bundle_session, secondary) - PointerWheelSend(bundle_session, input.x, input.y, input.wheel) - KeyboardModifiersSend(bundle_session, input.modifiers) - if input.key != 0 { KeyboardSend(bundle_session, input.key) } - codepoint := TakeBundleCodepoint() - while codepoint != 0 { - active = true - TypedCodepointSend(bundle_session, codepoint) - codepoint = TakeBundleCodepoint() - } - SetFrameMotionTime(bundle_session, cast(float64)MotionClock.Milliseconds() / 1000.0) - if BeginFrame(bundle_session, cast(u64)1, viewport) != cast(FrameStatus)FrameOk { - return 1 - } - result := Frame(bundle_session, viewport) - if result != 0 { - TreeCancel(bundle_session) - return result - } - finished := EndFrameRetained(bundle_session, BundleFrameReusableHost(), Clock.Observe(*bundle_activity, active)) - if finished.status != cast(FrameStatus)FrameOk { return 1 } - // A platform sees only committed, still-focused field identities. - if bundle_editor_identity != 0 { - found := false - for index: cast(s32)1..TreeCount(bundle_session) - 1 { - node := TreeNodeAt(bundle_session, index) - if node.identity_generation == bundle_editor_identity && node.selected && - TreeInputAllowedAt(bundle_session, index) && - (!TreeHasFocus(bundle_session) || TreeFocusedAt(bundle_session, index)) { - found = true - // Reopening an OS keyboard needs a fresh hit on the actual - // committed guest field, including clipping/overlay routing. - if input.pressed && TreeHitAt(bundle_session, input.x, input.y) == index { - bundle_editor_flags = bundle_editor_flags | 16 - } - break - } - } - if !found { bundle_editor_identity = 0; bundle_editor_count = 0; bundle_editor_cursor = 0; bundle_editor_anchor = 0 } - } - BundleTextEditorHost(bundle_editor_identity, TextView(bundle_editor_bytes[:bundle_editor_count]), - bundle_editor_cursor, bundle_editor_anchor, bundle_editor_flags) - BundleFrameFinishedHost(finished.paint_unchanged) - props := CursorResolve(bundle_session, TreeCursor(bundle_session)) - BundleFrameCursorHost(props.shape, props.asset_path, props.width, props.height, - props.hotspot_x, props.hotspot_y, props.hidden) - BundleTextInputHost(TreeTextInputActive(bundle_session)) - return 0 -} diff --git a/src/project/cli_linux.zi b/src/project/cli_linux.zi index 9df015b16..03585fb80 100644 --- a/src/project/cli_linux.zi +++ b/src/project/cli_linux.zi @@ -398,8 +398,8 @@ Usage :: () -> s32 { PreviewUsage :: () -> s32 { PrintFd(1, "usage: kryon preview FIXTURE --theme light|dark --width PX[,PX...] --height PX --output FILE.png|PREFIX [--profile NAME]\n") PrintFd(1, " Builds previews/FIXTURE.zi once and writes PNG and JSON. Multiple widths append -PX to the prefix.\n") - PrintFd(1, " The fixture exports Frame; it imports the module that draws the screen, never the entry\n") - PrintFd(1, " module that exports the app's own Frame. To shoot the app itself: kryon run --png FILE.png\n") + PrintFd(1, " The fixture is a program: its main runs App.Run with the module that draws the screen\n") + PrintFd(1, " as the frame. To shoot the app itself: kryon run --png FILE.png\n") return 0 } @@ -592,13 +592,13 @@ PreviewCapture :: (prefix: string, width: string, height: string, args: []string } // Build under the preview lock on the first capture only. if args[5] == "build" { - if RunChild(args) != 0 { return Error(failure) } + if RunChild(args[0:23]) != 0 { return Error(failure) } args[5] = "run-built" } - if RunChild(args) != 0 { return Error(failure) } + if RunChild(args[0:23]) != 0 { return Error(failure) } if !Exists(staged_tree) || !PreviewPngSizeMatches(*staged_png_bytes[0], PreviewDimension(width), PreviewDimension(height)) { - return Error("no widget tree and PNG of the requested size were drawn; export Frame from the entry") + return Error("no widget tree and PNG of the requested size were drawn; the entry's main must run App.Run from kryon/app") } if !CString(parent, parent_bytes[:]) { return Error("preview output directory is too long") } publish_lock := PreviewLockDirectory(*parent_bytes[0]) @@ -626,9 +626,9 @@ PreviewRun :: (options: PreviewOptions, profile: ProjectProfile, args: []string) return Error("the capture output must name a file or prefix") } area := ifx options.fixture == "" then "build/shot" else "build/preview" - failure := "preview build or render failed; see diagnostics above, add previews to [package] module_roots, export Frame from the fixture and import the drawing module, not the entry that exports Frame" + failure := "preview build or render failed; see diagnostics above, add previews to [package] module_roots, and give the fixture a main that runs App.Run with its drawing module" if options.fixture == "" { - failure = "run --png build or render failed; see diagnostics above and export Frame from the project entry" + failure = "run --png build or render failed; see diagnostics above and give the project entry a main that runs App.Run" } build_root_bytes: [4096]u8 @@ -644,7 +644,7 @@ PreviewRun :: (options: PreviewOptions, profile: ProjectProfile, args: []string) } args[5] = "build" args[22] = Join("PROJECT_BUILD_DIR=", build_root, build_option_bytes[:]) - args[23] = "PROJECT_CAPTURE=1" // Render Frame even for a program entry. + // Slot 23 stays reserved for the watch command; captures run slots 0..22. if args[22] == "" { return Error("capture build directory is too long") } mkdir: [4]string = .["mkdir", "-p", "--", build_root] if RunChild(mkdir[:]) != 0 { return Error("cannot create the capture build directory") } diff --git a/templates/app/src/app.zi b/templates/app/src/app.zi index 8891fdc3a..9d90bacd1 100644 --- a/templates/app/src/app.zi +++ b/templates/app/src/app.zi @@ -8,6 +8,7 @@ // kryon run shot --png build/shot.png --width 390 --height 844 --theme dark // kryon run tui the same interface in a terminal // kryon run web a Canvas2D browser page (needs Emscripten) +App :: #import "kryon/app"; Button :: #import "kryon/button"; Card :: #import "kryon/card"; Checkbox :: #import "kryon/checkbox"; @@ -28,13 +29,14 @@ started: bool; dark: bool; no_menu: []Dropdown.Option; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport // Start in the mode the host chose: the system's, or kryon run --theme. if !started { dark = Theme.CurrentTheme().dark; StartTasks(); started = true } unused ApplyLook(dark) screen := Layout.Draw(session, Layout.Props.{.bounds = viewport}) - if !screen.opened { return 0 } + if !screen.opened { return } AppBar(session) body := Layout.Draw(session, Layout.Props.{ .gap = Layout.Gap(.ThemeMetricSpace3), .gap_override = true, @@ -49,7 +51,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { unused End(session) } unused End(session) - return 0 + return } // The app bar: the title, and a dark mode switch at its right. @@ -86,3 +88,5 @@ Line :: (session: Session, text: string, role: Theme.ThemeMetricRole) { LineHeight :: (role: Theme.ThemeMetricRole) -> float32 { return Theme.CurrentThemeMetric(role) * 1.4 } + +main :: () -> s32 { return App.Run(App.Window.{.title = "{{name}}"}, Frame) } diff --git a/templates/pages/src/app.zi b/templates/pages/src/app.zi index e8a328e40..edf669cc6 100644 --- a/templates/pages/src/app.zi +++ b/templates/pages/src/app.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Checkbox :: #import "kryon/checkbox"; ListBox :: #import "kryon/list_box"; @@ -121,8 +122,9 @@ Settings :: (session: Session, page: *PageLayout) { if changed.changed { show_authors = changed.checked } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page: PageLayout = PageFor(viewport, 560.0) Label(session, "{{name}}", NextRow(*page, 36.0), FontSize(*page, 28)) tabs: Rectangle = NextRow(*page, 40.0) @@ -132,5 +134,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if current == PageHome { Home(session, *page) } if current == PageLibrary { Library(session, *page) } if current == PageSettings { Settings(session, *page) } - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "{{name}}"}, Frame) } diff --git a/templates/tui/src/app.zi b/templates/tui/src/app.zi index 9bc48e62b..2102a81bf 100644 --- a/templates/tui/src/app.zi +++ b/templates/tui/src/app.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; ListBox :: #import "kryon/list_box"; using Layout :: #import "layout"; #import "kryon/geometry" @@ -37,8 +38,9 @@ Start :: () { tasks[5].label = "Install it with kryon install" } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport if !started { Start(); started = true } move: s32 = 0 key: s32 = KeyboardTake(session) @@ -92,5 +94,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Label(session, "Up/Down move Space toggles Ctrl+C quits", NextRow(*page, 22.0), FontSize(*page, 14)) - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "{{name}}"}, Frame) } diff --git a/templates/web/src/app.zi b/templates/web/src/app.zi index 6e8c3f05a..3b7ad7f10 100644 --- a/templates/web/src/app.zi +++ b/templates/web/src/app.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Link :: #import "kryon/link"; Text :: #import "kryon/text"; @@ -31,8 +32,9 @@ WebLink :: (session: Session, text: string, url: string, bounds: Rectangle) { .link = url}) } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport page: PageLayout = PageFor(viewport, 640.0) Heading(session, "{{name}}", 1, NextRow(*page, 44.0), FontSize(*page, 34)) Paragraph(session, "This page is a Kryon application. The same Ziran source runs as semantic HTML, on a canvas, and in a desktop window.", @@ -55,5 +57,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { digits: [16]u8 Paragraph(session, Joined(FormatInteger(cast(s64)likes, digits[:]), " likes so far", likes_text[:]), NextRow(*page, 24.0), FontSize(*page, 16)) - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "{{name}}"}, Frame) } diff --git a/tests/android_frame_input/android_frame_app.zi b/tests/android_frame_input/android_frame_app.zi index c16887b58..6d1ca1eff 100644 --- a/tests/android_frame_input/android_frame_app.zi +++ b/tests/android_frame_input/android_frame_app.zi @@ -1,4 +1,5 @@ -// The application the canonical Android host calls back each frame. +// The application frame the canonical Android host calls back each frame. +App :: #import "app_types"; #import "session" #import "geometry" #import "frame_snapshot" @@ -6,7 +7,6 @@ #import "android_touch" #import "paint_queue" -fail: bool; frames: s32; seen: FrameInputSnapshot; foreign_seen: bool; @@ -14,9 +14,8 @@ foreign: Session; pointer_matches: bool; paint_red: u8; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - unused viewport +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} frames += 1 seen = CaptureFrameInput(session) first := PollPointer() @@ -25,7 +24,5 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { first.pressed == seen.pointer.pressed && second.pressed == first.pressed && first.released == seen.pointer.released && second.released == first.released if CaptureFrameInput(foreign).available { foreign_seen = true } - if fail { return 1 } if paint_red != 0 { PaintRoundedFill(session, -1, .{10.0, 10.0, 12.0, 8.0}, 0.0, 0, .{paint_red, 80, 120, 255}) } - return 0 } diff --git a/tests/android_frame_input_test.sh b/tests/android_frame_input_test.sh index 4bc4af7e8..e01553873 100755 --- a/tests/android_frame_input_test.sh +++ b/tests/android_frame_input_test.sh @@ -17,7 +17,7 @@ for path in "$webp" "$avif" "$aom"; do done rm -f "$work/c"/*.c "$work/c"/*.h # Deterministic Android OS calls and events; no window system is contacted. -"$ziran" build --project --entry android_frame_input_test:main --bind frame_entry:ProjectFrame=android_frame_app:Frame --target=c --define ANDROID_BUILD --root "$repo/tests" --module-path "$repo/tests/android_frame_input" \ +"$ziran" build --project --entry android_frame_input_test:main --target=c --define ANDROID_BUILD --root "$repo/tests" --module-path "$repo/tests/android_frame_input" \ --module-path "$repo/tests" --no-main -o "$work/c" "$repo/tests/android_frame_input_test.zi" "$repo/tests/android_frame_input/android_frame_app.zi" "${CC:-cc}" -std=c11 -O1 -ffunction-sections -fdata-sections -I"$ziran_root/include" -I"$work/c" \ "$work/c"/*.c "$webp" "$avif" "$aom" "${ZIRAN_LIB:-$ziran_root/build/libziran.a}" \ diff --git a/tests/android_frame_input_test.zi b/tests/android_frame_input_test.zi index e2be1c188..59c07f784 100644 --- a/tests/android_frame_input_test.zi +++ b/tests/android_frame_input_test.zi @@ -136,6 +136,9 @@ main :: () -> s32 { AndroidNativeStart(*app) defer { AndroidNativeClose() } AndroidNativeOnCommand(*app, AndroidNativeCommandInitWindow) + // The frame loop calls the app's frames through kryon/app's Android + // branch; this test drives it through the same callback slot. + AndroidUseDraw(Probe.Frame) session := SessionOpen() defer { unused CloseSession(session) } Probe.foreign = SessionOpen() @@ -149,10 +152,8 @@ main :: () -> s32 { if CaptureFrameInput(session).available || presents == 0 || presented_open { return Failure(4) } if !Draw(session) || Probe.seen.keys[65] != cast(u8)FrameKeyHeld || Probe.seen.sequence <= first.sequence { return Failure(5) } - Probe.fail = true - if !Send(1, 1, 29) || Draw(session) { return Failure(6) } + if !Send(1, 1, 29) || !Draw(session) { return Failure(6) } if Probe.seen.keys[65] != cast(u8)FrameKeyReleased || CaptureFrameInput(session).available { return Failure(7) } - Probe.fail = false if !Send(1, 0, 29) || !Draw(session) { return Failure(8) } AndroidNativeOnCommand(*app, AndroidNativeCommandLostFocus) if !Draw(session) || Probe.seen.focused || Probe.seen.keys[65] != cast(u8)FrameKeyReleased { return Failure(9) } diff --git a/tests/android_source_generation_test.py b/tests/android_source_generation_test.py index dfddb8c0d..81653deee 100644 --- a/tests/android_source_generation_test.py +++ b/tests/android_source_generation_test.py @@ -121,28 +121,35 @@ def main(): custom = [] if kind == "native": entry.write_text('\n'.join([ + 'App :: #import "kryon/app";', '#import "kryon/session"', '#import "kryon/geometry"', '#import "std/thread_linux"', - '#program_export', - 'Frame :: (session: Session, viewport: Rectangle) -> s32 {', - ' unused session; unused viewport', - ' return ifx ThreadFinished(null) then 1 else 0', '}\n'])) + 'Frame :: (frame: App.Frame) {', + ' session := Session.{.slot = frame.slot, .epoch = frame.epoch}', + ' unused ThreadFinished(null)', + ' unused session', '}', + 'main :: () -> s32 { return App.Run(App.Window.{}, Frame) }\n'])) elif kind == "native-gles": entry.write_text('\n'.join([ - '#import "kryon/session"', '#import "kryon/geometry"', - '#import "kryon/android_egl"', '#program_export', - 'Frame :: (session: Session, viewport: Rectangle) -> s32 {', - ' unused session; unused viewport', + 'App :: #import "kryon/app";', + '#import "kryon/geometry"', + '#import "kryon/android_egl"', + 'Frame :: (frame: App.Frame) {', + ' unused frame', ' EnableAndroidGlesComposition()', - ' return 0', '}\n'])) + '}', + 'main :: () -> s32 { return App.Run(App.Window.{}, Frame) }\n'])) elif kind in PICTURE_MODES: codec = f'#import "kryon/android_{kind}"' if kind != "pictures" else "" entry.write_text('\n'.join([ + 'App :: #import "kryon/app";', '#import "kryon/session"', '#import "kryon/geometry"', - 'Image :: #import "kryon/image";', codec, '#program_export', - 'Frame :: (session: Session, viewport: Rectangle) -> s32 {', - ' Image.Draw(session, Image.Props.{ .key = 1, .bounds = viewport, .asset_path = "image.png" })', - ' return 0', '}\n'])) + 'Image :: #import "kryon/image";', codec, + 'Frame :: (frame: App.Frame) {', + ' session := Session.{.slot = frame.slot, .epoch = frame.epoch}', + ' Image.Draw(session, Image.Props.{ .key = 1, .bounds = frame.viewport, .asset_path = "image.png" })', + '}', + 'main :: () -> s32 { return App.Run(App.Window.{}, Frame) }\n'])) if kind in ("runtime", "runtime-gles", "runtime-gles-armv7"): enable_gles = kind in GLES_MODES (source / "main.zi").write_text( @@ -179,9 +186,9 @@ def main(): "--manifest", manifest, "--define", "ANDROID_BUILD", "--define", cpu_define, "--codegen", "zx" if kind == "zx" else "c99", *custom]) - adapter = ir / (identity + "_frame_entry.zir") - if adapter.is_file() != native_frame: - raise AssertionError(kind + " has the wrong native Frame adapter graph") + host_module = ir / (identity + "_android_run.zir") + if host_module.is_file() != (kind != "custom" and not kind.startswith("runtime")): + raise AssertionError(kind + " has the wrong Android program host graph") if native_frame and not (ir / "selected.zir").is_file(): raise AssertionError("selected native Frame provider was omitted") if kind == "native": diff --git a/tests/application_entry_test.sh b/tests/application_entry_test.sh deleted file mode 100644 index 5df789d5b..000000000 --- a/tests/application_entry_test.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -set -eu -repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) -. "$repo/tests/toolchain.sh" -work="$repo/build/scratch/application-entry" -mkdir -p "$work" -for platform in native web; do - define_args="" - if test "$platform" = web; then define_args="--define PLATFORM_WEB"; fi - "$ziran" ir --project --root "$repo/tests" $define_args -o "$work/$platform-ir" "$repo/tests/application_entry_test.zi" - for form in source saved; do - source="$repo/tests/application_entry_test.zi" - root="$repo/tests" - if test "$form" = saved; then - source="$work/$platform-ir/application_entry_test.zir" - root="$work/$platform-ir" - fi - output="$work/$platform-$form" - "$ziran" build --project --target=c --root "$root" $define_args -o "$output" "$source" - "${CC:-cc}" -std=c11 -O1 -I"$output" "$output"/*.c -o "$output/test" - "$output/test" 'first argument' --second - done -done -echo 'Application entry: native arguments and browser empty arguments passed from source and saved IR' diff --git a/tests/application_entry_test.zi b/tests/application_entry_test.zi deleted file mode 100644 index 1c36566a1..000000000 --- a/tests/application_entry_test.zi +++ /dev/null @@ -1,20 +0,0 @@ -#import "application_entry" -#import "std/byte_text_linux" - -#program_export "KryonApplicationMain" -TestApplication :: (argc: s32, argv: **u8) -> s32 { - #if #defined(PLATFORM_WEB) { - if argc != 0 || argv != null { - return 1 - } - } else { - if argc != 3 || argv == null { - return 2 - } - if TextFromCString(argv[1]) != "first argument" || - TextFromCString(argv[2]) != "--second" { - return 3 - } - } - return 0 -} diff --git a/tests/desktop_project_test.py b/tests/desktop_project_test.py index 7609efdae..c7e7e284f 100644 --- a/tests/desktop_project_test.py +++ b/tests/desktop_project_test.py @@ -102,6 +102,8 @@ def main(): "[overrides]\n" + "".join(f'{key} = "{value}"\n' for key, value in overrides.items()) ) (project / "src/app.zi").write_text( + 'App :: #import "kryon/app";\n' + '#import "Window"\n' 'Image :: #import "kryon/image";\n' 'Scroll :: #import "kryon/scroll";\n' 'Text :: #import "kryon/text";\n' @@ -114,8 +116,9 @@ def main(): '#import "kryon/tree_input"\n' 'scroll_offset: s32;\n' 'first_frame: bool = true;\n' - '#program_export\n' - 'Frame :: (session: Session, viewport: Rectangle) -> s32 {\n' + 'Frame :: (frame: App.Frame) {\n' + ' session := Session.{.slot = frame.slot, .epoch = frame.epoch}\n' + ' viewport := frame.viewport\n' ' if first_frame {\n' ' first_frame = false\n' ' if Env.EnvironmentText("THEME_PROBE_OVERRIDE") == "light" {\n' @@ -123,18 +126,18 @@ def main(): ' }\n' ' }\n' ' key: s32 = KeyboardTake(session)\n' - ' if key == 65 { return 1 }\n' + ' if key == 65 { WindowQuit(); return }\n' ' control: bool = (KeyboardModifiers(session) & KeyModifierControl) != 0\n' - ' if key == 83 && control { return 1 }\n' + ' if key == 83 && control { WindowQuit(); return }\n' ' typed: s32 = TypedCodepointTake(session)\n' - ' if typed == 122 || typed == 233 { return 1 }\n' - ' if PointerWheelTake(session, viewport) > 0.0 { return 1 }\n' - ' if SecondaryPointerSample(session).released { return 1 }\n' + ' if typed == 122 || typed == 233 { WindowQuit(); return }\n' + ' if PointerWheelTake(session, viewport) > 0.0 { WindowQuit(); return }\n' + ' if SecondaryPointerSample(session).released { WindowQuit(); return }\n' ' scroll := Scroll.Draw(session, .{.key = 80, .bounds = .{700.0, 10.0, 200.0, 150.0},\n' ' .content_height = 600, .scroll_offset = scroll_offset})\n' ' scroll_offset = scroll.scroll_offset\n' ' if scroll.opened { End(session) }\n' - ' if scroll_offset > 0 { return 1 }\n' + ' if scroll_offset > 0 { WindowQuit(); return }\n' ' image: Image.Props\n' ' image.key = cast(u64)1\n' ' image.bounds = Rectangle.{80.0, 80.0, 240.0, 240.0}\n' @@ -146,13 +149,12 @@ def main(): ' label.text = "gjpqy"\n' ' label.size = 40\n' ' Text.Draw(session, label)\n' - ' return 0\n}\n' + ' return\n}\n' + 'main :: () -> s32 { return App.Run(App.Window.{.title = "desktop_probe"}, Frame) }\n' ) solid_png(project / "red.png", 32, 32, (230, 30, 40, 255)) env = private_environment() env["XDG_CONFIG_HOME"] = str(project / "config") - # The frame-mode probe keeps its frame entry until phase 2 ports it. - env["KRYON_FRAME_ENTRY"] = "1" run([ZIRAN, "lock"], project, env) run([ZIRAN, "tool", "kryon", "build", "--profile", "desktop"], project, env) @@ -300,8 +302,8 @@ def main(): " subprocess.run(['xdotool', 'mousemove', '--window', " "window, '780', '70', 'click', '5'], check=True)\n" " stdout, stderr = app.communicate(timeout=10)\n" - " assert app.returncode == 1, (app.returncode, stdout, stderr)\n" - " assert 'desktop frame rendering failed' in stderr, stderr\n" + " assert app.returncode == 0, (app.returncode, stdout, stderr)\n" + " assert 'desktop frame rendering failed' not in stderr, stderr\n" "finally:\n" " if app.poll() is None:\n" " app.terminate()\n" diff --git a/tests/dom_profile_app.zi b/tests/dom_profile_app.zi index 4ef356cf7..3e8f0fc21 100644 --- a/tests/dom_profile_app.zi +++ b/tests/dom_profile_app.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Dom :: #import "kryon/dom"; Page :: #import "kryon/page"; @@ -27,6 +28,7 @@ CSS; started: bool; count: s32; +failed: s32; Save :: (session: Session) { if Button.Draw(session, .{key = 10, id = 31, class_name = 9, @@ -35,15 +37,16 @@ Save :: (session: Session) { } } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport if !started { - if !Dom.SetStyleSheet(css) { return 1 } + if !Dom.SetStyleSheet(css) { print("dom profile: the style sheet failed\n"); failed = 1; return } started = true } page := Page.Draw(session, .{key = 1, bounds = viewport, class_name = 7, title = "DOM widget profile"}) - if !page.opened { return 1 } + if !page.opened { return } Text.Draw(session, .{key = 2, text = "Browser widgets", semantic_kind = SemanticKind.SemanticHeading, heading_level = 2}) reordered := count > 0 @@ -57,7 +60,12 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { closing := viewport.width >= 700.0 viewport_label := ifx closing then "Closed" else ifx viewport.width >= 500.0 then "Wide" else "Narrow" Text.Draw(session, .{key = 5, text = viewport_label}) - if !Tree.End(session) { return 1 } + if !Tree.End(session) { print("dom profile: the tree did not finish\n"); failed = 2; return } if closing { Dom.RequestClose() } - return 0 +} + +main :: () -> s32 { + code := App.Run(App.Window.{.title = "DOM widget profile"}, Frame) + if failed != 0 { return failed } + return code } diff --git a/tests/dom_profile_test.sh b/tests/dom_profile_test.sh index 2c0638f5d..a1f35f9d0 100644 --- a/tests/dom_profile_test.sh +++ b/tests/dom_profile_test.sh @@ -46,8 +46,8 @@ copy_changed "$repo/tests/dom_profile_app.zi" "$project/src/app.zi" "$ziran" lock --offline "$ziran" tool kryon build --profile web test -s build/dom_profile-web.html - test -s build/generated/web/ir/*_dom_run.zir - test -s build/generated/web/c/*_dom_run.c + test -s build/generated/web/ir/*_app.zir + test -s build/generated/web/c/*_app.c ) # Profile socket names fit Chromium's Unix-domain socket path limit. diff --git a/tests/fixtures/rotated_text.zi b/tests/fixtures/rotated_text.zi index 532b1c744..f3724e68a 100644 --- a/tests/fixtures/rotated_text.zi +++ b/tests/fixtures/rotated_text.zi @@ -1,11 +1,13 @@ +App :: #import "kryon/app"; Text :: #import "kryon/text"; #import "kryon/geometry" #import "kryon/session" #import "std/web" #import "kryon/paint_queue" frames: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport unused viewport frames += 1 WebSet(WebGlobal,WebName("__fixtureFrames"),WebNumber(cast(float64)frames)) @@ -14,5 +16,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Text.Draw(session,Text.Props.{.key=cast(u64)11,.bounds=.{100.0,260.0,180.0,40.0}, .text="Horizontal",.size=32,.wrap=.TextWrapNone}) WebSet(WebGlobal,WebName("__fixturePaint"),WebNumber(cast(float64)PendingPaintCount(session))) - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "rotated_text"}, Frame) } diff --git a/tests/frame_entry_binding_test.py b/tests/frame_entry_binding_test.py deleted file mode 100644 index 138e026cc..000000000 --- a/tests/frame_entry_binding_test.py +++ /dev/null @@ -1,58 +0,0 @@ -"""Execute Kryon's selected Frame capability from source and saved IR.""" -from pathlib import Path -import tempfile - -from toolchain import ROOT, ZIRAN, ZIRAN_ROOT -from project_entry_test import run - - -def main(): - scratch = ROOT / 'build/scratch' - scratch.mkdir(parents=True, exist_ok=True) - with tempfile.TemporaryDirectory(prefix='frame-binding-', dir=scratch) as temporary: - project = Path(temporary) - host = project / 'entry_host.zi' - selected = project / 'selected.zi' - host.write_text('''#import "session" -#import "geometry" -#import "frame_entry" -#program_export -main :: () -> s32 { - session: Session - session.slot = 1 - viewport: Rectangle - viewport.width = 41.0 - if Frame(session, viewport) != 42 { return 1 } - return 0 -} -''') - selected.write_text('''#import "session" -#import "geometry" -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - return session.slot + cast(s32)viewport.width -} -''') - sources = [host, selected, ROOT / 'src/backend/frame_entry.zi'] - paths = ['--root', project, '--module-path', ROOT / 'src/ui', - '--module-path', ROOT / 'src/backend', '--module-path', ZIRAN_ROOT / 'std'] - binding = ['--bind', 'frame_entry:ProjectFrame=selected:Frame'] - entry = ['--entry', 'entry_host:main'] - run([ZIRAN, 'build', '--target=c', '--exe', *paths, *entry, *binding, - '-o', project / 'source', *sources], ROOT) - run([project / 'source/entry_host'], ROOT) - ir = project / 'ir' - run([ZIRAN, 'ir', *paths, *entry, *binding, '-o', ir, *sources], ROOT) - saved = sorted(ir.glob('*.zir')) - run([ZIRAN, 'build', '--target=c', '--exe', '--root', ir, *entry, - '-o', project / 'saved', *saved], ROOT) - run([project / 'saved/entry_host'], ROOT) - bundle = project / 'entry.zx' - run([ZIRAN, 'bundle', '--root', ir, *entry, '-o', bundle, *saved], ROOT) - result = run([ZIRAN, 'run', bundle], ROOT) - assert result.stdout.strip() == '0', result.stdout - print('Frame binding native source, saved IR and portable local tests passed') - - -if __name__ == '__main__': - main() diff --git a/tests/host_frame_snapshot/snapshot_app.zi b/tests/host_frame_snapshot/snapshot_app.zi index 59c93e043..70791f35c 100644 --- a/tests/host_frame_snapshot/snapshot_app.zi +++ b/tests/host_frame_snapshot/snapshot_app.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; #import "session" #import "std/bundle_host" #import "geometry" @@ -20,6 +21,7 @@ expected_modifiers: s32; expected_pointer: bool; expected_sequence: u64; callback_fail: bool; +callback_failed: bool; failure: s32; saved: FrameInputSnapshot; last: FrameInputSnapshot; @@ -29,8 +31,9 @@ Print :: (format: *u8, sequence: s32, failure: s32, actual: s32, expected: s32) AllowAsset :: (path: string) -> bool { unused path; return false } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport unused viewport first := CaptureFrameInput(session) if !first.available || first.sequence != expected_sequence || @@ -73,5 +76,7 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if failure != 0 { unused Print(HostTextData("sequence %d failure %d key %d expected %d\n"), cast(s32)first.sequence, failure, cast(s32)keys.elements[65].integer, cast(s32)expected_flags) } } last = first - return ifx callback_fail then 1 else failure + callback_failed = callback_fail } + +main :: () -> s32 { return App.Run(App.Window.{.title = "snapshot_app"}, Frame) } diff --git a/tests/host_frame_snapshot_test.py b/tests/host_frame_snapshot_test.py index 6196beb03..41bc5964f 100644 --- a/tests/host_frame_snapshot_test.py +++ b/tests/host_frame_snapshot_test.py @@ -37,8 +37,7 @@ def main(): define = ['--define', 'PLATFORM_WEB'] if args.platform == 'canvas' else [] # The Canvas host is selected by OS == .WEB, so the page names its target. target = ['--target-os', 'web', '--target-cpu', 'wasm32'] if args.platform == 'canvas' else [] - # The Canvas host calls the app through the ProjectFrame capability. - bind = ['--bind', 'frame_entry:ProjectFrame=snapshot_app:Frame'] if args.platform == 'canvas' else [] + bind = [] ir = WORK / (args.platform + '-ir') gen = WORK / (args.platform + '-c') shutil.rmtree(ir, ignore_errors=True) diff --git a/tests/host_frame_snapshot_test.zi b/tests/host_frame_snapshot_test.zi index bd17b830f..1be7c941d 100644 --- a/tests/host_frame_snapshot_test.zi +++ b/tests/host_frame_snapshot_test.zi @@ -8,8 +8,10 @@ #import "frame_input_provider" #import "tree_frame" Probe :: #import "snapshot_app"; +App :: #import "kryon/app"; +#import "geometry" #if #defined(PLATFORM_WEB) { - Host :: #import "canvas_run"; + Host :: #import "frames_web"; #import "canvas_host" #import "canvas_raster" #import "canvas_input" @@ -139,11 +141,19 @@ Step :: (session: Session, flags: u8, focused: bool = true, legacy: s32 = 0, if key != 0 { unused KeyboardSend(session, key) } drawn: bool #if #defined(PLATFORM_WEB) { - drawn = Host.DrawCanvasFrame(session, CanvasViewport()) + drawn = Host.DrawCanvasFrame(session, CanvasViewport(), Probe.Frame) } else { - drawn = Host.DrawFrame(session, Probe.Frame) + drawn = Host.DrawFrame(session, HostFrame) } - return drawn != fail && Probe.failure == 0 && !CaptureFrameInput(session).available + return drawn && Probe.callback_failed == fail && Probe.failure == 0 && + !CaptureFrameInput(session).available +} + +// The app's frames are App.Draw calls now; the desktop loop still draws one +// (session, bounds) frame, so adapt between them. +HostFrame :: (session: Session, bounds: Rectangle) -> s32 { + App.CallDraw(Probe.Frame, session.slot, session.epoch, bounds) + return 0 } RunProbe :: () -> s32 { diff --git a/tests/new_widgets_test.zi b/tests/new_widgets_test.zi index fb31db8b9..2da85c81a 100644 --- a/tests/new_widgets_test.zi +++ b/tests/new_widgets_test.zi @@ -44,6 +44,7 @@ backend = "desktop" TOML; App :: #string ZI +App :: #import "kryon/app"; Chip :: #import "kryon/chip"; Layout :: #import "kryon/layout"; ListItem :: #import "kryon/list_item"; @@ -58,11 +59,12 @@ dismissed: bool; opened: bool; wifi: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport column := Layout.Draw(session, Layout.Props.{.bounds = viewport, .gap = 8, .gap_override = true, .padding = 16, .padding_override = true}) - if !column.opened { return 0 } + if !column.opened { return } chip := Chip.Draw(session, Chip.Props.{.label = "Design", .selectable = true, .selected = design}) if chip.changed { design = chip.selected } if !dismissed { @@ -83,8 +85,9 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Text.Draw(session, Text.Props.{.bounds = .{height = 24}, .text = ifx opened then "Profile opened" else "Closed"}) Text.Draw(session, Text.Props.{.bounds = .{height = 24}, .text = ifx wifi then "Wi-Fi on" else "Wi-Fi off"}) unused End(session) - return 0 } + +main :: () -> s32 { return App.Run(App.Window.{.title = "widgets"}, Frame) } ZI; Run :: (arguments: []string, directory: string, environment: []string, log: string) -> bool { diff --git a/tests/pixmap_parity_test.py b/tests/pixmap_parity_test.py index 4e8076161..0d52e304e 100644 --- a/tests/pixmap_parity_test.py +++ b/tests/pixmap_parity_test.py @@ -80,12 +80,20 @@ def template_program(work, name, env): identity = next(package["id"] for package in json.loads(lock)["packages"] if package["name"] == "kryon") ir = project / "build/parity-ir" - host = ROOT / "src/backend/pixmap_run.zi" - # The IR command Kryon's build rules use for a native profile. - run([ZIRAN, "ir", "--project", "--bind", f"{identity}_frame_entry:ProjectFrame=app:Frame", - "--entry", f"{identity}_pixmap_run:main", - "-o", ir, host, project / "src/app.zi"], project, env) - return Program(name, ir, f"{identity}_pixmap_run:main", [f"{identity}_pixmap"]) + # The template app declares main; a shot runner draws its frames through + # the pixmap loop, the way `kryon run shot` hosts an app. + # Project modules live under src/; the shot runner is one of them. + runner = project / "src/shot.zi" + runner.write_text('Loop :: #import "kryon/frames_pixmap";\n' + 'Program :: #import "app";\n' + 'Kryon :: #import "kryon/app";\n' + '\n' + 'main :: () -> s32 {\n' + ' return Loop.Run(Kryon.Window.{.title = "shot"}, Program.Frame)\n' + '}\n') + run([ZIRAN, "ir", "--project", "--define", "KRYON_NO_DESKTOP_HOST", + "--entry", "shot:main", "-o", ir, runner], project, env) + return Program(name, ir, "shot:main", [f"{identity}_pixmap"]) def example_program(work, name, env): diff --git a/tests/responsive_dashboard_test.py b/tests/responsive_dashboard_test.py index 818cb25e6..5daf8cfb7 100644 --- a/tests/responsive_dashboard_test.py +++ b/tests/responsive_dashboard_test.py @@ -97,14 +97,8 @@ def main(): run(ROOT / "build/bin/kryon", "preview", "responsive", "--theme", "dark", "--width", "550,1200", "--height", str(HEIGHT), "--output", PREVIEW, cwd=APP, env=env) check_previews() - api = run(ZIRAN, "api", "--project", "--json", "--imports-only", "--module", "responsive", - "previews/responsive.zi", cwd=APP, env=env, capture_output=True, text=True) - imports = json.loads(api.stdout)["modules"][0]["imports"] - layout = next(declaration["resolved_module"] for declaration in imports if declaration["name"] == "Layout") - package = layout.removesuffix("_layout") - run(ZIRAN, "bundle", "--project", "--define", "KRYON_ZX", "--bind", - f"{package}_frame_entry:ProjectFrame=responsive:Frame", "--entry", f"{package}_zx_run:main", - "-o", BUNDLE, ROOT / "src/backend/zx_run.zi", "previews/responsive.zi", cwd=APP, env=env) + run(ZIRAN, "bundle", "--project", "--define", "KRYON_ZX", "--entry", "responsive:main", + "-o", BUNDLE, "previews/responsive.zi", cwd=APP, env=env) run(PLAYER, "--check", BUNDLE, env=env) env["SDL_VIDEODRIVER"] = "x11" run("xvfb-run", "-a", "-s", "-screen 0 1400x1000x24", sys.executable, __file__, "--input", env=env) diff --git a/tests/text_hook_hosts_ir_test.sh b/tests/text_hook_hosts_ir_test.sh index 91885d712..8aacddd0f 100644 --- a/tests/text_hook_hosts_ir_test.sh +++ b/tests/text_hook_hosts_ir_test.sh @@ -9,7 +9,7 @@ work=$(mktemp -d) trap 'rm -rf "$work"' EXIT cd "$repo" "$ziran" ir --project --root tools -o "$work/desktop" tools/zx.zi -"$ziran" ir --project --entry android_frame_input_test:main --bind frame_entry:ProjectFrame=android_frame_app:Frame --define ANDROID_BUILD --define __aarch64__ --root tests \ +"$ziran" ir --project --entry android_frame_input_test:main --define ANDROID_BUILD --define __aarch64__ --root tests \ --module-path tests/android_frame_input --module-path tests \ -o "$work/android" tests/android_frame_input_test.zi tests/android_frame_input/android_frame_app.zi "$ziran" ir --project --target-os web --target-cpu wasm32 \ diff --git a/tests/watch_test.zi b/tests/watch_test.zi index c5279c29d..695ee7b32 100644 --- a/tests/watch_test.zi +++ b/tests/watch_test.zi @@ -91,7 +91,7 @@ main :: () -> s32 { defer ClosePrivateDisplay(*display) driver := DriverOpen(JoinPath(project, "driver")) arguments: [5]string = .[ziran, "tool", "kryon", "run", "--watch"] - extra: [2]string = .[DriverEnvironment(*driver), "KRYON_FRAME_ENTRY=1"] + extra: [1]string = .[DriverEnvironment(*driver)] watcher := StartOnDisplay(*display, arguments[:], extra[:], project, "build/test/watch.log") if !watcher.started { print("watch: FAIL kryon run --watch did not start\n"); return 1 } defer { unused StopOwnedProcess(*watcher, 5000) } diff --git a/tests/window_desktop_test.py b/tests/window_desktop_test.py index 9eea94479..06a728fa3 100644 --- a/tests/window_desktop_test.py +++ b/tests/window_desktop_test.py @@ -19,7 +19,8 @@ from toolchain import ZIRAN_ROOT, pinned, kryon_only ROOT = Path(__file__).resolve().parents[1] ZIRAN = str(ZIRAN_ROOT / "build/bin/ziran") -APP = '''Text :: #import "kryon/text"; +APP = '''App :: #import "kryon/app"; +Text :: #import "kryon/text"; #import "kryon/geometry" #import "kryon/session" #import "Window" @@ -28,22 +29,22 @@ frames: s32; hidden_at: s32; intercepting: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} frames += 1 // Hosts that cannot intercept closing (the terminal) only draw. if frames == 1 { intercepting = WindowInterceptClose(true) } - if frames > 3000 { return 1 } + if frames > 3000 { WindowQuit(); return } if intercepting && hidden_at == 0 && WindowTakeCloseRequest() { WindowHide() hidden_at = frames } if hidden_at > 0 && frames == hidden_at + 1 && WindowVisible() { - return 1 + WindowQuit() } if hidden_at > 0 && frames == hidden_at + 20 { WindowShow() } if hidden_at > 0 && frames == hidden_at + 22 { - if !WindowVisible() { return 1 } + if !WindowVisible() { WindowQuit(); return } WindowQuit() } text: Text.Props @@ -51,8 +52,9 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { text.bounds = Rectangle.{20.0, 20.0, 300.0, 30.0} text.text = "window probe" Text.Draw(session, text) - return 0 + return } +main :: () -> s32 { return App.Run(App.Window.{.title = "window probe"}, Frame) } ''' DRIVER = '''import subprocess @@ -146,8 +148,6 @@ def main(): (project / "src/app.zi").write_text(APP) (project / "driver.py").write_text(DRIVER) env = private_environment() - # The frame-mode probe keeps its frame entry until phase 2 ports it. - env["KRYON_FRAME_ENTRY"] = "1" run([ZIRAN, "lock"], project, env) run([ZIRAN, "tool", "kryon", "build", "--profile", "desktop"], project, env) diff --git a/tests/windows_desktop_frame.zi b/tests/windows_desktop_frame.zi index 6f3b3f5a2..4d6e0ac16 100644 --- a/tests/windows_desktop_frame.zi +++ b/tests/windows_desktop_frame.zi @@ -1,13 +1,19 @@ -// A project frame linked through the stock desktop_run entry. +// A project frame program: main runs App.Run. +App :: #import "app"; #import "session" #import "geometry" -Text :: #import "kryon/text"; +Text :: #import "text"; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} props: Text.Props props.bounds = .{20.0, 15.0, 280.0, 38.0} props.text = "Windows project frame" Text.Draw(session, props) - return 0 + return } + +// The Windows SDK test links the generated C itself, so the entry is the +// exported program main, like every other fixture in this suite. +#program_export +main :: () -> s32 { return App.Run(App.Window.{.title = "windows_desktop_frame"}, Frame) } diff --git a/tests/windows_desktop_test.py b/tests/windows_desktop_test.py index 4e561243d..8c64b0f8d 100644 --- a/tests/windows_desktop_test.py +++ b/tests/windows_desktop_test.py @@ -232,10 +232,8 @@ def main(): shutil.copyfile(path, WORK / path.name) compile_source(ROOT / 'examples/window.zi', 'window') compile_source(ROOT / 'tests/windows_desktop_widgets.zi', 'widgets') - compile_source(ROOT / 'src/backend/desktop_run.zi', 'frame', options=[ - '--module-path', ROOT / 'tests', - '--bind', 'frame_entry:ProjectFrame=windows_desktop_frame:Frame'], - sources=[ROOT / 'tests/windows_desktop_frame.zi']) + compile_source(ROOT / 'tests/windows_desktop_frame.zi', 'frame', options=[ + '--module-path', ROOT / 'tests']) compile_source(ROOT / 'tests/windows_desktop_audio.zi', 'audio') compile_source(ROOT / 'tests/windows_desktop_services.zi', 'services') compile_source(ROOT / 'tests/windows_file_dialog.zi', 'dialog') diff --git a/tests/zx/app.zi b/tests/zx/app.zi index 93cb50e26..de1f6e2e2 100644 --- a/tests/zx/app.zi +++ b/tests/zx/app.zi @@ -1,15 +1,18 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Image :: #import "kryon/image"; Text :: #import "kryon/text"; #import "kryon/geometry" #import "kryon/session" #import "kryon/tree_input" +#import "Window" clicks: s32; frames: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport frames += 1 button: Button.Props button.key = cast(u64)1 @@ -37,8 +40,11 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { } else { print("zx interaction failed: clicks=% frames=%\n", clicks, frames) } - return 1 + WindowQuit() + return } unused viewport - return 0 + return } + +main :: () -> s32 { return App.Run(App.Window.{.title = "app"}, Frame) } diff --git a/tests/zx/editor_app.zi b/tests/zx/editor_app.zi index 7e6ddc7bf..8c93873b8 100644 --- a/tests/zx/editor_app.zi +++ b/tests/zx/editor_app.zi @@ -1,21 +1,24 @@ +App :: #import "kryon/app"; TextField :: #import "kryon/text_field"; -#import "geometry" -#import "key_input" -#import "session" -#import "tree" -#import "tree_input" -#import "text_host" -#import "text_request" -#import "widget_kind" +#import "kryon/geometry" +#import "kryon/key_input" +#import "kryon/session" +#import "kryon/tree" +#import "kryon/tree_input" +#import "kryon/text_host" +#import "kryon/text_request" +#import "kryon/widget_kind" using WidgetKind; foreign_session: Session; +failed: s32; bytes: [64]u8; length: s32; cursor: s32; anchor: s32; started: bool; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport if !started { initial := "start水😀" for at: 0..initial.count - 1 { bytes[at] = initial[at] } @@ -46,12 +49,17 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { TreeSetSelected(foreign_session, other, true) TreeSetTextValue(foreign_session, other, "FOREIGN", 7, 0, false, false) if TreeSubmittedNodeAt(foreign_session, other).identity_generation != - TreeSubmittedNodeAt(session, 1).identity_generation { return 20 } - if TextRequestTake(foreign_session, other).pending { return 21 } + TreeSubmittedNodeAt(session, 1).identity_generation { failed = 20; return } + if TextRequestTake(foreign_session, other).pending { failed = 21; return } TextHostPresent(foreign_session, other, "FOREIGN", 7, 0, false, false, false, false) stale := Session.{session.slot, session.epoch + 1} TextHostPresent(stale, 1, "STALE", 5, 0, false, false, false, false) - if !TreeFinish(foreign_session) { return 22 } + if !TreeFinish(foreign_session) { failed = 22; return } unused TreeFocusAt(foreign_session, other) - return 0 +} + +main :: () -> s32 { + code := App.Run(App.Window.{.title = "editor_app"}, Frame) + if failed != 0 { print("editor isolation failed %\n", failed); return failed } + return code } diff --git a/tests/zx/editor_host.zi b/tests/zx/editor_host.zi index ecb75aba1..93e9118dc 100644 --- a/tests/zx/editor_host.zi +++ b/tests/zx/editor_host.zi @@ -9,7 +9,12 @@ Probe :: struct { identity: u64; bytes: [128]u8; count: s32; cursor: s32; anchor: s32; flags: s32; pending: bool; requests: s32; revocations: s32 } -pixels: [192000]u32; +Scene :: struct { + probe: Probe + step: s32 + stage: s32 + failed: s32 +} Present :: (context: *void, identity: u64, value: string, cursor: s32, anchor: s32, flags: s32) { probe := cast(*Probe)context probe.identity = identity; probe.count = cast(s32)value.count @@ -29,8 +34,64 @@ Take :: (context: *void, identity: u64, output: []u8) -> TextRequest { probe.pending = false; probe.requests += 1 return result } -Render :: (player: *Player.Player, input: Player.Input) -> bool { - return Player.PlayerFrame(player, input, 320, 600, pixels[:]) +// The bundle owns its loop: each wait call checks the frame that just +// finished and scripts the next one. Stage 1 drives press, release, re-tap +// and foreign presses; stage 2 lets a pending request reach the bundle; +// stage 3 renders one frame for the isolation check. +Wait :: (context: *void, input: *Player.Input) -> bool { + scene := cast(*Scene)context + input.width = 320; input.height = 600 + step := scene.step + scene.step += 1 + if scene.stage == 2 { + if step >= 3 { input.closed = true; return false } + return true + } + if scene.stage == 3 { + if step >= 1 { input.closed = true; return false } + return true + } + if step == 0 { return true } + if step == 1 { + input.x = 80.0; input.y = 40.0; input.down = true; input.pressed = true + return true + } + if step == 2 { + if (scene.probe.flags & 16) == 0 { scene.failed = 12 } + if scene.failed != 0 { input.closed = true; return false } + input.down = false; input.pressed = false; input.released = true + return true + } + if step == 3 { + committed: [128]u8 + committed_count: s32 + for at: 0..scene.probe.count - 1 { committed[committed_count] = scene.probe.bytes[at]; committed_count += 1 } + if scene.probe.identity == 0 || TextView(committed[:committed_count]) != "start水😀" { + scene.failed = 7 + } + if (scene.probe.flags & 16) != 0 { scene.failed = 13 } + if scene.failed != 0 { input.closed = true; return false } + input.pressed = true; input.down = true + return true + } + if step == 4 { + if (scene.probe.flags & 16) == 0 { scene.failed = 14 } + if scene.failed != 0 { input.closed = true; return false } + input.x = 310.0; input.y = 100.0 + return true + } + if step == 5 { + if (scene.probe.flags & 16) != 0 { scene.failed = 15 } + if scene.failed != 0 { input.closed = true; return false } + input.x = 80.0; input.y = 40.0 + return true + } + if step == 6 { + input.down = false; input.pressed = false; input.released = true + return true + } + input.closed = true + return false } #program_export main :: (argc: s32, argv: **u8) -> s32 { @@ -41,45 +102,34 @@ main :: (argc: s32, argv: **u8) -> s32 { source := BytesFromPointer(descriptor.data, cast(u64)data.count) first: Player.Player; second: Player.Player defer { Player.PlayerClose(*first); Player.PlayerClose(*second) } - // Use the empty callback from the zero-initialized player on a headless surface. if !Player.PlayerOpen(*first, source, first.platform, null) || !Player.PlayerOpen(*second, source, second.platform, null) { return 3 } - a: Probe; b: Probe - Player.PlayerUseTextEditor(*first, Present, Take, cast(*void)(*a)) - Player.PlayerUseTextEditor(*second, Present, Take, cast(*void)(*b)) - input := Player.Input.{.width = 320, .height = 600} - if !Render(*first, input) || !Render(*second, input) { return 4 } - input.x = 80.0; input.y = 40.0; input.down = true; input.pressed = true - if !Render(*first, input) || !Render(*second, input) { return 5 } - if (a.flags & 16) == 0 || (b.flags & 16) == 0 { return 12 } - input.down = false; input.pressed = false; input.released = true - if !Render(*first, input) || !Render(*second, input) { return 6 } - input.released = false - if a.identity == 0 || b.identity == 0 || TextView(a.bytes[:a.count]) != "start水😀" || - TextView(b.bytes[:b.count]) != "start水😀" { return 7 } - if (a.flags & 16) != 0 || (b.flags & 16) != 0 { return 13 } - // A fresh press inside the committed field carries re-tap intent; a - // press elsewhere does not, even though a field may retain selection. - input.pressed = true; input.down = true - if !Render(*first, input) || (a.flags & 16) == 0 { return 14 } - input.x = 310.0; input.y = 100.0 - if !Render(*first, input) || (a.flags & 16) != 0 { return 15 } - input.x = 80.0; input.y = 40.0 - if !Render(*first, input) { return 16 } - input.down = false; input.pressed = false; input.released = true - if !Render(*first, input) { return 17 } - input.released = false - a.pending = true - stale: [1]HostValue = .[HostScalar("u64", cast(s64)(a.identity + 1))] + a: Scene; b: Scene + Player.PlayerUseTextEditor(*first, Present, Take, cast(*void)(*a.probe)) + Player.PlayerUseTextEditor(*second, Present, Take, cast(*void)(*b.probe)) + if !Player.PlayerUseWait(*first, Wait, cast(*void)(*a)) || + !Player.PlayerUseWait(*second, Wait, cast(*void)(*b)) { return 4 } + if !Player.PlayerRun(*first) { return 5 } + if !Player.PlayerRun(*second) { return 5 } + if a.failed != 0 { return a.failed } + if b.failed != 0 { return b.failed } + a.probe.pending = true + stale: [1]HostValue = .[HostScalar("u64", cast(s64)(a.probe.identity + 1))] answer: HostValue - if Player.PlayerCall(cast(*void)(*first), HostTextData("zx_run"), HostTextData("BundleTextRequestHost"), - *stale[0], 1, *answer) != 1 || answer.fields[4].value.integer != 0 || !a.pending { return 8 } - if !Render(*first, input) || !Render(*first, input) || !Render(*second, input) { return 9 } - if TextView(a.bytes[:a.count]) != "水😀XYZ" || a.cursor != 3 || a.anchor != 7 || a.requests != 1 || - TextView(b.bytes[:b.count]) != "start水😀" || b.requests != 0 { return 10 } - before := b.identity + if Player.PlayerCall(cast(*void)(*first), HostTextData("frames_zx"), HostTextData("BundleTextRequestHost"), + *stale[0], 1, *answer) != 1 || answer.fields[4].value.integer != 0 || !a.probe.pending { return 8 } + a.stage = 2; a.step = 0; b.stage = 2; b.step = 0 + first.closed = false; second.closed = false + if !Player.PlayerRun(*first) { return 9 } + if !Player.PlayerRun(*second) { return 9 } + if TextView(a.probe.bytes[:a.probe.count]) != "水😀XYZ" || a.probe.cursor != 3 || a.probe.anchor != 7 || a.probe.requests != 1 || + TextView(b.probe.bytes[:b.probe.count]) != "start水😀" || b.probe.requests != 0 { return 10 } + before := b.probe.identity Player.PlayerClose(*first) - if a.identity != 0 || b.identity != before || !Render(*second, input) || b.identity != before { return 11 } + if a.probe.identity != 0 || b.probe.identity != before { return 11 } + b.stage = 3; b.step = 0 + second.closed = false + if !Player.PlayerRun(*second) || b.probe.identity != before { return 11 } print("Native VM editor UTF8 selection, copied snapshots, stale request and foreign-session rejection, committed re-tap and per-player isolation passed\n") return 0 } diff --git a/tests/zx/headless.zi b/tests/zx/headless.zi index 0e1fc93f1..2ff7fb961 100644 --- a/tests/zx/headless.zi +++ b/tests/zx/headless.zi @@ -16,6 +16,10 @@ ImageMemory :: struct { pixels: *u32 } PixelDescriptor :: struct { data: *u32; count: s64 } images: [128]ImageMemory; pixels: [576000]u32; +frames: s32; +failed: s32; +interactive: bool; +original: u64; CloseImages :: () { for image: images { Release(cast(*u8)image.pixels) } @@ -66,6 +70,35 @@ TextFingerprint :: () -> u64 { return result } +// The bundle owns its loop: each wait call finishes the previous frame's +// surface, checks it, and scripts the next frame's input. +Wait :: (context: *void, input: *Player.Input) -> bool { + player := cast(*Player.Player)context + if frames > 0 { PixmapEndInto() } + step := frames + frames += 1 + input.width = 960; input.height = 600 + if step == 1 { + ink: s32 + for pixel: pixels { if (pixel & cast(u32)0xffffff) != cast(u32)0x101010 { ink += 1 } } + if ink < 20 { failed = 5; input.closed = true; return false } + if !interactive { input.closed = true; return false } + if pixels[130 * 960 + 550] != cast(u32)0xffe61e28 { failed = 6; input.closed = true; return false } + original = TextFingerprint() + input.x = 100.0; input.y = 70.0; input.pressed = true; input.down = true + } else if step == 2 { + input.pressed = false; input.down = false; input.released = true + } else if step == 3 { + if TextFingerprint() == original { failed = 9; input.closed = true; return false } + Player.PlayerTyped(player, 233) + } else if step >= 4 { + input.closed = true + return false + } + PixmapBeginInto(cast(u32)0x101010, 960, 600, pixels[:], true) + return true +} + #program_export main :: (argc: s32, argv: **u8) -> s32 { if argc < 2 { return 1 } @@ -78,25 +111,13 @@ main :: (argc: s32, argv: **u8) -> s32 { Player.PlayerClose(*player) CloseImages() } - // Use the empty callback from the zero-initialized player on a headless surface. if !Player.PlayerLoad(*player, BytesFromPointer(descriptor.data, cast(u64)data.count), player.platform, null) || !LoadImages(player.bundle) || !Player.PlayerStart(*player) { return 3 } - input := Player.Input.{.width = 960, .height = 600} - if !Player.PlayerFrame(*player, input, 960, 600, pixels[:]) { return 4 } - ink: s32 - for pixel: pixels { if (pixel & cast(u32)0xffffff) != cast(u32)0x101010 { ink += 1 } } - if ink < 20 { return 5 } + interactive = argc > 2 + if !Player.PlayerUseWait(*player, Wait, cast(*void)(*player)) { return 4 } + if !Player.PlayerRun(*player) { return 5 } + if failed != 0 { return failed } if argc == 2 { print("Headless ZX rendered\n"); return 0 } - if pixels[130 * 960 + 550] != cast(u32)0xffe61e28 { return 6 } - original := TextFingerprint() - input.x = 100.0; input.y = 70.0; input.pressed = true; input.down = true - if !Player.PlayerFrame(*player, input, 960, 600, pixels[:]) { return 7 } - input.pressed = false; input.down = false; input.released = true - if !Player.PlayerFrame(*player, input, 960, 600, pixels[:]) { return 8 } - if TextFingerprint() == original { return 9 } - input.released = false - Player.PlayerTyped(*player, 233) - if Player.PlayerFrame(*player, input, 960, 600, pixels[:]) || !player.closed { return 10 } print("Headless ZX pixels, packed PNG, retained clicks and Unicode passed\n") return 0 } diff --git a/tests/zx/mobile_app.zi b/tests/zx/mobile_app.zi index eb0135f74..024d006c1 100644 --- a/tests/zx/mobile_app.zi +++ b/tests/zx/mobile_app.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Button :: #import "kryon/button"; Image :: #import "kryon/image"; Progress :: #import "kryon/progress"; @@ -18,10 +19,16 @@ cursor: s32; anchor: s32; scroll: s32; typed: [256]u8; +failed: s32; -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - if startup_width != 32 || outside_width != 0 { return 1 } +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport + if startup_width != 32 || outside_width != 0 { + print("zx mobile: asset isolation failed (embedded %, outside %)\n", startup_width, outside_width) + failed = 1 + return + } current: [256]u8 for index: 0..length - 1 { current[index] = bytes[index] } accepted := TextView(current[:length]) == "portable" @@ -53,5 +60,10 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { Progress.Draw(session, Progress.Props.{.key = cast(u64)5, .bounds = .{40.0, 240.0, 120.0, 24.0}, .min = 0, .max = 100, .value = ifx accepted && clicks == 1 then 100 else 0}) unused viewport - return 0 +} + +main :: () -> s32 { + code := App.Run(App.Window.{.title = "zx mobile probe"}, Frame) + if failed != 0 { return failed } + return code } diff --git a/tests/zx/services.zi b/tests/zx/services.zi index a384f2506..9a46b7e86 100644 --- a/tests/zx/services.zi +++ b/tests/zx/services.zi @@ -1,3 +1,4 @@ +App :: #import "kryon/app"; Shape :: #import "kryon/shape"; Text :: #import "kryon/text"; #import "kryon/drawing_props" @@ -10,19 +11,22 @@ Text :: #import "kryon/text"; stage: s32; started: s64; +failed: s32; -Failure :: (code: s32) -> s32 { +Failure :: (code: s32) -> bool { print("ZX service failure % at stage % (media %, fetch %)\n", code, stage, MediaState(), FetchTextState()) if ServiceKeepOpen() { stage = -code - return 0 + return false } - return 1 + failed = code + return true } -#program_export -Frame :: (session: Session, viewport: Rectangle) -> s32 { - if !CursorSet(session, CursorProps.{.shape = cast(s32)CursorShape.CursorCrosshair}) { return Failure(18) } +Frame :: (frame: App.Frame) { + session := Session.{.slot = frame.slot, .epoch = frame.epoch} + viewport := frame.viewport + if !CursorSet(session, CursorProps.{.shape = cast(s32)CursorShape.CursorCrosshair}) { if Failure(18) { return } } label: Text.Props label.bounds = Rectangle.{20.0, 20.0, 800.0, 50.0} label.text = "Portable audio and asynchronous HTTP" @@ -31,52 +35,57 @@ Frame :: (session: Session, viewport: Rectangle) -> s32 { if stage < 0 || stage == 4 { unused Shape.Circle(session, Shape.CircleProps.{.center = Vector2.{160.0, 160.0}, .radius = 60.0, .fill = ifx stage == 4 then Color.{20, 180, 80, 255} else Color.{220, 30, 40, 255}}) - return 0 + return } } if stage == 0 { started = Milliseconds() - if started < 0 { return Failure(1) } - if !MediaOpen("assets/tone.wav") || MediaState() != 2 { return Failure(2) } + if started < 0 { if Failure(1) { return } } + if !MediaOpen("assets/tone.wav") || MediaState() != 2 { if Failure(2) { return } } MediaPause() - if MediaState() != 3 { return Failure(3) } + if MediaState() != 3 { if Failure(3) { return } } MediaPause() - if MediaState() != 2 { return Failure(4) } - if !FetchText(TEXT_URL) { return Failure(5) } + if MediaState() != 2 { if Failure(4) { return } } + if !FetchText(TEXT_URL) { if Failure(5) { return } } stage = 1 } else if stage == 1 { - if FetchTextState() < 0 { return Failure(6) } + if FetchTextState() < 0 { if Failure(6) { return } } if FetchTextState() == 2 { - if FetchTextResult() != "portable response" { return Failure(7) } - if Milliseconds() <= started { return Failure(8) } + if FetchTextResult() != "portable response" { if Failure(7) { return } } + if Milliseconds() <= started { if Failure(8) { return } } MediaStop() - if MediaState() != 0 { return Failure(9) } - if MediaOpen("../private.wav") { return Failure(10) } - if FetchText("file:///etc/passwd") { return Failure(11) } - if !MediaOpen(AUDIO_URL) || MediaState() != 1 { return Failure(12) } + if MediaState() != 0 { if Failure(9) { return } } + if MediaOpen("../private.wav") { if Failure(10) { return } } + if FetchText("file:///etc/passwd") { if Failure(11) { return } } + if !MediaOpen(AUDIO_URL) || MediaState() != 1 { if Failure(12) { return } } stage = 2 } } else if stage == 2 { - if MediaState() < 0 { return Failure(13) } + if MediaState() < 0 { if Failure(13) { return } } if MediaState() == 2 { MediaPause() - if MediaState() != 3 { return Failure(14) } + if MediaState() != 3 { if Failure(14) { return } } MediaStop() - if !FetchText(MISSING_URL) { return Failure(15) } + if !FetchText(MISSING_URL) { if Failure(15) { return } } stage = 3 } } else if stage == 3 { - if FetchTextState() == 2 { return Failure(16) } + if FetchTextState() == 2 { if Failure(16) { return } } if FetchTextState() == -1 { print("ZX media, HTTP and clock passed\n") if ServiceKeepOpen() { stage = 4 - return 0 + return } - return 1 + return } } - if Milliseconds() - started > 15000 { return Failure(17) } + if Milliseconds() - started > 15000 { if Failure(17) { return } } unused viewport - return 0 +} + +main :: () -> s32 { + code := App.Run(App.Window.{.title = "services"}, Frame) + if failed != 0 { return failed } + return code } diff --git a/tests/zx_canvas_test.py b/tests/zx_canvas_test.py index 8c0933af6..4dbacc9bc 100644 --- a/tests/zx_canvas_test.py +++ b/tests/zx_canvas_test.py @@ -18,7 +18,8 @@ source = (ROOT / 'tests/zx/app.zi').read_text() source = ('#import "kryon/image_raster"\n' 'startup_width: s32 = AssetWidth("assets/red.png");\n' 'outside_width: s32 = AssetWidth("private.png");\n') + source -source = source.replace(' frames += 1', ' if startup_width != 32 || outside_width != 0 { return 1 }\n frames += 1') +source = source.replace(' frames += 1', + ' if startup_width != 32 || outside_width != 0 { WindowQuit(); return }\n frames += 1') (project / 'src/app.zi').write_text(source) solid_png(project / 'assets/red.png', 32, 32, (230, 30, 40, 255)) (project / 'ziran.toml').write_text(pinned('''[package] @@ -70,7 +71,7 @@ run([ROOT / 'build/bin/zx', '--check', portable]) generated = project / 'build/generated/web/player/generated/c' assert all(re.fullmatch(r'(?:p[0-9a-f]{16}_)?(?:bundle_app|hosted_app)\.c', path.name) for path in generated.glob('*_app.c')) -assert not list(generated.glob('*_zx_run.c')) +assert not list(generated.glob('*_frames_zx.c')) for mode in ('keyboard', 'unicode'): run([JS_RUNTIME, ROOT / 'tests/zx_canvas_browser.mjs', project / 'build/zx_canvas_probe-web.html', mode]) diff --git a/tests/zx_headless_test.py b/tests/zx_headless_test.py index a5092555a..8e222626e 100644 --- a/tests/zx_headless_test.py +++ b/tests/zx_headless_test.py @@ -16,7 +16,7 @@ parser.add_argument('--gallery-index', type=Path) args = parser.parse_args() output = ROOT / 'build/scratch/zx-headless' guest_project = output / 'app-project' -package_id = kryon_test_project(guest_project) +kryon_test_project(guest_project) app = guest_project / 'src' (output / 'assets').mkdir(exist_ok=True) solid_png(output / 'assets/red.png', 32, 32, (230, 30, 40, 255)) @@ -26,9 +26,9 @@ for key in ('DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRES env.pop(key, None) paths = ['--project'] bundle = output / 'app.zx' -subprocess.run([str(ZIRAN), 'bundle', '--bind', package_id + '_frame_entry:ProjectFrame=app:Frame', '--root', str(app), *paths, '--entry', package_id + '_zx_run:main', +subprocess.run([str(ZIRAN), 'bundle', *paths, '--root', str(app), '--entry', 'app:main', '--asset-dir', 'assets=' + str(output / 'assets'), '-o', str(bundle), - str(ROOT / 'src/backend/zx_run.zi'), str(app / 'app.zi')], cwd=guest_project, env=env, check=True, timeout=120) + str(app / 'app.zi')], cwd=guest_project, env=env, check=True, timeout=120) generated = output / 'host' shutil.rmtree(generated, ignore_errors=True) defines = [] @@ -52,12 +52,12 @@ assert 'zx interaction passed' in result.stdout, result.stdout + result.stderr print(result.stdout, end='') # Exercise the actual VM/native-editor exchange through source and saved IR. editor_root = output / 'editor-app' -editor_root.mkdir(exist_ok=True) -(editor_root / 'app.zi').write_text((ROOT / 'tests/zx/editor_app.zi').read_text()) +kryon_test_project(editor_root) +(editor_root / 'src/app.zi').write_text((ROOT / 'tests/zx/editor_app.zi').read_text()) editor_bundle = output / 'editor.zx' -subprocess.run([str(ZIRAN), 'bundle', '--bind', 'frame_entry:ProjectFrame=app:Frame', '--root', str(editor_root), *paths, - '--entry', 'zx_run:main', '-o', str(editor_bundle), - str(ROOT / 'src/backend/zx_run.zi'), str(editor_root / 'app.zi')], env=env, check=True, timeout=120) +subprocess.run([str(ZIRAN), 'bundle', *paths, '--entry', 'app:main', + '-o', str(editor_bundle), str(editor_root / 'src/app.zi')], + cwd=editor_root, env=env, check=True, timeout=120) editor_ir = output / 'editor-ir' editor_c = output / 'editor-c' editor_program = output / 'editor' diff --git a/tests/zx_project_test.py b/tests/zx_project_test.py index fe7a6e4f4..0e8f7a3ba 100644 --- a/tests/zx_project_test.py +++ b/tests/zx_project_test.py @@ -141,11 +141,13 @@ backend = "desktop" bundle = project / "build/zx_probe-portable.zx" assert bundle.is_file() ir = project / "build/generated/portable/ir" - module = next(ir.glob("*_zx_run.zir")).stem + # A zx program's bundle is its own entry module; the manifest names it. + module = Path(tomllib.loads((project / "ziran.toml").read_text()) + ["package"]["entry"]).stem saved = OUTPUT / "saved.zx" run([ZIRAN, "bundle", "--root", ir, "--entry", module + ":main", "--asset-dir", "assets=" + str(project / "assets"), - "-o", saved, ir / (module + ".zir"), ir / "app.zir"], project, env) + "-o", saved, *sorted(ir.glob("*.zir"))], project, env) assert saved.read_bytes() == bundle.read_bytes() # A download contains no source, lock, project manifest or generated code. diff --git a/tests/zx_reload_test.py b/tests/zx_reload_test.py index 296961e36..8248fac4a 100644 --- a/tests/zx_reload_test.py +++ b/tests/zx_reload_test.py @@ -77,24 +77,25 @@ def main(): ('DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRESS')} environment['YUE_DESKTOP_RECOVERY'] = '0' # Watching replaces a frame bundle's release; a console program bundle runs - # once by design, so the fixtures export Frame through Kryon's zx_run host. + # once by design, so the fixtures are main programs whose frames draw. guest = OUTPUT / 'app-project' - package_id = kryon_test_project(guest) + kryon_test_project(guest) app = guest / 'src' for name in ('one', 'two'): source = app / (name + '.zi') - source.write_text('#import "kryon/geometry"\n#import "kryon/session"\n' - 'started: bool;\n#program_export\n' - 'Frame :: (session: Session, viewport: Rectangle) -> s32 {\n' - f' if !started {{ print("module {name}\\n"); started = true }}\n return 0\n}}\n') + source.write_text('App :: #import "kryon/app";\n' + 'started: bool;\n' + 'Frame :: (frame: App.Frame) {\n' + f' if !started {{ print("module {name}\\n"); started = true }}\n' + '}\n' + f'main :: () -> s32 {{ return App.Run(App.Window.{{.title = "{name}"}}, Frame) }}\n') assets = OUTPUT / ('assets-' + name) assets.mkdir(exist_ok=True) (assets / 'version.txt').write_text(name) - run([ZIRAN, 'bundle', '--project', '--bind', - f'{package_id}_frame_entry:ProjectFrame={name}:Frame', '--root', str(app), - '--entry', f'{package_id}_zx_run:main', + run([ZIRAN, 'bundle', '--project', + '--entry', name + ':main', '--asset-dir', 'assets=' + str(assets), '-o', OUTPUT / (name + '.zx'), - ROOT / 'src/backend/zx_run.zi', source], cwd=guest, env=environment) + source], cwd=guest, env=environment) (OUTPUT / 'broken.zx').write_bytes(b'ZX\0\0') unsupported = OUTPUT / 'unsupported.zi' unsupported.write_text('host_api :: #system_library "host_api";\n' diff --git a/tools/zx_canvas.zi b/tools/zx_canvas.zi index 07fbb14ea..c801377fd 100644 --- a/tools/zx_canvas.zi +++ b/tools/zx_canvas.zi @@ -40,6 +40,46 @@ picker_fetch: s32; requested_bundle: bool; file_ready: bool; status: s32; +player_input: Session; + +// Prepares one bundle frame per browser tick: it presents the finished +// frame, yields to the page, drains its ordered keys and text, and fills +// the window event record the bundle reads. Returning false ends the +// bundle's loop, handing control back to the shell (a new file, or the +// page closing). +WebPlayerWait :: (context: *void, input: *Player.Input) -> bool { + player := cast(*Player.Player)context + scope := WebScope() + unused EndCanvasFrame() + if !PollCanvas() { WebEnd(scope); return false } + if requested_bundle { WebEnd(scope); return false } + BeginCanvasFrame() + BundleMediaTick(*media) + key, modifiers := CanvasInputTake(player_input) + point := TypedCodepointTake(player_input) + while point != 0 { + Player.PlayerTyped(player, point) + point = TypedCodepointTake(player_input) + } + viewport := CanvasViewport() + pointer := PollPointer() + secondary := PollSecondaryPointer() + input.width = cast(s32)viewport.width + input.height = cast(s32)viewport.height + input.x = pointer.x + input.y = pointer.y + input.down = pointer.down + input.pressed = pointer.pressed + input.released = pointer.released + input.secondary_down = secondary.down + input.secondary_pressed = secondary.pressed + input.secondary_released = secondary.released + input.modifiers = modifiers + input.key = key + input.wheel = CanvasWheelMove() + WebEnd(scope) + return true +} ShowStatus :: (message: string) { if status != 0 { WebSet(status, WebName("textContent"), WebText(message)) } @@ -229,7 +269,8 @@ LoadSelected :: (player: *Player.Player, assets: *AppFiles, raster: *RasterHost) media.bundle = player.bundle if !BundleWriteAssets(player.bundle, assets) || !Player.PlayerUseRenderer(player, RasterHostCall, cast(*void)raster) || - !Player.PlayerStart(player) { + !Player.PlayerStart(player) || + !Player.PlayerUseWait(player, WebPlayerWait, cast(*void)player) { Player.PlayerClose(player) ShowStatus("The ZX could not start.") return false @@ -267,7 +308,7 @@ main :: () -> s32 { defer { Player.PlayerClose(*player) } // A raw player has no UI session; this one receives the page's ordered // keys and text for it. - player_input := SessionOpen() + player_input = SessionOpen() if !SessionValid(player_input) { return 1 } defer { TreeInputReset(player_input); unused SessionClose(player_input) } initial, found := ReadEntireFile("/app.zx") @@ -283,13 +324,18 @@ main :: () -> s32 { if requested_bundle && file_ready && (BundleStorageReady() || BundleStorageFailed()) { requested_bundle = false load_failed = !LoadSelected(*player, *assets, *raster) + if load_failed && player.instance != null && player.closed { + // The load rejected the file without replacing the app; the + // running instance only paused for the load, so resume it. + player.closed = false + } } - BeginCanvasFrame() if hosted { app := *apps[active_app] key, modifiers := CanvasInputTake(app.app.session) typed: [1024]u8 text := TypedTextTake(app.app.session, typed[:]) + BeginCanvasFrame() if !BundleAppFrame(app, CanvasViewport(), PollPointer(), PollSecondaryPointer(), key, modifiers, CanvasWheelMove(), text, PageNow() / 1000.0) { ShowStatus("The app frame failed.") @@ -300,25 +346,14 @@ main :: () -> s32 { last_saved = PageNow() } } else if player.instance != null && !player.closed { - viewport := CanvasViewport() - pointer := PollPointer() - secondary := PollSecondaryPointer() - key, modifiers := CanvasInputTake(player_input) - point := TypedCodepointTake(player_input) - while point != 0 { - Player.PlayerTyped(*player, point) - point = TypedCodepointTake(player_input) - } - if !Player.PlayerFrameNative(*player, Player.Input.{ - .width = cast(s32)viewport.width, .height = cast(s32)viewport.height, - .x = pointer.x, .y = pointer.y, .down = pointer.down, - .pressed = pointer.pressed, .released = pointer.released, - .secondary_down = secondary.down, .secondary_pressed = secondary.pressed, - .secondary_released = secondary.released, .modifiers = modifiers, - .key = key, .wheel = CanvasWheelMove()}) { + // The bundle owns the loop: the wait callback yields to the + // browser each frame, drains the page's keys and text, and + // presents each finished frame. + if !Player.PlayerRun(*player) || player.closed { ShowStatus("The ZX finished or its frame failed. Choose a file to open another app.") } } else { + BeginCanvasFrame() if embedded { RasterText(ifx load_failed then "Could not start this app." else "Loading…", 24, 48, 22, Color.{30, 41, 59, 255}) } else { diff --git a/ziran.toml b/ziran.toml index c6500ad0c..86a017d7e 100644 --- a/ziran.toml +++ b/ziran.toml @@ -15,7 +15,6 @@ source = true [exports] workspace_pager = "src/ui/workspace_pager/workspace_pager.zi" canvas_clip = "src/backend/canvas_clip.zi" -application_entry = "src/backend/application_entry.zi" window_runtime = "src/backend/window_runtime.zi" window_icon = "src/backend/window_icon.zi" alert = "src/ui/alert/alert.zi" @@ -69,6 +68,7 @@ frame_capture = "src/ui/frame_capture.zi" app = "src/backend/app.zi" "host/desktop" = "src/backend/frames_desktop.zi" "host/web" = "src/backend/frames_web.zi" +frames_pixmap = "src/backend/frames_pixmap.zi" dom = "src/backend/dom.zi" desktop_runtime = "src/backend/desktop_runtime.zi" desktop_zx = "src/backend/desktop_zx.zi" @@ -281,6 +281,7 @@ surface = "src/ui/surface.zi" tree = "src/ui/tree.zi" tree_input = "src/ui/tree_input.zi" text_request = "src/ui/text_request.zi" +text_host = "src/ui/text_host.zi" AccessibilityLinux = "src/backend/accessibility_linux.zi" widget_kind = "src/ui/widget_kind.zi" system_theme = "src/ui/system_theme.zi"