Whole screen refreshing with button matrix


I am using LVGL (8.4) to create a keypad thanks to the button matrix widget.

The application is running on an embedded system (STM32) with a 2.8" touchscreen. Display and touch are working fine.
I have noticed that, when I click on the screen to select a button, the whole screen refreshes. Since I use an embedded system with a “low-speed” SPI communication, refreshing is pretty visible.
Furthermore, I’ve also noticed is that when I drag from one button to another, only the button areas refresh (and not the whole screen!).
I activated the LV_USE_REFR_DEBUG option in lv_conf.h and it confirms what I am saying.

So, I have two questions:

  1. Is there any option to refresh only the button area when screen is touched?
  2. If not, would it be possible to disable the dark layer when a button is pressed so that the screen doesn’t need to be refreshed each time it is clicked?

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

STM32WB55 Board

What LVGL version are you using?


What do you want to achieve?

In a button matrix, refresh only the area of the button that has been pressed.

What have you tried so far?

  • Changed background color when a button is pressed. The color changes but it’s not the one that I set (the darker layer is still there).
  • Tried to figure out why the whole screen is refreshed when clicked but did not find any answer.

Code to reproduce

lv_obj_t *keypad = lv_btnmatrix_create(activeScreen);
lv_btnmatrix_set_map(keypad, keypadMap);
lv_obj_align(keypad, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_size(keypad, SCREEN_WIDTH, SCREEN_HEIGHT);
lv_btnmatrix_set_btn_ctrl_all(keypad, LV_BTNMATRIX_CTRL_NO_REPEAT);
lv_obj_add_event_cb(keypad, _lvgl_keypad_handler, LV_EVENT_VALUE_CHANGED, NULL);

After a few tries, I actually answered my second question. Indeed, removing the buttons style when the state is pressed doesn’t refresh the whole screen but only the area concerned by the update. To do so, I used the following code:

lv_obj_remove_style(keypad, NULL, LV_PART_ITEMS | LV_STATE_PRESSED);

Now, the problem is that there is no style associated to the pressed state, so it’s not possible for the user to know if the key is really pressed or not. To solve this problem, I tried to create my own style and apply it to the pressed state but the whole screen refreshes again.

Maybe this comes from a bug?

I found another solution to my problem. It consists in using the grid layout and separated buttons instead of a button matrix. This way, only the buttons concerned by the click are refreshed during the pressed event. An example can be found here.

However, I still don’t know if the fact that the whole button matrix refreshes when a key is pressed is normal or not. If anyone knows the answer, feel free to reply to the post!