table_demo.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. local table_demo = {}
  2. function table_demo.demo()
  3. local table = lvgl.table_create(lvgl.scr_act(), nil);
  4. lvgl.table_set_col_cnt(table, 2);
  5. lvgl.table_set_row_cnt(table, 4);
  6. lvgl.obj_align(table, nil, lvgl.ALIGN_CENTER, 0, 0);
  7. --Make the cells of the first row center aligned
  8. lvgl.table_set_cell_align(table, 0, 0, lvgl.LABEL_ALIGN_CENTER);
  9. lvgl.table_set_cell_align(table, 0, 1, lvgl.LABEL_ALIGN_CENTER);
  10. --Align the price values to the right in the 2nd column
  11. lvgl.table_set_cell_align(table, 1, 1, lvgl.LABEL_ALIGN_RIGHT);
  12. lvgl.table_set_cell_align(table, 2, 1, lvgl.LABEL_ALIGN_RIGHT);
  13. lvgl.table_set_cell_align(table, 3, 1, lvgl.LABEL_ALIGN_RIGHT);
  14. lvgl.table_set_cell_type(table, 0, 0, 2);
  15. lvgl.table_set_cell_type(table, 0, 1, 2);
  16. --Fill the first column
  17. lvgl.table_set_cell_value(table, 0, 0, "Name");
  18. lvgl.table_set_cell_value(table, 1, 0, "Apple");
  19. lvgl.table_set_cell_value(table, 2, 0, "Banana");
  20. lvgl.table_set_cell_value(table, 3, 0, "Citron");
  21. --Fill the second column
  22. lvgl.table_set_cell_value(table, 0, 1, "Price");
  23. lvgl.table_set_cell_value(table, 1, 1, "$7");
  24. lvgl.table_set_cell_value(table, 2, 1, "$4");
  25. lvgl.table_set_cell_value(table, 3, 1, "$6");
  26. end
  27. return table_demo