add lv_components as src/extra and minor fixes
This commit is contained in:
12
examples/widgets/checkbox/index.rst
Normal file
12
examples/widgets/checkbox/index.rst
Normal file
@@ -0,0 +1,12 @@
|
||||
C
|
||||
^
|
||||
|
||||
Simple Checkbox
|
||||
""""""""""""""""
|
||||
.. lv_example:: lv_ex_widgets/lv_ex_checkbox/lv_ex_checkbox_1
|
||||
:language: c
|
||||
|
||||
MicroPython
|
||||
^^^^^^^^^^^
|
||||
|
||||
No examples yet.
|
||||
44
examples/widgets/checkbox/lv_checkbox_example_1.c
Normal file
44
examples/widgets/checkbox/lv_checkbox_example_1.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "../../../lvgl.h"
|
||||
#include <stdio.h>
|
||||
#if LV_USE_CHECKBOX
|
||||
|
||||
static void event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
const char * txt = lv_checkbox_get_text(obj);
|
||||
const char * state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" : "Unchecked";
|
||||
printf("%s: %s\n", txt, state);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_ex_checkbox_1(void)
|
||||
{
|
||||
static lv_flex_t flex_center;
|
||||
lv_flex_init(&flex_center);
|
||||
lv_flex_set_flow(&flex_center, LV_FLEX_FLOW_COLUMN);
|
||||
lv_flex_set_place(&flex_center, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER);
|
||||
|
||||
lv_obj_set_layout(lv_scr_act(), &flex_center);
|
||||
|
||||
lv_obj_t * cb;
|
||||
cb = lv_checkbox_create(lv_scr_act(), NULL);
|
||||
lv_checkbox_set_text(cb, "Apple");
|
||||
lv_obj_add_event_cb(cb, event_handler, NULL);
|
||||
|
||||
cb = lv_checkbox_create(lv_scr_act(), NULL);
|
||||
lv_checkbox_set_text(cb, "Banana");
|
||||
lv_obj_add_state(cb, LV_STATE_CHECKED);
|
||||
lv_obj_add_event_cb(cb, event_handler, NULL);
|
||||
|
||||
cb = lv_checkbox_create(lv_scr_act(), NULL);
|
||||
lv_checkbox_set_text(cb, "Lemon");
|
||||
lv_obj_add_state(cb, LV_STATE_DISABLED);
|
||||
lv_obj_add_event_cb(cb, event_handler, NULL);
|
||||
|
||||
cb = lv_checkbox_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED);
|
||||
lv_checkbox_set_text(cb, "Melon");
|
||||
lv_obj_add_event_cb(cb, event_handler, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
8
examples/widgets/checkbox/lv_checkbox_example_1.py
Normal file
8
examples/widgets/checkbox/lv_checkbox_example_1.py
Normal file
@@ -0,0 +1,8 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
print("State: %s" % ("Checked" if obj.is_checked() else "Unchecked"))
|
||||
|
||||
cb = lv.cb(lv.scr_act())
|
||||
cb.set_text("I agree to terms and conditions.")
|
||||
cb.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
cb.set_event_cb(event_handler)
|
||||
Reference in New Issue
Block a user