Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
24
sdk/lib/lvgl/examples/event/index.rst
Normal file
24
sdk/lib/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
sdk/lib/lvgl/examples/event/lv_example_event.h
Normal file
41
sdk/lib/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
sdk/lib/lvgl/examples/event/lv_example_event_1.c
Normal file
30
sdk/lib/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_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
|
||||
25
sdk/lib/lvgl/examples/event/lv_example_event_1.py
Normal file
25
sdk/lib/lvgl/examples/event/lv_example_event_1.py
Normal file
@@ -0,0 +1,25 @@
|
||||
class Event_1():
|
||||
def __init__(self):
|
||||
self.cnt = 1
|
||||
#
|
||||
# Add click event to a button
|
||||
#
|
||||
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.set_size(100, 50)
|
||||
btn.center()
|
||||
btn.add_event_cb(self.event_cb, lv.EVENT.CLICKED, None)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text("Click me!")
|
||||
label.center()
|
||||
|
||||
def event_cb(self,e):
|
||||
print("Clicked")
|
||||
|
||||
btn = e.get_target()
|
||||
label = btn.get_child(0)
|
||||
label.set_text(str(self.cnt))
|
||||
self.cnt += 1
|
||||
|
||||
evt1 = Event_1()
|
||||
46
sdk/lib/lvgl/examples/event/lv_example_event_2.c
Normal file
46
sdk/lib/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
|
||||
22
sdk/lib/lvgl/examples/event/lv_example_event_2.py
Normal file
22
sdk/lib/lvgl/examples/event/lv_example_event_2.py
Normal file
@@ -0,0 +1,22 @@
|
||||
def event_cb(e,label):
|
||||
code = e.get_code()
|
||||
if code == lv.EVENT.PRESSED:
|
||||
label.set_text("The last button event:\nLV_EVENT_PRESSED")
|
||||
elif code == lv.EVENT.CLICKED:
|
||||
label.set_text("The last button event:\nLV_EVENT_CLICKED")
|
||||
elif code == lv.EVENT.LONG_PRESSED:
|
||||
label.set_text("The last button event:\nLV_EVENT_LONG_PRESSED")
|
||||
elif code == lv.EVENT.LONG_PRESSED_REPEAT:
|
||||
label.set_text("The last button event:\nLV_EVENT_LONG_PRESSED_REPEAT")
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.set_size(100, 50)
|
||||
btn.center()
|
||||
|
||||
btn_label = lv.label(btn)
|
||||
btn_label.set_text("Click me!")
|
||||
btn_label.center()
|
||||
|
||||
info_label = lv.label(lv.scr_act())
|
||||
info_label.set_text("The last button event:\nNone")
|
||||
|
||||
btn.add_event_cb(lambda e: event_cb(e,info_label), lv.EVENT.ALL, None)
|
||||
44
sdk/lib/lvgl/examples/event/lv_example_event_3.c
Normal file
44
sdk/lib/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, "%"LV_PRIu32, i);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_CLICKED, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
32
sdk/lib/lvgl/examples/event/lv_example_event_3.py
Normal file
32
sdk/lib/lvgl/examples/event/lv_example_event_3.py
Normal file
@@ -0,0 +1,32 @@
|
||||
def event_cb(e):
|
||||
|
||||
# The original target of the event. Can be the buttons or the container
|
||||
target = e.get_target()
|
||||
# print(type(target))
|
||||
|
||||
# If container was clicked do nothing
|
||||
if type(target) != type(lv.btn()):
|
||||
return
|
||||
|
||||
# Make the clicked buttons red
|
||||
target.set_style_bg_color(lv.palette_main(lv.PALETTE.RED), 0)
|
||||
|
||||
#
|
||||
# Demonstrate event bubbling
|
||||
#
|
||||
|
||||
cont = lv.obj(lv.scr_act())
|
||||
cont.set_size(320, 200)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
|
||||
for i in range(30):
|
||||
btn = lv.btn(cont)
|
||||
btn.set_size(80, 50)
|
||||
btn.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text(str(i))
|
||||
label.center()
|
||||
|
||||
cont.add_event_cb(event_cb, lv.EVENT.CLICKED, None)
|
||||
56
sdk/lib/lvgl/examples/event/lv_example_event_4.c
Normal file
56
sdk/lib/lvgl/examples/event/lv_example_event_4.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#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(timer->user_data);
|
||||
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_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
|
||||
if(dsc->class_p == &lv_obj_class && 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_align(&obj->coords, &a, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_draw_rect(dsc->draw_ctx, &draw_dsc, &a);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrate the usage of draw event
|
||||
*/
|
||||
void lv_example_event_4(void)
|
||||
{
|
||||
lv_obj_t * cont = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(cont, 200, 200);
|
||||
lv_obj_center(cont);
|
||||
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_DRAW_PART_END, NULL);
|
||||
lv_timer_create(timer_cb, 30, cont);
|
||||
}
|
||||
|
||||
#endif
|
||||
52
sdk/lib/lvgl/examples/event/lv_example_event_4.py
Normal file
52
sdk/lib/lvgl/examples/event/lv_example_event_4.py
Normal file
@@ -0,0 +1,52 @@
|
||||
class LV_Example_Event_4:
|
||||
|
||||
def __init__(self):
|
||||
#
|
||||
# Demonstrate the usage of draw event
|
||||
#
|
||||
self.size = 0
|
||||
self.size_dec = False
|
||||
self.cont = lv.obj(lv.scr_act())
|
||||
self.cont.set_size(200, 200)
|
||||
self.cont.center()
|
||||
self.cont.add_event_cb(self.event_cb, lv.EVENT.DRAW_PART_END, None)
|
||||
lv.timer_create(self.timer_cb, 30, None)
|
||||
|
||||
def timer_cb(self,timer) :
|
||||
self.cont.invalidate()
|
||||
if self.size_dec :
|
||||
self.size -= 1
|
||||
else :
|
||||
self.size += 1
|
||||
|
||||
if self.size == 50 :
|
||||
self.size_dec = True
|
||||
elif self.size == 0:
|
||||
self.size_dec = False
|
||||
|
||||
def event_cb(self,e) :
|
||||
obj = e.get_target()
|
||||
dsc = e.get_draw_part_dsc()
|
||||
if dsc.class_p == lv.obj_class and dsc.part == lv.PART.MAIN :
|
||||
draw_dsc = lv.draw_rect_dsc_t()
|
||||
draw_dsc.init()
|
||||
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
|
||||
|
||||
a = lv.area_t()
|
||||
a.x1 = 0
|
||||
a.y1 = 0
|
||||
a.x2 = self.size
|
||||
a.y2 = self.size
|
||||
coords = lv.area_t()
|
||||
obj.get_coords(coords)
|
||||
coords.align(a, lv.ALIGN.CENTER, 0, 0)
|
||||
|
||||
dsc.draw_ctx.rect(draw_dsc, a)
|
||||
|
||||
lv_example_event_4 = LV_Example_Event_4()
|
||||
Reference in New Issue
Block a user