#include "lvgl.h" #include #include #define SCREEN_W 1024 #define SCREEN_H 600 #define TOTAL_ROWS 50 #define VISIBLE_ROWS 15 #define COL_CNT 6 /* Dynamic Row 7 Data */ typedef struct { int vol; int temp; int res; } row_data_t; static row_data_t row7_data = {1,1,601}; /* Row height */ static lv_coord_t ROW_H; /* Column character width, used to fill the whole screen (monospaced font) */ static int col_chars[COL_CNT] = {6, 12, 12, 12, 10, 30}; /* ===== Generate row text with spacing for columns ===== */ static void get_row_text_str(int row, char * buf, int len) { char temp[128]; char name[16]; if(row == 6) { snprintf(temp, sizeof(temp), "%-*s %-*s %-*d %-*d %-*d %-*s", col_chars[0], "7", col_chars[1], "BT007", col_chars[2], row7_data.vol, col_chars[3], row7_data.temp, col_chars[4], row7_data.res, col_chars[5], "2025-12-17 17:05"); } else { snprintf(name, sizeof(name), "BT%03d", row+1); snprintf(temp, sizeof(temp), "%-*d %-*s %-*d %-*d %-*d %-*s", col_chars[0], row+1, col_chars[1], name, col_chars[2], 12+row, col_chars[3], 20+row, col_chars[4], 601+row, col_chars[5], "2025-12-17 17:05"); } strncpy(buf, temp, len-1); buf[len-1] = 0; } /* ===== Array to store label objects ===== */ static lv_obj_t * label_rows[TOTAL_ROWS]; /* ===== Update Row 7 ===== */ static void update_row7_label(void) { char buf[128]; get_row_text_str(6, buf, sizeof(buf)); lv_label_set_text(label_rows[6], buf); } /* ===== Timer callback for Row 7 dynamic update ===== */ static void row7_timer_cb(lv_timer_t * t) { row7_data.vol++; row7_data.temp++; row7_data.res++; update_row7_label(); } /* ===== Main demo function ===== */ void demo_label_table(void) { lv_obj_t * scr = lv_scr_act(); lv_obj_clean(scr); /* Calculate row height to show VISIBLE_ROWS rows */ ROW_H = SCREEN_H / VISIBLE_ROWS; /* Create scrollable container */ lv_obj_t * cont = lv_obj_create(scr); lv_obj_set_size(cont, SCREEN_W, SCREEN_H); lv_obj_set_scroll_dir(cont, LV_DIR_VER); lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_AUTO); /* Create 50 label rows */ for(int r=0; r