update asserts

This commit is contained in:
Gabor Kiss-Vamosi
2021-02-08 09:53:03 +01:00
parent 956a367dbc
commit 7bec13c2b9
173 changed files with 4906 additions and 696 deletions

View File

@@ -0,0 +1,40 @@
#include "../../../lvgl.h"
#include <stdio.h>
#if LV_USE_SWITCH
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
if(event == LV_EVENT_VALUE_CHANGED) {
printf("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off");
}
}
void lv_example_switch_1(void)
{
lv_obj_set_layout(lv_scr_act(), &lv_flex_center_column);
lv_obj_t * sw;
sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, -50);
lv_obj_add_event_cb(sw, event_handler, NULL);
sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_add_state(sw, LV_STATE_CHECKED);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50);
lv_obj_add_event_cb(sw, event_handler, NULL);
sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_add_state(sw, LV_STATE_DISABLED);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50);
lv_obj_add_event_cb(sw, event_handler, NULL);
sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50);
lv_obj_add_event_cb(sw, event_handler, NULL);
}
#endif

View File

@@ -0,0 +1,48 @@
def event_handler(obj, event):
if event == lv.EVENT.VALUE_CHANGED:
print("State: %s" % ("On" if obj.get_state() else "Off"))
# Create styles for the switch
bg_style = lv.style_t()
indic_style = lv.style_t()
knob_on_style = lv.style_t()
knob_off_style = lv.style_t()
lv.style_copy(bg_style, lv.style_pretty)
bg_style.body.radius = 800
bg_style.body.padding.top = 6
bg_style.body.padding.bottom = 6
lv.style_copy(indic_style, lv.style_pretty_color)
indic_style.body.radius = 800
indic_style.body.main_color = lv.color_hex(0x9fc8ef)
indic_style.body.grad_color = lv.color_hex(0x9fc8ef)
indic_style.body.padding.left = 0
indic_style.body.padding.right = 0
indic_style.body.padding.top = 0
indic_style.body.padding.bottom = 0
lv.style_copy(knob_off_style, lv.style_pretty)
knob_off_style.body.radius = 800
knob_off_style.body.shadow.width = 4
knob_off_style.body.shadow.type = lv.SHADOW.BOTTOM
lv.style_copy(knob_on_style, lv.style_pretty_color)
knob_on_style.body.radius = 800
knob_on_style.body.shadow.width = 4
knob_on_style.body.shadow.type = lv.SHADOW.BOTTOM
# Create a switch and apply the styles
sw1 = lv.sw(lv.scr_act())
sw1.set_style(lv.sw.STYLE.BG, bg_style)
sw1.set_style(lv.sw.STYLE.INDIC, indic_style)
sw1.set_style(lv.sw.STYLE.KNOB_ON, knob_on_style)
sw1.set_style(lv.sw.STYLE.KNOB_OFF, knob_off_style)
sw1.align(None, lv.ALIGN.CENTER, 0, -50)
sw1.set_event_cb(event_handler)
# Copy the first switch and turn it ON
sw2 = lv.sw(lv.scr_act(), sw1)
sw2.on(lv.ANIM.ON)
sw2.align(None, lv.ALIGN.CENTER, 0, 50)
sw2.set_event_cb(lambda o,e: None)