How to prevent tab switching?

Description

When the current tab page is editing the content of the control, how to prohibit tabview from switching to other tab pages?

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

STM32F4

What LVGL version are you using?

V7.7.0

What do you want to achieve?

Can enable or disable tab page switching

What have you tried so far?

1、I tried to disable ext->btns , but I can’t see the color change in the disabled state in the UI .

lv_btnmatrix_set_btn_ctrl_all(ext->btns,LV_BTNMATRIX_CTRL_DISABLED);
lv_obj_add_state(ext->btns,LV_STATE_DISABLED);

2、And, Tabs can still be switched by dragging left and right.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

@embeddedt Can you give me some good ideas?

Unless I’m forgetting something, I don’t think there is a built-in way to disable a tabview. My suggested workaround would be a popup dialog with the control you are editing.

In v8 the disabled state will propagate to child objects, so I think implementing this will be much simpler.

(cc @kisvegabor)

Really there is no built-in way to do it but this should do the job:

    lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview);
    lv_obj_set_click(ext->btns, false);
    lv_obj_set_click(tabview, false);
    lv_page_set_scroll_propagation(tab1, false);
1 Like

@embeddedt How to set the color when tabview is disabled?

I added this in tabview_init, but it doesn’t work。

lv_style_set_bg_color(&styles->tabview_btns, LV_STATE_DISABLED, LV_COLOR_RED);

The disabled state doesn’t propagate down to the buttons so using LV_STATE_DISABLED on the style won’t work. I think you would have to change the color manually - probably with a local style.

1 Like