diff --git a/examples/layouts/flex/lv_example_flex_1.c b/examples/layouts/flex/lv_example_flex_1.c index 3113f86a0..52c265318 100644 --- a/examples/layouts/flex/lv_example_flex_1.c +++ b/examples/layouts/flex/lv_example_flex_1.c @@ -1,43 +1,53 @@ -//#include "../../lv_examples.h" -// -///** -// * A simple row and a column layout with flexbox -// */ -//void lv_example_flex_1(void) -//{ -// /*Create a container with ROW flex direction*/ -// lv_obj_t * cont_row = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont_row, 300, 75); -// lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5); -// lv_obj_set_flex_dir(cont_row, LV_FLEX_DIR_ROW); -// lv_obj_set_flex_gap(cont_row, 10); -// -// /*Create a container with COLUMN flex direction*/ -// lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont_col, 200, 150); -// lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); -// lv_obj_set_flex_dir(cont_col, LV_FLEX_DIR_COLUMN); -// lv_obj_set_flex_gap(cont_col, 10); -// -// uint32_t i; -// for(i = 0; i < 10; i++) { -// /*Add items to the row*/ -// lv_obj_t * obj1 = lv_obj_create(cont_row, NULL); -// lv_obj_set_size(obj1, 100, LV_COORD_PCT(100)); -// lv_obj_set_flex_item(obj1, true); -// -// lv_obj_t * label1 = lv_label_create(obj1, NULL); -// lv_label_set_text_fmt(label1, "Item: %d", i); -// lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0); -// -// /*Add items to the column*/ -// lv_obj_t * obj2 = lv_obj_create(cont_col, NULL); -// lv_obj_set_size(obj2, LV_COORD_PCT(100), LV_SIZE_AUTO); -// lv_obj_set_flex_item(obj2, true); -// -// lv_obj_t * label3 = lv_label_create(obj2, NULL); -// lv_label_set_text_fmt(label3, "Item: %d", i); -// lv_obj_align(label3, NULL, LV_ALIGN_CENTER, 0, 0); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_FLEX + +/** + * A simple row and a column layout with flexbox + */ +void lv_example_flex_1(void) +{ + static lv_flex_t flex_row; + lv_flex_init(&flex_row); + lv_flex_set_flow(&flex_row, LV_FLEX_FLOW_ROW); + + static lv_flex_t flex_col; + lv_flex_init(&flex_col); + lv_flex_set_flow(&flex_col, LV_FLEX_FLOW_COLUMN); + + /*Create a container with ROW flex direction*/ + lv_obj_t * cont_row = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont_row, 300, 75); + lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5); + lv_obj_set_layout(cont_row, &flex_row); + + /*Create a container with COLUMN flex direction*/ + lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont_col, 200, 150); + lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); + lv_obj_set_layout(cont_col, &flex_col); + + uint32_t i; + for(i = 0; i < 10; i++) { + lv_obj_t * obj; + lv_obj_t * label; + + /*Add items to the row*/ + obj= lv_obj_create(cont_row, NULL); + lv_obj_set_size(obj, 100, LV_SIZE_PCT(100)); + + label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "Item: %d", i); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Add items to the column*/ + obj = lv_obj_create(cont_col, NULL); + lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_CONTENT); + + label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "Item: %d", i); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } +} + +#endif diff --git a/examples/layouts/flex/lv_example_flex_2.c b/examples/layouts/flex/lv_example_flex_2.c index 974475e05..3b45de1e9 100644 --- a/examples/layouts/flex/lv_example_flex_2.c +++ b/examples/layouts/flex/lv_example_flex_2.c @@ -1,24 +1,30 @@ -//#include "../../lv_examples.h" -// -///** -// * Arrange items in column with wrap and place the row to get even space around them. -// */ -//void lv_example_flex_2(void) -//{ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP); -// lv_obj_set_flex_place(cont, LV_FLEX_PLACE_START, LV_FLEX_PLACE_START); -// -// uint32_t i; -// for(i = 0; i < 3; i++) { -// lv_obj_t * obj = lv_obj_create(cont, NULL); -// lv_obj_set_flex_item_place(obj, LV_FLEX_PLACE_STRETCH); -// lv_obj_set_size(obj, 70, LV_SIZE_AUTO); -// -// lv_obj_t * label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "%d", i); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_FLEX + +/** + * Arrange items in rows with wrap and place the items to get even space around them. + */ +void lv_example_flex_2(void) +{ + static lv_flex_t flex_row_wrap; + lv_flex_init(&flex_row_wrap); + lv_flex_set_flow(&flex_row_wrap, LV_FLEX_FLOW_ROW_WRAP); + lv_flex_set_place(&flex_row_wrap, LV_FLEX_PLACE_SPACE_EVENLY, LV_FLEX_PLACE_START, LV_FLEX_PLACE_START); + + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &flex_row_wrap); + + uint32_t i; + for(i = 0; i < 8; i++) { + lv_obj_t * obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, 70, LV_SIZE_CONTENT); + + lv_obj_t * label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "%d", i); + } +} + +#endif diff --git a/examples/layouts/flex/lv_example_flex_3.c b/examples/layouts/flex/lv_example_flex_3.c index e31d079d9..f8a3726af 100644 --- a/examples/layouts/flex/lv_example_flex_3.c +++ b/examples/layouts/flex/lv_example_flex_3.c @@ -1,30 +1,31 @@ -//#include "../../lv_examples.h" -// -///** -// * Arrange items in a row and demonstrate flex grow. -// */ -//void lv_example_flex_3(void) -//{ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW); -// -// lv_obj_t * obj; -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, 20, 20); /*Fix size*/ -// lv_obj_set_flex_item(obj, true); -// -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, LV_FLEX_GROW(1), 30); /*1 portion from the free space*/ -// lv_obj_set_flex_item(obj, true); -// -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, LV_FLEX_GROW(2), 40); /*2 portion from the free space*/ -// lv_obj_set_flex_item(obj, true); -// -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, 20, 20); /*Fix size. It is flushed to the right by the "grow" items*/ -// lv_obj_set_flex_item(obj, true); -//} -// +#include "../../../lvgl.h" + +#if LV_USE_FLEX + +/** + * Use a built in flex layout and demonstrate flex grow. + */ +void lv_example_flex_3(void) +{ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &lv_flex_queue); + + lv_obj_t * obj; + obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, 20, 20); /*Fix size*/ + + obj = lv_obj_create(cont, NULL); + lv_obj_set_height(obj, 30); + lv_obj_set_flex_grow(obj, 1); /*1 portion from the free space*/ + + obj = lv_obj_create(cont, NULL); + lv_obj_set_height(obj, 40); + lv_obj_set_flex_grow(obj, 2); /*2 portion from the free space*/ + + obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, 20, 20); /*Fix size. It is flushed to the right by the "grow" items*/ +} + +#endif diff --git a/examples/layouts/flex/lv_example_flex_4.c b/examples/layouts/flex/lv_example_flex_4.c index 94726af58..2dd33e5ff 100644 --- a/examples/layouts/flex/lv_example_flex_4.c +++ b/examples/layouts/flex/lv_example_flex_4.c @@ -1,24 +1,30 @@ -//#include "../../lv_examples.h" -// -///** -// * Reverse the order of flex items -// */ -//void lv_example_flex_4(void) -//{ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP_REVERSE); -// lv_obj_set_flex_gap(cont, 10); -// -// uint32_t i; -// for(i = 0; i < 20; i++) { -// lv_obj_t * obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, 100, LV_SIZE_AUTO); -// lv_obj_set_flex_item(obj, true); -// -// lv_obj_t * label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "Item: %d", i); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_FLEX + +/** + * Reverse the order of flex items + */ +void lv_example_flex_4(void) +{ + + static lv_flex_t flex_col_rev; + lv_flex_init(&flex_col_rev); + lv_flex_set_flow(&flex_col_rev, LV_FLEX_FLOW_COLUMN_WRAP_REVERSE); + + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &flex_col_rev); + + uint32_t i; + for(i = 0; i < 6; i++) { + lv_obj_t * obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, 100, 30); + + lv_obj_t * label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "Item: %d", i); + } +} + +#endif diff --git a/examples/layouts/flex/lv_example_flex_5.c b/examples/layouts/flex/lv_example_flex_5.c index 17e16218c..fcf2db8f5 100644 --- a/examples/layouts/flex/lv_example_flex_5.c +++ b/examples/layouts/flex/lv_example_flex_5.c @@ -1,28 +1,52 @@ -//#include "../../lv_examples.h" -// -///** -// * Demonstrate the effect of margin on flex item -// */ -//void lv_example_flex_5(void) -//{ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW_WRAP); -// -// uint32_t i; -// for(i = 0; i < 20; i++) { -// lv_obj_t * obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, 100, LV_SIZE_AUTO); -// lv_obj_set_flex_item(obj, true); -// -// /*Set margin on every side*/ -// if(i == 4) { -// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 20); -// } -// -// lv_obj_t * label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "Item:%d", i); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_FLEX + +static void row_gap_anim(lv_obj_t * obj, lv_anim_value_t v) +{ + lv_obj_set_style_pad_row(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v); +} + +static void column_gap_anim(lv_obj_t * obj, lv_anim_value_t v) +{ + lv_obj_set_style_pad_column(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v); +} + +/** + * Demonstrate the effect of column and row gap style properties + */ +void lv_example_flex_5(void) +{ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &lv_flex_inline); + + uint32_t i; + for(i = 0; i < 9; i++) { + lv_obj_t * obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, 70, LV_SIZE_CONTENT); + + lv_obj_t * label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "%d", i); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } + + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, cont); + lv_anim_set_values(&a, 0, 10); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) row_gap_anim); + lv_anim_set_time(&a, 500); + lv_anim_set_playback_time(&a, 500); + lv_anim_start(&a); + + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) column_gap_anim); + lv_anim_set_time(&a, 3000); + lv_anim_set_playback_time(&a, 3000); + lv_anim_start(&a); +} + +#endif diff --git a/examples/layouts/flex/lv_example_flex_6.c b/examples/layouts/flex/lv_example_flex_6.c index 9bb07e6fb..d5d269486 100644 --- a/examples/layouts/flex/lv_example_flex_6.c +++ b/examples/layouts/flex/lv_example_flex_6.c @@ -1,25 +1,27 @@ -//#include "../../lv_examples.h" -// -///** -// * RTL base direction changes order of the items. -// */ -//void lv_example_flex_6(void) -//{ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP); -// -// uint32_t i; -// for(i = 0; i < 20; i++) { -// lv_obj_t * obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, 80, LV_SIZE_AUTO); -// lv_obj_set_flex_item(obj, true); -// -// lv_obj_t * label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "%d", i); -// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_FLEX + +/** + * RTL base direction changes order of the items. + * Also demonstrate how horizontal scrolling works with RTL. + */ +void lv_example_flex_6(void) +{ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &lv_flex_center_column); + + uint32_t i; + for(i = 0; i < 20; i++) { + lv_obj_t * obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, 70, LV_SIZE_CONTENT); + + lv_obj_t * label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "%d", i); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } +} +#endif diff --git a/examples/layouts/grid/lv_example_grid_1.c b/examples/layouts/grid/lv_example_grid_1.c index 81e3a0bf2..a24828875 100644 --- a/examples/layouts/grid/lv_example_grid_1.c +++ b/examples/layouts/grid/lv_example_grid_1.c @@ -1,39 +1,44 @@ -//#include "../../lv_examples.h" -// -///** -// * A simple grid -// */ -//void lv_example_grid_1(void) -//{ -// static lv_coord_t col_dsc[3] = {80, 80, 80}; -// static lv_coord_t row_dsc[3] = {60, 60, 60}; -// -// static lv_grid_t grid; -// lv_grid_init(&grid); -// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); -// -// /*Create a container with grid*/ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_grid(cont, &grid); -// -// lv_obj_t * label; -// lv_obj_t * obj; -// -// uint32_t i; -// for(i = 0; i < 9; i++) { -// uint8_t col = i % 3; -// uint8_t row = i / 3; -// -// obj = lv_obj_create(cont, NULL); -// /* Stretch the cell horizontally and vertically too -// * Set span to 1 to make the cell 1 column/row sized */ -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1)); -// -// label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "c%d, r%d", col, row); -// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_GRID + + +/** + * A simple grid + */ +void lv_example_grid_1(void) +{ + static lv_coord_t col_dsc[3] = {70, 70, 70}; + static lv_coord_t row_dsc[3] = {50, 50, 50}; + + static lv_grid_t grid; + lv_grid_init(&grid); + lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); + + /*Create a container with grid*/ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &grid); + + lv_obj_t * label; + lv_obj_t * obj; + + uint32_t i; + for(i = 0; i < 9; i++) { + uint8_t col = i % 3; + uint8_t row = i / 3; + + obj = lv_obj_create(cont, NULL); + /* Stretch the cell horizontally and vertically too + * Set span to 1 to make the cell 1 column/row sized */ + lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1, + LV_GRID_STRETCH, row, 1); + + label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "c%d, r%d", col, row); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } +} + +#endif diff --git a/examples/layouts/grid/lv_example_grid_2.c b/examples/layouts/grid/lv_example_grid_2.c index 687a6d663..a7ef3d1c3 100644 --- a/examples/layouts/grid/lv_example_grid_2.c +++ b/examples/layouts/grid/lv_example_grid_2.c @@ -1,59 +1,68 @@ -//#include "../../lv_examples.h" -// -///** -// * Demonstrate cell placement and span -// */ -//void lv_example_grid_2(void) -//{ -// static lv_coord_t col_dsc[3] = {80, 80, 80}; -// static lv_coord_t row_dsc[3] = {60, 60, 60}; -// -// static lv_grid_t grid; -// lv_grid_init(&grid); -// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); -// -// /*Create a container with grid*/ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_grid(cont, &grid); -// -// lv_obj_t * label; -// lv_obj_t * obj; -// -// /*Cell to 0;0 and align to to the start (left/top) horizontally and vertically too */ -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(0, 1), LV_GRID_CELL_START(0, 1)); -// label = lv_label_create(obj, NULL); -// lv_label_set_text(label, "c0, r0"); -// -// /*Cell to 1;0 and align to to the start (left) horizontally and center vertically too */ -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(1, 1), LV_GRID_CELL_CENTER(0, 1)); -// label = lv_label_create(obj, NULL); -// lv_label_set_text(label, "c1, r0"); -// -// /*Cell to 2;0 and align to to the start (left) horizontally and end (bottom) vertically too */ -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(2, 1), LV_GRID_CELL_END(0, 1)); -// label = lv_label_create(obj, NULL); -// lv_label_set_text(label, "c2, r0"); -// -// /*Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched. */ -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(1, 2), LV_GRID_CELL_STRETCH(1, 1)); -// label = lv_label_create(obj, NULL); -// lv_label_set_text(label, "c1-2, r1"); -// -// /*Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched. */ -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(0, 1), LV_GRID_CELL_STRETCH(1, 2)); -// label = lv_label_create(obj, NULL); -// lv_label_set_text(label, "c0\nr1-2"); -//} -// +#include "../../../lvgl.h" + +#if LV_USE_GRID + + +/** + * Demonstrate cell placement and span + */ +void lv_example_grid_2(void) +{ + static lv_coord_t col_dsc[3] = {70, 70, 70}; + static lv_coord_t row_dsc[3] = {50, 50, 50}; + + static lv_grid_t grid; + lv_grid_init(&grid); + lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); + + /*Create a container with grid*/ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &grid); + + lv_obj_t * label; + lv_obj_t * obj; + + /*Cell to 0;0 and align to to the start (left/top) horizontally and vertically too */ + obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_set_grid_cell(obj, LV_GRID_START, 0, 1, + LV_GRID_START, 0, 1); + label = lv_label_create(obj, NULL); + lv_label_set_text(label, "c0, r0"); + + /*Cell to 1;0 and align to to the start (left) horizontally and center vertically too */ + obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_set_grid_cell(obj, LV_GRID_START, 1, 1, + LV_GRID_CENTER, 0, 1); + label = lv_label_create(obj, NULL); + lv_label_set_text(label, "c1, r0"); + + /*Cell to 2;0 and align to to the start (left) horizontally and end (bottom) vertically too */ + obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_set_grid_cell(obj, LV_GRID_START, 2, 1, + LV_GRID_END, 0, 1); + label = lv_label_create(obj, NULL); + lv_label_set_text(label, "c2, r0"); + + /*Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched. */ + obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, 1, 2, + LV_GRID_STRETCH, 1, 1); + label = lv_label_create(obj, NULL); + lv_label_set_text(label, "c1-2, r1"); + + /*Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched. */ + obj = lv_obj_create(cont, NULL); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, 0, 1, + LV_GRID_STRETCH, 1, 2); + label = lv_label_create(obj, NULL); + lv_label_set_text(label, "c0\nr1-2"); +} + +#endif diff --git a/examples/layouts/grid/lv_example_grid_3.c b/examples/layouts/grid/lv_example_grid_3.c index 7c06df2f1..a5972e2be 100644 --- a/examples/layouts/grid/lv_example_grid_3.c +++ b/examples/layouts/grid/lv_example_grid_3.c @@ -1,45 +1,49 @@ -//#include "../../lv_examples.h" -// -///** -// * Demonstrate grid's "free unit" -// */ -//void lv_example_grid_3(void) -//{ -// /* Column 1: fix width 60 px -// * Column 2: 1 unit from the remaining free space -// * Column 3: 2 unit from the remaining free space */ -// static lv_coord_t col_dsc[3] = {60, LV_GRID_FR(1), LV_GRID_FR(2)}; -// -// /* Row 1: fix width 60 px -// * Row 2: 1 unit from the remaining free space -// * Row 3: fix width 60 px */ -// static lv_coord_t row_dsc[3] = {60, LV_GRID_FR(1), 60}; -// -// static lv_grid_t grid; -// lv_grid_init(&grid); -// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); -// -// /*Create a container with grid*/ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_grid(cont, &grid); -// -// lv_obj_t * label; -// lv_obj_t * obj; -// uint32_t i; -// for(i = 0; i < 9; i++) { -// uint8_t col = i % 3; -// uint8_t row = i / 3; -// -// obj = lv_obj_create(cont, NULL); -// /* Stretch the cell horizontally and vertically too -// * Set span to 1 to make the cell 1 column/row sized */ -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1)); -// -// label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "%d,%d", col, row); -// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_GRID + +/** + * Demonstrate grid's "free unit" + */ +void lv_example_grid_3(void) +{ + /* Column 1: fix width 60 px + * Column 2: 1 unit from the remaining free space + * Column 3: 2 unit from the remaining free space */ + static lv_coord_t col_dsc[3] = {60, LV_GRID_FR(1), LV_GRID_FR(2)}; + + /* Row 1: fix width 60 px + * Row 2: 1 unit from the remaining free space + * Row 3: fix width 60 px */ + static lv_coord_t row_dsc[3] = {40, LV_GRID_FR(1), 40}; + + static lv_grid_t grid; + lv_grid_init(&grid); + lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); + + /*Create a container with grid*/ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &grid); + + lv_obj_t * label; + lv_obj_t * obj; + uint32_t i; + for(i = 0; i < 9; i++) { + uint8_t col = i % 3; + uint8_t row = i / 3; + + obj = lv_obj_create(cont, NULL); + /* Stretch the cell horizontally and vertically too + * Set span to 1 to make the cell 1 column/row sized */ + lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1, + LV_GRID_STRETCH, row, 1); + + label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "%d,%d", col, row); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } +} + +#endif diff --git a/examples/layouts/grid/lv_example_grid_4.c b/examples/layouts/grid/lv_example_grid_4.c index 6fffb66d5..e8486aa56 100644 --- a/examples/layouts/grid/lv_example_grid_4.c +++ b/examples/layouts/grid/lv_example_grid_4.c @@ -1,41 +1,45 @@ -//#include "../../lv_examples.h" -// -///** -// * Demonstrate track placement -// */ -//void lv_example_grid_4(void) -//{ -// static lv_coord_t col_dsc[3] = {60, 60, 60}; -// static lv_coord_t row_dsc[3] = {50, 50, 50}; -// -// static lv_grid_t grid; -// lv_grid_init(&grid); -// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); -// -// /*Add space between the columns and move the rows to the bottom (end)*/ -// lv_grid_set_place(&grid, LV_GRID_SPACE_BETWEEN, LV_GRID_END); -// -// /*Create a container with grid*/ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_grid(cont, &grid); -// -// lv_obj_t * label; -// lv_obj_t * obj; -// uint32_t i; -// for(i = 0; i < 9; i++) { -// uint8_t col = i % 3; -// uint8_t row = i / 3; -// -// obj = lv_obj_create(cont, NULL); -// /* Stretch the cell horizontally and vertically too -// * Set span to 1 to make the cell 1 column/row sized */ -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1)); -// -// label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "%d,%d", col, row); -// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_GRID + +/** + * Demonstrate track placement + */ +void lv_example_grid_4(void) +{ + static lv_coord_t col_dsc[3] = {60, 60, 60}; + static lv_coord_t row_dsc[3] = {40, 40, 40}; + + static lv_grid_t grid; + lv_grid_init(&grid); + lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); + + /*Add space between the columns and move the rows to the bottom (end)*/ + lv_grid_set_place(&grid, LV_GRID_SPACE_BETWEEN, LV_GRID_END); + + /*Create a container with grid*/ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &grid); + + lv_obj_t * label; + lv_obj_t * obj; + uint32_t i; + for(i = 0; i < 9; i++) { + uint8_t col = i % 3; + uint8_t row = i / 3; + + obj = lv_obj_create(cont, NULL); + /* Stretch the cell horizontally and vertically too + * Set span to 1 to make the cell 1 column/row sized */ + lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1, + LV_GRID_STRETCH, row, 1); + + label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "%d,%d", col, row); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } +} + +#endif diff --git a/examples/layouts/grid/lv_example_grid_5.c b/examples/layouts/grid/lv_example_grid_5.c index 0f93bbb03..2cf6ffc6e 100644 --- a/examples/layouts/grid/lv_example_grid_5.c +++ b/examples/layouts/grid/lv_example_grid_5.c @@ -1,41 +1,67 @@ -//#include "../../lv_examples.h" -// -///** -// * Demonstrate margin in grid -// */ -//void lv_example_grid_5(void) -//{ -// -// /*60x60 cells*/ -// static lv_coord_t col_dsc[3] = {100, 60, 60}; -// static lv_coord_t row_dsc[3] = {60, 60, 60}; -// -// static lv_grid_t grid; -// lv_grid_init(&grid); -// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); -// -// /*Create a container with grid*/ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_grid(cont, &grid); -// -// lv_obj_t * label; -// lv_obj_t * obj; -// uint32_t i; -// for(i = 0; i < 9; i++) { -// uint8_t col = i % 3; -// uint8_t row = i / 3; -// -// obj = lv_obj_create(cont, NULL); -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(col, 1), LV_GRID_CELL_START(row, 1)); -// lv_obj_set_size(obj, 55, 55); -// if(i == 1) { -// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 5); -// } -// label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "%d,%d", col, row); -// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_GRID + +static void row_gap_anim(lv_obj_t * obj, lv_anim_value_t v) +{ + lv_obj_set_style_pad_row(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v); +} + +static void column_gap_anim(lv_obj_t * obj, lv_anim_value_t v) +{ + lv_obj_set_style_pad_column(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v); +} +/** + * Demonstrate margin in grid + */ +void lv_example_grid_5(void) +{ + + /*60x60 cells*/ + static lv_coord_t col_dsc[3] = {60, 60, 60}; + static lv_coord_t row_dsc[3] = {40, 40, 40}; + + static lv_grid_t grid; + lv_grid_init(&grid); + lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); + + /*Create a container with grid*/ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_layout(cont, &grid); + + lv_obj_t * label; + lv_obj_t * obj; + uint32_t i; + for(i = 0; i < 9; i++) { + uint8_t col = i % 3; + uint8_t row = i / 3; + + obj = lv_obj_create(cont, NULL); + lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1, + LV_GRID_STRETCH, row, 1); + label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "%d,%d", col, row); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } + + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, cont); + lv_anim_set_values(&a, 0, 10); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) row_gap_anim); + lv_anim_set_time(&a, 500); + lv_anim_set_playback_time(&a, 500); + lv_anim_start(&a); + + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) column_gap_anim); + lv_anim_set_time(&a, 3000); + lv_anim_set_playback_time(&a, 3000); + lv_anim_start(&a); +} + +#endif + diff --git a/examples/layouts/grid/lv_example_grid_6.c b/examples/layouts/grid/lv_example_grid_6.c index b9edde377..93e2faa19 100644 --- a/examples/layouts/grid/lv_example_grid_6.c +++ b/examples/layouts/grid/lv_example_grid_6.c @@ -1,43 +1,44 @@ -//#include "../../lv_examples.h" -// -///** -// * Demonstrate RTL direction on grid -// */ -//void lv_example_grid_6(void) -//{ -// -// static lv_coord_t col_dsc[3] = {100, 60, 60}; -// static lv_coord_t row_dsc[3] = {60, 60, 60}; -// -// static lv_grid_t grid; -// lv_grid_init(&grid); -// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); -// -// /*Add space between the columns and move the rows to the bottom (end)*/ -// -// /*Create a container with grid*/ -// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); -// lv_obj_set_size(cont, 300, 220); -// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); -// lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); -// lv_obj_set_grid(cont, &grid); -// -// lv_obj_t * label; -// lv_obj_t * obj; -// uint32_t i; -// for(i = 0; i < 3; i++) { -// uint8_t col = i % 3; -// uint8_t row = i / 3; -// -// obj = lv_obj_create(cont, NULL); -// /* Stretch the cell horizontally and vertically too -// * Set span to 1 to make the cell 1 column/row sized */ -// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_START(row, 1)); -// lv_obj_set_size(obj, 55, 55); -// -// label = lv_label_create(obj, NULL); -// lv_label_set_text_fmt(label, "%d,%d", col, row); -// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); -// } -//} -// +#include "../../../lvgl.h" + +#if LV_USE_GRID + +/** + * Demonstrate RTL direction on grid + */ +void lv_example_grid_6(void) +{ + + static lv_coord_t col_dsc[3] = {60, 60, 60}; + static lv_coord_t row_dsc[3] = {40, 40, 40}; + + static lv_grid_t grid; + lv_grid_init(&grid); + lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); + + /*Create a container with grid*/ + lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_size(cont, 300, 220); + lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); + lv_obj_set_layout(cont, &grid); + + lv_obj_t * label; + lv_obj_t * obj; + uint32_t i; + for(i = 0; i < 9; i++) { + uint8_t col = i % 3; + uint8_t row = i / 3; + + obj = lv_obj_create(cont, NULL); + /* Stretch the cell horizontally and vertically too + * Set span to 1 to make the cell 1 column/row sized */ + lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1, + LV_GRID_STRETCH, row, 1); + + label = lv_label_create(obj, NULL); + lv_label_set_text_fmt(label, "%d,%d", col, row); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + } +} + +#endif diff --git a/examples/porting/lv_port_disp_template.c b/examples/porting/lv_port_disp_template.c index a4f95fab4..90dd9acd0 100644 --- a/examples/porting/lv_port_disp_template.c +++ b/examples/porting/lv_port_disp_template.c @@ -76,20 +76,20 @@ void lv_port_disp_init(void) /* Example for 1) */ static lv_disp_buf_t draw_buf_dsc_1; - static lv_color_t draw_buf_1[LV_HOR_RES_MAX * 10]; /*A buffer for 10 rows*/ - lv_disp_buf_init(&draw_buf_dsc_1, draw_buf_1, NULL, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/ + static lv_color_t draw_buf_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/ + lv_disp_buf_init(&draw_buf_dsc_1, draw_buf_1, NULL, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/ /* Example for 2) */ static lv_disp_buf_t draw_buf_dsc_2; - static lv_color_t draw_buf_2_1[LV_HOR_RES_MAX * 10]; /*A buffer for 10 rows*/ - static lv_color_t draw_buf_2_1[LV_HOR_RES_MAX * 10]; /*An other buffer for 10 rows*/ - lv_disp_buf_init(&draw_buf_dsc_2, draw_buf_2_1, draw_buf_2_1, LV_HOR_RES_MAX * 10); /*Initialize the display buffer*/ + static lv_color_t draw_buf_2_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/ + static lv_color_t draw_buf_2_1[MY_DISP_HOR_RES * 10]; /*An other buffer for 10 rows*/ + lv_disp_buf_init(&draw_buf_dsc_2, draw_buf_2_1, draw_buf_2_1, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/ /* Example for 3) */ static lv_disp_buf_t draw_buf_dsc_3; - static lv_color_t draw_buf_3_1[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*A screen sized buffer*/ - static lv_color_t draw_buf_3_1[LV_HOR_RES_MAX * LV_VER_RES_MAX]; /*An other screen sized buffer*/ - lv_disp_buf_init(&draw_buf_dsc_3, draw_buf_3_1, draw_buf_3_2, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/ + static lv_color_t draw_buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*A screen sized buffer*/ + static lv_color_t draw_buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*An other screen sized buffer*/ + lv_disp_buf_init(&draw_buf_dsc_3, draw_buf_3_1, draw_buf_3_2, MY_DISP_VER_RES * LV_VER_RES_MAX); /*Initialize the display buffer*/ /*----------------------------------- * Register the display in LVGL diff --git a/examples/widgets/imgbtn/lv_example_imgbtn_1.c b/examples/widgets/imgbtn/lv_example_imgbtn_1.c index 08ed15c97..f4c10c315 100644 --- a/examples/widgets/imgbtn/lv_example_imgbtn_1.c +++ b/examples/widgets/imgbtn/lv_example_imgbtn_1.c @@ -8,11 +8,10 @@ void lv_example_imgbtn_1(void) LV_IMG_DECLARE(imgbtn_right); LV_IMG_DECLARE(imgbtn_mid); - - /* Create a transition animation on width transformation.*/ - static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, 0}; + /* Create a transition animation on width transformation and recolor.*/ + static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMG_RECOLOR_OPA, 0}; static lv_style_transition_dsc_t tr; - lv_style_transition_dsc_init(&tr, tr_prop, &lv_anim_path_def, 300, 0); + lv_style_transition_dsc_init(&tr, tr_prop, &lv_anim_path_def, 200, 0); static lv_style_t style_def; lv_style_init(&style_def); diff --git a/examples/widgets/tileview/lv_example_tileview_1.c b/examples/widgets/tileview/lv_example_tileview_1.c index ff8d9ca15..01ce1c9c3 100644 --- a/examples/widgets/tileview/lv_example_tileview_1.c +++ b/examples/widgets/tileview/lv_example_tileview_1.c @@ -31,7 +31,7 @@ void lv_example_tileview_1(void) /*Tile3: a list*/ lv_obj_t * tile3 = lv_tileview_add_tile(tv, 1, 1, LV_DIR_LEFT); lv_obj_t * list = lv_list_create(tile3); - lv_obj_set_size(list, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_size(list, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); lv_list_add_btn(list, NULL, "One", NULL); lv_list_add_btn(list, NULL, "Two", NULL); diff --git a/lv_conf_template.h b/lv_conf_template.h index 503fd10e7..c5e26c3c8 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -72,9 +72,6 @@ #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ #endif /*LV_TICK_CUSTOM*/ -/*Max horizontal or vertical resolution that LVGL is able to manage*/ -#define LV_MAX_RESOLUTION 1366 - /* Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings. * (Not so important, you can adjust it to modify default sizes and spaces)*/ #define LV_DPI_DEF 130 /*[px/inch]*/ diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index f764009ee..f3abd7718 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -160,7 +160,6 @@ static void flex_update(lv_obj_t * cont, lv_obj_t * item) bool row = f->dir == LV_FLEX_FLOW_ROW ? true : false; lv_coord_t track_gap = !row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); lv_coord_t item_gap = row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); - /*Count the grow units and free space*/ lv_coord_t max_main_size = (row ? lv_obj_get_width_fit(cont) : lv_obj_get_height_fit(cont)); lv_coord_t abs_y = cont->coords.y1 + lv_obj_get_style_pad_top(cont, LV_PART_MAIN) - lv_obj_get_scroll_y(cont); lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont, LV_PART_MAIN) - lv_obj_get_scroll_x(cont); @@ -202,9 +201,14 @@ static void flex_update(lv_obj_t * cont, lv_obj_t * item) * If the the height of the tracks is larger than the available space * always use the gap = 0 and start position = 0 to avoid unintuitive scrolling*/ lv_coord_t max_cross_size = (row ? lv_obj_get_height_fit(cont) : lv_obj_get_width_fit(cont)); - if(total_track_cross_size < max_cross_size) { + if(total_track_cross_size < max_cross_size){ place_content(track_cross_place, max_cross_size, total_track_cross_size, track_cnt, cross_pos, &gap); } + else if(rtl && !row) { + /* For RTL columns set the cross_pos to the left side manually. + * It's not at x = 0 because with RTL the most right column is at cont->x2*/ + *cross_pos = max_cross_size - total_track_cross_size + lv_obj_get_style_pad_left(cont, LV_PART_MAIN); + } } track_first_item = f->rev ? cont->spec_attr->child_cnt - 1 : 0; @@ -318,12 +322,12 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_ bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; - if(row && rtl) abs_x += lv_obj_get_width_fit(cont); lv_coord_t main_pos = 0; lv_coord_t place_gap = 0; place_content(f->item_main_place, max_main_size, t->track_main_size, t->item_cnt, &main_pos, &place_gap); + if(row && rtl) main_pos += t->track_main_size; lv_obj_t * item = lv_obj_get_child(cont, item_first_id); /*Reposition the children*/ @@ -350,7 +354,7 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_ lv_coord_t cross_pos = 0; switch(f->item_cross_place) { case LV_FLEX_PLACE_CENTER: - /* Round the up the cross size to avoid rounding error when dividing by 2 + /* Round up the cross size to avoid rounding error when dividing by 2 * The issue comes up e,g, with column direction with center cross direction if an element's width changes*/ cross_pos = (((t->track_cross_size + 1) & (~1)) - area_get_cross_size(&item->coords)) / 2; break; @@ -361,6 +365,9 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_ break; } + if(row && rtl) main_pos -= area_get_main_size(&item->coords); + + lv_coord_t diff_x = abs_x - item->coords.x1; lv_coord_t diff_y = abs_y - item->coords.y1; diff_x += row ? main_pos : cross_pos; @@ -376,9 +383,9 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_ lv_obj_move_children_by(item, diff_x, diff_y); } - if(!(row && rtl)) { - main_pos += area_get_main_size(&item->coords) + item_gap + place_gap; - } + if(!(row && rtl)) main_pos += area_get_main_size(&item->coords) + item_gap + place_gap; + else main_pos -= item_gap + place_gap; + item = get_next_item(cont, f->rev, &item_first_id); } } diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index 704a84108..c6c92630d 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -18,7 +18,6 @@ #define CELL_POS_MASK ((1 << CELL_SHIFT) - 1) #define CELL_SPAN_MASK (CELL_POS_MASK << CELL_SHIFT) #define CELL_FLAG_MASK (CELL_POS_MASK << (2 * CELL_SHIFT)) -#define CELL_PLACE(b) ((b) << (CELL_SHIFT * 2)) #define IS_FR(x) (LV_COORD_IS_LAYOUT(x)) #define GET_FR(x) (_LV_COORD_PLAIN(x)) @@ -103,12 +102,12 @@ void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_place_t ver_place, uint8_t col if(!lv_obj_is_layout_positioned(obj)) return; lv_obj_t * parent = lv_obj_get_parent(obj); if(parent->spec_attr->layout_dsc->update_cb != grid_update) return; - const lv_grid_t * g = (const lv_grid_t *) parent->spec_attr->layout_dsc; - lv_coord_t x = LV_COORD_SET_LAYOUT(col_pos | (col_span << CELL_SHIFT) | CELL_PLACE(hor_place)); - lv_coord_t y = LV_COORD_SET_LAYOUT(row_pos | (row_span << CELL_SHIFT) | CELL_PLACE(ver_place)); + obj->x_set = LV_COORD_SET_LAYOUT(col_pos | (col_span << CELL_SHIFT) | (hor_place << (CELL_SHIFT * 2))); + obj->y_set = LV_COORD_SET_LAYOUT(row_pos | (row_span << CELL_SHIFT) | (ver_place << (CELL_SHIFT * 2))); + + lv_obj_update_layout(parent, obj); - lv_obj_set_pos(obj, x, y); } @@ -315,13 +314,14 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) */ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * hint) { - if(LV_COORD_IS_LAYOUT(item->x_set) && LV_COORD_IS_LAYOUT(item->y_set)) return; + if(LV_COORD_IS_LAYOUT(item->x_set) == 0 || LV_COORD_IS_LAYOUT(item->y_set) == 0) return; if(lv_obj_has_flag(item, LV_OBJ_FLAG_LAYOUTABLE) == false) return; + uint32_t col_span = GET_CELL_SPAN(item->x_set); + uint32_t row_span = GET_CELL_SPAN(item->y_set); + if(row_span == 0 || col_span == 0) return; uint32_t col_pos = GET_CELL_POS(item->x_set); - uint32_t col_span = GET_CELL_SPAN(item->x_set); uint32_t row_pos = GET_CELL_POS(item->y_set); - uint32_t row_span = GET_CELL_SPAN(item->y_set); lv_coord_t col_x1 = c->x[col_pos]; lv_coord_t col_x2 = c->x[col_pos + col_span - 1] + c->w[col_pos + col_span - 1]; diff --git a/src/extra/widgets/list/lv_list.c b/src/extra/widgets/list/lv_list.c index 6fefa2529..5c0c62c71 100644 --- a/src/extra/widgets/list/lv_list.c +++ b/src/extra/widgets/list/lv_list.c @@ -57,14 +57,14 @@ lv_obj_t * lv_list_add_text(lv_obj_t * list, const char * txt) lv_obj_t * label = lv_label_create(list, NULL); lv_label_set_text(label, txt); lv_label_set_long_mode(label, LV_LABEL_LONG_SROLL_CIRC); - lv_obj_set_width(label, LV_COORD_PCT(100)); + lv_obj_set_width(label, LV_SIZE_PCT(100)); return label; } lv_obj_t * lv_list_add_btn(lv_obj_t * list, const char * icon, const char * txt, lv_event_cb_t event_cb) { lv_obj_t * btn = lv_btn_create(list, NULL); - lv_obj_set_width(btn, LV_COORD_PCT(100)); + lv_obj_set_width(btn, LV_SIZE_PCT(100)); lv_obj_add_event_cb(btn, event_cb, NULL); lv_obj_set_layout(btn, &lv_flex_inline); diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index e2f883e59..93f062c0e 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -46,7 +46,7 @@ const lv_obj_class_t lv_msgbox_class = {.base_class = &lv_obj_class}; lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * btn_txts[], bool add_close_btn) { lv_obj_t * parent = lv_obj_create(lv_layer_top(), NULL); - lv_obj_set_size(parent, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_size(parent, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); lv_obj_remove_style(parent, LV_PART_ANY, LV_STATE_ANY, NULL); lv_obj_set_style_bg_color(parent, LV_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); @@ -67,7 +67,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b lv_label_set_text(label, title); lv_label_set_long_mode(label, LV_LABEL_LONG_SROLL_CIRC); if(add_close_btn) lv_obj_set_flex_grow(label, 1); - else lv_obj_set_width(label, LV_COORD_PCT(100)); + else lv_obj_set_width(label, LV_SIZE_PCT(100)); if(add_close_btn) { lv_obj_t * close_btn = lv_btn_create(mbox, NULL); @@ -83,7 +83,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b label = lv_label_create(mbox, NULL); lv_label_set_text(label, txt); lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); - lv_obj_set_width(label, LV_COORD_PCT(100)); + lv_obj_set_width(label, LV_SIZE_PCT(100)); lv_obj_t * btns = lv_btnmatrix_create(mbox, NULL); lv_btnmatrix_set_map(btns, btn_txts); diff --git a/src/extra/widgets/tabview/lv_tabview.c b/src/extra/widgets/tabview/lv_tabview.c index 013644ffe..d3bcdd2e5 100644 --- a/src/extra/widgets/tabview/lv_tabview.c +++ b/src/extra/widgets/tabview/lv_tabview.c @@ -61,7 +61,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name) lv_obj_clear_flag(page, LV_OBJ_FLAG_CLICK_FOCUSABLE); uint32_t tab_id = lv_obj_get_child_cnt(cont); - lv_obj_set_size(page, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_size(page, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); lv_obj_t * btns = lv_tabview_get_tab_btns(obj); @@ -167,7 +167,7 @@ static void lv_tabview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_o break; } - lv_obj_set_size(obj, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); lv_obj_set_layout(obj, &tabview->flex); lv_obj_t * btnm; @@ -189,14 +189,14 @@ static void lv_tabview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_o switch(tabview->tab_pos) { case LV_DIR_TOP: case LV_DIR_BOTTOM: - lv_obj_set_size(btnm, LV_COORD_PCT(100), tabsize_create); - lv_obj_set_width(cont, LV_COORD_PCT(100)); + lv_obj_set_size(btnm, LV_SIZE_PCT(100), tabsize_create); + lv_obj_set_width(cont, LV_SIZE_PCT(100)); lv_obj_set_flex_grow(cont, 1); break; case LV_DIR_LEFT: case LV_DIR_RIGHT: - lv_obj_set_size(btnm, tabsize_create, LV_COORD_PCT(100)); - lv_obj_set_height(cont, LV_COORD_PCT(100)); + lv_obj_set_size(btnm, tabsize_create, LV_SIZE_PCT(100)); + lv_obj_set_height(cont, LV_SIZE_PCT(100)); lv_obj_set_flex_grow(cont, 1); break; } diff --git a/src/extra/widgets/tileview/lv_tileview.c b/src/extra/widgets/tileview/lv_tileview.c index 1fc5d4327..9434b7874 100644 --- a/src/extra/widgets/tileview/lv_tileview.c +++ b/src/extra/widgets/tileview/lv_tileview.c @@ -109,7 +109,7 @@ void lv_obj_set_tile_id(lv_obj_t * tv, uint32_t col_id, uint32_t row_id, lv_anim static void lv_tileview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_set_size(obj, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); lv_obj_add_event_cb(obj, tileview_event_cb, NULL); lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE); lv_obj_set_snap_align_x(obj, LV_SCROLL_SNAP_ALIGN_CENTER); @@ -119,7 +119,7 @@ static void lv_tileview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ static void lv_tileview_tile_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_set_size(obj, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); lv_obj_set_pos(obj, create_col_id * lv_obj_get_width_fit(parent), create_row_id * lv_obj_get_height_fit(parent)); lv_tileview_tile_t * tile = (lv_tileview_tile_t *) obj; diff --git a/src/extra/widgets/win/lv_win.c b/src/extra/widgets/win/lv_win.c index 2cdce9972..ee74ff36b 100644 --- a/src/extra/widgets/win/lv_win.c +++ b/src/extra/widgets/win/lv_win.c @@ -56,7 +56,7 @@ lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w, l { lv_obj_t * header = lv_win_get_header(win); lv_obj_t * btn = lv_btn_create(header, NULL); - lv_obj_set_size(btn, btn_w, LV_COORD_PCT(100)); + lv_obj_set_size(btn, btn_w, LV_SIZE_PCT(100)); lv_obj_add_event_cb(btn, event_cb, NULL); lv_obj_t * img = lv_img_create(btn, NULL); @@ -86,12 +86,12 @@ static void lv_win_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t lv_obj_set_layout(obj, &lv_flex_stacked); lv_obj_t * header = lv_obj_create(obj, NULL); - lv_obj_set_size(header, LV_COORD_PCT(100), create_header_height); + lv_obj_set_size(header, LV_SIZE_PCT(100), create_header_height); lv_obj_set_layout(header, &lv_flex_inline); lv_obj_t * cont = lv_obj_create(obj, NULL); lv_obj_set_flex_grow(cont, 1); - lv_obj_set_width(cont, LV_COORD_PCT(100)); + lv_obj_set_width(cont, LV_SIZE_PCT(100)); } #endif diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index aed5239c5..9553d7dc6 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -204,15 +204,6 @@ #endif #endif /*LV_TICK_CUSTOM*/ -/*Max horizontal or vertical resolution that LVGL is able to manage*/ -#ifndef LV_MAX_RESOLUTION -# ifdef CONFIG_LV_MAX_RESOLUTION -# define LV_MAX_RESOLUTION CONFIG_LV_MAX_RESOLUTION -# else -# define LV_MAX_RESOLUTION 1366 -# endif -#endif - /* Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings. * (Not so important, you can adjust it to modify default sizes and spaces)*/ #ifndef LV_DPI_DEF diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index cd4027b8f..27cbe53ee 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -388,7 +388,7 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) lv_obj_invalidate(obj); - if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL); + if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_LAYOUT) lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ALL); else if(cmp_res == _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) lv_obj_refresh_ext_draw_size(obj); } diff --git a/src/lv_core/lv_obj_pos.h b/src/lv_core/lv_obj_pos.h index 0474d2243..04938d2a9 100644 --- a/src/lv_core/lv_obj_pos.h +++ b/src/lv_core/lv_obj_pos.h @@ -69,7 +69,7 @@ void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y); * @note possible values are: * pixel simple set the size accordingly * LV_SIZE_CONTENT set the size to involve all children in the given direction - * LV_COORD_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * LV_SIZE_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). * x should be in [0..1000]% range */ void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); @@ -81,7 +81,7 @@ void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); * @note possible values are: * pixel simple set the size accordingly * LV_SIZE_CONTENT set the size to involve all children in the given direction - * LV_COORD_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * LV_SIZE_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). * x should be in [0..1000]% range */ void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); @@ -93,7 +93,7 @@ void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); * @note possible values are: * pixel simple set the size accordingly * LV_SIZE_CONTENT set the size to involve all children in the given direction - * LV_COORD_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * LV_SIZE_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). * x should be in [0..1000]% range */ void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h); diff --git a/src/lv_core/lv_obj_scroll.c b/src/lv_core/lv_obj_scroll.c index ac73998f8..aadda1411 100644 --- a/src/lv_core/lv_obj_scroll.c +++ b/src/lv_core/lv_obj_scroll.c @@ -180,7 +180,7 @@ lv_coord_t lv_obj_get_scroll_left(lv_obj_t * obj) lv_coord_t self_w = lv_obj_get_self_width(obj); self_w = self_w - (lv_obj_get_width(obj) - pad_right - pad_left); - self_w -= lv_obj_get_scroll_x(obj); + self_w += lv_obj_get_scroll_x(obj); return LV_MAX(child_res, self_w); } diff --git a/src/lv_core/lv_obj_style.c b/src/lv_core/lv_obj_style.c index 777c985f0..5bbd6f522 100644 --- a/src/lv_core/lv_obj_style.c +++ b/src/lv_core/lv_obj_style.c @@ -108,7 +108,7 @@ void lv_obj_add_style(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_ obj->style_list.styles[i].part = part; obj->style_list.styles[i].state = state; - lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL); + lv_obj_refresh_style(obj, part, LV_STYLE_PROP_ALL); } void lv_obj_remove_style(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_t * style) @@ -148,7 +148,7 @@ void lv_obj_remove_style(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style * Therefore it doesn't needs to be incremented*/ } if(deleted) { - lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL); + lv_obj_refresh_style(obj, part, LV_STYLE_PROP_ALL); } } @@ -166,22 +166,21 @@ void lv_obj_report_style_change(lv_style_t * style) } } -void lv_obj_refresh_style(lv_obj_t * obj,lv_style_prop_t prop) +void lv_obj_refresh_style(lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop) { LV_ASSERT_OBJ(obj, MY_CLASS); if(!style_refr) return; - update_cache(obj, LV_PART_MAIN, prop); + update_cache(obj, part, prop); lv_obj_invalidate(obj); - if(prop == LV_STYLE_PROP_ALL || (prop & LV_STYLE_PROP_LAYOUT_REFR)) { - lv_signal_send(obj, LV_SIGNAL_STYLE_CHG, NULL); - lv_obj_invalidate(obj); + if(part == LV_PART_MAIN && (prop == LV_STYLE_PROP_ALL || (prop & LV_STYLE_PROP_LAYOUT_REFR))) { + lv_signal_send(obj, LV_SIGNAL_STYLE_CHG, NULL); /*To update layout*/ } else if(prop & LV_STYLE_PROP_EXT_DRAW) { lv_obj_refresh_ext_draw_size(obj); - lv_obj_invalidate(obj); } + lv_obj_invalidate(obj); if(prop == LV_STYLE_PROP_ALL || ((prop & LV_STYLE_PROP_INHERIT) && (prop & LV_STYLE_PROP_EXT_DRAW) && (prop & LV_STYLE_PROP_LAYOUT_REFR))) @@ -228,7 +227,7 @@ void lv_obj_set_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, { lv_style_t * style = get_local_style(obj, part, state); lv_style_set_prop(style, prop, value); - lv_obj_refresh_style(obj, prop); + lv_obj_refresh_style(obj, part, prop); } bool lv_obj_remove_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop) @@ -781,7 +780,7 @@ static void report_style_change_core(void * style, lv_obj_t * obj) uint32_t i; for(i = 0; i < list->style_cnt; i++) { if(style == NULL || list->styles[i].style == style) { - lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL); + lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ALL); break; } } @@ -904,7 +903,7 @@ static void trans_anim_cb(trans_t * tr, lv_anim_value_t v) } } lv_style_set_prop(list->styles[i].style, tr->prop, value_final); - if (refr) lv_obj_refresh_style(tr->obj, tr->prop); + if (refr) lv_obj_refresh_style(tr->obj, tr->part, tr->prop); break; } diff --git a/src/lv_core/lv_obj_style.h b/src/lv_core/lv_obj_style.h index ed33fadcc..884c6d3cc 100644 --- a/src/lv_core/lv_obj_style.h +++ b/src/lv_core/lv_obj_style.h @@ -112,10 +112,11 @@ void lv_obj_report_style_change(lv_style_t * style); /** * Notify an object and its children about its style is modified. * @param obj pointer to an object + * @param part the part whose style was changed. E.g. `LV_PART_ANY`, `LV_PART_MAIN` * @param prop `LV_STYLE_PROP_ALL` or an `LV_STYLE_...` property. * It is used to optimize what needs to be refreshed. */ -void lv_obj_refresh_style(struct _lv_obj_t * obj,lv_style_prop_t prop); +void lv_obj_refresh_style(struct _lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop); /** * Enable or disable automatic style refreshing when a new style is added/removed to/from an object diff --git a/src/lv_core/lv_theme.c b/src/lv_core/lv_theme.c index 1c370fc60..851bd6a39 100644 --- a/src/lv_core/lv_theme.c +++ b/src/lv_core/lv_theme.c @@ -67,7 +67,7 @@ void lv_theme_apply(lv_obj_t * obj) apply_theme(act_theme, obj); /*Apply the theme including the base theme(s)*/ lv_obj_enable_style_refresh(true); - lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL); + lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ALL); } /** diff --git a/src/lv_draw/lv_draw_blend.c b/src/lv_draw/lv_draw_blend.c index bd1787956..840f22b8a 100644 --- a/src/lv_draw/lv_draw_blend.c +++ b/src/lv_draw/lv_draw_blend.c @@ -70,10 +70,6 @@ static inline lv_color_t color_blend_true_color_subtractive(lv_color_t fg, lv_co * STATIC VARIABLES **********************/ -#if (LV_USE_GPU || LV_USE_GPU_STM32_DMA2D) && (LV_USE_GPU_NXP_PXP == 0) && (LV_USE_GPU_NXP_VG_LITE == 0) - LV_ATTRIBUTE_DMA static lv_color_t blend_buf[LV_HOR_RES_MAX]; -#endif - /********************** * MACROS **********************/ @@ -365,35 +361,6 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co } /* Fall down to SW render in case of error */ } -#elif LV_USE_GPU - if(disp->driver.gpu_blend_cb && lv_area_get_size(draw_area) > GPU_SIZE_LIMIT) { - for(x = 0; x < draw_area_w ; x++) blend_buf[x].full = color.full; - - for(y = draw_area->y1; y <= draw_area->y2; y++) { - disp->driver.gpu_blend_cb(&disp->driver, disp_buf_first, blend_buf, draw_area_w, opa); - disp_buf_first += disp_w; - } - return; - } -#endif - -#if LV_USE_GPU_STM32_DMA2D - if(lv_area_get_size(draw_area) >= 240) { - if(blend_buf[0].full != color.full) lv_color_fill(blend_buf, color, LV_HOR_RES_MAX); - - lv_coord_t line_h = LV_HOR_RES_MAX / draw_area_w; - for(y = 0; y <= draw_area_h - line_h; y += line_h) { - lv_gpu_stm32_dma2d_blend(disp_buf_first, disp_w, blend_buf, opa, draw_area_w, draw_area_w, line_h); - lv_gpu_stm32_dma2d_wait_cb(NULL); - disp_buf_first += disp_w * line_h; - } - - if(y != draw_area_h) { - lv_gpu_stm32_dma2d_blend(disp_buf_first, disp_w, blend_buf, opa, draw_area_w, draw_area_w, draw_area_h - y); - } - - return; - } #endif lv_color_t last_dest_color = LV_COLOR_BLACK; lv_color_t last_res_color = lv_color_mix(color, last_dest_color, opa); diff --git a/src/lv_draw/lv_draw_img.c b/src/lv_draw/lv_draw_img.c index aade2bbe4..1c205efca 100644 --- a/src/lv_draw/lv_draw_img.c +++ b/src/lv_draw/lv_draw_img.c @@ -407,11 +407,7 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const lv_coord_t draw_area_h = lv_area_get_height(&draw_area); lv_coord_t draw_area_w = lv_area_get_width(&draw_area); -#if LV_USE_IMG_TRANSFORM bool transform = draw_dsc->angle != 0 || draw_dsc->zoom != LV_IMG_ZOOM_NONE ? true : false; -#else - bool transform = false; -#endif /*Simple ARGB image. Handle it as special case because it's very common*/ if(other_mask_cnt == 0 && !transform && !chroma_key && draw_dsc->recolor_opa == LV_OPA_TRANSP && alpha_byte) { #if LV_USE_GPU_STM32_DMA2D && LV_COLOR_DEPTH == 32 @@ -481,7 +477,6 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const lv_color_t * map2 = lv_mem_buf_get(mask_buf_size * sizeof(lv_color_t)); lv_opa_t * mask_buf = lv_mem_buf_get(mask_buf_size); -#if LV_USE_IMG_TRANSFORM lv_img_transform_dsc_t trans_dsc; lv_memset_00(&trans_dsc, sizeof(lv_img_transform_dsc_t)); if(transform) { @@ -502,7 +497,6 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const _lv_img_buf_transform_init(&trans_dsc); } -#endif uint16_t recolor_premult[3] = {0}; lv_opa_t recolor_opa_inv = 255 - draw_dsc->recolor_opa; if(draw_dsc->recolor_opa != 0) { @@ -520,19 +514,13 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const int32_t x; int32_t y; -#if LV_USE_IMG_TRANSFORM int32_t rot_y = disp_area->y1 + draw_area.y1 - map_area->y1; -#endif for(y = 0; y < draw_area_h; y++) { map_px = map_buf_tmp; uint32_t px_i_start = px_i; -#if LV_USE_IMG_TRANSFORM int32_t rot_x = disp_area->x1 + draw_area.x1 - map_area->x1; -#endif for(x = 0; x < draw_area_w; x++, map_px += px_size_byte, px_i++) { - -#if LV_USE_IMG_TRANSFORM if(transform) { /*Transform*/ @@ -548,9 +536,7 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const } } /*No transform*/ - else -#endif - { + else { if(alpha_byte) { lv_opa_t px_opa = map_px[LV_IMG_PX_SIZE_ALPHA_BYTE - 1]; mask_buf[px_i] = px_opa; diff --git a/src/lv_hal/lv_hal_disp.c b/src/lv_hal/lv_hal_disp.c index c535fc4fb..2c67d0fe6 100644 --- a/src/lv_hal/lv_hal_disp.c +++ b/src/lv_hal/lv_hal_disp.c @@ -66,15 +66,6 @@ void lv_disp_drv_init(lv_disp_drv_t * driver) #if LV_COLOR_SCREEN_TRANSP driver->screen_transp = 1; #endif - - driver->gpu_blend_cb = NULL; - driver->gpu_fill_cb = NULL; - -#if LV_USE_USER_DATA - driver->user_data = NULL; -#endif - - driver->set_px_cb = NULL; } /** diff --git a/src/lv_hal/lv_hal_disp.h b/src/lv_hal/lv_hal_disp.h index 3c4d69e83..7b84303d6 100644 --- a/src/lv_hal/lv_hal_disp.h +++ b/src/lv_hal/lv_hal_disp.h @@ -115,10 +115,6 @@ typedef struct _disp_drv_t { /** OPTIONAL: called to wait while the gpu is working */ void (*gpu_wait_cb)(struct _disp_drv_t * disp_drv); - /** OPTIONAL: Blend two memories using opacity (GPU only)*/ - void (*gpu_blend_cb)(struct _disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, - lv_opa_t opa); - /** OPTIONAL: Fill a memory with a color (GPU only)*/ void (*gpu_fill_cb)(struct _disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width, const lv_area_t * fill_area, lv_color_t color); diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index fb7cce3a1..7c2f5aba7 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -245,7 +245,7 @@ void _lv_area_align(const lv_area_t * base, const lv_area_t * to_align, lv_align #define LV_COORD_SET_LAYOUT(x) ((x) | _LV_COORD_TYPE_LAYOUT) /*Special coordinates*/ -#define LV_COORD_PCT(x) LV_COORD_SET_SPEC(x) +#define LV_SIZE_PCT(x) LV_COORD_SET_SPEC(x) #define LV_COORD_IS_PCT(x) ((LV_COORD_IS_SPEC(x) && _LV_COORD_PLAIN(x) <= 1000) ? true : false) #define LV_COORD_GET_PCT(x) _LV_COORD_PLAIN(x) #define LV_SIZE_CONTENT LV_COORD_SET_SPEC(1001) diff --git a/src/lv_misc/lv_style.c b/src/lv_misc/lv_style.c index 75d54a567..ddc8f9042 100644 --- a/src/lv_misc/lv_style.c +++ b/src/lv_misc/lv_style.c @@ -59,6 +59,9 @@ void lv_style_reset(lv_style_t * style) if(style->allocated) lv_mem_free(style->values_and_props); lv_memset_00(style, sizeof(lv_style_t)); +#if LV_USE_ASSERT_STYLE + style->sentinel = LV_STYLE_SENTINEL_VALUE; +#endif } @@ -259,7 +262,6 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop) value.ptr = LV_THEME_FONT_NORMAL; break; case LV_STYLE_SIZE: - case LV_STYLE_ARC_WIDTH: value.num = 10; break; default: diff --git a/tests/lv_test_assert.c b/tests/lv_test_assert.c index 3b8dfefb6..c78fe33d7 100644 --- a/tests/lv_test_assert.c +++ b/tests/lv_test_assert.c @@ -176,10 +176,10 @@ void lv_test_assert_img_eq(const char * fn_ref, const char * s) return; #endif -#if LV_HOR_RES_MAX != 800 || LV_VER_RES_MAX != 480 - lv_test_print(" SKIP: Can't compare '%s' because the resolution needs to be 800x480 (LV_HOR_RES_MAX, LV_VER_RES_MAX)", fn_ref); +if (LV_HOR_RES != 800 || LV_VER_RES != 480) { + lv_test_print(" SKIP: Can't compare '%s' because the resolution needs to be 800x480", fn_ref); return; -#endif +} char fn_ref_full[512]; sprintf(fn_ref_full, "%s%s", REF_IMGS_PATH, fn_ref); diff --git a/tests/lv_test_main.c b/tests/lv_test_main.c index db68accf8..f4f0a7c9c 100644 --- a/tests/lv_test_main.c +++ b/tests/lv_test_main.c @@ -7,10 +7,13 @@ #if LV_BUILD_TEST #include +#define HOR_RES 800 +#define VER_RES 480 + static void hal_init(void); static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); -lv_color_t test_fb[LV_HOR_RES_MAX * LV_VER_RES_MAX]; +lv_color_t test_fb[HOR_RES * VER_RES]; int main(void) { @@ -99,6 +102,8 @@ static void hal_init(void) lv_disp_drv_init(&disp_drv); disp_drv.buffer = &disp_buf; disp_drv.flush_cb = dummy_flush_cb; + disp_drv.hor_res = HOR_RES; + disp_drv.ver_res = VER_RES; lv_disp_drv_register(&disp_drv); #if LV_USE_FILESYSTEM