btn: allow disable state for ever "normal" state
This commit is contained in:
@@ -137,27 +137,26 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)
|
|||||||
|
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case LV_BTN_STATE_RELEASED:
|
case LV_BTN_STATE_RELEASED:
|
||||||
lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED | LV_STATE_DISABLED);
|
lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED);
|
||||||
break;
|
break;
|
||||||
case LV_BTN_STATE_PRESSED:
|
case LV_BTN_STATE_PRESSED:
|
||||||
lv_obj_clear_state(btn, LV_STATE_CHECKED | LV_STATE_DISABLED);
|
lv_obj_clear_state(btn, LV_STATE_CHECKED);
|
||||||
lv_obj_add_state(btn, LV_STATE_PRESSED);
|
lv_obj_add_state(btn, LV_STATE_PRESSED);
|
||||||
break;
|
break;
|
||||||
case LV_BTN_STATE_CHECKED_RELEASED:
|
case LV_BTN_STATE_CHECKED_RELEASED:
|
||||||
lv_obj_add_state(btn, LV_STATE_CHECKED);
|
lv_obj_add_state(btn, LV_STATE_CHECKED);
|
||||||
lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_DISABLED);
|
lv_obj_clear_state(btn, LV_STATE_PRESSED);
|
||||||
break;
|
break;
|
||||||
case LV_BTN_STATE_CHECKED_PRESSED:
|
case LV_BTN_STATE_CHECKED_PRESSED:
|
||||||
lv_obj_add_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED | LV_STATE_DISABLED);
|
lv_obj_add_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED);
|
||||||
break;
|
break;
|
||||||
case LV_BTN_STATE_DISABLED:
|
case LV_BTN_STATE_DISABLED:
|
||||||
lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED);
|
|
||||||
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
||||||
break;
|
break;
|
||||||
|
case LV_BTN_STATE_ACTIVE:
|
||||||
|
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// /*Make the state change happen immediately, without transition*/
|
|
||||||
// btn->prev_state = btn->state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,26 +184,25 @@ void lv_btn_toggle(lv_obj_t * btn)
|
|||||||
/**
|
/**
|
||||||
* Get the current state of the button
|
* Get the current state of the button
|
||||||
* @param btn pointer to a button object
|
* @param btn pointer to a button object
|
||||||
* @return the state of the button (from lv_btn_state_t enum)
|
* @return the state of the button (from lv_btn_state_t enum).
|
||||||
|
* If the button is in disabled state `LV_BTN_STATE_DISABLED` will be ORed to the other button states.
|
||||||
*/
|
*/
|
||||||
lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn)
|
lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn)
|
||||||
{
|
{
|
||||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||||
|
|
||||||
lv_state_t state = lv_obj_get_state(btn, LV_BTN_PART_MAIN);
|
lv_state_t obj_state = lv_obj_get_state(btn, LV_BTN_PART_MAIN);
|
||||||
|
lv_btn_state_t btn_state = 0;
|
||||||
|
if(obj_state & LV_STATE_DISABLED) btn_state = LV_BTN_STATE_DISABLED;
|
||||||
|
|
||||||
if(state & LV_STATE_DISABLED) {
|
if(obj_state & LV_STATE_CHECKED) {
|
||||||
return LV_BTN_STATE_DISABLED;
|
if(obj_state & LV_STATE_PRESSED) return btn_state | LV_BTN_STATE_CHECKED_PRESSED;
|
||||||
}
|
else return btn_state | LV_BTN_STATE_CHECKED_RELEASED;
|
||||||
else if(state & LV_STATE_CHECKED) {
|
|
||||||
if(state & LV_STATE_PRESSED) return LV_BTN_STATE_CHECKED_PRESSED;
|
|
||||||
else return LV_BTN_STATE_CHECKED_RELEASED;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(state & LV_STATE_PRESSED) return LV_BTN_STATE_PRESSED;
|
if(obj_state & LV_STATE_PRESSED) return btn_state | LV_BTN_STATE_PRESSED;
|
||||||
else return LV_BTN_STATE_RELEASED;
|
else return btn_state | LV_BTN_STATE_RELEASED;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,11 +36,12 @@ extern "C" {
|
|||||||
/** Possible states of a button.
|
/** Possible states of a button.
|
||||||
* It can be used not only by buttons but other button-like objects too*/
|
* It can be used not only by buttons but other button-like objects too*/
|
||||||
enum {
|
enum {
|
||||||
|
LV_BTN_STATE_ACTIVE,
|
||||||
LV_BTN_STATE_RELEASED,
|
LV_BTN_STATE_RELEASED,
|
||||||
LV_BTN_STATE_PRESSED,
|
LV_BTN_STATE_PRESSED,
|
||||||
LV_BTN_STATE_CHECKED_RELEASED,
|
LV_BTN_STATE_CHECKED_RELEASED,
|
||||||
LV_BTN_STATE_CHECKED_PRESSED,
|
LV_BTN_STATE_CHECKED_PRESSED,
|
||||||
LV_BTN_STATE_DISABLED,
|
LV_BTN_STATE_DISABLED = 0x80,
|
||||||
_LV_BTN_STATE_LAST, /* Number of states*/
|
_LV_BTN_STATE_LAST, /* Number of states*/
|
||||||
};
|
};
|
||||||
typedef uint8_t lv_btn_state_t;
|
typedef uint8_t lv_btn_state_t;
|
||||||
@@ -153,6 +154,7 @@ static inline void lv_btn_set_fit(lv_obj_t * btn, lv_fit_t fit)
|
|||||||
* Get the current state of the button
|
* Get the current state of the button
|
||||||
* @param btn pointer to a button object
|
* @param btn pointer to a button object
|
||||||
* @return the state of the button (from lv_btn_state_t enum)
|
* @return the state of the button (from lv_btn_state_t enum)
|
||||||
|
* If the button is in disabled state `LV_BTN_STATE_DISABLED` will be ORed to the other button states.
|
||||||
*/
|
*/
|
||||||
lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn);
|
lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user