From 36369325e725cea19147bc785591f15dc578375f Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 23 Sep 2018 23:27:28 +0200 Subject: [PATCH] minor fixes for better encoder support --- lv_core/lv_group.c | 2 +- lv_core/lv_group.h | 2 +- lv_core/lv_indev.c | 3 ++- lv_objx/lv_bar.c | 35 ++++++++++++++++++++++++++++++++--- lv_objx/lv_ddlist.c | 8 +++++++- lv_objx/lv_page.c | 4 ++-- lv_objx/lv_slider.c | 37 ++++++++++++++++++++++++++++++++++--- lv_objx/lv_sw.c | 2 +- 8 files changed, 80 insertions(+), 13 deletions(-) diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index b2d6f4c93..7d4910aa2 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -394,7 +394,7 @@ lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group) * @param group pointer to group * @return true editing is enabled */ -bool lv_group_get_edit_enable(const lv_group_t * group, bool en) +bool lv_group_get_edit_enable(const lv_group_t * group) { return group->edit_mode_en ? true : false; } diff --git a/lv_core/lv_group.h b/lv_core/lv_group.h index 27b02e074..f60d6536c 100644 --- a/lv_core/lv_group.h +++ b/lv_core/lv_group.h @@ -208,7 +208,7 @@ lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group); * @param group pointer to group * @return true editing is enabled */ -bool lv_group_get_edit_enable(const lv_group_t * group, bool en); +bool lv_group_get_edit_enable(const lv_group_t * group); /** * Get the current mode (edit or navigate). diff --git a/lv_core/lv_indev.c b/lv_core/lv_indev.c index 3f9b82511..23a03a1e5 100644 --- a/lv_core/lv_indev.c +++ b/lv_core/lv_indev.c @@ -366,13 +366,14 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) i->proc.long_pr_sent == 0 && lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME ) { - /*If edit mode is enabled and the focused obejct is editable then change between edit and navigate on long press*/ + /*If edit mode is enabled and the focused obeject is editable then change between edit and navigate on long press*/ lv_obj_t * focused = lv_group_get_focused(i->group); bool editable = false; focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable); if (i->group->edit_mode_en && editable) { i->group->editing = i->group->editing ? 0 : 1; + focused->signal_func(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again. Some object do something on navigate->edit change*/ LV_LOG_INFO("Edit mode changed"); if(focused) lv_obj_invalidate(focused); } diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index 958f746ba..46e754ee0 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -283,10 +283,25 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode { if(mode == LV_DESIGN_COVER_CHK) { /*Return false if the object is not covers the mask area*/ - return ancestor_design_f(bar, mask, mode);; + return ancestor_design_f(bar, mask, mode); } else if(mode == LV_DESIGN_DRAW_MAIN) { - ancestor_design_f(bar, mask, mode); + lv_opa_t opa_scale = lv_obj_get_opa_scale(bar); +#if USE_LV_GROUP == 0 + ancestor_design_f(bar, mask, mode); +#else + /* Draw the borders later if the bar is focused. + * At value = 100% the indicator can cover to whole background and the focused style won't be visible*/ + if(lv_obj_is_focused(bar)) { + lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG); + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.border.width = 0; + lv_draw_rect(&bar->coords, mask, &style_tmp, opa_scale); + } else { + ancestor_design_f(bar, mask, mode); + } +#endif lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); if(ext->cur_value != ext->min_value) { @@ -310,8 +325,22 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode } /*Draw the indicator*/ - lv_draw_rect(&indic_area, mask, style_indic, lv_obj_get_opa_scale(bar)); + lv_draw_rect(&indic_area, mask, style_indic, opa_scale); } + }else if(mode == LV_DESIGN_DRAW_POST) { +#if USE_LV_GROUP + /*Draw the border*/ + if(lv_obj_is_focused(bar)) { + lv_opa_t opa_scale = lv_obj_get_opa_scale(bar); + lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG); + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.empty = 1; + style_tmp.body.shadow.width = 0; + lv_draw_rect(&bar->coords, mask, &style_tmp, opa_scale); + } +#endif + } return true; } diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 64c22fe4c..a3936b0c9 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -526,7 +526,13 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par } else if(sign == LV_SIGNAL_CLEANUP) { ext->label = NULL; } else if(sign == LV_SIGNAL_FOCUS) { - if(ext->opened == false) { + + /*Open the list if editing*/ + lv_group_t * g = lv_obj_get_group(ddlist); + bool editing = true; + if(lv_group_get_edit_enable(g)) editing = lv_group_get_editing(g); + + if(ext->opened == false && editing) { ext->opened = true; lv_ddlist_refr_size(ddlist, true); ext->sel_opt_id_ori = ext->sel_opt_id; diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index aac73fe28..c24988308 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -557,9 +557,9 @@ static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mo return ancestor_design(scrl, mask, mode); } else if(mode == LV_DESIGN_DRAW_MAIN) { #if USE_LV_GROUP - /* If the page is the active in a group and + /* If the page is focused in a group and * the background (page) is not visible (transparent or empty) - * then activate the style of the scrollable*/ + * then "activate" the style of the scrollable*/ lv_style_t * style_ori = lv_obj_get_style(scrl); lv_obj_t * page = lv_obj_get_parent(scrl); lv_style_t * style_page = lv_obj_get_style(page); diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index 17e53b5ac..143d83568 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -269,6 +269,8 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig lv_style_t * style_knob = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB); lv_style_t * style_indic = lv_slider_get_style(slider, LV_SLIDER_STYLE_INDIC); + lv_opa_t opa_scale = lv_obj_get_opa_scale(slider); + lv_coord_t slider_w = lv_area_get_width(&slider->coords); lv_coord_t slider_h = lv_area_get_height(&slider->coords); @@ -301,7 +303,23 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig area_bg.y1 += slider_w > slider_h ? pad_ver_bg : 0; /*Pad only for horizontal slider*/ area_bg.y2 -= slider_w > slider_h ? pad_ver_bg : 0; /*Pad only for horizontal slider*/ } + + +#if USE_LV_GROUP == 0 lv_draw_rect(&area_bg, mask, style_bg, lv_obj_get_opa_scale(slider)); +#else + /* Draw the borders later if the bar is focused. + * At value = 100% the indicator can cover to whole background and the focused style won't be visible*/ + if(lv_obj_is_focused(slider)) { + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.border.width = 0; + lv_draw_rect(&area_bg, mask, &style_tmp, opa_scale); + } else { + lv_draw_rect(&area_bg, mask, style_bg, opa_scale); + } +#endif + /*Draw the indicator*/ lv_area_t area_indic; @@ -339,7 +357,20 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig area_indic.y1 = area_indic.y2 - area_indic.y1; } - if(cur_value != min_value) lv_draw_rect(&area_indic, mask, style_indic, lv_obj_get_opa_scale(slider)); + if(cur_value != min_value) lv_draw_rect(&area_indic, mask, style_indic, opa_scale); + + /*Before the knob add the border if required*/ +#if USE_LV_GROUP + /* Draw the borders later if the bar is focused. + * At value = 100% the indicator can cover to whole background and the focused style won't be visible*/ + if(lv_obj_is_focused(slider)) { + lv_style_t style_tmp; + lv_style_copy(&style_tmp, style_bg); + style_tmp.body.empty = 1; + style_tmp.body.shadow.width = 0; + lv_draw_rect(&area_bg, mask, &style_tmp, opa_scale); + } +#endif /*Draw the knob*/ lv_area_t knob_area; @@ -371,7 +402,7 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig } - lv_draw_rect(&knob_area, mask, style_knob, lv_obj_get_opa_scale(slider)); + lv_draw_rect(&knob_area, mask, style_knob, opa_scale); } /*Post draw when the children are drawn*/ @@ -455,7 +486,7 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par } } else if(sign == LV_SIGNAL_CONTROLL) { char c = *((char *)param); - if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_ENTER) { lv_slider_set_value(slider, lv_slider_get_value(slider) + 1); if(ext->action != NULL) ext->action(slider); } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index a39021f42..941e1c05d 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -250,7 +250,7 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) char c = *((char *)param); if(c == LV_GROUP_KEY_ENTER) { - if(lv_sw_get_state(sw)) lv_sw_off(sw); + if(old_val) lv_sw_off(sw); else lv_sw_on(sw); if(slider_action) slider_action(sw);