Skip to content

Commit 7eb99b6

Browse files
committed
Add buttons
1 parent 1be67ea commit 7eb99b6

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

feature-phone.wasm

3.57 KB
Binary file not shown.

feature-phone.zig

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub export fn lv_demo_widgets() void {
6868

6969
// Register the Input Device
7070
// https://docs.lvgl.io/8.3/porting/indev.html
71+
indev_drv = std.mem.zeroes(c.lv_indev_drv_t);
7172
c.lv_indev_drv_init(&indev_drv);
7273
indev_drv.type = c.LV_INDEV_TYPE_POINTER;
7374
indev_drv.read_cb = readInput;
@@ -138,7 +139,7 @@ fn createWidgetsWrapped() !void {
138139
label.alignObject(c.LV_ALIGN_CENTER, 0, -30);
139140

140141
// Create a Button Widget
141-
createButton();
142+
createButtons();
142143
}
143144

144145
/// Create the LVGL Widgets that will be rendered on the display. Calls the
@@ -176,15 +177,39 @@ fn createWidgetsUnwrapped() !void {
176177
c.lv_obj_align(label, c.LV_ALIGN_CENTER, 0, -30);
177178

178179
// Create a Button Widget
179-
createButton();
180+
createButtons();
180181
}
181182

182183
/// Create an LVGL Button
183184
/// https://docs.lvgl.io/8.3/examples.html#simple-buttons
184-
fn createButton() void {
185+
fn createButtons() void {
186+
style = std.mem.zeroes(c.lv_style_t);
187+
c.lv_style_init(&style);
188+
c.lv_style_set_flex_flow(&style, c.LV_FLEX_FLOW_ROW_WRAP);
189+
c.lv_style_set_flex_main_place(&style, c.LV_FLEX_ALIGN_SPACE_EVENLY);
190+
c.lv_style_set_layout(&style, c.LV_LAYOUT_FLEX);
191+
192+
const cont = c.lv_obj_create(c.lv_scr_act());
193+
c.lv_obj_set_size(cont, 700, 1000);
194+
c.lv_obj_center(cont);
195+
c.lv_obj_add_style(cont, &style, 0);
196+
197+
var i: usize = 0;
198+
while (i < 12) : (i += 1) {
199+
const obj = c.lv_obj_create(cont);
200+
c.lv_obj_set_size(obj, 150, c.LV_SIZE_CONTENT);
201+
c.lv_obj_add_flag(obj, c.LV_OBJ_FLAG_CHECKABLE);
202+
_ = c.lv_obj_add_event_cb(obj, eventHandler, c.LV_EVENT_ALL, null);
203+
204+
const label = c.lv_label_create(obj);
205+
//c.lv_label_set_text_fmt(label, "%"LV_PRIu32, i);
206+
c.lv_label_set_text(label, "0");
207+
c.lv_obj_center(label);
208+
}
209+
185210
const btn = c.lv_btn_create(c.lv_scr_act());
186211
_ = c.lv_obj_add_event_cb(btn, eventHandler, c.LV_EVENT_ALL, null);
187-
c.lv_obj_align(btn, c.LV_ALIGN_CENTER, 0, 40);
212+
c.lv_obj_align(btn, c.LV_ALIGN_TOP_MID, 0, 40);
188213
c.lv_obj_add_flag(btn, c.LV_OBJ_FLAG_CHECKABLE);
189214

190215
const label = c.lv_label_create(btn);
@@ -204,6 +229,9 @@ export fn eventHandler(e: ?*c.lv_event_t) void {
204229
}
205230
}
206231

232+
/// LVGL Button Style (std.mem.zeroes crashes the compiler)
233+
var style: c.lv_style_t = undefined;
234+
207235
///////////////////////////////////////////////////////////////////////////////
208236
// LVGL Input
209237

@@ -256,22 +284,8 @@ var input_state: c.lv_indev_state_t = 0;
256284
var input_x: c.lv_coord_t = 0;
257285
var input_y: c.lv_coord_t = 0;
258286

259-
/// LVGL Input Device Driver
260-
/// TODO: std.mem.zeroes crashes the compiler
261-
var indev_drv = c.lv_indev_drv_t{
262-
.type = 0,
263-
.read_cb = null,
264-
.feedback_cb = null,
265-
.user_data = null,
266-
.disp = null,
267-
.read_timer = null,
268-
.scroll_limit = 0,
269-
.scroll_throw = 0,
270-
.gesture_min_velocity = 0,
271-
.gesture_limit = 0,
272-
.long_press_time = 0,
273-
.long_press_repeat_time = 0,
274-
};
287+
/// LVGL Input Device Driver (std.mem.zeroes crashes the compiler)
288+
var indev_drv: c.lv_indev_drv_t = undefined;
275289

276290
///////////////////////////////////////////////////////////////////////////////
277291
// LVGL Porting Layer for WebAssembly

0 commit comments

Comments
 (0)