Skip to content

Commit

Permalink
wasm: add support for Window.on_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
zenith391 committed Oct 29, 2024
1 parent ddfa942 commit eb2785c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/backends/wasm/backend.zig
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ pub fn runStep(step: shared.EventLoopStep) bool {
.UpdateAudio => {
lib.audio.backendUpdate();
},
.WindowTick => {
if (@import("Window.zig").globalWindow) |window| {
if (window.peer.user.propertyChangeHandler) |handler| {
const value: u64 = 0;
handler("tick_id", &value, window.peer.userdata);
}
}
},
else => {
if (@import("Window.zig").globalWindow) |window| {
if (window.child) |child| {
Expand Down
6 changes: 6 additions & 0 deletions src/backends/wasm/capy.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,12 @@ async function loadExtras() {
}
drawCommands = [];

// send window tick event
pushEvent({
type: 8,
args: [],
});

requestAnimationFrame(update);
}
//setInterval(update, 32);
Expand Down
2 changes: 1 addition & 1 deletion src/backends/wasm/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn Events(comptime T: type) type {
handler(dx, dy, self.peer.userdata);
}
},
.UpdateAudio => unreachable,
.UpdateAudio, .WindowTick => unreachable,
.PropertyChange => {
if (self.peer.user.propertyChangeHandler) |handler| {
const value_f32 = js.getValue(self.peer.element);
Expand Down
1 change: 1 addition & 0 deletions src/backends/wasm/js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const EventType = enum(usize) {
MouseScroll,
UpdateAudio,
PropertyChange,
WindowTick,
};

pub extern fn jsPrint(msg: [*]const u8, len: usize) void;
Expand Down

0 comments on commit eb2785c

Please sign in to comment.