╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ main_wasm.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
177 _consoleLog(arg.ptr, @intCast(arg.len)); 178 } 179 180 extern fn _consoleLog(arg: [*]const u8, len: u32) void; 181 extern fn _setHtml(arg: [*]const u8, len: u32) void; 182 extern fn _replaceState(arg: [*]const u8, len: u32) void; 183 extern fn _focusInput(focus_id: u32) void; 184 extern fn _navigate(arg: [*]const u8, len: u32) void; 185 extern fn _scrollToFocus(focus_id: u32) void; 186 /// js calls this first to get a wasm pointer it can write the page json into. 187 export fn _alloc(len: u32) ?[*]u8 { 188 const slice = allocator.alloc(u8, len) catch return null; 189 return slice.ptr; 190 } 191 192 export fn _init(json_ptr: [*]u8, json_len: u32, min_height: u32, max_width: u32) void { 193 const json = json_ptr[0..json_len]; 194 defer allocator.free(json); 195 init(json, min_height, max_width) catch |err| { 196 var buf: [256]u8 = undefined; 197 const str = std.fmt.bufPrint(&buf, "init: {}", .{err}) catch unreachable; 198 consoleLog(str); 199 }; 200 } 201 202 export fn _tick(min_height: u32, max_width: u32) bool { 203 tick(min_height, max_width) catch |err| { 204 var buf: [256]u8 = undefined; 205 const str = std.fmt.bufPrint(&buf, "tick: {}", .{err}) catch unreachable; 206 consoleLog(str); 207 return false; 208 }; 209 return true; 210 } 211 212 export fn _onKeyDown(key_code: u32) void { 213 onKeyDown(key_code) catch |err| { 214 var buf: [256]u8 = undefined; 215 const str = std.fmt.bufPrint(&buf, "onKeyDown: {}", .{err}) catch unreachable; 216 consoleLog(str); 217 }; 218 } 219 220 export fn _onMouseClick(focus_id: u32) void { 221 onMouseClick(focus_id) catch |err| { 222 var buf: [256]u8 = undefined; 223 const str = std.fmt.bufPrint(&buf, "onMouseClick: {}", .{err}) catch unreachable; 224 consoleLog(str); 225 }; 226 } 227 228 export fn _setFocus(focus_id: u32) void { 229 setFocus(focus_id) catch |err| { 230 var buf: [256]u8 = undefined; 231 const str = std.fmt.bufPrint(&buf, "setFocus: {}", .{err}) catch unreachable; 232 consoleLog(str); 233 }; 234 } 235 236 // js calls this when the value of a native <input> changes; we replace 237 // the matching TextInput's content with the supplied utf-8 bytes. 238 export fn _setTextInputValue(focus_id: u32, value_ptr: [*]const u8, value_len: u32) void { 239 setTextInputValue(focus_id, value_ptr[0..value_len]) catch |err| { 240 var buf: [256]u8 = undefined; 241 const str = std.fmt.bufPrint(&buf, "setTextInputValue: {}", .{err}) catch unreachable; 242 consoleLog(str); 243 }; 244 } 245 246 fn setTextInputValue(focus_id: u32, bytes: []const u8) !void { 247 const root_ptr = if (root) |*r| r else return error.NotStarted; 248 const root_focus = root_ptr.getFocus(); 249 const child = root_focus.children.get(focus_id) orelse return error.UnknownFocusId; 250 switch (child.focus.kind) { 251 .text_input, .text_input_password, .text_area => {}, 252 else => return error.NotATextInput, 253 } 254 const ti = session.text_inputs.get(focus_id) orelse return error.UnknownFocusId; 255 try ti.setContent(allocator, bytes); 256 } 257