mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +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:
parent
953d9fb003
commit
26e15fa577
@ -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 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.
|
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
|
## Events
|
||||||
- `LV_EVENT_VALUE_CHANGED` Sent when the button is toggled.
|
- `LV_EVENT_VALUE_CHANGED` Sent when the button is toggled.
|
||||||
|
|
||||||
|
@ -90,6 +90,23 @@ void lv_imgbtn_set_src(lv_obj_t * obj, lv_imgbtn_state_t state, const void * src
|
|||||||
refr_img(obj);
|
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
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
@ -78,6 +78,13 @@ void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_imgbtn_state_t state, const void *
|
|||||||
const void * src_right);
|
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
|
* Getter functions
|
||||||
*====================*/
|
*====================*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user