Merge pull request #762 from joltwallet/sw_toggle

Add lv_sw_toggle() and lv_sw_toggle_anim()
This commit is contained in:
Themba D
2019-01-26 15:29:32 -05:00
committed by GitHub
2 changed files with 46 additions and 0 deletions

View File

@@ -147,6 +147,22 @@ void lv_sw_off(lv_obj_t * sw)
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
}
/**
* Toggle the position of the switch
* @param sw pointer to a switch object
* @return resulting state of the switch.
*/
bool lv_sw_toggle(lv_obj_t *sw) {
bool state = lv_sw_get_state(sw);
if(state) {
lv_sw_off(sw);
}
else {
lv_sw_on(sw);
}
return !state;
}
/**
* Turn ON the switch with an animation
* @param sw pointer to a switch object
@@ -173,6 +189,22 @@ void lv_sw_off_anim(lv_obj_t * sw)
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
}
/**
* Toggle the position of the switch with an animation
* @param sw pointer to a switch object
* @return resulting state of the switch.
*/
bool lv_sw_toggle_anim(lv_obj_t *sw) {
bool state = lv_sw_get_state(sw);
if(state) {
lv_sw_off_anim(sw);
}
else {
lv_sw_on_anim(sw);
}
return !state;
}
/**
* Set a style of a switch
* @param sw pointer to a switch object

View File

@@ -88,6 +88,13 @@ void lv_sw_on(lv_obj_t *sw);
*/
void lv_sw_off(lv_obj_t *sw);
/**
* Toggle the position of the switch
* @param sw pointer to a switch object
* @return resulting state of the switch.
*/
bool lv_sw_toggle(lv_obj_t *sw);
/**
* Turn ON the switch with an animation
* @param sw pointer to a switch object
@@ -100,6 +107,13 @@ void lv_sw_on_anim(lv_obj_t * sw);
*/
void lv_sw_off_anim(lv_obj_t * sw);
/**
* Toggle the position of the switch with an animation
* @param sw pointer to a switch object
* @return resulting state of the switch.
*/
bool lv_sw_toggle_anim(lv_obj_t *sw);
/**
* Set a function which will be called when the switch is toggled by the user
* @param sw pointer to switch object