init Files
This commit is contained in:
24
libraries/lvgl/examples/event/index.rst
Normal file
24
libraries/lvgl/examples/event/index.rst
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
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
|
||||
|
||||
Draw event
|
||||
----------
|
||||
.. lv_example:: event/lv_example_event_4
|
||||
:language: c
|
||||
|
||||
|
||||
41
libraries/lvgl/examples/event/lv_example_event.h
Normal file
41
libraries/lvgl/examples/event/lv_example_event.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @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);
|
||||
void lv_example_event_4(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_EVENT_H*/
|
||||
30
libraries/lvgl/examples/event/lv_example_event_1.c
Normal file
30
libraries/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, "%"LV_PRIu32, cnt);
|
||||
cnt++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add click event to a button
|
||||
*/
|
||||
void lv_example_event_1(void)
|
||||
{
|
||||
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, 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
libraries/lvgl/examples/event/lv_example_event_2.c
Normal file
46
libraries/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_button_create(lv_screen_active());
|
||||
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_screen_active());
|
||||
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
libraries/lvgl/examples/event/lv_example_event_3.c
Normal file
44
libraries/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_screen_active());
|
||||
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_button_create(cont);
|
||||
lv_obj_set_size(btn, 70, 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, "%"LV_PRIu32, i);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_CLICKED, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
60
libraries/lvgl/examples/event/lv_example_event_4.c
Normal file
60
libraries/lvgl/examples/event/lv_example_event_4.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "../lv_examples.h"
|
||||
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
static uint32_t size = 0;
|
||||
static bool size_dec = false;
|
||||
|
||||
static void timer_cb(lv_timer_t * timer)
|
||||
{
|
||||
lv_obj_invalidate(lv_timer_get_user_data(timer));
|
||||
if(size_dec) size--;
|
||||
else size++;
|
||||
|
||||
if(size == 50) size_dec = true;
|
||||
else if(size == 0) size_dec = false;
|
||||
}
|
||||
|
||||
static void event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
lv_draw_task_t * draw_task = lv_event_get_draw_task(e);
|
||||
lv_draw_dsc_base_t * base_dsc = lv_draw_task_get_draw_dsc(draw_task);
|
||||
if(base_dsc->part == LV_PART_MAIN) {
|
||||
lv_draw_rect_dsc_t draw_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_dsc);
|
||||
draw_dsc.bg_color = lv_color_hex(0xffaaaa);
|
||||
draw_dsc.radius = LV_RADIUS_CIRCLE;
|
||||
draw_dsc.border_color = lv_color_hex(0xff5555);
|
||||
draw_dsc.border_width = 2;
|
||||
draw_dsc.outline_color = lv_color_hex(0xff0000);
|
||||
draw_dsc.outline_pad = 3;
|
||||
draw_dsc.outline_width = 2;
|
||||
|
||||
lv_area_t a;
|
||||
a.x1 = 0;
|
||||
a.y1 = 0;
|
||||
a.x2 = size;
|
||||
a.y2 = size;
|
||||
lv_area_t obj_coords;
|
||||
lv_obj_get_coords(obj, &obj_coords);
|
||||
lv_area_align(&obj_coords, &a, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_draw_rect(base_dsc->layer, &draw_dsc, &a);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrate the usage of draw event
|
||||
*/
|
||||
void lv_example_event_4(void)
|
||||
{
|
||||
lv_obj_t * cont = lv_obj_create(lv_screen_active());
|
||||
lv_obj_set_size(cont, 200, 200);
|
||||
lv_obj_center(cont);
|
||||
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_DRAW_TASK_ADDED, NULL);
|
||||
lv_obj_add_flag(cont, LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS);
|
||||
lv_timer_create(timer_cb, 30, cont);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user