Description
What MCU/Processor/Board and compiler are you using?
STM32F769, ARM-Embedded-Toolchain
What LVGL version are you using?
LVGL 7.11
What do you want to achieve?
I want to change the image of an image button when the state is changed. I set up two different images with lv_imgbtn_set_src and specified states LV_STATE_DEFAULT and LV_STATE_FOCUSED.
The image should be changed now when the state changes to LV_STATE_FOCUSED but it does not.
What have you tried so far?
Set the image source of the image button for the state LV_STATE_FOCUSED. Also checked if both images are correctly added to lvgl with switching between the images in LV_STATE_DEFAULT.
I added an event callback to the image buttons and when the event is LV_EVENT_FOCUSED set the state to LV_STATE_FOCUSED. Which is maybe not required because it gets already done in the default implementation of the widget.
I checked if the state is actually applied with setting up a new style and applying it. In the style i added image recoloring when the state is LV_STATE_FOCUSED, which works. So why is the new image not applied?
Code to reproduce
static lv_style_t imageButtonStyle;
lv_style_set_image_recolor(&imageButtonStyle, LV_STATE_PRESSED, LV_COLOR_BLACK);
lv_style_set_image_recolor_opa(&imageButtonStyle, LV_STATE_PRESSED, LV_OPA_30);
lv_style_set_image_recolor(&imageButtonStyle, LV_STATE_FOCUSED, LV_COLOR_BLACK);
lv_obj_t* tempBtn = lv_imgbtn_create(mainContainer, NULL);
lv_imgbtn_set_src(tempBtn, LV_STATE_DEFAULT, &image_src1);
lv_imgbtn_set_src(tempBtn, LV_STATE_FOCUSED, &image_src2]);
lv_obj_add_style(tempBtn, LV_IMGBTN_PART_MAIN, &imageButtonStyle);
lv_obj_set_event_cb(tempBtn, imageButtonCallback);
....
static void imageButtonCallback(lv_obj_t* obj, lv_event_t event) {
if(event == LV_EVENT_FOCUSED) {
lv_obj_set_state(obj,LV_STATE_FOCUSED);
}
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.