╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ main_wasm.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
222 const str = std.fmt.bufPrint(&buf, "onMouseClick: {}", .{err}) catch unreachable; 223 consoleLog(str); 224 }; 225 } 226 227 export fn _setFocus(focus_id: u32) void { 228 setFocus(focus_id) catch |err| { 229 var buf: [256]u8 = undefined; 230 const str = std.fmt.bufPrint(&buf, "setFocus: {}", .{err}) catch unreachable; 231 consoleLog(str); 232 }; 233 } 234 235 // js calls this when the value of a native <input> changes; we replace 236 // the matching TextInput's content with the supplied utf-8 bytes. 237 export fn _setTextInputValue(focus_id: u32, value_ptr: [*]const u8, value_len: u32) void { 238 setTextInputValue(focus_id, value_ptr[0..value_len]) catch |err| { 239 var buf: [256]u8 = undefined; 240 const str = std.fmt.bufPrint(&buf, "setTextInputValue: {}", .{err}) catch unreachable; 241 consoleLog(str); 242 }; 243 } 244 245 fn setTextInputValue(focus_id: u32, bytes: []const u8) !void { 246 const root_ptr = if (root) |*r| r else return error.NotStarted; 247 const root_focus = root_ptr.getFocus(); 248 const child = root_focus.children.get(focus_id) orelse return error.UnknownFocusId; 249 switch (child.focus.kind) { 250 .text_input, .text_input_password, .text_area => {}, 251 else => return error.NotATextInput, 252 } 253 const ti = session.text_inputs.get(focus_id) orelse return error.UnknownFocusId; 254 try ti.setContent(allocator, bytes); 255 } 256