@native-sdk/cli 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.zig +41 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +39 -3
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +3 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +69 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/macos/appkit_host.h +11 -0
- package/src/platform/macos/appkit_host.m +130 -0
- package/src/platform/macos/root.zig +34 -0
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +118 -4
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +26 -0
- package/src/primitives/canvas/tokens.zig +170 -7
- package/src/primitives/canvas/ui.zig +62 -7
- package/src/primitives/canvas/ui_markup.zig +51 -4
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +49 -4
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +160 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
- package/src/primitives/canvas/ui_markup_tests.zig +73 -0
- package/src/primitives/canvas/ui_markup_view.zig +63 -5
- package/src/primitives/canvas/ui_markup_view_tests.zig +151 -2
- package/src/primitives/canvas/ui_schema.zig +31 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +259 -0
- package/src/primitives/canvas/widget_layout.zig +13 -5
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +28 -0
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +13 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +159 -28
- package/src/runtime/canvas_font_tests.zig +272 -3
- package/src/runtime/canvas_fonts.zig +60 -20
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +26 -0
- package/src/runtime/canvas_images.zig +33 -7
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +1295 -7
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +88 -6
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +112 -6
- package/src/runtime/flow.zig +51 -1
- package/src/runtime/gpu_surface_events.zig +51 -5
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +9 -0
- package/src/runtime/session_journal.zig +52 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +575 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_ui_app.zig +56 -0
- package/src/runtime/ui_app.zig +64 -1
- package/src/runtime/ui_app_tests.zig +794 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
package/src/embed/tests.zig
CHANGED
|
@@ -79,6 +79,75 @@ test "embedded app starts and loads source" {
|
|
|
79
79
|
try @import("std").testing.expectEqualStrings("<p>Embedded</p>", null_platform.loaded_source.?.bytes);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
test "embedded app deinit returns registered font bytes across create-destroy cycles" {
|
|
83
|
+
// A direct embedder that creates and destroys apps in one process:
|
|
84
|
+
// every cycle registers a face (font bytes are the embedded
|
|
85
|
+
// runtime's only heap ownership) and tears down through the public
|
|
86
|
+
// `deinit` — the lifecycle end the doc comment promises. The
|
|
87
|
+
// leak-checking test allocator behind the `Options.allocator` seam
|
|
88
|
+
// fails this test if any cycle strands the storage, which is
|
|
89
|
+
// exactly what a stop()-only teardown did.
|
|
90
|
+
var cycle: usize = 0;
|
|
91
|
+
while (cycle < 3) : (cycle += 1) {
|
|
92
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
93
|
+
var state: u8 = 0;
|
|
94
|
+
const embedded = try std.testing.allocator.create(EmbeddedApp);
|
|
95
|
+
defer std.testing.allocator.destroy(embedded);
|
|
96
|
+
embedded.initInPlace(.{
|
|
97
|
+
.context = &state,
|
|
98
|
+
.name = "embedded-font-cycle",
|
|
99
|
+
.source = platform.WebViewSource.html("<p>Fonts</p>"),
|
|
100
|
+
}, null_platform.platform());
|
|
101
|
+
defer embedded.deinit();
|
|
102
|
+
// Ownership is frozen at init (`Runtime.owned_allocator`;
|
|
103
|
+
// mutating `options.allocator` retargets nothing), so the test
|
|
104
|
+
// re-freezes the field itself — equivalent to constructing with
|
|
105
|
+
// the leak-checked allocator, safe while nothing is owned yet.
|
|
106
|
+
embedded.runtime.owned_allocator = std.testing.allocator;
|
|
107
|
+
|
|
108
|
+
try embedded.start();
|
|
109
|
+
try embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
110
|
+
try std.testing.expectEqual(@as(usize, 1), embedded.runtime.registeredCanvasFontCount());
|
|
111
|
+
try embedded.stop();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
test "embedded app deinit is idempotent" {
|
|
116
|
+
var null_platform = platform.NullPlatform.init(.{});
|
|
117
|
+
var state: u8 = 0;
|
|
118
|
+
const embedded = try std.testing.allocator.create(EmbeddedApp);
|
|
119
|
+
defer std.testing.allocator.destroy(embedded);
|
|
120
|
+
embedded.initInPlace(.{
|
|
121
|
+
.context = &state,
|
|
122
|
+
.name = "embedded-deinit-twice",
|
|
123
|
+
.source = platform.WebViewSource.html("<p>Fonts</p>"),
|
|
124
|
+
}, null_platform.platform());
|
|
125
|
+
embedded.runtime.owned_allocator = std.testing.allocator;
|
|
126
|
+
try embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
127
|
+
|
|
128
|
+
// The documented idiom is `defer embedded.deinit()`, which must
|
|
129
|
+
// compose with an explicit early teardown: the second call is a
|
|
130
|
+
// no-op, never a double free.
|
|
131
|
+
embedded.deinit();
|
|
132
|
+
try std.testing.expectEqual(@as(usize, 0), embedded.runtime.registeredCanvasFontCount());
|
|
133
|
+
embedded.deinit();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
test "mobile C ABI destroy returns registered font bytes through the embedded deinit" {
|
|
137
|
+
const app = native_sdk_app_create() orelse return error.TestUnexpectedResult;
|
|
138
|
+
errdefer native_sdk_app_destroy(app);
|
|
139
|
+
|
|
140
|
+
const self = mobileApp(app).?;
|
|
141
|
+
self.embedded.runtime.owned_allocator = std.testing.allocator;
|
|
142
|
+
try self.embedded.runtime.registerCanvasFont(canvas.min_registered_font_id, canvas.font_ttf.geist_mono_bytes);
|
|
143
|
+
try std.testing.expectEqual(@as(usize, 1), self.embedded.runtime.registeredCanvasFontCount());
|
|
144
|
+
|
|
145
|
+
// `native_sdk_app_destroy` is the shim's whole teardown: it routes
|
|
146
|
+
// through `EmbeddedApp.deinit` (one lifecycle owner), so the
|
|
147
|
+
// leak-checked font bytes must come back here.
|
|
148
|
+
native_sdk_app_destroy(app);
|
|
149
|
+
}
|
|
150
|
+
|
|
82
151
|
test "mobile C ABI can load packaged asset source" {
|
|
83
152
|
const app = native_sdk_app_create() orelse return error.TestUnexpectedResult;
|
|
84
153
|
defer native_sdk_app_destroy(app);
|
package/src/embed/ui_host.zig
CHANGED
|
@@ -174,6 +174,10 @@ pub fn UiAppHost(comptime AppDef: type) type {
|
|
|
174
174
|
host.disableAutomation(self);
|
|
175
175
|
self.render_memo.deinit();
|
|
176
176
|
self.ui.deinit();
|
|
177
|
+
// One lifecycle owner: the embedded app's own deinit returns
|
|
178
|
+
// its heap-owned registrations (registered canvas font
|
|
179
|
+
// bytes) before the host storage goes.
|
|
180
|
+
self.embedded.deinit();
|
|
177
181
|
std.heap.page_allocator.destroy(self);
|
|
178
182
|
}
|
|
179
183
|
|
|
@@ -76,6 +76,17 @@ typedef enum {
|
|
|
76
76
|
NATIVE_SDK_APPKIT_GPU_INPUT_IME_COMMIT_COMPOSITION = 9,
|
|
77
77
|
NATIVE_SDK_APPKIT_GPU_INPUT_IME_CANCEL_COMPOSITION = 10,
|
|
78
78
|
NATIVE_SDK_APPKIT_GPU_INPUT_POINTER_CANCEL = 11,
|
|
79
|
+
/* Trackpad pinch phases (magnifyWithEvent:). The event's `scale`
|
|
80
|
+
* field carries the per-event magnification DELTA on PINCH_CHANGE —
|
|
81
|
+
* raw NSEvent.magnification, which IS the multiplicative per-event
|
|
82
|
+
* delta per the browser-engine convention (see the doctrine note at
|
|
83
|
+
* magnifyWithEvent: in appkit_host.m); cumulative gesture scale is
|
|
84
|
+
* the product of (1 + delta); 0 on begin/end. The pointer anchor rides
|
|
85
|
+
* x/y (the event's locationInWindow — gesture events report the
|
|
86
|
+
* pointer location, not a midpoint between the fingers). */
|
|
87
|
+
NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_BEGIN = 12,
|
|
88
|
+
NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_CHANGE = 13,
|
|
89
|
+
NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_END = 14,
|
|
79
90
|
} native_sdk_appkit_gpu_input_kind_t;
|
|
80
91
|
|
|
81
92
|
typedef enum {
|
|
@@ -569,6 +569,7 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
|
|
|
569
569
|
@property(nonatomic, assign) double pendingScrollDriverOffsetY;
|
|
570
570
|
@property(nonatomic, assign) uint64_t scrollDriverEventLastEmitNs;
|
|
571
571
|
@property(nonatomic, assign) BOOL controlClickActive;
|
|
572
|
+
@property(nonatomic, assign) BOOL pinchGestureActive;
|
|
572
573
|
- (void)configureWithHost:(NativeSdkAppKitHost *)host windowId:(uint64_t)windowId label:(NSString *)label;
|
|
573
574
|
- (BOOL)isAvailable;
|
|
574
575
|
- (void)updateDrawableSize;
|
|
@@ -613,6 +614,8 @@ static NSMutableDictionary *NativeSdkCredentialQuery(NSString *service, NSString
|
|
|
613
614
|
- (void)emitQueuedPointerMotionInputEvent;
|
|
614
615
|
- (void)queueScrollInputEvent:(NSEvent *)event deltaX:(double)deltaX deltaY:(double)deltaY;
|
|
615
616
|
- (void)emitQueuedScrollInputEvent;
|
|
617
|
+
- (void)emitPinchInputEventWithKind:(NSInteger)kind event:(NSEvent *)event magnification:(double)magnification;
|
|
618
|
+
- (void)emitPinchChangeForEvent:(NSEvent *)event;
|
|
616
619
|
- (void)emitInputEventWithKind:(NSInteger)kind point:(NSPoint)point timestampNs:(uint64_t)timestampNs modifiers:(uint32_t)modifiers keyText:(NSString *)keyText inputText:(NSString *)inputText button:(NSInteger)button deltaX:(double)deltaX deltaY:(double)deltaY;
|
|
617
620
|
- (void)emitSyntheticKeyDownWithKey:(NSString *)key modifiers:(uint32_t)modifiers;
|
|
618
621
|
- (void)updateSurfaceTrackingArea;
|
|
@@ -5530,6 +5533,80 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
|
|
|
5530
5533
|
[self queueScrollInputEvent:event deltaX:-event.scrollingDeltaX deltaY:-event.scrollingDeltaY];
|
|
5531
5534
|
}
|
|
5532
5535
|
|
|
5536
|
+
- (void)magnifyWithEvent:(NSEvent *)event {
|
|
5537
|
+
// Trackpad pinch, phase-explicit. A cancelled gesture folds into
|
|
5538
|
+
// PINCH_END: pinch delivers incremental deltas the app applies as
|
|
5539
|
+
// they arrive, so there is no un-committed transient to roll back
|
|
5540
|
+
// the way pointer_cancel rolls back an in-flight press —
|
|
5541
|
+
// cancellation just means "the delta stream stops here".
|
|
5542
|
+
//
|
|
5543
|
+
// Change deltas emit uncoalesced (no per-frame queue like scroll):
|
|
5544
|
+
// the cumulative gesture scale is the PRODUCT of (1 + delta), and
|
|
5545
|
+
// summing coalesced deltas would drift from what the fingers did.
|
|
5546
|
+
//
|
|
5547
|
+
// HOW TO READ NSEvent.magnification — settled; do not "fix" again.
|
|
5548
|
+
// Apple's documentation contradicts itself: the NSEvent API
|
|
5549
|
+
// reference's prose says to ADD each event's magnification to your
|
|
5550
|
+
// scale factor, while Apple's own Event Handling Guide example
|
|
5551
|
+
// MULTIPLIES (currentSize *= 1 + event.magnification). The de facto
|
|
5552
|
+
// platform behavior is what the browser engines ship, and every
|
|
5553
|
+
// engine reads raw magnification as the MULTIPLICATIVE per-event
|
|
5554
|
+
// delta:
|
|
5555
|
+
// - WebKit, ViewGestureControllerMac.mm:
|
|
5556
|
+
// m_magnification += m_magnification * scaleWithResistance;
|
|
5557
|
+
// i.e. zoom *= 1 + event.magnification, per event.
|
|
5558
|
+
// - Chromium's mac gesture-event builder emits
|
|
5559
|
+
// pinch_update.scale = event.magnification + 1.0;
|
|
5560
|
+
// compounded multiplicatively downstream.
|
|
5561
|
+
// Ruling: raw event.magnification IS the multiplicative per-event
|
|
5562
|
+
// delta. This handler forwards it untransformed (per-event floor
|
|
5563
|
+
// aside — see emitPinchChangeForEvent:), and the app-side product
|
|
5564
|
+
// of (1 + scale) is the zoom users already experience for the same
|
|
5565
|
+
// gesture in Safari and Chrome. Do NOT reintroduce a running-sum
|
|
5566
|
+
// "additive normalization" here: it matches neither Apple's example
|
|
5567
|
+
// nor any engine — a raw +0.25, +0.20 stream must land on
|
|
5568
|
+
// 1.25 * 1.20 = 1.5, where a sum-normalized stream lands on 1.45.
|
|
5569
|
+
//
|
|
5570
|
+
// EVERY magnifyWithEvent: carries the magnification since the
|
|
5571
|
+
// previous event — the terminal (Ended/Cancelled) one included —
|
|
5572
|
+
// so each branch below must forward a nonzero magnification as a
|
|
5573
|
+
// PINCH_CHANGE or the cumulative product diverges from what the
|
|
5574
|
+
// OS delivered.
|
|
5575
|
+
const NSEventPhase phase = event.phase;
|
|
5576
|
+
if (phase & NSEventPhaseBegan) {
|
|
5577
|
+
[self emitQueuedPointerMotionInputEvent];
|
|
5578
|
+
self.pinchGestureActive = YES;
|
|
5579
|
+
[self emitPinchInputEventWithKind:NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_BEGIN event:event magnification:0];
|
|
5580
|
+
[self emitPinchChangeForEvent:event];
|
|
5581
|
+
return;
|
|
5582
|
+
}
|
|
5583
|
+
if (phase & NSEventPhaseChanged) {
|
|
5584
|
+
if (!self.pinchGestureActive) {
|
|
5585
|
+
// A gesture already in flight when this view became the
|
|
5586
|
+
// hit target skips Began; open the stream cleanly anyway.
|
|
5587
|
+
self.pinchGestureActive = YES;
|
|
5588
|
+
[self emitPinchInputEventWithKind:NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_BEGIN event:event magnification:0];
|
|
5589
|
+
}
|
|
5590
|
+
[self emitPinchChangeForEvent:event];
|
|
5591
|
+
return;
|
|
5592
|
+
}
|
|
5593
|
+
if (phase & (NSEventPhaseEnded | NSEventPhaseCancelled)) {
|
|
5594
|
+
if (!self.pinchGestureActive) return;
|
|
5595
|
+
self.pinchGestureActive = NO;
|
|
5596
|
+
// The terminal event's nonzero magnification emits as a final
|
|
5597
|
+
// PINCH_CHANGE before the end marker (a zero-magnification
|
|
5598
|
+
// terminal event emits only PINCH_END). Cancelled takes the
|
|
5599
|
+
// same path deliberately: our model applies deltas
|
|
5600
|
+
// incrementally with no rollback (see above), so the honest
|
|
5601
|
+
// stream reports every delta the OS measured, then says the
|
|
5602
|
+
// gesture is over.
|
|
5603
|
+
[self emitPinchChangeForEvent:event];
|
|
5604
|
+
[self emitPinchInputEventWithKind:NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_END event:event magnification:0];
|
|
5605
|
+
return;
|
|
5606
|
+
}
|
|
5607
|
+
// NSEventPhaseMayBegin / stationary phases carry no gesture fact.
|
|
5608
|
+
}
|
|
5609
|
+
|
|
5533
5610
|
- (void)keyDown:(NSEvent *)event {
|
|
5534
5611
|
if ([self focusedTextAccessibilityElement]) {
|
|
5535
5612
|
self.interpretedKeyEventEmittedInput = NO;
|
|
@@ -5710,6 +5787,59 @@ static BOOL NativeSdkCompositeBlurWriteRegion(NSDictionary *command, CGFloat sca
|
|
|
5710
5787
|
deltaY:deltaY];
|
|
5711
5788
|
}
|
|
5712
5789
|
|
|
5790
|
+
// --- Pinch change forwarding ---------------------------------------------
|
|
5791
|
+
// Raw event.magnification IS the wire's multiplicative per-event delta
|
|
5792
|
+
// (see the doctrine note at magnifyWithEvent:); it forwards untransformed.
|
|
5793
|
+
// One guard stands between the OS and the wire: a single event whose
|
|
5794
|
+
// magnification is at or below -1 would put a factor (1 + delta) <= 0 on
|
|
5795
|
+
// the wire — a zoom inverting through zero scale, which no physical pinch
|
|
5796
|
+
// can perform (only a driver/toolkit glitch could report it), and which
|
|
5797
|
+
// downstream products cannot recover from. Clamp PER EVENT to a floor
|
|
5798
|
+
// just above -1; the epsilon is 2^-10 (~0.001, exactly representable in
|
|
5799
|
+
// f32 and f64), so a glitched event's factor bottoms out at 2^-10 and
|
|
5800
|
+
// every emitted factor stays > 0.
|
|
5801
|
+
static const double NativeSdkPinchMagnificationFloor = -1.0 + 0x1p-10;
|
|
5802
|
+
|
|
5803
|
+
static double NativeSdkClampedPinchMagnification(double magnification) {
|
|
5804
|
+
return magnification < NativeSdkPinchMagnificationFloor ? NativeSdkPinchMagnificationFloor : magnification;
|
|
5805
|
+
}
|
|
5806
|
+
|
|
5807
|
+
// Forward one magnify event's raw magnification as a PINCH_CHANGE
|
|
5808
|
+
// (nothing to emit when the event measured no magnification).
|
|
5809
|
+
- (void)emitPinchChangeForEvent:(NSEvent *)event {
|
|
5810
|
+
const double magnification = NativeSdkClampedPinchMagnification(event.magnification);
|
|
5811
|
+
if (magnification == 0) return;
|
|
5812
|
+
[self emitPinchInputEventWithKind:NATIVE_SDK_APPKIT_GPU_INPUT_PINCH_CHANGE event:event magnification:magnification];
|
|
5813
|
+
}
|
|
5814
|
+
|
|
5815
|
+
// Pinch input: the shared input-emit shape (converted point, top-left
|
|
5816
|
+
// origin flip, host timestamp, modifier flags) with the magnification
|
|
5817
|
+
// delta riding the event's `scale` field — unused (zero) on every other
|
|
5818
|
+
// input kind, so the runtime reads it unconditionally. The x/y point is
|
|
5819
|
+
// the POINTER anchor: AppKit reports gesture events at locationInWindow
|
|
5820
|
+
// (the pointer location), never a midpoint between the fingers — NSTouch
|
|
5821
|
+
// positions are trackpad-normalized and have no view-space meaning, and
|
|
5822
|
+
// zoom-at-cursor is the anchoring apps want.
|
|
5823
|
+
- (void)emitPinchInputEventWithKind:(NSInteger)kind event:(NSEvent *)event magnification:(double)magnification {
|
|
5824
|
+
if (!self.host || self.surfaceLabel.length == 0 || !event) return;
|
|
5825
|
+
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
|
|
5826
|
+
CGFloat y = self.bounds.size.height - point.y;
|
|
5827
|
+
const char *labelBytes = self.surfaceLabel.UTF8String ?: "";
|
|
5828
|
+
[self.host emitEvent:(native_sdk_appkit_event_t){
|
|
5829
|
+
.kind = NATIVE_SDK_APPKIT_EVENT_GPU_SURFACE_INPUT,
|
|
5830
|
+
.window_id = self.windowId,
|
|
5831
|
+
.timestamp_ns = NativeSdkTimestampNanoseconds(),
|
|
5832
|
+
.x = point.x,
|
|
5833
|
+
.y = y,
|
|
5834
|
+
.scale = magnification,
|
|
5835
|
+
.view_label = labelBytes,
|
|
5836
|
+
.view_label_len = [self.surfaceLabel lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
|
|
5837
|
+
.shortcut_modifiers = NativeSdkModifierFlagsForEvent(event),
|
|
5838
|
+
.input_kind = (int)kind,
|
|
5839
|
+
}];
|
|
5840
|
+
[self requestRetainedCanvasFrame];
|
|
5841
|
+
}
|
|
5842
|
+
|
|
5713
5843
|
// --- Native scroll drivers ---------------------------------------------
|
|
5714
5844
|
// Each scrollable canvas region gets an invisible NSScrollView subview
|
|
5715
5845
|
// sized to the region and backed by a flipped document view sized to the
|
|
@@ -906,6 +906,9 @@ fn gpuSurfaceInputEventFromAppKitEvent(event: *const AppKitEvent) platform_mod.G
|
|
|
906
906
|
.text = event.input_text[0..event.input_text_len],
|
|
907
907
|
.composition_cursor = if (event.has_composition_cursor != 0) event.composition_cursor else null,
|
|
908
908
|
.modifiers = shortcutModifiersFromFlags(event.shortcut_modifiers),
|
|
909
|
+
// The pinch magnification delta rides the ABI event's `scale`
|
|
910
|
+
// field (zero on every non-pinch input emission).
|
|
911
|
+
.scale = @floatCast(event.scale),
|
|
909
912
|
};
|
|
910
913
|
}
|
|
911
914
|
|
|
@@ -1813,6 +1816,9 @@ fn gpuSurfaceInputKindFromInt(value: c_int) platform_mod.GpuSurfaceInputKind {
|
|
|
1813
1816
|
9 => .ime_commit_composition,
|
|
1814
1817
|
10 => .ime_cancel_composition,
|
|
1815
1818
|
11 => .pointer_cancel,
|
|
1819
|
+
12 => .pinch_begin,
|
|
1820
|
+
13 => .pinch_change,
|
|
1821
|
+
14 => .pinch_end,
|
|
1816
1822
|
else => .pointer_move,
|
|
1817
1823
|
};
|
|
1818
1824
|
}
|
|
@@ -2242,6 +2248,34 @@ test "mac gpu surface input maps pointer cancel" {
|
|
|
2242
2248
|
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.pointer_cancel, input.kind);
|
|
2243
2249
|
}
|
|
2244
2250
|
|
|
2251
|
+
test "mac gpu surface input maps pinch phases and carries the magnification delta" {
|
|
2252
|
+
const label = "timeline-canvas";
|
|
2253
|
+
var event = std.mem.zeroes(AppKitEvent);
|
|
2254
|
+
event.view_label = label.ptr;
|
|
2255
|
+
event.view_label_len = label.len;
|
|
2256
|
+
event.input_kind = 12;
|
|
2257
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.pinch_begin, gpuSurfaceInputEventFromAppKitEvent(&event).kind);
|
|
2258
|
+
|
|
2259
|
+
// The magnification delta rides the ABI event's `scale` field with
|
|
2260
|
+
// the pointer anchor on x/y (the host's converted, top-left-origin
|
|
2261
|
+
// pointer location).
|
|
2262
|
+
event.input_kind = 13;
|
|
2263
|
+
event.x = 160;
|
|
2264
|
+
event.y = 120;
|
|
2265
|
+
event.scale = 0.25;
|
|
2266
|
+
const change = gpuSurfaceInputEventFromAppKitEvent(&event);
|
|
2267
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.pinch_change, change.kind);
|
|
2268
|
+
try std.testing.expectEqual(@as(f32, 0.25), change.scale);
|
|
2269
|
+
try std.testing.expectEqual(@as(f32, 160), change.x);
|
|
2270
|
+
try std.testing.expectEqual(@as(f32, 120), change.y);
|
|
2271
|
+
|
|
2272
|
+
event.input_kind = 14;
|
|
2273
|
+
event.scale = 0;
|
|
2274
|
+
const end = gpuSurfaceInputEventFromAppKitEvent(&event);
|
|
2275
|
+
try std.testing.expectEqual(platform_mod.GpuSurfaceInputKind.pinch_end, end.kind);
|
|
2276
|
+
try std.testing.expectEqual(@as(f32, 0), end.scale);
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2245
2279
|
test "mac appearance event maps color scheme" {
|
|
2246
2280
|
try std.testing.expectEqual(platform_mod.ColorScheme.light, appKitColorScheme(0));
|
|
2247
2281
|
try std.testing.expectEqual(platform_mod.ColorScheme.dark, appKitColorScheme(1));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const geometry = @import("geometry");
|
|
3
|
+
const canvas = @import("canvas");
|
|
3
4
|
const types = @import("types.zig");
|
|
4
5
|
const null_backend = @import("null_platform.zig");
|
|
5
6
|
const default_gpu_frame_interval_ns = types.default_gpu_frame_interval_ns;
|
|
@@ -558,6 +559,44 @@ test "null platform records gpu surface image upload lifecycle" {
|
|
|
558
559
|
try std.testing.expectError(error.UnsupportedService, services.uploadGpuSurfaceImage(.{ .id = 7, .width = 1, .height = 1, .rgba8 = &red }));
|
|
559
560
|
}
|
|
560
561
|
|
|
562
|
+
test "gpu surface image upload bounds are honest per id namespace" {
|
|
563
|
+
var null_platform = NullPlatform.init(.{});
|
|
564
|
+
null_platform.gpu_surfaces = true;
|
|
565
|
+
const services = null_platform.platform().services;
|
|
566
|
+
|
|
567
|
+
// This validation is the one gate in front of EVERY host's upload
|
|
568
|
+
// seam (the AppKit store included — macos/root.zig forwards whatever
|
|
569
|
+
// passes here), so the bounds are pinned at this seam.
|
|
570
|
+
const media_bit = canvas.media_surface_image_id_bit;
|
|
571
|
+
const buffer = try std.testing.allocator.alloc(u8, types.max_gpu_surface_media_image_pixel_bytes + 4);
|
|
572
|
+
defer std.testing.allocator.free(buffer);
|
|
573
|
+
@memset(buffer, 128);
|
|
574
|
+
|
|
575
|
+
// Ordinary registered-image ids keep the registry's avatar-scale
|
|
576
|
+
// bound: exactly 1 MiB (512x512 RGBA8) passes, one pixel past it is
|
|
577
|
+
// an engine bug and refuses loudly.
|
|
578
|
+
try services.uploadGpuSurfaceImage(.{ .id = 7, .width = 512, .height = 512, .rgba8 = buffer[0..types.max_gpu_surface_image_pixel_bytes] });
|
|
579
|
+
try std.testing.expectError(error.InvalidGpuSurfaceImage, services.uploadGpuSurfaceImage(.{
|
|
580
|
+
.id = 7,
|
|
581
|
+
.width = types.max_gpu_surface_image_pixel_bytes / 4 + 1,
|
|
582
|
+
.height = 1,
|
|
583
|
+
.rgba8 = buffer[0 .. types.max_gpu_surface_image_pixel_bytes + 4],
|
|
584
|
+
}));
|
|
585
|
+
|
|
586
|
+
// Media-surface texture ids are video-scale: the flagship 1920x1080
|
|
587
|
+
// RGBA8 frame (8,294,400 bytes — 8x the ordinary bound) passes, the
|
|
588
|
+
// exact frame budget passes, one pixel past the budget refuses.
|
|
589
|
+
try services.uploadGpuSurfaceImage(.{ .id = media_bit | 5, .width = 1920, .height = 1080, .rgba8 = buffer[0 .. 1920 * 1080 * 4] });
|
|
590
|
+
try std.testing.expectEqual(@as(usize, 1920 * 1080 * 4), null_platform.gpu_surface_image_upload_byte_len);
|
|
591
|
+
try services.uploadGpuSurfaceImage(.{ .id = media_bit | 5, .width = 2048, .height = 1024, .rgba8 = buffer[0..types.max_gpu_surface_media_image_pixel_bytes] });
|
|
592
|
+
try std.testing.expectError(error.InvalidGpuSurfaceImage, services.uploadGpuSurfaceImage(.{
|
|
593
|
+
.id = media_bit | 5,
|
|
594
|
+
.width = types.max_gpu_surface_media_image_pixel_bytes / 4 + 1,
|
|
595
|
+
.height = 1,
|
|
596
|
+
.rgba8 = buffer,
|
|
597
|
+
}));
|
|
598
|
+
}
|
|
599
|
+
|
|
561
600
|
test "null platform preserves shifted webview storage after close" {
|
|
562
601
|
var null_platform = NullPlatform.init(.{});
|
|
563
602
|
const services = null_platform.platform().services;
|
package/src/platform/root.zig
CHANGED
|
@@ -61,6 +61,7 @@ pub const max_gpu_surface_packet_json_bytes = types.max_gpu_surface_packet_json_
|
|
|
61
61
|
pub const max_gpu_surface_packet_binary_bytes = types.max_gpu_surface_packet_binary_bytes;
|
|
62
62
|
pub const max_gpu_present_fallback_detail_bytes = types.max_gpu_present_fallback_detail_bytes;
|
|
63
63
|
pub const max_gpu_surface_image_pixel_bytes = types.max_gpu_surface_image_pixel_bytes;
|
|
64
|
+
pub const max_gpu_surface_media_image_pixel_bytes = types.max_gpu_surface_media_image_pixel_bytes;
|
|
64
65
|
pub const max_gpu_surface_font_bytes = types.max_gpu_surface_font_bytes;
|
|
65
66
|
pub const ShortcutModifiers = types.ShortcutModifiers;
|
|
66
67
|
pub const Shortcut = types.Shortcut;
|
|
@@ -139,6 +140,8 @@ pub const GpuSurfaceFrameEvent = types.GpuSurfaceFrameEvent;
|
|
|
139
140
|
pub const GpuSurfaceResizeEvent = types.GpuSurfaceResizeEvent;
|
|
140
141
|
pub const GpuSurfaceInputKind = types.GpuSurfaceInputKind;
|
|
141
142
|
pub const GpuSurfaceInputEvent = types.GpuSurfaceInputEvent;
|
|
143
|
+
pub const PinchPhase = types.PinchPhase;
|
|
144
|
+
pub const PinchEvent = types.PinchEvent;
|
|
142
145
|
pub const max_gpu_surface_scroll_drivers = types.max_gpu_surface_scroll_drivers;
|
|
143
146
|
pub const GpuSurfaceScrollDriver = types.GpuSurfaceScrollDriver;
|
|
144
147
|
pub const GpuSurfaceScrollDriverEvent = types.GpuSurfaceScrollDriverEvent;
|
package/src/platform/types.zig
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const geometry = @import("geometry");
|
|
3
|
+
const canvas = @import("canvas");
|
|
3
4
|
const security = @import("../security/root.zig");
|
|
4
5
|
|
|
5
6
|
pub const default_gpu_frame_interval_ns: u64 = 16_666_667;
|
|
@@ -256,12 +257,27 @@ pub const max_gpu_surface_packet_binary_bytes: usize = 512 * 1024;
|
|
|
256
257
|
pub const max_gpu_present_fallback_detail_bytes: usize = 32;
|
|
257
258
|
/// Per-image bound for the binary gpu-surface image upload side-channel;
|
|
258
259
|
/// matches the runtime registry's per-slot bound
|
|
259
|
-
/// (`canvas_limits.max_registered_canvas_image_pixel_bytes`).
|
|
260
|
+
/// (`canvas_limits.max_registered_canvas_image_pixel_bytes`). Applies to
|
|
261
|
+
/// ORDINARY registered-image ids only: the registry refuses anything
|
|
262
|
+
/// larger at registration, so an over-bound upload of a registered image
|
|
263
|
+
/// can only be an engine bug and is refused loudly here rather than
|
|
264
|
+
/// copied into host allocations.
|
|
260
265
|
pub const max_gpu_surface_image_pixel_bytes: usize = 1024 * 1024;
|
|
266
|
+
/// Per-image bound for uploads in the media-surface texture namespace
|
|
267
|
+
/// (ids with `canvas.media_surface_image_id_bit` set — producer-pushed
|
|
268
|
+
/// dynamic textures, structurally disjoint from registered-image ids):
|
|
269
|
+
/// video scale, not avatar scale. Matches the producer channel's
|
|
270
|
+
/// per-frame budget (`canvas_limits.max_media_surface_pixel_bytes`; a
|
|
271
|
+
/// lockstep test in media_surface_tests.zig pins the pair), so a frame
|
|
272
|
+
/// the producer accepted — a full 1920x1080 RGBA8 frame included — can
|
|
273
|
+
/// never be refused between adoption and host presentation.
|
|
274
|
+
pub const max_gpu_surface_media_image_pixel_bytes: usize = 8 * 1024 * 1024;
|
|
261
275
|
/// Per-font bound for the gpu-surface font registration side-channel;
|
|
262
276
|
/// matches the runtime registry's per-slot bound
|
|
263
|
-
/// (`canvas_limits.max_registered_canvas_font_bytes`)
|
|
264
|
-
|
|
277
|
+
/// (`canvas_limits.max_registered_canvas_font_bytes`), sized so full
|
|
278
|
+
/// CJK faces register (Noto Sans SC's TrueType build, the largest
|
|
279
|
+
/// measured, is 17.8 MB).
|
|
280
|
+
pub const max_gpu_surface_font_bytes: usize = 24 * 1024 * 1024;
|
|
265
281
|
|
|
266
282
|
pub const ShortcutModifiers = struct {
|
|
267
283
|
primary: bool = false,
|
|
@@ -1550,6 +1566,16 @@ pub const GpuSurfaceInputKind = enum {
|
|
|
1550
1566
|
ime_set_composition,
|
|
1551
1567
|
ime_commit_composition,
|
|
1552
1568
|
ime_cancel_composition,
|
|
1569
|
+
// Trackpad gestures are phase-explicit (every source models phases:
|
|
1570
|
+
// NSEvent.phase on macOS, GTK GestureZoom begin/scale-changed/end,
|
|
1571
|
+
// Windows precision-touchpad gesture messages), and the family stays
|
|
1572
|
+
// open for rotate/smart-zoom later. Only the macOS host emits these
|
|
1573
|
+
// today; Windows (precision touchpad) and Linux (GTK GestureZoom)
|
|
1574
|
+
// are staged follow-ups — on those platforms the kinds simply never
|
|
1575
|
+
// arrive.
|
|
1576
|
+
pinch_begin,
|
|
1577
|
+
pinch_change,
|
|
1578
|
+
pinch_end,
|
|
1553
1579
|
};
|
|
1554
1580
|
|
|
1555
1581
|
pub const GpuSurfaceInputEvent = struct {
|
|
@@ -1568,6 +1594,73 @@ pub const GpuSurfaceInputEvent = struct {
|
|
|
1568
1594
|
text: []const u8 = "",
|
|
1569
1595
|
composition_cursor: ?usize = null,
|
|
1570
1596
|
modifiers: ShortcutModifiers = .{},
|
|
1597
|
+
/// Pinch magnification DELTA for this event: nonzero only on
|
|
1598
|
+
/// `pinch_change`, 0 on begin/end. The delta is MULTIPLICATIVE: the
|
|
1599
|
+
/// cumulative gesture scale is the running product of `(1 + scale)`
|
|
1600
|
+
/// across the gesture's change events. On macOS this is AppKit's
|
|
1601
|
+
/// raw per-event `NSEvent.magnification`, forwarded untransformed —
|
|
1602
|
+
/// raw magnification IS the multiplicative per-event delta, the
|
|
1603
|
+
/// convention every browser engine ships (see the doctrine note at
|
|
1604
|
+
/// `magnifyWithEvent:` in appkit_host.m), so the product matches
|
|
1605
|
+
/// the zoom the same gesture performs in Safari and Chrome. The
|
|
1606
|
+
/// host guarantees `1 + scale > 0` on every event (a per-event
|
|
1607
|
+
/// floor clamps the physically impossible). The pointer anchor rides
|
|
1608
|
+
/// `x`/`y` (view-local, same space as pointer events) — the pointer
|
|
1609
|
+
/// location during the gesture, NOT a midpoint between the fingers:
|
|
1610
|
+
/// hosts report gesture events at the pointer (AppKit's
|
|
1611
|
+
/// `locationInWindow`), and zoom-at-cursor is the anchoring apps
|
|
1612
|
+
/// want.
|
|
1613
|
+
scale: f32 = 0,
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
/// Pinch gesture phase for the app-level pinch channel (`Options.on_pinch`
|
|
1617
|
+
/// / the TS core's `pinchMsg` export). Every source is phase-explicit
|
|
1618
|
+
/// (NSEvent phases, GTK GestureZoom, Windows precision-touchpad gestures);
|
|
1619
|
+
/// a host-cancelled gesture folds into `.end` — pinch delivers incremental
|
|
1620
|
+
/// deltas the app applies as they arrive, so there is no transient state
|
|
1621
|
+
/// to roll back the way `pointer_cancel` rolls back an in-flight press.
|
|
1622
|
+
/// A terminal host event (Ended or Cancelled) that still measured a
|
|
1623
|
+
/// nonzero magnification delivers that delta as a final `.change` before
|
|
1624
|
+
/// the `.end`, so the cumulative product always matches what the OS
|
|
1625
|
+
/// reported.
|
|
1626
|
+
pub const PinchPhase = enum {
|
|
1627
|
+
begin,
|
|
1628
|
+
change,
|
|
1629
|
+
end,
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
/// The pinch channel's app-facing record, derived from the raw
|
|
1633
|
+
/// `gpu_surface_input` pinch events. Pinch bypasses the widget pipeline
|
|
1634
|
+
/// deliberately: it is a view-global gesture (timeline/canvas zoom), the
|
|
1635
|
+
/// `on_key`-fallback shape rather than a widget-targeted event.
|
|
1636
|
+
pub const PinchEvent = struct {
|
|
1637
|
+
/// Source identity: which window and gpu-surface view the gesture
|
|
1638
|
+
/// happened on (the `GpuFrame` identity shape, because `x`/`y` are
|
|
1639
|
+
/// view-local — a coordinate without its view is not a position).
|
|
1640
|
+
/// Multi-window and multi-view apps tell pinches apart by these.
|
|
1641
|
+
/// `label` is borrowed for the callback, like every event slice:
|
|
1642
|
+
/// a model that keeps it must copy.
|
|
1643
|
+
window_id: WindowId = 1,
|
|
1644
|
+
label: []const u8 = "",
|
|
1645
|
+
phase: PinchPhase,
|
|
1646
|
+
/// Magnification DELTA for this event: nonzero only on `.change`,
|
|
1647
|
+
/// 0 on begin/end. The delta is MULTIPLICATIVE — the cumulative
|
|
1648
|
+
/// gesture scale is the running product of `(1 + scale)` across the
|
|
1649
|
+
/// gesture's change events; apply it memorylessly
|
|
1650
|
+
/// (`zoom *= 1 + scale`), no gesture-start bookkeeping. On macOS
|
|
1651
|
+
/// this is AppKit's raw per-event `NSEvent.magnification`, which IS
|
|
1652
|
+
/// that multiplicative delta per the browser-engine convention, so
|
|
1653
|
+
/// the product matches the zoom the same gesture performs in Safari
|
|
1654
|
+
/// and Chrome. Every event keeps `1 + scale > 0`.
|
|
1655
|
+
scale: f32 = 0,
|
|
1656
|
+
/// The pointer anchor, view-local canvas points (the pointer-event
|
|
1657
|
+
/// space): where the zoom should anchor. This is the POINTER
|
|
1658
|
+
/// location during the gesture (AppKit reports gesture events at
|
|
1659
|
+
/// `locationInWindow`), not a midpoint between the fingers — raw
|
|
1660
|
+
/// touch positions are trackpad-normalized and never reach view
|
|
1661
|
+
/// space, and zoom-at-cursor is what apps want anyway.
|
|
1662
|
+
x: f32 = 0,
|
|
1663
|
+
y: f32 = 0,
|
|
1571
1664
|
};
|
|
1572
1665
|
|
|
1573
1666
|
/// Upper bound on native scroll drivers per gpu-surface view (one per
|
|
@@ -1817,6 +1910,15 @@ pub const WidgetAccessibilityActionKind = enum(c_int) {
|
|
|
1817
1910
|
drag = 8,
|
|
1818
1911
|
drop_files = 9,
|
|
1819
1912
|
dismiss = 10,
|
|
1913
|
+
// The composition verbs never arrive from desktop assistive-tech
|
|
1914
|
+
// bridges (AppKit has no AX composition action); they exist so the
|
|
1915
|
+
// DIRECT verb surfaces (embed hosts, automation commands) and the
|
|
1916
|
+
// session journal can carry every accessibility verb as one
|
|
1917
|
+
// `widget_accessibility_action` — replay re-runs the verb, focus
|
|
1918
|
+
// included, instead of replaying its untargeted ime children.
|
|
1919
|
+
set_composition = 11,
|
|
1920
|
+
commit_composition = 12,
|
|
1921
|
+
cancel_composition = 13,
|
|
1820
1922
|
};
|
|
1821
1923
|
|
|
1822
1924
|
pub const WidgetAccessibilityActionEvent = struct {
|
|
@@ -2570,7 +2672,19 @@ pub const PlatformServices = struct {
|
|
|
2570
2672
|
pub fn uploadGpuSurfaceImage(self: PlatformServices, image: GpuSurfaceImagePixels) anyerror!void {
|
|
2571
2673
|
const expected = image.expectedByteLen() orelse return error.InvalidGpuSurfaceImage;
|
|
2572
2674
|
if (image.rgba8.len != expected) return error.InvalidGpuSurfaceImage;
|
|
2573
|
-
|
|
2675
|
+
// Two honest bounds, keyed by the id namespace: hosts copy every
|
|
2676
|
+
// upload into host-owned allocations (AppKit's NSData + NSImage
|
|
2677
|
+
// store), so each bound teaches the real cost of its id space.
|
|
2678
|
+
// Ordinary registered images are avatar-scale by the registry's
|
|
2679
|
+
// own slot bound; media-surface textures (the reserved high-bit
|
|
2680
|
+
// namespace) are video-scale by the producer channel's frame
|
|
2681
|
+
// budget — the bound the producer already enforced, so nothing a
|
|
2682
|
+
// producer staged can fail here.
|
|
2683
|
+
const bound = if ((image.id & canvas.media_surface_image_id_bit) != 0)
|
|
2684
|
+
max_gpu_surface_media_image_pixel_bytes
|
|
2685
|
+
else
|
|
2686
|
+
max_gpu_surface_image_pixel_bytes;
|
|
2687
|
+
if (image.rgba8.len > bound) return error.InvalidGpuSurfaceImage;
|
|
2574
2688
|
const upload_fn = self.upload_gpu_surface_image_fn orelse return error.UnsupportedService;
|
|
2575
2689
|
return upload_fn(self.context, image);
|
|
2576
2690
|
}
|
|
@@ -44,13 +44,13 @@ pub const max_chart_points_per_series: usize = 256;
|
|
|
44
44
|
/// filled series — or dozens of sparkline-sized ones — per frame.
|
|
45
45
|
pub const max_chart_path_elements_per_frame: usize = 2048;
|
|
46
46
|
|
|
47
|
-
///
|
|
48
|
-
/// (
|
|
49
|
-
///
|
|
50
|
-
///
|
|
51
|
-
/// hover tooltip a row per series, each
|
|
52
|
-
/// long, so 2 KiB holds dozens of charts
|
|
53
|
-
/// loudly with `ChartLabelBytesFull`.
|
|
47
|
+
/// Byte budget for the display-list builder's own formatted tick/tooltip
|
|
48
|
+
/// label store (`Builder.allocChartLabelBytes` — builder-owned like the
|
|
49
|
+
/// path-element store, so the emitted `drawText` commands keep their
|
|
50
|
+
/// label bytes for the builder's lifetime). A y axis labels at most a
|
|
51
|
+
/// handful of ticks and a hover tooltip a row per series, each
|
|
52
|
+
/// `max_chart_value_label_bytes` long, so 2 KiB holds dozens of charts
|
|
53
|
+
/// per frame; overflow fails loudly with `ChartLabelBytesFull`.
|
|
54
54
|
pub const max_chart_label_bytes_per_frame: usize = 2048;
|
|
55
55
|
|
|
56
56
|
/// Longest formatted value label: the integer digits of f32's full
|
|
@@ -436,6 +436,72 @@ test "axis labels draw muted in reserved gutters and thin to fit" {
|
|
|
436
436
|
try testing.expect(narrow_plot.maxY() < widget.frame.maxY());
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
+
test "emitted tick labels survive a later emit into another builder" {
|
|
440
|
+
// The builder contract (the `allocPathElements` rule): a display
|
|
441
|
+
// list may be HELD while another builder emits, and it may
|
|
442
|
+
// accumulate several emit calls — either way every emitted command
|
|
443
|
+
// stays intact. Label bytes live in the BUILDER's own store, so a
|
|
444
|
+
// second chart's labels can never overwrite a held list's text the
|
|
445
|
+
// way a per-emit-reset scratch pool would.
|
|
446
|
+
var widget = Widget{
|
|
447
|
+
.id = 93,
|
|
448
|
+
.kind = WidgetKind.chart,
|
|
449
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
450
|
+
.chart = .{
|
|
451
|
+
.series = &.{.{ .kind = .line, .values = &[_]f32{ 0.2, 0.8 } }},
|
|
452
|
+
.y_min = 0,
|
|
453
|
+
.y_max = 1,
|
|
454
|
+
.grid_lines = 1,
|
|
455
|
+
.y_labels = true,
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
const tokens = DesignTokens{};
|
|
459
|
+
var commands: [32]CanvasCommand = undefined;
|
|
460
|
+
var builder = Builder.init(&commands);
|
|
461
|
+
try emitWidgetTree(&builder, widget, tokens);
|
|
462
|
+
|
|
463
|
+
// A second chart over a DIFFERENT domain emits different label
|
|
464
|
+
// bytes into another builder while the first list is held.
|
|
465
|
+
widget.chart.y_min = 0;
|
|
466
|
+
widget.chart.y_max = 4;
|
|
467
|
+
var other_commands: [32]CanvasCommand = undefined;
|
|
468
|
+
var other_builder = Builder.init(&other_commands);
|
|
469
|
+
try emitWidgetTree(&other_builder, widget, tokens);
|
|
470
|
+
|
|
471
|
+
// The held list still reads the FIRST chart's lattice ("0", "0.5",
|
|
472
|
+
// "1"), not the second's ("0", "2", "4") or a byte mix.
|
|
473
|
+
try expectChartTickLabels(builder.displayList(), &.{ "0", "0.5", "1" });
|
|
474
|
+
try expectChartTickLabels(other_builder.displayList(), &.{ "0", "2", "4" });
|
|
475
|
+
|
|
476
|
+
// Accumulating both charts into ONE builder keeps both intact too.
|
|
477
|
+
var accumulated_commands: [64]CanvasCommand = undefined;
|
|
478
|
+
var accumulated = Builder.init(&accumulated_commands);
|
|
479
|
+
widget.chart.y_min = 0;
|
|
480
|
+
widget.chart.y_max = 1;
|
|
481
|
+
try emitWidgetTree(&accumulated, widget, tokens);
|
|
482
|
+
var second = widget;
|
|
483
|
+
second.id = 94;
|
|
484
|
+
second.chart.y_min = 0;
|
|
485
|
+
second.chart.y_max = 4;
|
|
486
|
+
try emitWidgetTree(&accumulated, second, tokens);
|
|
487
|
+
try expectChartTickLabels(accumulated.displayList(), &.{ "0", "0.5", "1", "0", "2", "4" });
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
fn expectChartTickLabels(display_list: DisplayList, expected: []const []const u8) !void {
|
|
491
|
+
var index: usize = 0;
|
|
492
|
+
for (display_list.commands) |command| {
|
|
493
|
+
switch (command) {
|
|
494
|
+
.draw_text => |text| {
|
|
495
|
+
try testing.expect(index < expected.len);
|
|
496
|
+
try testing.expectEqualStrings(expected[index], text.text);
|
|
497
|
+
index += 1;
|
|
498
|
+
},
|
|
499
|
+
else => {},
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
try testing.expectEqual(expected.len, index);
|
|
503
|
+
}
|
|
504
|
+
|
|
439
505
|
test "hover-detail chrome renders only under interaction and is deterministic" {
|
|
440
506
|
const values = [_]f32{ 0.2, 0.8, 0.4, 0.6 };
|
|
441
507
|
const labels = [_][]const u8{ "q1", "q2", "q3", "q4" };
|