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.

Sorry boy, but disable anim because flicker isnt right way… But when you strict require no anim use image button with state = no animation.

And upgrade to v9 require handle some changes in code and not find same func…

Nope I need a switch, the problem is if the device have the “on” state, it’s firstly displayed on “off” state, and just after in “on” state, and it causes visual problems.

Was same for the slider but solved with the LV_ANIM_OFF (fistly displayed on 0 position, then on real position)

If you mean on screen load , here you require other way to init based on events LOAD_START … next variant is place hidden switch and unhide after right setup , but your steps is still wrong way.

What are you talking about ?
I don’t make a complex code, I just print a simple switch

If you just do that

        lv_obj_t * sw = lv_switch_create(GridSmall);
        lv_obj_add_state(sw, LV_STATE_CHECKED);

The switch will be displayed on “off” and a ms after on position “on”.

Ma question is simple. How to display a switch direclty on “on” position ? and from the switch code, it’s not possible

You realy think the solution is hiding the switch, and display it later, or play with even (or use images button) ?
Just need a LV_ANIM_OFF to have slider working, I need 30 lines of code for switch ?
Are you sure it’s my steps that are in wrong way ?

Ok normal work with any GUI is prepare screen and load it only after all widgets is right setup. If your code preffer create on the fly = memory risk = you can do change in lvgl sources as your design need. Is open source…

FYI

lv_obj_t * panel = lv_obj_create(parent);
lv_obj_add_flag(panel, LV_OBJ_FLAG_HIDDEN);

lv_obj_t * sw = lv_switch_create(panel);
lv_obj_add_state(sw, LV_STATE_CHECKED);   

lv_obj_clear_flag(panel, LV_OBJ_FLAG_HIDDEN);

next variant simpler if you have next screen not loaded for view , simply create switch on this invisible screen and after setup state move it to view

lv_obj_set_parent(sw, active_screen...);
        lv_obj_add_flag(GridSmall, LV_OBJ_FLAG_HIDDEN);
        lv_obj_t * sw = lv_switch_create(GridSmall);
        lv_obj_add_state(sw, LV_STATE_CHECKED);
        lv_obj_clear_flag(GridSmall, LV_OBJ_FLAG_HIDDEN);

Thx, but not working, sill have the “off>on” passage visible.

Last line try place on delayed event in loop…

Hello,

Do you call these functions before or after loading your screen? Calling them beforehand should make the initial state to be switched off when the widgets get shown.

Set the state of the switch and all other objects first, then call lv_screen_load() afterwards.

Hi,

After, I just clear the actual screen, and draw on it.

lv_screen_load() is a V8 fonction ?

There is a “simple” (I will not use a double buffer just for a missing option on a simple switch) method to draw on a screen without showing it ?

@Smanar,
The lv_screen_load function does not belong to version 8.2.0. If you want to load a screen, you should use lv_disp_load_scr. You can check the API for version 8. Map