feat(switch): add vertical switch function (#6786)
Co-authored-by: lizhaoming <13678462+lizhao-ming@user.noreply.gitee.com> Co-authored-by: 100ask <support@100ask.net> Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
committed by
GitHub
parent
7f57f37560
commit
a37f84f34c
@@ -136,6 +136,7 @@ void lv_example_spinbox_1(void);
|
||||
void lv_example_spinner_1(void);
|
||||
|
||||
void lv_example_switch_1(void);
|
||||
void lv_example_switch_2(void);
|
||||
|
||||
void lv_example_table_1(void);
|
||||
void lv_example_table_2(void);
|
||||
|
||||
@@ -5,3 +5,10 @@ Simple Switch
|
||||
.. lv_example:: widgets/switch/lv_example_switch_1
|
||||
:language: c
|
||||
|
||||
|
||||
Switch Orientation
|
||||
-------------------
|
||||
|
||||
.. lv_example:: widgets/switch/lv_example_switch_2
|
||||
:language: c
|
||||
|
||||
|
||||
32
examples/widgets/switch/lv_example_switch_2.c
Normal file
32
examples/widgets/switch/lv_example_switch_2.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_SWITCH && LV_BUILD_EXAMPLES
|
||||
|
||||
static void event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
LV_UNUSED(obj);
|
||||
LV_LOG_USER("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off");
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_switch_2(void)
|
||||
{
|
||||
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(lv_screen_active(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
lv_obj_t * sw;
|
||||
|
||||
sw = lv_switch_create(lv_screen_active());
|
||||
lv_obj_set_size(sw, 30, 60);
|
||||
lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
sw = lv_switch_create(lv_screen_active());
|
||||
lv_obj_set_size(sw, 30, 60);
|
||||
lv_switch_set_orientation(sw, LV_SWITCH_ORIENTATION_VERTICAL);
|
||||
lv_obj_add_state(sw, LV_STATE_CHECKED);
|
||||
lv_obj_add_event_cb(sw, event_handler, LV_EVENT_ALL, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user