diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index 027a6a47b0..ca72ea2b97 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -256,104 +256,101 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) /* Include the ancient signal function */ res = ancestor_signal(btn, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); - lv_btn_state_t state = lv_btn_get_state(btn); - bool tgl = lv_btn_get_toggle(btn); + lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn); + lv_btn_state_t state = lv_btn_get_state(btn); + bool tgl = lv_btn_get_toggle(btn); - if(sign == LV_SIGNAL_PRESSED) { - /*Refresh the state*/ - if(ext->state == LV_BTN_STATE_RELEASED) { - lv_btn_set_state(btn, LV_BTN_STATE_PRESSED); - } else if(ext->state == LV_BTN_STATE_TGL_RELEASED) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_PRESSED); - } - - ext->long_press_action_executed = 0; - /*Call the press action, 'param' is the caller indev_proc*/ - if(ext->actions[LV_BTN_ACTION_PRESS] && state != LV_BTN_STATE_INACTIVE) { - res = ext->actions[LV_BTN_ACTION_PRESS](btn); - } + if(sign == LV_SIGNAL_PRESSED) { + /*Refresh the state*/ + if(ext->state == LV_BTN_STATE_RELEASED) { + lv_btn_set_state(btn, LV_BTN_STATE_PRESSED); + } else if(ext->state == LV_BTN_STATE_TGL_RELEASED) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_PRESSED); } - else if(sign == LV_SIGNAL_PRESS_LOST) { - /*Refresh the state*/ + + ext->long_press_action_executed = 0; + /*Call the press action, 'param' is the caller indev_proc*/ + if(ext->actions[LV_BTN_ACTION_PRESS] && state != LV_BTN_STATE_INACTIVE) { + res = ext->actions[LV_BTN_ACTION_PRESS](btn); + } + } + else if(sign == LV_SIGNAL_PRESS_LOST) { + /*Refresh the state*/ + if(ext->state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + else if(ext->state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); + } + else if(sign == LV_SIGNAL_PRESSING) { + /*When the button begins to drag revert pressed states to released*/ + if(lv_indev_is_dragging(param) != false) { if(ext->state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); else if(ext->state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); } - else if(sign == LV_SIGNAL_PRESSING) { - /*When the button begins to drag revert pressed states to released*/ - if(lv_indev_is_dragging(param) != false) { - if(ext->state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - else if(ext->state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); + } + else if(sign == LV_SIGNAL_RELEASED) { + /*If not dragged and it was not long press action then + *change state and run the action*/ + if(lv_indev_is_dragging(param) == false && ext->long_press_action_executed == 0) { + if(ext->state == LV_BTN_STATE_PRESSED && tgl == false) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + } else if(ext->state == LV_BTN_STATE_TGL_PRESSED && tgl == false) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); + } else if(ext->state == LV_BTN_STATE_PRESSED && tgl == true) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); + } else if(ext->state == LV_BTN_STATE_TGL_PRESSED && tgl == true) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); } - } - else if(sign == LV_SIGNAL_RELEASED) { - /*If not dragged and it was not long press action then - *change state and run the action*/ - if(lv_indev_is_dragging(param) == false && ext->long_press_action_executed == 0) { - if(ext->state == LV_BTN_STATE_PRESSED && tgl == false) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - } else if(ext->state == LV_BTN_STATE_TGL_PRESSED && tgl == false) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); - } else if(ext->state == LV_BTN_STATE_PRESSED && tgl == true) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); - } else if(ext->state == LV_BTN_STATE_TGL_PRESSED && tgl == true) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - } - if(ext->actions[LV_BTN_ACTION_RELEASE] && state != LV_BTN_STATE_INACTIVE) { - res = ext->actions[LV_BTN_ACTION_RELEASE](btn); - } - } else { /*If dragged change back the state*/ - if(ext->state == LV_BTN_STATE_PRESSED) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - } else if(ext->state == LV_BTN_STATE_TGL_PRESSED) { - lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); - } + if(ext->actions[LV_BTN_ACTION_RELEASE] && state != LV_BTN_STATE_INACTIVE) { + res = ext->actions[LV_BTN_ACTION_RELEASE](btn); + } + } else { /*If dragged change back the state*/ + if(ext->state == LV_BTN_STATE_PRESSED) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + } else if(ext->state == LV_BTN_STATE_TGL_PRESSED) { + lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); } } - else if(sign == LV_SIGNAL_LONG_PRESS) { - if(ext->actions[LV_BTN_ACTION_LONG_PRESS] && state != LV_BTN_STATE_INACTIVE) { - ext->long_press_action_executed = 1; - res = ext->actions[LV_BTN_ACTION_LONG_PRESS](btn); - } - } - else if(sign == LV_SIGNAL_LONG_PRESS_REP) { - if(ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE] && state != LV_BTN_STATE_INACTIVE) { - res = ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE](btn); + } + else if(sign == LV_SIGNAL_LONG_PRESS) { + if(ext->actions[LV_BTN_ACTION_LONG_PRESS] && state != LV_BTN_STATE_INACTIVE) { + ext->long_press_action_executed = 1; + res = ext->actions[LV_BTN_ACTION_LONG_PRESS](btn); } + } + else if(sign == LV_SIGNAL_LONG_PRESS_REP) { + if(ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE] && state != LV_BTN_STATE_INACTIVE) { + res = ext->actions[LV_BTN_ACTION_LONG_PRESS_REPEATE](btn); } - else if(sign == LV_SIGNAL_CONTROLL) { - char c = *((char*)param); - if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { - if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); - if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) { - res = ext->actions[LV_BTN_ACTION_RELEASE](btn); - } - } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { - if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) { - res = ext->actions[LV_BTN_ACTION_RELEASE](btn); - } - } else if(c == LV_GROUP_KEY_ENTER) { - if(lv_btn_get_toggle(btn) != false) { - lv_btn_state_t state = lv_btn_get_state(btn); - if(state == LV_BTN_STATE_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); - else if(state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_PRESSED); - else if(state == LV_BTN_STATE_TGL_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - else if(state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_PRESSED); - } - if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) { - res = ext->actions[LV_BTN_ACTION_RELEASE](btn); - } + } + else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char*)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { + if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); + if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) { + res = ext->actions[LV_BTN_ACTION_RELEASE](btn); + } + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { + if(lv_btn_get_toggle(btn) != false) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) { + res = ext->actions[LV_BTN_ACTION_RELEASE](btn); + } + } else if(c == LV_GROUP_KEY_ENTER) { + if(lv_btn_get_toggle(btn) != false) { + lv_btn_state_t state = lv_btn_get_state(btn); + if(state == LV_BTN_STATE_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_RELEASED); + else if(state == LV_BTN_STATE_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_TGL_PRESSED); + else if(state == LV_BTN_STATE_TGL_RELEASED) lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + else if(state == LV_BTN_STATE_TGL_PRESSED) lv_btn_set_state(btn, LV_BTN_STATE_PRESSED); + } + if(ext->actions[LV_BTN_ACTION_RELEASE] && lv_btn_get_state(btn) != LV_BTN_STATE_INACTIVE) { + res = ext->actions[LV_BTN_ACTION_RELEASE](btn); } } } - return res; + return LV_RES_OK; } diff --git a/lv_objx/lv_cb.c b/lv_objx/lv_cb.c index d980149e8c..60424650c9 100644 --- a/lv_objx/lv_cb.c +++ b/lv_objx/lv_cb.c @@ -241,31 +241,28 @@ static lv_res_t lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param) /* Include the ancient signal function */ res = ancestor_signal(cb, sign, param); + if(res != LV_RES_OK) return res; lv_cb_ext_t * ext = lv_obj_get_ext_attr(cb); lv_style_t * style = lv_obj_get_style(cb); - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - if(sign == LV_SIGNAL_STYLE_CHG) { - lv_obj_set_size(ext->bullet, font_get_height(style->text.font), font_get_height(style->text.font)); + if(sign == LV_SIGNAL_STYLE_CHG) { + lv_obj_set_size(ext->bullet, font_get_height(style->text.font), font_get_height(style->text.font)); + lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); + } else if(sign == LV_SIGNAL_PRESSED || + sign == LV_SIGNAL_RELEASED || + sign == LV_SIGNAL_PRESS_LOST) { + lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); + } else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char*)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN || + c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP || + c == LV_GROUP_KEY_ENTER) { lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); - } else if(sign == LV_SIGNAL_PRESSED || - sign == LV_SIGNAL_RELEASED || - sign == LV_SIGNAL_PRESS_LOST) { - lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); - } else if(sign == LV_SIGNAL_CONTROLL) { - char c = *((char*)param); - if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN || - c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP || - c == LV_GROUP_KEY_ENTER) { - lv_btn_set_state(ext->bullet, lv_btn_get_state(cb)); - } } } - return res; + return LV_RES_OK; } #endif diff --git a/lv_objx/lv_cont.c b/lv_objx/lv_cont.c index 3cdb99bf8f..bb7a9b8b61 100644 --- a/lv_objx/lv_cont.c +++ b/lv_objx/lv_cont.c @@ -191,26 +191,23 @@ static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param) /* Include the ancient signal function */ res = ancestor_signal(cont, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/ + if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/ + lv_cont_refr_layout(cont); + lv_cont_refr_autofit(cont); + } else if(sign == LV_SIGNAL_CHILD_CHG) { + lv_cont_refr_layout(cont); + lv_cont_refr_autofit(cont); + } else if(sign == LV_SIGNAL_CORD_CHG) { + if(lv_obj_get_width(cont) != area_get_width(param) || + lv_obj_get_height(cont) != area_get_height(param)) { lv_cont_refr_layout(cont); lv_cont_refr_autofit(cont); - } else if(sign == LV_SIGNAL_CHILD_CHG) { - lv_cont_refr_layout(cont); - lv_cont_refr_autofit(cont); - } else if(sign == LV_SIGNAL_CORD_CHG) { - if(lv_obj_get_width(cont) != area_get_width(param) || - lv_obj_get_height(cont) != area_get_height(param)) { - lv_cont_refr_layout(cont); - lv_cont_refr_autofit(cont); - } } } - return res; + return LV_RES_OK; } diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index b5eb5f2b77..93f094ca97 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -29,6 +29,7 @@ * STATIC PROTOTYPES **********************/ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_mode_t mode); +lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param); static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); static lv_res_t lv_ddlist_rel_action(lv_obj_t * ddlist); static void lv_ddlist_refr_size(lv_obj_t * ddlist, uint16_t anim_time); @@ -118,70 +119,6 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) return new_ddlist; } -/** - * Signal function of the drop down list - * @param ddlist pointer to a drop down list object - * @param sign a signal type from lv_signal_t enum - * @param param pointer to a signal specific variable - * @return true: the object is still valid (not deleted), false: the object become invalid - */ -bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) -{ - bool valid; - - /* Include the ancient signal function */ - valid = ancestor_signal(ddlist, sign, param); - - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(valid != false) { - if(sign == LV_SIGNAL_STYLE_CHG) { - lv_ddlist_refr_size(ddlist, 0); - lv_obj_t *scrl = lv_page_get_scrl(ddlist); - lv_obj_refresh_ext_size(scrl); /*Because of the wider selected rectangle*/ - } else if(sign == LV_SIGNAL_FOCUS) { - lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - if(ext->opened == false) { - ext->opened = true; - lv_ddlist_refr_size(ddlist, true); - } - } else if(sign == LV_SIGNAL_DEFOCUS) { - lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - if(ext->opened != false) { - ext->opened = false; - lv_ddlist_refr_size(ddlist, true); - } - } else if(sign == LV_SIGNAL_CONTROLL) { - lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - char c = *((char*)param); - if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { - if(ext->selected_option_id +1 < ext->option_cnt) { - ext->selected_option_id ++; - lv_obj_invalidate(ddlist); - if(ext->callback != NULL) { - ext->callback(ddlist); - } - } - } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) { - if(ext->selected_option_id > 0) { - ext->selected_option_id --; - lv_obj_invalidate(ddlist); - if(ext->callback != NULL) { - ext->callback(ddlist); - } - } - } else if(c == LV_GROUP_KEY_ENTER || c == LV_GROUP_KEY_ESC) { - if(ext->opened != false) ext->opened = false; - if(ext->opened == false) ext->opened = true; - - lv_ddlist_refr_size(ddlist, true); - } - } - } - - return valid; -} - /*===================== * Setter functions *====================*/ @@ -451,6 +388,69 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const area_t * mask, lv_design_m return true; } +/** + * Signal function of the drop down list + * @param ddlist pointer to a drop down list object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) +{ + lv_res_t res; + /* Include the ancient signal function */ + res = ancestor_signal(ddlist, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_STYLE_CHG) { + lv_ddlist_refr_size(ddlist, 0); + lv_obj_t *scrl = lv_page_get_scrl(ddlist); + lv_obj_refresh_ext_size(scrl); /*Because of the wider selected rectangle*/ + } + else if(sign == LV_SIGNAL_FOCUS) { + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + if(ext->opened == false) { + ext->opened = true; + lv_ddlist_refr_size(ddlist, true); + } + } + else if(sign == LV_SIGNAL_DEFOCUS) { + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + if(ext->opened != false) { + ext->opened = false; + lv_ddlist_refr_size(ddlist, true); + } + } + else if(sign == LV_SIGNAL_CONTROLL) { + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + char c = *((char*)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { + if(ext->selected_option_id +1 < ext->option_cnt) { + ext->selected_option_id ++; + lv_obj_invalidate(ddlist); + if(ext->callback != NULL) { + ext->callback(ddlist); + } + } + } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) { + if(ext->selected_option_id > 0) { + ext->selected_option_id --; + lv_obj_invalidate(ddlist); + if(ext->callback != NULL) { + ext->callback(ddlist); + } + } + } else if(c == LV_GROUP_KEY_ENTER || c == LV_GROUP_KEY_ESC) { + if(ext->opened != false) ext->opened = false; + if(ext->opened == false) ext->opened = true; + + lv_ddlist_refr_size(ddlist, true); + } + } + + return res; +} + /** * Signal function of the drop down list's scrollable part * @param scrl pointer to a drop down list's scrollable part @@ -464,17 +464,14 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * /* Include the ancient signal function */ res = ancestor_scrl_signal(scrl, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res != false) { - if(sign == LV_SIGNAL_REFR_EXT_SIZE) { - /* Because of the wider selected rectangle ext. size - * In this way by dragging the scrollable part the wider rectangle area can be redrawn too*/ - lv_obj_t *ddlist = lv_obj_get_parent(scrl); - lv_style_t *style = lv_ddlist_get_style_bg(ddlist); - if(scrl->ext_size < style->body.padding.hor) scrl->ext_size = style->body.padding.hor; - } + if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + /* Because of the wider selected rectangle ext. size + * In this way by dragging the scrollable part the wider rectangle area can be redrawn too*/ + lv_obj_t *ddlist = lv_obj_get_parent(scrl); + lv_style_t *style = lv_ddlist_get_style_bg(ddlist); + if(scrl->ext_size < style->body.padding.hor) scrl->ext_size = style->body.padding.hor; } return res; diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index 01c3af4828..8a5dfc88c9 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -64,15 +64,6 @@ typedef struct */ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy); -/** - * Signal function of the drop down list - * @param ddlist pointer to a drop down list object - * @param sign a signal type from lv_signal_t enum - * @param param pointer to a signal specific variable - * @return true: the object is still valid (not deleted), false: the object become invalid - */ -bool lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param); - /** * Set the options in a drop down list from a string * @param ddlist pointer to drop down list object diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 329e59e2fb..38d051da18 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -406,35 +406,84 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) /* Include the ancient signal function */ res = ancestor_signal(list, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - if(sign == LV_SIGNAL_CORD_CHG) { - /*Be sure the width of the buttons are correct*/ - cord_t w = lv_obj_get_width(list); - if(w != area_get_width(param)) { /*Width changed*/ - refr_btn_width(list); - } + if(sign == LV_SIGNAL_CORD_CHG) { + /*Be sure the width of the buttons are correct*/ + cord_t w = lv_obj_get_width(list); + if(w != area_get_width(param)) { /*Width changed*/ + refr_btn_width(list); } - else if(sign == LV_SIGNAL_STYLE_CHG) { - /*Because of the possible change of horizontal and vertical padding refresh buttons width */ - refr_btn_width(list); + } + else if(sign == LV_SIGNAL_STYLE_CHG) { + /*Because of the possible change of horizontal and vertical padding refresh buttons width */ + refr_btn_width(list); + } + else if(sign == LV_SIGNAL_FOCUS) { + /*Get the first button*/ + lv_obj_t * btn = NULL; + lv_obj_t * btn_prev = NULL; + btn = get_next_btn(list, btn); + while(btn != NULL) { + btn_prev = btn; + btn = get_next_btn(list, btn); } - else if(sign == LV_SIGNAL_FOCUS) { - /*Get the first button*/ + if(btn_prev != NULL) { + lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); + } + } + else if(sign == LV_SIGNAL_DEFOCUS) { + /*Get the 'pressed' button*/ + lv_obj_t * btn = NULL; + btn = get_next_btn(list, btn); + while(btn != NULL) { + if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; + btn = get_next_btn(list, btn); + } + + if(btn != NULL) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + } + } + else if(sign == LV_SIGNAL_CONTROLL) { + char c = *((char*)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { + /*Get the last pressed button*/ lv_obj_t * btn = NULL; lv_obj_t * btn_prev = NULL; + lv_list_ext_t *ext = lv_obj_get_ext_attr(list); btn = get_next_btn(list, btn); while(btn != NULL) { + if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; btn_prev = btn; btn = get_next_btn(list, btn); } - if(btn_prev != NULL) { + + if(btn_prev != NULL && btn != NULL) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); + lv_page_focus(list, btn_prev, ext->anim_time); } } - else if(sign == LV_SIGNAL_DEFOCUS) { + else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) { + /*Get the last pressed button*/ + lv_obj_t * btn = NULL; + lv_list_ext_t *ext = lv_obj_get_ext_attr(list); + btn = get_next_btn(list, btn); + while(btn != NULL) { + if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; + btn = get_next_btn(list, btn); + } + + if(btn != NULL) { + lv_obj_t * btn_prev = get_next_btn(list, btn); + if(btn_prev != NULL) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); + lv_page_focus(list, btn_prev, ext->anim_time); + } + } + } else if(c == LV_GROUP_KEY_ENTER) { /*Get the 'pressed' button*/ lv_obj_t * btn = NULL; btn = get_next_btn(list, btn); @@ -444,65 +493,13 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) } if(btn != NULL) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - } - } - else if(sign == LV_SIGNAL_CONTROLL) { - char c = *((char*)param); - if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_DOWN) { - /*Get the last pressed button*/ - lv_obj_t * btn = NULL; - lv_obj_t * btn_prev = NULL; - lv_list_ext_t *ext = lv_obj_get_ext_attr(list); - btn = get_next_btn(list, btn); - while(btn != NULL) { - if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; - btn_prev = btn; - btn = get_next_btn(list, btn); - } - - if(btn_prev != NULL && btn != NULL) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); - lv_page_focus(list, btn_prev, ext->anim_time); - } - } - else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_UP) { - /*Get the last pressed button*/ - lv_obj_t * btn = NULL; - lv_list_ext_t *ext = lv_obj_get_ext_attr(list); - btn = get_next_btn(list, btn); - while(btn != NULL) { - if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; - btn = get_next_btn(list, btn); - } - - if(btn != NULL) { - lv_obj_t * btn_prev = get_next_btn(list, btn); - if(btn_prev != NULL) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); - lv_page_focus(list, btn_prev, ext->anim_time); - } - } - } else if(c == LV_GROUP_KEY_ENTER) { - /*Get the 'pressed' button*/ - lv_obj_t * btn = NULL; - btn = get_next_btn(list, btn); - while(btn != NULL) { - if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; - btn = get_next_btn(list, btn); - } - - if(btn != NULL) { - lv_action_t rel_action; - rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_RELEASE); - if(rel_action != NULL) rel_action(btn); - } + lv_action_t rel_action; + rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_RELEASE); + if(rel_action != NULL) rel_action(btn); } } } - return res; + return LV_RES_OK; } /** diff --git a/lv_objx/lv_mbox.c b/lv_objx/lv_mbox.c index 6a83c97398..03e0e9cdff 100644 --- a/lv_objx/lv_mbox.c +++ b/lv_objx/lv_mbox.c @@ -308,50 +308,84 @@ static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param) /* Include the ancient signal function */ res = ancestor_signal(mbox, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { + lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); + if(sign == LV_SIGNAL_CORD_CHG) { + if(lv_obj_get_width(mbox) != area_get_width(param)) { + btnh_resize(mbox); + } + } + if(sign == LV_SIGNAL_LONG_PRESS) { + lv_mbox_start_auto_close(mbox, 0); + lv_indev_wait_release(param); + res = LV_RES_INV; + } + else if(sign == LV_SIGNAL_STYLE_CHG) { + /*Refresh all the buttons*/ + if(ext->btnh != NULL) { + lv_obj_t * btn; + btn = lv_obj_get_child(ext->btnh, NULL); + while(btn != NULL) { + /*Refresh the next button's style*/ + lv_btn_set_style(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL); + btn = lv_obj_get_child(ext->btnh, btn); + } + } + } + else if(sign == LV_SIGNAL_FOCUS) { + /*Get the first button*/ + if(ext->btnh != NULL) { + lv_obj_t * btn = NULL; + lv_obj_t * btn_prev = NULL; + btn = lv_obj_get_child(ext->btnh, btn); + while(btn != NULL) { + btn_prev = btn; + btn = lv_obj_get_child(ext->btnh, btn); + } + if(btn_prev != NULL) { + lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); + } + } + } + else if(sign == LV_SIGNAL_DEFOCUS) { + /*Get the 'pressed' button*/ + if(ext->btnh != NULL) { + lv_obj_t * btn = NULL; + btn = lv_obj_get_child(ext->btnh, btn); + while(btn != NULL) { + if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; + btn = lv_obj_get_child(ext->btnh, btn); + } + + if(btn != NULL) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); + } + } + } + else if(sign == LV_SIGNAL_CONTROLL) { lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); - if(sign == LV_SIGNAL_CORD_CHG) { - if(lv_obj_get_width(mbox) != area_get_width(param)) { - btnh_resize(mbox); - } - } - if(sign == LV_SIGNAL_LONG_PRESS) { - lv_mbox_start_auto_close(mbox, 0); - lv_indev_wait_release(param); - res = LV_RES_INV; - } - else if(sign == LV_SIGNAL_STYLE_CHG) { - /*Refresh all the buttons*/ - if(ext->btnh != NULL) { - lv_obj_t * btn; - btn = lv_obj_get_child(ext->btnh, NULL); - while(btn != NULL) { - /*Refresh the next button's style*/ - lv_btn_set_style(btn, ext->style_btn_rel, ext->style_btn_pr, NULL, NULL, NULL); - btn = lv_obj_get_child(ext->btnh, btn); - } - } - } - else if(sign == LV_SIGNAL_FOCUS) { - /*Get the first button*/ + char c = *((char*)param); + if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { + /*Get the last pressed button*/ if(ext->btnh != NULL) { lv_obj_t * btn = NULL; lv_obj_t * btn_prev = NULL; btn = lv_obj_get_child(ext->btnh, btn); while(btn != NULL) { + if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; btn_prev = btn; btn = lv_obj_get_child(ext->btnh, btn); } - if(btn_prev != NULL) { + + if(btn_prev != NULL && btn != NULL) { + lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); } } } - else if(sign == LV_SIGNAL_DEFOCUS) { - /*Get the 'pressed' button*/ + else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { + /*Get the last pressed button*/ if(ext->btnh != NULL) { lv_obj_t * btn = NULL; btn = lv_obj_get_child(ext->btnh, btn); @@ -361,72 +395,35 @@ static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param) } if(btn != NULL) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - } - } - } - else if(sign == LV_SIGNAL_CONTROLL) { - lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox); - char c = *((char*)param); - if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { - /*Get the last pressed button*/ - if(ext->btnh != NULL) { - lv_obj_t * btn = NULL; - lv_obj_t * btn_prev = NULL; - btn = lv_obj_get_child(ext->btnh, btn); - while(btn != NULL) { - if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; - btn_prev = btn; - btn = lv_obj_get_child(ext->btnh, btn); - } - - if(btn_prev != NULL && btn != NULL) { + lv_obj_t * btn_prev = lv_obj_get_child(ext->btnh, btn); + if(btn_prev != NULL) { lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); } } - } - else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { - /*Get the last pressed button*/ - if(ext->btnh != NULL) { - lv_obj_t * btn = NULL; - btn = lv_obj_get_child(ext->btnh, btn); - while(btn != NULL) { - if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; - btn = lv_obj_get_child(ext->btnh, btn); - } - if(btn != NULL) { - lv_obj_t * btn_prev = lv_obj_get_child(ext->btnh, btn); - if(btn_prev != NULL) { - lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); - lv_btn_set_state(btn_prev, LV_BTN_STATE_PRESSED); - } - } - - } } - else if(c == LV_GROUP_KEY_ENTER) { - /*Get the 'pressed' button*/ - if(ext->btnh != NULL) { - lv_obj_t * btn = NULL; + } + else if(c == LV_GROUP_KEY_ENTER) { + /*Get the 'pressed' button*/ + if(ext->btnh != NULL) { + lv_obj_t * btn = NULL; + btn = lv_obj_get_child(ext->btnh, btn); + while(btn != NULL) { + if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; btn = lv_obj_get_child(ext->btnh, btn); - while(btn != NULL) { - if(lv_btn_get_state(btn) == LV_BTN_STATE_PRESSED) break; - btn = lv_obj_get_child(ext->btnh, btn); - } - - if(btn != NULL) { - lv_action_t rel_action; - rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_RELEASE); - if(rel_action != NULL) rel_action(btn); - } } - } + + if(btn != NULL) { + lv_action_t rel_action; + rel_action = lv_btn_get_action(btn, LV_BTN_ACTION_RELEASE); + if(rel_action != NULL) rel_action(btn); + } + } } } - return res; + return LV_RES_OK; } /** diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index e21f2fd3ff..c044bc475b 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -410,75 +410,72 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) /* Include the ancient signal function */ res = ancestor_signal(page, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - lv_page_ext_t * ext = lv_obj_get_ext_attr(page); - lv_style_t * style = lv_obj_get_style(page); - lv_obj_t * child; - if(sign == LV_SIGNAL_CHILD_CHG) { /*Automatically move children to the scrollable object*/ - child = lv_obj_get_child(page, NULL); - while(child != NULL) { - if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) { - lv_obj_t * tmp = child; - child = lv_obj_get_child(page, child); /*Get the next child before move this*/ - lv_obj_set_parent(tmp, ext->scrl); - } else { - child = lv_obj_get_child(page, child); - } + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + lv_style_t * style = lv_obj_get_style(page); + lv_obj_t * child; + if(sign == LV_SIGNAL_CHILD_CHG) { /*Automatically move children to the scrollable object*/ + child = lv_obj_get_child(page, NULL); + while(child != NULL) { + if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) { + lv_obj_t * tmp = child; + child = lv_obj_get_child(page, child); /*Get the next child before move this*/ + lv_obj_set_parent(tmp, ext->scrl); + } else { + child = lv_obj_get_child(page, child); } } - else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { + /*If no hor_fit enabled set the scrollable's width to the page's width*/ + if(lv_cont_get_hor_fit(ext->scrl) == false) { + lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor); + } else { + ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); + } + + /*The scrollbars are important only if they are visible now*/ + if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page); + + /*Refresh the ext. size because the scrollbars might be positioned out of the page*/ + lv_obj_refresh_ext_size(page); + } + else if(sign == LV_SIGNAL_CORD_CHG) { + /*Refresh the scrollbar and notify the scrl if the size is changed*/ + if(ext->scrl != NULL && (lv_obj_get_width(page) != area_get_width(param) || + lv_obj_get_height(page) != area_get_height(param))) + { /*If no hor_fit enabled set the scrollable's width to the page's width*/ if(lv_cont_get_hor_fit(ext->scrl) == false) { lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor); - } else { - ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); } + ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); + /*The scrollbars are important only if they are visible now*/ if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page); - - /*Refresh the ext. size because the scrollbars might be positioned out of the page*/ - lv_obj_refresh_ext_size(page); - } - else if(sign == LV_SIGNAL_CORD_CHG) { - /*Refresh the scrollbar and notify the scrl if the size is changed*/ - if(ext->scrl != NULL && (lv_obj_get_width(page) != area_get_width(param) || - lv_obj_get_height(page) != area_get_height(param))) - { - /*If no hor_fit enabled set the scrollable's width to the page's width*/ - if(lv_cont_get_hor_fit(ext->scrl) == false) { - lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor); - } - - ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); - - /*The scrollbars are important only if they are visible now*/ - if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page); - } - } - else if(sign == LV_SIGNAL_PRESSED) { - if(ext->pr_action != NULL) { - ext->pr_action(page); - } - } - else if(sign == LV_SIGNAL_RELEASED) { - if(lv_indev_is_dragging(lv_indev_get_act()) == false) { - if(ext->rel_action != NULL) { - ext->rel_action(page); - } - } - } - else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { - /*Ensure ext. size for the scrollbars if they are out of the page*/ - if(page->ext_size < (-ext->sb.style->body.padding.hor)) page->ext_size = -ext->sb.style->body.padding.hor; - if(page->ext_size < (-ext->sb.style->body.padding.ver)) page->ext_size = -ext->sb.style->body.padding.ver; } } + else if(sign == LV_SIGNAL_PRESSED) { + if(ext->pr_action != NULL) { + ext->pr_action(page); + } + } + else if(sign == LV_SIGNAL_RELEASED) { + if(lv_indev_is_dragging(lv_indev_get_act()) == false) { + if(ext->rel_action != NULL) { + ext->rel_action(page); + } + } + } + else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + /*Ensure ext. size for the scrollbars if they are out of the page*/ + if(page->ext_size < (-ext->sb.style->body.padding.hor)) page->ext_size = -ext->sb.style->body.padding.hor; + if(page->ext_size < (-ext->sb.style->body.padding.ver)) page->ext_size = -ext->sb.style->body.padding.ver; + } - return res; + return LV_RES_OK; } /** @@ -494,117 +491,113 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi /* Include the ancient signal function */ res = ancestor_signal(scrl, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res != false) { + lv_obj_t * page = lv_obj_get_parent(scrl); + lv_style_t * page_style = lv_obj_get_style(page); + lv_page_ext_t * page_ext = lv_obj_get_ext_attr(page); - lv_obj_t * page = lv_obj_get_parent(scrl); - lv_style_t * page_style = lv_obj_get_style(page); - lv_page_ext_t * page_ext = lv_obj_get_ext_attr(page); - - if(sign == LV_SIGNAL_CORD_CHG) { - /*Be sure the width of the scrollable is correct*/ - if(lv_cont_get_hor_fit(scrl) == false) { - lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * page_style->body.padding.hor); - } - - /*Limit the position of the scrollable object to be always visible - * (Do not let its edge inner then its parent respective edge)*/ - cord_t new_x; - cord_t new_y; - bool refr_x = false; - bool refr_y = false; - area_t page_cords; - area_t scrl_cords; - cord_t hpad = page_style->body.padding.hor; - cord_t vpad = page_style->body.padding.ver; - - new_x = lv_obj_get_x(scrl); - new_y = lv_obj_get_y(scrl); - lv_obj_get_coords(scrl, &scrl_cords); - lv_obj_get_coords(page, &page_cords); - - /*scrollable width smaller then page width? -> align to left*/ - if(area_get_width(&scrl_cords) + 2 * hpad < area_get_width(&page_cords)) { - if(scrl_cords.x1 != page_cords.x1 + hpad) { - new_x = hpad; - refr_x = true; - } - } else { - /*The edges of the scrollable can not be in the page (minus hpad) */ - if(scrl_cords.x2 < page_cords.x2 - hpad) { - new_x = area_get_width(&page_cords) - area_get_width(&scrl_cords) - hpad; /* Right align */ - refr_x = true; - } - if (scrl_cords.x1 > page_cords.x1 + hpad) { - new_x = hpad; /*Left align*/ - refr_x = true; - } - } - - /*scrollable height smaller then page height? -> align to left*/ - if(area_get_height(&scrl_cords) + 2 * vpad < area_get_height(&page_cords)) { - if(scrl_cords.y1 != page_cords.y1 + vpad) { - new_y = vpad; - refr_y = true; - } - } else { - /*The edges of the scrollable can not be in the page (minus vpad) */ - if(scrl_cords.y2 < page_cords.y2 - vpad) { - new_y = area_get_height(&page_cords) - area_get_height(&scrl_cords) - vpad; /* Bottom align */ - refr_y = true; - } - if (scrl_cords.y1 > page_cords.y1 + vpad) { - new_y = vpad; /*Top align*/ - refr_y = true; - } - } - if(refr_x != false || refr_y != false) { - lv_obj_set_pos(scrl, new_x, new_y); - } - - lv_page_sb_refresh(page); + if(sign == LV_SIGNAL_CORD_CHG) { + /*Be sure the width of the scrollable is correct*/ + if(lv_cont_get_hor_fit(scrl) == false) { + lv_obj_set_width(scrl, lv_obj_get_width(page) - 2 * page_style->body.padding.hor); } - else if(sign == LV_SIGNAL_DRAG_END) { - /*Hide scrollbars if required*/ - if(page_ext->sb.mode == LV_PAGE_SB_MODE_DRAG) { - area_t sb_area_tmp; - if(page_ext->sb.hor_draw) { - area_cpy(&sb_area_tmp, &page_ext->sb.hor_area); - sb_area_tmp.x1 += page->coords.x1; - sb_area_tmp.y1 += page->coords.y1; - sb_area_tmp.x2 += page->coords.x2; - sb_area_tmp.y2 += page->coords.y2; - lv_inv_area(&sb_area_tmp); - page_ext->sb.hor_draw = 0; - } - if(page_ext->sb.ver_draw) { - area_cpy(&sb_area_tmp, &page_ext->sb.ver_area); - sb_area_tmp.x1 += page->coords.x1; - sb_area_tmp.y1 += page->coords.y1; - sb_area_tmp.x2 += page->coords.x2; - sb_area_tmp.y2 += page->coords.y2; - lv_inv_area(&sb_area_tmp); - page_ext->sb.ver_draw = 0; - } + + /*Limit the position of the scrollable object to be always visible + * (Do not let its edge inner then its parent respective edge)*/ + cord_t new_x; + cord_t new_y; + bool refr_x = false; + bool refr_y = false; + area_t page_cords; + area_t scrl_cords; + cord_t hpad = page_style->body.padding.hor; + cord_t vpad = page_style->body.padding.ver; + + new_x = lv_obj_get_x(scrl); + new_y = lv_obj_get_y(scrl); + lv_obj_get_coords(scrl, &scrl_cords); + lv_obj_get_coords(page, &page_cords); + + /*scrollable width smaller then page width? -> align to left*/ + if(area_get_width(&scrl_cords) + 2 * hpad < area_get_width(&page_cords)) { + if(scrl_cords.x1 != page_cords.x1 + hpad) { + new_x = hpad; + refr_x = true; + } + } else { + /*The edges of the scrollable can not be in the page (minus hpad) */ + if(scrl_cords.x2 < page_cords.x2 - hpad) { + new_x = area_get_width(&page_cords) - area_get_width(&scrl_cords) - hpad; /* Right align */ + refr_x = true; + } + if (scrl_cords.x1 > page_cords.x1 + hpad) { + new_x = hpad; /*Left align*/ + refr_x = true; } } - else if(sign == LV_SIGNAL_PRESSED) { - if(page_ext->pr_action != NULL) { - page_ext->pr_action(page); + + /*scrollable height smaller then page height? -> align to left*/ + if(area_get_height(&scrl_cords) + 2 * vpad < area_get_height(&page_cords)) { + if(scrl_cords.y1 != page_cords.y1 + vpad) { + new_y = vpad; + refr_y = true; + } + } else { + /*The edges of the scrollable can not be in the page (minus vpad) */ + if(scrl_cords.y2 < page_cords.y2 - vpad) { + new_y = area_get_height(&page_cords) - area_get_height(&scrl_cords) - vpad; /* Bottom align */ + refr_y = true; + } + if (scrl_cords.y1 > page_cords.y1 + vpad) { + new_y = vpad; /*Top align*/ + refr_y = true; } } - else if(sign == LV_SIGNAL_RELEASED) { - if(lv_indev_is_dragging(lv_indev_get_act()) == false) { - if(page_ext->rel_action != NULL) { - page_ext->rel_action(page); - } + if(refr_x != false || refr_y != false) { + lv_obj_set_pos(scrl, new_x, new_y); + } + + lv_page_sb_refresh(page); + } + else if(sign == LV_SIGNAL_DRAG_END) { + /*Hide scrollbars if required*/ + if(page_ext->sb.mode == LV_PAGE_SB_MODE_DRAG) { + area_t sb_area_tmp; + if(page_ext->sb.hor_draw) { + area_cpy(&sb_area_tmp, &page_ext->sb.hor_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x2; + sb_area_tmp.y2 += page->coords.y2; + lv_inv_area(&sb_area_tmp); + page_ext->sb.hor_draw = 0; + } + if(page_ext->sb.ver_draw) { + area_cpy(&sb_area_tmp, &page_ext->sb.ver_area); + sb_area_tmp.x1 += page->coords.x1; + sb_area_tmp.y1 += page->coords.y1; + sb_area_tmp.x2 += page->coords.x2; + sb_area_tmp.y2 += page->coords.y2; + lv_inv_area(&sb_area_tmp); + page_ext->sb.ver_draw = 0; + } + } + } + else if(sign == LV_SIGNAL_PRESSED) { + if(page_ext->pr_action != NULL) { + page_ext->pr_action(page); + } + } + else if(sign == LV_SIGNAL_RELEASED) { + if(lv_indev_is_dragging(lv_indev_get_act()) == false) { + if(page_ext->rel_action != NULL) { + page_ext->rel_action(page); } } } - return res; + return LV_RES_OK; } diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 2cb056c8cd..3ac411c96c 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -215,30 +215,28 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par /* Include the ancient signal function */ res = ancestor_signal(roller, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); - if(sign == LV_SIGNAL_STYLE_CHG) { + + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + if(sign == LV_SIGNAL_STYLE_CHG) { + lv_obj_set_height(lv_page_get_scrl(roller), + lv_obj_get_height(ext->ddlist.options_label) + lv_obj_get_height(roller)); + lv_obj_align(ext->ddlist.options_label, NULL, LV_ALIGN_CENTER, 0, 0); + lv_ddlist_set_selected(roller, ext->ddlist.selected_option_id); + refr_position(roller, false); + } else if(sign == LV_SIGNAL_CORD_CHG) { + + if(lv_obj_get_width(roller) != area_get_width(param) || + lv_obj_get_height(roller) != area_get_height(param)) { + + lv_ddlist_set_fix_height(roller, lv_obj_get_height(roller)); lv_obj_set_height(lv_page_get_scrl(roller), lv_obj_get_height(ext->ddlist.options_label) + lv_obj_get_height(roller)); + lv_obj_align(ext->ddlist.options_label, NULL, LV_ALIGN_CENTER, 0, 0); lv_ddlist_set_selected(roller, ext->ddlist.selected_option_id); refr_position(roller, false); - } else if(sign == LV_SIGNAL_CORD_CHG) { - - if(lv_obj_get_width(roller) != area_get_width(param) || - lv_obj_get_height(roller) != area_get_height(param)) { - - lv_ddlist_set_fix_height(roller, lv_obj_get_height(roller)); - lv_obj_set_height(lv_page_get_scrl(roller), - lv_obj_get_height(ext->ddlist.options_label) + lv_obj_get_height(roller)); - - lv_obj_align(ext->ddlist.options_label, NULL, LV_ALIGN_CENTER, 0, 0); - lv_ddlist_set_selected(roller, ext->ddlist.selected_option_id); - refr_position(roller, false); - } } } @@ -258,44 +256,42 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, /* Include the ancient signal function */ res = ancestor_scrl_signal(roller_scrl, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - lv_indev_t * indev = lv_indev_get_act(); - int32_t id = -1; - lv_obj_t * roller = lv_obj_get_parent(roller_scrl); - lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); - lv_style_t * style_label = lv_obj_get_style(ext->ddlist.options_label); - const font_t * font = style_label->text.font; - cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; - if(sign == LV_SIGNAL_DRAG_END) { - /*If dragged then align the list to there be an element in the middle*/ - cord_t label_y1 = ext->ddlist.options_label->coords.y1 - roller->coords.y1; - cord_t label_unit = font_h + style_label->text.line_space; - cord_t mid = (roller->coords.y2 - roller->coords.y1) / 2; - id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit; + lv_indev_t * indev = lv_indev_get_act(); + int32_t id = -1; + lv_obj_t * roller = lv_obj_get_parent(roller_scrl); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_style_t * style_label = lv_obj_get_style(ext->ddlist.options_label); + const font_t * font = style_label->text.font; + cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; + + if(sign == LV_SIGNAL_DRAG_END) { + /*If dragged then align the list to there be an element in the middle*/ + cord_t label_y1 = ext->ddlist.options_label->coords.y1 - roller->coords.y1; + cord_t label_unit = font_h + style_label->text.line_space; + cord_t mid = (roller->coords.y2 - roller->coords.y1) / 2; + id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit; + if(id < 0) id = 0; + if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; + ext->ddlist.selected_option_id = id; + } + else if(sign == LV_SIGNAL_RELEASED) { + /*If picked an option by clicking then set it*/ + if(!lv_indev_is_dragging(indev)) { + point_t p; + lv_indev_get_point(indev, &p); + p.y = p.y - ext->ddlist.options_label->coords.y1; + id = p.y / (font_h + style_label->text.line_space); if(id < 0) id = 0; if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; ext->ddlist.selected_option_id = id; } - else if(sign == LV_SIGNAL_RELEASED) { - /*If picked an option by clicking then set it*/ - if(!lv_indev_is_dragging(indev)) { - point_t p; - lv_indev_get_point(indev, &p); - p.y = p.y - ext->ddlist.options_label->coords.y1; - id = p.y / (font_h + style_label->text.line_space); - if(id < 0) id = 0; - if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; - ext->ddlist.selected_option_id = id; - } - } + } - /*Position the scrollable according to the new selected option*/ - if(id != -1) { - refr_position(roller, true); - } + /*Position the scrollable according to the new selected option*/ + if(id != -1) { + refr_position(roller, true); } return res; diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index a072b179f2..0cdf3d4acb 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -861,61 +861,59 @@ static lv_res_t lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param) /* Include the ancient signal function */ res = ancestor_signal(ta, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); - if(sign == LV_SIGNAL_CLEANUP) { - if(ext->pwd_tmp != NULL) dm_free(ext->pwd_tmp); + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + if(sign == LV_SIGNAL_CLEANUP) { + if(ext->pwd_tmp != NULL) dm_free(ext->pwd_tmp); - /* (The created label will be deleted automatically) */ - } else if(sign == LV_SIGNAL_STYLE_CHG) { - if(ext->label) { - lv_obj_t * scrl = lv_page_get_scrl(ta); - lv_style_t * style_ta = lv_obj_get_style(ta); - lv_style_t * style_scrl = lv_obj_get_style(scrl); - if(ext->one_line) { - /*In one line mode refresh the Text Area height because 'vpad' can modify it*/ - lv_style_t * style_label = lv_obj_get_style(ext->label); - cord_t font_h = font_get_height(style_label->text.font) >> FONT_ANTIALIAS; - lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2); - } else { - /*In not one line mode refresh the Label width because 'hpad' can modify it*/ - lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); - lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); /*Be sure the Label is in the correct position*/ - } - lv_label_set_text(ext->label, NULL); - - lv_obj_refresh_ext_size(scrl); /*Refresh ext. size because of cursor drawing*/ - } - } else if(sign == LV_SIGNAL_CORD_CHG) { - /*Set the label width according to the text area width*/ - if(ext->label) { - if(lv_obj_get_width(ta) != area_get_width(param) || - lv_obj_get_height(ta) != area_get_height(param)) { - lv_obj_t * scrl = lv_page_get_scrl(ta); - lv_style_t * style_scrl = lv_obj_get_style(scrl); - lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); - lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); - lv_label_set_text(ext->label, NULL); /*Refresh the label*/ - } + /* (The created label will be deleted automatically) */ + } else if(sign == LV_SIGNAL_STYLE_CHG) { + if(ext->label) { + lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_ta = lv_obj_get_style(ta); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + if(ext->one_line) { + /*In one line mode refresh the Text Area height because 'vpad' can modify it*/ + lv_style_t * style_label = lv_obj_get_style(ext->label); + cord_t font_h = font_get_height(style_label->text.font) >> FONT_ANTIALIAS; + lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2); + } else { + /*In not one line mode refresh the Label width because 'hpad' can modify it*/ + lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); /*Be sure the Label is in the correct position*/ } + lv_label_set_text(ext->label, NULL); + + lv_obj_refresh_ext_size(scrl); /*Refresh ext. size because of cursor drawing*/ } - else if (sign == LV_SIGNAL_CONTROLL) { - char c = *((char*)param); - if(c == LV_GROUP_KEY_RIGHT) { - lv_ta_cursor_right(ta); - } else if(c == LV_GROUP_KEY_LEFT) { - lv_ta_cursor_left(ta); - } else if(c == LV_GROUP_KEY_UP) { - lv_ta_cursor_up(ta); - } else if(c == LV_GROUP_KEY_DOWN) { - lv_ta_cursor_down(ta); + } else if(sign == LV_SIGNAL_CORD_CHG) { + /*Set the label width according to the text area width*/ + if(ext->label) { + if(lv_obj_get_width(ta) != area_get_width(param) || + lv_obj_get_height(ta) != area_get_height(param)) { + lv_obj_t * scrl = lv_page_get_scrl(ta); + lv_style_t * style_scrl = lv_obj_get_style(scrl); + lv_obj_set_width(ext->label, lv_obj_get_width(scrl) - 2 * style_scrl->body.padding.hor); + lv_obj_set_pos(ext->label, style_scrl->body.padding.hor, style_scrl->body.padding.ver); + lv_label_set_text(ext->label, NULL); /*Refresh the label*/ } } } - return res; + else if (sign == LV_SIGNAL_CONTROLL) { + char c = *((char*)param); + if(c == LV_GROUP_KEY_RIGHT) { + lv_ta_cursor_right(ta); + } else if(c == LV_GROUP_KEY_LEFT) { + lv_ta_cursor_left(ta); + } else if(c == LV_GROUP_KEY_UP) { + lv_ta_cursor_up(ta); + } else if(c == LV_GROUP_KEY_DOWN) { + lv_ta_cursor_down(ta); + } + } + + return LV_RES_OK; } /** @@ -931,20 +929,18 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void /* Include the ancient signal function */ res = scrl_signal(scrl, sign, param); + if(res != LV_RES_OK) return res; - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(res == LV_RES_OK) { - if(sign == LV_SIGNAL_REFR_EXT_SIZE) { - /*Set ext. size because the cursor might be out of this object*/ - lv_obj_t * ta = lv_obj_get_parent(scrl); - lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); - lv_style_t * style_label = lv_obj_get_style(ext->label); - cord_t font_h = font_get_height(style_label->text.font) >> FONT_ANTIALIAS; - scrl->ext_size = MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h); - } + if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + /*Set ext. size because the cursor might be out of this object*/ + lv_obj_t * ta = lv_obj_get_parent(scrl); + lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta); + lv_style_t * style_label = lv_obj_get_style(ext->label); + cord_t font_h = font_get_height(style_label->text.font) >> FONT_ANTIALIAS; + scrl->ext_size = MATH_MAX(scrl->ext_size, style_label->text.line_space + font_h); } - return res; + + return LV_RES_OK; } /**