@@ -2,23 +2,29 @@
|
||||
Button click event
|
||||
------------------
|
||||
|
||||
.. lv_example:: event/lv_example_event_1
|
||||
.. lv_example:: event/lv_example_event_click
|
||||
:language: c
|
||||
|
||||
Click streaks
|
||||
-------------
|
||||
|
||||
.. lv_example:: event/lv_example_event_streak
|
||||
:language: c
|
||||
|
||||
Handle multiple events
|
||||
----------------------
|
||||
.. lv_example:: event/lv_example_event_2
|
||||
.. lv_example:: event/lv_example_event_button
|
||||
:language: c
|
||||
|
||||
|
||||
Event bubbling
|
||||
--------------
|
||||
.. lv_example:: event/lv_example_event_3
|
||||
.. lv_example:: event/lv_example_event_bubble
|
||||
:language: c
|
||||
|
||||
Draw event
|
||||
----------
|
||||
.. lv_example:: event/lv_example_event_4
|
||||
.. lv_example:: event/lv_example_event_draw
|
||||
:language: c
|
||||
|
||||
|
||||
|
||||
@@ -25,10 +25,11 @@ extern "C" {
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_event_1(void);
|
||||
void lv_example_event_2(void);
|
||||
void lv_example_event_3(void);
|
||||
void lv_example_event_4(void);
|
||||
void lv_example_event_click(void);
|
||||
void lv_example_event_streak(void);
|
||||
void lv_example_event_button(void);
|
||||
void lv_example_event_bubble(void);
|
||||
void lv_example_event_draw(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -19,7 +19,7 @@ static void event_cb(lv_event_t * e)
|
||||
/**
|
||||
* Demonstrate event bubbling
|
||||
*/
|
||||
void lv_example_event_3(void)
|
||||
void lv_example_event_bubble(void)
|
||||
{
|
||||
|
||||
lv_obj_t * cont = lv_obj_create(lv_screen_active());
|
||||
@@ -27,7 +27,7 @@ static void event_cb(lv_event_t * e)
|
||||
/**
|
||||
* Handle multiple events
|
||||
*/
|
||||
void lv_example_event_2(void)
|
||||
void lv_example_event_button(void)
|
||||
{
|
||||
lv_obj_t * btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_size(btn, 100, 50);
|
||||
@@ -15,7 +15,7 @@ static void event_cb(lv_event_t * e)
|
||||
/**
|
||||
* Add click event to a button
|
||||
*/
|
||||
void lv_example_event_1(void)
|
||||
void lv_example_event_click(void)
|
||||
{
|
||||
lv_obj_t * btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_size(btn, 100, 50);
|
||||
@@ -47,7 +47,7 @@ static void event_cb(lv_event_t * e)
|
||||
/**
|
||||
* Demonstrate the usage of draw event
|
||||
*/
|
||||
void lv_example_event_4(void)
|
||||
void lv_example_event_draw(void)
|
||||
{
|
||||
lv_obj_t * cont = lv_obj_create(lv_screen_active());
|
||||
lv_obj_set_size(cont, 200, 200);
|
||||
40
examples/event/lv_example_event_streak.c
Normal file
40
examples/event/lv_example_event_streak.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES && LV_USE_LABEL
|
||||
|
||||
static void short_click_event_cb(lv_event_t * e)
|
||||
{
|
||||
LV_LOG_USER("Short clicked");
|
||||
|
||||
lv_obj_t * info_label = lv_event_get_user_data(e);
|
||||
lv_indev_t * indev = lv_event_get_param(e);
|
||||
uint8_t cnt = lv_indev_get_short_click_streak(indev);
|
||||
lv_label_set_text_fmt(info_label, "Short click streak: %"LV_PRIu32, cnt);
|
||||
}
|
||||
|
||||
static void streak_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
lv_obj_t * label = lv_obj_get_child(btn, 0);
|
||||
const char * text = lv_event_get_user_data(e);
|
||||
lv_label_set_text(label, text);
|
||||
}
|
||||
|
||||
void lv_example_event_streak(void)
|
||||
{
|
||||
lv_obj_t * info_label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(info_label, "No events yet");
|
||||
|
||||
lv_obj_t * btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_size(btn, 100, 50);
|
||||
lv_obj_center(btn);
|
||||
lv_obj_add_event_cb(btn, short_click_event_cb, LV_EVENT_SHORT_CLICKED, info_label);
|
||||
lv_obj_add_event_cb(btn, streak_event_cb, LV_EVENT_SINGLE_CLICKED, "Single clicked");
|
||||
lv_obj_add_event_cb(btn, streak_event_cb, LV_EVENT_DOUBLE_CLICKED, "Double clicked");
|
||||
lv_obj_add_event_cb(btn, streak_event_cb, LV_EVENT_TRIPLE_CLICKED, "Triple clicked");
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Click me!");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user