How to disable animation for switch

Hello, I have some “flickering” at moment.

For exemple the slider go to left when I redraw the page.
For slider I have disabled this using

lv_slider_set_value(slider, SelectedDevice->level, LV_ANIM_OFF);

But how to do for switch ?

On old version there was the fonction
void lv_switch_on(lv_obj_t *sw, lv_anim_enable_t anim)

But this one is deprecated for
lv_obj_add_state(sw, LV_STATE_CHECKED);

But without the Anim option.

anim – LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately

Hi

Try this:

lv_obj_set_style_anim_duration(switch_test, 0, LV_PART_MAIN);

Should disable the animation.

Undefined fonction.

I m still on 8.3.9, I need to update the project to test it, will take time …

Ok, so there is too much missing stuff in V9 compared to V8.

So I return to V8, no one have a similar fonction that can work on V8 ?

@Smanar, try to use

lv_obj_set_style_anim_time(switch_test, 0, LV_PART_MAIN)

If I’m not mistaken, move the animation time to zero, the animation will not execute.

Ha nice.
It haven’t worked (have tried with other values, it have no impact) but your link is so usefull.

    if(LV_SWITCH_IS_ANIMATING(sw)) {
        /* Use the animation's coordinate */
        anim_value_x = (anim_length * sw->anim_state) / LV_SWITCH_ANIM_STATE_END;
    }
    else {
        /* Use LV_STATE_CHECKED to decide the coordinate */
        bool chk = lv_obj_get_state(obj) & LV_STATE_CHECKED;
        anim_value_x = chk ? anim_length : 0;
    }

And there is no way to set (sw)->anim_state.

So I think it’s just not possible to disable, the code draw the device in position 0 and after in good position.