diff --git a/examples/widgets/btn/lv_btn_example_1.c b/examples/widgets/btn/lv_btn_example_1.c index 9951fed79..c76522c21 100644 --- a/examples/widgets/btn/lv_btn_example_1.c +++ b/examples/widgets/btn/lv_btn_example_1.c @@ -27,7 +27,7 @@ void lv_ex_btn_1(void) 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_AUTO); + lv_obj_set_height(btn2, LV_SIZE_CONTENT); label = lv_label_create(btn2, NULL); lv_label_set_text(label, "Toggle"); diff --git a/examples/widgets/keyboard/lv_keyboard_example_1.c b/examples/widgets/keyboard/lv_keyboard_example_1.c index e8ac02e23..dacecf19d 100644 --- a/examples/widgets/keyboard/lv_keyboard_example_1.c +++ b/examples/widgets/keyboard/lv_keyboard_example_1.c @@ -26,6 +26,7 @@ void lv_keyboard_example_1(void) ta = lv_textarea_create(lv_scr_act(), NULL); lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10); lv_obj_add_event_cb(ta, ta_event_cb, kb); + lv_textarea_set_placeholder_text(ta, "Hello"); ta = lv_textarea_create(lv_scr_act(), NULL); lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 10); diff --git a/examples/widgets/spinbox/lv_spinbox_example_1.c b/examples/widgets/spinbox/lv_spinbox_example_1.c index 362bdeeba..d3d191c3a 100644 --- a/examples/widgets/spinbox/lv_spinbox_example_1.c +++ b/examples/widgets/spinbox/lv_spinbox_example_1.c @@ -23,7 +23,7 @@ static void lv_spinbox_decrement_event_cb(lv_obj_t * btn, lv_event_t e) void lv_ex_spinbox_1(void) { spinbox = lv_spinbox_create(lv_scr_act()); - lv_spinbox_set_range(spinbox, -1000, 90000); + lv_spinbox_set_range(spinbox, -1000, 25000); lv_spinbox_set_digit_format(spinbox, 5, 2); lv_spinbox_step_prev(spinbox); lv_obj_set_width(spinbox, 100); diff --git a/examples/widgets/tabview/lv_tabview_example_1.c b/examples/widgets/tabview/lv_tabview_example_1.c index f156dc42e..563563406 100644 --- a/examples/widgets/tabview/lv_tabview_example_1.c +++ b/examples/widgets/tabview/lv_tabview_example_1.c @@ -36,5 +36,7 @@ void lv_ex_tabview_1(void) label = lv_label_create(tab3, NULL); lv_label_set_text(label, "Third tab"); + + lv_obj_scroll_to_view_recursive(label, LV_ANIM_ON); } #endif diff --git a/examples/widgets/tileview/lv_tileview_example_1.c b/examples/widgets/tileview/lv_tileview_example_1.c index f625a0e20..d59c1aeb2 100644 --- a/examples/widgets/tileview/lv_tileview_example_1.c +++ b/examples/widgets/tileview/lv_tileview_example_1.c @@ -2,7 +2,7 @@ #if LV_USE_TILEVIEW /** - * Create a 2x2 tile view and allow scrolling on in an "L" shape. + * Create a 2x2 tile view and allow scrolling only in an "L" shape. * Demonstrate scroll chaining with a long list that * scrolls the tile view when it cant't be scrolled further. */ @@ -16,9 +16,21 @@ void lv_ex_tileview_1(void) lv_label_set_text(label, "Scroll down"); lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); - /*Tile2: a list*/ + + /*Tile2: a button*/ lv_obj_t * tile2 = lv_tileview_add_tile(tv, 0, 1, LV_DIR_TOP | LV_DIR_RIGHT); - lv_obj_t * list = lv_list_create(tile2); + + lv_obj_t * btn = lv_btn_create(tile2, NULL); + + label = lv_label_create(btn, NULL); + lv_label_set_text(label, "Scroll up or right"); + + lv_obj_set_size(btn, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_align(btn, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Tile3: a list*/ + lv_obj_t * tile3 = lv_tileview_add_tile(tv, 1, 1, LV_DIR_LEFT); + lv_obj_t * list = lv_list_create(tile3); lv_obj_set_size(list, LV_COORD_PCT(100), LV_COORD_PCT(100)); lv_list_add_btn(list, NULL, "One", NULL); @@ -29,15 +41,9 @@ void lv_ex_tileview_1(void) lv_list_add_btn(list, NULL, "Six", NULL); lv_list_add_btn(list, NULL, "Seven", NULL); lv_list_add_btn(list, NULL, "Eight", NULL); + lv_list_add_btn(list, NULL, "Nine", NULL); + lv_list_add_btn(list, NULL, "Ten", NULL); - /*Tile3: a button*/ - lv_obj_t * tile3 = lv_tileview_add_tile(tv, 1, 1, LV_DIR_LEFT); - - lv_obj_t * btn = lv_btn_create(tile3, NULL); - lv_obj_align(btn, NULL, LV_ALIGN_CENTER, 0, 0); - label = lv_label_create(btn, NULL); - lv_label_set_text(label, "No scroll up"); - lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); } #endif diff --git a/examples/widgets/win/lv_win_example_1.c b/examples/widgets/win/lv_win_example_1.c index 6eec9ac70..c70b0a4b7 100644 --- a/examples/widgets/win/lv_win_example_1.c +++ b/examples/widgets/win/lv_win_example_1.c @@ -6,17 +6,17 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { if(event == LV_EVENT_CLICKED) { - printf("Value: %d\n", lv_obj_get_child_id(obj)); + printf("Button: %d\n", lv_obj_get_child_id(obj)); } } void lv_ex_win_1(void) { - lv_obj_t * win = lv_win_create(lv_scr_act(), LV_SIZE_AUTO); - lv_win_add_btn(win, LV_SYMBOL_LEFT, 40, 40, event_handler); + lv_obj_t * win = lv_win_create(lv_scr_act(), 60); + lv_win_add_btn(win, LV_SYMBOL_LEFT, 40, event_handler); lv_win_add_title(win, "A title"); - lv_win_add_btn(win, LV_SYMBOL_RIGHT, 40, 40, event_handler); - lv_win_add_btn(win, LV_SYMBOL_CLOSE, 40, 40, event_handler); + lv_win_add_btn(win, LV_SYMBOL_RIGHT, 40, event_handler); + lv_win_add_btn(win, LV_SYMBOL_CLOSE, 60, event_handler); lv_obj_t * cont = lv_win_get_content(win); /*Content can be aded here*/ lv_obj_t * label = lv_label_create(cont, NULL); diff --git a/lvgl.h b/lvgl.h index d65367fe7..fc6a72792 100644 --- a/lvgl.h +++ b/lvgl.h @@ -1,6 +1,6 @@ /** * @file lvgl.h - * Include all LittleV GL related headers + * Include all LVGL related headers */ #ifndef LVGL_H @@ -77,6 +77,8 @@ extern "C" { #include "src/extra/widgets/spinbox/lv_spinbox.h" #include "src/extra/widgets/spinner/lv_spinner.h" #include "src/extra/widgets/tabview/lv_tabview.h" +#include "src/extra/widgets/tileview/lv_tileview.h" +#include "src/extra/widgets/win/lv_win.h" /* LAYOUTS */ #include "src/extra/layouts/flex/lv_flex.h" diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index 17490a44a..859a351f8 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -143,6 +143,8 @@ void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow) 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_update_layout(parent, obj); } /********************** @@ -166,8 +168,8 @@ static void flex_update(lv_obj_t * cont, lv_obj_t * item) lv_flex_place_t cross_place = f->track_cross_place; lv_coord_t * cross_pos = (row ? &abs_y : &abs_x); - if((row && cont->h_set == LV_SIZE_AUTO) || - (!row && cont->w_set == LV_SIZE_AUTO)) + if((row && cont->h_set == LV_SIZE_CONTENT) || + (!row && cont->w_set == LV_SIZE_CONTENT)) { cross_place = LV_FLEX_PLACE_START; } @@ -241,7 +243,7 @@ static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t 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_AUTO) || (!row && cont->h_set == LV_SIZE_AUTO))) { + if(wrap && ((row && cont->w_set == LV_SIZE_CONTENT) || (!row && cont->h_set == LV_SIZE_CONTENT))) { wrap = false; } lv_coord_t(*get_main_size)(const lv_obj_t *) = (row ? lv_obj_get_width : lv_obj_get_height); diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index e655badb8..a7da80629 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -150,7 +150,7 @@ static void full_refresh(lv_obj_t * cont) } calc_free(&c); - if(cont->w_set == LV_SIZE_AUTO || cont->h_set == LV_SIZE_AUTO) { + if(cont->w_set == LV_SIZE_CONTENT || cont->h_set == LV_SIZE_CONTENT) { lv_obj_set_size(cont, cont->w_set, cont->h_set); } } @@ -196,11 +196,11 @@ 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_AUTO ? 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_AUTO ? true : false; + bool auto_h = cont->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); @@ -232,7 +232,7 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) uint32_t col_fr_cnt = 0; lv_coord_t grid_w = 0; - bool auto_w = cont->w_set == LV_SIZE_AUTO ? true : false; + bool auto_w = cont->w_set == LV_SIZE_CONTENT ? true : false; for(i = 0; i < c->col_num; i++) { lv_coord_t x = grid->col_dsc[i]; @@ -271,7 +271,7 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) uint32_t row_fr_cnt = 0; lv_coord_t grid_h = 0; - bool auto_h = cont->h_set == LV_SIZE_AUTO ? true : false; + bool auto_h = cont->h_set == LV_SIZE_CONTENT ? true : false; for(i = 0; i < grid->row_dsc_len; i++) { diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 3b6c2e3a2..0a6741294 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -24,7 +24,8 @@ #define RADIUS_DEFAULT LV_DPX(8) /*SCREEN*/ -#define COLOR_SCR (IS_LIGHT ? lv_color_hex(0xf5f8fa) : lv_color_hex(0x444b5a)) +//#define COLOR_SCR (IS_LIGHT ? lv_color_hex(0xf5f8fa) : lv_color_hex(0x444b5a)) +#define COLOR_SCR (IS_LIGHT ? lv_color_hex(0xf3f6f7) : lv_color_hex(0x444b5a)) #define COLOR_SCR_TEXT (IS_LIGHT ? lv_color_hex(0x3b3e42) : lv_color_hex(0xe7e9ec)) /*BUTTON*/ @@ -62,7 +63,7 @@ #define COLOR_BG_TEXT_DIS (IS_LIGHT ? lv_color_hex3(0xaaa) : lv_color_hex3(0x999)) /*SECONDARY BACKGROUND*/ -#define COLOR_GRAY (IS_LIGHT ? lv_color_hex(0xcfd2d4) : lv_color_hex(0x45494d)) +#define COLOR_GRAY (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x45494d)) #define COLOR_BG_SEC_BORDER (IS_LIGHT ? lv_color_hex(0xdfe7ed) : lv_color_hex(0x404040)) #define COLOR_BG_SEC_TEXT (IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex(0xa5a8ad)) #define COLOR_BG_SEC_TEXT_DIS (IS_LIGHT ? lv_color_hex(0xaaaaaa) : lv_color_hex(0xa5a8ad)) @@ -89,7 +90,7 @@ typedef struct { lv_style_t bg_color_primary; lv_style_t bg_color_secondary; lv_style_t bg_color_gray; - lv_style_t bg_color_white; + lv_style_t bg_color_panel; lv_style_t pressed; lv_style_t disabled; lv_style_t pad_zero; @@ -99,10 +100,8 @@ typedef struct { lv_style_t pad_small_negative; lv_style_t line_space_large; lv_style_t text_align_center; - lv_style_t focus_border; lv_style_t focus_outline; lv_style_t edit_outline; - lv_style_t edit_border; lv_style_t circle; lv_style_t no_radius; lv_style_t clip_corner; @@ -110,7 +109,6 @@ typedef struct { lv_style_t transition_delayed; lv_style_t transition_normal; lv_style_t anim; - lv_style_t line_dashed; /*Parts*/ lv_style_t knob; @@ -122,7 +120,7 @@ typedef struct { #endif #if LV_USE_CHART - lv_style_t chart_series, chart_ticks; + lv_style_t chart_series, chart_ticks, chart_bg; #endif #if LV_USE_CHECKBOX @@ -239,12 +237,6 @@ static void style_init(void) lv_style_set_line_color(&styles->card, COLOR_GRAY); lv_style_set_line_width(&styles->card, LV_DPX(1)); - style_init_reset(&styles->focus_border); - lv_style_set_border_color(&styles->focus_border, theme.color_primary); - - style_init_reset(&styles->edit_border); - lv_style_set_border_color(&styles->edit_border, theme.color_secondary); - style_init_reset(&styles->focus_outline); lv_style_set_outline_color(&styles->focus_outline, theme.color_primary); lv_style_set_outline_width(&styles->focus_outline, OUTLINE_WIDTH); @@ -321,11 +313,11 @@ static void style_init(void) lv_style_set_text_color(&styles->bg_color_gray, CARD_TEXT_COLOR); lv_style_set_content_color(&styles->bg_color_gray, CARD_TEXT_COLOR); - style_init_reset(&styles->bg_color_white); - lv_style_set_bg_color(&styles->bg_color_white, LV_COLOR_WHITE); - lv_style_set_bg_opa(&styles->bg_color_white, LV_OPA_COVER); - lv_style_set_text_color(&styles->bg_color_white, CARD_TEXT_COLOR); - lv_style_set_content_color(&styles->bg_color_white, CARD_TEXT_COLOR); + style_init_reset(&styles->bg_color_panel); + lv_style_set_bg_color(&styles->bg_color_panel, LV_COLOR_WHITE); + lv_style_set_bg_opa(&styles->bg_color_panel, LV_OPA_COVER); + lv_style_set_text_color(&styles->bg_color_panel, CARD_TEXT_COLOR); + lv_style_set_content_color(&styles->bg_color_panel, CARD_TEXT_COLOR); style_init_reset(&styles->circle); lv_style_set_radius(&styles->circle, LV_RADIUS_CIRCLE); @@ -346,10 +338,6 @@ static void style_init(void) style_init_reset(&styles->anim); lv_style_set_anim_time(&styles->anim, 200); - style_init_reset(&styles->line_dashed); - lv_style_set_line_dash_width(&styles->line_dashed, LV_DPX(10)); - lv_style_set_line_dash_gap(&styles->line_dashed, LV_DPX(10)); - #if LV_USE_ARC style_init_reset(&styles->arc_indic); lv_style_set_arc_color(&styles->arc_indic, COLOR_GRAY); @@ -381,6 +369,10 @@ static void style_init(void) #endif #if LV_USE_CHART + style_init_reset(&styles->chart_bg); + lv_style_set_line_dash_width(&styles->chart_bg, LV_DPX(10)); + lv_style_set_line_dash_gap(&styles->chart_bg, LV_DPX(10)); + style_init_reset(&styles->chart_series); lv_style_set_line_width(&styles->chart_series, LV_DPX(3)); lv_style_set_radius(&styles->chart_series, LV_DPX(1)); @@ -499,6 +491,41 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) } if(lv_obj_check_type(obj, &lv_obj)) { +#if LV_USE_TABVIEW + lv_obj_t * parent = lv_obj_get_parent(obj); + /*Tabvew content area*/ + if(lv_obj_check_type(parent, &lv_tabview)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_gray); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_gap); + return; + } + /*Tabview pages*/ + else if(lv_obj_check_type(lv_obj_get_parent(parent), &lv_tabview)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->scr); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_normal); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); + return; + } +#endif + +#if LV_USE_WIN + /*Header*/ + if(lv_obj_get_child_id(obj) == 0 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_gray); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_normal); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->text_align_center); + return; + } + /*Content*/ + else if(lv_obj_get_child_id(obj) == 1 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->scr); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_normal); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); + return; + } +#endif lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); @@ -508,7 +535,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #if LV_USE_LIST /*Add different buttons to the lists*/ if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_list)) { - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_white); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_panel); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_btn); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->list_item_grow); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->pressed); @@ -536,6 +563,15 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_primary); return; } +#endif +#if LV_USE_TABVIEW + if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_tabview)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_panel); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_gray); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_panel); + return; + } #endif lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn); @@ -575,7 +611,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->no_radius); lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); - lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_white); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_panel); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->table_cell); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->pad_normal); } @@ -604,7 +640,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->circle); lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DISABLED, &styles->disabled); lv_obj_add_style(obj, LV_PART_KNOB, LV_STATE_DEFAULT, &styles->knob); - lv_obj_add_style(obj, LV_PART_KNOB, LV_STATE_DEFAULT, &styles->bg_color_white); + lv_obj_add_style(obj, LV_PART_KNOB, LV_STATE_DEFAULT, &styles->bg_color_panel); lv_obj_add_style(obj, LV_PART_KNOB, LV_STATE_DEFAULT, &styles->pad_small_negative); lv_obj_add_style(obj, LV_PART_KNOB, LV_STATE_DISABLED, &styles->disabled); } @@ -613,7 +649,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #if LV_USE_CHART else if(lv_obj_check_type(obj, &lv_chart)) { lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->line_dashed); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->chart_bg); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_small); lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); @@ -688,6 +724,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); lv_obj_add_style(obj, LV_PART_MARKER, LV_STATE_FOCUSED, &styles->ta_cursor); + lv_obj_add_style(obj, LV_PART_TEXTAREA_PLACEHOLDER, LV_STATE_DEFAULT, &styles->ta_placeholder); } #endif @@ -706,7 +743,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->scr); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_small); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn); - lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_white); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_panel); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_gray); } @@ -732,6 +769,17 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->bg_color_gray); } #endif +#if LV_USE_TILEVIEW + else if(lv_obj_check_type(obj, &lv_tileview)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->scr); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); + } + else if(lv_obj_check_type(obj, &lv_tileview_tile)) { + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); + } +#endif } /********************** diff --git a/src/extra/widgets/calendar/lv_calendar.c b/src/extra/widgets/calendar/lv_calendar.c index 025d97ec8..e6be7738e 100644 --- a/src/extra/widgets/calendar/lv_calendar.c +++ b/src/extra/widgets/calendar/lv_calendar.c @@ -209,8 +209,6 @@ bool lv_calendar_get_pressed_date(const lv_obj_t * obj, lv_calendar_date_t * dat static void my_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_construct_base(obj, parent, copy); - lv_calendar_t * calendar = (lv_calendar_t *) obj; /*Initialize the allocated 'ext' */ diff --git a/src/extra/widgets/calendar/lv_calendar_header_arrow.c b/src/extra/widgets/calendar/lv_calendar_header_arrow.c index da49ea0d0..c044e8e3e 100644 --- a/src/extra/widgets/calendar/lv_calendar_header_arrow.c +++ b/src/extra/widgets/calendar/lv_calendar_header_arrow.c @@ -45,7 +45,7 @@ lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent, lv_obj_t * calenda const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar); lv_coord_t w = lv_obj_get_width(calendar); - lv_obj_set_size(header, w, LV_SIZE_AUTO); + lv_obj_set_size(header, w, LV_SIZE_CONTENT); lv_obj_set_layout(header, &lv_flex_center_row); lv_obj_t * mo_prev = lv_btn_create(header, NULL); diff --git a/src/extra/widgets/keyboard/lv_keyboard.c b/src/extra/widgets/keyboard/lv_keyboard.c index 3a517c1ec..81b93a3ef 100644 --- a/src/extra/widgets/keyboard/lv_keyboard.c +++ b/src/extra/widgets/keyboard/lv_keyboard.c @@ -319,8 +319,6 @@ void lv_keyboard_def_event_cb(lv_obj_t * obj, lv_event_t event) static void my_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_construct_base(obj, parent, copy); - lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_keyboard_t * keyboard = (lv_keyboard_t *) obj; diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index 91056d546..994846f27 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -56,7 +56,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b lv_coord_t w = lv_obj_get_width_fit(parent); if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF; - lv_obj_set_size(mbox, w, LV_SIZE_AUTO); + lv_obj_set_size(mbox, w, LV_SIZE_CONTENT); lv_obj_set_layout(mbox, &lv_flex_inline); lv_obj_t * label; diff --git a/src/extra/widgets/spinbox/lv_spinbox.c b/src/extra/widgets/spinbox/lv_spinbox.c index 2654c239e..eba53fe06 100644 --- a/src/extra/widgets/spinbox/lv_spinbox.c +++ b/src/extra/widgets/spinbox/lv_spinbox.c @@ -269,8 +269,6 @@ static void lv_spinbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_o { LV_LOG_TRACE("spinbox create started"); - lv_obj_construct_base(obj, parent, copy); - lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; diff --git a/src/extra/widgets/tabview/lv_tabview.c b/src/extra/widgets/tabview/lv_tabview.c index 3b83c4607..9d82d3c1c 100644 --- a/src/extra/widgets/tabview/lv_tabview.c +++ b/src/extra/widgets/tabview/lv_tabview.c @@ -145,7 +145,6 @@ lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv) static void lv_tabview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_construct_base(obj, parent, copy); lv_tabview_t * tabview = (lv_tabview_t *) obj; // lv_flex_flow_t flex_dir; diff --git a/src/extra/widgets/tabview/lv_tabview.h b/src/extra/widgets/tabview/lv_tabview.h index f99d41cfb..7a3c3dec8 100644 --- a/src/extra/widgets/tabview/lv_tabview.h +++ b/src/extra/widgets/tabview/lv_tabview.h @@ -32,6 +32,8 @@ typedef struct uint16_t tab_cur; }lv_tabview_t; +extern const lv_obj_class_t lv_tabview; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/extra/widgets/tileview/lv_tileview.c b/src/extra/widgets/tileview/lv_tileview.c index b9838614c..165524da1 100644 --- a/src/extra/widgets/tileview/lv_tileview.c +++ b/src/extra/widgets/tileview/lv_tileview.c @@ -16,22 +16,29 @@ /********************** * TYPEDEFS **********************/ -typedef struct -{ - lv_dir_t dir; -}lv_tile_ext_t; /********************** * STATIC PROTOTYPES **********************/ +static void lv_tileview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); +static void lv_tileview_tile_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); static void tileview_event_cb(lv_obj_t * tv, lv_event_t e); /********************** * STATIC VARIABLES **********************/ -static bool inited; -static lv_style_t style_bg; -static lv_style_t style_tile; + +const lv_obj_class_t lv_tileview = {.constructor_cb = lv_tileview_constructor, + .base_class = &lv_obj, + .instance_size = sizeof(lv_tileview_t)}; + +const lv_obj_class_t lv_tileview_tile = {.constructor_cb = lv_tileview_tile_constructor, + .base_class = &lv_obj, + .instance_size = sizeof(lv_tileview_tile_t)}; + +static lv_dir_t create_dir; +static uint32_t create_col_id; +static uint32_t create_row_id; /********************** * MACROS @@ -49,26 +56,7 @@ static lv_style_t style_tile; */ lv_obj_t * lv_tileview_create(lv_obj_t * parent) { - if(!inited) { - lv_style_init(&style_bg); - lv_style_set_radius(&style_bg, LV_STATE_DEFAULT, 0); - lv_style_set_pad_all(&style_bg, LV_STATE_DEFAULT, 0); - - lv_style_init(&style_tile); - lv_style_set_radius(&style_tile, LV_STATE_DEFAULT, 0); - } - - lv_obj_t * tileview = lv_obj_create(parent, NULL); - LV_ASSERT_MEM(tileview); - if(tileview == NULL) return NULL; - - lv_obj_add_style(tileview, LV_OBJ_PART_MAIN, &style_bg); - lv_obj_set_size(tileview, LV_COORD_PCT(100), LV_COORD_PCT(100)); - lv_obj_set_event_cb(tileview, tileview_event_cb); - lv_obj_add_flag(tileview, LV_OBJ_FLAG_SCROLL_STOP); - lv_obj_set_snap_align_x(tileview, LV_SCROLL_SNAP_ALIGN_CENTER); - lv_obj_set_snap_align_y(tileview, LV_SCROLL_SNAP_ALIGN_CENTER); - return tileview; + return lv_obj_create_from_class(&lv_tileview, parent, NULL); } /*====================== @@ -77,29 +65,19 @@ lv_obj_t * lv_tileview_create(lv_obj_t * parent) lv_obj_t * lv_tileview_add_tile(lv_obj_t * tv, uint8_t col_id, uint8_t row_id, lv_dir_t dir) { - lv_obj_t * tile = lv_obj_create(tv, NULL); - lv_obj_set_size(tile, LV_COORD_PCT(100), LV_COORD_PCT(100)); - lv_obj_set_pos(tile, col_id * lv_obj_get_width_fit(tv), row_id * lv_obj_get_height_fit(tv)); - lv_obj_add_style(tile, LV_OBJ_PART_MAIN, &style_tile); - - lv_tile_ext_t * ext = lv_obj_allocate_ext_attr(tile, sizeof(lv_tile_ext_t)); - - ext->dir = dir; - - if(col_id == 0 && row_id == 0) { - lv_obj_set_scroll_dir(tv, dir); - } - - return tile; + create_dir = dir; + create_col_id = col_id; + create_row_id = row_id; + return lv_obj_create_from_class(&lv_tileview_tile, tv, NULL); } -void lv_obj_set_tile(lv_obj_t * tv, lv_obj_t * tile, lv_anim_enable_t anim_en) +void lv_obj_set_tile(lv_obj_t * tv, lv_obj_t * tile_obj, lv_anim_enable_t anim_en) { - lv_coord_t tx = lv_obj_get_x(tile); - lv_coord_t ty = lv_obj_get_y(tile); + lv_coord_t tx = lv_obj_get_x(tile_obj); + lv_coord_t ty = lv_obj_get_y(tile_obj); - lv_tile_ext_t * ext = lv_obj_get_ext_attr(tile); - lv_obj_set_scroll_dir(tv, ext->dir); + lv_tileview_tile_t * tile = (lv_tileview_tile_t *) tile_obj; + lv_obj_set_scroll_dir(tv, tile->dir); lv_obj_scroll_to(tv, tx, ty, anim_en); } @@ -111,26 +89,47 @@ void lv_obj_set_tile_id(lv_obj_t * tv, uint32_t col_id, uint32_t row_id, lv_anim lv_coord_t tx = col_id * w; lv_coord_t ty = row_id * h; - lv_dir_t dir = LV_DIR_ALL; - lv_obj_t * tile = lv_obj_get_child(tv, NULL); - while(tile) { - lv_coord_t x = lv_obj_get_x(tile); - lv_coord_t y = lv_obj_get_y(tile); + uint32_t i; + for(i = 0; i < lv_obj_get_child_cnt(tv); i++) { + lv_obj_t * tile_obj = lv_obj_get_child(tv, i); + lv_coord_t x = lv_obj_get_x(tile_obj); + lv_coord_t y = lv_obj_get_y(tile_obj); if(x == tx && y == ty) { - lv_tile_ext_t * ext = lv_obj_get_ext_attr(tile); - dir = ext->dir; - break; + lv_obj_set_tile(tv, tile_obj, anim_en); + return; } - tile = lv_obj_get_child(tv, tile); } - lv_obj_set_scroll_dir(tv, dir); - lv_obj_scroll_to(tv, tx, ty, anim_en); + + LV_LOG_WARN("No tile found with at (%d,%d) index", col_id, row_id); } /********************** * STATIC FUNCTIONS **********************/ +static void lv_tileview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) +{ + lv_obj_set_size(obj, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_add_event_cb(obj, tileview_event_cb, NULL); + lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ONE); + lv_obj_set_snap_align_x(obj, LV_SCROLL_SNAP_ALIGN_CENTER); + lv_obj_set_snap_align_y(obj, LV_SCROLL_SNAP_ALIGN_CENTER); + +} + +static void lv_tileview_tile_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) +{ + lv_obj_set_size(obj, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_pos(obj, create_col_id * lv_obj_get_width_fit(parent), create_row_id * lv_obj_get_height_fit(parent)); + + lv_tileview_tile_t * tile = (lv_tileview_tile_t *) obj; + tile->dir = create_dir; + + if(create_col_id == 0 && create_row_id == 0) { + lv_obj_set_scroll_dir(parent, create_dir); + } +} + static void tileview_event_cb(lv_obj_t * tv, lv_event_t e) { if(e == LV_EVENT_SCROLL_END) { @@ -147,18 +146,17 @@ static void tileview_event_cb(lv_obj_t * tv, lv_event_t e) lv_dir_t dir = LV_DIR_ALL; - lv_obj_t * tile = lv_obj_get_child(tv, NULL); - while(tile) { - lv_coord_t x = lv_obj_get_x(tile); - lv_coord_t y = lv_obj_get_y(tile); + uint32_t i; + for(i = 0; i < lv_obj_get_child_cnt(tv); i++) { + lv_obj_t * tile_obj = lv_obj_get_child(tv, i); + lv_coord_t x = lv_obj_get_x(tile_obj); + lv_coord_t y = lv_obj_get_y(tile_obj); if(x == tx && y == ty) { - lv_tile_ext_t * ext = lv_obj_get_ext_attr(tile); - dir = ext->dir; + lv_tileview_tile_t * tile = (lv_tileview_tile_t *) tile_obj; + dir = tile->dir; break; } - tile = lv_obj_get_child(tv, tile); } - lv_obj_set_scroll_dir(tv, dir); } } diff --git a/src/extra/widgets/tileview/lv_tileview.h b/src/extra/widgets/tileview/lv_tileview.h index 0a7c778ea..f46b1ba47 100644 --- a/src/extra/widgets/tileview/lv_tileview.h +++ b/src/extra/widgets/tileview/lv_tileview.h @@ -24,6 +24,17 @@ extern "C" { /********************** * TYPEDEFS **********************/ +typedef struct { + lv_obj_t obj; +}lv_tileview_t; + +typedef struct { + lv_obj_t obj; + lv_dir_t dir; +}lv_tileview_tile_t; + +extern const lv_obj_class_t lv_tileview; +extern const lv_obj_class_t lv_tileview_tile; /********************** * GLOBAL PROTOTYPES diff --git a/src/extra/widgets/win/lv_win.c b/src/extra/widgets/win/lv_win.c index b4bcbdca8..495a5e441 100644 --- a/src/extra/widgets/win/lv_win.c +++ b/src/extra/widgets/win/lv_win.c @@ -9,6 +9,7 @@ #include "lv_win.h" #if LV_USE_WIN + /********************* * DEFINES *********************/ @@ -20,12 +21,13 @@ /********************** * STATIC PROTOTYPES **********************/ +static void lv_win_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); /********************** * STATIC VARIABLES **********************/ -static bool inited = false; - +const lv_obj_class_t lv_win = {.constructor_cb = lv_win_constructor, .base_class = &lv_obj, .instance_size = sizeof(lv_win_t)}; +static lv_coord_t create_header_height; /********************** * MACROS **********************/ @@ -36,52 +38,26 @@ static bool inited = false; lv_obj_t * lv_win_create(lv_obj_t * parent, lv_coord_t header_height) { - static lv_style_t style_plain; - if(!inited) { - lv_style_init(&style_plain); - lv_style_set_radius(&style_plain, LV_STATE_DEFAULT, 0); - inited = true; - } - - lv_obj_t * win = lv_obj_create(parent, NULL); - lv_obj_set_size(win, lv_obj_get_width(parent), lv_obj_get_height(parent)); - lv_obj_set_flex_dir(win, LV_FLEX_DIR_COLUMN); - lv_obj_reset_style_list(win, LV_OBJ_PART_MAIN); - - lv_obj_t * header = lv_obj_create(win, NULL); - lv_obj_set_flex_item(header, true); - lv_obj_set_size(header, LV_COORD_PCT(100), header_height); - lv_obj_set_flex_dir(header, LV_FLEX_DIR_ROW); - lv_obj_set_flex_place(header, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER); -// lv_obj_set_flex_gap(header, LV_DPX(2)); - lv_obj_add_style(header, LV_OBJ_PART_MAIN, &style_plain); - - lv_obj_t * cont = lv_obj_create(win, NULL); - lv_obj_set_flex_item(cont, true); - lv_obj_set_size(cont, LV_COORD_PCT(100), LV_FLEX_GROW(1)); - lv_obj_add_style(cont, LV_OBJ_PART_MAIN, &style_plain); - - return win; + create_header_height = header_height; + return lv_obj_create_from_class(&lv_win, parent, NULL); } lv_obj_t * lv_win_add_title(lv_obj_t * win, const char * txt) { lv_obj_t * header = lv_win_get_header(win); lv_obj_t * title = lv_label_create(header, NULL); - lv_obj_set_flex_item(title, LV_FLEX_PLACE_CENTER); lv_label_set_long_mode(title, LV_LABEL_LONG_DOT); lv_label_set_text(title, txt); - lv_obj_set_width(title, LV_FLEX_GROW(1)); + lv_obj_set_flex_grow(title, 1); return title; } -lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w, lv_coord_t btn_h, lv_event_cb_t event_cb) +lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w, lv_event_cb_t event_cb) { lv_obj_t * header = lv_win_get_header(win); lv_obj_t * btn = lv_btn_create(header, NULL); - lv_obj_set_size(btn, btn_w, btn_h); - lv_obj_set_flex_item(btn, LV_FLEX_PLACE_CENTER); - lv_obj_set_event_cb(btn, event_cb); + lv_obj_set_size(btn, btn_w, LV_COORD_PCT(100)); + lv_obj_add_event_cb(btn, event_cb, NULL); lv_obj_t * img = lv_img_create(btn, NULL); lv_img_set_src(img, icon); @@ -92,16 +68,31 @@ lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w, l lv_obj_t * lv_win_get_header(lv_obj_t * win) { - return lv_obj_get_child_back(win, NULL); + return lv_obj_get_child(win, 0); } lv_obj_t * lv_win_get_content(lv_obj_t * win) { - return lv_obj_get_child(win, NULL); + return lv_obj_get_child(win, 1); } /********************** * STATIC FUNCTIONS **********************/ + +static void lv_win_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) +{ + lv_obj_set_size(obj, lv_obj_get_width(parent), lv_obj_get_height(parent)); + lv_obj_set_layout(obj, &lv_flex_stacked); + + lv_obj_t * header = lv_obj_create(obj, NULL); + lv_obj_set_size(header, LV_COORD_PCT(100), create_header_height); + lv_obj_set_layout(header, &lv_flex_inline); + + lv_obj_t * cont = lv_obj_create(obj, NULL); + lv_obj_set_flex_grow(cont, 1); + lv_obj_set_width(cont, LV_COORD_PCT(100)); +} + #endif diff --git a/src/extra/widgets/win/lv_win.h b/src/extra/widgets/win/lv_win.h index 8a0108338..82db11c8f 100644 --- a/src/extra/widgets/win/lv_win.h +++ b/src/extra/widgets/win/lv_win.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "../../../lv_core/lv_obj.h" +#include "../../../lvgl.h" /********************* * DEFINES @@ -22,6 +22,11 @@ extern "C" { /********************** * TYPEDEFS **********************/ +typedef struct { + lv_obj_t obj; +}lv_win_t; + +extern const lv_obj_class_t lv_win; /********************** * GLOBAL PROTOTYPES @@ -31,7 +36,7 @@ lv_obj_t * lv_win_create(lv_obj_t * parent, lv_coord_t header_height); lv_obj_t * lv_win_add_title(lv_obj_t * win, const char * txt); -lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w, lv_coord_t btn_h, lv_event_cb_t event_cb); +lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w, lv_event_cb_t event_cb); lv_obj_t * lv_win_get_header(lv_obj_t * win); lv_obj_t * lv_win_get_content(lv_obj_t * win); diff --git a/src/lv_core/lv_indev_scroll.c b/src/lv_core/lv_indev_scroll.c index 4f0a30b08..28614f3ae 100644 --- a/src/lv_core/lv_indev_scroll.c +++ b/src/lv_core/lv_indev_scroll.c @@ -82,9 +82,9 @@ void lv_indev_scroll_handler(lv_indev_proc_t * proc) } lv_dir_t scroll_dir = lv_obj_get_scroll_dir(scroll_obj); - if((scroll_dir & LV_DIR_LEFT) == 0 && diff_x > 0) diff_x = 0; - if((scroll_dir & LV_DIR_RIGHT) == 0 && diff_x < 0) diff_x = 0; - if((scroll_dir & LV_DIR_TOP) == 0 && diff_y > 0) diff_y = 0; + if((scroll_dir & LV_DIR_LEFT) == 0 && diff_x > 0) diff_x = 0; + if((scroll_dir & LV_DIR_RIGHT) == 0 && diff_x < 0) diff_x = 0; + if((scroll_dir & LV_DIR_TOP) == 0 && diff_y > 0) diff_y = 0; if((scroll_dir & LV_DIR_BOTTOM) == 0 && diff_y < 0) diff_y = 0; /*Respect the scroll limit area*/ @@ -552,7 +552,7 @@ static lv_coord_t elastic_diff(lv_obj_t * obj, lv_coord_t diff, lv_coord_t scrol if(lv_obj_has_flag(obj, LV_OBJ_FLAG_SCROLL_ELASTIC)) { /*Elastic scroll if scrolled in*/ if(scroll_end < 0) diff = (diff + ELASTIC_SLOWNESS_FACTOR / 2) / ELASTIC_SLOWNESS_FACTOR; - else if(scroll_start < 0) diff = (diff + ELASTIC_SLOWNESS_FACTOR / 2) / ELASTIC_SLOWNESS_FACTOR; + else if(scroll_start < 0) diff = (diff - ELASTIC_SLOWNESS_FACTOR / 2) / ELASTIC_SLOWNESS_FACTOR; } else { /*Scroll back to the boundary id required*/ if(scroll_end + diff < 0) diff = - scroll_end; diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 2847ad361..26de1da74 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -552,6 +552,7 @@ lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj) bool lv_obj_check_type(const lv_obj_t * obj, const void * class_p) { + if(obj == NULL) return false; return obj->class_p == class_p ? true : false; } @@ -1074,7 +1075,7 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) else if(sign == LV_SIGNAL_CHILD_CHG) { lv_obj_update_layout(obj, param); - if(obj->w_set == LV_SIZE_AUTO || obj->h_set == LV_SIZE_AUTO) { + if(obj->w_set == LV_SIZE_CONTENT || obj->h_set == LV_SIZE_CONTENT) { lv_obj_set_size(obj, obj->w_set, obj->h_set); } } @@ -1110,7 +1111,7 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) } } - if(obj->w_set == LV_SIZE_AUTO || obj->h_set == LV_SIZE_AUTO) { + 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_refresh_ext_draw_size(obj); diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 1c728e374..8700f94ea 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -168,7 +168,6 @@ enum { LV_PART_INDICATOR, /**< Indicator, e.g. for slider, bar, switch, */ LV_PART_KNOB, /**< Like handle to grab to adjust the value */ LV_PART_SELECTED, /**< Indicate the currently selected option or section*/ - LV_PART_PLACEHOLDER, /**< A text other element used when the widget is empty*/ LV_PART_ITEMS, /**< Used if the widget has multiple similar elements (e.g. tabel cells)*/ LV_PART_MARKER, /**< Tick box of a check box, cursor of a text area or anything used to mark something*/ @@ -194,16 +193,16 @@ enum { LV_OBJ_FLAG_SCROLLABLE = (1 << 4), /**< Make the object scrollable*/ LV_OBJ_FLAG_SCROLL_ELASTIC = (1 << 5), /**< Allow scrolling inside but with slower speed*/ LV_OBJ_FLAG_SCROLL_MOMENTUM = (1 << 6), /**< Make the object scroll further when "thrown"*/ - LV_OBJ_FLAG_SCROLL_ONE = (1 << 7), /**< Allow scrolling only one snappable children*/ + LV_OBJ_FLAG_SCROLL_ONE = (1 << 7), /**< Allow scrolling only one snapable children*/ LV_OBJ_FLAG_SCROLL_CHAIN = (1 << 8), /**< Allow propagating the scroll to a parent */ LV_OBJ_FLAG_SCROLL_ON_FOCUS = (1 << 9), /**< Automatically scroll object to make it visible when focused*/ - LV_OBJ_FLAG_SNAPABLE = (1 << 10), /**< If scroll snap is enabled it can snap to this object*/ + LV_OBJ_FLAG_SNAPABLE = (1 << 10), /**< If scroll snap is enabled on the parent it can snap to this object*/ LV_OBJ_FLAG_PRESS_LOCK = (1 << 11), /**< Keep the object pressed even if the press slid from the object */ LV_OBJ_FLAG_EVENT_BUBBLE = (1 << 12), /**< Propagate the events to the parent too */ LV_OBJ_FLAG_GESTURE_BUBBLE = (1 << 13), /**< Propagate the gestures to the parent */ LV_OBJ_FLAG_FOCUS_BUBBLE = (1 << 14), /**< Propagate the focus to the parent */ - LV_OBJ_FLAG_ADV_HITTEST = (1 << 15), /**< Allow performing more accurate hit (click) test. E.g. on rounded corners. */ - LV_OBJ_FLAG_LAYOUTABLE = (1 << 16), /**< MAke the object position-able by the layouts */ + LV_OBJ_FLAG_ADV_HITTEST = (1 << 15), /**< Allow performing more accurate hit (click) test. E.g. consider rounded corners. */ + LV_OBJ_FLAG_LAYOUTABLE = (1 << 16), /**< Make the object position-able by the layouts */ LV_OBJ_FLAG_LAYOUT_1 = (1 << 24), /** Custom flag, free to use by layouts*/ LV_OBJ_FLAG_LAYOUT_2 = (1 << 25), /** Custom flag, free to use by layouts*/ diff --git a/src/lv_core/lv_obj_class.c b/src/lv_core/lv_obj_class.c index 662cc3058..295afbb15 100644 --- a/src/lv_core/lv_obj_class.c +++ b/src/lv_core/lv_obj_class.c @@ -24,6 +24,7 @@ /********************** * STATIC PROTOTYPES **********************/ +static void lv_obj_construct(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); static uint32_t get_instance_size(const lv_obj_class_t * class_p); /********************** @@ -49,27 +50,14 @@ lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class_p, lv_obj_t * p while(class_start && class_start->constructor_cb == NULL) class_start = class_start->base_class; - class_start->constructor_cb(obj, parent, copy); - +// class_start->constructor_cb(obj, parent, copy); + lv_obj_construct(obj, parent, copy); if(!copy) lv_theme_apply(obj); // else lv_style_list_copy(&checkbox->style_indic, &checkbox_copy->style_indic); return obj; } -void lv_obj_construct_base(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) -{ - const lv_obj_class_t * original_class_p = obj->class_p; - - /*Don't let the descendant methods run during constructing the ancestor type*/ - obj->class_p = obj->class_p->base_class; - - obj->class_p->constructor_cb(obj, parent, copy); - - /*Restore the original class*/ - obj->class_p = original_class_p; - -} lv_res_t lv_obj_signal_base(const lv_obj_class_t * class_p, struct _lv_obj_t * obj, lv_signal_t sign, void * param) { @@ -116,6 +104,25 @@ bool lv_obj_is_editable(struct _lv_obj_t * obj) * STATIC FUNCTIONS **********************/ +static void lv_obj_construct(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) +{ + const lv_obj_class_t * original_class_p = obj->class_p; + + if(obj->class_p->base_class) { + /*Don't let the descendant methods run during constructing the ancestor type*/ + obj->class_p = obj->class_p->base_class; + + /*Construct the base first*/ + lv_obj_construct(obj, parent, copy); + } + + /*Restore the original class*/ + obj->class_p = original_class_p; + + if(obj->class_p->constructor_cb) obj->class_p->constructor_cb(obj, parent, copy); + + +} static uint32_t get_instance_size(const lv_obj_class_t * class_p) { /*Find a base in which instance size is set*/ diff --git a/src/lv_core/lv_obj_class.h b/src/lv_core/lv_obj_class.h index ffef375a7..dd3d8d7b5 100644 --- a/src/lv_core/lv_obj_class.h +++ b/src/lv_core/lv_obj_class.h @@ -60,15 +60,6 @@ typedef struct _lv_obj_class_t{ */ struct _lv_obj_t * lv_obj_create_from_class(const struct _lv_obj_class_t * class_p, struct _lv_obj_t * parent, const struct _lv_obj_t * copy); -/** - * Used internally in widget's constructor to construct the base type - * @param obj pointer to the object being constructed - * @param parent pointer to the parent - * @param copy pointer to the object to copy (DEPRECATED will be removed in v9) - */ -void lv_obj_construct_base(struct _lv_obj_t * obj, struct _lv_obj_t * parent, const struct _lv_obj_t * copy); - - lv_res_t lv_obj_signal_base(const lv_obj_class_t * class_p, struct _lv_obj_t * obj, lv_signal_t sign, void * param); lv_draw_res_t lv_obj_draw_base(const lv_obj_class_t * class_p, struct _lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode); diff --git a/src/lv_core/lv_obj_pos.c b/src/lv_core/lv_obj_pos.c index dbebe870a..290afcfc0 100644 --- a/src/lv_core/lv_obj_pos.c +++ b/src/lv_core/lv_obj_pos.c @@ -38,12 +38,6 @@ void lv_obj_move_children_by(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_dif * GLOBAL FUNCTIONS **********************/ -/** - * Set the relative the position of an object (relative to the parent's top left corner) - * @param obj: pointer to an object - * @param x: new distance from the left side of the parent plus the parent's left padding - * @param y: new distance from the top side of the parent plus the parent's right padding - */ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -59,11 +53,6 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) lv_obj_move_to(obj, x, y, true); } -/** - * Set the x coordinate of a object - * @param obj: pointer to an object - * @param x: new distance from the left side from the parent plus the parent's left padding - */ void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -71,11 +60,6 @@ void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x) lv_obj_set_pos(obj, x, obj->y_set); } -/** - * Set the y coordinate of a object - * @param obj: pointer to an object - * @param y: new distance from the top of the parent plus the parent's top padding - */ void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -83,12 +67,6 @@ void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y) lv_obj_set_pos(obj, obj->x_set, y); } -/** - * Set the size of an object. - * @param obj: pointer to an object - * @param w: new width in pixels or `LV_SIZE_AUTO` to set the size to involve all children - * @param h: new height in pixels or `LV_SIZE_AUTO` to set the size to involve all children - */ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -107,16 +85,16 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) if(LV_COORD_IS_LAYOUT(h)) h = lv_obj_get_height(obj); /*Calculate the required auto sizes*/ - bool x_auto = obj->w_set == LV_SIZE_AUTO ? true : false; - bool y_auto = obj->h_set == LV_SIZE_AUTO ? true : false; + bool w_content = obj->w_set == LV_SIZE_CONTENT ? true : false; + bool h_content = obj->h_set == LV_SIZE_CONTENT ? true : false; /*Be sure the object is not scrolled when it has auto size*/ - if(x_auto) lv_obj_scroll_to_x(obj, 0, LV_ANIM_OFF); - if(y_auto) lv_obj_scroll_to_y(obj, 0, LV_ANIM_OFF); + if(w_content) lv_obj_scroll_to_x(obj, 0, LV_ANIM_OFF); + if(h_content) lv_obj_scroll_to_y(obj, 0, LV_ANIM_OFF); - if(x_auto && y_auto) calc_auto_size(obj, &w, &h); - else if(x_auto) calc_auto_size(obj, &w, NULL); - else if(y_auto) calc_auto_size(obj, NULL, &h); + if(w_content && h_content) calc_auto_size(obj, &w, &h); + else if(w_content) calc_auto_size(obj, &w, NULL); + 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; @@ -133,11 +111,6 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) refr_size(obj, w, h); } -/** - * Set the width of an object - * @param obj: pointer to an object - * @param w: new width in pixels or `LV_SIZE_AUTO` to set the size to involve all children - */ void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -145,11 +118,6 @@ void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w) lv_obj_set_size(obj, w, obj->h_set); } -/** - * Set the height of an object - * @param obj: pointer to an object - * @param h: new height in pixels or `LV_SIZE_AUTO` to set the size to involve all children - */ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -157,11 +125,6 @@ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h) lv_obj_set_size(obj, obj->w_set, h); } -/** - * Set the width reduced by the left and right padding. - * @param obj: pointer to an object - * @param w: the width without paddings in pixels - */ void lv_obj_set_content_width(lv_obj_t * obj, lv_coord_t w) { lv_coord_t pleft = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); @@ -170,11 +133,6 @@ void lv_obj_set_content_width(lv_obj_t * obj, lv_coord_t w) lv_obj_set_width(obj, w + pleft + pright); } -/** - * Set the height reduced by the top and bottom padding. - * @param obj: pointer to an object - * @param h: the height without paddings in pixels - */ void lv_obj_set_content_height(lv_obj_t * obj, lv_coord_t h) { lv_coord_t ptop = lv_obj_get_style_pad_top(obj, LV_PART_MAIN); @@ -183,11 +141,6 @@ void lv_obj_set_content_height(lv_obj_t * obj, lv_coord_t h) lv_obj_set_height(obj, h + ptop + pbottom); } -/** - * Set a layout for an object - * @param obj: pointer to an object - * @param layout: pointer to a layout descriptor to set - */ void lv_obj_set_layout(lv_obj_t * obj, const void * layout) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -198,11 +151,6 @@ void lv_obj_set_layout(lv_obj_t * obj, const void * layout) lv_obj_update_layout(obj, NULL); } -/** - * Test whether the and object is positioned by a layout or not - * @param obj: pointer to an object to test - * @return true: positioned by a layout; false: not positioned by a layout - */ bool lv_obj_is_layout_positioned(const lv_obj_t * obj) { if(lv_obj_has_flag(obj, LV_OBJ_FLAG_LAYOUTABLE) == false) return false; @@ -213,32 +161,17 @@ bool lv_obj_is_layout_positioned(const lv_obj_t * obj) else return false; } -/** - * Update the layout of an object. - * @param cont: pointer to an object whose children needs to be updated - * @param item: pointer to a child object that triggered the update. Set to `NULL` is not known. - * If not `NULL` the update process should make some optimization - * to update only the required parts of the layout - */ -void lv_obj_update_layout(lv_obj_t * cont, lv_obj_t * item) +void lv_obj_update_layout(lv_obj_t * obj, lv_obj_t * item) { - if(cont->spec_attr == NULL) return; - if(cont->spec_attr->layout_dsc == NULL) return; - if(cont->spec_attr->child_cnt == 0) return; + if(obj->spec_attr == NULL) return; + if(obj->spec_attr->layout_dsc == NULL) return; + if(obj->spec_attr->child_cnt == 0) return; - const lv_layout_dsc_t * layout = cont->spec_attr->layout_dsc; + const lv_layout_dsc_t * layout = obj->spec_attr->layout_dsc; if(layout->update_cb == NULL) return; - layout->update_cb(cont, item); + layout->update_cb(obj, item); } -/** - * Align an object to an other object. - * @param obj: pointer to an object to align - * @param base: pointer to an other object (if NULL `obj`s parent is used). 'obj' will be aligned to it. - * @param align: type of alignment (see 'lv_align_t' enum) - * @param x_ofs: x coordinate offset after alignment - * @param y_ofs: y coordinate offset after alignment - */ 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); @@ -362,12 +295,6 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co lv_obj_set_pos(obj, x, y); } - -/** - * Copy the coordinates of an object to an area - * @param obj: pointer to an object - * @param coords: pointer to an area to store the coordinates - */ void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * coords) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -375,14 +302,6 @@ void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * coords) lv_area_copy(coords, &obj->coords); } -/** - * Get the x coordinate of object. - * @param obj: pointer to an object - * @return distance of `obj` from the left side of its parent plus the parent's left padding - * @note Zero return value means the object is on the left padding of the parent, and not on the left 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_x(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -400,14 +319,6 @@ lv_coord_t lv_obj_get_x(const lv_obj_t * obj) return rel_x; } -/** - * Get the y coordinate of object. - * @param obj: pointer to an object - * @return distance of `obj` from the top side of its parent plus the parent's top padding - * @note Zero return value means the object is on the top padding of the parent, and not on the top 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_y(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -425,11 +336,6 @@ lv_coord_t lv_obj_get_y(const lv_obj_t * obj) return rel_y; } -/** - * Get the width of an object - * @param obj pointer to an object - * @return the width in pixels - */ lv_coord_t lv_obj_get_width(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -437,11 +343,6 @@ lv_coord_t lv_obj_get_width(const lv_obj_t * obj) return lv_area_get_width(&obj->coords); } -/** - * Get the height of an object - * @param obj pointer to an object - * @return the height in pixels - */ lv_coord_t lv_obj_get_height(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -449,11 +350,6 @@ lv_coord_t lv_obj_get_height(const lv_obj_t * obj) return lv_area_get_height(&obj->coords); } -/** - * Get that width reduced by the left and right padding. - * @param obj: pointer to an object - * @return the width which still fits into the container without causing overflow (making the object scrollable) - */ lv_coord_t lv_obj_get_width_fit(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -464,11 +360,6 @@ lv_coord_t lv_obj_get_width_fit(const lv_obj_t * obj) return lv_obj_get_width(obj) - left - right; } -/** - * Get that height reduced by the top an bottom padding. - * @param obj: pointer to an object - * @return the height which still fits into the container without causing overflow (making the object scrollable) - */ lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -479,13 +370,6 @@ lv_coord_t lv_obj_get_height_fit(const lv_obj_t * obj) return lv_obj_get_height(obj) - top - bottom; } -/** - * Get the width occupied by the "parts" of the widget. E.g. the width of all columns of a table. - * @param obj: pointer to an objects - * @return the width of the virtually drawn content - * @note This size independent from the real size of the widget. - * It just tells how large the internal ("virtual") content is. - */ lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj) { lv_point_t p = {0, LV_COORD_MIN}; @@ -493,13 +377,6 @@ lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj) return p.x; } -/** - * Get the height occupied by the "parts" of the widget. E.g. the height of all rows of a table. - * @param obj: pointer to an objects - * @return the width of the virtually drawn content - * @note This size independent from the real size of the widget. - * It just tells how large the internal ("virtual") content is. - */ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj) { lv_point_t p = {LV_COORD_MIN, 0}; @@ -507,27 +384,14 @@ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj) return p.y; } -/** - * Handle if the size of the internal ("virtual") content of an object has changed. - * @param obj: pointer to an object - * @return false: nothing happened; true: refresh happened - */ bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj) { - if(obj->w_set != LV_SIZE_AUTO && obj->h_set == LV_SIZE_AUTO) return false; + if(obj->w_set != LV_SIZE_CONTENT && obj->h_set == LV_SIZE_CONTENT) return false; lv_obj_set_size(obj, obj->w_set, obj->h_set); return true; } -/** - * Move an object to a given x and y coordinate. - * It's the core function to move objects. User should use `lv_obj_set_pos/x/y/..` etc. - * @param obj: pointer to an object to move - * @param x: the new x coordinate in pixels - * @param y: the new y coordinate in pixels - * @param notify: true: send `LV_SIGNAL_CHILD_CHG` to the parent if `obj` moved; false: do not notify the parent - */ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify) { /*Convert x and y to absolute coordinates*/ @@ -575,14 +439,6 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify) lv_obj_invalidate(obj); } - -/** - * Reposition the children of an object. (Called recursively) - * It's a low level function and shouldn't be used by the user directly. - * @param obj: pointer to an object which children will be repositioned - * @param x_diff: x coordinate shift - * @param y_diff: y coordinate shift - */ void lv_obj_move_children_by(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff) { uint32_t i; diff --git a/src/lv_core/lv_obj_pos.h b/src/lv_core/lv_obj_pos.h index d1578dd56..0474d2243 100644 --- a/src/lv_core/lv_obj_pos.h +++ b/src/lv_core/lv_obj_pos.h @@ -41,188 +41,188 @@ typedef struct { /** * Set the relative the position of an object (relative to the parent's top left corner) - * @param obj: pointer to an object - * @param x: new distance from the left side of the parent plus the parent's left padding - * @param y: new distance from the top side of the parent plus the parent's right padding + * @param obj pointer to an object + * @param x new distance from the left side of the parent plus the parent's left padding + * @param y new distance from the top side of the parent plus the parent's right padding */ void lv_obj_set_pos(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); /** * Set the x coordinate of a object - * @param obj: pointer to an object - * @param x: new distance from the left side from the parent plus the parent's left padding + * @param obj pointer to an object + * @param x new distance from the left side from the parent plus the parent's left padding */ void lv_obj_set_x(struct _lv_obj_t * obj, lv_coord_t x); /** * Set the y coordinate of a object - * @param obj: pointer to an object - * @param y: new distance from the top of the parent plus the parent's top padding + * @param obj pointer to an object + * @param y new distance from the top of the parent plus the parent's top padding */ void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y); /** * Set the size of an object. - * @param obj: pointer to an object - * @param w: the new width - * @param h: the new height - * @note possible values are: - * pixel: simple set the size accordingly - * LV_SIZE_AUTO: to set the size to involve all children in the given direction - * LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings). - * x should be [0..1000] range + * @param obj pointer to an object + * @param w the new width + * @param h the new height + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * LV_COORD_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range */ void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); /** * Set the width of an object - * @param obj: pointer to an object - * @param w: the new width - * @note possible values are: - * pixel: simple set the size accordingly - * LV_SIZE_AUTO: to set the size to involve all children in the given direction - * LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings). - * x should be [0..1000] range + * @param obj pointer to an object + * @param w the new width + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * LV_COORD_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range */ void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); /** * Set the height of an object - * @param obj: pointer to an object - * @param h: the new height - * @note possible values are: - * pixel: simple set the size accordingly - * LV_SIZE_AUTO: to set the size to involve all children in the given direction - * LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings). - * x should be [0..1000] range + * @param obj pointer to an object + * @param h the new height + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * LV_COORD_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range */ void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h); /** * Set the width reduced by the left and right padding. - * @param obj: pointer to an object - * @param w: the width without paddings in pixels + * @param obj pointer to an object + * @param w the width without paddings in pixels */ void lv_obj_set_content_width(struct _lv_obj_t * obj, lv_coord_t w); /** * Set the height reduced by the top and bottom padding. - * @param obj: pointer to an object - * @param h: the height without paddings in pixels + * @param obj pointer to an object + * @param h the height without paddings in pixels */ void lv_obj_set_content_height(struct _lv_obj_t * obj, lv_coord_t h); /** * Set a layout for an object - * @param obj: pointer to an object - * @param layout: pointer to a layout descriptor to set + * @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); /** * Test whether the and object is positioned by a layout or not - * @param obj: pointer to an object to test - * @return true: positioned by a layout; false: not positioned by a layout + * @param obj pointer to an object to test + * @return true: positioned by a layout; false: not positioned by a layout */ bool lv_obj_is_layout_positioned(const struct _lv_obj_t * obj); /** * Update the layout of an object. - * @param cont: pointer to an object whose children needs to be updated - * @param item: pointer to a child object that triggered the update. Set to `NULL` is not known. - * If not `NULL` the update process should make some optimization - * to update only the required parts of the layout + * @param obj pointer to an object whose children needs to be updated + * @param item pointer to a child object that triggered the update. Set to `NULL` is not known. + * If not `NULL` the update process can make some optimization + * to update only the required parts of the layout */ -void lv_obj_update_layout(struct _lv_obj_t * cont, struct _lv_obj_t * item); +void lv_obj_update_layout(struct _lv_obj_t * obj, struct _lv_obj_t * item); /** * Align an object to an other object. - * @param obj: pointer to an object to align - * @param base: pointer to an other object (if NULL `obj`s parent is used). 'obj' will be aligned to it. - * @param align: type of alignment (see 'lv_align_t' enum) - * @param x_ofs: x coordinate offset after alignment - * @param y_ofs: y coordinate offset after alignment + * @param obj pointer to an object to align + * @param base pointer to an other object (if NULL `obj`s parent is used). 'obj' will be aligned to it. + * @param align type of alignment (see 'lv_align_t' enum) + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment */ void lv_obj_align(struct _lv_obj_t * obj, const struct _lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); /** * Copy the coordinates of an object to an area - * @param obj: pointer to an object - * @param coords: pointer to an area to store the coordinates + * @param obj pointer to an object + * @param coords pointer to an area to store the coordinates */ void lv_obj_get_coords(const struct _lv_obj_t * obj, lv_area_t * coords); /** * Get the x coordinate of object. - * @param obj: pointer to an object - * @return distance of `obj` from the left side of its parent plus the parent's left padding - * @note Zero return value means the object is on the left padding of the parent, and not on the left 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. + * @param obj pointer to an object + * @return distance of `obj` from the left side of its parent plus the parent's left padding + * @note Zero return value means the object is on the left padding of the parent, and not on the left 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_x(const struct _lv_obj_t * obj); /** * Get the y coordinate of object. - * @param obj: pointer to an object - * @return distance of `obj` from the top side of its parent plus the parent's top padding - * @note Zero return value means the object is on the top padding of the parent, and not on the top 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. + * @param obj pointer to an object + * @return distance of `obj` from the top side of its parent plus the parent's top padding + * @note Zero return value means the object is on the top padding of the parent, and not on the top 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_y(const struct _lv_obj_t * obj); /** * Get the width of an object - * @param obj pointer to an object - * @return the width in pixels + * @param obj pointer to an object + * @return the width in pixels */ lv_coord_t lv_obj_get_width(const struct _lv_obj_t * obj); /** * Get the height of an object - * @param obj pointer to an object - * @return the height in pixels + * @param obj pointer to an object + * @return the height in pixels */ lv_coord_t lv_obj_get_height(const struct _lv_obj_t * obj); /** * Get that width reduced by the left and right padding. - * @param obj: pointer to an object - * @return the width which still fits into the container without causing overflow (making the object scrollable) + * @param obj pointer to an object + * @return the width which still fits into the container without causing overflow (making the object scrollable) */ lv_coord_t lv_obj_get_width_fit(const struct _lv_obj_t * obj); /** * Get that height reduced by the top an bottom padding. - * @param obj: pointer to an object - * @return the height which still fits into the container without causing overflow (making the object scrollable) + * @param obj pointer to an object + * @return the height which still fits into the container without causing overflow (making the object scrollable) */ lv_coord_t lv_obj_get_height_fit(const struct _lv_obj_t * obj); /** * Get the width occupied by the "parts" of the widget. E.g. the width of all columns of a table. - * @param obj: pointer to an objects - * @return the width of the virtually drawn content - * @note This size independent from the real size of the widget. - * It just tells how large the internal ("virtual") content is. + * @param obj pointer to an objects + * @return the width of the virtually drawn content + * @note This size independent from the real size of the widget. + * It just tells how large the internal ("virtual") content is. */ lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj); /** * Get the height occupied by the "parts" of the widget. E.g. the height of all rows of a table. - * @param obj: pointer to an objects - * @return the width of the virtually drawn content - * @note This size independent from the real size of the widget. - * It just tells how large the internal ("virtual") content is. + * @param obj pointer to an objects + * @return the width of the virtually drawn content + * @note This size independent from the real size of the widget. + * It just tells how large the internal ("virtual") content is. */ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj); /** * Handle if the size of the internal ("virtual") content of an object has changed. - * @param obj: pointer to an object - * @return false: nothing happened; true: refresh happened + * @param obj pointer to an object + * @return false: nothing happened; true: refresh happened */ bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj); @@ -230,52 +230,52 @@ bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj); /** * Mark an area of an object as invalid. * The area will be truncated to the object's area and marked for redraw. - * @param obj: pointer to an object - * @param area: the area to redraw + * @param obj pointer to an object + * @param area the area to redraw */ void lv_obj_invalidate_area(const struct _lv_obj_t * obj, const lv_area_t * area); /** * Mark the object as invalid to redrawn its area - * @param obj: pointer to an object + * @param obj pointer to an object */ void lv_obj_invalidate(const struct _lv_obj_t * obj); /** * Tell whether an area of an object is visible (even partially) now or not - * @param obj: pointer to an object - * @param area: the are to check. The visible part of the area will be written back here. - * @return true: visible; false: not visible (hidden, out of parent, on other screen, etc) + * @param obj pointer to an object + * @param area the are to check. The visible part of the area will be written back here. + * @return true visible; false not visible (hidden, out of parent, on other screen, etc) */ bool lv_obj_area_is_visible(const struct _lv_obj_t * obj, lv_area_t * area); /** * Tell whether an object is visible (even partially) now or not - * @param obj pointer to an object - * @return true: visible; false: not visible (hidden, out of parent, on other screen, etc) + * @param obj pointer to an object + * @return true: visible; false not visible (hidden, out of parent, on other screen, etc) */ bool lv_obj_is_visible(const struct _lv_obj_t * obj); /** * Set the size of an extended clickable area - * @param obj pointer to an object - * @param size extended clickable area in all 4 directions [px] + * @param obj pointer to an object + * @param size extended clickable area in all 4 directions [px] */ void lv_obj_set_ext_click_area(struct _lv_obj_t * obj, lv_coord_t size); /** * Get the an area where to object can be clicked. * It's the object's normal area plus the extended click area. - * @param obj: pointer to an object - * @param area: store the result area here + * @param obj pointer to an object + * @param area store the result area here */ void lv_obj_get_click_area(const struct _lv_obj_t * obj, lv_area_t * area); /** * Hit-test an object given a particular point in screen space. - * @param obj object to hit-test - * @param point screen-space point (absolute coordinate) - * @return true: if the object is considered under the point + * @param obj object to hit-test + * @param point screen-space point (absolute coordinate) + * @return true: if the object is considered under the point */ bool lv_obj_hit_test(struct _lv_obj_t * obj, const lv_point_t * point); diff --git a/src/lv_core/lv_obj_scroll.c b/src/lv_core/lv_obj_scroll.c index 7f2c4d0f2..93d64d080 100644 --- a/src/lv_core/lv_obj_scroll.c +++ b/src/lv_core/lv_obj_scroll.c @@ -30,6 +30,7 @@ void lv_obj_move_children_by(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_dif **********************/ static void scroll_anim_x_cb(lv_obj_t * obj, lv_anim_value_t v); static void scroll_anim_y_cb(lv_obj_t * obj, lv_anim_value_t v); +static void scroll_anim_ready_cb(lv_anim_t * a); /********************** * STATIC VARIABLES @@ -252,12 +253,20 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, obj); + lv_anim_set_ready_cb(&a, scroll_anim_ready_cb); lv_anim_path_t path; lv_anim_path_init(&path); lv_anim_path_set_cb(&path, lv_anim_path_ease_out); if(x) { + lv_res_t res; + res = lv_signal_send(obj, LV_SIGNAL_SCROLL_BEGIN, NULL); + if(res != LV_RES_OK) return; + + res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, NULL); + if(res != LV_RES_OK) return; + uint32_t t = lv_anim_speed_to_time((lv_disp_get_hor_res(d) * 2) >> 2, 0, x); if(t < SCROLL_ANIM_TIME_MIN) t = SCROLL_ANIM_TIME_MIN; if(t > SCROLL_ANIM_TIME_MAX) t = SCROLL_ANIM_TIME_MAX; @@ -270,6 +279,13 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable } if(y) { + lv_res_t res; + res = lv_signal_send(obj, LV_SIGNAL_SCROLL_BEGIN, NULL); + if(res != LV_RES_OK) return; + + res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, NULL); + if(res != LV_RES_OK) return; + uint32_t t = lv_anim_speed_to_time((lv_disp_get_ver_res(d) * 2) >> 2, 0, y); if(t < SCROLL_ANIM_TIME_MIN) t = SCROLL_ANIM_TIME_MIN; if(t > SCROLL_ANIM_TIME_MAX) t = SCROLL_ANIM_TIME_MAX; @@ -356,6 +372,15 @@ void lv_obj_scroll_to_view(lv_obj_t * obj, lv_anim_enable_t anim_en) lv_obj_scroll_by(parent, x_scroll, y_scroll, anim_en); } +void lv_obj_scroll_to_view_recursive(lv_obj_t * obj, lv_anim_enable_t anim_en) +{ + lv_obj_t * parent = lv_obj_get_parent(obj); + while(parent) { + lv_obj_scroll_to_view(obj, LV_ANIM_ON); + obj = parent; + parent = lv_obj_get_parent(parent); + } +} /********************** * STATIC FUNCTIONS @@ -370,3 +395,11 @@ static void scroll_anim_y_cb(lv_obj_t * obj, lv_anim_value_t v) { _lv_obj_scroll_by_raw(obj, 0, v + lv_obj_get_scroll_y(obj)); } + +static void scroll_anim_ready_cb(lv_anim_t * a) +{ + lv_res_t res = lv_signal_send(a->var, LV_SIGNAL_SCROLL_END, NULL); + if(res != LV_RES_OK) return; + + lv_event_send(a->var, LV_EVENT_SCROLL_END, NULL); +} diff --git a/src/lv_core/lv_obj_scroll.h b/src/lv_core/lv_obj_scroll.h index 6349c2605..b44e13a21 100644 --- a/src/lv_core/lv_obj_scroll.h +++ b/src/lv_core/lv_obj_scroll.h @@ -37,7 +37,7 @@ enum { typedef uint8_t lv_scrollbar_mode_t; -/** Scroll span align options. Tells where to align the object when it's snapped. */ +/** Scroll span align options. Tells where to align the snapable children when scroll stops. */ enum { LV_SCROLL_SNAP_ALIGN_NONE, /**< Do not align, leave where it is */ LV_SCROLL_SNAP_ALIGN_START, /**< Align to to the left/top */ @@ -56,29 +56,29 @@ typedef uint8_t lv_snap_align_t; /** * Set how the scrollbars should behave. - * @param obj pointer to an object - * @param mode: LV_SCROLL_MODE_ON/OFF/AUTO/ACTIVE + * @param obj pointer to an object + * @param mode LV_SCROLL_MODE_ON/OFF/AUTO/ACTIVE */ void lv_obj_set_scrollbar_mode(struct _lv_obj_t * obj, lv_scrollbar_mode_t mode); /** * Set the object in which directions can be scrolled - * @param obj pointer to an object - * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` + * @param obj pointer to an object + * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` */ void lv_obj_set_scroll_dir(struct _lv_obj_t * obj, lv_dir_t dir); /** * Set where to snap the children when scrolling ends horizontally - * @param obj pointer to an object - * @param align the snap align to set from `lv_snap_align_t` + * @param obj pointer to an object + * @param align the snap align to set from `lv_snap_align_t` */ void lv_obj_set_snap_align_x(struct _lv_obj_t * obj, lv_snap_align_t align); /** * Set where to snap the children when scrolling ends vertically - * @param obj pointer to an object - * @param align the snap align to set from `lv_snap_align_t` + * @param obj pointer to an object + * @param align the snap align to set from `lv_snap_align_t` */ void lv_obj_set_snap_align_y(struct _lv_obj_t * obj, lv_snap_align_t align); @@ -88,49 +88,49 @@ void lv_obj_set_snap_align_y(struct _lv_obj_t * obj, lv_snap_align_t align); /** * Get the current scroll mode (when to hide the scrollbars) - * @param obj pointer to an object - * @return the current scroll mode from `lv_scroll_mode_t` + * @param obj pointer to an object + * @return the current scroll mode from `lv_scroll_mode_t` */ lv_scrollbar_mode_t lv_obj_get_scrollbar_mode(const struct _lv_obj_t * obj); /** * Get the object in which directions can be scrolled - * @param obj pointer to an object - * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` + * @param obj pointer to an object + * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` */ lv_dir_t lv_obj_get_scroll_dir(const struct _lv_obj_t * obj); /** * Get where to snap the children when scrolling ends horizontally - * @param obj pointer to an object - * @return the current snap align from `lv_snap_align_t` + * @param obj pointer to an object + * @return the current snap align from `lv_snap_align_t` */ lv_snap_align_t lv_obj_get_snap_align_x(const struct _lv_obj_t * obj); /** * Get where to snap the children when scrolling ends vertically - * @param obj pointer to an object - * @return the current snap align from `lv_snap_align_t` + * @param obj pointer to an object + * @return the current snap align from `lv_snap_align_t` */ lv_snap_align_t lv_obj_get_snap_align_y(const struct _lv_obj_t * obj); /** * Get current X scroll position. - * @param obj pointer to an object - * @return the current scroll position from the left edge. - * If the object is not scrolled return 0 - * If scrolled return > 0 - * If scrolled in (elastic scroll) return < 0 + * @param obj pointer to an object + * @return the current scroll position from the left edge. + * If the object is not scrolled return 0 + * If scrolled return > 0 + * If scrolled in (elastic scroll) return < 0 */ lv_coord_t lv_obj_get_scroll_x(const struct _lv_obj_t * obj); /** * Get current Y scroll position. - * @param obj pointer to an object - * @return the current scroll position from the top edge. - * If the object is not scrolled return 0 - * If scrolled return > 0 - * If scrolled inside return < 0 + * @param obj pointer to an object + * @return the current scroll position from the top edge. + * If the object is not scrolled return 0 + * If scrolled return > 0 + * If scrolled inside return < 0 */ lv_coord_t lv_obj_get_scroll_y(const struct _lv_obj_t * obj); @@ -138,8 +138,8 @@ lv_coord_t lv_obj_get_scroll_y(const struct _lv_obj_t * obj); * Return the height of the area above the object. * That is the number of pixels the object can be scrolled down. * Normally positive but can be negative when scrolled inside. - * @param obj pointer to an object - * @return the scrollable area above the object in pixels + * @param obj pointer to an object + * @return the scrollable area above the object in pixels */ lv_coord_t lv_obj_get_scroll_top(struct _lv_obj_t * obj); @@ -147,8 +147,8 @@ lv_coord_t lv_obj_get_scroll_top(struct _lv_obj_t * obj); * Return the height of the area below the object. * That is the number of pixels the object can be scrolled down. * Normally positive but can be negative when scrolled inside. - * @param obj pointer to an object - * @return the scrollable area below the object in pixels + * @param obj pointer to an object + * @return the scrollable area below the object in pixels */ lv_coord_t lv_obj_get_scroll_bottom(struct _lv_obj_t * obj); @@ -156,8 +156,8 @@ lv_coord_t lv_obj_get_scroll_bottom(struct _lv_obj_t * obj); * Return the width of the area on the left the object. * That is the number of pixels the object can be scrolled down. * Normally positive but can be negative when scrolled inside. - * @param obj pointer to an object - * @return the scrollable area on the left the object in pixels + * @param obj pointer to an object + * @return the scrollable area on the left the object in pixels */ lv_coord_t lv_obj_get_scroll_left(struct _lv_obj_t * obj); @@ -165,16 +165,16 @@ lv_coord_t lv_obj_get_scroll_left(struct _lv_obj_t * obj); * Return the width of the area on the right the object. * That is the number of pixels the object can be scrolled down. * Normally positive but can be negative when scrolled inside. - * @param obj pointer to an object - * @return the scrollable area on the right the object in pixels + * @param obj pointer to an object + * @return the scrollable area on the right the object in pixels */ lv_coord_t lv_obj_get_scroll_right(struct _lv_obj_t * obj); /** * Get the X and Y coordinates where the scrolling will end for this object if a scrolling animation is in progress. * In no scrolling animation give the current `x` or `y` scroll position. - * @param obj pointer to an object - * @param end poinr to point to store the result + * @param obj pointer to an object + * @param end poinr to point to store the result */ void lv_obj_get_scroll_end(struct _lv_obj_t * obj, lv_point_t * end); @@ -183,60 +183,71 @@ void lv_obj_get_scroll_end(struct _lv_obj_t * obj, lv_point_t * end); *====================*/ /** - * The most basic function to scroll by a given amount of pixels - * @param obj pointer to an object to scroll - * @param x pixels to scroll horizontally - * @param y pixels to scroll vertically - * @note > 0 value means scroll right/bottom (show the right/bottom content) + * The most basic function to scroll by a given amount of pixels. + * Used internally. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @note > 0 value means scroll right/bottom (show the more content on the right/bottom) */ void _lv_obj_scroll_by_raw(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); /** * * Scroll by a given amount of pixels - * @param obj pointer to an object to scroll - * @param x pixels to scroll horizontally - * @param y pixels to scroll vertically - * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately - * @note > 0 value means scroll right/bottom (show the right/bottom content) + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @note > 0 value means scroll right/bottom (show the more content on the right/bottom) + * @note */ void lv_obj_scroll_by(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en); /** * Scroll to a given coordinate on an object. * `x` and `y` will be limited internally to allow scrolling only on the content area. - * @param obj pointer to an object to scroll - * @param x pixels to scroll horizontally - * @param y pixels to scroll vertically - * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately */ void lv_obj_scroll_to(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en); /** * Scroll to a given X coordinate on an object. * `x` will be limited internally to allow scrolling only on the content area. - * @param obj pointer to an object to scroll - * @param x pixels to scroll horizontally - * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately */ void lv_obj_scroll_to_x(struct _lv_obj_t * obj, lv_coord_t x, lv_anim_enable_t anim_en); /** * Scroll to a given Y coordinate on an object * `y` will be limited internally to allow scrolling only on the content area. - * @param obj pointer to an object to scroll - * @param y pixels to scroll vertically - * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @param obj pointer to an object to scroll + * @param y pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately */ void lv_obj_scroll_to_y(struct _lv_obj_t * obj, lv_coord_t y, lv_anim_enable_t anim_en); /** - * Scroll to an object - * @param obj pointer to an object to scroll into view - * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * Scroll to an object until it becomes visible on its parent + * @param obj pointer to an object to scroll into view + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately */ void lv_obj_scroll_to_view(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); +/** + * Scroll to an object until it becomes visible on its parent. + * Do the same on the parent's parent, and so on. + * Therefore the object will be scrolled into view even it has nested scrollable parents + * @param obj pointer to an object to scroll into view + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_view_recursive(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + /********************** * MACROS **********************/ diff --git a/src/lv_core/lv_obj_style.c b/src/lv_core/lv_obj_style.c index c2185ed93..d916f10e3 100644 --- a/src/lv_core/lv_obj_style.c +++ b/src/lv_core/lv_obj_style.c @@ -39,6 +39,11 @@ typedef enum { CACHE_NEED_CHECK = 4, }cache_t; +/********************** + * GLOBAL PROTOTYPES + **********************/ +uint8_t lv_style_get_prop_group(lv_style_prop_t prop); + /********************** * STATIC PROTOTYPES **********************/ @@ -60,7 +65,7 @@ static void fade_in_anim_ready(lv_anim_t * a); /********************** * STATIC VARIABLES **********************/ -static style_refr = true; +static bool style_refr = true; /********************** * MACROS @@ -484,6 +489,7 @@ static bool get_prop_core(const lv_obj_t * obj, uint8_t part, lv_style_prop_t pr break; } + uint8_t group = 1 << lv_style_get_prop_group(prop); int32_t weight = -1; lv_state_t state = obj->state; lv_state_t state_inv = ~state; @@ -496,6 +502,7 @@ static bool get_prop_core(const lv_obj_t * obj, uint8_t part, lv_style_prop_t pr if(obj_style->is_trans == false) break; if(skip_trans) continue; if(obj_style->part != part) continue; + if((obj_style->style->has_group & group) == 0) continue; found = lv_style_get_prop(obj_style->style, prop, &value_tmp); if(found) { *v = value_tmp; @@ -507,6 +514,8 @@ static bool get_prop_core(const lv_obj_t * obj, uint8_t part, lv_style_prop_t pr lv_obj_style_t * obj_style = &obj->style_list.styles[i]; if(obj_style->part != part) continue; + if((obj_style->style->has_group & group) == 0) continue; + /* Be sure the style not specifies other state than the requested. * E.g. For HOVER+PRESS object state, HOVER style only is OK, but HOVER+FOCUS style is not*/ if((obj_style->state & state_inv)) continue; diff --git a/src/lv_core/lv_obj_tree.c b/src/lv_core/lv_obj_tree.c index dd61afbe7..058d0cd82 100644 --- a/src/lv_core/lv_obj_tree.c +++ b/src/lv_core/lv_obj_tree.c @@ -240,6 +240,7 @@ lv_disp_t * lv_obj_get_disp(const lv_obj_t * obj) lv_obj_t * lv_obj_get_parent(const lv_obj_t * obj) { + if(obj == NULL) return NULL; LV_ASSERT_OBJ(obj, MY_CLASS); return obj->parent; @@ -305,14 +306,6 @@ static void obj_del_core(lv_obj_t * obj) /*Remove the animations from this object*/ lv_anim_del(obj, NULL); -// _lv_obj_remove_style_trans(obj); - - /*Delete the user data*/ -#if LV_USE_USER_DATA -#if LV_USE_USER_DATA_FREE - LV_USER_DATA_FREE(obj); -#endif -#endif /*Recursively delete the children*/ lv_obj_t * child = lv_obj_get_child(obj, 0); @@ -323,6 +316,9 @@ static void obj_del_core(lv_obj_t * obj) lv_event_mark_deleted(obj); + /*Remove all style*/ + lv_obj_remove_style(obj, LV_PART_ANY, LV_STATE_ANY, NULL); + /* Reset all input devices if the object to delete is used*/ lv_indev_t * indev = lv_indev_get_next(NULL); while(indev) { diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index bf68f60bd..fb7cce3a1 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -248,7 +248,7 @@ void _lv_area_align(const lv_area_t * base, const lv_area_t * to_align, lv_align #define LV_COORD_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_AUTO LV_COORD_SET_SPEC(1001) +#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 diff --git a/src/lv_misc/lv_style.c b/src/lv_misc/lv_style.c index 92dec7aad..e5019af01 100644 --- a/src/lv_misc/lv_style.c +++ b/src/lv_misc/lv_style.c @@ -41,7 +41,7 @@ void lv_style_init(lv_style_t * style) { #if LV_USE_ASSERT_STYLE - if(style->sentinel == LV_DEBUG_STYLE_SENTINEL_VALUE && style->allocated && style->props_and_values != NULL) { + if(style->sentinel == LV_DEBUG_STYLE_SENTINEL_VALUE && style->allocated && style->values_and_props != NULL) { LV_LOG_WARN("Style might be already inited. (Potential memory leak)") } #endif @@ -57,7 +57,7 @@ void lv_style_reset(lv_style_t * style) { LV_ASSERT_STYLE(style); - if(style->allocated) lv_mem_free(style->props_and_values); + if(style->allocated) lv_mem_free(style->values_and_props); lv_style_init(style); } @@ -82,12 +82,12 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop) return false; } - uint8_t * tmp = style->props_and_values + style->prop_cnt * sizeof(lv_style_value_t); + uint8_t * tmp = style->values_and_props + style->prop_cnt * sizeof(lv_style_value_t); uint16_t * props = (uint16_t *) tmp; uint32_t i; for(i = 0; i < style->prop_cnt; i++) { if(props[i] == prop) { - lv_style_value_t * values = (lv_style_value_t *)style->props_and_values; + lv_style_value_t * values = (lv_style_value_t *)style->values_and_props; style->prop_cnt--; size_t size = style->prop_cnt * (sizeof(lv_style_value_t) + sizeof(uint16_t)); uint8_t * new_values_and_props = lv_mem_alloc(size); @@ -107,8 +107,8 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop) } } - lv_mem_free(style->props_and_values); - style->props_and_values = new_values_and_props; + lv_mem_free(style->values_and_props); + style->values_and_props = new_values_and_props; return true; } } @@ -116,15 +116,31 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop) return false; } +/** + * Tell the group of a property. If the a property from a group is set in a style the (1 << group) bit of style->has_group is set. + * It allows early skipping the style if the property is not exists in the style at all. + * @param prop a style property + * @return the group [0..7] 7 means all the custom properties with index > 112 + */ +uint8_t lv_style_get_prop_group(lv_style_prop_t prop) +{ + uint16_t group = (prop & 0x1FF) >> 4; + if(group > 7) group = 7; /*The MSB marks all the custom properties*/ + return (uint8_t)group; +} + void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value) { + uint8_t group = lv_style_get_prop_group(prop); + style->has_group |= 1 << group; + if(style->allocated) { - uint8_t * tmp = style->props_and_values + style->prop_cnt * sizeof(lv_style_value_t); + uint8_t * tmp = style->values_and_props + style->prop_cnt * sizeof(lv_style_value_t); uint16_t * props = (uint16_t *) tmp; int32_t i; for(i = 0; i < style->prop_cnt; i++) { if(props[i] == prop) { - lv_style_value_t * values = (lv_style_value_t *)style->props_and_values; + lv_style_value_t * values = (lv_style_value_t *)style->values_and_props; values[i] = value; return; } @@ -132,8 +148,8 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ style->prop_cnt++; size_t size = style->prop_cnt * (sizeof(lv_style_value_t) + sizeof(uint16_t)); - style->props_and_values = lv_mem_realloc(style->props_and_values, size); - tmp = style->props_and_values + (style->prop_cnt - 1) * sizeof(lv_style_value_t); + style->values_and_props = lv_mem_realloc(style->values_and_props, size); + tmp = style->values_and_props + (style->prop_cnt - 1) * sizeof(lv_style_value_t); props = (uint16_t *) tmp; /*Shift all props to make place for the value before them*/ for(i = style->prop_cnt - 2; i >= 0; i--) { @@ -141,9 +157,9 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ } /*Go to the new position wit the props*/ - tmp = style->props_and_values + (style->prop_cnt) * sizeof(lv_style_value_t); + tmp = style->values_and_props + (style->prop_cnt) * sizeof(lv_style_value_t); props = (uint16_t *) tmp; - lv_style_value_t * values = (lv_style_value_t *)style->props_and_values; + lv_style_value_t * values = (lv_style_value_t *)style->values_and_props; /*Set the new property and value*/ props[style->prop_cnt - 1] = prop; @@ -155,16 +171,16 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ } style->prop_cnt++; size_t size = style->prop_cnt * (sizeof(lv_style_value_t) + sizeof(uint16_t)); - uint8_t * props_and_values = lv_mem_alloc(size); - uint8_t * tmp = props_and_values + (style->prop_cnt) * sizeof(lv_style_value_t); + uint8_t * values_and_props = lv_mem_alloc(size); + uint8_t * tmp = values_and_props + (style->prop_cnt) * sizeof(lv_style_value_t); uint16_t * props = (uint16_t *) tmp; - lv_style_value_t * values = (lv_style_value_t *)props_and_values; + lv_style_value_t * values = (lv_style_value_t *)values_and_props; props[0] = style->prop1; props[1] = prop; values[0] = style->value1; values[1] = value; - style->props_and_values = props_and_values; + style->values_and_props = values_and_props; style->allocated = 1; } else if (style->prop_cnt == 0) { @@ -176,13 +192,15 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) { + if(style->prop_cnt == 0) return false; + if(style->allocated) { - uint8_t * tmp = style->props_and_values + style->prop_cnt * sizeof(lv_style_value_t); + uint8_t * tmp = style->values_and_props + style->prop_cnt * sizeof(lv_style_value_t); uint16_t * props = (uint16_t *) tmp; uint32_t i; for(i = 0; i < style->prop_cnt; i++) { if(props[i] == prop) { - lv_style_value_t * values = (lv_style_value_t *)style->props_and_values; + lv_style_value_t * values = (lv_style_value_t *)style->values_and_props; *value = values[i]; return true; } diff --git a/src/lv_misc/lv_style.h b/src/lv_misc/lv_style.h index 403504892..b8d4cddd3 100644 --- a/src/lv_misc/lv_style.h +++ b/src/lv_misc/lv_style.h @@ -113,13 +113,15 @@ typedef union { typedef enum { LV_STYLE_PROP_INV = 0, + /*Group 0*/ LV_STYLE_RADIUS = 1, LV_STYLE_CLIP_CORNER = 2, - LV_STYLE_TRANSFORM_WIDTH = 3 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_TRANSFORM_HEIGHT = 4 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_TRANSFORM_WIDTH = 3 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_TRANSFORM_HEIGHT = 4 | LV_STYLE_PROP_EXT_DRAW, LV_STYLE_TRANSFORM_ZOOM = 5 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_TRANSFORM_ANGLE = 6 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_OPA = 7 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TRANSFORM_ANGLE = 6 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_OPA = 7 | LV_STYLE_PROP_INHERIT, + LV_STYLE_COLOR_FILTER_CB = 8, LV_STYLE_COLOR_FILTER_OPA = 9, LV_STYLE_ANIM_TIME = 10, @@ -127,92 +129,99 @@ typedef enum { LV_STYLE_SIZE = 12, LV_STYLE_BLEND_MODE = 13, - LV_STYLE_PAD_TOP = 20 | LV_STYLE_PROP_LAYOUT_REFR, - LV_STYLE_PAD_BOTTOM = 21 | LV_STYLE_PROP_LAYOUT_REFR, - LV_STYLE_PAD_LEFT = 22 | LV_STYLE_PROP_LAYOUT_REFR, - LV_STYLE_PAD_RIGHT = 23 | LV_STYLE_PROP_LAYOUT_REFR, - LV_STYLE_PAD_ROW = 24 | LV_STYLE_PROP_LAYOUT_REFR, - LV_STYLE_PAD_COLUMN = 25 | LV_STYLE_PROP_LAYOUT_REFR, + /*Group 1*/ + LV_STYLE_PAD_TOP = 16 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_PAD_BOTTOM = 17 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_PAD_LEFT = 18 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_PAD_RIGHT = 19 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_PAD_ROW = 20 | LV_STYLE_PROP_LAYOUT_REFR, + LV_STYLE_PAD_COLUMN = 21 | LV_STYLE_PROP_LAYOUT_REFR, - LV_STYLE_BG_COLOR = 30, - LV_STYLE_BG_COLOR_FILTERED = 30 | LV_STYLE_PROP_FILTER, - LV_STYLE_BG_OPA = 31, - LV_STYLE_BG_GRAD_COLOR = 32, - LV_STYLE_BG_GRAD_COLOR_FILTERED = 32 | LV_STYLE_PROP_FILTER, - LV_STYLE_BG_GRAD_DIR = 33, - LV_STYLE_BG_MAIN_STOP = 35, - LV_STYLE_BG_GRAD_STOP = 36, + /*Group 2*/ + LV_STYLE_BG_COLOR = 32, + LV_STYLE_BG_COLOR_FILTERED = 32 | LV_STYLE_PROP_FILTER, + LV_STYLE_BG_OPA = 33, + LV_STYLE_BG_GRAD_COLOR = 34, + LV_STYLE_BG_GRAD_COLOR_FILTERED = 34 | LV_STYLE_PROP_FILTER, + LV_STYLE_BG_GRAD_DIR = 35, + LV_STYLE_BG_MAIN_STOP = 36, + LV_STYLE_BG_GRAD_STOP = 37, - LV_STYLE_BG_IMG_SRC = 40, - LV_STYLE_BG_IMG_OPA = 41, - LV_STYLE_BG_IMG_RECOLOR = 42, - LV_STYLE_BG_IMG_RECOLOR_FILTERED = 43 | LV_STYLE_PROP_FILTER, - LV_STYLE_BG_IMG_RECOLOR_OPA = 44, - LV_STYLE_BG_IMG_TILED = 45, + LV_STYLE_BG_IMG_SRC = 38, + LV_STYLE_BG_IMG_OPA = 39, + LV_STYLE_BG_IMG_RECOLOR = 40, + LV_STYLE_BG_IMG_RECOLOR_FILTERED = 40 | LV_STYLE_PROP_FILTER, + LV_STYLE_BG_IMG_RECOLOR_OPA = 41, + LV_STYLE_BG_IMG_TILED = 42, - LV_STYLE_BORDER_COLOR = 50, - LV_STYLE_BORDER_COLOR_FILTERED = 50 | LV_STYLE_PROP_FILTER, - LV_STYLE_BORDER_OPA = 51, - LV_STYLE_BORDER_WIDTH = 52, - LV_STYLE_BORDER_SIDE = 53, - LV_STYLE_BORDER_POST = 54, + LV_STYLE_BORDER_COLOR = 43, + LV_STYLE_BORDER_COLOR_FILTERED = 43 | LV_STYLE_PROP_FILTER, + LV_STYLE_BORDER_OPA = 44, + LV_STYLE_BORDER_WIDTH = 45, + LV_STYLE_BORDER_SIDE = 46, + LV_STYLE_BORDER_POST = 47, - LV_STYLE_TEXT_COLOR = 60 | LV_STYLE_PROP_INHERIT, - LV_STYLE_TEXT_COLOR_FILTERED = 60 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER, - LV_STYLE_TEXT_OPA = 61 | LV_STYLE_PROP_INHERIT, - LV_STYLE_TEXT_FONT = 62 | LV_STYLE_PROP_INHERIT, - LV_STYLE_TEXT_LETTER_SPACE = 63 | LV_STYLE_PROP_INHERIT, - LV_STYLE_TEXT_LINE_SPACE = 64 | LV_STYLE_PROP_INHERIT, - LV_STYLE_TEXT_DECOR = 65 | LV_STYLE_PROP_INHERIT, - LV_STYLE_TEXT_ALIGN = 66 | LV_STYLE_PROP_INHERIT, + /*Group 3*/ + LV_STYLE_OUTLINE_WIDTH = 48 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_OUTLINE_COLOR = 49, + LV_STYLE_OUTLINE_COLOR_FILTERED = 49 | LV_STYLE_PROP_FILTER, + LV_STYLE_OUTLINE_OPA = 50 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_OUTLINE_PAD = 51 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_IMG_OPA = 70, - LV_STYLE_IMG_RECOLOR = 71, - LV_STYLE_IMG_RECOLOR_FILTERED = 71 | LV_STYLE_PROP_FILTER, - LV_STYLE_IMG_RECOLOR_OPA = 73, + LV_STYLE_SHADOW_WIDTH = 55 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_SHADOW_OFS_X = 56 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_SHADOW_OFS_Y = 57 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_SHADOW_SPREAD = 58 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_SHADOW_COLOR = 59, + LV_STYLE_SHADOW_COLOR_FILTERED = 59 | LV_STYLE_PROP_FILTER, + LV_STYLE_SHADOW_OPA = 60 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_OUTLINE_WIDTH = 80 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_OUTLINE_COLOR = 81, - LV_STYLE_OUTLINE_COLOR_FILTERED = 81 | LV_STYLE_PROP_FILTER, - LV_STYLE_OUTLINE_OPA = 82 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_OUTLINE_PAD = 83 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_SHADOW_WIDTH = 90 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_SHADOW_OFS_X = 91 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_SHADOW_OFS_Y = 92 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_SHADOW_SPREAD = 93 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_SHADOW_COLOR = 94, - LV_STYLE_SHADOW_COLOR_FILTERED = 94 | LV_STYLE_PROP_FILTER, - LV_STYLE_SHADOW_OPA = 95 | LV_STYLE_PROP_EXT_DRAW, + /*Group 4*/ + LV_STYLE_IMG_OPA = 64, + LV_STYLE_IMG_RECOLOR = 65, + LV_STYLE_IMG_RECOLOR_FILTERED = 65 | LV_STYLE_PROP_FILTER, + LV_STYLE_IMG_RECOLOR_OPA = 66, - LV_STYLE_LINE_WIDTH = 100 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_LINE_DASH_WIDTH = 101, - LV_STYLE_LINE_DASH_GAP = 102, - LV_STYLE_LINE_ROUNDED = 103, - LV_STYLE_LINE_COLOR = 104, - LV_STYLE_LINE_COLOR_FILTERED = 104 | LV_STYLE_PROP_FILTER, - LV_STYLE_LINE_OPA = 105, + LV_STYLE_LINE_WIDTH = 68 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_LINE_DASH_WIDTH = 69, + LV_STYLE_LINE_DASH_GAP = 70, + LV_STYLE_LINE_ROUNDED = 71, + LV_STYLE_LINE_COLOR = 72, + LV_STYLE_LINE_COLOR_FILTERED = 72 | LV_STYLE_PROP_FILTER, + LV_STYLE_LINE_OPA = 73, - LV_STYLE_ARC_WIDTH = 110 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_ARC_ROUNDED = 111, - LV_STYLE_ARC_COLOR = 112, - LV_STYLE_ARC_COLOR_FILTERED = 112 | LV_STYLE_PROP_FILTER, - LV_STYLE_ARC_OPA = 113, - LV_STYLE_ARC_IMG_SRC = 114, + LV_STYLE_ARC_WIDTH = 75 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_ARC_ROUNDED = 76, + LV_STYLE_ARC_COLOR = 77, + LV_STYLE_ARC_COLOR_FILTERED = 77 | LV_STYLE_PROP_FILTER, + LV_STYLE_ARC_OPA = 78, + LV_STYLE_ARC_IMG_SRC = 79, - LV_STYLE_CONTENT_TEXT = 120 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_ALIGN = 121 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_OFS_X = 122 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_OFS_Y = 123 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_FONT = 124 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_COLOR = 125 | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_COLOR_FILTERED = 125 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER, - LV_STYLE_CONTENT_OPA = 126 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_LETTER_SPACE = 127 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_LINE_SPACE = 128 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_DECOR = 129 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + /*Group 5*/ + LV_STYLE_TEXT_COLOR = 80 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TEXT_COLOR_FILTERED = 80 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER, + LV_STYLE_TEXT_OPA = 81 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TEXT_FONT = 82 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TEXT_LETTER_SPACE = 83 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TEXT_LINE_SPACE = 84 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TEXT_DECOR = 85 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TEXT_ALIGN = 86 | LV_STYLE_PROP_INHERIT, - _LV_STYLE_LAST_BUILT_IN_PROP = 140, + /*Group 6*/ + LV_STYLE_CONTENT_TEXT = 96 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_ALIGN = 97 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_OFS_X = 98 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_OFS_Y = 99 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_FONT = 100 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_COLOR = 101 | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_COLOR_FILTERED = 101 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER, + LV_STYLE_CONTENT_OPA = 102 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_LETTER_SPACE = 103 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_LINE_SPACE = 104 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_DECOR = 105 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + + _LV_STYLE_LAST_BUILT_IN_PROP = 111, LV_STYLE_PROP_ALL = 0xFFFF }lv_style_prop_t; @@ -251,13 +260,14 @@ typedef struct { lv_style_value_t value1; }; struct { - uint8_t * props_and_values; + uint8_t * values_and_props; }; }; uint16_t prop1; - uint16_t prop_cnt:14; - uint16_t allocated:1; + uint8_t has_group; + uint8_t prop_cnt :7; + uint8_t allocated :1; } lv_style_t; /********************** diff --git a/src/lv_widgets/lv_arc.c b/src/lv_widgets/lv_arc.c index 9fd18e8c4..4c2901fdf 100644 --- a/src/lv_widgets/lv_arc.c +++ b/src/lv_widgets/lv_arc.c @@ -484,8 +484,6 @@ static void lv_arc_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t { LV_LOG_TRACE("lv_arc create started"); - lv_obj_construct_base(obj, parent, copy); - lv_arc_t * arc = (lv_arc_t *)obj; LV_LOG_TRACE("arc create started"); diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index 7ff2873d7..2be6976d2 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -203,8 +203,6 @@ static void lv_bar_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t { LV_LOG_TRACE("lv_bar create started"); - lv_obj_construct_base(obj, parent, copy); - lv_bar_t * bar = (lv_bar_t *)obj; bar->min_value = 0; bar->max_value = 100; diff --git a/src/lv_widgets/lv_btn.c b/src/lv_widgets/lv_btn.c index 55c8fa4f2..a210fa75e 100644 --- a/src/lv_widgets/lv_btn.c +++ b/src/lv_widgets/lv_btn.c @@ -55,8 +55,6 @@ static void lv_btn_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t { LV_LOG_TRACE("lv_btn create started"); - lv_obj_construct_base(obj, parent, copy); - lv_obj_set_size(obj, LV_DPI_DEF, LV_DPI_DEF / 3); lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); diff --git a/src/lv_widgets/lv_btnmatrix.c b/src/lv_widgets/lv_btnmatrix.c index 31295131e..255df0e3a 100644 --- a/src/lv_widgets/lv_btnmatrix.c +++ b/src/lv_widgets/lv_btnmatrix.c @@ -375,8 +375,6 @@ bool lv_btnmatrix_get_one_checked(const lv_obj_t * obj) static void lv_btnmatrix_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_construct_base(obj, parent, copy); - lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj; btnm->btn_cnt = 0; btnm->btn_id_pr = LV_BTNMATRIX_BTN_NONE; diff --git a/src/lv_widgets/lv_canvas.c b/src/lv_widgets/lv_canvas.c index d72ee5143..cf190d74f 100644 --- a/src/lv_widgets/lv_canvas.c +++ b/src/lv_widgets/lv_canvas.c @@ -890,8 +890,6 @@ static void lv_canvas_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob { LV_LOG_TRACE("canvas create started"); - lv_obj_construct_base(obj, parent, copy); - lv_canvas_t * canvas = (lv_canvas_t *) obj; /*Initialize the allocated 'ext' */ diff --git a/src/lv_widgets/lv_chart.c b/src/lv_widgets/lv_chart.c index 9caede14c..33457a374 100644 --- a/src/lv_widgets/lv_chart.c +++ b/src/lv_widgets/lv_chart.c @@ -493,8 +493,6 @@ static void lv_chart_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj { LV_LOG_TRACE("chart create started"); - lv_obj_construct_base(obj, parent, copy); - lv_chart_t * chart = (lv_chart_t *) obj; _lv_ll_init(&chart->series_ll, sizeof(lv_chart_series_t)); @@ -627,7 +625,7 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area) lv_coord_t scroll_top = lv_obj_get_scroll_top(obj); if(chart->hdiv_cnt != 0) { lv_coord_t y_ofs = obj->coords.y1 + pad_top - scroll_top; - p1.x = obj->coords.x1 + scroll_left; + p1.x = obj->coords.x1; p2.x = obj->coords.x2; for(i = 0; i <= chart->hdiv_cnt + 1; i++) { p1.y = (int32_t)((int32_t)(h - line_dsc.width) * i) / (chart->hdiv_cnt + 1); @@ -639,7 +637,7 @@ static void draw_div_lines(lv_obj_t * obj, const lv_area_t * clip_area) if(chart->vdiv_cnt != 0) { lv_coord_t x_ofs = obj->coords.x1 + pad_left - scroll_left; - p1.y = obj->coords.y1 + scroll_top; + p1.y = obj->coords.y1; p2.y = obj->coords.y2; for(i = 0; i <= chart->vdiv_cnt + 1; i++) { p1.x = (int32_t)((int32_t)(w - line_dsc.width) * i) / (chart->vdiv_cnt + 1); diff --git a/src/lv_widgets/lv_chart.h b/src/lv_widgets/lv_chart.h index 5299e661b..e1fed8667 100644 --- a/src/lv_widgets/lv_chart.h +++ b/src/lv_widgets/lv_chart.h @@ -181,9 +181,9 @@ uint16_t lv_chart_get_zoom_x(const lv_obj_t * obj); uint16_t lv_chart_get_zoom_y(const lv_obj_t * obj); /** - * Set the number of tick lines between two division lines + * Set the number of tick lines on an axis * @param obj pointer to a chart object - * @param axis an axis which sub tick count should be set + * @param axis an axis which ticks count should be set * @param major_len length of major ticks * @param minor_len length of minor ticks * @param major_cnt number of major ticks on the axis diff --git a/src/lv_widgets/lv_checkbox.c b/src/lv_widgets/lv_checkbox.c index f1648044f..67dc57443 100644 --- a/src/lv_widgets/lv_checkbox.c +++ b/src/lv_widgets/lv_checkbox.c @@ -111,8 +111,6 @@ static void lv_checkbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ { LV_LOG_TRACE("lv_checkbox create started"); - lv_obj_construct_base(obj, parent, copy); - lv_checkbox_t * cb = (lv_checkbox_t *) obj; /*Create the ancestor basic object*/ @@ -122,7 +120,7 @@ static void lv_checkbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ cb->static_txt = 1; lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE); lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE); - lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); } else { // const lv_checkbox_t * copy_ext = (const lv_checkbox_t *)copy; diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index 110bd85bc..180c05b7e 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -41,7 +41,6 @@ static lv_draw_res_t lv_dropdown_draw(lv_obj_t * obj, const lv_area_t * clip_are static lv_res_t lv_dropdown_signal(lv_obj_t * obj, lv_signal_t sign, void * param); static void lv_dropdown_list_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); -static void lv_dropdown_list_destructor(lv_obj_t * obj); static lv_draw_res_t lv_dropdown_list_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode); static lv_res_t lv_dropdown_list_signal(lv_obj_t * list, lv_signal_t sign, void * param); @@ -68,7 +67,6 @@ const lv_obj_class_t lv_dropdown = { const lv_obj_class_t lv_dropdown_list = { .constructor_cb = lv_dropdown_list_constructor, - .destructor_cb = lv_dropdown_list_destructor, .signal_cb = lv_dropdown_list_signal, .draw_cb = lv_dropdown_list_draw, .instance_size = sizeof(lv_dropdown_list_t), @@ -421,7 +419,7 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) (dropdown->dir == LV_DIR_TOP || dropdown->dir == LV_DIR_BOTTOM)) { lv_obj_set_width(dropdown->list, lv_obj_get_width(dropdown_obj)); } else { - lv_obj_set_width(dropdown->list, LV_SIZE_AUTO); + lv_obj_set_width(dropdown->list, LV_SIZE_CONTENT); } lv_obj_t * label = get_label(dropdown_obj); @@ -526,8 +524,6 @@ static void lv_dropdown_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ { LV_LOG_TRACE("dropdown create started"); - lv_obj_construct_base(obj, parent, copy); - lv_dropdown_t * dropdown = (lv_dropdown_t *) obj; /*Initialize the allocated 'ext' */ @@ -776,16 +772,9 @@ static lv_draw_res_t lv_dropdown_list_draw(lv_obj_t * list_obj, const lv_area_t static void lv_dropdown_list_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_construct_base(obj, parent, copy); - lv_label_create(obj, NULL); } -static void lv_dropdown_list_destructor(lv_obj_t * obj) -{ - -} - /** * Signal function of the drop down list * @param ddlist pointer to a drop down list object diff --git a/src/lv_widgets/lv_img.c b/src/lv_widgets/lv_img.c index 3add8d5c6..1d625cf5f 100644 --- a/src/lv_widgets/lv_img.c +++ b/src/lv_widgets/lv_img.c @@ -364,8 +364,6 @@ static void lv_img_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t { LV_LOG_TRACE("lv_bar create started"); - lv_obj_construct_base(obj, parent, copy); - lv_img_t * img = (lv_img_t *)obj; img->src = NULL; @@ -388,7 +386,7 @@ static void lv_img_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t /* Enable auto size for non screens * because image screens are wallpapers * and must be screen sized*/ - if(parent) lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); + if(parent) lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); } else { lv_img_t * copy_img = (lv_img_t *) copy; @@ -526,7 +524,7 @@ static lv_draw_res_t lv_img_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc); - label_dsc.color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN); +// label_dsc.color = lv_obj_get_style_img_recolor(obj, LV_PART_MAIN); lv_draw_label(&obj->coords, clip_area, &label_dsc, img->src, NULL); } else { diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index 88f45e601..196def935 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -701,8 +701,6 @@ static void lv_label_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj { LV_LOG_TRACE("label create started"); - lv_obj_construct_base(obj, parent, copy); - lv_label_t * label = (lv_label_t *)obj; label->text = NULL; diff --git a/src/lv_widgets/lv_line.c b/src/lv_widgets/lv_line.c index 64728fa4d..e9a5b0a58 100644 --- a/src/lv_widgets/lv_line.c +++ b/src/lv_widgets/lv_line.c @@ -108,8 +108,6 @@ static void lv_line_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_ { LV_LOG_TRACE("line create started"); - lv_obj_construct_base(obj, parent, copy); - /*Create a basic object*/ lv_line_t * line = (lv_line_t *) obj; line->point_num = 0; @@ -119,7 +117,7 @@ static void lv_line_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_ /*Init the new line*/ if(copy == NULL) { - lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE); } /*Copy an existing object*/ diff --git a/src/lv_widgets/lv_roller.c b/src/lv_widgets/lv_roller.c index 2ddb2d8e2..c0ab5e200 100644 --- a/src/lv_widgets/lv_roller.c +++ b/src/lv_widgets/lv_roller.c @@ -284,8 +284,6 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj) static void lv_roller_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_construct_base(obj, parent, copy); - lv_roller_t * roller = (lv_roller_t*)obj; roller->mode = LV_ROLLER_MODE_NORMAL; @@ -297,7 +295,7 @@ static void lv_roller_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob if(copy == NULL) { lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_CHAIN); - lv_obj_set_width(obj, LV_SIZE_AUTO); + lv_obj_set_width(obj, LV_SIZE_CONTENT); lv_obj_create_from_class(&lv_roller_label, obj, NULL); lv_roller_set_options(obj, "Option 1\nOption 2\nOption 3\nOption 4\nOption 5", LV_ROLLER_MODE_NORMAL); diff --git a/src/lv_widgets/lv_slider.c b/src/lv_widgets/lv_slider.c index cc4029266..9044620ae 100644 --- a/src/lv_widgets/lv_slider.c +++ b/src/lv_widgets/lv_slider.c @@ -80,7 +80,6 @@ bool lv_slider_is_dragged(const lv_obj_t * obj) static void lv_slider_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { - lv_obj_construct_base(obj, parent, copy); lv_slider_t * slider = (lv_slider_t *)obj; /*Initialize the allocated 'slider' */ diff --git a/src/lv_widgets/lv_switch.c b/src/lv_widgets/lv_switch.c index 02523a45f..bfb539c92 100644 --- a/src/lv_widgets/lv_switch.c +++ b/src/lv_widgets/lv_switch.c @@ -78,8 +78,6 @@ static void lv_switch_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ob { LV_LOG_TRACE("switch create started"); - lv_obj_construct_base(obj, parent, copy); - if(copy == NULL) { lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE); diff --git a/src/lv_widgets/lv_table.c b/src/lv_widgets/lv_table.c index 58aa01377..a5a7a934b 100644 --- a/src/lv_widgets/lv_table.c +++ b/src/lv_widgets/lv_table.c @@ -564,9 +564,6 @@ static void lv_table_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj { LV_LOG_TRACE("lv_table create started"); - lv_obj_construct_base(obj, parent, copy); - - lv_table_t * table = (lv_table_t *) obj; /*Initialize the allocated 'ext' */ @@ -587,7 +584,7 @@ static void lv_table_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj table->cell_data = lv_mem_realloc(table->cell_data, table->row_cnt * table->col_cnt * sizeof(char *)); table->cell_data[0] = NULL; - lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); + lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); } /*Copy an existing table*/ else { diff --git a/src/lv_widgets/lv_textarea.c b/src/lv_widgets/lv_textarea.c index 81e640073..86f89df2a 100644 --- a/src/lv_widgets/lv_textarea.c +++ b/src/lv_widgets/lv_textarea.c @@ -948,7 +948,6 @@ void lv_textarea_cursor_up(lv_obj_t * obj) static void lv_textarea_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) { LV_LOG_TRACE("text area create started"); - lv_obj_construct_base(obj, parent, copy); lv_textarea_t * ta = (lv_textarea_t *) obj; @@ -1488,7 +1487,7 @@ static void draw_placeholder(lv_obj_t * obj, const lv_area_t * clip_area) if(txt[0] == '\0' && ta->placeholder_txt && ta->placeholder_txt[0] != 0) { lv_draw_label_dsc_t ph_dsc; lv_draw_label_dsc_init(&ph_dsc); - lv_obj_init_draw_label_dsc(obj, LV_PART_PLACEHOLDER, &ph_dsc); + lv_obj_init_draw_label_dsc(obj, LV_PART_TEXTAREA_PLACEHOLDER, &ph_dsc); if(ta->one_line) ph_dsc.flag |= LV_TEXT_FLAG_EXPAND; diff --git a/src/lv_widgets/lv_textarea.h b/src/lv_widgets/lv_textarea.h index 3ac00d891..f30d984d2 100644 --- a/src/lv_widgets/lv_textarea.h +++ b/src/lv_widgets/lv_textarea.h @@ -67,6 +67,10 @@ typedef struct { extern const lv_obj_class_t lv_textarea; +enum { + LV_PART_TEXTAREA_PLACEHOLDER = LV_PART_CUSTOM_1, +}; + /********************** * GLOBAL PROTOTYPES **********************/