100ask
1
Effect
Code
static void scroll_begin_event(lv_event_t * e)
{
lv_obj_t * cont = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * tv = lv_obj_get_parent(cont);
if(lv_event_get_code(e) == LV_EVENT_SCROLL_END) {
lv_indev_t * indev = lv_indev_active();
if(indev && lv_indev_get_state(indev) == LV_INDEV_STATE_PRESSED) {
return;
}
int32_t tb_index;
lv_coord_t s;
lv_point_t p;
lv_obj_get_scroll_end(cont, &p);
if(lv_obj_get_style_flex_flow(lv_tabview_get_tab_bar(tv), 0) != LV_FLEX_FLOW_COLUMN) {
s = lv_obj_get_scroll_x(cont);
if(s < 0) tb_index = lv_tabview_get_tab_count(tv) - 1;
if((tb_index == (lv_tabview_get_tab_count(tv) - 1)) && (s > p.x)) tb_index = 0;
}
else {
s = lv_obj_get_scroll_y(cont);
if(s < 0) tb_index = lv_tabview_get_tab_count(tv) - 1;
if((tb_index == (lv_tabview_get_tab_count(tv) - 1)) && (s > p.y)) tb_index = 0;
}
bool new_tab = false;
if(tb_index != (int32_t)lv_tabview_get_tab_active(tv)) new_tab = true;
/*If not scrolled by an indev set the tab immediately*/
if(lv_indev_active()) {
lv_tabview_set_active(tv, tb_index, LV_ANIM_ON);
}
else {
lv_tabview_set_active(tv, tb_index, LV_ANIM_OFF);
}
if(new_tab) lv_obj_send_event(tv, LV_EVENT_VALUE_CHANGED, NULL);
}
}
lv_obj_add_event_cb(lv_tabview_get_content(tabview), scroll_begin_event, LV_EVENT_SCROLL_END, NULL);
1 Like