update asserts

This commit is contained in:
Gabor Kiss-Vamosi
2021-02-08 09:53:03 +01:00
parent 956a367dbc
commit 7bec13c2b9
173 changed files with 4906 additions and 696 deletions

View File

@@ -0,0 +1,66 @@
#include "../../../lvgl.h"
#if LV_USE_TABLE
static void event_cb(lv_obj_t * obj, lv_event_t e)
{
if(e == LV_EVENT_DRAW_PART_BEGIN) {
lv_obj_draw_hook_dsc_t * hook_dsc = lv_event_get_param();
/*If the cells are drawn...*/
if(hook_dsc->part == LV_PART_ITEMS) {
uint32_t row = hook_dsc->id / lv_table_get_col_cnt(obj);
uint32_t col = hook_dsc->id - row * lv_table_get_col_cnt(obj);
/*Make the texts in the first cell center aligned*/
if(row == 0) {
hook_dsc->label_dsc->align = LV_TEXT_ALIGN_CENTER;
hook_dsc->rect_dsc->bg_color = lv_color_mix(LV_COLOR_BLUE, hook_dsc->rect_dsc->bg_color, LV_OPA_20);
hook_dsc->rect_dsc->bg_opa = LV_OPA_COVER;
}
/*In the first column align the texts to the right*/
else if(col == 0) {
hook_dsc->label_dsc->flag = LV_TEXT_ALIGN_RIGHT;
}
/*MAke every 2nd row grayish*/
if((row != 0 && row % 2) == 0) {
hook_dsc->rect_dsc->bg_color = lv_color_mix(LV_COLOR_GRAY, hook_dsc->rect_dsc->bg_color, LV_OPA_10);
hook_dsc->rect_dsc->bg_opa = LV_OPA_COVER;
}
}
}
}
void lv_example_table_1(void)
{
lv_obj_t * table = lv_table_create(lv_scr_act(), NULL);
/*Fill the first column*/
lv_table_set_cell_value(table, 0, 0, "Name");
lv_table_set_cell_value(table, 1, 0, "Apple");
lv_table_set_cell_value(table, 2, 0, "Banana");
lv_table_set_cell_value(table, 3, 0, "Lemon");
lv_table_set_cell_value(table, 4, 0, "Grape");
lv_table_set_cell_value(table, 5, 0, "Melon");
lv_table_set_cell_value(table, 6, 0, "Peach");
lv_table_set_cell_value(table, 7, 0, "Nuts");
/*Fill the second column*/
lv_table_set_cell_value(table, 0, 1, "Price");
lv_table_set_cell_value(table, 1, 1, "$7");
lv_table_set_cell_value(table, 2, 1, "$4");
lv_table_set_cell_value(table, 3, 1, "$6");
lv_table_set_cell_value(table, 4, 1, "$2");
lv_table_set_cell_value(table, 5, 1, "$5");
lv_table_set_cell_value(table, 6, 1, "$1");
lv_table_set_cell_value(table, 7, 1, "$9");
/*Set a smaller height to the table. It'll make it scrollable*/
lv_obj_set_height(table, 200);
lv_obj_align(table, NULL, LV_ALIGN_CENTER, 0, 0);
/*Add an event callback to to apply some custom drawing*/
lv_obj_add_event_cb(table, event_cb, NULL);
}
#endif

View File

@@ -0,0 +1,41 @@
# Create a normal cell style
style_cell1 = lv.style_t()
lv.style_copy(style_cell1, lv.style_plain)
style_cell1.body.border.width = 1
style_cell1.body.border.color = lv.color_make(0,0,0)
# Crealte a header cell style
style_cell2 = lv.style_t()
lv.style_copy(style_cell2, lv.style_plain)
style_cell2.body.border.width = 1
style_cell2.body.border.color = lv.color_make(0,0,0)
style_cell2.body.main_color = lv.color_make(0xC0, 0xC0, 0xC0)
style_cell2.body.grad_color = lv.color_make(0xC0, 0xC0, 0xC0)
table = lv.table(lv.scr_act())
table.set_style(lv.table.STYLE.CELL1, style_cell1)
table.set_style(lv.table.STYLE.CELL2, style_cell2)
table.set_style(lv.table.STYLE.BG, lv.style_transp_tight)
table.set_col_cnt(2)
table.set_row_cnt(4)
table.align(None, lv.ALIGN.CENTER, 0, 0)
# Make the cells of the first row center aligned
table.set_cell_align(0, 0, lv.label.ALIGN.CENTER)
table.set_cell_align(0, 1, lv.label.ALIGN.CENTER)
# Make the cells of the first row TYPE = 2 (use `style_cell2`)
table.set_cell_type(0, 0, 2)
table.set_cell_type(0, 1, 2)
# Fill the first column
table.set_cell_value(0, 0, "Name")
table.set_cell_value(1, 0, "Apple")
table.set_cell_value(2, 0, "Banana")
table.set_cell_value(3, 0, "Citron")
# Fill the second column
table.set_cell_value(0, 1, "Price")
table.set_cell_value(1, 1, "$7")
table.set_cell_value(2, 1, "$4")
table.set_cell_value(3, 1, "$6")