A39模拟器
This commit is contained in:
13
MXC-A39/lvgl/examples/widgets/checkbox/index.rst
Normal file
13
MXC-A39/lvgl/examples/widgets/checkbox/index.rst
Normal file
@ -0,0 +1,13 @@
|
||||
C
|
||||
^
|
||||
|
||||
Simple Checkboxes
|
||||
"""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/checkbox/lv_example_checkbox_1
|
||||
:language: c
|
||||
|
||||
MicroPython
|
||||
^^^^^^^^^^^
|
||||
|
||||
No examples yet.
|
@ -0,0 +1,43 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CHECKBOX && 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) {
|
||||
const char * txt = lv_checkbox_get_text(obj);
|
||||
const char * state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" : "Unchecked";
|
||||
LV_LOG_USER("%s: %s", txt, state);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_checkbox_1(void)
|
||||
{
|
||||
lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(lv_scr_act(), LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
lv_obj_t * cb;
|
||||
cb = lv_checkbox_create(lv_scr_act());
|
||||
lv_checkbox_set_text(cb, "Apple");
|
||||
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
cb = lv_checkbox_create(lv_scr_act());
|
||||
lv_checkbox_set_text(cb, "Banana");
|
||||
lv_obj_add_state(cb, LV_STATE_CHECKED);
|
||||
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
cb = lv_checkbox_create(lv_scr_act());
|
||||
lv_checkbox_set_text(cb, "Lemon");
|
||||
lv_obj_add_state(cb, LV_STATE_DISABLED);
|
||||
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
cb = lv_checkbox_create(lv_scr_act());
|
||||
lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED);
|
||||
lv_checkbox_set_text(cb, "Melon\nand a new line");
|
||||
lv_obj_add_event_cb(cb, event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
lv_obj_update_layout(cb);
|
||||
}
|
||||
|
||||
#endif
|
@ -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