From ac3fa78718357c2d89768f771173ca21ac1b2f86 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 19 Mar 2021 13:00:21 +0100 Subject: [PATCH] minor fixes --- src/core/lv_indev.c | 3 ++ src/core/lv_obj.c | 30 ++++++++++++- src/core/lv_obj.h | 1 + src/core/lv_obj_scroll.c | 32 ++++++++++--- src/core/lv_obj_style.c | 6 ++- src/extra/themes/default/lv_theme_default.c | 19 ++++++-- src/widgets/lv_chart.c | 23 +++++----- src/widgets/lv_table.c | 50 +++++++++++++++------ 8 files changed, 128 insertions(+), 36 deletions(-) diff --git a/src/core/lv_indev.c b/src/core/lv_indev.c index 60a671b01..813de9036 100644 --- a/src/core/lv_indev.c +++ b/src/core/lv_indev.c @@ -585,6 +585,7 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) /*Don't leave edit mode if there is only one object (nowhere to navigate)*/ if(_lv_ll_get_len(&g->obj_ll) > 1) { lv_group_set_editing(g, lv_group_get_editing(g) ? false : true); /*Toggle edit mode on long press*/ + lv_obj_clear_state(indev_obj_act, LV_STATE_PRESSED); /*Remove the pressed state manually*/ } } /*If not editable then just send a long press Call the ancestor's event handler*/ @@ -655,6 +656,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) lv_group_send_data(g, LV_KEY_ENTER); + } else { + lv_obj_clear_state(indev_obj_act, LV_STATE_PRESSED); /*Remove the pressed state manually*/ } } /*If the focused object is editable and now in navigate mode then on enter switch edit diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index 74485fd25..f627381fc 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -68,6 +68,7 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc static bool obj_valid_child(const lv_obj_t * parent, const lv_obj_t * obj_to_find); static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state); static void base_dir_refr_children(lv_obj_t * obj); +static bool event_is_bubbled(lv_event_t e); /********************** * STATIC VARIABLES @@ -249,7 +250,7 @@ lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, void * param) /*Remove this element from the list*/ event_temp_data_head = event_temp_data_head->prev; - if(res == LV_RES_OK) { + if(res == LV_RES_OK && event_is_bubbled(event)) { if(lv_obj_has_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE) && obj->parent) { res = lv_event_send(obj->parent, event, param); if(res != LV_RES_OK) return LV_RES_INV; @@ -1171,3 +1172,30 @@ static bool obj_valid_child(const lv_obj_t * parent, const lv_obj_t * obj_to_fin } return false; } + +static bool event_is_bubbled(lv_event_t e) +{ + switch(e) { + case LV_EVENT_HIT_TEST: + case LV_EVENT_COVER_CHECK: + case LV_EVENT_REFR_EXT_DRAW_SIZE: + case LV_EVENT_DRAW_MAIN_BEGIN: + case LV_EVENT_DRAW_MAIN: + case LV_EVENT_DRAW_MAIN_END: + case LV_EVENT_DRAW_POST_BEGIN: + case LV_EVENT_DRAW_POST: + case LV_EVENT_DRAW_POST_END: + case LV_EVENT_DRAW_PART_BEGIN: + case LV_EVENT_DRAW_PART_END: + case LV_EVENT_REFRESH: + case LV_EVENT_DELETE: + case LV_EVENT_CHILD_CHANGED: + case LV_EVENT_COORD_CHANGED: + case LV_EVENT_STYLE_CHANGED: + case LV_EVENT_GET_SELF_SIZE: + return false; + default: + return true; + } +} + diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index c87535b5f..039877201 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -27,6 +27,7 @@ extern "C" { /********************* * DEFINES *********************/ +#define _LV_EVENT_FLAG_BUBBLED 0x80 /********************** * TYPEDEFS diff --git a/src/core/lv_obj_scroll.c b/src/core/lv_obj_scroll.c index 18b871f3c..d0a7549fa 100644 --- a/src/core/lv_obj_scroll.c +++ b/src/core/lv_obj_scroll.c @@ -572,11 +572,21 @@ static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_p lv_coord_t pbottom = lv_obj_get_style_pad_bottom(parent, LV_PART_MAIN); lv_coord_t top_diff = parent->coords.y1 + ptop - area_tmp->y1 - scroll_value->y; lv_coord_t bottom_diff = -(parent->coords.y2 - pbottom - area_tmp->y2 - scroll_value->y); - if((top_diff > 0 && bottom_diff > 0)) y_scroll = 0; - else if(top_diff > 0) y_scroll = top_diff; - else if(bottom_diff > 0) y_scroll = -bottom_diff; - lv_coord_t parent_h = lv_obj_get_height(parent) - ptop - pbottom; + if((top_diff > 0 && bottom_diff > 0)) y_scroll = 0; + else if(top_diff > 0) { + y_scroll = top_diff; + /*Do not let scrolling in*/ + lv_coord_t st = lv_obj_get_scroll_top(parent); + if(st - y_scroll < 0) y_scroll = 0; + } + else if(bottom_diff > 0) { + y_scroll = -bottom_diff; + /*Do not let scrolling in*/ + lv_coord_t sb = lv_obj_get_scroll_bottom(parent); + if(sb + y_scroll < 0) y_scroll = 0; + } + switch(snap_y) { case LV_SCROLL_SNAP_START: snap_goal = parent->coords.y1 + ptop; @@ -605,8 +615,18 @@ static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_p lv_coord_t left_diff = parent->coords.x1 + pleft - area_tmp->x1 - scroll_value->x; lv_coord_t right_diff = -(parent->coords.x2 - pright - area_tmp->x2- scroll_value->x); if((left_diff > 0 && right_diff > 0)) x_scroll = 0; - else if(left_diff > 0) x_scroll = left_diff; - else if(right_diff > 0) x_scroll = -right_diff; + else if(left_diff > 0) { + x_scroll = left_diff; + /*Do not let scrolling in*/ + lv_coord_t sl = lv_obj_get_scroll_left(parent); + if(sl + x_scroll > 0) x_scroll = 0; + } + else if(right_diff > 0) { + x_scroll = -right_diff; + /*Do not let scrolling in*/ + lv_coord_t sr = lv_obj_get_scroll_right(parent); + if(sr + x_scroll < 0) x_scroll = 0; + } lv_coord_t parent_w = lv_obj_get_width(parent) - pleft - pright; switch(snap_x) { diff --git a/src/core/lv_obj_style.c b/src/core/lv_obj_style.c index 0af5266af..8d0acd08e 100644 --- a/src/core/lv_obj_style.c +++ b/src/core/lv_obj_style.c @@ -357,7 +357,11 @@ _lv_style_state_cmp_t _lv_obj_style_state_compare(lv_obj_t * obj, lv_state_t sta else if(lv_style_get_prop(style, LV_STYLE_CONTENT_LETTER_SPACE, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; else if(lv_style_get_prop(style, LV_STYLE_CONTENT_OPA, &v)) res = _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD; else { - if(res != _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) res = _LV_STYLE_STATE_CMP_DIFF_REDRAW; + if(res != _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD) { + if(res != _LV_STYLE_STATE_CMP_SAME && (obj->styles[i].part == LV_PART_MAIN || obj->styles[i].part != LV_PART_SCROLLBAR)) { + res = _LV_STYLE_STATE_CMP_DIFF_REDRAW; + } + } } } } diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 5c75fa1b8..8ea979563 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -124,6 +124,10 @@ typedef struct { lv_style_t msgbox_btns_bg; #endif +#if LV_USE_KEYBOARD + lv_style_t keyboard_btn_bg; +#endif + #if LV_USE_LIST lv_style_t list_bg, list_btn, list_item_grow, list_label; #endif @@ -253,7 +257,7 @@ static void style_init(void) lv_style_set_outline_opa(&styles->outline_primary, LV_OPA_50); style_init_reset(&styles->outline_secondary); - lv_style_set_outline_color(&styles->outline_secondary, color_secondary_muted); + lv_style_set_outline_color(&styles->outline_secondary, color_secondary_accent); lv_style_set_outline_width(&styles->outline_secondary, OUTLINE_WIDTH); lv_style_set_outline_opa(&styles->outline_secondary, LV_OPA_50); @@ -475,6 +479,11 @@ static void style_init(void) style_init_reset(&styles->msgbox_btns_bg); lv_style_set_pad_all(&styles->msgbox_btns_bg, OUTLINE_WIDTH); #endif +#if LV_USE_KEYBOARD + style_init_reset(&styles->keyboard_btn_bg); + lv_style_set_shadow_width(&styles->keyboard_btn_bg, 0); + lv_style_set_radius(&styles->keyboard_btn_bg, disp_size == DISP_SMALL ? RADIUS_DEFAULT / 2 : RADIUS_DEFAULT); +#endif #if LV_USE_TABVIEW style_init_reset(&styles->tab_btn); @@ -650,10 +659,12 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #endif lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_FOCUS_KEY, &styles->outline_primary); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_EDITED, &styles->outline_secondary); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn); 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_primary); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_FOCUS_KEY, &styles->outline_primary); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_EDITED, &styles->outline_secondary); } #endif @@ -672,8 +683,6 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) else if(lv_obj_check_type(obj, &lv_slider_class)) { lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_primary_muted); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->circle); - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->transition_delayed); - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_PRESSED, &styles->transition_normal); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_FOCUS_KEY, &styles->outline_primary); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_EDITED, &styles->outline_secondary); lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->bg_color_primary); @@ -692,6 +701,8 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) 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->pad_zero); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->no_radius); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_FOCUS_KEY, &styles->outline_primary); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_EDITED, &styles->outline_secondary); 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); @@ -825,6 +836,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DISABLED, &styles->disabled); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_FOCUS_KEY, &styles->outline_primary); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_EDITED, &styles->outline_secondary); } #endif @@ -836,6 +848,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_EDITED, &styles->outline_secondary); 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->keyboard_btn_bg); 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_grey); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_FOCUSED, &styles->outline_primary); diff --git a/src/widgets/lv_chart.c b/src/widgets/lv_chart.c index 9823569f4..798e466ad 100644 --- a/src/widgets/lv_chart.c +++ b/src/widgets/lv_chart.c @@ -640,6 +640,7 @@ static void lv_chart_event(lv_obj_t * obj, lv_event_t e) lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); } } else if(e == LV_EVENT_RELEASED) { + invalidate_point(obj, chart->pressed_point_id); chart->pressed_point_id = LV_CHART_POINT_NONE; } else if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) { lv_coord_t * s = lv_event_get_param(); @@ -919,7 +920,6 @@ static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area) lv_obj_draw_dsc_init(&dsc, &series_mask); dsc.part = LV_PART_ITEMS; - /*Go through all points*/ for(i = 0; i < chart->point_cnt; i++) { lv_coord_t x_act = (int32_t)((int32_t)(w + block_gap) * i) / (chart->point_cnt) + obj->coords.x1 + x_ofs; @@ -1276,13 +1276,13 @@ static uint32_t get_index_from_x(lv_obj_t * obj, lv_coord_t x) static void invalidate_point(lv_obj_t * obj, uint16_t i) { - /*FIXME*/ lv_chart_t * chart = (lv_chart_t *)obj; if(i >= chart->point_cnt) return; - lv_coord_t w = lv_obj_get_width(obj); + lv_coord_t w = (lv_obj_get_width_fit(obj) * chart->zoom_x) >> 8; + lv_coord_t scroll_left = lv_obj_get_scroll_left(obj); if(chart->type == LV_CHART_TYPE_LINE) { - lv_coord_t x_ofs = obj->coords.x1; + lv_coord_t x_ofs = obj->coords.x1 + lv_obj_get_style_pad_left(obj, LV_PART_MAIN) - scroll_left; lv_coord_t line_width = lv_obj_get_style_line_width(obj, LV_PART_ITEMS); lv_coord_t point_radius = lv_obj_get_style_size(obj, LV_PART_ITEMS); @@ -1305,18 +1305,19 @@ static void invalidate_point(lv_obj_t * obj, uint16_t i) } else if(chart->type == LV_CHART_TYPE_BAR) { lv_area_t col_a; - lv_coord_t col_w = w / ((_lv_ll_get_len(&chart->series_ll) + 1) * chart->point_cnt); /*Suppose + 1 series as separator*/ - lv_coord_t x_ofs = col_w / 2; /*Shift with a half col.*/ + int32_t block_gap = (lv_obj_get_style_pad_column(obj, LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ + lv_coord_t block_w = (w + block_gap) / chart->point_cnt; lv_coord_t x_act; - x_act = (int32_t)((int32_t)w * i) / chart->point_cnt; - x_act += obj->coords.x1 + x_ofs; + x_act = (int32_t)((int32_t)(block_w) * i) ; + x_act += obj->coords.x1 + lv_obj_get_style_pad_left(obj, LV_PART_MAIN); lv_obj_get_coords(obj, &col_a); - col_a.x1 = x_act; - col_a.x2 = col_a.x1 + col_w; + col_a.x1 = x_act - scroll_left; + col_a.x2 = col_a.x1 + block_w; + col_a.x1 -= block_gap; - _lv_inv_area(lv_obj_get_disp(obj), &col_a); + lv_obj_invalidate_area(obj, &col_a); } else { lv_obj_invalidate(obj); } diff --git a/src/widgets/lv_table.c b/src/widgets/lv_table.c index f2bde97b5..6df8fca05 100644 --- a/src/widgets/lv_table.c +++ b/src/widgets/lv_table.c @@ -47,6 +47,7 @@ const lv_obj_class_t lv_table_class = { .destructor_cb = lv_table_destructor, .event_cb = lv_table_event, .base_class = &lv_obj_class, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, .instance_size = sizeof(lv_table_t), }; /********************** @@ -474,44 +475,65 @@ static void lv_table_event(lv_obj_t * obj, lv_event_t e) else if(e == LV_EVENT_PRESSED || e == LV_EVENT_PRESSING) { uint16_t col; uint16_t row; - get_pressed_cell(obj, &row, &col); + lv_res_t res = get_pressed_cell(obj, &row, &col); - if(table->col_act != col || table->row_act != row) { + if(res == LV_RES_OK && (table->col_act != col || table->row_act != row)) { table->col_act = col; table->row_act = row; - lv_obj_invalidate(obj); } + lv_obj_invalidate(obj); } else if(e == LV_EVENT_RELEASED) { + lv_obj_invalidate(obj); lv_indev_t * indev = lv_indev_get_act(); lv_obj_t * scroll_obj = lv_indev_get_scroll_obj(indev); - if(table->col_act != 0xFFFF && table->row_act != 0xFFFF && scroll_obj == NULL) { + if(table->col_act != LV_TABLE_CELL_NONE && table->row_act != LV_TABLE_CELL_NONE && scroll_obj == NULL) { res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return; } lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); if(indev_type == LV_INDEV_TYPE_POINTER || indev_type == LV_INDEV_TYPE_BUTTON) { - table->col_act = 0xFFFF; - table->row_act = 0xFFFF; - lv_obj_invalidate(obj); + table->col_act = LV_TABLE_CELL_NONE; + table->row_act = LV_TABLE_CELL_NONE; } } - else if(e == LV_EVENT_KEY) { + else if(e == LV_EVENT_FOCUSED) { + lv_obj_invalidate(obj); + } else if(e == LV_EVENT_KEY) { int32_t c = *((int32_t *)lv_event_get_param()); int32_t col = table->col_act; int32_t row = table->row_act; + if(col == LV_TABLE_CELL_NONE || row == LV_TABLE_CELL_NONE) { + table->col_act = 0; + table->row_act = 0; + lv_obj_invalidate(obj); + return; + } + + if(col >= table->col_cnt) col = 0; + if(row >= table->row_cnt) row = 0; + if(c == LV_KEY_LEFT) col--; else if(c == LV_KEY_RIGHT) col++; else if(c == LV_KEY_UP) row--; else if(c == LV_KEY_DOWN) row++; + else return; if(col >= table->col_cnt) { - col = 0; - row++; + if(row < table->row_cnt) { + col = 0; + row++; + } else { + col = table->col_cnt - 1; + } } else if (col < 0) { - col = table->col_cnt - 1; - row--; + if(row != 0) { + col = table->col_cnt - 1; + row--; + } else { + col = 0; + } } if(row >= table->row_cnt) { @@ -803,8 +825,8 @@ static lv_res_t get_pressed_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col) lv_indev_type_t type = lv_indev_get_type(lv_indev_get_act()); if(type != LV_INDEV_TYPE_POINTER && type != LV_INDEV_TYPE_BUTTON) { - if(col) *col = 0xFFFF; - if(row) *row = 0xFFFF; + if(col) *col = LV_TABLE_CELL_NONE; + if(row) *row = LV_TABLE_CELL_NONE; return LV_RES_INV; }