初版
This commit is contained in:
@@ -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*/
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".lv_ui_core.data.bss")
|
||||
#pragma data_seg(".lv_ui_core.data")
|
||||
#pragma const_seg(".lv_ui_core.text.const")
|
||||
#pragma code_seg(".lv_ui_core.text")
|
||||
#endif
|
||||
#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_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
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".lv_ui_core.data.bss")
|
||||
#pragma data_seg(".lv_ui_core.data")
|
||||
#pragma const_seg(".lv_ui_core.text.const")
|
||||
#pragma code_seg(".lv_ui_core.text")
|
||||
#endif
|
||||
#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
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".lv_ui_core.data.bss")
|
||||
#pragma data_seg(".lv_ui_core.data")
|
||||
#pragma const_seg(".lv_ui_core.text.const")
|
||||
#pragma code_seg(".lv_ui_core.text")
|
||||
#endif
|
||||
#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, "%"LV_PRIu32, i);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_CLICKED, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".lv_ui_core.data.bss")
|
||||
#pragma data_seg(".lv_ui_core.data")
|
||||
#pragma const_seg(".lv_ui_core.text.const")
|
||||
#pragma code_seg(".lv_ui_core.text")
|
||||
#endif
|
||||
#include "../lv_examples.h"
|
||||
|
||||
#if LV_BUILD_EXAMPLES
|
||||
|
||||
static int n = 3;
|
||||
static lv_obj_t *label = NULL;
|
||||
|
||||
static void timer_cb(lv_timer_t *timer)
|
||||
{
|
||||
if (n < 3 || n > 32) {
|
||||
n = 3;
|
||||
} else {
|
||||
static uint32_t old_tick = 0;
|
||||
uint32_t tick = lv_tick_get();
|
||||
if (!old_tick) {
|
||||
old_tick = tick;
|
||||
}
|
||||
if (tick - old_tick > 3000) {
|
||||
n++;
|
||||
lv_label_set_text_fmt(label, "%d sides", n);
|
||||
old_tick = tick;
|
||||
}
|
||||
}
|
||||
lv_obj_invalidate(timer->user_data);
|
||||
}
|
||||
|
||||
static void event_cb(lv_event_t *e)
|
||||
{
|
||||
/*The original target of the event. Can be the buttons or the container*/
|
||||
lv_draw_ctx_t *draw_ctx = lv_event_get_draw_ctx(e);
|
||||
lv_draw_rect_dsc_t draw_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_dsc);
|
||||
draw_dsc.bg_color = lv_palette_main(LV_PALETTE_LIGHT_GREEN);
|
||||
draw_dsc.bg_opa = LV_OPA_COVER;
|
||||
lv_point_t points[32];
|
||||
int i, r = 150;
|
||||
uint32_t tick = lv_tick_get();
|
||||
for (i = 0; i < n; i++) {
|
||||
int angle = i * 360 / n + ((tick % 36000) / 100);
|
||||
lv_coord_t x = 150 + (r * lv_trigo_cos(angle) >> LV_TRIGO_SHIFT), y =
|
||||
150 + (r * lv_trigo_sin(angle) >> LV_TRIGO_SHIFT);
|
||||
points[i].x = x;
|
||||
points[i].y = y;
|
||||
}
|
||||
lv_draw_polygon(draw_ctx, &draw_dsc, points, n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrate event bubbling
|
||||
*/
|
||||
void lv_example_event_4(void)
|
||||
{
|
||||
|
||||
lv_obj_t *cont = lv_obj_create(lv_scr_act());
|
||||
lv_obj_remove_style_all(cont);
|
||||
lv_obj_set_size(cont, 300, 300);
|
||||
label = lv_label_create(cont);
|
||||
lv_label_set_text_fmt(label, "%d sides", n);
|
||||
lv_obj_center(label);
|
||||
|
||||
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_DRAW_MAIN, NULL);
|
||||
lv_timer_create(timer_cb, 17, cont);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user