@native-sdk/cli 0.9.1 → 0.9.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/app.zig +26 -9
- package/build.zig +124 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/packages/core/sdk/events.d.ts +7 -0
- package/packages/core/sdk/events.ts +26 -5
- package/packages/core/sdk/text.d.ts +4 -0
- package/packages/core/sdk/text.ts +51 -0
- package/packages/core/src/checker.ts +58 -1
- package/packages/core/src/contract.ts +5 -4
- package/packages/core/src/devhost_journal.mjs +2 -2
- package/packages/core/src/diagnostics.ts +2 -2
- package/packages/core/src/service_contract.ts +10 -0
- package/packages/core/src/typed_ast.ts +9 -7
- package/packages/core/src/types.ts +28 -8
- package/skill-data/automation/SKILL.md +4 -3
- package/skill-data/native-ui/SKILL.md +10 -8
- package/skill-data/ts-core/SKILL.md +8 -5
- package/src/app_runner/root.zig +301 -12
- package/src/app_runner/ts_core_main.zig +6 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +119 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +271 -52
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +222 -14
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +129 -1
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +14 -2
- package/src/primitives/canvas/text_interaction.zig +23 -0
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +65 -0
- package/src/primitives/canvas/ui.zig +66 -10
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +67 -6
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +84 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +593 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +33 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/canvas_widget_text_tests.zig +124 -0
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/native_command_event_tests.zig +29 -0
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_journal.zig +21 -2
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ts_ui_app.zig +164 -1
- package/src/runtime/ui_app.zig +100 -21
- package/src/runtime/ui_app_tests.zig +351 -32
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_text.zig +1 -1
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/verbs.zig +1 -0
- package/src/tooling/web_engine.zig +1 -1
- package/tools/corewire/emit.zig +31 -12
- package/tools/corewire/emit_facade.zig +57 -2
- package/tools/corewire/shim_rt.zig +20 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
|
+
const builtin = @import("builtin");
|
|
2
3
|
const geometry = @import("geometry");
|
|
3
4
|
const canvas = @import("root.zig");
|
|
4
5
|
const text_model = @import("text.zig");
|
|
@@ -71,6 +72,13 @@ pub const WidgetPointerEvent = struct {
|
|
|
71
72
|
/// Shift on pointer-down to extend from the existing selection
|
|
72
73
|
/// anchor instead of replacing it with a collapsed caret.
|
|
73
74
|
modifiers: WidgetKeyboardModifiers = .{},
|
|
75
|
+
/// Runtime-stamped outcome for a release that selected a radio:
|
|
76
|
+
/// true when retained selection actually changed, false when the
|
|
77
|
+
/// already-selected radio was activated again, null when this event
|
|
78
|
+
/// was not a radio selection (or never crossed the runtime seam).
|
|
79
|
+
/// Typed dispatch uses the stamp to keep `on_change` edge-triggered
|
|
80
|
+
/// while preserving the legacy toggle/press activation fallbacks.
|
|
81
|
+
radio_selection_changed: ?bool = null,
|
|
74
82
|
};
|
|
75
83
|
|
|
76
84
|
pub const WidgetKeyboardPhase = enum {
|
|
@@ -105,6 +113,24 @@ pub const WidgetKeyboardEvent = struct {
|
|
|
105
113
|
/// it to tell "selection followed focus onto me" (dispatch select)
|
|
106
114
|
/// from "an arrow landed on me in place" (collapse/expand intent).
|
|
107
115
|
focus_moved: bool = false,
|
|
116
|
+
/// True when the nearest `radio_group` scope owns this
|
|
117
|
+
/// Arrow/Home/End key. Unlike `focus_moved`, this stays true when the
|
|
118
|
+
/// target is already at the requested edge or is the group's only
|
|
119
|
+
/// focusable radio, so the key cannot leak to an app-level fallback.
|
|
120
|
+
/// Bare radios deliberately leave this false: they retain their
|
|
121
|
+
/// legacy focus-only spatial navigation.
|
|
122
|
+
radio_group_navigation: bool = false,
|
|
123
|
+
/// Whether this radio-group navigation should select the routed
|
|
124
|
+
/// target. A real focus move always selects; an in-place move selects
|
|
125
|
+
/// only when the current radio was unchecked, avoiding duplicate
|
|
126
|
+
/// change dispatches for Home-on-first / End-on-last.
|
|
127
|
+
radio_group_selection: bool = false,
|
|
128
|
+
/// Runtime-stamped outcome for a radio select intent. Space/Enter and
|
|
129
|
+
/// radio-group navigation set this to the retained mutation result;
|
|
130
|
+
/// null means the event was not a radio selection (or was routed by a
|
|
131
|
+
/// direct Tree consumer). This keeps `on_change` tied to a transition,
|
|
132
|
+
/// not merely to an activation key.
|
|
133
|
+
radio_selection_changed: ?bool = null,
|
|
108
134
|
edit: ?TextInputEvent = null,
|
|
109
135
|
/// True when the runtime clamped a clipboard paste to fit capacity
|
|
110
136
|
/// before building `edit`; apps that care about lost bytes must check
|
|
@@ -515,6 +541,7 @@ fn widgetKeyboardKeyDownTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEven
|
|
|
515
541
|
if (widgetKeyboardCommandTextNavigationEvent(event)) |edit| return edit;
|
|
516
542
|
if (widgetKeyboardWordTextNavigationEvent(event)) |edit| return edit;
|
|
517
543
|
if (widgetKeyboardWordDeleteTextEditEvent(event)) |edit| return edit;
|
|
544
|
+
if (widgetKeyboardLineDeleteTextEditEvent(event)) |edit| return edit;
|
|
518
545
|
if (event.modifiers.hasNavigationModifier()) return null;
|
|
519
546
|
if (std.ascii.eqlIgnoreCase(event.key, "backspace")) return .delete_backward;
|
|
520
547
|
if (std.ascii.eqlIgnoreCase(event.key, "delete")) return .delete_forward;
|
|
@@ -541,13 +568,49 @@ fn widgetKeyboardWordTextNavigationEvent(event: WidgetKeyboardEvent) ?TextInputE
|
|
|
541
568
|
}
|
|
542
569
|
|
|
543
570
|
fn widgetKeyboardWordDeleteTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
544
|
-
|
|
571
|
+
return widgetKeyboardWordDeleteTextEditEventForPlatform(builtin.os.tag, event);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
fn widgetKeyboardWordDeleteTextEditEventForPlatform(comptime os_tag: @TypeOf(builtin.os.tag), event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
575
|
+
// Ctrl-primary hosts project Ctrl into BOTH `control` and `super`.
|
|
576
|
+
// Accept that folded shape off macOS so Ctrl+Backspace keeps its
|
|
577
|
+
// platform word-delete meaning; a bare Super/Meta chord stays inert.
|
|
578
|
+
if (event.modifiers.shift) return null;
|
|
579
|
+
if (event.modifiers.super) {
|
|
580
|
+
if (comptime os_tag == .macos) return null;
|
|
581
|
+
if (!event.modifiers.control) return null;
|
|
582
|
+
}
|
|
545
583
|
if (event.modifiers.alt == event.modifiers.control) return null;
|
|
546
584
|
if (std.ascii.eqlIgnoreCase(event.key, "backspace")) return .delete_word_backward;
|
|
547
585
|
if (std.ascii.eqlIgnoreCase(event.key, "delete")) return .delete_word_forward;
|
|
548
586
|
return null;
|
|
549
587
|
}
|
|
550
588
|
|
|
589
|
+
fn widgetKeyboardLineDeleteTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
590
|
+
return widgetKeyboardLineDeleteTextEditEventForPlatform(builtin.os.tag, event);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
fn widgetKeyboardLineDeleteTextEditEventForPlatform(comptime os_tag: @TypeOf(builtin.os.tag), event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
594
|
+
// Command+Backspace is Cocoa's deleteToBeginningOfLine:. Keep it
|
|
595
|
+
// macOS-only: elsewhere Primary is Ctrl and belongs to word delete.
|
|
596
|
+
// Textareas deliberately use the hard newline boundary in v1; visual
|
|
597
|
+
// soft-wrap deletion can layer on runtime geometry in a follow-up.
|
|
598
|
+
if (comptime os_tag != .macos) return null;
|
|
599
|
+
if (!event.modifiers.super or event.modifiers.control or event.modifiers.alt) return null;
|
|
600
|
+
if (std.ascii.eqlIgnoreCase(event.key, "backspace")) return .delete_to_line_start;
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/// Resolve the generic keyboard vocabulary against a concrete editor kind.
|
|
605
|
+
/// A single-line field presents model-provided line breaks as spaces, so its
|
|
606
|
+
/// Command+Backspace target is always offset 0; a textarea keeps the hard-line
|
|
607
|
+
/// boundary carried by `.delete_to_line_start`.
|
|
608
|
+
pub fn widgetKeyboardTextEditEventForWidget(widget: Widget, event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
609
|
+
const edit = event.textEditEvent() orelse return null;
|
|
610
|
+
if (edit == .delete_to_line_start and widgetKindSingleLineTextEntry(widget.kind)) return .delete_to_start;
|
|
611
|
+
return edit;
|
|
612
|
+
}
|
|
613
|
+
|
|
551
614
|
fn widgetKeyboardSelectAllTextEditEvent(event: WidgetKeyboardEvent) ?TextInputEvent {
|
|
552
615
|
if (!event.modifiers.hasCommandModifier() or event.modifiers.alt or event.modifiers.shift) return null;
|
|
553
616
|
if (!std.ascii.eqlIgnoreCase(event.key, "a")) return null;
|
|
@@ -563,6 +626,9 @@ pub fn widgetKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent
|
|
|
563
626
|
if (widget.semantics.role == .treeitem) {
|
|
564
627
|
if (widgetTreeItemKeyboardControlIntent(widget, keyboard)) |intent| return intent;
|
|
565
628
|
}
|
|
629
|
+
if (widget.kind == .radio) {
|
|
630
|
+
if (widgetRadioKeyboardControlIntent(widget, keyboard)) |intent| return intent;
|
|
631
|
+
}
|
|
566
632
|
return switch (widget.kind) {
|
|
567
633
|
.button, .icon_button => if (isWidgetActivationKey(keyboard.key))
|
|
568
634
|
.{ .kind = .press, .actions = .{ .press = true } }
|
|
@@ -682,6 +748,9 @@ fn widgetSemanticPressControlIntent(widget: Widget, actions: WidgetActions) Widg
|
|
|
682
748
|
}
|
|
683
749
|
|
|
684
750
|
pub fn isWidgetActivationKey(key: []const u8) bool {
|
|
751
|
+
// Host adapters normalize the physical Return key to "enter" before
|
|
752
|
+
// it reaches this canonical event vocabulary. AppKit maps both its
|
|
753
|
+
// carriage-return key event and insertNewline: selector to that name.
|
|
685
754
|
return std.ascii.eqlIgnoreCase(key, "space") or std.ascii.eqlIgnoreCase(key, "enter");
|
|
686
755
|
}
|
|
687
756
|
|
|
@@ -699,6 +768,43 @@ pub fn isWidgetTextEntry(widget: Widget) bool {
|
|
|
699
768
|
};
|
|
700
769
|
}
|
|
701
770
|
|
|
771
|
+
test "line delete is macOS-only and folded Ctrl-primary remains word delete elsewhere" {
|
|
772
|
+
const command_backspace = WidgetKeyboardEvent{
|
|
773
|
+
.phase = .key_down,
|
|
774
|
+
.key = "backspace",
|
|
775
|
+
.modifiers = .{ .super = true },
|
|
776
|
+
};
|
|
777
|
+
try std.testing.expectEqual(TextInputEvent.delete_to_line_start, widgetKeyboardLineDeleteTextEditEventForPlatform(.macos, command_backspace).?);
|
|
778
|
+
try std.testing.expect(widgetKeyboardLineDeleteTextEditEventForPlatform(.linux, command_backspace) == null);
|
|
779
|
+
try std.testing.expect(widgetKeyboardLineDeleteTextEditEventForPlatform(.windows, command_backspace) == null);
|
|
780
|
+
|
|
781
|
+
const folded_control_backspace = WidgetKeyboardEvent{
|
|
782
|
+
.phase = .key_down,
|
|
783
|
+
.key = "backspace",
|
|
784
|
+
.modifiers = .{ .super = true, .control = true },
|
|
785
|
+
};
|
|
786
|
+
try std.testing.expect(widgetKeyboardWordDeleteTextEditEventForPlatform(.macos, folded_control_backspace) == null);
|
|
787
|
+
try std.testing.expectEqual(TextInputEvent.delete_word_backward, widgetKeyboardWordDeleteTextEditEventForPlatform(.linux, folded_control_backspace).?);
|
|
788
|
+
try std.testing.expectEqual(TextInputEvent.delete_word_backward, widgetKeyboardWordDeleteTextEditEventForPlatform(.windows, folded_control_backspace).?);
|
|
789
|
+
|
|
790
|
+
const shifted_command_backspace = WidgetKeyboardEvent{
|
|
791
|
+
.phase = .key_down,
|
|
792
|
+
.key = "backspace",
|
|
793
|
+
.modifiers = .{ .super = true, .shift = true },
|
|
794
|
+
};
|
|
795
|
+
try std.testing.expectEqual(TextInputEvent.delete_to_line_start, widgetKeyboardLineDeleteTextEditEventForPlatform(.macos, shifted_command_backspace).?);
|
|
796
|
+
|
|
797
|
+
// Widget-kind resolution is downstream of platform recognition. Stamp
|
|
798
|
+
// the recognized semantic edit so these assertions stay host-neutral;
|
|
799
|
+
// the explicit-platform assertions above own the macOS chord mapping.
|
|
800
|
+
const recognized_line_delete = WidgetKeyboardEvent{
|
|
801
|
+
.phase = .key_down,
|
|
802
|
+
.edit = .delete_to_line_start,
|
|
803
|
+
};
|
|
804
|
+
try std.testing.expectEqual(TextInputEvent.delete_to_start, widgetKeyboardTextEditEventForWidget(.{ .kind = .input }, recognized_line_delete).?);
|
|
805
|
+
try std.testing.expectEqual(TextInputEvent.delete_to_line_start, widgetKeyboardTextEditEventForWidget(.{ .kind = .textarea }, recognized_line_delete).?);
|
|
806
|
+
}
|
|
807
|
+
|
|
702
808
|
/// The arrow keys that open a closed select/combobox trigger's picker
|
|
703
809
|
/// (and, once it is mounted, walk into it).
|
|
704
810
|
pub fn isWidgetMenuOpenArrowKey(key: []const u8) bool {
|
|
@@ -778,6 +884,28 @@ fn widgetTreeItemKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardE
|
|
|
778
884
|
return null;
|
|
779
885
|
}
|
|
780
886
|
|
|
887
|
+
/// A radio inside a `radio_group` follows focus for the group's
|
|
888
|
+
/// Arrow/Home/End keymap. Space/Enter continue through the ordinary
|
|
889
|
+
/// activation arm below; radios outside a group never receive the
|
|
890
|
+
/// `radio_group_selection` stamp and keep their old behavior.
|
|
891
|
+
fn widgetRadioKeyboardControlIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
|
|
892
|
+
if (!keyboard.radio_group_selection) return null;
|
|
893
|
+
const navigation_key = std.ascii.eqlIgnoreCase(keyboard.key, "arrowup") or
|
|
894
|
+
std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown") or
|
|
895
|
+
std.ascii.eqlIgnoreCase(keyboard.key, "arrowleft") or
|
|
896
|
+
std.ascii.eqlIgnoreCase(keyboard.key, "arrowright") or
|
|
897
|
+
std.ascii.eqlIgnoreCase(keyboard.key, "home") or
|
|
898
|
+
std.ascii.eqlIgnoreCase(keyboard.key, "end");
|
|
899
|
+
if (!navigation_key) return null;
|
|
900
|
+
return .{
|
|
901
|
+
.kind = .select,
|
|
902
|
+
.actions = .{
|
|
903
|
+
.select = true,
|
|
904
|
+
.press = widget.command.len > 0,
|
|
905
|
+
},
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
|
|
781
909
|
pub fn widgetScrollKeyboardIntent(widget: Widget, keyboard: WidgetKeyboardEvent) ?WidgetControlIntent {
|
|
782
910
|
if (keyboard.phase != .key_down or keyboard.modifiers.hasNavigationModifier()) return null;
|
|
783
911
|
if (widget.state.disabled) return null;
|
|
@@ -380,7 +380,7 @@ fn nodeIsOverlapCandidate(layout: WidgetLayoutTree, node_index: usize, parent_in
|
|
|
380
380
|
const node = layout.nodes[node_index];
|
|
381
381
|
if (node.parent_index != parent_index) return false;
|
|
382
382
|
const widget = node.widget;
|
|
383
|
-
if (widget
|
|
383
|
+
if (widget_tree.widgetEscapesAncestorClips(widget)) return false;
|
|
384
384
|
if (widget.semantics.hidden) return false;
|
|
385
385
|
if (widget.opacity <= 0) return false;
|
|
386
386
|
if (!equality_model.affinesEqual(widget.transform, canvas.Affine.identity())) return false;
|
|
@@ -411,15 +411,15 @@ fn scopeScrollsHorizontally(widget: Widget) bool {
|
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
/// Nearest ancestor whose clip bounds this node: the first clipping
|
|
414
|
-
/// ancestor, or the window (node 0's scope) when none clips.
|
|
415
|
-
///
|
|
416
|
-
///
|
|
414
|
+
/// ancestor, or the window (node 0's scope) when none clips. Window-level
|
|
415
|
+
/// surfaces hoist out of every ancestor clip and are clipped by the window
|
|
416
|
+
/// alone, so the walk stops at that boundary.
|
|
417
417
|
fn clipScopeIndex(layout: WidgetLayoutTree, node_index: usize) ?usize {
|
|
418
|
-
if (layout.nodes[node_index].widget
|
|
418
|
+
if (widget_tree.widgetEscapesAncestorClips(layout.nodes[node_index].widget)) return null;
|
|
419
419
|
var current = layout.nodes[node_index].parent_index;
|
|
420
420
|
while (current) |index| {
|
|
421
421
|
if (widgetClipsForAudit(layout.nodes[index].widget)) return index;
|
|
422
|
-
if (layout.nodes[index].widget
|
|
422
|
+
if (widget_tree.widgetEscapesAncestorClips(layout.nodes[index].widget)) return null;
|
|
423
423
|
current = layout.nodes[index].parent_index;
|
|
424
424
|
}
|
|
425
425
|
return null;
|
|
@@ -1530,6 +1530,10 @@ pub fn Markdown(comptime Msg: type) type {
|
|
|
1530
1530
|
if (style.html_small > 0) span.scale = if (span.scale > 0) span.scale * 0.875 else 0.875;
|
|
1531
1531
|
if (style.html_heading_level) |level| span.scale = heading_scales[@min(level, heading_scales.len) - 1];
|
|
1532
1532
|
if (span.link.len == 0 and style.html_link.len > 0) span.link = style.html_link;
|
|
1533
|
+
// Markdown keeps its conventional underlined-link register,
|
|
1534
|
+
// while the underlying TextSpan renderer leaves decoration
|
|
1535
|
+
// entirely under the span's explicit `underline` flag.
|
|
1536
|
+
if (span.link.len > 0) span.underline = true;
|
|
1533
1537
|
appendSpan(spans, len, span);
|
|
1534
1538
|
}
|
|
1535
1539
|
|
|
@@ -187,6 +187,7 @@ test "markdown maps headings, paragraphs, and inline styles onto spans" {
|
|
|
187
187
|
try testing.expectEqualStrings("gone", spans[7].text);
|
|
188
188
|
try testing.expectEqualStrings("a link", spans[9].text);
|
|
189
189
|
try testing.expectEqualStrings("https://example.com", spans[9].link);
|
|
190
|
+
try testing.expect(spans[9].underline);
|
|
190
191
|
|
|
191
192
|
// The link span grew a hit-area child that dispatches on_link's Msg.
|
|
192
193
|
const link_child = paragraph.children[0];
|
|
@@ -252,6 +252,144 @@ pub fn decodeRgba8(bytes: []const u8, output: []u8) Error!Decoded {
|
|
|
252
252
|
return .{ .width = width, .height = height, .rgba8 = output[0 .. width * height * 4] };
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
+
/// Decode the strict writer subset while fitting its RGBA8 pixels inside a
|
|
256
|
+
/// pixel-count budget. Stored-deflate bytes are addressed directly from the
|
|
257
|
+
/// encoded stream, so an oversized source is never materialized at native
|
|
258
|
+
/// size. Downscaling uses deterministic integer box averages in sRGB space;
|
|
259
|
+
/// the test/null codec values bounded repeatability over color-management
|
|
260
|
+
/// fidelity (real hosts use their platform codecs' native thumbnail paths).
|
|
261
|
+
pub fn decodeRgba8Fitted(bytes: []const u8, output: []u8, max_pixels: usize, max_fitted_dimension: usize) Error!Decoded {
|
|
262
|
+
if (max_pixels == 0 or max_fitted_dimension == 0) return error.PngPixelBufferTooSmall;
|
|
263
|
+
if (bytes.len < signature.len or !std.mem.eql(u8, bytes[0..signature.len], &signature)) return error.InvalidPng;
|
|
264
|
+
|
|
265
|
+
var offset: usize = signature.len;
|
|
266
|
+
var width: usize = 0;
|
|
267
|
+
var height: usize = 0;
|
|
268
|
+
var idat: ?[]const u8 = null;
|
|
269
|
+
var saw_iend = false;
|
|
270
|
+
while (offset < bytes.len) {
|
|
271
|
+
if (bytes.len - offset < chunk_overhead) return error.InvalidPng;
|
|
272
|
+
const data_len: usize = std.mem.readInt(u32, bytes[offset..][0..4], .big);
|
|
273
|
+
const chunk_type = bytes[offset + 4 .. offset + 8];
|
|
274
|
+
if (bytes.len - offset < chunk_overhead + data_len) return error.InvalidPng;
|
|
275
|
+
const data = bytes[offset + 8 .. offset + 8 + data_len];
|
|
276
|
+
const stored_crc = std.mem.readInt(u32, bytes[offset + 8 + data_len ..][0..4], .big);
|
|
277
|
+
var crc = std.hash.Crc32.init();
|
|
278
|
+
crc.update(chunk_type);
|
|
279
|
+
crc.update(data);
|
|
280
|
+
if (crc.final() != stored_crc) return error.InvalidPng;
|
|
281
|
+
offset += chunk_overhead + data_len;
|
|
282
|
+
|
|
283
|
+
if (std.mem.eql(u8, chunk_type, "IHDR")) {
|
|
284
|
+
if (width != 0 or data.len != 13) return error.InvalidPng;
|
|
285
|
+
width = std.mem.readInt(u32, data[0..4], .big);
|
|
286
|
+
height = std.mem.readInt(u32, data[4..8], .big);
|
|
287
|
+
try validateDimensions(width, height);
|
|
288
|
+
if (data[8] != 8 or data[9] != 6 or data[10] != 0 or data[11] != 0 or data[12] != 0) return error.UnsupportedPng;
|
|
289
|
+
} else if (std.mem.eql(u8, chunk_type, "IDAT")) {
|
|
290
|
+
if (width == 0 or idat != null) return error.UnsupportedPng;
|
|
291
|
+
idat = data;
|
|
292
|
+
} else if (std.mem.eql(u8, chunk_type, "IEND")) {
|
|
293
|
+
if (data.len != 0) return error.InvalidPng;
|
|
294
|
+
saw_iend = true;
|
|
295
|
+
break;
|
|
296
|
+
} else {
|
|
297
|
+
return error.UnsupportedPng;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (!saw_iend) return error.InvalidPng;
|
|
301
|
+
const stream_data = idat orelse return error.InvalidPng;
|
|
302
|
+
if (stream_data.len < 6 or stream_data[0] != 0x78) return error.UnsupportedPng;
|
|
303
|
+
const expected_adler = std.mem.readInt(u32, stream_data[stream_data.len - 4 ..][0..4], .big);
|
|
304
|
+
const deflate = stream_data[2 .. stream_data.len - 4];
|
|
305
|
+
const raw_len = rawStreamLen(width, height);
|
|
306
|
+
|
|
307
|
+
// The strict writer emits canonical full-sized stored blocks. Validate
|
|
308
|
+
// that shape and the zlib checksum once, then rawByteAt below can map a
|
|
309
|
+
// raw offset to its encoded byte in O(1) without an allocation.
|
|
310
|
+
var compressed_offset: usize = 0;
|
|
311
|
+
var raw_offset: usize = 0;
|
|
312
|
+
var adler: std.hash.Adler32 = .{};
|
|
313
|
+
while (raw_offset < raw_len) {
|
|
314
|
+
if (deflate.len - compressed_offset < 5) return error.InvalidPng;
|
|
315
|
+
const header = deflate[compressed_offset];
|
|
316
|
+
if (header & 0xFE != 0) return error.UnsupportedPng;
|
|
317
|
+
const block_len: usize = std.mem.readInt(u16, deflate[compressed_offset + 1 ..][0..2], .little);
|
|
318
|
+
const block_nlen: usize = std.mem.readInt(u16, deflate[compressed_offset + 3 ..][0..2], .little);
|
|
319
|
+
const expected_len = @min(raw_len - raw_offset, max_stored_block_bytes);
|
|
320
|
+
if (block_len != expected_len or block_len ^ 0xFFFF != block_nlen) return error.UnsupportedPng;
|
|
321
|
+
if (deflate.len - compressed_offset < 5 + block_len) return error.InvalidPng;
|
|
322
|
+
const block = deflate[compressed_offset + 5 .. compressed_offset + 5 + block_len];
|
|
323
|
+
adler.update(block);
|
|
324
|
+
raw_offset += block_len;
|
|
325
|
+
compressed_offset += 5 + block_len;
|
|
326
|
+
const should_be_final = raw_offset == raw_len;
|
|
327
|
+
if ((header & 1 == 1) != should_be_final) return error.InvalidPng;
|
|
328
|
+
}
|
|
329
|
+
if (compressed_offset != deflate.len or adler.adler != expected_adler) return error.InvalidPng;
|
|
330
|
+
|
|
331
|
+
const source_pixels = std.math.mul(usize, width, height) catch return error.InvalidPngDimensions;
|
|
332
|
+
var fitted_width = width;
|
|
333
|
+
var fitted_height = height;
|
|
334
|
+
if (source_pixels > max_pixels or width > max_fitted_dimension or height > max_fitted_dimension) {
|
|
335
|
+
const area_scale = @sqrt(@as(f64, @floatFromInt(max_pixels)) / @as(f64, @floatFromInt(source_pixels)));
|
|
336
|
+
const axis_scale = @as(f64, @floatFromInt(max_fitted_dimension)) / @as(f64, @floatFromInt(@max(width, height)));
|
|
337
|
+
const scale = @min(1.0, @min(area_scale, axis_scale));
|
|
338
|
+
fitted_width = @max(1, @as(usize, @intFromFloat(@floor(@as(f64, @floatFromInt(width)) * scale))));
|
|
339
|
+
fitted_height = @max(1, @as(usize, @intFromFloat(@floor(@as(f64, @floatFromInt(height)) * scale))));
|
|
340
|
+
while (fitted_width * fitted_height > max_pixels) {
|
|
341
|
+
if (fitted_width > 1 and (fitted_height == 1 or fitted_width > fitted_height)) fitted_width -= 1 else fitted_height -= 1;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const fitted_byte_len = fitted_width * fitted_height * 4;
|
|
345
|
+
if (output.len < fitted_byte_len) return error.PngPixelBufferTooSmall;
|
|
346
|
+
|
|
347
|
+
const Reader = struct {
|
|
348
|
+
fn byteAt(data: []const u8, index: usize) u8 {
|
|
349
|
+
const block_index = index / max_stored_block_bytes;
|
|
350
|
+
const in_block = index % max_stored_block_bytes;
|
|
351
|
+
return data[block_index * (5 + max_stored_block_bytes) + 5 + in_block];
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
const source_row_len = rowByteLen(width);
|
|
355
|
+
var oy: usize = 0;
|
|
356
|
+
while (oy < fitted_height) : (oy += 1) {
|
|
357
|
+
const top: u64 = @as(u64, oy) * height;
|
|
358
|
+
const bottom: u64 = @as(u64, oy + 1) * height;
|
|
359
|
+
const sy0: usize = @intCast(top / fitted_height);
|
|
360
|
+
const sy1: usize = @intCast((bottom + fitted_height - 1) / fitted_height);
|
|
361
|
+
var ox: usize = 0;
|
|
362
|
+
while (ox < fitted_width) : (ox += 1) {
|
|
363
|
+
const left: u64 = @as(u64, ox) * width;
|
|
364
|
+
const right: u64 = @as(u64, ox + 1) * width;
|
|
365
|
+
const sx0: usize = @intCast(left / fitted_width);
|
|
366
|
+
const sx1: usize = @intCast((right + fitted_width - 1) / fitted_width);
|
|
367
|
+
var sums = [4]u64{ 0, 0, 0, 0 };
|
|
368
|
+
var weight_total: u64 = 0;
|
|
369
|
+
var sy = sy0;
|
|
370
|
+
while (sy < sy1) : (sy += 1) {
|
|
371
|
+
if (Reader.byteAt(deflate, sy * source_row_len) != 0) return error.UnsupportedPng;
|
|
372
|
+
const source_top: u64 = @as(u64, sy) * fitted_height;
|
|
373
|
+
const source_bottom: u64 = @as(u64, sy + 1) * fitted_height;
|
|
374
|
+
const weight_y = @min(bottom, source_bottom) - @max(top, source_top);
|
|
375
|
+
var sx = sx0;
|
|
376
|
+
while (sx < sx1) : (sx += 1) {
|
|
377
|
+
const source_left: u64 = @as(u64, sx) * fitted_width;
|
|
378
|
+
const source_right: u64 = @as(u64, sx + 1) * fitted_width;
|
|
379
|
+
const weight_x = @min(right, source_right) - @max(left, source_left);
|
|
380
|
+
const weight = weight_x * weight_y;
|
|
381
|
+
const source = sy * source_row_len + 1 + sx * 4;
|
|
382
|
+
inline for (0..4) |channel| sums[channel] += @as(u64, Reader.byteAt(deflate, source + channel)) * weight;
|
|
383
|
+
weight_total += weight;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const destination = (oy * fitted_width + ox) * 4;
|
|
387
|
+
inline for (0..4) |channel| output[destination + channel] = @intCast((sums[channel] + weight_total / 2) / weight_total);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return .{ .width = fitted_width, .height = fitted_height, .rgba8 = output[0..fitted_byte_len] };
|
|
391
|
+
}
|
|
392
|
+
|
|
255
393
|
test "png writer emits signature and IHDR fields" {
|
|
256
394
|
const width: usize = 3;
|
|
257
395
|
const height: usize = 2;
|
|
@@ -645,6 +645,7 @@ pub const WidgetClipboardAction = event_model.WidgetClipboardAction;
|
|
|
645
645
|
pub const widgetKeyboardClipboardAction = event_model.widgetKeyboardClipboardAction;
|
|
646
646
|
pub const widgetKeyboardNewlineTextEditEvent = event_model.widgetKeyboardNewlineTextEditEvent;
|
|
647
647
|
pub const widgetCodeTabTextEditEvent = event_model.widgetCodeTabTextEditEvent;
|
|
648
|
+
pub const widgetKeyboardTextEditEventForWidget = event_model.widgetKeyboardTextEditEventForWidget;
|
|
648
649
|
pub const widgetKindSingleLineTextEntry = event_model.widgetKindSingleLineTextEntry;
|
|
649
650
|
pub const sanitizedSingleLineTextInputEvent = event_model.sanitizedSingleLineTextInputEvent;
|
|
650
651
|
pub const widgetKeyboardControlIntent = event_model.widgetKeyboardControlIntent;
|
|
@@ -740,7 +741,7 @@ pub const cursorForWidgetTarget = widget_runtime.cursorForWidgetTarget;
|
|
|
740
741
|
/// the single source of truth the runtime, both markup engines, and the
|
|
741
742
|
/// markup validator's element list all derive from). Kind-level only: the
|
|
742
743
|
/// widget-level predicate is `widgetIsHitTarget`, which also admits any
|
|
743
|
-
/// widget carrying a bound press/toggle handler.
|
|
744
|
+
/// widget carrying a bound press/toggle/drag handler.
|
|
744
745
|
pub const widgetKindHitTarget = @import("widget_access.zig").widgetKindHitTarget;
|
|
745
746
|
/// Widget-level keyboard focusability without geometry/ancestor-clip
|
|
746
747
|
/// filtering. Runtime roving-focus groups use this to identify a logical
|
|
@@ -749,7 +750,7 @@ pub const widgetKindHitTarget = @import("widget_access.zig").widgetKindHitTarget
|
|
|
749
750
|
/// rejects clipped targets.
|
|
750
751
|
pub const widgetIsFocusable = @import("widget_access.zig").isFocusable;
|
|
751
752
|
/// Widget-level hit-target-ness: kind-level `widgetKindHitTarget` plus
|
|
752
|
-
/// any widget with a bound press/toggle handler (stamped into
|
|
753
|
+
/// any widget with a bound press/toggle/drag handler (stamped into
|
|
753
754
|
/// `semantics.actions` by the builder and both markup engines).
|
|
754
755
|
pub const widgetIsHitTarget = @import("widget_access.zig").isHitTarget;
|
|
755
756
|
pub const widgetIsHoverMsgHitTarget = @import("widget_access.zig").isHoverMsgHitTarget;
|
|
@@ -780,6 +781,11 @@ pub const widgetWindowDragTargetIndexFromNode = @import("widget_routing.zig").wi
|
|
|
780
781
|
/// stack-container list all derive from).
|
|
781
782
|
pub const widgetKindStacksChildren = @import("widget_layout.zig").widgetKindStacksChildren;
|
|
782
783
|
pub const widgetIsAnchored = @import("widget_tree.zig").widgetIsAnchored;
|
|
784
|
+
pub const widgetIsRootRelativeModal = @import("widget_tree.zig").widgetIsRootRelativeModal;
|
|
785
|
+
pub const widgetEscapesAncestorClips = @import("widget_tree.zig").widgetEscapesAncestorClips;
|
|
786
|
+
pub const WidgetPaintOrder = @import("widget_tree.zig").WidgetPaintOrder;
|
|
787
|
+
pub const widgetLayoutWindowSurfaceOrder = @import("widget_tree.zig").widgetLayoutWindowSurfaceOrder;
|
|
788
|
+
pub const widgetPaintOrderLess = @import("widget_tree.zig").widgetPaintOrderLess;
|
|
783
789
|
/// The runtime-scrolled virtual list predicate (widget_tree.zig): a
|
|
784
790
|
/// virtualized scroll_view with a DECLARED total item count, whose
|
|
785
791
|
/// scroll offset the runtime owns (engine scrolling + native drivers)
|
|
@@ -798,6 +804,12 @@ pub const disclosureSettledOpen = @import("widget_tree.zig").disclosureSettledOp
|
|
|
798
804
|
pub const disclosureContentBottom = @import("widget_tree.zig").disclosureContentBottom;
|
|
799
805
|
pub const isWidgetConcealedByDisclosure = @import("widget_tree.zig").isWidgetConcealedByDisclosure;
|
|
800
806
|
pub const anchoredWidgetFrame = @import("widget_layout.zig").anchoredWidgetFrame;
|
|
807
|
+
pub const relayoutAnchoredChildren = @import("widget_layout.zig").relayoutAnchoredChildren;
|
|
808
|
+
pub const relayoutAnchoredChildrenWithRootBounds = @import("widget_layout.zig").relayoutAnchoredChildrenWithRootBounds;
|
|
809
|
+
pub const relayoutAnchoredChildrenAtDepth = @import("widget_layout.zig").relayoutAnchoredChildrenAtDepth;
|
|
810
|
+
pub const anchoredNestingDepth = @import("widget_layout.zig").anchoredNestingDepth;
|
|
811
|
+
pub const maxAnchoredNestingDepth = @import("widget_layout.zig").maxAnchoredNestingDepth;
|
|
812
|
+
pub const widgetLayoutRootBounds = @import("widget_render.zig").widgetLayoutRootBounds;
|
|
801
813
|
/// Window-control reservation trigger (widget_layout.zig): true when a
|
|
802
814
|
/// laid-out tree left drag-header CONTENT under the OS window-control
|
|
803
815
|
/// cluster, so runtimes know to stamp `DesignTokens.window_controls`
|
|
@@ -103,6 +103,8 @@ pub const TextInputEvent = union(enum) {
|
|
|
103
103
|
delete_forward,
|
|
104
104
|
delete_word_backward,
|
|
105
105
|
delete_word_forward,
|
|
106
|
+
delete_to_start,
|
|
107
|
+
delete_to_line_start,
|
|
106
108
|
clear,
|
|
107
109
|
move_caret: TextCaretMove,
|
|
108
110
|
set_selection: TextSelection,
|
|
@@ -136,6 +138,8 @@ pub fn applyTextInputEvent(state: TextEditState, event: TextInputEvent, output:
|
|
|
136
138
|
.delete_forward => deleteForwardTextEdit(normalized, output),
|
|
137
139
|
.delete_word_backward => deleteWordBackwardTextEdit(normalized, output),
|
|
138
140
|
.delete_word_forward => deleteWordForwardTextEdit(normalized, output),
|
|
141
|
+
.delete_to_start => deleteToStartTextEdit(normalized, output),
|
|
142
|
+
.delete_to_line_start => deleteToLineStartTextEdit(normalized, output),
|
|
139
143
|
.clear => .{
|
|
140
144
|
.text = "",
|
|
141
145
|
.selection = TextSelection.collapsed(0),
|
|
@@ -251,6 +255,25 @@ fn deleteWordForwardTextEdit(state: TextEditState, output: []u8) Error!TextEditS
|
|
|
251
255
|
return replaceTextEditRange(state, TextRange.init(caret, nextTextWordOffset(state.text, caret)), "", output, null, 0);
|
|
252
256
|
}
|
|
253
257
|
|
|
258
|
+
fn deleteToStartTextEdit(state: TextEditState, output: []u8) Error!TextEditState {
|
|
259
|
+
const range = activeTextReplaceRange(state);
|
|
260
|
+
if (!range.isCollapsed(state.text.len)) return replaceTextEditRange(state, range, "", output, null, 0);
|
|
261
|
+
|
|
262
|
+
const caret = snapTextCaretOffset(state.text, state.selection.focus);
|
|
263
|
+
if (caret == 0) return .{ .text = state.text, .selection = TextSelection.collapsed(0), .composition = null };
|
|
264
|
+
return replaceTextEditRange(state, TextRange.init(0, caret), "", output, null, 0);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
fn deleteToLineStartTextEdit(state: TextEditState, output: []u8) Error!TextEditState {
|
|
268
|
+
const range = activeTextReplaceRange(state);
|
|
269
|
+
if (!range.isCollapsed(state.text.len)) return replaceTextEditRange(state, range, "", output, null, 0);
|
|
270
|
+
|
|
271
|
+
const caret = snapTextCaretOffset(state.text, state.selection.focus);
|
|
272
|
+
const line_start = textLineStartOffset(state.text, caret);
|
|
273
|
+
if (line_start == caret) return .{ .text = state.text, .selection = TextSelection.collapsed(caret), .composition = null };
|
|
274
|
+
return replaceTextEditRange(state, TextRange.init(line_start, caret), "", output, null, 0);
|
|
275
|
+
}
|
|
276
|
+
|
|
254
277
|
fn moveTextCaret(state: TextEditState, move: TextCaretMove) TextEditState {
|
|
255
278
|
const range = state.selection.range(state.text.len);
|
|
256
279
|
const focus = snapTextCaretOffset(state.text, state.selection.focus);
|
|
@@ -435,7 +435,7 @@ fn paragraphView(ui: *SpanUi) SpanUi.Node {
|
|
|
435
435
|
.{ .text = "Read " },
|
|
436
436
|
.{ .text = "the guide", .link = "https://example.com/guide" },
|
|
437
437
|
.{ .text = " and " },
|
|
438
|
-
.{ .text = "the spec", .link = "https://example.com/spec" },
|
|
438
|
+
.{ .text = "the spec", .link = "https://example.com/spec", .underline = true },
|
|
439
439
|
};
|
|
440
440
|
return ui.column(.{ .gap = 8 }, .{
|
|
441
441
|
ui.paragraph(.{ .on_link = SpanUi.linkMsg(.open) }, &spans),
|
|
@@ -502,7 +502,7 @@ test "link children get span-derived frames and are hit-testable" {
|
|
|
502
502
|
try testing.expectEqual(paragraph.id, paragraph_hit.id);
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
-
test "span
|
|
505
|
+
test "span underline decoration is independent from link behavior" {
|
|
506
506
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
507
507
|
defer arena_state.deinit();
|
|
508
508
|
var ui = SpanUi.init(arena_state.allocator());
|
|
@@ -532,7 +532,9 @@ test "span paragraphs emit one text command per run plus link underlines" {
|
|
|
532
532
|
}
|
|
533
533
|
// 4 spans on one wide line + the plain trailer text widget.
|
|
534
534
|
try testing.expectEqual(@as(usize, 5), text_commands);
|
|
535
|
-
|
|
535
|
+
// Both links keep accent ink and link interaction, but only the second
|
|
536
|
+
// span explicitly opts into an underline.
|
|
537
|
+
try testing.expectEqual(@as(usize, 1), underlines);
|
|
536
538
|
try testing.expectEqual(@as(usize, 2), accent_texts);
|
|
537
539
|
}
|
|
538
540
|
|
|
@@ -78,6 +78,8 @@ pub const TextSpan = struct {
|
|
|
78
78
|
/// backgrounds never affect measurement or layout (#86, intra-line
|
|
79
79
|
/// diff emphasis).
|
|
80
80
|
background: ?TextSpanColor = null,
|
|
81
|
+
/// Visual underline decoration. Independent from `link`: clickable
|
|
82
|
+
/// spans remain undecorated unless this is true.
|
|
81
83
|
underline: bool = false,
|
|
82
84
|
strikethrough: bool = false,
|
|
83
85
|
/// Relative size multiplier against the paragraph base size; 0 means
|
|
@@ -429,6 +429,31 @@ test "text edit state applies utf8-aware caret insert and delete events" {
|
|
|
429
429
|
try std.testing.expectEqualStrings(" cafe", state.text);
|
|
430
430
|
try std.testing.expectEqualDeep(TextSelection.collapsed(0), state.selection);
|
|
431
431
|
|
|
432
|
+
state = TextEditState{ .text = "first\nsecond line", .selection = TextSelection.collapsed(12) };
|
|
433
|
+
state = try state.apply(.delete_to_start, &storage_b);
|
|
434
|
+
try std.testing.expectEqualStrings(" line", state.text);
|
|
435
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(0), state.selection);
|
|
436
|
+
|
|
437
|
+
state = TextEditState{ .text = "first\nsecond line", .selection = TextSelection.collapsed(12) };
|
|
438
|
+
state = try state.apply(.delete_to_line_start, &storage_a);
|
|
439
|
+
try std.testing.expectEqualStrings("first\n line", state.text);
|
|
440
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(6), state.selection);
|
|
441
|
+
|
|
442
|
+
state = TextEditState{ .text = "first\nsecond", .selection = TextSelection.collapsed(6) };
|
|
443
|
+
state = try state.apply(.delete_to_line_start, &storage_b);
|
|
444
|
+
try std.testing.expectEqualStrings("first\nsecond", state.text);
|
|
445
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(6), state.selection);
|
|
446
|
+
|
|
447
|
+
state = TextEditState{ .text = "first\nsecond", .selection = .{ .anchor = 7, .focus = 10 } };
|
|
448
|
+
state = try state.apply(.delete_to_line_start, &storage_a);
|
|
449
|
+
try std.testing.expectEqualStrings("first\nsnd", state.text);
|
|
450
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(7), state.selection);
|
|
451
|
+
|
|
452
|
+
state = TextEditState{ .text = "one\r\ntwo", .selection = TextSelection.collapsed(8) };
|
|
453
|
+
state = try state.apply(.delete_to_line_start, &storage_b);
|
|
454
|
+
try std.testing.expectEqualStrings("one\r\n", state.text);
|
|
455
|
+
try std.testing.expectEqualDeep(TextSelection.collapsed(5), state.selection);
|
|
456
|
+
|
|
432
457
|
state = TextEditState.init("");
|
|
433
458
|
state = try state.apply(.{ .insert_text = "AxB" }, &storage_b);
|
|
434
459
|
try std.testing.expectEqualStrings("AxB", state.text);
|
|
@@ -475,6 +500,26 @@ test "widget keyboard control intents map activation keys" {
|
|
|
475
500
|
try std.testing.expect(radio.actions.press);
|
|
476
501
|
try std.testing.expect(!radio.actions.toggle);
|
|
477
502
|
|
|
503
|
+
const grouped_radio_move = widgetKeyboardControlIntent(.{ .kind = .radio, .text = "Annual" }, .{
|
|
504
|
+
.phase = .key_down,
|
|
505
|
+
.key = "arrowright",
|
|
506
|
+
.focus_moved = true,
|
|
507
|
+
.radio_group_navigation = true,
|
|
508
|
+
.radio_group_selection = true,
|
|
509
|
+
}).?;
|
|
510
|
+
try std.testing.expectEqual(WidgetControlIntentKind.select, grouped_radio_move.kind);
|
|
511
|
+
try std.testing.expect(grouped_radio_move.actions.select);
|
|
512
|
+
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .radio, .text = "Annual", .state = .{ .selected = true } }, .{
|
|
513
|
+
.phase = .key_down,
|
|
514
|
+
.key = "home",
|
|
515
|
+
.radio_group_navigation = true,
|
|
516
|
+
}) == null);
|
|
517
|
+
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .radio, .text = "Bare" }, .{
|
|
518
|
+
.phase = .key_down,
|
|
519
|
+
.key = "arrowright",
|
|
520
|
+
.focus_moved = true,
|
|
521
|
+
}) == null);
|
|
522
|
+
|
|
478
523
|
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .button, .text = "Save" }, .{ .phase = .key_down, .key = "enter", .modifiers = .{ .super = true } }) == null);
|
|
479
524
|
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .button, .text = "Save", .state = .{ .disabled = true } }, .{ .phase = .key_down, .key = "enter" }) == null);
|
|
480
525
|
try std.testing.expect(widgetKeyboardControlIntent(.{ .kind = .button, .text = "Save" }, .{ .phase = .key_up, .key = "enter" }) == null);
|
|
@@ -712,6 +757,26 @@ test "widget keyboard events map to text edit events" {
|
|
|
712
757
|
try std.testing.expectEqualStrings("hello brave ", nav_state.text);
|
|
713
758
|
try std.testing.expectEqualDeep(TextSelection.collapsed(12), nav_state.selection);
|
|
714
759
|
|
|
760
|
+
const command_backspace = (WidgetKeyboardEvent{ .phase = .key_down, .key = "backspace", .modifiers = .{ .super = true } }).textEditEvent();
|
|
761
|
+
if (comptime @import("builtin").os.tag == .macos) {
|
|
762
|
+
try std.testing.expectEqual(TextInputEvent.delete_to_line_start, command_backspace.?);
|
|
763
|
+
} else {
|
|
764
|
+
try std.testing.expect(command_backspace == null);
|
|
765
|
+
}
|
|
766
|
+
const shifted_command_backspace = (WidgetKeyboardEvent{ .phase = .key_down, .key = "backspace", .modifiers = .{ .super = true, .shift = true } }).textEditEvent();
|
|
767
|
+
if (comptime @import("builtin").os.tag == .macos) {
|
|
768
|
+
try std.testing.expectEqual(TextInputEvent.delete_to_line_start, shifted_command_backspace.?);
|
|
769
|
+
} else {
|
|
770
|
+
try std.testing.expect(shifted_command_backspace == null);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const folded_control_backspace = (WidgetKeyboardEvent{ .phase = .key_down, .key = "backspace", .modifiers = .{ .super = true, .control = true } }).textEditEvent();
|
|
774
|
+
if (comptime @import("builtin").os.tag == .macos) {
|
|
775
|
+
try std.testing.expect(folded_control_backspace == null);
|
|
776
|
+
} else {
|
|
777
|
+
try std.testing.expectEqual(TextInputEvent.delete_word_backward, folded_control_backspace.?);
|
|
778
|
+
}
|
|
779
|
+
|
|
715
780
|
nav_state = TextEditState{ .text = "hello brave world", .selection = TextSelection.collapsed(0) };
|
|
716
781
|
const control_delete = (WidgetKeyboardEvent{ .phase = .key_down, .key = "delete", .modifiers = .{ .control = true } }).textEditEvent().?;
|
|
717
782
|
nav_state = try nav_state.apply(control_delete, &nav_storage);
|