From 327c8af9b701d24093c6ddeee64ca0cbac8b1207 Mon Sep 17 00:00:00 2001 From: agra Date: Sun, 17 May 2026 14:39:08 +0300 Subject: [PATCH] platform: protocol skeleton (types + api, no backend yet) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First commit of the Phase 8 platform abstraction (see current/PLATFORM_PLAN.md): - `library/modules/platform/types.sx` — `FrameContext` (viewport_w/h, pixel_w/h, dpi_scale, delta_time) and `KeyboardState` (visible, height + `zero()`). `EdgeInsets`/`Point`/`Size` and `Event` are reused from `modules/ui/types.sx` / `modules/ui/events.sx`. - `library/modules/platform/api.sx` — `Platform :: protocol { init, run_frame_loop, poll_events, begin_frame, end_frame, safe_insets, keyboard, show_keyboard, hide_keyboard, shutdown }`. Protocol bodies omit `self` (matches the `View`/`Allocator` convention). - `run_frame_loop` takes `Closure()` so backends own the run loop: SDL drives a `while !quit`, UIKit hands it to a `CADisplayLink` tick, Emscripten hands it to `emscripten_set_main_loop`. No backend yet. Regression suite still 50/50; game build still green. --- library/modules/platform/api.sx | 22 ++++++++++++++++++++++ library/modules/platform/types.sx | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 library/modules/platform/api.sx create mode 100644 library/modules/platform/types.sx diff --git a/library/modules/platform/api.sx b/library/modules/platform/api.sx new file mode 100644 index 0000000..3563c95 --- /dev/null +++ b/library/modules/platform/api.sx @@ -0,0 +1,22 @@ +#import "modules/std.sx"; +#import "modules/ui/types.sx"; +#import "modules/ui/events.sx"; +#import "modules/platform/types.sx"; + +Platform :: protocol { + init :: (title: [:0]u8, w: s32, h: s32) -> bool; + + run_frame_loop :: (frame_fn: Closure()); + + poll_events :: () -> []Event; + + begin_frame :: () -> FrameContext; + end_frame :: (); + + safe_insets :: () -> EdgeInsets; + keyboard :: () -> KeyboardState; + show_keyboard :: (); + hide_keyboard :: (); + + shutdown :: (); +} diff --git a/library/modules/platform/types.sx b/library/modules/platform/types.sx new file mode 100644 index 0000000..37b1e39 --- /dev/null +++ b/library/modules/platform/types.sx @@ -0,0 +1,19 @@ +#import "modules/std.sx"; +#import "modules/ui/types.sx"; +#import "modules/ui/events.sx"; + +FrameContext :: struct { + viewport_w: f32; + viewport_h: f32; + pixel_w: s32; + pixel_h: s32; + dpi_scale: f32; + delta_time: f32; +} + +KeyboardState :: struct { + visible: bool; + height: f32; + + zero :: () -> KeyboardState => .{ visible = false, height = 0.0 }; +}