Change animation speed in tabview?

Description

How do I change the animation speed in tabview. Instead of the slow sliding animation, I would like it to change fast - it doesn’t even need to slide. Just a fast change.

What MCU/Processor/Board and compiler are you using?

ESP32 with arduino on a 480x320 display

What LVGL version are you using?

8.3.7

What do you want to achieve?

Change the animation speed when a tab button is changed

What have you tried so far?

Seen how it´s done in version 7, but that doesn’t work anymore

Code to reproduce

    lv_obj_t* tabView = lv_tabview_create(myScreen, LV_DIR_TOP, 30);
    lv_obj_t* tab1 = lv_tabview_add_tab(tabView, "Tab1");
    lv_obj_t* tab2 = lv_tabview_add_tab(tabView, "Tab2");

Hi @AlexJ ,

You need to override the default scroll event with a custom event handler…

Hopefully this code will do the trick for you…

static void scroll_begin_event_cb(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;

    }
}

lv_obj_t* tabView = lv_tabview_create(myScreen, LV_DIR_TOP, 30);
lv_obj_add_event_cb(lv_tabview_get_content(tabView), scroll_begin_event_cb, LV_EVENT_SCROLL_BEGIN, NULL);
lv_obj_t* tab1 = lv_tabview_add_tab(tabView, "Tab1");
lv_obj_t* tab2 = lv_tabview_add_tab(tabView, "Tab2");

Kind Regards,

Pete

Hi Pete,

I get where you are going with your example.
When you attach the event handler for tabView you forget to send the content.
I have been trying this, but still no success

lv_obj_t* tabView = lv_tabview_create(myScreen, LV_DIR_TOP, 30);
lv_obj_add_event_cb(tabView, CbScrollBeginEvent, LV_EVENT_SCROLL_BEGIN, lv_tabview_get_content(tabView));
lv_obj_t* tab1 = lv_tabview_add_tab(tabView, "Tab1");
lv_obj_t* tab2 = lv_tabview_add_tab(tabView, "Tab2");

static void CbScrollBeginEvent(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_anim_t*)lv_event_get_param(e);
        if (a)
            a->time = 0;
    }
}

Hi @AlexJ ,

My sincere apologies I should test my code before suggesting it, I made a typo…

Please see this TESTED version:

static void CbScrollBeginEvent(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_anim_t*)lv_event_get_param(e);
        if (a)
            a->time = 0;
    }
}

void tv_example( lv_obj_t *myScreen ) {

	lv_obj_t *tabView = lv_tabview_create(myScreen, LV_DIR_TOP, 30);
	lv_obj_add_event_cb(lv_tabview_get_content(tabView), CbScrollBeginEvent, LV_EVENT_SCROLL_BEGIN, NULL);
	lv_obj_t *tab1 = lv_tabview_add_tab(tabView, "Tab1");
	lv_obj_t *tab2 = lv_tabview_add_tab(tabView, "Tab2");

	lv_obj_t *txt = lv_label_create( tab1 );
	lv_label_set_text( txt, "Text on Tab1" );

	txt = lv_label_create( tab2 );
	lv_label_set_text( txt, "Text on Tab2" );
}

tv_example( lv_scr_act() );

I hope it’s okay for you now! :slight_smile:

Kind Regards,

Pete

Thanks a lot Pete for your time. It seems to work now :slight_smile:

It still seems a little slow. I guess it would be better just to disable the finger sliding between tabs.
When I use the tab menu the speed is ok.

Is there a way to disable finger sliding totally?

Best regards,
Alex

Hi @AlexJ ,

Sure, see below:

static void CbScrollBeginEvent(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_anim_t*)lv_event_get_param(e);
        if (a)
            a->time = 0;
    }
}

void tv_example( lv_obj_t *myScreen ) {

	lv_obj_t *tabView = lv_tabview_create(myScreen, LV_DIR_TOP, 30);
	lv_obj_add_event_cb(lv_tabview_get_content(tabView), CbScrollBeginEvent, LV_EVENT_SCROLL_BEGIN, NULL);
	lv_obj_clear_flag(lv_tabview_get_content(tabView), LV_OBJ_FLAG_SCROLLABLE);
	lv_obj_t *tab1 = lv_tabview_add_tab(tabView, "Tab1");
	lv_obj_t *tab2 = lv_tabview_add_tab(tabView, "Tab2");

	lv_obj_t *txt = lv_label_create( tab1 );
	lv_label_set_text( txt, "Text on Tab1" );

	txt = lv_label_create( tab2 );
	lv_label_set_text( txt, "Text on Tab2" );
}

Kind Regards,

Pete

Thanks a lot Pete - you saved my day :smiley:
This eliminated the sluggishness i felt :slight_smile:
Have a nice day.

1 Like