1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

fix(imgbtn) add lv_imgbtn_set_state

The normal lv_obj_add/clear_state couldn't refresh the image button properly.
This commit is contained in:
Gabor Kiss-Vamosi 2021-09-13 17:44:02 +02:00
parent 953d9fb003
commit 26e15fa577
3 changed files with 29 additions and 0 deletions

View File

@ -34,6 +34,11 @@ The possible states are:
If you set sources only in `LV_IMGBTN_STATE_RELEASED`, these sources will be used in other states too.
If you set e.g. `LV_IMGBTN_STATE_PRESSED` they will be used in pressed state instead of the released images.
### States
Instead of the regular `lv_obj_add/clear_state()` functions the `lv_imgbtn_set_state(imgbtn, LV_IMGBTN_STATE_...)` functions should be used to manually set a state.
## Events
- `LV_EVENT_VALUE_CHANGED` Sent when the button is toggled.

View File

@ -90,6 +90,23 @@ void lv_imgbtn_set_src(lv_obj_t * obj, lv_imgbtn_state_t state, const void * src
refr_img(obj);
}
void lv_imgbtn_set_state(lv_obj_t * obj, lv_imgbtn_state_t state)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_state_t obj_state = LV_STATE_DEFAULT;
if(state == LV_IMGBTN_STATE_PRESSED || state == LV_IMGBTN_STATE_CHECKED_PRESSED) obj_state |= LV_STATE_PRESSED;
if(state == LV_IMGBTN_STATE_DISABLED || state == LV_IMGBTN_STATE_CHECKED_DISABLED) obj_state |= LV_STATE_DISABLED;
if(state == LV_IMGBTN_STATE_CHECKED_DISABLED || state == LV_IMGBTN_STATE_CHECKED_PRESSED || state == LV_IMGBTN_STATE_CHECKED_RELEASED) {
obj_state |= LV_STATE_CHECKED;
}
lv_obj_clear_state(obj, LV_STATE_CHECKED | LV_STATE_PRESSED | LV_STATE_DISABLED);
lv_obj_add_state(obj, obj_state);
refr_img(obj);
}
/*=====================
* Getter functions
*====================*/

View File

@ -78,6 +78,13 @@ void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_imgbtn_state_t state, const void *
const void * src_right);
/**
* Use this function instead of `lv_obj_add/clear_state` to set a state manually
* @param imgbtn pointer to an image button object
* @param state the new state
*/
void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_imgbtn_state_t state);
/*=====================
* Getter functions
*====================*/