From b7becbbb22d30d4bcbf4af5aad2e9d4223b119c1 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 23 Mar 2021 20:51:39 +0100 Subject: [PATCH] feat(style): store layout and position coordinates as style properties related to #2152 --- .../get_started/lv_example_get_started_1.c | 2 +- examples/layouts/flex/lv_example_flex_1.c | 12 +- examples/layouts/flex/lv_example_flex_2.c | 11 +- examples/layouts/flex/lv_example_flex_3.c | 10 +- examples/layouts/flex/lv_example_flex_4.c | 8 +- examples/layouts/flex/lv_example_flex_5.c | 2 +- examples/layouts/flex/lv_example_flex_6.c | 2 +- examples/layouts/grid/lv_example_grid_1.c | 12 +- examples/layouts/grid/lv_example_grid_2.c | 10 +- examples/layouts/grid/lv_example_grid_3.c | 10 +- examples/layouts/grid/lv_example_grid_4.c | 11 +- examples/layouts/grid/lv_example_grid_5.c | 10 +- examples/layouts/grid/lv_example_grid_6.c | 10 +- examples/scroll/lv_example_scroll_2.c | 4 +- examples/widgets/bar/lv_example_bar_4.c | 2 +- examples/widgets/btn/lv_example_btn_1.c | 20 +- .../widgets/calendar/lv_example_calendar_1.c | 1 - .../widgets/checkbox/lv_example_checkbox_1.c | 8 +- examples/widgets/list/lv_example_list_1.c | 12 + examples/widgets/slider/lv_example_slider_3.c | 2 +- examples/widgets/switch/lv_example_switch_1.c | 9 +- .../widgets/tabview/lv_example_tabview_1.c | 2 +- src/core/lv_indev.c | 6 +- src/core/lv_indev.h | 6 +- src/core/lv_obj.c | 164 ++------- src/core/lv_obj.h | 16 +- src/core/lv_obj_class.c | 18 +- src/core/lv_obj_pos.c | 348 +++++++++++------- src/core/lv_obj_pos.h | 45 ++- src/core/lv_obj_scroll.c | 4 +- src/core/lv_obj_style.c | 17 + src/core/lv_obj_style.h | 2 + src/core/lv_obj_style_gen.h | 71 ++++ src/core/lv_obj_tree.c | 2 +- src/core/lv_refr.c | 6 +- src/core/lv_theme.c | 5 - src/extra/layouts/flex/lv_flex.c | 226 +++++------- src/extra/layouts/flex/lv_flex.h | 164 +++++++-- src/extra/layouts/grid/lv_grid.c | 262 +++++++------ src/extra/layouts/grid/lv_grid.h | 306 ++++++++++++--- src/extra/themes/basic/lv_theme_basic.c | 5 + src/extra/themes/default/lv_theme_default.c | 17 +- src/extra/widgets/calendar/lv_calendar.c | 2 +- .../calendar/lv_calendar_header_arrow.c | 3 +- .../calendar/lv_calendar_header_dropdown.c | 5 +- src/extra/widgets/colorwheel/lv_colorwheel.c | 2 +- src/extra/widgets/list/lv_list.c | 3 +- src/extra/widgets/msgbox/lv_msgbox.c | 2 +- src/extra/widgets/tabview/lv_tabview.c | 12 +- src/extra/widgets/tabview/lv_tabview.h | 1 - src/extra/widgets/win/lv_win.c | 4 +- src/hal/lv_hal_disp.c | 2 +- src/misc/lv_area.h | 4 - src/misc/lv_mem.c | 2 +- src/misc/lv_printf.c | 2 + src/misc/lv_printf.h | 2 + src/misc/lv_style.c | 2 +- src/misc/lv_style.h | 24 +- src/misc/lv_style_gen.h | 42 +++ src/widgets/lv_arc.c | 2 - src/widgets/lv_bar.c | 20 +- src/widgets/lv_bar.h | 18 +- src/widgets/lv_btn.c | 4 - src/widgets/lv_btnmatrix.c | 11 +- src/widgets/lv_dropdown.c | 12 +- src/widgets/lv_label.c | 10 +- src/widgets/lv_roller.c | 9 +- src/widgets/lv_slider.c | 24 +- src/widgets/lv_slider.h | 30 +- src/widgets/lv_switch.c | 2 - src/widgets/lv_textarea.c | 13 +- 71 files changed, 1247 insertions(+), 882 deletions(-) diff --git a/examples/get_started/lv_example_get_started_1.c b/examples/get_started/lv_example_get_started_1.c index ea51de93c..df6e4cf5d 100644 --- a/examples/get_started/lv_example_get_started_1.c +++ b/examples/get_started/lv_example_get_started_1.c @@ -1,5 +1,5 @@ #include "../../lvgl.h" -#if LV_BUILD_EXAMPLES +#if LV_BUILD_EXAMPLES && LV_USE_BTN static void btn_event_cb(lv_obj_t * btn, lv_event_t event) { diff --git a/examples/layouts/flex/lv_example_flex_1.c b/examples/layouts/flex/lv_example_flex_1.c index 45c76d5b3..4f80ded2f 100644 --- a/examples/layouts/flex/lv_example_flex_1.c +++ b/examples/layouts/flex/lv_example_flex_1.c @@ -6,25 +6,17 @@ */ 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); + lv_obj_set_flex_flow(cont_row, LV_FLEX_FLOW_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); + lv_obj_set_flex_flow(cont_col, LV_FLEX_FLOW_COLUMN); uint32_t i; for(i = 0; i < 10; i++) { diff --git a/examples/layouts/flex/lv_example_flex_2.c b/examples/layouts/flex/lv_example_flex_2.c index ac0cf9aab..af988cd17 100644 --- a/examples/layouts/flex/lv_example_flex_2.c +++ b/examples/layouts/flex/lv_example_flex_2.c @@ -6,15 +6,16 @@ */ 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); + static lv_style_t style; + lv_style_init(&style); + lv_style_set_flex_flow(&style, LV_FLEX_FLOW_ROW_WRAP); + lv_style_set_flex_main_place(&style, LV_FLEX_PLACE_SPACE_EVENLY); + lv_style_set_layout(&style, LV_LAYOUT_FLEX); 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); + lv_obj_add_style(cont, LV_PART_MAIN, LV_STATE_DEFAULT, &style); uint32_t i; for(i = 0; i < 8; i++) { diff --git a/examples/layouts/flex/lv_example_flex_3.c b/examples/layouts/flex/lv_example_flex_3.c index 6195184b1..0e0eeb13e 100644 --- a/examples/layouts/flex/lv_example_flex_3.c +++ b/examples/layouts/flex/lv_example_flex_3.c @@ -2,21 +2,21 @@ #if LV_USE_FLEX && LV_BUILD_EXAMPLES /** - * Use a built in flex layout and demonstrate flex grow. + * 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_row_nowrap); + lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW); lv_obj_t * obj; obj = lv_obj_create(cont, NULL); - lv_obj_set_size(obj, 20, 20); /*Fix size*/ + lv_obj_set_size(obj, 40, 40); /*Fix size*/ obj = lv_obj_create(cont, NULL); - lv_obj_set_height(obj, 30); + lv_obj_set_height(obj, 40); lv_obj_set_flex_grow(obj, 1); /*1 portion from the free space*/ obj = lv_obj_create(cont, NULL); @@ -24,7 +24,7 @@ void lv_example_flex_3(void) 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*/ + lv_obj_set_size(obj, 40, 40); /*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 73403a8c7..85c5d4bb3 100644 --- a/examples/layouts/flex/lv_example_flex_4.c +++ b/examples/layouts/flex/lv_example_flex_4.c @@ -7,19 +7,15 @@ 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); + lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN_REVERSE); 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_set_size(obj, 100, 50); lv_obj_t * label = lv_label_create(obj, NULL); lv_label_set_text_fmt(label, "Item: %d", i); diff --git a/examples/layouts/flex/lv_example_flex_5.c b/examples/layouts/flex/lv_example_flex_5.c index 2d2d58893..9e5a08960 100644 --- a/examples/layouts/flex/lv_example_flex_5.c +++ b/examples/layouts/flex/lv_example_flex_5.c @@ -19,7 +19,7 @@ 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_row_wrap); + lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP); uint32_t i; for(i = 0; i < 9; i++) { diff --git a/examples/layouts/flex/lv_example_flex_6.c b/examples/layouts/flex/lv_example_flex_6.c index 812380357..2b308bc0b 100644 --- a/examples/layouts/flex/lv_example_flex_6.c +++ b/examples/layouts/flex/lv_example_flex_6.c @@ -11,7 +11,7 @@ void lv_example_flex_6(void) 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_column_center); + lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP); uint32_t i; for(i = 0; i < 20; i++) { diff --git a/examples/layouts/grid/lv_example_grid_1.c b/examples/layouts/grid/lv_example_grid_1.c index ba25135df..611b5b752 100644 --- a/examples/layouts/grid/lv_example_grid_1.c +++ b/examples/layouts/grid/lv_example_grid_1.c @@ -6,18 +6,16 @@ */ 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); + static lv_coord_t col_dsc[] = {70, 70, 70, LV_COORD_MAX}; + static lv_coord_t row_dsc[] = {50, 50, 50, LV_COORD_MAX}; /*Create a container with grid*/ lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_style_grid_column_template(cont, LV_PART_MAIN, LV_STATE_DEFAULT, col_dsc); + lv_obj_set_style_grid_row_template(cont, LV_PART_MAIN, LV_STATE_DEFAULT, row_dsc); 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_set_layout(cont, LV_LAYOUT_GRID); lv_obj_t * label; lv_obj_t * obj; diff --git a/examples/layouts/grid/lv_example_grid_2.c b/examples/layouts/grid/lv_example_grid_2.c index f3bec6007..02d7f2732 100644 --- a/examples/layouts/grid/lv_example_grid_2.c +++ b/examples/layouts/grid/lv_example_grid_2.c @@ -7,18 +7,14 @@ */ 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); + static lv_coord_t col_dsc[] = {70, 70, 70, LV_GRID_TEMPLATE_LAST}; + static lv_coord_t row_dsc[] = {50, 50, 50, LV_GRID_TEMPLATE_LAST}; /*Create a container with grid*/ lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); + lv_obj_set_grid_template(cont, col_dsc, row_dsc); 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; diff --git a/examples/layouts/grid/lv_example_grid_3.c b/examples/layouts/grid/lv_example_grid_3.c index a7e686a0e..4989f22f3 100644 --- a/examples/layouts/grid/lv_example_grid_3.c +++ b/examples/layouts/grid/lv_example_grid_3.c @@ -9,22 +9,18 @@ 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)}; + static lv_coord_t col_dsc[] = {60, LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST}; /*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); + static lv_coord_t row_dsc[] = {40, LV_GRID_FR(1), 40, LV_GRID_TEMPLATE_LAST}; /*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_set_grid_template(cont, col_dsc, row_dsc); lv_obj_t * label; lv_obj_t * obj; diff --git a/examples/layouts/grid/lv_example_grid_4.c b/examples/layouts/grid/lv_example_grid_4.c index 0ce28a712..e884c5076 100644 --- a/examples/layouts/grid/lv_example_grid_4.c +++ b/examples/layouts/grid/lv_example_grid_4.c @@ -6,21 +6,18 @@ */ 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_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST}; + static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST}; - 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_grid_place(cont, LV_GRID_SPACE_BETWEEN, LV_GRID_END); + lv_obj_set_grid_template(cont, col_dsc, row_dsc); 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; diff --git a/examples/layouts/grid/lv_example_grid_5.c b/examples/layouts/grid/lv_example_grid_5.c index 15a0c70b0..c516c3ca9 100644 --- a/examples/layouts/grid/lv_example_grid_5.c +++ b/examples/layouts/grid/lv_example_grid_5.c @@ -18,18 +18,14 @@ 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); + static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST}; + static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST}; /*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_set_grid_template(cont, col_dsc, row_dsc); lv_obj_t * label; lv_obj_t * obj; diff --git a/examples/layouts/grid/lv_example_grid_6.c b/examples/layouts/grid/lv_example_grid_6.c index ca8833775..9624d7e3b 100644 --- a/examples/layouts/grid/lv_example_grid_6.c +++ b/examples/layouts/grid/lv_example_grid_6.c @@ -7,19 +7,15 @@ 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); + static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST}; + static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST}; /*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_set_grid_template(cont, col_dsc, row_dsc); lv_obj_t * label; lv_obj_t * obj; diff --git a/examples/scroll/lv_example_scroll_2.c b/examples/scroll/lv_example_scroll_2.c index 08b89bb3a..5e15c5600 100644 --- a/examples/scroll/lv_example_scroll_2.c +++ b/examples/scroll/lv_example_scroll_2.c @@ -1,5 +1,5 @@ #include "../../lvgl.h" -#if LV_BUILD_EXAMPLES +#if LV_BUILD_EXAMPLES && LV_USE_FLEX static void sw_event_cb(lv_obj_t * sw, lv_event_t e) { @@ -19,7 +19,7 @@ void lv_example_scroll_2(void) lv_obj_t * panel = lv_obj_create(lv_scr_act(), NULL); lv_obj_set_size(panel, 280, 150); lv_obj_set_scroll_snap_x(panel, LV_SCROLL_SNAP_CENTER); - lv_obj_set_layout(panel, &lv_flex_row_nowrap); + lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW); lv_obj_center(panel); uint32_t i; diff --git a/examples/widgets/bar/lv_example_bar_4.c b/examples/widgets/bar/lv_example_bar_4.c index 32193d949..9d4f2f246 100644 --- a/examples/widgets/bar/lv_example_bar_4.c +++ b/examples/widgets/bar/lv_example_bar_4.c @@ -19,7 +19,7 @@ void lv_example_bar_4(void) lv_obj_set_size(bar, 260, 20); lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0); - lv_bar_set_type(bar, LV_BAR_TYPE_RANGE); + lv_bar_set_mode(bar, LV_BAR_MODE_RANGE); lv_bar_set_value(bar, 90, LV_ANIM_OFF); lv_bar_set_start_value(bar, 20, LV_ANIM_OFF); } diff --git a/examples/widgets/btn/lv_example_btn_1.c b/examples/widgets/btn/lv_example_btn_1.c index 9ad53e746..0114ab7eb 100644 --- a/examples/widgets/btn/lv_example_btn_1.c +++ b/examples/widgets/btn/lv_example_btn_1.c @@ -15,21 +15,25 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) void lv_example_btn_1(void) { lv_obj_t * label; - - lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); - lv_obj_add_event_cb(btn1, event_handler, NULL); - lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40); - - label = lv_label_create(btn1, NULL); - lv_label_set_text(label, "Button"); +// +// lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); +// lv_obj_add_event_cb(btn1, event_handler, NULL); +// lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40); +// +// label = lv_label_create(btn1, NULL); +// lv_label_set_text(label, "Button"); +// lv_obj_center(label); lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL); lv_obj_add_event_cb(btn2, event_handler, NULL); lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40); lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE); - lv_obj_set_height(btn2, LV_SIZE_CONTENT); +// lv_obj_set_height(btn2, LV_SIZE_CONTENT); + label = lv_label_create(btn2, NULL); lv_label_set_text(label, "Toggle"); +// lv_obj_update_layout(btn2); +// lv_obj_update_layout(cont); } #endif diff --git a/examples/widgets/calendar/lv_example_calendar_1.c b/examples/widgets/calendar/lv_example_calendar_1.c index f55e8357a..0fcc43a6f 100644 --- a/examples/widgets/calendar/lv_example_calendar_1.c +++ b/examples/widgets/calendar/lv_example_calendar_1.c @@ -37,7 +37,6 @@ void lv_example_calendar_1(void) lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3); - lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, -20); #if LV_USE_CALENDAR_HEADER_DROPDOWN lv_calendar_header_dropdown_create(lv_scr_act(), calendar); #elif LV_USE_CALENDAR_HEADER_ARROW diff --git a/examples/widgets/checkbox/lv_example_checkbox_1.c b/examples/widgets/checkbox/lv_example_checkbox_1.c index 85dc349d9..d44be9915 100644 --- a/examples/widgets/checkbox/lv_example_checkbox_1.c +++ b/examples/widgets/checkbox/lv_example_checkbox_1.c @@ -12,12 +12,8 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) void lv_example_checkbox_1(void) { - static lv_flex_t flex_center; - lv_flex_init(&flex_center); - lv_flex_set_flow(&flex_center, LV_FLEX_FLOW_COLUMN); - lv_flex_set_place(&flex_center, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER); - - lv_obj_set_layout(lv_scr_act(), &flex_center); + lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_place(lv_scr_act(), LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER); lv_obj_t * cb; cb = lv_checkbox_create(lv_scr_act(), NULL); diff --git a/examples/widgets/list/lv_example_list_1.c b/examples/widgets/list/lv_example_list_1.c index 91face9e4..80100cbf1 100644 --- a/examples/widgets/list/lv_example_list_1.c +++ b/examples/widgets/list/lv_example_list_1.c @@ -12,8 +12,20 @@ void lv_example_list_1(void) { /*Create a list*/ list1 = lv_list_create(lv_scr_act()); + lv_obj_set_size(list1, 180, 220); lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0); + + uint32_t t = lv_tick_get(); + int i; + for(i = 0; i < 3; i++) { +// lv_btn_create(lv_scr_act(), NULL); + lv_list_add_btn(list1, LV_SYMBOL_FILE, "New", event_handler); + } + + printf("%d\n", t); + + return; /*Add buttons to the list*/ lv_list_add_text(list1, "File"); lv_list_add_btn(list1, LV_SYMBOL_FILE, "New", event_handler); diff --git a/examples/widgets/slider/lv_example_slider_3.c b/examples/widgets/slider/lv_example_slider_3.c index aeb3e3e1b..89ccde46b 100644 --- a/examples/widgets/slider/lv_example_slider_3.c +++ b/examples/widgets/slider/lv_example_slider_3.c @@ -14,7 +14,7 @@ void lv_example_slider_3(void) slider = lv_slider_create(lv_scr_act(), NULL); lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_add_event_cb(slider, slider_event_cb, NULL); - lv_slider_set_type(slider, LV_SLIDER_TYPE_RANGE); + lv_slider_set_mode(slider, LV_SLIDER_MODE_RANGE); lv_slider_set_value(slider, 70, LV_ANIM_OFF); lv_slider_set_left_value(slider, 20, LV_ANIM_OFF); diff --git a/examples/widgets/switch/lv_example_switch_1.c b/examples/widgets/switch/lv_example_switch_1.c index 8894ece23..e64b8181d 100644 --- a/examples/widgets/switch/lv_example_switch_1.c +++ b/examples/widgets/switch/lv_example_switch_1.c @@ -10,30 +10,25 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) void lv_example_switch_1(void) { - lv_obj_set_layout(lv_scr_act(), &lv_flex_column_center); + lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_place(lv_scr_act(), LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_CENTER); lv_obj_t * sw; sw = lv_switch_create(lv_scr_act(), NULL); - lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, -50); lv_obj_add_event_cb(sw, event_handler, NULL); sw = lv_switch_create(lv_scr_act(), NULL); lv_obj_add_state(sw, LV_STATE_CHECKED); - lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50); lv_obj_add_event_cb(sw, event_handler, NULL); sw = lv_switch_create(lv_scr_act(), NULL); lv_obj_add_state(sw, LV_STATE_DISABLED); - lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50); lv_obj_add_event_cb(sw, event_handler, NULL); sw = lv_switch_create(lv_scr_act(), NULL); lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED); - lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50); lv_obj_add_event_cb(sw, event_handler, NULL); - - } #endif diff --git a/examples/widgets/tabview/lv_example_tabview_1.c b/examples/widgets/tabview/lv_example_tabview_1.c index 9471291ee..7742b7e6e 100644 --- a/examples/widgets/tabview/lv_example_tabview_1.c +++ b/examples/widgets/tabview/lv_example_tabview_1.c @@ -36,7 +36,7 @@ void lv_example_tabview_1(void) label = lv_label_create(tab3, NULL); lv_label_set_text(label, "Third tab"); - lv_obj_scroll_to_view_recursive(label, 1); + lv_obj_scroll_to_view_recursive(label, LV_ANIM_ON); } #endif diff --git a/src/core/lv_indev.c b/src/core/lv_indev.c index 813de9036..ac82b5a7a 100644 --- a/src/core/lv_indev.c +++ b/src/core/lv_indev.c @@ -821,7 +821,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) proc->types.pointer.vect.x = 0; proc->types.pointer.vect.y = 0; - /*Send a Call the ancestor's event handler about the press*/ + /*Call the ancestor's event handler about the press*/ lv_event_send(indev_obj_act, LV_EVENT_PRESSED, NULL); if(indev_reset_check(proc)) return; @@ -859,7 +859,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) /*If there is no scrolling then check for long press time*/ if(proc->types.pointer.scroll_obj == NULL && proc->long_pr_sent == 0) { - /*Send a Call the ancestor's event handler about the long press if enough time elapsed*/ + /*Call the ancestor's event handler about the long press if enough time elapsed*/ if(lv_tick_elaps(proc->pr_timestamp) > indev_act->driver->long_press_time) { lv_event_send(indev_obj_act, LV_EVENT_LONG_PRESSED, NULL); if(indev_reset_check(proc)) return; @@ -874,7 +874,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) /*Send long press repeated Call the ancestor's event handler*/ if(proc->types.pointer.scroll_obj == NULL && proc->long_pr_sent == 1) { - /*Send a Call the ancestor's event handler about the long press repeat if enough time elapsed*/ + /*Call the ancestor's event handler about the long press repeat if enough time elapsed*/ if(lv_tick_elaps(proc->longpr_rep_timestamp) > indev_act->driver->long_press_rep_time) { lv_event_send(indev_obj_act, LV_EVENT_LONG_PRESSED_REPEAT, NULL); if(indev_reset_check(proc)) return; diff --git a/src/core/lv_indev.h b/src/core/lv_indev.h index 7d216c8e7..f275185e0 100644 --- a/src/core/lv_indev.h +++ b/src/core/lv_indev.h @@ -35,11 +35,7 @@ extern "C" { */ void lv_indev_read_timer_cb(lv_timer_t * timer); -/** - * Enable or disable an input devices - * @param indev pointer to an input device - * @param en true: enable; false: disable - */ + void lv_indev_enable(lv_indev_t * indev, bool en); /** diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index 45881464a..b0f55f961 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -298,7 +298,6 @@ lv_res_t lv_obj_event_base(const lv_obj_class_t * class_p, struct _lv_obj_t * ob event_temp_data_head = event_temp_data_head->prev; return res; - } @@ -612,64 +611,16 @@ static void lv_obj_constructor(lv_obj_t * obj, const lv_obj_t * copy) LV_TRACE_OBJ_CREATE("begin"); lv_obj_t * parent = obj->parent; - /*Create a screen*/ - if(parent == NULL) { - LV_TRACE_OBJ_CREATE("creating a screen"); - lv_disp_t * disp = lv_disp_get_default(); - if(!disp) { - LV_LOG_WARN("No display created to so far. No place to assign the new screen"); - return; - } - - if(disp->screens == NULL) { - disp->screens = lv_mem_alloc(sizeof(lv_obj_t *)); - disp->screens[0] = obj; - disp->screen_cnt = 1; - } else { - disp->screen_cnt++; - disp->screens = lv_mem_realloc(disp->screens, sizeof(lv_obj_t *) * disp->screen_cnt); - disp->screens[disp->screen_cnt - 1] = obj; - } - - /*Set coordinates to full screen size*/ - obj->coords.x1 = 0; - obj->coords.y1 = 0; - obj->coords.x2 = lv_disp_get_hor_res(NULL) - 1; - obj->coords.y2 = lv_disp_get_ver_res(NULL) - 1; - } - /*Create a normal object*/ - else { - LV_TRACE_OBJ_CREATE("creating normal object"); - LV_ASSERT_OBJ(parent, MY_CLASS); - if(parent->spec_attr == NULL) { - lv_obj_allocate_spec_attr(parent); - } - - if(parent->spec_attr->children == NULL) { - parent->spec_attr->children = lv_mem_alloc(sizeof(lv_obj_t *)); - parent->spec_attr->children[0] = obj; - parent->spec_attr->child_cnt = 1; - } else { - parent->spec_attr->child_cnt++; - parent->spec_attr->children = lv_mem_realloc(parent->spec_attr->children, sizeof(lv_obj_t *) * parent->spec_attr->child_cnt); - parent->spec_attr->children[parent->spec_attr->child_cnt - 1] = obj; - } - + if(parent) { lv_coord_t sl = lv_obj_get_scroll_left(parent); lv_coord_t st = lv_obj_get_scroll_top(parent); obj->coords.y1 = parent->coords.y1 + lv_obj_get_style_pad_top(parent, LV_PART_MAIN) - st; - obj->coords.y2 = obj->coords.y1 + LV_OBJ_DEF_HEIGHT; - if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) { - obj->coords.x2 = parent->coords.x2 - lv_obj_get_style_pad_right(parent, LV_PART_MAIN) - sl; - obj->coords.x1 = obj->coords.x2 - LV_OBJ_DEF_WIDTH; - } - else { - obj->coords.x1 = parent->coords.x1 + lv_obj_get_style_pad_left(parent, LV_PART_MAIN) - sl; - obj->coords.x2 = obj->coords.x1 + LV_OBJ_DEF_WIDTH; - } - obj->w_set = lv_area_get_width(&obj->coords); - obj->h_set = lv_area_get_height(&obj->coords); + obj->coords.y2 = obj->coords.y1 - 1; + obj->coords.x1 = parent->coords.x1 + lv_obj_get_style_pad_left(parent, LV_PART_MAIN) - sl; + obj->coords.x2 = obj->coords.x1 - 1; + + lv_obj_set_size(obj, LV_OBJ_DEF_WIDTH, LV_OBJ_DEF_HEIGHT); } /*Set attributes*/ @@ -683,30 +634,6 @@ static void lv_obj_constructor(lv_obj_t * obj, const lv_obj_t * copy) obj->flags |= LV_OBJ_FLAG_SCROLL_MOMENTUM; if(parent) obj->flags |= LV_OBJ_FLAG_GESTURE_BUBBLE; - /*Copy the attributes if required*/ - if(copy != NULL) { - lv_area_copy(&obj->coords, ©->coords); - - obj->flags = copy->flags; - if(copy->spec_attr) { - lv_obj_allocate_spec_attr(obj); - lv_memcpy_small(obj->spec_attr, copy->spec_attr, sizeof(lv_obj_spec_attr_t)); - obj->spec_attr->children = NULL; /*Make the child list empty*/ - } - /*Add to the same group*/ - if(copy->spec_attr && copy->spec_attr->group_p) { - obj->spec_attr->group_p = NULL; /*It was simply copied*/ - lv_group_add_obj(copy->spec_attr->group_p, obj); - } - - /*Set the same coordinates for non screen objects*/ - if(lv_obj_get_parent(copy) != NULL && parent != NULL) { - lv_obj_set_pos(obj, lv_obj_get_x(copy), lv_obj_get_y(copy)); - lv_obj_set_size(obj, lv_obj_get_width(copy), lv_obj_get_height(copy)); - - } - } - LV_TRACE_OBJ_CREATE("finished"); } @@ -900,6 +827,7 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc #endif } +#include "lvgl/lvgl.h" static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e) { @@ -972,62 +900,22 @@ static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e) lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED | LV_STATE_FOCUS_KEY); } - else if(e == LV_EVENT_COORD_CHANGED) { - bool w_new = true; - bool h_new = true; - void * param = lv_event_get_param(); - if(param) { - if(lv_area_get_width(param) == lv_obj_get_width(obj)) w_new = false; - if(lv_area_get_height(param) == lv_obj_get_height(obj)) h_new = false; + else if(e == LV_EVENT_SIZE_CHANGED) { + uint32_t i; + for(i = 0; i < lv_obj_get_child_cnt(obj); i++) { + lv_obj_t * child = lv_obj_get_child(obj, i); + + lv_obj_refr_size(child); } - if(w_new || h_new) { - uint32_t i = 0; - for(i = 0; i < lv_obj_get_child_cnt(obj); i++) { - lv_obj_t * child = lv_obj_get_child(obj, i); - if((LV_COORD_IS_PCT(child->w_set) && w_new) || - (LV_COORD_IS_PCT(child->h_set) && h_new)) - { - lv_obj_set_size(child, child->w_set, child->h_set); - } - } + if(lv_obj_get_style_layout(obj, LV_PART_MAIN)) { lv_obj_mark_layout_as_dirty(obj); } - - - if(h_new) { - /*Be sure the bottom side is not remains scrolled in*/ - lv_coord_t st = lv_obj_get_scroll_top(obj); - lv_coord_t sb = lv_obj_get_scroll_bottom(obj); - if(sb < 0 && st > 0) { - sb = LV_MIN(st, -sb); - lv_obj_scroll_by(obj, 0, sb, LV_ANIM_OFF); - } - } - - if(w_new) { - lv_coord_t sl = lv_obj_get_scroll_left(obj); - lv_coord_t sr = lv_obj_get_scroll_right(obj); - if(lv_obj_get_base_dir(obj) != LV_BIDI_DIR_RTL) { - /*Be sure the left side is not remains scrolled in*/ - if(sr < 0 && sl > 0) { - sr = LV_MIN(sl, -sr); - lv_obj_scroll_by(obj, 0, sr, LV_ANIM_OFF); - } - } else { - /*Be sure the right side is not remains scrolled in*/ - if(sl < 0 && sr > 0) { - sr = LV_MIN(sr, -sl); - lv_obj_scroll_by(obj, 0, sl, LV_ANIM_OFF); - } - } - } } else if(e == LV_EVENT_CHILD_CHANGED) { - lv_obj_mark_layout_as_dirty(obj); - - if(obj->w_set == LV_SIZE_CONTENT || obj->h_set == LV_SIZE_CONTENT) { - lv_obj_set_size(obj, obj->w_set, obj->h_set); +// lv_obj_mark_layout_as_dirty(obj); + if(lv_obj_get_style_layout(obj, LV_PART_MAIN)) { + lv_obj_mark_layout_as_dirty(obj); } } else if(e == LV_EVENT_BASE_DIR_CHANGED) { @@ -1047,20 +935,18 @@ static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e) } else if(e == LV_EVENT_STYLE_CHANGED) { /*Padding might have changed so the layout should be recalculated*/ - lv_obj_mark_layout_as_dirty(obj); - - /*Reposition non grid objects on by one*/ uint32_t i; for(i = 0; i < lv_obj_get_child_cnt(obj); i++) { - lv_obj_t * child = lv_obj_get_child(obj, i); - if(LV_COORD_IS_PX(child->x_set) || LV_COORD_IS_PX(child->y_set)) { - lv_obj_set_pos(child, child->x_set, child->y_set); - } + lv_obj_t * child = lv_obj_get_child(obj, i); + + lv_obj_refr_size(child); + lv_obj_refr_pos(child); } - if(obj->w_set == LV_SIZE_CONTENT || obj->h_set == LV_SIZE_CONTENT) { - lv_obj_set_size(obj, obj->w_set, obj->h_set); + if(lv_obj_get_style_layout(obj, LV_PART_MAIN)) { + lv_obj_mark_layout_as_dirty(obj); } + lv_obj_refresh_ext_draw_size(obj); } else if(e == LV_EVENT_DRAW_MAIN || e == LV_EVENT_DRAW_POST || e == LV_EVENT_COVER_CHECK) { @@ -1190,7 +1076,7 @@ static bool event_is_bubbled(lv_event_t e) case LV_EVENT_REFRESH: case LV_EVENT_DELETE: case LV_EVENT_CHILD_CHANGED: - case LV_EVENT_COORD_CHANGED: + case LV_EVENT_SIZE_CHANGED: case LV_EVENT_STYLE_CHANGED: case LV_EVENT_GET_SELF_SIZE: return false; diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index 3d1ca4cb5..c31048fbf 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -82,7 +82,7 @@ typedef enum { LV_EVENT_READY, /**< A process has finished*/ LV_EVENT_CANCEL, /**< A process has been cancelled */ LV_EVENT_CHILD_CHANGED, /**< Child was removed/added*/ - LV_EVENT_COORD_CHANGED, /**< Object coordinates/size have changed*/ + LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/ LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/ LV_EVENT_BASE_DIR_CHANGED, /**< The base dir has changed*/ LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/ @@ -220,8 +220,6 @@ typedef struct { uint32_t child_cnt; /**< Number of children*/ lv_group_t * group_p; - const lv_layout_dsc_t * layout_dsc; /**< Pointer to the layout descriptor*/ - lv_event_dsc_t * event_dsc; /**< Dynamically allocated event callback and user data array*/ lv_point_t scroll; /**< The current X/Y scroll offset*/ @@ -242,15 +240,13 @@ typedef struct _lv_obj_t { lv_obj_spec_attr_t * spec_attr; lv_obj_style_t * styles; lv_area_t coords; - lv_coord_t x_set; - lv_coord_t y_set; - lv_coord_t w_set; - lv_coord_t h_set; lv_obj_flag_t flags; lv_state_t state; - uint8_t layout_inv :1; - uint8_t skip_trans :1; - uint8_t style_cnt :6; + uint16_t layout_inv :1; + uint16_t skip_trans :1; + uint16_t style_cnt :6; + uint16_t h_layout :1; + uint16_t w_layout :1; }lv_obj_t; diff --git a/src/core/lv_obj_class.c b/src/core/lv_obj_class.c index 8c52b66fb..7d9c6afe0 100644 --- a/src/core/lv_obj_class.c +++ b/src/core/lv_obj_class.c @@ -49,20 +49,18 @@ lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class_p, lv_obj_t * p obj->class_p = class_p; obj->parent = parent; + lv_theme_apply(obj); lv_obj_construct(obj, copy); - if(parent) { - /*Send a Call the ancestor's event handler to the parent to notify it about the new child. - *Also triggers layout update*/ - lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj); + if(parent) { + /*Call the ancestor's event handler to the parent to notify it about the new child. + *Also triggers layout update*/ + lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj); - /*Invalidate the area if not screen created*/ - lv_obj_invalidate(obj); - } + /*Invalidate the area if not screen created*/ + lv_obj_invalidate(obj); + } - if(!copy) lv_theme_apply(obj); - - LV_TRACE_OBJ_CREATE("Object created at %p address with %p class on %p parent", obj, class_p, parent); return obj; } diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index fa19744a0..1c931713a 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -22,15 +22,14 @@ /********************** * STATIC PROTOTYPES **********************/ -static bool refr_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); static void calc_auto_size(lv_obj_t * obj, lv_coord_t * w_out, lv_coord_t * h_out); static void layout_update_core(lv_obj_t * obj); -void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify); - /********************** * STATIC VARIABLES **********************/ +static lv_layout_update_cb_t * layouts; +static uint32_t layout_cnt; /********************** * MACROS @@ -44,50 +43,69 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) { LV_ASSERT_OBJ(obj, MY_CLASS); - if(lv_obj_is_layout_positioned(obj)) { - return; - } + lv_obj_set_x(obj, x); + lv_obj_set_y(obj, y); - obj->x_set = x; - obj->y_set = y; - - lv_obj_move_to(obj, x, y, true); } void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x) { LV_ASSERT_OBJ(obj, MY_CLASS); + if(lv_obj_is_layout_positioned(obj)) { + return; + } - lv_obj_set_pos(obj, x, obj->y_set); + lv_res_t res_x; + lv_style_value_t v_x; + + res_x = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_X, &v_x); + + if((res_x == LV_RES_OK && v_x.num != x) || res_x == LV_RES_INV) { + lv_obj_set_style_x(obj, LV_PART_MAIN, LV_STATE_DEFAULT, x); + } + + lv_obj_refr_pos(obj); } void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y) { + if(lv_obj_is_layout_positioned(obj)) { + return; + } LV_ASSERT_OBJ(obj, MY_CLASS); - lv_obj_set_pos(obj, obj->x_set, y); + lv_res_t res_y; + lv_style_value_t v_y; + + res_y = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_Y, &v_y); + + if((res_y == LV_RES_OK && v_y.num != y) || res_y == LV_RES_INV) { + lv_obj_set_style_y(obj, LV_PART_MAIN, LV_STATE_DEFAULT, y); + } + + lv_obj_refr_pos(obj); } -void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) +void lv_obj_refr_size(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); /*If the width or height is set by a layout do not modify them*/ - if(obj->w_set == LV_SIZE_LAYOUT && obj->h_set == LV_SIZE_LAYOUT) return; - if(obj->w_set == LV_SIZE_LAYOUT) w = lv_obj_get_width(obj); - if(obj->h_set == LV_SIZE_LAYOUT) h = lv_obj_get_height(obj); + if(obj->w_layout && obj->h_layout) return; - obj->w_set = w; - obj->h_set = h; + lv_obj_t * parent = lv_obj_get_parent(obj); + if(parent == NULL) return; - /*If the width or height is set to special layout related value save them in w_set and h_set - *but use the current size on the object width*/ - if(LV_COORD_IS_LAYOUT(w)) w = lv_obj_get_width(obj); - if(LV_COORD_IS_LAYOUT(h)) h = lv_obj_get_height(obj); + lv_coord_t w; + lv_coord_t h; + if(obj->w_layout) w = lv_obj_get_width(obj); + else w = lv_obj_get_style_width(obj, LV_PART_MAIN); + if(obj->h_layout) h = lv_obj_get_height(obj); + else h = lv_obj_get_style_height(obj, LV_PART_MAIN); /*Calculate the required auto sizes*/ - bool w_content = obj->w_set == LV_SIZE_CONTENT ? true : false; - bool h_content = obj->h_set == LV_SIZE_CONTENT ? true : false; + bool w_content = w == LV_SIZE_CONTENT ? true : false; + bool h_content = h == LV_SIZE_CONTENT ? true : false; /*Be sure the object is not scrolled when it has auto size*/ if(w_content) lv_obj_scroll_to_x(obj, 0, LV_ANIM_OFF); @@ -98,32 +116,97 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) else if(h_content) calc_auto_size(obj, NULL, &h); /*Calculate the required auto sizes*/ - bool pct_w = LV_COORD_IS_PCT(obj->w_set) ? true : false; - bool pct_h = LV_COORD_IS_PCT(obj->h_set) ? true : false; + bool pct_w = LV_COORD_IS_PCT(w) ? true : false; + bool pct_h = LV_COORD_IS_PCT(h) ? true : false; - lv_obj_t * parent = lv_obj_get_parent(obj); - if(parent) { - lv_coord_t parent_w = lv_obj_get_width_fit(parent); - lv_coord_t parent_h = lv_obj_get_height_fit(parent); - if(pct_w) w = (LV_COORD_GET_PCT(obj->w_set) * parent_w) / 100; - if(pct_h) h = (LV_COORD_GET_PCT(obj->h_set) * parent_h) / 100; + lv_coord_t parent_w = lv_obj_get_width_fit(parent); + lv_coord_t parent_h = lv_obj_get_height_fit(parent); + if(pct_w) w = (LV_COORD_GET_PCT(w) * parent_w) / 100; + if(pct_h) h = (LV_COORD_GET_PCT(h) * parent_h) / 100; + + /*Do nothing if the size is not changed*/ + /*It is very important else recursive resizing can occur without size change*/ + if(lv_obj_get_width(obj) == w && lv_obj_get_height(obj) == h) return; + + /*Invalidate the original area*/ + lv_obj_invalidate(obj); + + /*Save the original coordinates*/ + lv_area_t ori; + lv_obj_get_coords(obj, &ori); + + /*Check if the object inside the parent or not*/ + lv_area_t parent_fit_area; + lv_obj_get_coords_fit(parent, &parent_fit_area); + + /*If the object is already out of the parent and its position is changes + *surely the scrollbars also changes so invalidate them*/ + bool on1 = _lv_area_is_in(&ori, &parent_fit_area, 0); + if(!on1) lv_obj_scrollbar_invalidate(parent); + + /*Set the length and height + *Be sure the content is not scrolled in an invalid position on the new size*/ + obj->coords.y2 = obj->coords.y1 + h - 1; + if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) { + obj->coords.x1 = obj->coords.x2 - w + 1; + } + else { + obj->coords.x2 = obj->coords.x1 + w - 1; } - refr_size(obj, w, h); + /*Call the ancestor's event handler to the object with its new coordinates*/ + lv_event_send(obj, LV_EVENT_SIZE_CHANGED, &ori); + + /*Call the ancestor's event handler to the parent too*/ + lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj); + + /*Invalidate the new area*/ + lv_obj_invalidate(obj); + + /*Calculate the required auto sizes*/ + + /*If the object was out of the parent invalidate the new scrollbar area too. + *If it wasn't out of the parent but out now, also invalidate the srollbars*/ + bool on2 = _lv_area_is_in(&obj->coords, &parent_fit_area, 0); + if(on1 || (!on1 && on2)) lv_obj_scrollbar_invalidate(parent); +} + +void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) +{ + LV_ASSERT_OBJ(obj, MY_CLASS); + + lv_obj_set_width(obj, w); + lv_obj_set_height(obj, h); } void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w) { LV_ASSERT_OBJ(obj, MY_CLASS); + lv_res_t res_w; + lv_style_value_t v_w; - lv_obj_set_size(obj, w, obj->h_set); + res_w = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_WIDTH, &v_w); + + if((res_w == LV_RES_OK && v_w.num != w) || res_w == LV_RES_INV) { + lv_obj_set_style_width(obj, LV_PART_MAIN, LV_STATE_DEFAULT, w); + } + + lv_obj_refr_size(obj); } void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h) { LV_ASSERT_OBJ(obj, MY_CLASS); + lv_res_t res_h; + lv_style_value_t v_h; - lv_obj_set_size(obj, obj->w_set, h); + res_h = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_HEIGHT, &v_h); + + if((res_h == LV_RES_OK && v_h.num != h) || res_h == LV_RES_INV) { + lv_obj_set_style_height(obj, LV_PART_MAIN, LV_STATE_DEFAULT, h); + } + + lv_obj_refr_size(obj); } void lv_obj_set_content_width(lv_obj_t * obj, lv_coord_t w) @@ -142,12 +225,11 @@ void lv_obj_set_content_height(lv_obj_t * obj, lv_coord_t h) lv_obj_set_height(obj, h + ptop + pbottom); } -void lv_obj_set_layout(lv_obj_t * obj, const void * layout) +void lv_obj_set_layout(lv_obj_t * obj, uint32_t layout) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_obj_allocate_spec_attr(obj); - obj->spec_attr->layout_dsc = layout; + lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, layout); lv_obj_mark_layout_as_dirty(obj); } @@ -158,7 +240,9 @@ bool lv_obj_is_layout_positioned(const lv_obj_t * obj) lv_obj_t * parent = lv_obj_get_parent(obj); if(parent == NULL) return false; - if(parent->spec_attr && parent->spec_attr->layout_dsc) return true; + + uint32_t layout = lv_obj_get_style_layout(parent, LV_PART_MAIN); + if(layout) return true; else return false; } @@ -177,27 +261,41 @@ void lv_obj_mark_layout_as_dirty(lv_obj_t * obj) void lv_obj_update_layout(lv_obj_t * obj) { + static bool mutex = false; + if(mutex) { + LV_LOG_TRACE("Already running, returning") + return; + } + mutex = true; + lv_obj_t * scr = lv_obj_get_screen(obj); - /*There are no dirty layouts on this screen*/ - if(scr->layout_inv == 0) return; - - do { + /*Repeat until there where layout invalidations*/ + while(scr->layout_inv) { + LV_LOG_INFO("Start layout update") scr->layout_inv = 0; - layout_update_core(obj); - }while(scr->layout_inv); /*Repeat until there where layout invalidations*/ + layout_update_core(scr); + LV_LOG_TRACE("Layout update finished") + } - /*Restore the global state because other calls of this function needs this info too. - *Other calls might use different start object, but they need to know if there is dirty layout somewhere. - *However if the screen was updated it's sure that all layouts are ready.*/ - if(obj != scr) scr->layout_inv = 1; + mutex = false; +} +uint32_t lv_layout_register(lv_layout_update_cb_t cb) +{ + layout_cnt++; + layouts = lv_mem_realloc(layouts, layout_cnt * sizeof(lv_layout_update_cb_t)); + LV_ASSERT_MALLOC(layouts); + + layouts[layout_cnt - 1] = cb; + return layout_cnt; /*No -1 to skip 0th index*/ } void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs) { LV_ASSERT_OBJ(obj, MY_CLASS); + lv_obj_update_layout(obj); if(base == NULL) base = lv_obj_get_parent(obj); LV_ASSERT_OBJ(base, MY_CLASS); @@ -311,8 +409,8 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co break; } - x += x_ofs + base->coords.x1 - parent->coords.x1; - y += y_ofs + base->coords.y1 - parent->coords.y1; + x += x_ofs + base->coords.x1 - parent->coords.x1 + lv_obj_get_scroll_left(parent); + y += y_ofs + base->coords.y1 - parent->coords.y1 + lv_obj_get_scroll_top(parent); lv_obj_set_pos(obj, x, y); } @@ -341,6 +439,13 @@ lv_coord_t lv_obj_get_x(const lv_obj_t * obj) return rel_x; } +lv_coord_t lv_obj_get_x2(const lv_obj_t * obj) +{ + LV_ASSERT_OBJ(obj, MY_CLASS); + + return lv_obj_get_x(obj) + lv_obj_get_width(obj); +} + lv_coord_t lv_obj_get_y(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -358,6 +463,13 @@ lv_coord_t lv_obj_get_y(const lv_obj_t * obj) return rel_y; } +lv_coord_t lv_obj_get_y2(const lv_obj_t * obj) +{ + LV_ASSERT_OBJ(obj, MY_CLASS); + + return lv_obj_get_y(obj) + lv_obj_get_height(obj); +} + lv_coord_t lv_obj_get_width(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -406,7 +518,7 @@ void lv_obj_get_coords_fit(const lv_obj_t * obj, lv_area_t * area) lv_coord_t lv_obj_get_height_visible(const lv_obj_t * obj) { - lv_obj_update_layout(lv_obj_get_screen(obj)); + lv_obj_update_layout(obj); lv_coord_t h = LV_COORD_MAX; lv_obj_t * parent = lv_obj_get_parent(obj); @@ -420,7 +532,7 @@ lv_coord_t lv_obj_get_height_visible(const lv_obj_t * obj) lv_coord_t lv_obj_get_width_visible(const lv_obj_t * obj) { - lv_obj_update_layout(lv_obj_get_screen(obj)); + lv_obj_update_layout(obj); lv_coord_t w = LV_COORD_MAX; lv_obj_t * parent = lv_obj_get_parent(obj); @@ -448,14 +560,25 @@ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj) bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj) { - if(obj->w_set != LV_SIZE_CONTENT && obj->h_set == LV_SIZE_CONTENT) return false; + lv_coord_t w_set = lv_obj_get_style_width(obj, LV_PART_MAIN); + lv_coord_t h_set = lv_obj_get_style_height(obj, LV_PART_MAIN); + if(w_set != LV_SIZE_CONTENT && h_set == LV_SIZE_CONTENT) return false; - lv_obj_set_size(obj, obj->w_set, obj->h_set); + lv_obj_refr_size(obj); return true; } -void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify) +void lv_obj_refr_pos(lv_obj_t * obj) { + lv_coord_t x = lv_obj_get_style_x(obj, LV_PART_MAIN); + lv_coord_t y = lv_obj_get_style_y(obj, LV_PART_MAIN); + lv_obj_move_to(obj, x, y); +} + +void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) +{ + if(lv_obj_is_layout_positioned(obj)) return; + /*Convert x and y to absolute coordinates*/ lv_obj_t * parent = obj->parent; @@ -503,11 +626,8 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify) lv_obj_move_children_by(obj, diff.x, diff.y, false); - /*Inform the object about its new coordinates*/ - lv_event_send(obj, LV_EVENT_COORD_CHANGED, &ori); - - /*Send a Call the ancestor's event handler to the parent too*/ - if(parent && notify) lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj); + /*Call the ancestor's event handler to the parent too*/ + if(parent) lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj); /*Invalidate the new area*/ lv_obj_invalidate(obj); @@ -664,71 +784,6 @@ bool lv_obj_hit_test(lv_obj_t * obj, const lv_point_t * point) * STATIC FUNCTIONS **********************/ -/** - * Set the size of an object. - * It's the core function to set the size of objects but user should use `lv_obj_set_size/width/height/..` etc. - * @param obj pointer to an object - * @param w the new width in pixels - * @param h the new height in pixels - * @return true: the size was changed; false: `w` and `h` was equal to the current width and height so nothing happened. - */ -static bool refr_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) -{ - lv_obj_t * parent = lv_obj_get_parent(obj); - if(parent == NULL) return false; - - /*If the size is managed by the layout don't let to overwrite it.*/ - if(obj->w_set == LV_SIZE_LAYOUT) w = lv_obj_get_width(obj); - if(obj->h_set == LV_SIZE_LAYOUT) h = lv_obj_get_height(obj); - - /*Do nothing if the size is not changed*/ - /*It is very important else recursive resizing can - *occur without size change*/ - if(lv_obj_get_width(obj) == w && lv_obj_get_height(obj) == h) { - return false; - } - /*Invalidate the original area*/ - lv_obj_invalidate(obj); - - /*Save the original coordinates*/ - lv_area_t ori; - lv_obj_get_coords(obj, &ori); - - /*Check if the object inside the parent or not*/ - lv_area_t parent_fit_area; - lv_obj_get_coords_fit(parent, &parent_fit_area); - - /*If the object is already out of the parent and its position is changes - *surely the scrollbars also changes so invalidate them*/ - bool on1 = _lv_area_is_in(&ori, &parent_fit_area, 0); - if(!on1) lv_obj_scrollbar_invalidate(parent); - - /*Set the length and height - *Be sure the content is not scrolled in an invalid position on the new size*/ - obj->coords.y2 = obj->coords.y1 + h - 1; - if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) { - obj->coords.x1 = obj->coords.x2 - w + 1; - } - else { - obj->coords.x2 = obj->coords.x1 + w - 1; - } - - /*Send a Call the ancestor's event handler to the object with its new coordinates*/ - lv_event_send(obj, LV_EVENT_COORD_CHANGED, &ori); - - /*Send a Call the ancestor's event handler to the parent too*/ - if(parent != NULL) lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj); - - /*Invalidate the new area*/ - lv_obj_invalidate(obj); - - /*If the object was out of the parent invalidate the new scrollbar area too. - *If it wasn't out of the parent but out now, also invalidate the srollbars*/ - bool on2 = _lv_area_is_in(&obj->coords, &parent_fit_area, 0); - if(on1 || (!on1 && on2)) lv_obj_scrollbar_invalidate(parent); - return true; -} - /** * Calculate the "auto size". It's `auto_size = max(children_size, self_size)` @@ -761,12 +816,41 @@ static void layout_update_core(lv_obj_t * obj) layout_update_core(child); } - if(!obj->layout_inv) return; + if(obj->layout_inv == 0) return; - const lv_layout_dsc_t * layout = obj->spec_attr ? obj->spec_attr->layout_dsc : NULL; - const lv_layout_update_cb_t update_cp = layout ? layout->update_cb : NULL; - if(update_cp != NULL && lv_obj_get_child_cnt(obj) > 0) { - obj->layout_inv = 0; - update_cp(obj); + if(lv_obj_get_screen(obj) != obj) obj->layout_inv = 0; + + lv_obj_refr_size(obj); + lv_obj_refr_pos(obj); + + /*Be sure the bottom side is not remains scrolled in*/ + lv_coord_t st = lv_obj_get_scroll_top(obj); + lv_coord_t sb = lv_obj_get_scroll_bottom(obj); + if(sb < 0 && st > 0) { + sb = LV_MIN(st, -sb); + lv_obj_scroll_by(obj, 0, sb, LV_ANIM_OFF); + } + + lv_coord_t sl = lv_obj_get_scroll_left(obj); + lv_coord_t sr = lv_obj_get_scroll_right(obj); + if(lv_obj_get_base_dir(obj) != LV_BIDI_DIR_RTL) { + /*Be sure the left side is not remains scrolled in*/ + if(sr < 0 && sl > 0) { + sr = LV_MIN(sl, -sr); + lv_obj_scroll_by(obj, 0, sr, LV_ANIM_OFF); + } + } else { + /*Be sure the right side is not remains scrolled in*/ + if(sl < 0 && sr > 0) { + sr = LV_MIN(sr, -sl); + lv_obj_scroll_by(obj, 0, sl, LV_ANIM_OFF); + } + } + + if(lv_obj_get_child_cnt(obj) > 0) { + uint32_t layout_id = lv_obj_get_style_layout(obj, LV_PART_MAIN); + if(layout_id > 0 && layout_id <= layout_cnt) { + layouts[layout_id -1](obj); + } } } diff --git a/src/core/lv_obj_pos.h b/src/core/lv_obj_pos.h index ec1471660..4ee953eff 100644 --- a/src/core/lv_obj_pos.h +++ b/src/core/lv_obj_pos.h @@ -23,17 +23,7 @@ extern "C" { * TYPEDEFS **********************/ struct _lv_obj_t; - -typedef void (*lv_layout_update_cb_t)(struct _lv_obj_t * cont); - -/** - * The base of all layouts descriptor. - * Every custom layout descriptor needs to extend this struct - * by adding `lv_layout_dsc_t` as the first element. - */ -typedef struct { - lv_layout_update_cb_t update_cb; -}lv_layout_dsc_t; +typedef void (*lv_layout_update_cb_t)(struct _lv_obj_t *); /********************** * GLOBAL PROTOTYPES @@ -74,6 +64,8 @@ void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y); */ void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); +void lv_obj_refr_size(struct _lv_obj_t * obj); + /** * Set the width of an object * @param obj pointer to an object @@ -117,7 +109,7 @@ void lv_obj_set_content_height(struct _lv_obj_t * obj, lv_coord_t h); * @param obj pointer to an object * @param layout pointer to a layout descriptor to set */ -void lv_obj_set_layout(struct _lv_obj_t * obj, const void * layout); +void lv_obj_set_layout(struct _lv_obj_t * obj, uint32_t layout); /** * Test whether the and object is positioned by a layout or not @@ -138,6 +130,12 @@ void lv_obj_mark_layout_as_dirty(struct _lv_obj_t * obj); */ void lv_obj_update_layout(struct _lv_obj_t * obj); +/** + * Regsiter a new layout + * @param cb the layout update callback + * @return the ID of the new layout + */ +uint32_t lv_layout_register(lv_layout_update_cb_t cb); /** * Align an object to an other object. @@ -178,6 +176,16 @@ void lv_obj_get_coords(const struct _lv_obj_t * obj, lv_area_t * coords); */ lv_coord_t lv_obj_get_x(const struct _lv_obj_t * obj); +/** + * Get the x2 coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the right side of its parent plus the parent's right padding + * @note Zero return value means the object is on the right padding of the parent, and not on the right edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_x2(const struct _lv_obj_t * obj); + /** * Get the y coordinate of object. * @param obj pointer to an object @@ -188,6 +196,16 @@ lv_coord_t lv_obj_get_x(const struct _lv_obj_t * obj); */ lv_coord_t lv_obj_get_y(const struct _lv_obj_t * obj); +/** + * Get the y2 coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the bottom side of its parent plus the parent's bottom padding + * @note Zero return value means the object is on the bottom padding of the parent, and not on the bottom edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_y2(const struct _lv_obj_t * obj); + /** * Get the width of an object * @param obj pointer to an object @@ -266,6 +284,9 @@ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj); */ bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj); +void lv_obj_refr_pos(struct _lv_obj_t * obj); + +void lv_obj_move_to(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); void lv_obj_move_children_by(struct _lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff, bool ignore_floating); diff --git a/src/core/lv_obj_scroll.c b/src/core/lv_obj_scroll.c index d0a7549fa..db65db6af 100644 --- a/src/core/lv_obj_scroll.c +++ b/src/core/lv_obj_scroll.c @@ -333,7 +333,7 @@ void lv_obj_scroll_to_y(lv_obj_t * obj, lv_coord_t y, lv_anim_enable_t anim_en) void lv_obj_scroll_to_view(lv_obj_t * obj, lv_anim_enable_t anim_en) { /*Be sure the screens layout is correct*/ - lv_obj_update_layout(lv_obj_get_screen(obj)); + lv_obj_update_layout(obj); lv_point_t p = {0, 0}; scroll_area_into_view(&obj->coords, obj, &p, anim_en); @@ -342,7 +342,7 @@ void lv_obj_scroll_to_view(lv_obj_t * obj, lv_anim_enable_t anim_en) void lv_obj_scroll_to_view_recursive(lv_obj_t * obj, lv_anim_enable_t anim_en) { /*Be sure the screens layout is correct*/ - lv_obj_update_layout(lv_obj_get_screen(obj)); + lv_obj_update_layout(obj); lv_point_t p = {0, 0}; lv_obj_t * child = obj; diff --git a/src/core/lv_obj_style.c b/src/core/lv_obj_style.c index cbfc7a668..8f7799cbf 100644 --- a/src/core/lv_obj_style.c +++ b/src/core/lv_obj_style.c @@ -223,6 +223,22 @@ void lv_obj_set_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, lv_obj_refresh_style(obj, part, prop); } + +lv_res_t lv_obj_get_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop, lv_style_value_t * value) +{ + uint32_t i; + for(i = 0; i < obj->style_cnt; i++) { + if(obj->styles[i].is_local && + obj->styles[i].part == part && + obj->styles[i].state == state) + { + return lv_style_get_prop(obj->styles[i].style, prop, value); + } + } + + return LV_RES_INV; +} + bool lv_obj_remove_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -416,6 +432,7 @@ static lv_style_t * get_local_style(lv_obj_t * obj, uint32_t part, uint32_t stat obj->style_cnt++; obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(lv_obj_style_t)); + LV_ASSERT_MALLOC(obj->styles); for(i = obj->style_cnt - 1; i > 0 ; i--) { /*Copy only normal styles (not local and transition). diff --git a/src/core/lv_obj_style.h b/src/core/lv_obj_style.h index d17ee6113..d06e9553b 100644 --- a/src/core/lv_obj_style.h +++ b/src/core/lv_obj_style.h @@ -128,6 +128,8 @@ lv_style_value_t lv_obj_get_style_prop(const struct _lv_obj_t * obj, uint8_t par */ void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop, lv_style_value_t value); +lv_res_t lv_obj_get_local_style_prop(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop, lv_style_value_t * value); + /** * Remove a local style property from a part of an object with a given state. * @param obj pointer to an object diff --git a/src/core/lv_obj_style_gen.h b/src/core/lv_obj_style_gen.h index b38169f2e..8e8e355c0 100644 --- a/src/core/lv_obj_style_gen.h +++ b/src/core/lv_obj_style_gen.h @@ -112,6 +112,37 @@ static inline lv_coord_t lv_obj_get_style_pad_column(const struct _lv_obj_t * ob return (lv_coord_t)v.num; } +static inline lv_coord_t lv_obj_get_style_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_Y); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_layout(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LAYOUT); + return (lv_coord_t)v.num; +} + + static inline lv_color_t lv_obj_get_style_bg_color(const struct _lv_obj_t * obj, uint32_t part) { lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_COLOR); @@ -672,6 +703,46 @@ static inline void lv_obj_set_style_pad_column(struct _lv_obj_t * obj, uint32_t lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_PAD_COLUMN, v); } +static inline void lv_obj_set_style_width(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_WIDTH, v); +} + +static inline void lv_obj_set_style_height(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_HEIGHT, v); +} + +static inline void lv_obj_set_style_x(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_X, v); +} + +static inline void lv_obj_set_style_y(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_Y, v); +} +static inline void lv_obj_set_style_layout(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_LAYOUT, v); +} + + static inline void lv_obj_set_style_bg_color(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_color_t value) { lv_style_value_t v = { diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index b447540ae..d13ff2ae6 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -64,7 +64,7 @@ void lv_obj_del(lv_obj_t * obj) obj_del_core(obj); - /*Send a Call the ancestor's event handler to the parent to notify it about the child delete*/ + /*Call the ancestor's event handler to the parent to notify it about the child delete*/ if(par) { /*Just to remove scroll animations if any*/ lv_obj_scroll_to(par, 0, 0, LV_ANIM_OFF); diff --git a/src/core/lv_refr.c b/src/core/lv_refr.c index 4446faca0..3c6cc4a2a 100644 --- a/src/core/lv_refr.c +++ b/src/core/lv_refr.c @@ -197,10 +197,8 @@ void _lv_disp_refr_timer(lv_timer_t * tmr) #endif /*Refresh the screen's layout if required*/ - uint32_t i; - for(i = 0; i < disp_refr->screen_cnt; i++) { - lv_obj_update_layout(disp_refr->screens[i]); - } + lv_obj_update_layout(disp_refr->act_scr); + if(disp_refr->prev_scr) lv_obj_update_layout(disp_refr->prev_scr); lv_obj_update_layout(disp_refr->top_layer); lv_obj_update_layout(disp_refr->sys_layer); diff --git a/src/core/lv_theme.c b/src/core/lv_theme.c index 4f4f4a699..ce59a4ea0 100644 --- a/src/core/lv_theme.c +++ b/src/core/lv_theme.c @@ -49,14 +49,9 @@ void lv_theme_apply(lv_obj_t * obj) lv_theme_t * th = lv_theme_get_from_obj(obj); if(th == NULL) return; - lv_obj_enable_style_refresh(false); - lv_obj_remove_style(obj, LV_PART_ANY, LV_STATE_ANY, NULL); apply_theme(th, obj); /*Apply the theme including the base theme(s)*/ - - lv_obj_enable_style_refresh(true); - lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ALL); } /** diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index 68f405eed..72b30b29b 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -17,6 +17,15 @@ /********************** * TYPEDEFS **********************/ +typedef struct { + lv_flex_place_t main_place; + lv_flex_place_t cross_place; + lv_flex_place_t track_place; + uint8_t row :1; + uint8_t wrap :1; + uint8_t rev :1; +}flex_t; + typedef struct { lv_coord_t grow_unit; lv_coord_t track_cross_size; @@ -33,66 +42,20 @@ typedef struct { * STATIC PROTOTYPES **********************/ static void flex_update(lv_obj_t * cont); -static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t item_gap, lv_coord_t max_main_size, track_t * t); -static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t); +static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t item_gap, lv_coord_t max_main_size, track_t * t); +static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t); static void place_content(lv_flex_place_t place, lv_coord_t max_size, lv_coord_t content_size, lv_coord_t item_cnt, lv_coord_t * start_pos, lv_coord_t * gap); static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id); /********************** * GLOBAL VARIABLES **********************/ - -const lv_flex_t lv_flex_row_center = { - .base.update_cb = flex_update, - .main_place = LV_FLEX_PLACE_CENTER, - .cross_place = LV_FLEX_PLACE_CENTER, - .track_place = LV_FLEX_PLACE_CENTER, - .dir = LV_FLEX_FLOW_ROW, - .wrap = 1 -}; - -const lv_flex_t lv_flex_column_center = { - .base.update_cb = flex_update, - .main_place = LV_FLEX_PLACE_CENTER, - .cross_place = LV_FLEX_PLACE_CENTER, - .track_place = LV_FLEX_PLACE_CENTER, - .dir = LV_FLEX_FLOW_COLUMN, - .wrap = 1 -}; - -const lv_flex_t lv_flex_row_wrap = { - .base.update_cb = flex_update, - .main_place = LV_FLEX_PLACE_START, - .cross_place = LV_FLEX_PLACE_CENTER, - .track_place = LV_FLEX_PLACE_START, - .dir = LV_FLEX_FLOW_ROW, - .wrap = 1 -}; - -const lv_flex_t lv_flex_row_even = { - .base.update_cb = flex_update, - .main_place = LV_FLEX_PLACE_SPACE_EVENLY, - .cross_place = LV_FLEX_PLACE_CENTER, - .track_place = LV_FLEX_PLACE_CENTER, - .dir = LV_FLEX_FLOW_ROW, - .wrap = 1 -}; - -const lv_flex_t lv_flex_column_nowrap = { - .base.update_cb = flex_update, - .main_place = LV_FLEX_PLACE_START, - .cross_place = LV_FLEX_PLACE_CENTER, - .track_place = LV_FLEX_PLACE_START, - .dir = LV_FLEX_FLOW_COLUMN -}; - -const lv_flex_t lv_flex_row_nowrap = { - .base.update_cb = flex_update, - .main_place = LV_FLEX_PLACE_START, - .cross_place = LV_FLEX_PLACE_CENTER, - .track_place = LV_FLEX_PLACE_START, - .dir = LV_FLEX_FLOW_ROW -}; +uint32_t LV_LAYOUT_FLEX; +lv_style_prop_t LV_STYLE_FLEX_FLOW; +lv_style_prop_t LV_STYLE_FLEX_MAIN_PLACE; +lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE; +lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE; +lv_style_prop_t LV_STYLE_FLEX_GROW; /********************** @@ -111,41 +74,33 @@ const lv_flex_t lv_flex_row_nowrap = { * Setter functions *====================*/ -void lv_flex_init(lv_flex_t * flex) +void lv_flex_init(void) { - lv_memset_00(flex, sizeof(lv_flex_t)); - flex->base.update_cb = flex_update; - flex->dir = LV_FLEX_FLOW_ROW; - flex->main_place = LV_FLEX_PLACE_START; - flex->track_place = LV_FLEX_PLACE_START; - flex->cross_place = LV_FLEX_PLACE_START; + LV_LAYOUT_FLEX = lv_layout_register(flex_update); + + LV_STYLE_FLEX_FLOW = lv_style_register_prop(); + LV_STYLE_FLEX_MAIN_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_FLEX_CROSS_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_FLEX_TRACK_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; } -void lv_flex_set_flow(lv_flex_t * flex, lv_flex_flow_t flow) +void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow) { - flex->dir = flow & 0x3; - flex->wrap = flow & _LV_FLEX_WRAP ? 1 : 0; - flex->rev = flow & _LV_FLEX_REVERSE ? 1 : 0; + lv_obj_set_style_flex_flow(obj, LV_PART_MAIN, LV_STATE_DEFAULT, flow); + lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_LAYOUT_FLEX); } -void lv_flex_set_place(lv_flex_t * flex, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_place) +void lv_obj_set_flex_place(lv_obj_t * obj, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_place) { - flex->main_place = main_place; - flex->cross_place = cross_place; - flex->track_place = track_place; + lv_obj_set_style_flex_main_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, main_place); + lv_obj_set_style_flex_cross_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, cross_place); + lv_obj_set_style_flex_track_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, track_place); + lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_LAYOUT_FLEX); } void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow) { - 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 != flex_update) return; - const lv_flex_t * f = (const lv_flex_t *)parent->spec_attr->layout_dsc; - - if(f->dir == LV_FLEX_FLOW_ROW) lv_obj_set_width(obj, (LV_COORD_SET_LAYOUT(grow))); - else lv_obj_set_height(obj, (LV_COORD_SET_LAYOUT(grow))); - - lv_obj_mark_layout_as_dirty(parent); + lv_obj_set_style_flex_grow(obj, LV_PART_MAIN, LV_STATE_DEFAULT, grow); } /********************** @@ -154,29 +109,37 @@ void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow) static void flex_update(lv_obj_t * cont) { - if(cont->spec_attr == NULL) return; - const lv_flex_t * f = (const lv_flex_t *)cont->spec_attr->layout_dsc; - LV_LOG_INFO("update %p container", cont); + flex_t f; + lv_flex_flow_t flow = lv_obj_get_style_flex_flow(cont, LV_PART_MAIN); + f.row = flow & _LV_FLEX_COLUMN ? 0 : 1; + f.wrap = flow & _LV_FLEX_WRAP ? 1 : 0; + f.rev = flow & _LV_FLEX_REVERSE ? 1 : 0; + f.main_place = lv_obj_get_style_flex_main_place(cont, LV_PART_MAIN); + f.cross_place = lv_obj_get_style_flex_cross_place(cont, LV_PART_MAIN); + f.track_place = lv_obj_get_style_flex_track_place(cont, LV_PART_MAIN); + bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; - 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); - lv_coord_t max_main_size = (row ? lv_obj_get_width_fit(cont) : lv_obj_get_height_fit(cont)); + lv_coord_t track_gap = !f.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 = f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); + lv_coord_t max_main_size = (f.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); - lv_flex_place_t track_cross_place = f->track_place; - lv_coord_t * cross_pos = (row ? &abs_y : &abs_x); + lv_flex_place_t track_cross_place = f.track_place; + lv_coord_t * cross_pos = (f.row ? &abs_y : &abs_x); - if((row && cont->h_set == LV_SIZE_CONTENT) || - (!row && cont->w_set == LV_SIZE_CONTENT)) + lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN); + lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN); + + if((f.row && h_set == LV_SIZE_CONTENT) || + (!f.row && w_set == LV_SIZE_CONTENT)) { track_cross_place = LV_FLEX_PLACE_START; } - if(rtl && !row) { + if(rtl && !f.row) { if(track_cross_place == LV_FLEX_PLACE_START) track_cross_place = LV_FLEX_PLACE_END; else if(track_cross_place == LV_FLEX_PLACE_END) track_cross_place = LV_FLEX_PLACE_START; } @@ -188,11 +151,11 @@ static void flex_update(lv_obj_t * cont) int32_t next_track_first_item; if(track_cross_place != LV_FLEX_PLACE_START) { - track_first_item = f->rev ? cont->spec_attr->child_cnt - 1 : 0; + track_first_item = f.rev ? cont->spec_attr->child_cnt - 1 : 0; track_t t; while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) { /*Search the first item of the next row*/ - next_track_first_item = find_track_end(cont, track_first_item, max_main_size, item_gap, &t); + next_track_first_item = find_track_end(cont, &f, track_first_item, max_main_size, item_gap, &t); total_track_cross_size += t.track_cross_size + track_gap; track_cnt++; track_first_item = next_track_first_item; @@ -201,28 +164,28 @@ static void flex_update(lv_obj_t * cont) if(track_cnt) total_track_cross_size -= track_gap; /*No gap after the last track*/ /*Place the tracks to get the start position*/ - lv_coord_t max_cross_size = (row ? lv_obj_get_height_fit(cont) : lv_obj_get_width_fit(cont)); + lv_coord_t max_cross_size = (f.row ? lv_obj_get_height_fit(cont) : lv_obj_get_width_fit(cont)); place_content(track_cross_place, max_cross_size, total_track_cross_size, track_cnt, cross_pos, &gap); } - track_first_item = f->rev ? cont->spec_attr->child_cnt - 1 : 0; + track_first_item = f.rev ? cont->spec_attr->child_cnt - 1 : 0; - if(rtl && !row) { + if(rtl && !f.row) { *cross_pos += total_track_cross_size; } while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) { track_t t; /*Search the first item of the next row*/ - next_track_first_item = find_track_end(cont, track_first_item, max_main_size, item_gap, &t); + next_track_first_item = find_track_end(cont, &f, track_first_item, max_main_size, item_gap, &t); - if(rtl && !row) { + if(rtl && !f.row) { *cross_pos -= t.track_cross_size; } - children_repos(cont, track_first_item, next_track_first_item, abs_x, abs_y, max_main_size, item_gap, &t); + children_repos(cont, &f, track_first_item, next_track_first_item, abs_x, abs_y, max_main_size, item_gap, &t); track_first_item = next_track_first_item; - if(rtl && !row) { + if(rtl && !f.row) { *cross_pos -= gap + track_gap; } else { *cross_pos += t.track_cross_size + gap + track_gap; @@ -230,8 +193,8 @@ static void flex_update(lv_obj_t * cont) } LV_ASSERT_MEM_INTEGRITY(); - if(cont->w_set == LV_SIZE_CONTENT || cont->h_set == LV_SIZE_CONTENT) { - lv_obj_set_size(cont, cont->w_set, cont->h_set); + if(w_set == LV_SIZE_CONTENT || h_set == LV_SIZE_CONTENT) { + lv_obj_refr_size(cont); } LV_TRACE_LAYOUT("finished"); @@ -240,18 +203,17 @@ static void flex_update(lv_obj_t * cont) /** * Find the last item of a track */ -static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) +static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) { - const lv_flex_t * f = (const lv_flex_t *)cont->spec_attr->layout_dsc; + lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN); + lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN); - bool row = f->dir == LV_FLEX_FLOW_ROW ? true : false; - bool wrap = f->wrap; /*Can't wrap if the size if auto (i.e. the size depends on the children)*/ - if(wrap && ((row && cont->w_set == LV_SIZE_CONTENT) || (!row && cont->h_set == LV_SIZE_CONTENT))) { - wrap = false; + if(f->wrap && ((f->row && w_set == LV_SIZE_CONTENT) || (!f->row && h_set == LV_SIZE_CONTENT))) { + f->wrap = false; } - lv_coord_t(*get_main_size)(const lv_obj_t *) = (row ? lv_obj_get_width : lv_obj_get_height); - lv_coord_t(*get_cross_size)(const lv_obj_t *) = (!row ? lv_obj_get_width : lv_obj_get_height); + lv_coord_t(*get_main_size)(const lv_obj_t *) = (f->row ? lv_obj_get_width : lv_obj_get_height); + lv_coord_t(*get_cross_size)(const lv_obj_t *) = (!f->row ? lv_obj_get_width : lv_obj_get_height); lv_coord_t grow_sum = 0; t->track_main_size = 0; @@ -267,14 +229,14 @@ static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t if(item_id != item_start_id && lv_obj_has_flag(item, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK)) break; if(!lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) { - lv_coord_t main_size = (row ? item->w_set : item->h_set); - if(_LV_FLEX_GET_GROW(main_size)) { - grow_sum += _LV_FLEX_GET_GROW(main_size); + uint8_t grow_size = lv_obj_get_style_flex_grow(item, LV_PART_MAIN); + if(grow_size) { + grow_sum += grow_size; grow_item_cnt++; t->track_main_size += item_gap; } else { lv_coord_t item_size = get_main_size(item); - if(wrap && t->track_main_size + item_size > max_main_size) break; + if(f->wrap && t->track_main_size + item_size > max_main_size) break; t->track_main_size += item_size + item_gap; } @@ -315,14 +277,11 @@ static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t /** * Position the children in the same track */ -static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) +static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) { - const lv_flex_t * f = (const lv_flex_t *)cont->spec_attr->layout_dsc; - bool row = f->dir == LV_FLEX_FLOW_ROW ? true : false; - - void (*area_set_main_size)(lv_area_t *, lv_coord_t) = (row ? lv_area_set_width : lv_area_set_height); - lv_coord_t (*area_get_main_size)(const lv_area_t *) = (row ? lv_area_get_width : lv_area_get_height); - lv_coord_t (*area_get_cross_size)(const lv_area_t *) = (!row ? lv_area_get_width : lv_area_get_height); + void (*area_set_main_size)(lv_area_t *, lv_coord_t) = (f->row ? lv_area_set_width : lv_area_set_height); + lv_coord_t (*area_get_main_size)(const lv_area_t *) = (f->row ? lv_area_get_width : lv_area_get_height); + lv_coord_t (*area_get_cross_size)(const lv_area_t *) = (!f->row ? lv_area_get_width : lv_area_get_height); bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; @@ -330,7 +289,7 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_ lv_coord_t place_gap = 0; place_content(f->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; + if(f->row && rtl) main_pos += t->track_main_size; lv_obj_t * item = lv_obj_get_child(cont, item_first_id); /*Reposition the children*/ @@ -339,19 +298,26 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_ item = get_next_item(cont, f->rev, &item_first_id); continue; } - lv_coord_t main_size = (row ? item->w_set : item->h_set); - if(_LV_FLEX_GET_GROW(main_size)) { + uint8_t grow_size = lv_obj_get_style_flex_grow(item, LV_PART_MAIN); + if(grow_size) { lv_area_t old_coords; lv_area_copy(&old_coords, &item->coords); - lv_coord_t s = _LV_FLEX_GET_GROW(main_size) * t->grow_unit; + lv_coord_t s = grow_size * t->grow_unit; area_set_main_size(&item->coords, s); - if(lv_area_get_height(&old_coords) != area_get_main_size(&item->coords)) { + if(f->row) item->w_layout = 1; + else item->h_layout = 1; + + if(area_get_main_size(&old_coords) != area_get_main_size(&item->coords)) { lv_obj_invalidate(item); - lv_event_send(item, LV_EVENT_COORD_CHANGED, &old_coords); + lv_event_send(item, LV_EVENT_SIZE_CHANGED, &old_coords); + lv_event_send(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item); lv_obj_invalidate(item); } + } else { + item->w_layout = 0; + item->h_layout = 0; } lv_coord_t cross_pos = 0; @@ -368,13 +334,13 @@ 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); + if(f->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; - diff_y += row ? cross_pos : main_pos; + diff_x += f->row ? main_pos : cross_pos; + diff_y += f->row ? cross_pos : main_pos; if(diff_x || diff_y) { lv_obj_invalidate(item); @@ -386,7 +352,7 @@ 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, true); } - if(!(row && rtl)) main_pos += area_get_main_size(&item->coords) + item_gap + place_gap; + if(!(f->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/flex/lv_flex.h b/src/extra/layouts/flex/lv_flex.h index bfa25f90d..73db84f2d 100644 --- a/src/extra/layouts/flex/lv_flex.h +++ b/src/extra/layouts/flex/lv_flex.h @@ -19,14 +19,14 @@ extern "C" { /********************* * DEFINES *********************/ -#define _LV_FLEX_GET_GROW(v) (LV_COORD_IS_LAYOUT(v) ? _LV_COORD_PLAIN(v) : 0) - -#define _LV_FLEX_WRAP (1 << 2) -#define _LV_FLEX_REVERSE (1 << 3) #define LV_OBJ_FLAG_FLEX_IN_NEW_TRACK LV_OBJ_FLAG_LAYOUT_1 LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); +#define _LV_FLEX_COLUMN (1 << 0) +#define _LV_FLEX_WRAP (1 << 2) +#define _LV_FLEX_REVERSE (1 << 3) + /********************** * TYPEDEFS **********************/ @@ -35,7 +35,6 @@ LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); struct _lv_obj_t; typedef enum { - LV_FLEX_PLACE_NONE, LV_FLEX_PLACE_START, LV_FLEX_PLACE_END, LV_FLEX_PLACE_CENTER, @@ -45,8 +44,8 @@ typedef enum { }lv_flex_place_t; typedef enum { - LV_FLEX_FLOW_ROW = 0x01, - LV_FLEX_FLOW_COLUMN = 0x02, + LV_FLEX_FLOW_ROW = 0x00, + LV_FLEX_FLOW_COLUMN = _LV_FLEX_COLUMN, LV_FLEX_FLOW_ROW_WRAP = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP, LV_FLEX_FLOW_ROW_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_REVERSE, LV_FLEX_FLOW_ROW_WRAP_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, @@ -55,15 +54,15 @@ typedef enum { LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, }lv_flex_flow_t; -typedef struct { - lv_layout_dsc_t base; - uint32_t dir :2; - uint32_t wrap :1; - uint32_t rev :1; - uint32_t main_place :3; - uint32_t track_place :3; - uint32_t cross_place :3; -}lv_flex_t; +/********************** + * GLOBAL VARIABLES + **********************/ +extern uint32_t LV_LAYOUT_FLEX; +extern lv_style_prop_t LV_STYLE_FLEX_FLOW; +extern lv_style_prop_t LV_STYLE_FLEX_MAIN_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_GROW; /********************** * GLOBAL PROTOTYPES @@ -73,14 +72,14 @@ typedef struct { * Initialize a felx layout the default values * @param flex pointer to a flex layout descriptor */ -void lv_flex_init(lv_flex_t * flex); +void lv_flex_init(void); /** * Set hot the item should flow * @param flex pointer to a flex layout descriptor * @param flow an element of `lv_flex_flow_t`. */ -void lv_flex_set_flow(lv_flex_t * flex, lv_flex_flow_t flow); +void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow); /** * Set how to place (where to align) the items an tracks @@ -89,28 +88,129 @@ void lv_flex_set_flow(lv_flex_t * flex, lv_flex_flow_t flow); * @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_PLACE_START/END/CENTER` * @param track_place where to place the tracks in the cross direction. Any value of `lv_flex_place_t`. */ -void lv_flex_set_place(lv_flex_t * flex, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_cross_place); +void lv_obj_set_flex_place(lv_obj_t * obj, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_cross_place); /** * Sets the width or height (on main axis) to grow the object in order fill the free space * @param obj pointer to an object. The parent must have flex layout else nothing will happen. * @param grow a value to set how much free space to take proportionally to other growing items. */ -void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow); +void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow); -/********************** - * GLOBAL VARIABLES - **********************/ -/** - * Predefines flex layouts - */ -extern const lv_flex_t lv_flex_row_wrap; /**< Just put the items next to each other with wrap*/ -extern const lv_flex_t lv_flex_row_center; /**< Center in a row with wrap*/ -extern const lv_flex_t lv_flex_column_center; /**< Center in a column with wrap*/ -extern const lv_flex_t lv_flex_column_nowrap; /**< Stack the items vertically without wrapping*/ -extern const lv_flex_t lv_flex_row_nowrap; /**< Put the items next to each other without wrap*/ -extern const lv_flex_t lv_flex_row_even; /**< Place the items evenly in row with wrapping and vertical centering*/ + +static inline void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_FLEX_FLOW, v); +} + +static inline void lv_style_set_flex_main_place(lv_style_t * style, lv_flex_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_FLEX_MAIN_PLACE, v); +} + +static inline void lv_style_set_flex_cross_place(lv_style_t * style, lv_flex_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_FLEX_CROSS_PLACE, v); +} + +static inline void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_FLEX_TRACK_PLACE, v); +} + +static inline void lv_style_set_flex_grow(lv_style_t * style, uint8_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_FLEX_GROW, v); +} + + + +static inline void lv_obj_set_style_flex_flow(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_flow_t value) +{ + lv_style_value_t v = { + .num = (int32_t) value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_FLOW, v); +} + +static inline void lv_obj_set_style_flex_main_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t) value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_MAIN_PLACE, v); +} + +static inline void lv_obj_set_style_flex_cross_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t) value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_CROSS_PLACE, v); +} + +static inline void lv_obj_set_style_flex_track_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t) value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_TRACK_PLACE, v); +} + +static inline void lv_obj_set_style_flex_grow(lv_obj_t * obj, lv_part_t part, lv_state_t state, uint8_t value) +{ + lv_style_value_t v = { + .num = (int32_t) value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_GROW, v); +} + +static inline lv_flex_flow_t lv_obj_get_style_flex_flow(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_FLOW); + return (lv_flex_flow_t)v.num; +} + +static inline lv_flex_place_t lv_obj_get_style_flex_main_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_MAIN_PLACE); + return (lv_flex_place_t)v.num; +} + +static inline lv_flex_place_t lv_obj_get_style_flex_cross_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_CROSS_PLACE); + return (lv_flex_place_t)v.num; +} + +static inline lv_flex_place_t lv_obj_get_style_flex_track_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_TRACK_PLACE); + return (lv_flex_place_t)v.num; +} + +static inline uint8_t lv_obj_get_style_flex_grow(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_GROW); + return (uint8_t)v.num; +} + /********************** * MACROS diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index 6fa47dafb..05ccac47c 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -16,15 +16,9 @@ /** * Some helper defines */ -#define CELL_SHIFT 4 -#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 IS_FR(x) (LV_COORD_IS_LAYOUT(x) && _LV_COORD_PLAIN(x) < 100) -#define IS_CONTENT(x) (LV_COORD_IS_LAYOUT(x) && _LV_COORD_PLAIN(x) == 100) -#define GET_FR(x) (_LV_COORD_PLAIN(x)) - +#define IS_FR(x) (x >= LV_COORD_MAX - 100) +#define IS_CONTENT(x) (x == LV_COORD_MAX - 101) +#define GET_FR(x) (x - (LV_COORD_MAX - 100)) /********************** * TYPEDEFS @@ -35,29 +29,59 @@ typedef struct { lv_point_t grid_abs; }item_repos_hint_t; +typedef struct { + lv_coord_t * x; + lv_coord_t * y; + lv_coord_t * w; + lv_coord_t * h; + uint32_t col_num; + uint32_t row_num; + lv_coord_t grid_w; + lv_coord_t grid_h; +}_lv_grid_calc_t; + + /********************** * GLOBAL PROTOTYPES **********************/ -void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify_parent); /********************** * STATIC PROTOTYPES **********************/ static void grid_update(lv_obj_t * cont); -static void full_refresh(lv_obj_t * cont); static void calc(struct _lv_obj_t * obj, _lv_grid_calc_t * calc); static void calc_free(_lv_grid_calc_t * calc); static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c); 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); static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t place, lv_coord_t gap, uint32_t track_num, lv_coord_t * size_array, lv_coord_t * pos_array, bool reverse); +static uint32_t count_tracks(const lv_coord_t * templ); + +static inline const lv_coord_t * get_col_templ(lv_obj_t * obj) {return lv_obj_get_style_grid_column_template(obj, LV_PART_MAIN); } +static inline const lv_coord_t * get_row_templ(lv_obj_t * obj) {return lv_obj_get_style_grid_row_template(obj, LV_PART_MAIN); } +static inline uint8_t get_col_pos(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_column_pos(obj, LV_PART_MAIN); } +static inline uint8_t get_row_pos(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_row_pos(obj, LV_PART_MAIN); } +static inline uint8_t get_col_span(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_column_span(obj, LV_PART_MAIN); } +static inline uint8_t get_row_span(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_row_span(obj, LV_PART_MAIN); } +static inline uint8_t get_cell_col_place(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_x_place(obj, LV_PART_MAIN); } +static inline uint8_t get_cell_row_place(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_y_place(obj, LV_PART_MAIN); } +static inline uint8_t get_grid_col_place(lv_obj_t * obj) {return lv_obj_get_style_grid_column_place(obj, LV_PART_MAIN); } +static inline uint8_t get_grid_row_place(lv_obj_t * obj) {return lv_obj_get_style_grid_row_place(obj, LV_PART_MAIN); } /********************** * GLOBAL VARIABLES **********************/ -static const lv_coord_t grid_12_template[12] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), - LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1)}; -const lv_grid_t grid_12 = {.base.update_cb = grid_update, .col_dsc = grid_12_template, .col_dsc_len = 12, .row_dsc = grid_12_template, .row_dsc_len = 12}; +uint32_t LV_LAYOUT_GRID; +lv_style_prop_t LV_STYLE_GRID_COL_TEMPLATE; +lv_style_prop_t LV_STYLE_GRID_COL_PLACE; +lv_style_prop_t LV_STYLE_GRID_ROW_TEMPLATE; +lv_style_prop_t LV_STYLE_GRID_ROW_PLACE; +lv_style_prop_t LV_STYLE_GRID_CELL_COL_POS; +lv_style_prop_t LV_STYLE_GRID_CELL_COL_SPAN; +lv_style_prop_t LV_STYLE_GRID_CELL_COL_PLACE; +lv_style_prop_t LV_STYLE_GRID_CELL_ROW_POS; +lv_style_prop_t LV_STYLE_GRID_CELL_ROW_SPAN; +lv_style_prop_t LV_STYLE_GRID_CELL_ROW_PLACE; /********************** * STATIC VARIABLES @@ -66,50 +90,55 @@ const lv_grid_t grid_12 = {.base.update_cb = grid_update, .col_dsc = grid_12_tem /********************** * MACROS **********************/ -#define GET_CELL_POS(c) ((c) & CELL_POS_MASK) -#define GET_CELL_SPAN(c) (((c) & CELL_SPAN_MASK) >> CELL_SHIFT) -#define GET_CELL_PLACE(c) ((c) >> (CELL_SHIFT * 2) & 0x7) /********************** * GLOBAL FUNCTIONS **********************/ -void lv_grid_init(lv_grid_t * grid) + +void lv_grid_init(void) { - lv_memset_00(grid,sizeof(lv_grid_t)); - grid->base.update_cb = grid_update; - grid->col_place = LV_GRID_START; - grid->row_place = LV_GRID_START; + LV_LAYOUT_GRID = lv_layout_register(grid_update); + + LV_STYLE_GRID_COL_TEMPLATE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_ROW_TEMPLATE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_COL_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_ROW_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + + LV_STYLE_GRID_CELL_ROW_SPAN = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_CELL_ROW_POS = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_CELL_COL_SPAN = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_CELL_COL_POS = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_CELL_COL_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; + LV_STYLE_GRID_CELL_ROW_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR; } -void lv_grid_set_template(lv_grid_t * grid, const lv_coord_t * col_dsc, uint8_t col_cnt, const lv_coord_t * row_dsc, uint8_t row_cnt) +void lv_obj_set_grid_template(lv_obj_t * obj, const lv_coord_t * col_templ, const lv_coord_t * row_templ) { - grid->col_dsc = col_dsc; - grid->col_dsc_len = col_cnt; - grid->row_dsc = row_dsc; - grid->row_dsc_len = row_cnt; + lv_obj_set_style_grid_column_template(obj, LV_PART_MAIN, LV_STATE_DEFAULT, col_templ); + lv_obj_set_style_grid_row_template(obj, LV_PART_MAIN, LV_STATE_DEFAULT, row_templ); + lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_LAYOUT_GRID); } - -void lv_grid_set_place(lv_grid_t * grid, uint8_t col_place, uint8_t row_place) +void lv_obj_set_grid_place(lv_obj_t * obj, lv_grid_place_t hor_place, lv_grid_place_t ver_place) { - grid->col_place = col_place; - grid->row_place = row_place; + lv_obj_set_style_grid_column_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, hor_place); + lv_obj_set_style_grid_row_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, ver_place); + } void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col_pos, uint8_t col_span, lv_grid_place_t ver_place, uint8_t row_pos, uint8_t row_span) { - 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; - - 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_mark_layout_as_dirty(parent); + lv_obj_set_style_grid_cell_column_pos(obj, LV_PART_MAIN, LV_STATE_DEFAULT, col_pos); + lv_obj_set_style_grid_cell_row_pos(obj, LV_PART_MAIN, LV_STATE_DEFAULT, row_pos); + lv_obj_set_style_grid_cell_x_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, hor_place); + lv_obj_set_style_grid_cell_column_span(obj, LV_PART_MAIN, LV_STATE_DEFAULT, col_span); + lv_obj_set_style_grid_cell_row_span(obj, LV_PART_MAIN, LV_STATE_DEFAULT, row_span); + lv_obj_set_style_grid_cell_y_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, ver_place); + lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj)); } @@ -119,29 +148,15 @@ void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col static void grid_update(lv_obj_t * cont) { - if(cont->spec_attr == NULL) return; - if(cont->spec_attr->layout_dsc == NULL) return; - LV_LOG_INFO("update %p container", cont); - full_refresh(cont); + const lv_coord_t * col_templ = get_col_templ(cont); + const lv_coord_t * row_templ = get_row_templ(cont); + if(col_templ == NULL || row_templ == NULL) return; - LV_TRACE_LAYOUT("finished"); -} - -/** - * Refresh the all grid item on a container - * @param cont pointer to a grid container object - */ -static void full_refresh(lv_obj_t * cont) -{ - const lv_grid_t * g = (const lv_grid_t *)cont->spec_attr->layout_dsc; - /*Calculate the grid*/ - if(g == NULL) return; _lv_grid_calc_t c; calc(cont, &c); - item_repos_hint_t hint; lv_memset_00(&hint, sizeof(hint)); @@ -155,15 +170,17 @@ static void full_refresh(lv_obj_t * cont) uint32_t i; for(i = 0; i < cont->spec_attr->child_cnt; i++) { lv_obj_t * item = cont->spec_attr->children[i]; - if(LV_COORD_IS_LAYOUT(item->x_set) && LV_COORD_IS_LAYOUT(item->y_set)) { - item_repos(item, &c, &hint); - } + item_repos(item, &c, &hint); } calc_free(&c); - if(cont->w_set == LV_SIZE_CONTENT || cont->h_set == LV_SIZE_CONTENT) { - lv_obj_set_size(cont, cont->w_set, cont->h_set); + lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN); + lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN); + if(w_set == LV_SIZE_CONTENT || h_set == LV_SIZE_CONTENT) { + lv_obj_refr_size(cont); } + + LV_TRACE_LAYOUT("finished"); } /** @@ -174,10 +191,6 @@ static void full_refresh(lv_obj_t * cont) */ static void calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out) { - const lv_grid_t * g = (const lv_grid_t *)cont->spec_attr->layout_dsc; - if(g->col_dsc == NULL || g->row_dsc == NULL) return; - if(g->col_dsc_len == 0 || g->row_dsc_len == 0) return; - if(lv_obj_get_child(cont, 0) == NULL) { lv_memset_00(calc_out, sizeof(_lv_grid_calc_t)); return; @@ -190,13 +203,16 @@ static void calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out) lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN); bool rev = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; - bool auto_w = cont->w_set == LV_SIZE_CONTENT ? true : false; - lv_coord_t cont_w = lv_obj_get_width_fit(cont); - calc_out->grid_w = grid_place(cont_w, auto_w, g->col_place, col_gap, calc_out->col_num, calc_out->w, calc_out->x, rev); - bool auto_h = cont->h_set == LV_SIZE_CONTENT ? true : false; + lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN); + lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN); + bool auto_w = w_set == LV_SIZE_CONTENT ? true : false; + lv_coord_t cont_w = lv_obj_get_width_fit(cont); + calc_out->grid_w = grid_place(cont_w, auto_w, get_grid_col_place(cont), col_gap, calc_out->col_num, calc_out->w, calc_out->x, rev); + + bool auto_h = h_set == LV_SIZE_CONTENT ? true : false; lv_coord_t cont_h = lv_obj_get_height_fit(cont); - calc_out->grid_h = grid_place(cont_h, auto_h, g->row_place, row_gap, calc_out->row_num, calc_out->h, calc_out->y, false); + calc_out->grid_h = grid_place(cont_h, auto_h, get_grid_row_place(cont), row_gap, calc_out->row_num, calc_out->h, calc_out->y, false); LV_ASSERT_MEM_INTEGRITY(); } @@ -215,30 +231,29 @@ static void calc_free(_lv_grid_calc_t * calc) static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) { - const lv_grid_t * grid = (const lv_grid_t *)cont->spec_attr->layout_dsc; - uint32_t i; - + const lv_coord_t * col_templ = get_col_templ(cont); lv_coord_t cont_w = lv_obj_get_width_fit(cont); - c->col_num = grid->col_dsc_len; + c->col_num = count_tracks(col_templ); c->x = lv_mem_buf_get(sizeof(lv_coord_t) * c->col_num); c->w = lv_mem_buf_get(sizeof(lv_coord_t) * c->col_num); /*Set sizes for CONTENT cells*/ + uint32_t i; for(i = 0; i < c->col_num; i++) { lv_coord_t size = LV_COORD_MIN; - if(IS_CONTENT(grid->col_dsc[i])) { + if(IS_CONTENT(col_templ[i])) { /*Check the size of children of this cell*/ uint32_t ci; for(ci = 0; ci < lv_obj_get_child_cnt(cont); ci++) { lv_obj_t * item = lv_obj_get_child(cont, ci); - if(LV_COORD_IS_LAYOUT(item->x_set) == false || LV_COORD_IS_LAYOUT(item->y_set) == false) continue; if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue; - uint32_t col_pos = GET_CELL_POS(item->x_set); - if(col_pos != i) continue; - uint32_t col_span = GET_CELL_SPAN(item->x_set); + uint32_t col_span = get_col_span(item); if(col_span != 1) continue; + uint32_t col_pos = get_col_pos(item); + if(col_pos != i) continue; + size = LV_MAX(size, lv_obj_get_width(item)); } if(size >= 0) c->w[i] = size; @@ -250,7 +265,7 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) lv_coord_t grid_w = 0; for(i = 0; i < c->col_num; i++) { - lv_coord_t x = grid->col_dsc[i]; + lv_coord_t x = col_templ[i]; if(IS_FR(x)) { col_fr_cnt += GET_FR(x); } @@ -268,7 +283,7 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) lv_coord_t free_w = cont_w - grid_w; for(i = 0; i < c->col_num; i++) { - lv_coord_t x = grid->col_dsc[i]; + lv_coord_t x = col_templ[i]; if(IS_FR(x)) { lv_coord_t f = GET_FR(x); c->w[i] = (free_w * f) / col_fr_cnt; @@ -278,27 +293,26 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) { - const lv_grid_t * grid = (const lv_grid_t *)cont->spec_attr->layout_dsc; uint32_t i; - - c->row_num = grid->row_dsc_len; + const lv_coord_t * row_templ = get_row_templ(cont); + c->row_num = count_tracks(row_templ); c->y = lv_mem_buf_get(sizeof(lv_coord_t) * c->row_num); c->h = lv_mem_buf_get(sizeof(lv_coord_t) * c->row_num); /*Set sizes for CONTENT cells*/ for(i = 0; i < c->row_num; i++) { lv_coord_t size = LV_COORD_MIN; - if(IS_CONTENT(grid->row_dsc[i])) { + if(IS_CONTENT(row_templ[i])) { /*Check the size of children of this cell*/ uint32_t ci; for(ci = 0; ci < lv_obj_get_child_cnt(cont); ci++) { lv_obj_t * item = lv_obj_get_child(cont, ci); - if(LV_COORD_IS_LAYOUT(item->x_set) == false || LV_COORD_IS_LAYOUT(item->y_set) == false) continue; if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue; - uint32_t row_pos = GET_CELL_POS(item->y_set); - if(row_pos != i) continue; - uint32_t row_span = GET_CELL_SPAN(item->y_set); + uint32_t row_span = get_row_span(item); if(row_span != 1) continue; + uint32_t row_pos = get_row_pos(item); + if(row_pos != i) continue; + size = LV_MAX(size, lv_obj_get_height(item)); } if(size >= 0) c->h[i] = size; @@ -310,7 +324,7 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) lv_coord_t grid_h = 0; for(i = 0; i < c->row_num; i++) { - lv_coord_t x = grid->row_dsc[i]; + lv_coord_t x = row_templ[i]; if(IS_FR(x)) { row_fr_cnt += GET_FR(x); } else if (IS_CONTENT(x)) { @@ -322,11 +336,11 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) } lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN); - lv_coord_t cont_h = lv_obj_get_height_fit(cont) - row_gap * (grid->row_dsc_len - 1); + lv_coord_t cont_h = lv_obj_get_height_fit(cont) - row_gap * (c->row_num - 1); lv_coord_t free_h = cont_h - grid_h; - for(i = 0; i < grid->row_dsc_len; i++) { - lv_coord_t x = grid->row_dsc[i]; + for(i = 0; i < c->row_num; i++) { + lv_coord_t x = row_templ[i]; if(IS_FR(x)) { lv_coord_t f = GET_FR(x); c->h[i] = (free_h * f) / row_fr_cnt; @@ -343,14 +357,16 @@ 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) == 0 || LV_COORD_IS_LAYOUT(item->y_set) == 0) return; if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) return; - uint32_t col_span = GET_CELL_SPAN(item->x_set); - uint32_t row_span = GET_CELL_SPAN(item->y_set); + uint32_t col_span = get_col_span(item); + uint32_t row_span = get_row_span(item); if(row_span == 0 || col_span == 0) return; - uint32_t col_pos = GET_CELL_POS(item->x_set); - uint32_t row_pos = GET_CELL_POS(item->y_set); + uint32_t col_pos = get_col_pos(item); + uint32_t row_pos = get_row_pos(item); + lv_grid_place_t col_place = get_cell_col_place(item); + lv_grid_place_t row_place = get_cell_row_place(item); + 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]; @@ -360,13 +376,11 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * lv_coord_t row_y2 = c->y[row_pos + row_span - 1] + c->h[row_pos + row_span - 1]; lv_coord_t row_h = row_y2 - row_y1; - uint8_t x_flag = GET_CELL_PLACE(item->x_set); - uint8_t y_flag = GET_CELL_PLACE(item->y_set); /*If the item has RTL base dir switch start and end*/ if(lv_obj_get_base_dir(item) == LV_BIDI_DIR_RTL) { - if(x_flag == LV_GRID_START) x_flag = LV_GRID_END; - else if(x_flag == LV_GRID_END) x_flag = LV_GRID_START; + if(col_place == LV_GRID_START) col_place = LV_GRID_END; + else if(col_place == LV_GRID_END) col_place = LV_GRID_START; } lv_coord_t x; @@ -374,42 +388,45 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * lv_coord_t item_w = lv_area_get_width(&item->coords); lv_coord_t item_h = lv_area_get_height(&item->coords); - if(item->w_set == LV_SIZE_LAYOUT) item->w_set = item_w; - if(item->h_set == LV_SIZE_LAYOUT) item->h_set = item_h; - - switch(x_flag) { + switch(col_place) { default: case LV_GRID_START: x = c->x[col_pos]; + item->w_layout = 0; break; case LV_GRID_STRETCH: x = c->x[col_pos]; item_w = col_w; - item->w_set = LV_SIZE_LAYOUT; + item->w_layout = 1; break; case LV_GRID_CENTER: x = c->x[col_pos] + (col_w - item_w) / 2; + item->w_layout = 0; break; case LV_GRID_END: x = c->x[col_pos] + col_w - lv_obj_get_width(item); + item->w_layout = 0; break; } - switch(y_flag) { + switch(row_place) { default: case LV_GRID_START: y = c->y[row_pos]; + item->h_layout = 0; break; case LV_GRID_STRETCH: y = c->y[row_pos]; item_h = row_h; - item->h_set = LV_SIZE_LAYOUT; + item->h_layout = 1; break; case LV_GRID_CENTER: y = c->y[row_pos] + (row_h - item_h) / 2; + item->h_layout = 0; break; case LV_GRID_END: y = c->y[row_pos] + row_h - lv_obj_get_height(item); + item->h_layout = 0; break; } @@ -421,15 +438,21 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * lv_area_set_width(&item->coords, item_w); lv_area_set_height(&item->coords, item_h); lv_obj_invalidate(item); - lv_event_send(item, LV_EVENT_COORD_CHANGED, &old_coords); + lv_event_send(item, LV_EVENT_SIZE_CHANGED, &old_coords); + lv_event_send(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item); } - bool moved = true; - if(hint) { - if(hint->grid_abs.x + x == item->coords.x1 && hint->grid_abs.y + y == item->coords.y1) moved = false; + lv_coord_t diff_x = hint->grid_abs.x + x - item->coords.x1; + lv_coord_t diff_y = hint->grid_abs.y + y - item->coords.y1; + if(diff_x || diff_y) { + lv_obj_invalidate(item); + item->coords.x1 += diff_x; + item->coords.x2 += diff_x; + item->coords.y1 += diff_y; + item->coords.y2 += diff_y; + lv_obj_invalidate(item); + lv_obj_move_children_by(item, diff_x, diff_y, true); } - - if(moved) lv_obj_move_to(item, x, y, false); } /** @@ -509,4 +532,13 @@ static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t plac return total_gird_size; } +static uint32_t count_tracks(const lv_coord_t * templ) +{ + uint32_t i; + for(i = 0; templ[i] != LV_COORD_MAX; i++); + + return i; +} + + #endif /*LV_USE_GRID*/ diff --git a/src/extra/layouts/grid/lv_grid.h b/src/extra/layouts/grid/lv_grid.h index 7f8a9e759..c5029ad32 100644 --- a/src/extra/layouts/grid/lv_grid.h +++ b/src/extra/layouts/grid/lv_grid.h @@ -14,11 +14,19 @@ extern "C" { * INCLUDES *********************/ #include "../../../core/lv_obj.h" +#if LV_USE_GRID /********************* * DEFINES *********************/ -#if LV_USE_GRID +/** + * Can be used track size to make the track fill the free space. + * @param x how much space to take proportionally to other FR tracks + * @return a special track size + */ +#define LV_GRID_FR(x) (LV_COORD_MAX - 100 + x) +#define LV_GRID_CONTENT (LV_COORD_MAX - 101) +#define LV_GRID_TEMPLATE_LAST (LV_COORD_MAX) /********************** * TYPEDEFS @@ -37,56 +45,29 @@ typedef enum { LV_GRID_SPACE_BETWEEN, }lv_grid_place_t; -typedef struct { - lv_layout_dsc_t base; /*The first element must be the update callback*/ - const lv_coord_t * col_dsc; - const lv_coord_t * row_dsc; - uint8_t col_dsc_len; - uint8_t row_dsc_len; - uint8_t col_place; - uint8_t row_place; -}lv_grid_t; +/********************** + * GLOBAL VARIABLES + **********************/ -typedef struct { - lv_coord_t * x; - lv_coord_t * y; - lv_coord_t * w; - lv_coord_t * h; - uint32_t col_num; - uint32_t row_num; - lv_coord_t grid_w; - lv_coord_t grid_h; -}_lv_grid_calc_t; +extern uint32_t LV_LAYOUT_GRID; +extern lv_style_prop_t LV_STYLE_GRID_COL_TEMPLATE; +extern lv_style_prop_t LV_STYLE_GRID_COL_PLACE; +extern lv_style_prop_t LV_STYLE_GRID_ROW_TEMPLATE; +extern lv_style_prop_t LV_STYLE_GRID_ROW_PLACE; +extern lv_style_prop_t LV_STYLE_GRID_CELL_COL_POS; +extern lv_style_prop_t LV_STYLE_GRID_CELL_COL_SPAN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_COL_PLACE; +extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_POS; +extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_SPAN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_PLACE; /********************** * GLOBAL PROTOTYPES **********************/ +void lv_obj_set_grid_template(lv_obj_t * obj, const lv_coord_t * col_templ, const lv_coord_t * row_templ); -/** - * Initialize a grid layout the default values - * @param grid pointer to a grid layout descriptor - */ -void lv_grid_init(lv_grid_t * grid); - -/** - * Set the number of rows and columns and their sizes - * @param grid pointer to a grid layout descriptor - * @param col_dsc an array with the column widths - * @param col_cnt number of columns (max 16) - * @param row_dsc an array with the row heights - * @param row_cnt number of rows (max 16) - * @note `LV_GRID_FR(x)` can be used as track size. - */ -void lv_grid_set_template(lv_grid_t * grid, const lv_coord_t * col_dsc, uint8_t col_cnt, const lv_coord_t * row_dsc, uint8_t row_cnt); - -/** - * Set how to place (where to align) the rows and columns - * @param grid - * @param col_place - * @param row_place - */ -void lv_grid_set_place(lv_grid_t * grid, uint8_t col_place, uint8_t row_place); +void lv_obj_set_grid_place(lv_obj_t * obj, lv_grid_place_t hor_place, lv_grid_place_t ver_place); /** * Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen @@ -101,15 +82,6 @@ void lv_grid_set_place(lv_grid_t * grid, uint8_t col_place, uint8_t row_place); void lv_obj_set_grid_cell(struct _lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col_pos, uint8_t col_span, lv_grid_place_t ver_place, uint8_t row_pos, uint8_t row_span); -/** - * Can be used track size to make the track fill the free space. - * @param x how much space to take proportionally to other FR tracks - * @return a special track size - */ -#define LV_GRID_FR(x) (LV_COORD_SET_LAYOUT(x)) - -#define LV_GRID_CONTENT (LV_COORD_SET_LAYOUT(100)) - /** * Just a wrapper to `LV_GRID_FR` for bindings. */ @@ -118,10 +90,236 @@ static inline lv_coord_t lv_grid_fr(uint8_t x) return LV_GRID_FR(x); } +static inline void lv_style_set_grid_row_template(lv_style_t * style, const lv_coord_t * value) +{ + lv_style_value_t v = { + .ptr = (const void *)value + }; + lv_style_set_prop(style, LV_STYLE_GRID_ROW_TEMPLATE, v); +} + +static inline void lv_style_set_grid_column_template(lv_style_t * style, const lv_coord_t * value) +{ + lv_style_value_t v = { + .ptr = (const void *)value + }; + lv_style_set_prop(style, LV_STYLE_GRID_COL_TEMPLATE, v); +} + +static inline void lv_style_set_grid_row_place(lv_style_t * style, lv_grid_place_t value) +{ + lv_style_value_t v = { + .num = (lv_grid_place_t)value + }; + lv_style_set_prop(style, LV_STYLE_GRID_ROW_PLACE, v); +} + +static inline void lv_style_set_grid_col_place(lv_style_t * style, lv_grid_place_t value) +{ + lv_style_value_t v = { + .num = (lv_grid_place_t)value + }; + lv_style_set_prop(style, LV_STYLE_GRID_COL_PLACE, v); +} + + +static inline void lv_style_set_grid_cell_column_pos(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_style_set_prop(style, LV_STYLE_GRID_CELL_COL_POS, v); +} + +static inline void lv_style_set_grid_cell_column_span(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_style_set_prop(style, LV_STYLE_GRID_CELL_COL_SPAN, v); +} + +static inline void lv_style_set_grid_cell_row_pos(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_POS, v); +} + +static inline void lv_style_set_grid_cell_row_span(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_SPAN, v); +} + +static inline void lv_style_set_grid_cell_x_place(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_style_set_prop(style, LV_STYLE_GRID_CELL_COL_PLACE, v); +} + +static inline void lv_style_set_grid_cell_y_place(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_PLACE, v); +} + +static inline void lv_obj_set_style_grid_row_template(lv_obj_t * obj, lv_part_t part, lv_state_t state, const lv_coord_t * value) +{ + lv_style_value_t v = { + .ptr = (const void *)value + }; + lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_ROW_TEMPLATE, v); +} + +static inline void lv_obj_set_style_grid_column_template(lv_obj_t * obj, lv_part_t part, lv_state_t state, const lv_coord_t * value) +{ + lv_style_value_t v = { + .ptr = (const void *)value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_COL_TEMPLATE, v); +} + + +static inline void lv_obj_set_style_grid_row_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_grid_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t) value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_ROW_PLACE, v); +} + +static inline void lv_obj_set_style_grid_column_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_grid_place_t value) +{ + lv_style_value_t v = { + .num = (int32_t) value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_COL_PLACE, v); +} + + +static inline void lv_obj_set_style_grid_cell_column_pos(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_CELL_COL_POS, v); +} + +static inline void lv_obj_set_style_grid_cell_column_span(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_CELL_COL_SPAN, v); +} + +static inline void lv_obj_set_style_grid_cell_row_pos(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_CELL_ROW_POS, v); +} + +static inline void lv_obj_set_style_grid_cell_row_span(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_CELL_ROW_SPAN, v); +} + +static inline void lv_obj_set_style_grid_cell_x_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_CELL_COL_PLACE, v); +} + +static inline void lv_obj_set_style_grid_cell_y_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value) +{ + lv_style_value_t v = { + .num = value + }; + lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_CELL_ROW_PLACE, v); +} + + + + +static inline const lv_coord_t * lv_obj_get_style_grid_row_template(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_TEMPLATE); + return (const lv_coord_t *)v.ptr; +} + +static inline const lv_coord_t * lv_obj_get_style_grid_column_template(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COL_TEMPLATE); + return (const lv_coord_t *)v.ptr; +} + +static inline lv_grid_place_t lv_obj_get_style_grid_row_place(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_PLACE); + return (lv_grid_place_t)v.num; +} + +static inline lv_grid_place_t lv_obj_get_style_grid_column_place(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COL_PLACE); + return (lv_grid_place_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_column_pos(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COL_POS); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_column_span(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COL_SPAN); + return (lv_coord_t)v.num; +} + + +static inline lv_coord_t lv_obj_get_style_grid_cell_row_pos(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_POS); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_row_span(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_SPAN); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_x_place(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COL_PLACE); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_y_place(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_PLACE); + return (lv_coord_t)v.num; +} + /********************** * GLOBAL VARIABLES **********************/ -extern const lv_grid_t grid_12; /********************** * MACROS diff --git a/src/extra/themes/basic/lv_theme_basic.c b/src/extra/themes/basic/lv_theme_basic.c index f5ee1274c..3954e64f3 100644 --- a/src/extra/themes/basic/lv_theme_basic.c +++ b/src/extra/themes/basic/lv_theme_basic.c @@ -97,6 +97,9 @@ static void style_init(void) lv_style_set_line_color(&styles->light, COLOR_MID); lv_style_set_arc_width(&styles->light, LV_DPX(2)); lv_style_set_arc_color(&styles->light, COLOR_MID); + lv_style_set_width(&styles->light, 100); + lv_style_set_height(&styles->light, 60); + style_init_reset(&styles->dark); lv_style_set_bg_opa(&styles->dark, LV_OPA_COVER); @@ -109,6 +112,8 @@ static void style_init(void) lv_style_set_line_color(&styles->dark, COLOR_DIM); lv_style_set_arc_width(&styles->dark, LV_DPX(2)); lv_style_set_arc_color(&styles->dark, COLOR_DIM); + lv_style_set_width(&styles->dark, 100); + lv_style_set_height(&styles->dark, 60); static lv_color_filter_dsc_t dark_filter; lv_color_filter_dsc_init(&dark_filter, dark_color_filter_cb); diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 7eca2dc45..6035b0c72 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -179,7 +179,7 @@ static lv_color_t dark_color_filter_cb(const lv_color_filter_dsc_t * f, lv_color static lv_color_t grey_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t color, lv_opa_t opa) { LV_UNUSED(f); - return lv_color_mix(lv_color_white(), color, opa); + return lv_color_mix(lv_color_grey_lighten_2(), color, opa); } static void style_init(void) @@ -230,8 +230,8 @@ static void style_init(void) lv_style_set_bg_opa(&styles->scr, LV_OPA_COVER); lv_style_set_bg_color(&styles->scr, COLOR_SCR); lv_style_set_text_color(&styles->scr, COLOR_SCR_TEXT); - lv_style_set_pad_row(&styles->scr, PAD_SMALL * disp_size); - lv_style_set_pad_column(&styles->scr, PAD_SMALL * disp_size); + lv_style_set_pad_row(&styles->scr, PAD_SMALL); + lv_style_set_pad_column(&styles->scr, PAD_SMALL); style_init_reset(&styles->card); lv_style_set_radius(&styles->card, RADIUS_DEFAULT); @@ -269,6 +269,13 @@ static void style_init(void) lv_style_set_pad_ver(&styles->btn, PAD_SMALL); lv_style_set_pad_column(&styles->btn, LV_DPX(5)); lv_style_set_pad_row(&styles->btn, LV_DPX(5)); +#if LV_USE_FLEX + lv_style_set_layout(&styles->btn, LV_LAYOUT_FLEX); + lv_style_set_flex_flow(&styles->btn, LV_FLEX_FLOW_ROW); + lv_style_set_flex_main_place(&styles->btn, LV_FLEX_PLACE_CENTER); + lv_style_set_flex_cross_place(&styles->btn, LV_FLEX_PLACE_CENTER); + lv_style_set_flex_track_place(&styles->btn, LV_FLEX_PLACE_CENTER); +#endif static lv_color_filter_dsc_t dark_filter; @@ -283,7 +290,7 @@ static void style_init(void) style_init_reset(&styles->disabled); lv_style_set_color_filter_dsc(&styles->disabled, &grey_filter); - lv_style_set_color_filter_opa(&styles->disabled, LV_OPA_70); + lv_style_set_color_filter_opa(&styles->disabled, LV_OPA_50); style_init_reset(&styles->clip_corner); lv_style_set_clip_corner(&styles->clip_corner, true); @@ -501,6 +508,8 @@ static void style_init(void) lv_style_set_border_side(&styles->list_btn, LV_BORDER_SIDE_BOTTOM); lv_style_set_pad_all(&styles->list_btn, PAD_SMALL); lv_style_set_pad_column(&styles->list_btn, PAD_SMALL); + lv_style_set_flex_flow(&styles->list_btn, LV_FLEX_FLOW_ROW); + lv_style_set_layout(&styles->list_btn, LV_LAYOUT_FLEX); style_init_reset(&styles->list_item_grow); lv_style_set_transform_width(&styles->list_item_grow, PAD_DEF); diff --git a/src/extra/widgets/calendar/lv_calendar.c b/src/extra/widgets/calendar/lv_calendar.c index 3149a1e26..dd239958d 100644 --- a/src/extra/widgets/calendar/lv_calendar.c +++ b/src/extra/widgets/calendar/lv_calendar.c @@ -221,7 +221,7 @@ static void my_constructor(lv_obj_t * obj, const lv_obj_t * copy) calendar->highlighted_dates = NULL; calendar->highlighted_dates_num = 0; - lv_obj_set_size(obj, LV_DPX(240), LV_DPX(240)); + lv_obj_set_size(obj, LV_DPX(180), LV_DPX(180)); lv_memset_00(calendar->nums, sizeof(calendar->nums)); uint8_t i; diff --git a/src/extra/widgets/calendar/lv_calendar_header_arrow.c b/src/extra/widgets/calendar/lv_calendar_header_arrow.c index 874746e0e..a4e6e031f 100644 --- a/src/extra/widgets/calendar/lv_calendar_header_arrow.c +++ b/src/extra/widgets/calendar/lv_calendar_header_arrow.c @@ -56,7 +56,8 @@ lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent, lv_obj_t * calenda lv_coord_t w = lv_obj_get_width(calendar); lv_obj_set_size(header, w, LV_SIZE_CONTENT); - lv_obj_set_layout(header, &lv_flex_row_center); + lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW); + lv_obj_set_flex_place(header, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START); lv_obj_t * mo_prev = lv_btn_create(header, NULL); lv_obj_set_style_content_text(mo_prev, LV_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_LEFT); diff --git a/src/extra/widgets/calendar/lv_calendar_header_dropdown.c b/src/extra/widgets/calendar/lv_calendar_header_dropdown.c index c795b883b..d9b22c4ed 100644 --- a/src/extra/widgets/calendar/lv_calendar_header_dropdown.c +++ b/src/extra/widgets/calendar/lv_calendar_header_dropdown.c @@ -65,21 +65,20 @@ lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent, lv_obj_t * cale lv_coord_t w = lv_obj_get_width(calendar); lv_obj_set_size(header, w, LV_SIZE_CONTENT); - lv_obj_set_layout(header, &lv_flex_row_center); + lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW); + lv_obj_set_flex_place(header, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START); lv_obj_t * year_dd = lv_dropdown_create(header, NULL); lv_dropdown_set_options(year_dd, year_list); lv_dropdown_set_selected(year_dd, 2023 - cur_date->year); lv_obj_add_event_cb(year_dd, year_event_cb, calendar); lv_obj_set_flex_grow(year_dd, 1); - lv_obj_clear_flag(year_dd, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_obj_t * month_dd = lv_dropdown_create(header, NULL); lv_dropdown_set_options(month_dd, month_list); lv_dropdown_set_selected(month_dd, cur_date->month - 1); lv_obj_add_event_cb(month_dd, month_event_cb, calendar); lv_obj_set_flex_grow(month_dd, 1); - lv_obj_clear_flag(month_dd, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_obj_align(header, calendar, LV_ALIGN_OUT_TOP_MID, 0, 0); diff --git a/src/extra/widgets/colorwheel/lv_colorwheel.c b/src/extra/widgets/colorwheel/lv_colorwheel.c index 3f335737d..6859e0056 100644 --- a/src/extra/widgets/colorwheel/lv_colorwheel.c +++ b/src/extra/widgets/colorwheel/lv_colorwheel.c @@ -355,7 +355,7 @@ static void lv_colorwheel_event(lv_obj_t * obj, lv_event_t e) lv_coord_t * s = lv_event_get_param(); *s = LV_MAX(*s, knob_pad); } - else if(e == LV_EVENT_COORD_CHANGED) { + else if(e == LV_EVENT_SIZE_CHANGED) { void * param = lv_event_get_param(); /*Refresh extended draw area to make knob visible*/ if(lv_obj_get_width(obj) != lv_area_get_width(param) || diff --git a/src/extra/widgets/list/lv_list.c b/src/extra/widgets/list/lv_list.c index 56b190856..2a9928608 100644 --- a/src/extra/widgets/list/lv_list.c +++ b/src/extra/widgets/list/lv_list.c @@ -55,7 +55,7 @@ lv_obj_t * lv_list_create(lv_obj_t * parent) { lv_obj_t * list = lv_obj_create_from_class(&lv_list_class, parent, NULL); lv_obj_set_size(list, LV_DPX(200), LV_DPX(300)); - lv_obj_set_layout(list, &lv_flex_column_nowrap); + lv_obj_set_flex_flow(list, LV_FLEX_FLOW_COLUMN); return list; } @@ -74,7 +74,6 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const char * icon, const char * txt, lv_obj_t * btn = lv_obj_create_from_class(&lv_list_btn_class, list, NULL); lv_obj_set_size(btn, LV_SIZE_PCT(100), LV_SIZE_CONTENT); lv_obj_add_event_cb(btn, event_cb, NULL); - lv_obj_set_layout(btn, &lv_flex_row_wrap); if(icon) { lv_obj_t * img = lv_img_create(btn, NULL); diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index a312fc167..47eefd03c 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -60,7 +60,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF; lv_obj_set_size(mbox, w, LV_SIZE_CONTENT); - lv_obj_set_layout(mbox, &lv_flex_row_wrap); + lv_obj_set_flex_flow(mbox, LV_FLEX_FLOW_ROW); lv_obj_t * label; label = lv_label_create(mbox, NULL); diff --git a/src/extra/widgets/tabview/lv_tabview.c b/src/extra/widgets/tabview/lv_tabview.c index 0bb6fe96f..644907c14 100644 --- a/src/extra/widgets/tabview/lv_tabview.c +++ b/src/extra/widgets/tabview/lv_tabview.c @@ -151,25 +151,23 @@ static void lv_tabview_constructor(lv_obj_t * obj, const lv_obj_t * copy) lv_tabview_t * tabview = (lv_tabview_t *)obj; tabview->tab_pos = tabpos_create; - lv_flex_init(&tabview->flex); switch(tabview->tab_pos) { case LV_DIR_TOP: - lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); break; case LV_DIR_BOTTOM: - lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_COLUMN_REVERSE); + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN_REVERSE); break; case LV_DIR_LEFT: - lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_ROW); + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW); break; case LV_DIR_RIGHT: - lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_ROW_REVERSE); + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW_REVERSE); break; } lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); - lv_obj_set_layout(obj, &tabview->flex); lv_obj_t * btnm; lv_obj_t * cont; @@ -202,7 +200,7 @@ static void lv_tabview_constructor(lv_obj_t * obj, const lv_obj_t * copy) break; } - lv_obj_set_layout(cont, &lv_flex_row_nowrap); + lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW); lv_obj_set_scroll_snap_x(cont, LV_SCROLL_SNAP_CENTER); lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ONE); lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS); diff --git a/src/extra/widgets/tabview/lv_tabview.h b/src/extra/widgets/tabview/lv_tabview.h index 3ff22fd0c..c7773d487 100644 --- a/src/extra/widgets/tabview/lv_tabview.h +++ b/src/extra/widgets/tabview/lv_tabview.h @@ -29,7 +29,6 @@ typedef struct { lv_obj_t obj; char ** map; - lv_flex_t flex; uint16_t tab_cnt; uint16_t tab_cur; lv_dir_t tab_pos; diff --git a/src/extra/widgets/win/lv_win.c b/src/extra/widgets/win/lv_win.c index ebef6c1f4..16071bbe3 100644 --- a/src/extra/widgets/win/lv_win.c +++ b/src/extra/widgets/win/lv_win.c @@ -85,11 +85,11 @@ static void lv_win_constructor(lv_obj_t * obj, const lv_obj_t * copy) LV_UNUSED(copy); lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_set_size(obj, lv_obj_get_width(parent), lv_obj_get_height(parent)); - lv_obj_set_layout(obj, &lv_flex_column_nowrap); + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); lv_obj_t * header = lv_obj_create(obj, NULL); lv_obj_set_size(header, LV_SIZE_PCT(100), create_header_height); - lv_obj_set_layout(header, &lv_flex_row_wrap); + lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW); lv_obj_t * cont = lv_obj_create(obj, NULL); lv_obj_set_flex_grow(cont, 1); diff --git a/src/hal/lv_hal_disp.c b/src/hal/lv_hal_disp.c index 82cb80911..63a0cb224 100644 --- a/src/hal/lv_hal_disp.c +++ b/src/hal/lv_hal_disp.c @@ -169,7 +169,7 @@ void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv) lv_obj_get_coords(disp->screens[i], &prev_coords); lv_area_set_width(&disp->screens[i]->coords, w); lv_area_set_height(&disp->screens[i]->coords, h); - lv_event_send(disp->screens[i], LV_EVENT_COORD_CHANGED, &prev_coords); + lv_event_send(disp->screens[i], LV_EVENT_SIZE_CHANGED, &prev_coords); } /* diff --git a/src/misc/lv_area.h b/src/misc/lv_area.h index 0f9564f63..b495fd13b 100644 --- a/src/misc/lv_area.h +++ b/src/misc/lv_area.h @@ -234,22 +234,18 @@ void _lv_area_align(const lv_area_t * base, const lv_area_t * to_align, lv_align #define _LV_COORD_TYPE_PX (0 << _LV_COORD_TYPE_SHIFT) #define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT) -#define _LV_COORD_TYPE_LAYOUT (2 << _LV_COORD_TYPE_SHIFT) #define _LV_COORD_TYPE_RESERVED (3 << _LV_COORD_TYPE_SHIFT) #define LV_COORD_IS_PX(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_PX) ? true : false) #define LV_COORD_IS_SPEC(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_SPEC) ? true : false) -#define LV_COORD_IS_LAYOUT(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_LAYOUT) ? true : false) #define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC) -#define LV_COORD_SET_LAYOUT(x) ((x) | _LV_COORD_TYPE_LAYOUT) /*Special coordinates*/ #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) -#define LV_SIZE_LAYOUT LV_COORD_SET_SPEC(1002) /*The size is managed by the layout therefore `lv_obj_set_width/height/size()` can't change is*/ #ifdef __cplusplus } /*extern "C"*/ diff --git a/src/misc/lv_mem.c b/src/misc/lv_mem.c index 484210a71..453e16722 100644 --- a/src/misc/lv_mem.c +++ b/src/misc/lv_mem.c @@ -23,7 +23,7 @@ *********************/ /*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/ #ifndef LV_MEM_ADD_JUNK -# define LV_MEM_ADD_JUNK 0 +# define LV_MEM_ADD_JUNK 1 #endif #ifdef LV_ARCH_64 diff --git a/src/misc/lv_printf.c b/src/misc/lv_printf.c index 1a31e78f5..852c77c64 100644 --- a/src/misc/lv_printf.c +++ b/src/misc/lv_printf.c @@ -30,6 +30,8 @@ // /////////////////////////////////////////////////////////////////////////////// +/*Original repository: https://github.com/mpaland/printf*/ + #include "lv_printf.h" #if LV_SPRINTF_CUSTOM == 0 diff --git a/src/misc/lv_printf.h b/src/misc/lv_printf.h index 4543cffed..c29d18dad 100644 --- a/src/misc/lv_printf.h +++ b/src/misc/lv_printf.h @@ -29,6 +29,8 @@ // /////////////////////////////////////////////////////////////////////////////// +/*Original repository: https://github.com/mpaland/printf*/ + #ifndef _LV_PRINTF_H_ #define _LV_PRINTF_H_ diff --git a/src/misc/lv_style.c b/src/misc/lv_style.c index 82f4a9010..e8f12d406 100644 --- a/src/misc/lv_style.c +++ b/src/misc/lv_style.c @@ -188,7 +188,7 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ style->has_group |= 1 << group; } -bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) +lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) { return lv_style_get_prop_inlined(style, prop, value); } diff --git a/src/misc/lv_style.h b/src/misc/lv_style.h index 9c5abc3f8..7e9f0fa9b 100644 --- a/src/misc/lv_style.h +++ b/src/misc/lv_style.h @@ -134,6 +134,12 @@ typedef enum { LV_STYLE_PAD_ROW = 20 | LV_STYLE_PROP_LAYOUT_REFR, LV_STYLE_PAD_COLUMN = 21 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_WIDTH = 22 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_HEIGHT = 23 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_X = 24 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_Y = 25 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_LAYOUT = 26 | LV_STYLE_PROP_LAYOUT_REFR, + /*Group 2*/ LV_STYLE_BG_COLOR = 32, LV_STYLE_BG_COLOR_FILTERED = 32 | LV_STYLE_PROP_FILTER, @@ -318,11 +324,11 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ * @param style pointer to a style * @param prop the ID of a property * @param value pointer to a `lv_style_value_t` variable to store the value - * @return false: the property wsn't found in the style (`value` is unchanged) - * true: the property was fond, and `value` is set accordingly + * @return LV_RES_INV: the property wsn't found in the style (`value` is unchanged) + * LV_RES_OK: the property was fond, and `value` is set accordingly * @note For performance reasons there are no sanity check on `style` */ -bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value); +lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value); /** @@ -330,14 +336,14 @@ bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ * @param style pointer to a style * @param prop the ID of a property * @param value pointer to a `lv_style_value_t` variable to store the value - * @return false: the property wsn't found in the style (`value` is unchanged) - * true: the property was fond, and `value` is set accordingly + * @return LV_RES_INV: the property wsn't found in the style (`value` is unchanged) + * LV_RES_OK: the property was fond, and `value` is set accordingly * @note For performance reasons there are no sanity check on `style` * @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places */ -static inline bool lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) +static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) { - if(style->prop_cnt == 0) return false; + if(style->prop_cnt == 0) return LV_RES_INV; if(style->prop_cnt > 1) { uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t); @@ -347,14 +353,14 @@ static inline bool lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t if(props[i] == prop) { lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props; *value = values[i]; - return true; + return LV_RES_OK; } } } else if(style->prop1 == prop) { *value = style->v_p.value1; return true; } - return false; + return LV_RES_INV; } /** diff --git a/src/misc/lv_style_gen.h b/src/misc/lv_style_gen.h index 0f401f214..e1418cd2b 100644 --- a/src/misc/lv_style_gen.h +++ b/src/misc/lv_style_gen.h @@ -150,6 +150,48 @@ static inline void lv_style_set_pad_column(lv_style_t * style, lv_coord_t value) lv_style_set_prop(style, LV_STYLE_PAD_COLUMN, v); } +static inline void lv_style_set_width(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_WIDTH, v); +} + +static inline void lv_style_set_height(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_HEIGHT, v); +} + + +static inline void lv_style_set_x(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_X, v); +} + +static inline void lv_style_set_y(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_Y, v); +} + + +static inline void lv_style_set_layout(lv_style_t * style, lv_coord_t value) +{ + lv_style_value_t v = { + .num = (int32_t)value + }; + lv_style_set_prop(style, LV_STYLE_LAYOUT, v); +} + static inline void lv_style_set_bg_color(lv_style_t * style, lv_color_t value) { lv_style_value_t v = { diff --git a/src/widgets/lv_arc.c b/src/widgets/lv_arc.c index e78cf258e..9048e790f 100644 --- a/src/widgets/lv_arc.c +++ b/src/widgets/lv_arc.c @@ -502,8 +502,6 @@ static void lv_arc_constructor(lv_obj_t * obj, const lv_obj_t * copy) arc->last_tick = lv_tick_get(); arc->last_angle =arc->indic_angle_end; - lv_obj_set_size(obj, LV_DPI_DEF, LV_DPI_DEF); - /*Init the new arc arc*/ if(copy == NULL) { lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE); diff --git a/src/widgets/lv_bar.c b/src/widgets/lv_bar.c index 5e96b496a..5a33fdd23 100644 --- a/src/widgets/lv_bar.c +++ b/src/widgets/lv_bar.c @@ -122,7 +122,7 @@ void lv_bar_set_range(lv_obj_t * obj, int16_t min, int16_t max) bar->max_value = max; bar->min_value = min; - if(lv_bar_get_type(obj) != LV_BAR_TYPE_RANGE) + if(lv_bar_get_mode(obj) != LV_BAR_MODE_RANGE) bar->start_value = min; if(bar->cur_value > max) { @@ -136,13 +136,13 @@ void lv_bar_set_range(lv_obj_t * obj, int16_t min, int16_t max) lv_obj_invalidate(obj); } -void lv_bar_set_type(lv_obj_t * obj, lv_bar_type_t type) +void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode) { LV_ASSERT_OBJ(obj, MY_CLASS); lv_bar_t * bar = (lv_bar_t *)obj; - bar->type = type; - if(bar->type != LV_BAR_TYPE_RANGE) { + bar->mode = mode; + if(bar->mode != LV_BAR_MODE_RANGE) { bar->start_value = bar->min_value; } @@ -166,7 +166,7 @@ int16_t lv_bar_get_start_value(const lv_obj_t * obj) LV_ASSERT_OBJ(obj, MY_CLASS); lv_bar_t * bar = (lv_bar_t *)obj; - if(bar->type != LV_BAR_TYPE_RANGE) return bar->min_value; + if(bar->mode != LV_BAR_MODE_RANGE) return bar->min_value; return LV_BAR_GET_ANIM_VALUE(bar->start_value, bar->start_value_anim); } @@ -186,12 +186,12 @@ int16_t lv_bar_get_max_value(const lv_obj_t * obj) return bar->max_value; } -lv_bar_type_t lv_bar_get_type(lv_obj_t * obj) +lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); lv_bar_t * bar = (lv_bar_t *)obj; - return bar->type; + return bar->mode; } /********************** @@ -207,7 +207,7 @@ static void lv_bar_constructor(lv_obj_t * obj, const lv_obj_t * copy) bar->max_value = 100; bar->start_value = 0; bar->cur_value = 0; - bar->type = LV_BAR_TYPE_NORMAL; + bar->mode = LV_BAR_MODE_NORMAL; lv_bar_init_anim(obj, &bar->cur_value_anim); lv_bar_init_anim(obj, &bar->start_value_anim); @@ -223,7 +223,7 @@ static void lv_bar_constructor(lv_obj_t * obj, const lv_obj_t * copy) bar->start_value = copy_bar->start_value; bar->max_value = copy_bar->max_value; bar->cur_value = copy_bar->cur_value; - bar->type = copy_bar->type; + bar->mode = copy_bar->mode; lv_bar_set_value(obj, bar->cur_value, LV_ANIM_OFF); } @@ -258,7 +258,7 @@ static void draw_indic(lv_obj_t * obj) int32_t range = bar->max_value - bar->min_value; bool hor = barw >= barh ? true : false; bool sym = false; - if(bar->type == LV_BAR_TYPE_SYMMETRICAL && bar->min_value < 0 && bar->max_value > 0 && + if(bar->mode == LV_BAR_MODE_SYMMETRICAL && bar->min_value < 0 && bar->max_value > 0 && bar->start_value == bar->min_value) sym = true; /*Calculate the indicator area*/ diff --git a/src/widgets/lv_bar.h b/src/widgets/lv_bar.h index b978832e9..9889e17a9 100644 --- a/src/widgets/lv_bar.h +++ b/src/widgets/lv_bar.h @@ -31,11 +31,11 @@ extern "C" { **********************/ enum { - LV_BAR_TYPE_NORMAL, - LV_BAR_TYPE_SYMMETRICAL, - LV_BAR_TYPE_RANGE + LV_BAR_MODE_NORMAL, + LV_BAR_MODE_SYMMETRICAL, + LV_BAR_MODE_RANGE }; -typedef uint8_t lv_bar_type_t; +typedef uint8_t lv_bar_mode_t; typedef struct { lv_obj_t * bar; @@ -53,7 +53,7 @@ typedef struct { lv_area_t indic_area; /**< Save the indicator area. Might be used by derived types*/ lv_bar_anim_t cur_value_anim; lv_bar_anim_t start_value_anim; - lv_bar_type_t type : 2; /**< Type of bar*/ + lv_bar_mode_t mode : 2; /**< Type of bar*/ }lv_bar_t; extern const lv_obj_class_t lv_bar_class; @@ -102,9 +102,9 @@ void lv_bar_set_range(lv_obj_t * obj, int16_t min, int16_t max); /** * Set the type of bar. * @param obj pointer to bar object - * @param type bar type from ::lv_bar_type_t + * @param mode bar type from ::lv_bar_mode_t */ -void lv_bar_set_type(lv_obj_t * obj, lv_bar_type_t type); +void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode); /*===================== * Getter functions @@ -141,9 +141,9 @@ int16_t lv_bar_get_max_value(const lv_obj_t * obj); /** * Get the type of bar. * @param obj pointer to bar object - * @return bar type from ::lv_bar_type_t + * @return bar type from ::lv_bar_mode_t */ -lv_bar_type_t lv_bar_get_type(lv_obj_t * obj); +lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj); /********************** * MACROS diff --git a/src/widgets/lv_btn.c b/src/widgets/lv_btn.c index 914b5f1ed..f58ecdb03 100644 --- a/src/widgets/lv_btn.c +++ b/src/widgets/lv_btn.c @@ -60,10 +60,6 @@ static void lv_btn_constructor(lv_obj_t * obj, const lv_obj_t * copy) lv_obj_set_size(obj, LV_DPI_DEF, LV_DPI_DEF / 3); lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); - -#if LV_USE_FLEX - lv_obj_set_layout(obj, &lv_flex_row_center); -#endif } LV_TRACE_OBJ_CREATE("finished"); diff --git a/src/widgets/lv_btnmatrix.c b/src/widgets/lv_btnmatrix.c index 8ad120ddd..333ffd62e 100644 --- a/src/widgets/lv_btnmatrix.c +++ b/src/widgets/lv_btnmatrix.c @@ -84,7 +84,7 @@ lv_obj_t * lv_btnmatrix_create(lv_obj_t * parent, const lv_obj_t * copy) void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_NULL(map); + if(map == NULL) return; lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;; @@ -403,13 +403,8 @@ static void lv_btnmatrix_event(lv_obj_t * obj, lv_event_t e) if(e == LV_EVENT_STYLE_CHANGED) { lv_btnmatrix_set_map(obj, btnm->map_p); } - else if(e == LV_EVENT_COORD_CHANGED) { - void * param = lv_event_get_param(); - if(param && - (lv_obj_get_width(obj) != lv_area_get_width(param) || lv_obj_get_height(obj) != lv_area_get_height(param))) - { - lv_btnmatrix_set_map(obj, btnm->map_p); - } + else if(e == LV_EVENT_SIZE_CHANGED) { + lv_btnmatrix_set_map(obj, btnm->map_p); } else if(e == LV_EVENT_PRESSED) { void * param = lv_event_get_param(); diff --git a/src/widgets/lv_dropdown.c b/src/widgets/lv_dropdown.c index cb36d3986..ccaed47c6 100644 --- a/src/widgets/lv_dropdown.c +++ b/src/widgets/lv_dropdown.c @@ -429,6 +429,8 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) ((lv_dropdown_list_t*) list_obj)->dropdown = dropdown_obj; dropdown->list = list_obj; lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_CLICK_FOCUSABLE); + lv_obj_add_flag(dropdown->list, LV_OBJ_FLAG_IGNORE_LAYOUT); + lv_obj_update_layout(dropdown->list); } lv_obj_t * label = get_label(dropdown_obj); @@ -441,7 +443,6 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) lv_obj_set_width(dropdown->list, lv_obj_get_width(dropdown_obj)); } - lv_coord_t label_h = lv_obj_get_height(label); lv_coord_t top = lv_obj_get_style_pad_top(dropdown->list, LV_PART_MAIN); lv_coord_t bottom = lv_obj_get_style_pad_bottom(dropdown->list, LV_PART_MAIN); @@ -490,9 +491,12 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) else if(dir == LV_DIR_LEFT) lv_obj_align(dropdown->list, dropdown_obj, LV_ALIGN_OUT_LEFT_TOP, 0, 0); else if(dir == LV_DIR_RIGHT) lv_obj_align(dropdown->list, dropdown_obj, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); + if(dropdown->dir == LV_DIR_LEFT || dropdown->dir == LV_DIR_RIGHT) { - if(dropdown->list->coords.y2 >= LV_VER_RES) { - lv_obj_set_y(dropdown->list, lv_obj_get_y(dropdown->list) - (dropdown->list->coords.y2 - LV_VER_RES) - 1); + lv_coord_t y1 = lv_obj_get_y(dropdown->list); + lv_coord_t y2 = lv_obj_get_y2(dropdown->list); + if(y2 >= LV_VER_RES) { + lv_obj_set_y(dropdown->list, y1 - (y2 - LV_VER_RES) - 1); } } @@ -662,7 +666,7 @@ static void lv_dropdown_event(lv_obj_t * obj, lv_event_t e) lv_obj_invalidate(obj); } } - else if(e == LV_EVENT_COORD_CHANGED) { + else if(e == LV_EVENT_SIZE_CHANGED) { if(dropdown->list) lv_dropdown_close(obj); } else if(e == LV_EVENT_GET_SELF_SIZE) { diff --git a/src/widgets/lv_label.c b/src/widgets/lv_label.c index 49ef9b57e..1b2316dab 100644 --- a/src/widgets/lv_label.c +++ b/src/widgets/lv_label.c @@ -750,13 +750,9 @@ static void lv_label_event_cb(lv_obj_t * obj, lv_event_t e) lv_label_revert_dots(obj); lv_label_refr_text(obj); } - else if(e == LV_EVENT_COORD_CHANGED) { - void * param = lv_event_get_param(); - if(lv_area_get_width(&obj->coords) != lv_area_get_width(param) || - lv_area_get_height(&obj->coords) != lv_area_get_height(param)) { - lv_label_revert_dots(obj); - lv_label_refr_text(obj); - } + else if(e == LV_EVENT_SIZE_CHANGED) { + lv_label_revert_dots(obj); + lv_label_refr_text(obj); } else if(e == LV_EVENT_BASE_DIR_CHANGED) { #if LV_USE_BIDI diff --git a/src/widgets/lv_roller.c b/src/widgets/lv_roller.c index d34c425e4..63911e065 100644 --- a/src/widgets/lv_roller.c +++ b/src/widgets/lv_roller.c @@ -334,13 +334,8 @@ static void lv_roller_event(lv_obj_t * obj, lv_event_t e) lv_obj_handle_self_size_chg(obj); refr_position(obj, false); } - else if(e == LV_EVENT_COORD_CHANGED) { - void * param = lv_event_get_param(); - if(lv_obj_get_width(obj) != lv_area_get_width(param) || - lv_obj_get_height(obj) != lv_area_get_height(param)) - { - refr_position(obj, false); - } + else if(e == LV_EVENT_SIZE_CHANGED) { + refr_position(obj, false); } else if(e == LV_EVENT_PRESSED) { roller->moved = 0; diff --git a/src/widgets/lv_slider.c b/src/widgets/lv_slider.c index 20c4afca5..b6dc0485f 100644 --- a/src/widgets/lv_slider.c +++ b/src/widgets/lv_slider.c @@ -105,7 +105,7 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e) if(res != LV_RES_OK) return; lv_slider_t * slider = (lv_slider_t *)obj; - lv_slider_type_t type = lv_slider_get_type(obj); + lv_slider_mode_t type = lv_slider_get_mode(obj); /*Advanced hit testing: react only on dragging the knob(s)*/ if(e == LV_EVENT_HIT_TEST) { @@ -115,17 +115,17 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e) info->result = _lv_area_is_point_on(&slider->right_knob_area, info->point, 0); /*There's still a change we have a hit, if we have another knob*/ - if((info->result == false) && (type == LV_SLIDER_TYPE_RANGE)) { + if((info->result == false) && (type == LV_SLIDER_MODE_RANGE)) { info->result = _lv_area_is_point_on(&slider->left_knob_area, info->point, 0); } } else if(e == LV_EVENT_PRESSED) { lv_point_t p; slider->dragging = true; - if(type == LV_SLIDER_TYPE_NORMAL || type == LV_SLIDER_TYPE_SYMMETRICAL) { + if(type == LV_SLIDER_MODE_NORMAL || type == LV_SLIDER_MODE_SYMMETRICAL) { slider->value_to_set = &slider->bar.cur_value; } - else if(type == LV_SLIDER_TYPE_RANGE) { + else if(type == LV_SLIDER_MODE_RANGE) { lv_indev_get_point(lv_indev_get_act(), &p); bool hor = lv_obj_get_width(obj) >= lv_obj_get_height(obj); lv_bidi_dir_t base_dir = lv_obj_get_base_dir(obj); @@ -249,7 +249,7 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e) lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); if(indev_type == LV_INDEV_TYPE_ENCODER) { if(editing) { - if(lv_slider_get_type(obj) == LV_SLIDER_TYPE_RANGE) { + if(lv_slider_get_mode(obj) == LV_SLIDER_MODE_RANGE) { if(slider->left_knob_focus == 0) slider->left_knob_focus = 1; else { slider->left_knob_focus = 0; @@ -269,14 +269,8 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e) slider->left_knob_focus = 0; } } - else if(e == LV_EVENT_COORD_CHANGED) { - /*The knob size depends on slider size. - *During the drawing method the obj. size is used by the knob so refresh the obj. size.*/ - void * param = lv_event_get_param(); - if(lv_obj_get_width(obj) != lv_area_get_width(param) || - lv_obj_get_height(obj) != lv_area_get_height(param)) { - lv_obj_refresh_ext_draw_size(obj); - } + else if(e == LV_EVENT_SIZE_CHANGED) { + lv_obj_refresh_ext_draw_size(obj); } else if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) { lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB); @@ -331,7 +325,7 @@ static void draw_knob(lv_obj_t * obj) bool hor = objw >= objh ? true : false; lv_coord_t knob_size = hor ? objh : objw; bool sym = false; - if(slider->bar.type == LV_BAR_TYPE_SYMMETRICAL && slider->bar.min_value < 0 && slider->bar.max_value > 0) sym = true; + if(slider->bar.mode == LV_BAR_MODE_SYMMETRICAL && slider->bar.min_value < 0 && slider->bar.max_value > 0) sym = true; lv_area_t knob_area; @@ -378,7 +372,7 @@ static void draw_knob(lv_obj_t * obj) dsc.draw_area = &slider->right_knob_area; dsc.rect_dsc = &knob_rect_dsc; - if(lv_slider_get_type(obj) != LV_SLIDER_TYPE_RANGE) { + if(lv_slider_get_mode(obj) != LV_SLIDER_MODE_RANGE) { lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); lv_draw_rect(&slider->right_knob_area, clip_area, &knob_rect_dsc); lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); diff --git a/src/widgets/lv_slider.h b/src/widgets/lv_slider.h index 1eec5599d..1dba0b357 100644 --- a/src/widgets/lv_slider.h +++ b/src/widgets/lv_slider.h @@ -34,11 +34,11 @@ extern "C" { **********************/ enum { - LV_SLIDER_TYPE_NORMAL = LV_BAR_TYPE_NORMAL, - LV_SLIDER_TYPE_SYMMETRICAL = LV_BAR_TYPE_SYMMETRICAL, - LV_SLIDER_TYPE_RANGE = LV_BAR_TYPE_RANGE + LV_SLIDER_MODE_NORMAL = LV_BAR_MODE_NORMAL, + LV_SLIDER_MODE_SYMMETRICAL = LV_BAR_MODE_SYMMETRICAL, + LV_SLIDER_MODE_RANGE = LV_BAR_MODE_RANGE }; -typedef uint8_t lv_slider_type_t; +typedef uint8_t lv_slider_mode_t; typedef struct { lv_bar_t bar; /*Add the ancestor's type first*/ @@ -102,13 +102,13 @@ static inline void lv_slider_set_range(lv_obj_t * obj, int16_t min, int16_t max) } /** - * Set the type of slider. + * Set the mode of slider. * @param obj pointer to a slider object - * @param en the type of the slider. See ::lv_slider_type_t + * @param mode the mode of the slider. See ::lv_slider_mode_t */ -static inline void lv_slider_set_type(lv_obj_t * obj, lv_slider_type_t type) +static inline void lv_slider_set_mode(lv_obj_t * obj, lv_slider_mode_t mode) { - lv_bar_set_type(obj, (lv_bar_type_t)type); + lv_bar_set_mode(obj, (lv_bar_mode_t)mode); } /*===================== @@ -163,16 +163,16 @@ static inline int16_t lv_slider_get_max_value(const lv_obj_t * obj) bool lv_slider_is_dragged(const lv_obj_t * obj); /** - * Get the type of the slider. + * Get the mode of the slider. * @param obj pointer to a bar object - * @return see ::lv_slider_type_t + * @return see ::lv_slider_mode_t */ -static inline lv_slider_type_t lv_slider_get_type(lv_obj_t * slider) +static inline lv_slider_mode_t lv_slider_get_mode(lv_obj_t * slider) { - lv_bar_type_t type = lv_bar_get_type(slider); - if(type == LV_BAR_TYPE_SYMMETRICAL) return LV_SLIDER_TYPE_SYMMETRICAL; - else if(type == LV_BAR_TYPE_RANGE) return LV_SLIDER_TYPE_RANGE; - else return LV_SLIDER_TYPE_NORMAL; + lv_bar_mode_t mode = lv_bar_get_mode(slider); + if(mode == LV_BAR_MODE_SYMMETRICAL) return LV_SLIDER_MODE_SYMMETRICAL; + else if(mode == LV_BAR_MODE_RANGE) return LV_SLIDER_MODE_RANGE; + else return LV_SLIDER_MODE_NORMAL; } /********************** diff --git a/src/widgets/lv_switch.c b/src/widgets/lv_switch.c index b01e1d47b..a4dfe2f3b 100644 --- a/src/widgets/lv_switch.c +++ b/src/widgets/lv_switch.c @@ -105,8 +105,6 @@ static void lv_switch_event(lv_obj_t * obj, lv_event_t e) knob_size += 2; /*For rounding error*/ knob_size += lv_obj_calculate_ext_draw_size(obj, LV_PART_KNOB); -// knob_size = (knob_size - lv_obj_get_height(obj)) / 2; - lv_coord_t * s = lv_event_get_param(); *s = LV_MAX(*s, knob_size); *s = LV_MAX(*s, lv_obj_calculate_ext_draw_size(obj, LV_PART_INDICATOR)); diff --git a/src/widgets/lv_textarea.c b/src/widgets/lv_textarea.c index dde94d407..e6fd01e07 100644 --- a/src/widgets/lv_textarea.c +++ b/src/widgets/lv_textarea.c @@ -1055,17 +1055,14 @@ static void lv_textarea_event(lv_obj_t * obj, lv_event_t e) else if(e == LV_EVENT_FOCUSED) { start_cursor_blink(obj); } - else if(e == LV_EVENT_COORD_CHANGED) { + else if(e == LV_EVENT_SIZE_CHANGED) { /*Set the label width according to the text area width*/ if(ta->label) { - void * param = lv_event_get_param(); - if(lv_obj_get_width(obj) != lv_area_get_width(param) || lv_obj_get_height(obj) != lv_area_get_height(param)) { - lv_obj_set_width(ta->label, lv_obj_get_width_fit(obj)); - lv_obj_set_pos(ta->label, 0, 0); - lv_label_set_text(ta->label, NULL); /*Refresh the label*/ + lv_obj_set_width(ta->label, lv_obj_get_width_fit(obj)); + lv_obj_set_pos(ta->label, 0, 0); + lv_label_set_text(ta->label, NULL); /*Refresh the label*/ - refr_cursor_area(obj); - } + refr_cursor_area(obj); } } else if(e == LV_EVENT_KEY) {