diff --git a/docs/overview/event.md b/docs/overview/event.md index 1bf1bd1c9..b2919914f 100644 --- a/docs/overview/event.md +++ b/docs/overview/event.md @@ -78,7 +78,7 @@ The following event codes exist: - `LV_EVENT_LONG_PRESSED_REPEAT` Called after `long_press_time` in every `long_press_repeat_time` ms. Not called if scrolled. - `LV_EVENT_CLICKED` Called on release if the object not scrolled (regardless to long press) - `LV_EVENT_RELEASED` Called in every cases when the object has been released -- `LV_EVENT_SCROLL_BEGIN` Scrolling begins +- `LV_EVENT_SCROLL_BEGIN` Scrolling begins. The event paramter is `NULL` or an `lv_anim_t *` with the scroll animation descriptor to modify if required. - `LV_EVENT_SCROLL_END` Scrolling ends - `LV_EVENT_SCROLL` The object was scrolled - `LV_EVENT_GESTURE` A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` diff --git a/examples/widgets/lv_example_widgets.h b/examples/widgets/lv_example_widgets.h index 0d1fc633a..3c074dca8 100644 --- a/examples/widgets/lv_example_widgets.h +++ b/examples/widgets/lv_example_widgets.h @@ -113,6 +113,7 @@ void lv_example_table_1(void); void lv_example_table_2(void); void lv_example_tabview_1(void); +void lv_example_tabview_2(void); void lv_example_textarea_1(void); void lv_example_textarea_2(void); diff --git a/examples/widgets/tabview/index.rst b/examples/widgets/tabview/index.rst index 1ca60b161..d037e1ee9 100644 --- a/examples/widgets/tabview/index.rst +++ b/examples/widgets/tabview/index.rst @@ -7,6 +7,12 @@ Simple Tabview .. lv_example:: widgets/tabview/lv_example_tabview_1 :language: c +Tabs on the right, styling and no scrolling +""""""""""""""""""""""""""""""""""""""""""""" + +.. lv_example:: widgets/tabview/lv_example_tabview_2 + :language: c + MicroPython ^^^^^^^^^^^ diff --git a/examples/widgets/tabview/lv_example_tabview_2.c b/examples/widgets/tabview/lv_example_tabview_2.c new file mode 100644 index 000000000..e90a5638f --- /dev/null +++ b/examples/widgets/tabview/lv_example_tabview_2.c @@ -0,0 +1,56 @@ +#include "../../lv_examples.h" +#if LV_USE_TABVIEW && LV_BUILD_EXAMPLES + +static void scroll_begin_event(lv_event_t * e) +{ + /*Disable the scroll animations. Triggered when a tab button is clicked */ + if(lv_event_get_code(e) == LV_EVENT_SCROLL_BEGIN) { + lv_anim_t * a = lv_event_get_param(e); + if(a) a->time = 0; + } +} + +void lv_example_tabview_2(void) +{ + /*Create a Tab view object*/ + lv_obj_t *tabview; + tabview = lv_tabview_create(lv_scr_act(), LV_DIR_LEFT, 80); + lv_obj_add_event_cb(lv_tabview_get_content(tabview), scroll_begin_event, LV_EVENT_SCROLL_BEGIN, NULL); + + lv_obj_set_style_bg_color(tabview, lv_palette_lighten(LV_PALETTE_RED, 2), 0); + + lv_obj_t * tab_btns = lv_tabview_get_tab_btns(tabview); + lv_obj_set_style_bg_color(tab_btns, lv_palette_darken(LV_PALETTE_GREY, 3), 0); + lv_obj_set_style_text_color(tab_btns, lv_palette_lighten(LV_PALETTE_GREY, 5), 0); + lv_obj_set_style_border_side(tab_btns, LV_BORDER_SIDE_RIGHT, LV_PART_ITEMS | LV_STATE_CHECKED); + + + /*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/ + lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1"); + lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2"); + lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3"); + lv_obj_t *tab4 = lv_tabview_add_tab(tabview, "Tab 4"); + lv_obj_t *tab5 = lv_tabview_add_tab(tabview, "Tab 5"); + + lv_obj_set_style_bg_color(tab2, lv_palette_lighten(LV_PALETTE_AMBER, 3), 0); + lv_obj_set_style_bg_opa(tab2, LV_OPA_COVER, 0); + + /*Add content to the tabs*/ + lv_obj_t * label = lv_label_create(tab1); + lv_label_set_text(label, "First tab"); + + label = lv_label_create(tab2); + lv_label_set_text(label, "Second tab"); + + label = lv_label_create(tab3); + lv_label_set_text(label, "Third tab"); + + label = lv_label_create(tab4); + lv_label_set_text(label, "Forth tab"); + + label = lv_label_create(tab5); + lv_label_set_text(label, "Fifth tab"); + + lv_obj_clear_flag(lv_tabview_get_content(tabview), LV_OBJ_FLAG_SCROLLABLE); +} +#endif diff --git a/src/core/lv_event.c b/src/core/lv_event.c index 71f396fe0..01cac5554 100644 --- a/src/core/lv_event.c +++ b/src/core/lv_event.c @@ -288,6 +288,16 @@ uint32_t lv_event_get_key(lv_event_t * e) } } +lv_anim_t * lv_event_get_scroll_anim(lv_event_t * e) +{ + if(e->code == LV_EVENT_SCROLL_BEGIN) { + return lv_event_get_param(e); + } else { + LV_LOG_WARN("Not interpreted with this event code"); + return 0; + } +} + void lv_event_set_ext_draw_size(lv_event_t * e, lv_coord_t size) { if(e->code == LV_EVENT_REFR_EXT_DRAW_SIZE) { diff --git a/src/core/lv_event.h b/src/core/lv_event.h index 800c31350..c8b60bb2f 100644 --- a/src/core/lv_event.h +++ b/src/core/lv_event.h @@ -263,6 +263,13 @@ const lv_area_t * lv_event_get_old_size(lv_event_t * e); */ uint32_t lv_event_get_key(lv_event_t * e); +/** + * Get the animation descriptor of a scrolling. Can be used in `LV_EVENT_SCROLL_BEGIN` + * @param e pointer to an event + * @return the animation that will scroll the object. (can be modified as required) + */ +lv_anim_t * lv_event_get_scroll_anim(lv_event_t * e); + /** * Set the new extra draw size. Can be used in `LV_EVENT_REFR_EXT_DRAW_SIZE` * @param e pointer to an event diff --git a/src/core/lv_indev_scroll.c b/src/core/lv_indev_scroll.c index 8cefbe6fd..ff386aefc 100644 --- a/src/core/lv_indev_scroll.c +++ b/src/core/lv_indev_scroll.c @@ -55,8 +55,7 @@ void _lv_indev_scroll_handler(_lv_indev_proc_t * proc) init_scroll_limits(proc); - lv_indev_t * indev_act = lv_indev_get_act(); - lv_event_send(scroll_obj, LV_EVENT_SCROLL_BEGIN, indev_act); + lv_event_send(scroll_obj, LV_EVENT_SCROLL_BEGIN, NULL); if(proc->reset_query) return; } diff --git a/src/core/lv_obj_scroll.c b/src/core/lv_obj_scroll.c index d3c0222ff..bc7232dbb 100644 --- a/src/core/lv_obj_scroll.c +++ b/src/core/lv_obj_scroll.c @@ -256,9 +256,6 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable lv_anim_set_ready_cb(&a, scroll_anim_ready_cb); if(x) { - lv_res_t res; - 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; @@ -268,14 +265,14 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable lv_anim_set_values(&a, -sx, -sx + x); lv_anim_set_exec_cb(&a, scroll_x_anim); lv_anim_set_path_cb(&a, lv_anim_path_ease_out); + + lv_res_t res; + res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, &a); + if(res != LV_RES_OK) return; lv_anim_start(&a); } if(y) { - lv_res_t res; - 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; @@ -285,6 +282,11 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable lv_anim_set_exec_cb(&a, scroll_y_anim); lv_anim_set_path_cb(&a, lv_anim_path_ease_out); lv_anim_start(&a); + + lv_res_t res; + res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, &a); + if(res != LV_RES_OK) return; + } } else { /*Remove pending animations*/