From d962e36dbbe363c459dda4365ab3db2a61d3c2fa Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Fri, 25 Jan 2019 17:09:59 -0800 Subject: [PATCH 1/3] lv_sw: lv_sw_toggle initial commit --- lv_objx/lv_sw.c | 16 ++++++++++++++++ lv_objx/lv_sw.h | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index 25f00f5db..f25144cfa 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -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); } +/** + * Set a function which will be called when the switch is toggled by the user + * @param sw pointer to switch object + * @param action a callback function + */ +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 diff --git a/lv_objx/lv_sw.h b/lv_objx/lv_sw.h index 9ab27144f..a0a0c9bcc 100644 --- a/lv_objx/lv_sw.h +++ b/lv_objx/lv_sw.h @@ -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 From 6af285adb87ed3f99f70a40b879c09cee9e38e94 Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Fri, 25 Jan 2019 17:42:08 -0800 Subject: [PATCH 2/3] lv_sw: lv_sw_toggle doc fix --- lv_objx/lv_sw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index f25144cfa..cb3b35855 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -148,9 +148,9 @@ void lv_sw_off(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 - * @param action a callback function + * 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); From 64c87e0e4a751b31ab086465389aff8ceff8461d Mon Sep 17 00:00:00 2001 From: Brian Pugh Date: Fri, 25 Jan 2019 20:17:43 -0800 Subject: [PATCH 3/3] lv_sw.c: lv_sw_toggle_anim initial commit --- lv_objx/lv_sw.c | 16 ++++++++++++++++ lv_objx/lv_sw.h | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index cb3b35855..2b09354ae 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -189,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 diff --git a/lv_objx/lv_sw.h b/lv_objx/lv_sw.h index a0a0c9bcc..28b22f739 100644 --- a/lv_objx/lv_sw.h +++ b/lv_objx/lv_sw.h @@ -107,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