Skip to content

Commit 35cc0b7

Browse files
committed
Button Click is OK yay!
1 parent bf3f2ab commit 35cc0b7

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ function build_zig {
103103
-DLV_USE_LOG=1 \
104104
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
105105
-DLV_LOG_TRACE_OBJ_CREATE=1 \
106-
-DLV_LOG_TRACE_TIMER=1 \
107106
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
108107
-I . \
109108
\
@@ -248,7 +247,6 @@ function compile_lvgl {
248247
-DLV_USE_LOG=1 \
249248
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
250249
-DLV_LOG_TRACE_OBJ_CREATE=1 \
251-
-DLV_LOG_TRACE_TIMER=1 \
252250
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
253251
\
254252
-c \
@@ -309,7 +307,6 @@ function build_feature_phone {
309307
-DLV_USE_LOG=1 \
310308
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
311309
-DLV_LOG_TRACE_OBJ_CREATE=1 \
312-
-DLV_LOG_TRACE_TIMER=1 \
313310
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
314311
-I . \
315312
\

feature-phone.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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");
7374
const imageData = context.createImageData(canvas.width, canvas.height);
7475
context.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
7798
function 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

feature-phone.wasm

18.2 KB
Binary file not shown.

feature-phone.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ fn createButton() void {
198198
/// https://docs.lvgl.io/8.3/examples.html#simple-buttons
199199
export fn eventHandler(e: ?*c.lv_event_t) void {
200200
const code = c.lv_event_get_code(e);
201+
// debug("eventHandler: code={}", .{code});
201202
if (code == c.LV_EVENT_CLICKED) {
202203
debug("eventHandler: clicked", .{});
203204
} else if (code == c.LV_EVENT_VALUE_CHANGED) {
@@ -238,6 +239,7 @@ export fn readInput(drv: [*c]c.lv_indev_drv_t, data: [*c]c.lv_indev_data_t) void
238239
if (input_updated) {
239240
input_updated = false;
240241
c.set_input_data(data, input_state, input_x, input_y);
242+
debug("readInput: state={}, x={}, y={}", .{ input_state, input_x, input_y });
241243
}
242244
}
243245

lvglwasm.wasm

-743 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)