╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ main_wasm.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
136 extern fn _focusInput(focus_id: u32) void; 137 138 /// js calls this first to get a wasm pointer it can write the page json into. 139 export fn _alloc(len: u32) ?[*]u8 { 140 const slice = allocator.alloc(u8, len) catch return null; 141 return slice.ptr; 142 } 143 144 export fn _init(json_ptr: [*]u8, json_len: u32, min_height: u32, max_width: u32) void { 145 const json = json_ptr[0..json_len]; 146 defer allocator.free(json); 147 init(json, min_height, max_width) catch |err| { 148 var buf: [256]u8 = undefined; 149 const str = std.fmt.bufPrint(&buf, "init: {}", .{err}) catch unreachable; 150 consoleLog(str); 151 }; 152 } 153 154 export fn _tick(min_height: u32, max_width: u32) bool { 155 tick(min_height, max_width) catch |err| { 156 var buf: [256]u8 = undefined; 157 const str = std.fmt.bufPrint(&buf, "tick: {}", .{err}) catch unreachable; 158 consoleLog(str); 159 return false; 160 }; 161 return true; 162 } 163 164 export fn _onKeyDown(key_code: u32) void { 165 onKeyDown(key_code) catch |err| { 166 var buf: [256]u8 = undefined; 167 const str = std.fmt.bufPrint(&buf, "onKeyDown: {}", .{err}) catch unreachable; 168 consoleLog(str); 169 }; 170 } 171 172 export fn _onMouseClick(focus_id: u32) void { 173 onMouseClick(focus_id) catch |err| { 174 var buf: [256]u8 = undefined; 175 const str = std.fmt.bufPrint(&buf, "onMouseClick: {}", .{err}) catch unreachable; 176 consoleLog(str); 177 }; 178 } 179 180 // js calls this when the value of an overlay <input> changes; we replace 181 // the matching TextInput's content with the supplied utf-8 bytes. 182 export fn _setTextInputValue(focus_id: u32, value_ptr: [*]const u8, value_len: u32) void { 183 setTextInputValue(focus_id, value_ptr[0..value_len]) catch |err| { 184 var buf: [256]u8 = undefined; 185 const str = std.fmt.bufPrint(&buf, "setTextInputValue: {}", .{err}) catch unreachable; 186 consoleLog(str); 187 }; 188 } 189 190 fn setTextInputValue(focus_id: u32, bytes: []const u8) !void { 191 const root_ptr = if (root) |*r| r else return error.NotStarted; 192 const root_focus = root_ptr.getFocus(); 193 const child = root_focus.children.get(focus_id) orelse return error.UnknownFocusId; 194 switch (child.focus.kind) { 195 .text_input, .text_input_password => {}, 196 else => return error.NotATextInput, 197 } 198 const ti: *wgt.TextInput(ui.Widget) = @fieldParentPtr("focus", child.focus); 199 try ti.setContent(allocator, bytes); 200 // mirror the TTY behavior in Login.View.input: editing an input clears 201 // the stale failure flag so the "(invalid)" label doesn't linger after 202 // the user has typed a correction 203 session.data.login_failure = null; 204 } 205