Files
waozi 139a62893b Use package-qualified Kryon widget modules with exact Ziran and Kryon pins
Draw through Box, Button, Text, Image, Scroll, TextField and the other
qualified Kryon modules in the shared host, launcher, game HUD, controller
UI, fixtures and tests, and drop the obsolete aggregate Widgets guest.
Pin Ziran 37a64372 and Kryon bd693c1 and regenerate the lock.
2026-11-13 13:17:38 -03:00

57 lines
2.9 KiB
Ziran

#import "node_types"
TextField :: #import "kryon/text_field";
#import "kryon/input_protocol"
#import "kryon/frame_snapshot"
host_api :: #system_library "host_api";
ReadAppHost :: () -> AppMessage #foreign host_api;
WriteAppHost :: (message: AppMessage) #foreign host_api;
ReadAppUiHost :: () -> AppUiFrame #foreign host_api;
AppRecordHost :: (name: string) -> string #foreign host_api;
SaveAppRecordHost :: (name: string, value: string) -> bool #foreign host_api;
AppLocaleHost :: (key: string) -> string #foreign host_api;
AppKeyHost :: () -> s32 #foreign host_api;
AppSoundHost :: (path: string) -> bool #foreign host_api;
AppSupportsHost :: (capability: string) -> bool #foreign host_api;
AppServiceHost :: (name: string, request: string) -> string #foreign host_api;
AppFieldInputHost :: () -> TextField.Input #foreign host_api;
#program_export
Main :: () -> s32 {
message := ReadAppHost()
if message.abi != MODULE_ABI { return -1 }
if message.action == MODULE_IDENTIFY { return MODULE_NODE_APP }
message.succeeded = message.action == APP_ROUTE
if message.action == APP_FRAME {
frame := ReadAppUiHost()
if message.name != "node" || AppLocaleHost("node_label") != "Node fixture" { return -2 }
if frame.width == 1 {
if !SaveAppRecordHost("position", "node saved") { return -3 }
} else if AppRecordHost("position") != "node saved" { return -4 }
if frame.width == 1 && (AppKeyHost() != 42 || AppKeyHost() != 0) { return -5 }
// Only the first frame's host has audio; the other answers false.
if AppSoundHost("assets/node/sound.wav") != (frame.width == 1) { return -6 }
// Its echo service too; without it the service answers unavailable.
if AppSupportsHost("echo") != (frame.width == 1) { return -7 }
echo := ifx frame.width == 1 then "{\"echo\":\"ping\"}" else "{\"status\":\"unavailable\"}"
if AppServiceHost("echo", "ping") != echo { return -8 }
input := CaptureFrameInput(frame.session)
if frame.width == 1 {
if !input.available || !input.focused || input.sequence != cast(u64)1 ||
input.elapsed_ms != 239 || input.pointer.x != 9.0 || input.pointer.y != 12.0 ||
input.keys[KeyLeft] != cast(u8)(FrameKeyHeld | FrameKeyPressed) { return -10 }
} else if input.available { return -11 }
// Typing reaches the focused field as it reaches app/1 apps.
typed := AppFieldInputHost()
expected := ifx frame.width == 1 then "hi" else ""
if typed.text != expected || typed.backspace != (frame.width == 1) { return -9 }
message.succeeded = true
// A guest's reply cannot replace host-owned identity or account input.
message.name = "other"
message.account = "other-account"
}
if message.action == APP_BACK { message.succeeded = message.screen == 42 }
WriteAppHost(message)
return 0
}