diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index e126da5f69..563f12b63c 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -388,6 +388,62 @@ void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time) } } +/** + * Scroll down the page a little + * @param page pointer to a page object + */ +void lv_page_scroll_down(lv_obj_t * page) +{ + lv_obj_t * scrl = lv_page_get_scrl(page); + +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = scrl; + a.start = lv_obj_get_y(scrl); + a.end = a.start - lv_obj_get_height(page) / 4; + a.fp = (lv_anim_fp_t)lv_obj_set_y; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_PAGE_GROUP_SCROLL_ANIM_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#else + lv_obj_set_y(scrl, lv_obj_get_y(scrl) - lv_obj_get_height(page) / 4); +#endif +} + + +/** + *Scroll up the page a little + * @param page pointer to a page object + */ +void lv_page_scroll_up(lv_obj_t * page) +{ + lv_obj_t * scrl = lv_page_get_scrl(page); +#if USE_LV_ANIMATION + lv_anim_t a; + a.var = scrl; + a.start = lv_obj_get_y(scrl); + a.end = a.start + lv_obj_get_height(page) / 4; + a.fp = (lv_anim_fp_t)lv_obj_set_y; + a.path = lv_anim_path_linear; + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_PAGE_GROUP_SCROLL_ANIM_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + lv_anim_create(&a); +#else + lv_obj_set_y(scrl, lv_obj_get_y(scrl) + lv_obj_get_height(page) / 4); +#endif +} + /********************** * STATIC FUNCTIONS **********************/ @@ -570,47 +626,12 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) if(page->ext_size < (-ext->sb.style->body.padding.ver)) page->ext_size = -ext->sb.style->body.padding.ver; } else if(sign == LV_SIGNAL_CONTROLL) { uint32_t c = *((uint32_t *) param); - lv_obj_t * scrl = lv_page_get_scrl(page); if((c == LV_GROUP_KEY_DOWN || c == LV_GROUP_KEY_RIGHT) && ext->arrow_scroll) { -#if USE_LV_ANIMATION - lv_anim_t a; - a.var = scrl; - a.start = lv_obj_get_y(scrl); - a.end = a.start - lv_obj_get_height(page) / 4; - a.fp = (lv_anim_fp_t)lv_obj_set_y; - a.path = lv_anim_path_linear; - a.end_cb = NULL; - a.act_time = 0; - a.time = LV_PAGE_GROUP_SCROLL_ANIM_TIME; - a.playback = 0; - a.playback_pause = 0; - a.repeat = 0; - a.repeat_pause = 0; - lv_anim_create(&a); -#else - lv_obj_set_y(scrl, lv_obj_get_y(scrl) - lv_obj_get_height(page) / 4); -#endif + lv_page_scroll_down(page); } else if((c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_LEFT) && ext->arrow_scroll) { -#if USE_LV_ANIMATION - lv_anim_t a; - a.var = scrl; - a.start = lv_obj_get_y(scrl); - a.end = a.start + lv_obj_get_height(page) / 4; - a.fp = (lv_anim_fp_t)lv_obj_set_y; - a.path = lv_anim_path_linear; - a.end_cb = NULL; - a.act_time = 0; - a.time = LV_PAGE_GROUP_SCROLL_ANIM_TIME; - a.playback = 0; - a.playback_pause = 0; - a.repeat = 0; - a.repeat_pause = 0; - lv_anim_create(&a); -#else - lv_obj_set_y(scrl, lv_obj_get_y(scrl) + lv_obj_get_height(page) / 4); -#endif + lv_page_scroll_up(page); } } else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; diff --git a/lv_objx/lv_page.h b/lv_objx/lv_page.h index 070fd1f6f2..7c38c3fab4 100644 --- a/lv_objx/lv_page.h +++ b/lv_objx/lv_page.h @@ -278,6 +278,18 @@ void lv_page_glue_obj(lv_obj_t * obj, bool glue); */ void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time); +/** + * Scroll down the page a little + * @param page pointer to a page object + */ +void lv_page_scroll_down(lv_obj_t * page); + +/** + * Scroll up the page a little + * @param page pointer to a page object + */ +void lv_page_scroll_up(lv_obj_t * page); + /********************** * MACROS **********************/ diff --git a/lv_objx/lv_win.c b/lv_objx/lv_win.c index 1d8d6fcbc9..484d0c22bb 100644 --- a/lv_objx/lv_win.c +++ b/lv_objx/lv_win.c @@ -77,6 +77,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) ext->page = lv_page_create(new_win, NULL); lv_obj_set_protect(ext->page, LV_PROTECT_PARENT); lv_page_set_sb_mode(ext->page, LV_SB_MODE_AUTO); + lv_page_set_arrow_scroll(ext->page, true); /*Create a holder for the header*/ ext->header = lv_obj_create(new_win, NULL); @@ -472,7 +473,12 @@ static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param) ext->header = NULL; /*These objects were children so they are already invalid*/ ext->page = NULL; ext->title = NULL; - } else if(sign == LV_SIGNAL_GET_TYPE) { + } + else if(sign == LV_SIGNAL_CONTROLL) { + /*Forward all the control signals to the page*/ + ext->page->signal_func(ext->page, sign, param); + } + else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ diff --git a/lv_objx/lv_win.h b/lv_objx/lv_win.h index 8032a39823..9e0d8c188a 100644 --- a/lv_objx/lv_win.h +++ b/lv_objx/lv_win.h @@ -223,6 +223,19 @@ lv_style_t * lv_win_get_style(const lv_obj_t *win, lv_win_style_t type); */ void lv_win_focus(lv_obj_t * win, lv_obj_t * obj, uint16_t anim_time); + +static inline void lv_win_scroll_down(lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_page_scroll_down(ext->page); +} + +static inline void lv_win_scroll_up(lv_obj_t * win) +{ + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + lv_page_scroll_up(ext->page); +} + /********************** * MACROS **********************/