@@ -36,7 +36,8 @@ const importObject = {
3636
3737 // Get the WebAssembly Pointer to the LVGL Canvas Buffer
3838 console . log ( "render: start" ) ;
39- const bufferOffset = wasm . instance . exports . getCanvasBuffer ( ) ;
39+ const bufferOffset = wasm . instance . exports
40+ . getCanvasBuffer ( ) ;
4041 console . log ( { bufferOffset } ) ;
4142
4243 // Load the WebAssembly Pointer into a JavaScript Image Data
@@ -73,13 +74,34 @@ const context = canvas.getContext("2d");
7374const imageData = context . createImageData ( canvas . width , canvas . height ) ;
7475context . clearRect ( 0 , 0 , canvas . width , canvas . height ) ;
7576
77+ // Handle Mouse Down on HTML Canvas
78+ canvas . addEventListener ( "mousedown" , ( e ) => {
79+ // Notify Zig of Mouse Down
80+ const x = e . offsetX ;
81+ const y = e . offsetY ;
82+ console . log ( { mousedown : { x, y} } ) ;
83+ wasm . instance . exports
84+ . notifyInput ( 1 , x , y ) ;
85+ } ) ;
86+
87+ // Handle Mouse Up on HTML Canvas
88+ canvas . addEventListener ( "mouseup" , ( e ) => {
89+ // Notify Zig of Mouse Up
90+ x = e . offsetX ;
91+ y = e . offsetY ;
92+ console . log ( { mouseup : { x, y} } ) ;
93+ wasm . instance . exports
94+ . notifyInput ( 0 , x , y ) ;
95+ } ) ;
96+
7697// Main Function
7798function main ( ) {
7899 console . log ( "main: start" ) ;
79100 const start_ms = Date . now ( ) ;
80101
81102 // Render the LVGL Widgets in Zig
82- wasm . instance . exports . lv_demo_widgets ( ) ;
103+ wasm . instance . exports
104+ . lv_demo_widgets ( ) ;
83105
84106 // Render Loop
85107 const loop = function ( ) {
@@ -88,11 +110,12 @@ function main() {
88110 const elapsed_ms = Date . now ( ) - start_ms ;
89111
90112 // Handle LVGL Tasks to update the display
91- wasm . instance . exports . handleTimer ( elapsed_ms ) ;
113+ wasm . instance . exports
114+ . handleTimer ( elapsed_ms ) ;
92115
93116 // Loop to next frame
94- // TODO: window.requestAnimationFrame(loop);
95- window . setTimeout ( loop , 1000 ) ;
117+ window . requestAnimationFrame ( loop ) ;
118+ // Previously: window.setTimeout(loop, 100 );
96119 } ;
97120
98121 // Start the Render Loop
0 commit comments