Disable/enable button


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

ESP32, own board

What do you want to achieve?

Disable or enable button

What have you tried so far?

/* Disable button */
lv_btn_set_state(btn_refresh, LV_BTN_STATE_INA);

/* Enable button */
lv_btn_set_state(btn_refresh, LV_BTN_STATE_REL);

When I try this, it seems working, but I must focus the button, and then it was changed. I tried use lv_obj_invalidate but nothing.

Please, could you help me?

Version of the lib is 5.3.

Thank you

Have you tried,

lv_obj_set_click( btn_refresh, false );  /* Disable */
lv_obj_set_click( btn_refresh, true );   /* Enable */

Thank you,I tried it, but I need change the style of the button too. It must by grayscale instead of color, when disabled.

You should be able to do that as follows,

lv_theme_t * pTh = lv_theme_get_current();
pTh->btn.rel->body.main_color = LV_COLOR_HEX( 0x404040 ); /* Or whatever color */
pTh->btn.rel->body.grad_color = LV_COLOR_HEX( 0x404040 );
pTh->btn.ina->body.main_color = LV_COLOR_HEX( 0x404040 ); /* Or whatever color */
pTh->btn.ina->body.grad_color = LV_COLOR_HEX( 0x404040 );

Another option is just to hide the button when you do not want it active,

lv_obj_set_hidden( btn_refresh, true );      /* Hide it */
lv_obj_set_hidden( btn_refresh, false );     /* Show it */

I have right style in theme file. When I set the ‘lv_btn_set_state’ then I see the change, but only after I focus/defocus the button. It seems, that it is not reload the view.

Where have you tried to change the state? In a the button’s action function or an other object’s action function or something else?

Don’t you mean @zavovi ? :slight_smile:

In both of case. When I click the button, then I start WiFi scanning (want to disable button - seems ok - it is focused and disabled). Then I get the scan results in callback, I want enable button (button is still focused and still disabled). I tried focused other button before scan done, but refresh button is still disabled.
When I focus disabled refresh button and defocus it, I see, it is enabled.

The enable process is from another function (can be from another task too).

Ups, yes, sorry :slight_smile:

I’m not sure I fully understand. Please send a simple code example to reproduce the issue. It can be independent form your WiFi GUI just with 1-2 buttons (only the most required things)

Hello, I am sorry about late response - I solved this issue. The issue was in the RTOS tasks. When I right set semaphores for tasks, then it was solved.