A39模拟器
This commit is contained in:
25
MXC-A39/lvgl/examples/event/index.rst
Normal file
25
MXC-A39/lvgl/examples/event/index.rst
Normal file
@ -0,0 +1,25 @@
|
||||
C
|
||||
^
|
||||
|
||||
Button click event
|
||||
"""""""""""""""""""
|
||||
|
||||
.. lv_example:: event/lv_example_event_1
|
||||
:language: c
|
||||
|
||||
Handle multiple events
|
||||
""""""""""""""""""""""""
|
||||
.. lv_example:: event/lv_example_event_2
|
||||
:language: c
|
||||
|
||||
|
||||
Event bubbling
|
||||
""""""""""""""""""""""""
|
||||
.. lv_example:: event/lv_example_event_3
|
||||
:language: c
|
||||
|
||||
|
||||
MicroPython
|
||||
^^^^^^^^^^^
|
||||
|
||||
No examples yet.
|
40
MXC-A39/lvgl/examples/event/lv_example_event.h
Normal file
40
MXC-A39/lvgl/examples/event/lv_example_event.h
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file lv_example_event.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_EVENT_H
|
||||
#define LV_EXAMPLE_EVENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_event_1(void);
|
||||
void lv_example_event_2(void);
|
||||
void lv_example_event_3(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_EVENT_H*/
|
30
MXC-A39/lvgl/examples/event/lv_example_event_1.c
Normal file
30
MXC-A39/lvgl/examples/event/lv_example_event_1.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_SWITCH
|
||||
|
||||
static void event_cb(lv_event_t * e)
|
||||
{
|
||||
LV_LOG_USER("Clicked");
|
||||
|
||||
static uint32_t cnt = 1;
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
lv_obj_t * label = lv_obj_get_child(btn, 0);
|
||||
lv_label_set_text_fmt(label, "%d", cnt);
|
||||
cnt++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add click event to a button
|
||||
*/
|
||||
void lv_example_event_1(void)
|
||||
{
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_size(btn, 100, 50);
|
||||
lv_obj_center(btn);
|
||||
lv_obj_add_event_cb(btn, event_cb, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Click me!");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif
|
46
MXC-A39/lvgl/examples/event/lv_example_event_2.c
Normal file
46
MXC-A39/lvgl/examples/event/lv_example_event_2.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_SWITCH
|
||||
|
||||
static void event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * label = lv_event_get_user_data(e);
|
||||
|
||||
switch(code) {
|
||||
case LV_EVENT_PRESSED:
|
||||
lv_label_set_text(label, "The last button event:\nLV_EVENT_PRESSED");
|
||||
break;
|
||||
case LV_EVENT_CLICKED:
|
||||
lv_label_set_text(label, "The last button event:\nLV_EVENT_CLICKED");
|
||||
break;
|
||||
case LV_EVENT_LONG_PRESSED:
|
||||
lv_label_set_text(label, "The last button event:\nLV_EVENT_LONG_PRESSED");
|
||||
break;
|
||||
case LV_EVENT_LONG_PRESSED_REPEAT:
|
||||
lv_label_set_text(label, "The last button event:\nLV_EVENT_LONG_PRESSED_REPEAT");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle multiple events
|
||||
*/
|
||||
void lv_example_event_2(void)
|
||||
{
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_size(btn, 100, 50);
|
||||
lv_obj_center(btn);
|
||||
|
||||
lv_obj_t * btn_label = lv_label_create(btn);
|
||||
lv_label_set_text(btn_label, "Click me!");
|
||||
lv_obj_center(btn_label);
|
||||
|
||||
lv_obj_t * info_label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(info_label, "The last button event:\nNone");
|
||||
|
||||
lv_obj_add_event_cb(btn, event_cb, LV_EVENT_ALL, info_label);
|
||||
}
|
||||
|
||||
#endif
|
44
MXC-A39/lvgl/examples/event/lv_example_event_3.c
Normal file
44
MXC-A39/lvgl/examples/event/lv_example_event_3.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_FLEX
|
||||
|
||||
static void event_cb(lv_event_t * e)
|
||||
{
|
||||
/*The original target of the event. Can be the buttons or the container*/
|
||||
lv_obj_t * target = lv_event_get_target(e);
|
||||
|
||||
/*The current target is always the container as the event is added to it*/
|
||||
lv_obj_t * cont = lv_event_get_current_target(e);
|
||||
|
||||
/*If container was clicked do nothing*/
|
||||
if(target == cont) return;
|
||||
|
||||
/*Make the clicked buttons red*/
|
||||
lv_obj_set_style_bg_color(target, lv_palette_main(LV_PALETTE_RED), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrate event bubbling
|
||||
*/
|
||||
void lv_example_event_3(void)
|
||||
{
|
||||
|
||||
lv_obj_t * cont = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(cont, 290, 200);
|
||||
lv_obj_center(cont);
|
||||
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < 30; i++) {
|
||||
lv_obj_t * btn = lv_btn_create(cont);
|
||||
lv_obj_set_size(btn, 80, 50);
|
||||
lv_obj_add_flag(btn, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text_fmt(label, "%d", i);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_CLICKED, NULL);
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user