Skip to content

Commit ce46e36

Browse files
committed
Move C imports to Zig module
1 parent 5b7f300 commit ce46e36

File tree

5 files changed

+23
-36
lines changed

5 files changed

+23
-36
lines changed

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ function build_zig {
202202
-mcpu cortex_a53 \
203203
\
204204
-isystem "../nuttx/include" \
205+
-I . \
205206
-I "../apps/include" \
206207
-I "../apps/graphics/lvgl" \
207208
-I "../apps/graphics/lvgl/lvgl/src/core" \

feature-phone.wasm

-4.35 KB
Binary file not shown.

feature-phone.zig

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,14 @@
33
/// Import the Zig Standard Library
44
const std = @import("std");
55

6-
/// Import the LVGL Module
7-
const lvgl = @import("lvgl.zig");
8-
96
/// Import the WebAssembly Logger
107
const wasmlog = @import("wasmlog.zig");
118

9+
/// Import the LVGL Module
10+
const lvgl = @import("lvgl.zig");
11+
1212
/// Import the LVGL Library from C
13-
const c = @cImport({
14-
// NuttX Defines
15-
@cDefine("__NuttX__", "");
16-
@cDefine("NDEBUG", "");
17-
18-
// NuttX Header Files
19-
@cInclude("arch/types.h");
20-
@cInclude("../../nuttx/include/limits.h");
21-
@cInclude("stdio.h");
22-
@cInclude("nuttx/config.h");
23-
@cInclude("sys/boardctl.h");
24-
@cInclude("unistd.h");
25-
@cInclude("stddef.h");
26-
@cInclude("stdlib.h");
27-
28-
// LVGL Header Files
29-
@cInclude("lvgl/lvgl.h");
30-
31-
// LVGL Display Interface for Zig
32-
@cInclude("display.h");
33-
});
13+
const c = lvgl.c;
3414

3515
///////////////////////////////////////////////////////////////////////////////
3616
// Main Function
@@ -158,14 +138,11 @@ fn createWidgets() !void {
158138

159139
/// Create the Display Label
160140
fn createDisplayLabel(cont: *c.lv_obj_t) !void {
161-
// TODO: Create the Label inside the Container
162-
_ = cont;
163-
164-
// Get the Active Screen
165-
var screen = try lvgl.getActiveScreen();
141+
// Get the Container
142+
var container = lvgl.Object.init(cont);
166143

167144
// Create a Label Widget
168-
var label = try screen.createLabel();
145+
var label = try container.createLabel();
169146

170147
// Wrap long lines in the label text
171148
label.setLongMode(c.LV_LABEL_LONG_WRAP);
@@ -185,8 +162,8 @@ fn createDisplayLabel(cont: *c.lv_obj_t) !void {
185162
// Set the label width
186163
label.setWidth(200);
187164

188-
// Align the label to the top middle of the screen
189-
label.alignObject(c.LV_ALIGN_TOP_MID, 0, 20);
165+
// Align the label to the top middle
166+
label.alignObject(c.LV_ALIGN_TOP_MID, 0, 0);
190167
}
191168

192169
/// Create the Call and Cancel Buttons

lvgl.zig

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@
44
const std = @import("std");
55

66
/// Import the LVGL Library from C
7-
const c = @cImport({
7+
pub const c = @cImport({
88
// NuttX Defines
9-
@cDefine("__NuttX__", "");
10-
@cDefine("NDEBUG", "");
9+
@cDefine("__NuttX__", "");
10+
@cDefine("NDEBUG", "");
1111

1212
// NuttX Header Files
1313
@cInclude("arch/types.h");
1414
@cInclude("../../nuttx/include/limits.h");
15+
@cInclude("stdio.h");
16+
@cInclude("nuttx/config.h");
17+
@cInclude("sys/boardctl.h");
18+
@cInclude("unistd.h");
19+
@cInclude("stddef.h");
20+
@cInclude("stdlib.h");
1521

1622
// LVGL Header Files
1723
@cInclude("lvgl/lvgl.h");
24+
25+
// LVGL Display Interface for Zig
26+
@cInclude("display.h");
1827
});
1928

2029
/// Return the Active Screen
@@ -106,4 +115,4 @@ pub const Label = struct {
106115
};
107116

108117
/// LVGL Errors
109-
pub const LvglError = error{ UnknownError };
118+
pub const LvglError = error{UnknownError};

lvglwasm.wasm

-58 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)