@@ -68,6 +68,7 @@ pub export fn lv_demo_widgets() void {
68
68
69
69
// Register the Input Device
70
70
// https://docs.lvgl.io/8.3/porting/indev.html
71
+ indev_drv = std .mem .zeroes (c .lv_indev_drv_t );
71
72
c .lv_indev_drv_init (& indev_drv );
72
73
indev_drv .type = c .LV_INDEV_TYPE_POINTER ;
73
74
indev_drv .read_cb = readInput ;
@@ -138,7 +139,7 @@ fn createWidgetsWrapped() !void {
138
139
label .alignObject (c .LV_ALIGN_CENTER , 0 , -30 );
139
140
140
141
// Create a Button Widget
141
- createButton ();
142
+ createButtons ();
142
143
}
143
144
144
145
/// Create the LVGL Widgets that will be rendered on the display. Calls the
@@ -176,15 +177,39 @@ fn createWidgetsUnwrapped() !void {
176
177
c .lv_obj_align (label , c .LV_ALIGN_CENTER , 0 , -30 );
177
178
178
179
// Create a Button Widget
179
- createButton ();
180
+ createButtons ();
180
181
}
181
182
182
183
/// Create an LVGL Button
183
184
/// 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
+
185
210
const btn = c .lv_btn_create (c .lv_scr_act ());
186
211
_ = 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 );
188
213
c .lv_obj_add_flag (btn , c .LV_OBJ_FLAG_CHECKABLE );
189
214
190
215
const label = c .lv_label_create (btn );
@@ -204,6 +229,9 @@ export fn eventHandler(e: ?*c.lv_event_t) void {
204
229
}
205
230
}
206
231
232
+ /// LVGL Button Style (std.mem.zeroes crashes the compiler)
233
+ var style : c.lv_style_t = undefined ;
234
+
207
235
///////////////////////////////////////////////////////////////////////////////
208
236
// LVGL Input
209
237
@@ -256,22 +284,8 @@ var input_state: c.lv_indev_state_t = 0;
256
284
var input_x : c.lv_coord_t = 0 ;
257
285
var input_y : c.lv_coord_t = 0 ;
258
286
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 ;
275
289
276
290
///////////////////////////////////////////////////////////////////////////////
277
291
// LVGL Porting Layer for WebAssembly
0 commit comments