initial commit
This commit is contained in:
16
libraries/lvgl/examples/others/fragment/index.rst
Normal file
16
libraries/lvgl/examples/others/fragment/index.rst
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
Basic fragment usage
|
||||
"""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/fragment/lv_example_fragment_1
|
||||
:language: c
|
||||
|
||||
|
||||
|
||||
Stack navigation example
|
||||
"""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/fragment/lv_example_fragment_2
|
||||
:language: c
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file lv_example_fragment.h
|
||||
*/
|
||||
#ifndef LV_EXAMPLE_FRAGMENT_H
|
||||
#define LV_EXAMPLE_FRAGMENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_fragment_1(void);
|
||||
|
||||
void lv_example_fragment_2(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_fragment_H*/
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @file lv_example_fragment_1.c
|
||||
* @brief Basic usage of obj fragment
|
||||
*/
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_FRAGMENT && LV_BUILD_EXAMPLES
|
||||
|
||||
static void sample_fragment_ctor(lv_fragment_t * self, void * args);
|
||||
|
||||
static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * parent);
|
||||
|
||||
static void sample_container_del(lv_event_t * e);
|
||||
|
||||
static lv_obj_t * root = NULL;
|
||||
|
||||
struct sample_fragment_t {
|
||||
lv_fragment_t base;
|
||||
const char * name;
|
||||
};
|
||||
|
||||
static const lv_fragment_class_t sample_cls = {
|
||||
.constructor_cb = sample_fragment_ctor,
|
||||
.create_obj_cb = sample_fragment_create_obj,
|
||||
.instance_size = sizeof(struct sample_fragment_t)
|
||||
};
|
||||
|
||||
void lv_example_fragment_1(void)
|
||||
{
|
||||
root = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(root, LV_PCT(100), LV_PCT(100));
|
||||
lv_fragment_manager_t * manager = lv_fragment_manager_create(NULL);
|
||||
/* Clean up the fragment manager before objects in containers got deleted */
|
||||
lv_obj_add_event_cb(root, sample_container_del, LV_EVENT_DELETE, manager);
|
||||
|
||||
lv_fragment_t * fragment = lv_fragment_create(&sample_cls, "Fragment");
|
||||
lv_fragment_manager_replace(manager, fragment, &root);
|
||||
}
|
||||
|
||||
|
||||
static void sample_fragment_ctor(lv_fragment_t * self, void * args)
|
||||
{
|
||||
((struct sample_fragment_t *) self)->name = args;
|
||||
}
|
||||
|
||||
static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * parent)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(parent);
|
||||
lv_obj_set_style_bg_opa(label, LV_OPA_COVER, 0);;
|
||||
lv_label_set_text_fmt(label, "Hello, %s!", ((struct sample_fragment_t *) self)->name);
|
||||
return label;
|
||||
}
|
||||
|
||||
static void sample_container_del(lv_event_t * e)
|
||||
{
|
||||
lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e);
|
||||
lv_fragment_manager_del(manager);
|
||||
}
|
||||
|
||||
#endif
|
||||
127
libraries/lvgl/examples/others/fragment/lv_example_fragment_2.c
Normal file
127
libraries/lvgl/examples/others/fragment/lv_example_fragment_2.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* @file lv_example_fragment_2.c
|
||||
* @brief Navigation stack using obj fragment
|
||||
*/
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_FRAGMENT && LV_USE_WIN && LV_BUILD_EXAMPLES
|
||||
|
||||
static void sample_fragment_ctor(lv_fragment_t * self, void * args);
|
||||
|
||||
static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * parent);
|
||||
|
||||
static void sample_push_click(lv_event_t * e);
|
||||
|
||||
static void sample_pop_click(lv_event_t * e);
|
||||
|
||||
static void sample_container_del(lv_event_t * e);
|
||||
|
||||
static void sample_fragment_inc_click(lv_event_t * e);
|
||||
|
||||
typedef struct sample_fragment_t {
|
||||
lv_fragment_t base;
|
||||
lv_obj_t * label;
|
||||
int depth;
|
||||
int counter;
|
||||
} sample_fragment_t;
|
||||
|
||||
static const lv_fragment_class_t sample_cls = {
|
||||
.constructor_cb = sample_fragment_ctor,
|
||||
.create_obj_cb = sample_fragment_create_obj,
|
||||
.instance_size = sizeof(sample_fragment_t)
|
||||
};
|
||||
|
||||
static lv_obj_t * container = NULL;
|
||||
|
||||
void lv_example_fragment_2(void)
|
||||
{
|
||||
lv_obj_t * root = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(root, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_layout(root, LV_LAYOUT_GRID);
|
||||
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||
static const lv_coord_t row_dsc[] = {LV_GRID_FR(1), LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
|
||||
lv_obj_set_grid_dsc_array(root, col_dsc, row_dsc);
|
||||
container = lv_obj_create(root);
|
||||
lv_obj_remove_style_all(container);
|
||||
lv_obj_set_grid_cell(container, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_STRETCH, 0, 1);
|
||||
|
||||
lv_obj_t * push_btn = lv_btn_create(root);
|
||||
lv_obj_t * push_label = lv_label_create(push_btn);
|
||||
lv_label_set_text(push_label, "Push");
|
||||
|
||||
lv_obj_t * pop_btn = lv_btn_create(root);
|
||||
lv_obj_t * pop_label = lv_label_create(pop_btn);
|
||||
lv_label_set_text(pop_label, "Pop");
|
||||
lv_obj_set_grid_cell(push_btn, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
|
||||
lv_obj_set_grid_cell(pop_btn, LV_GRID_ALIGN_END, 1, 1, LV_GRID_ALIGN_CENTER, 1, 1);
|
||||
|
||||
lv_fragment_manager_t * manager = lv_fragment_manager_create(NULL);
|
||||
/* Clean up the fragment manager before objects in containers got deleted */
|
||||
lv_obj_add_event_cb(root, sample_container_del, LV_EVENT_DELETE, manager);
|
||||
|
||||
int depth = 0;
|
||||
lv_fragment_t * fragment = lv_fragment_create(&sample_cls, &depth);
|
||||
lv_fragment_manager_push(manager, fragment, &container);
|
||||
lv_obj_add_event_cb(push_btn, sample_push_click, LV_EVENT_CLICKED, manager);
|
||||
lv_obj_add_event_cb(pop_btn, sample_pop_click, LV_EVENT_CLICKED, manager);
|
||||
}
|
||||
|
||||
|
||||
static void sample_fragment_ctor(lv_fragment_t * self, void * args)
|
||||
{
|
||||
LV_UNUSED(args);
|
||||
((sample_fragment_t *) self)->depth = *((int *) args);
|
||||
((sample_fragment_t *) self)->counter = 0;
|
||||
}
|
||||
|
||||
static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * parent)
|
||||
{
|
||||
sample_fragment_t * fragment = (sample_fragment_t *) self;
|
||||
lv_obj_t * content = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(content);
|
||||
lv_obj_set_style_bg_opa(content, LV_OPA_50, 0);
|
||||
lv_obj_set_style_bg_color(content, lv_palette_main(LV_PALETTE_YELLOW), 0);
|
||||
lv_obj_set_size(content, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_flex_flow(content, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_t * depth = lv_label_create(content);
|
||||
lv_label_set_text_fmt(depth, "Depth: %d", fragment->depth);
|
||||
lv_obj_t * label = lv_label_create(content);
|
||||
fragment->label = label;
|
||||
lv_label_set_text_fmt(label, "The button has been pressed %d times", fragment->counter);
|
||||
|
||||
lv_obj_t * inc_btn = lv_btn_create(content);
|
||||
lv_obj_t * inc_label = lv_label_create(inc_btn);
|
||||
lv_label_set_text(inc_label, "+1");
|
||||
lv_obj_add_event_cb(inc_btn, sample_fragment_inc_click, LV_EVENT_CLICKED, fragment);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
static void sample_push_click(lv_event_t * e)
|
||||
{
|
||||
lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e);
|
||||
size_t stack_size = lv_fragment_manager_get_stack_size(manager);
|
||||
lv_fragment_t * fragment = lv_fragment_create(&sample_cls, &stack_size);
|
||||
lv_fragment_manager_push(manager, fragment, &container);
|
||||
}
|
||||
|
||||
static void sample_pop_click(lv_event_t * e)
|
||||
{
|
||||
lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e);
|
||||
lv_fragment_manager_pop(manager);
|
||||
}
|
||||
|
||||
static void sample_container_del(lv_event_t * e)
|
||||
{
|
||||
lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e);
|
||||
lv_fragment_manager_del(manager);
|
||||
}
|
||||
|
||||
static void sample_fragment_inc_click(lv_event_t * e)
|
||||
{
|
||||
sample_fragment_t * fragment = (sample_fragment_t *) lv_event_get_user_data(e);
|
||||
fragment->counter++;
|
||||
lv_label_set_text_fmt(fragment->label, "The button has been pressed %d times", fragment->counter);
|
||||
}
|
||||
|
||||
#endif
|
||||
24
libraries/lvgl/examples/others/gridnav/index.rst
Normal file
24
libraries/lvgl/examples/others/gridnav/index.rst
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
Basic grid navigation
|
||||
"""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/gridnav/lv_example_gridnav_1
|
||||
:language: c
|
||||
|
||||
Grid navigation on a list
|
||||
""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/gridnav/lv_example_gridnav_2
|
||||
:language: c
|
||||
|
||||
Nested grid navigations
|
||||
"""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/gridnav/lv_example_gridnav_3
|
||||
:language: c
|
||||
|
||||
Simple navigation on a list widget
|
||||
"""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/gridnav/lv_example_gridnav_4
|
||||
:language: c
|
||||
41
libraries/lvgl/examples/others/gridnav/lv_example_gridnav.h
Normal file
41
libraries/lvgl/examples/others/gridnav/lv_example_gridnav.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file lv_example_gridnav.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_GRIDNAV_H
|
||||
#define LV_EXAMPLE_GRIDNAV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_gridnav_1(void);
|
||||
void lv_example_gridnav_2(void);
|
||||
void lv_example_gridnav_3(void);
|
||||
void lv_example_gridnav_4(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_GRIDNAV_H*/
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_GRIDNAV && LV_USE_FLEX && LV_BUILD_EXAMPLES
|
||||
|
||||
/**
|
||||
* Demonstrate a a basic grid navigation
|
||||
*/
|
||||
void lv_example_gridnav_1(void)
|
||||
{
|
||||
/*It's assumed that the default group is set and
|
||||
*there is a keyboard indev*/
|
||||
|
||||
lv_obj_t * cont1 = lv_obj_create(lv_scr_act());
|
||||
lv_gridnav_add(cont1, LV_GRIDNAV_CTRL_NONE);
|
||||
|
||||
/*Use flex here, but works with grid or manually placed objects as well*/
|
||||
lv_obj_set_flex_flow(cont1, LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_style_bg_color(cont1, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED);
|
||||
lv_obj_set_size(cont1, lv_pct(50), lv_pct(100));
|
||||
|
||||
/*Only the container needs to be in a group*/
|
||||
lv_group_add_obj(lv_group_get_default(), cont1);
|
||||
|
||||
lv_obj_t * label = lv_label_create(cont1);
|
||||
lv_label_set_text_fmt(label, "No rollover");
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < 10; i++) {
|
||||
lv_obj_t * obj = lv_btn_create(cont1);
|
||||
lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
|
||||
lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE);
|
||||
lv_group_remove_obj(obj); /*Not needed, we use the gridnav instead*/
|
||||
|
||||
lv_obj_t * label = lv_label_create(obj);
|
||||
lv_label_set_text_fmt(label, "%d", i);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
/* Create a second container with rollover grid nav mode.*/
|
||||
|
||||
lv_obj_t * cont2 = lv_obj_create(lv_scr_act());
|
||||
lv_gridnav_add(cont2, LV_GRIDNAV_CTRL_ROLLOVER);
|
||||
lv_obj_set_style_bg_color(cont2, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED);
|
||||
lv_obj_set_size(cont2, lv_pct(50), lv_pct(100));
|
||||
lv_obj_align(cont2, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
|
||||
label = lv_label_create(cont2);
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
lv_label_set_text_fmt(label, "Rollover\nUse tab to focus the other container");
|
||||
|
||||
/*Only the container needs to be in a group*/
|
||||
lv_group_add_obj(lv_group_get_default(), cont2);
|
||||
|
||||
/*Add and place some children manually*/
|
||||
lv_obj_t * ta = lv_textarea_create(cont2);
|
||||
lv_obj_set_size(ta, lv_pct(100), 80);
|
||||
lv_obj_set_pos(ta, 0, 80);
|
||||
lv_group_remove_obj(ta); /*Not needed, we use the gridnav instead*/
|
||||
|
||||
lv_obj_t * cb = lv_checkbox_create(cont2);
|
||||
lv_obj_set_pos(cb, 0, 170);
|
||||
lv_group_remove_obj(cb); /*Not needed, we use the gridnav instead*/
|
||||
|
||||
lv_obj_t * sw1 = lv_switch_create(cont2);
|
||||
lv_obj_set_pos(sw1, 0, 200);
|
||||
lv_group_remove_obj(sw1); /*Not needed, we use the gridnav instead*/
|
||||
|
||||
lv_obj_t * sw2 = lv_switch_create(cont2);
|
||||
lv_obj_set_pos(sw2, lv_pct(50), 200);
|
||||
lv_group_remove_obj(sw2); /*Not needed, we use the gridnav instead*/
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_GRIDNAV && LV_USE_LIST && LV_BUILD_EXAMPLES
|
||||
|
||||
/**
|
||||
* Grid navigation on a list
|
||||
*/
|
||||
void lv_example_gridnav_2(void)
|
||||
{
|
||||
/*It's assumed that the default group is set and
|
||||
*there is a keyboard indev*/
|
||||
|
||||
lv_obj_t * list1 = lv_list_create(lv_scr_act());
|
||||
lv_gridnav_add(list1, LV_GRIDNAV_CTRL_NONE);
|
||||
lv_obj_set_size(list1, lv_pct(45), lv_pct(80));
|
||||
lv_obj_align(list1, LV_ALIGN_LEFT_MID, 5, 0);
|
||||
lv_obj_set_style_bg_color(list1, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED);
|
||||
lv_group_add_obj(lv_group_get_default(), list1);
|
||||
|
||||
|
||||
char buf[32];
|
||||
uint32_t i;
|
||||
for(i = 0; i < 15; i++) {
|
||||
lv_snprintf(buf, sizeof(buf), "File %d", i + 1);
|
||||
lv_obj_t * item = lv_list_add_btn(list1, LV_SYMBOL_FILE, buf);
|
||||
lv_obj_set_style_bg_opa(item, 0, 0);
|
||||
lv_group_remove_obj(item); /*Not needed, we use the gridnav instead*/
|
||||
}
|
||||
|
||||
lv_obj_t * list2 = lv_list_create(lv_scr_act());
|
||||
lv_gridnav_add(list2, LV_GRIDNAV_CTRL_ROLLOVER);
|
||||
lv_obj_set_size(list2, lv_pct(45), lv_pct(80));
|
||||
lv_obj_align(list2, LV_ALIGN_RIGHT_MID, -5, 0);
|
||||
lv_obj_set_style_bg_color(list2, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED);
|
||||
lv_group_add_obj(lv_group_get_default(), list2);
|
||||
|
||||
for(i = 0; i < 15; i++) {
|
||||
lv_snprintf(buf, sizeof(buf), "Folder %d", i + 1);
|
||||
lv_obj_t * item = lv_list_add_btn(list2, LV_SYMBOL_DIRECTORY, buf);
|
||||
lv_obj_set_style_bg_opa(item, 0, 0);
|
||||
lv_group_remove_obj(item);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
101
libraries/lvgl/examples/others/gridnav/lv_example_gridnav_3.c
Normal file
101
libraries/lvgl/examples/others/gridnav/lv_example_gridnav_3.c
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_GRIDNAV && LV_USE_FLEX && LV_BUILD_EXAMPLES
|
||||
|
||||
static void cont_sub_event_cb(lv_event_t * e)
|
||||
{
|
||||
uint32_t k = lv_event_get_key(e);
|
||||
lv_obj_t * obj = lv_event_get_current_target(e);
|
||||
if(k == LV_KEY_ENTER) {
|
||||
lv_group_focus_obj(obj);
|
||||
}
|
||||
else if(k == LV_KEY_ESC) {
|
||||
lv_group_focus_next(lv_obj_get_group(obj));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Nested grid navigations
|
||||
*/
|
||||
void lv_example_gridnav_3(void)
|
||||
{
|
||||
/*It's assumed that the default group is set and
|
||||
*there is a keyboard indev*/
|
||||
|
||||
lv_obj_t * cont_main = lv_obj_create(lv_scr_act());
|
||||
lv_gridnav_add(cont_main, LV_GRIDNAV_CTRL_ROLLOVER | LV_GRIDNAV_CTRL_SCROLL_FIRST);
|
||||
|
||||
/*Only the container needs to be in a group*/
|
||||
lv_group_add_obj(lv_group_get_default(), cont_main);
|
||||
|
||||
/*Use flex here, but works with grid or manually placed objects as well*/
|
||||
lv_obj_set_flex_flow(cont_main, LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_style_bg_color(cont_main, lv_palette_lighten(LV_PALETTE_BLUE, 5), LV_STATE_FOCUSED);
|
||||
lv_obj_set_size(cont_main, lv_pct(80), LV_SIZE_CONTENT);
|
||||
|
||||
lv_obj_t * btn;
|
||||
lv_obj_t * label;
|
||||
|
||||
btn = lv_btn_create(cont_main);
|
||||
lv_group_remove_obj(btn);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Button 1");
|
||||
|
||||
btn = lv_btn_create(cont_main);
|
||||
lv_group_remove_obj(btn);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Button 2");
|
||||
|
||||
|
||||
/*Create an other container with long text to show how LV_GRIDNAV_CTRL_SCROLL_FIRST works*/
|
||||
lv_obj_t * cont_sub1 = lv_obj_create(cont_main);
|
||||
lv_obj_set_size(cont_sub1, lv_pct(100), 100);
|
||||
|
||||
label = lv_label_create(cont_sub1);
|
||||
lv_obj_set_style_bg_color(cont_sub1, lv_palette_lighten(LV_PALETTE_RED, 5), LV_STATE_FOCUSED);
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
lv_label_set_text(label,
|
||||
"I'm a very long text which is makes my container scrollable. "
|
||||
"As LV_GRIDNAV_FLAG_SCROLL_FIRST is enabled arrow will scroll me first "
|
||||
"and a new objects will be focused only when an edge is reached with the scrolling.\n\n"
|
||||
"This is only some placeholder text to be sure the parent will be scrollable. \n\n"
|
||||
"Hello world!\n"
|
||||
"Hello world!\n"
|
||||
"Hello world!\n"
|
||||
"Hello world!\n"
|
||||
"Hello world!\n"
|
||||
"Hello world!");
|
||||
|
||||
/*Create a third container that can be focused with ENTER and contains an other grid nav*/
|
||||
lv_obj_t * cont_sub2 = lv_obj_create(cont_main);
|
||||
lv_gridnav_add(cont_sub2, LV_GRIDNAV_CTRL_ROLLOVER);
|
||||
/*Only the container needs to be in a group*/
|
||||
lv_group_add_obj(lv_group_get_default(), cont_sub2);
|
||||
|
||||
lv_obj_add_event_cb(cont_sub2, cont_sub_event_cb, LV_EVENT_KEY, NULL);
|
||||
|
||||
/*Use flex here, but works with grid or manually placed objects as well*/
|
||||
lv_obj_set_flex_flow(cont_sub2, LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_style_bg_color(cont_sub2, lv_palette_lighten(LV_PALETTE_RED, 5), LV_STATE_FOCUSED);
|
||||
lv_obj_set_size(cont_sub2, lv_pct(100), LV_SIZE_CONTENT);
|
||||
|
||||
label = lv_label_create(cont_sub2);
|
||||
lv_label_set_text(label, "Use ENTER/ESC to focus/defocus this container");
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
|
||||
btn = lv_btn_create(cont_sub2);
|
||||
lv_group_remove_obj(btn);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Button 3");
|
||||
|
||||
btn = lv_btn_create(cont_sub2);
|
||||
lv_group_remove_obj(btn);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Button 4");
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_GRIDNAV && LV_USE_FLEX && LV_BUILD_EXAMPLES
|
||||
|
||||
|
||||
static void event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
lv_obj_t * list = lv_obj_get_parent(obj);
|
||||
LV_LOG_USER("Clicked: %s", lv_list_get_btn_text(list, obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple navigation on a list widget
|
||||
*/
|
||||
void lv_example_gridnav_4(void)
|
||||
{
|
||||
/*It's assumed that the default group is set and
|
||||
*there is a keyboard indev*/
|
||||
|
||||
lv_obj_t * list = lv_list_create(lv_scr_act());
|
||||
lv_gridnav_add(list, LV_GRIDNAV_CTRL_ROLLOVER);
|
||||
lv_obj_align(list, LV_ALIGN_LEFT_MID, 0, 10);
|
||||
lv_group_add_obj(lv_group_get_default(), list);
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < 20; i++) {
|
||||
char buf[32];
|
||||
|
||||
/*Add some separators too, they are not focusable by gridnav*/
|
||||
if((i % 5) == 0) {
|
||||
lv_snprintf(buf, sizeof(buf), "Section %d", i / 5 + 1);
|
||||
lv_list_add_text(list, buf);
|
||||
}
|
||||
|
||||
lv_snprintf(buf, sizeof(buf), "File %d", i + 1);
|
||||
lv_obj_t * item = lv_list_add_btn(list, LV_SYMBOL_FILE, buf);
|
||||
lv_obj_add_event_cb(item, event_handler, LV_EVENT_CLICKED, NULL);
|
||||
lv_group_remove_obj(item); /*The default group adds it automatically*/
|
||||
}
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, -10);
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Button");
|
||||
}
|
||||
|
||||
#endif
|
||||
12
libraries/lvgl/examples/others/ime/index.rst
Normal file
12
libraries/lvgl/examples/others/ime/index.rst
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
Pinyin IME 26 key input
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/ime/lv_example_ime_pinyin_1
|
||||
:language: c
|
||||
|
||||
Pinyin IME 9 key input
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/ime/lv_example_ime_pinyin_2
|
||||
:language: c
|
||||
39
libraries/lvgl/examples/others/ime/lv_example_ime_pinyin.h
Normal file
39
libraries/lvgl/examples/others/ime/lv_example_ime_pinyin.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @file lv_example_ime_pinyin.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EX_IME_PINYIN_H
|
||||
#define LV_EX_IME_PINYIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_ime_pinyin_1(void);
|
||||
void lv_example_ime_pinyin_2(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EX_IME_PINYIN_H*/
|
||||
56
libraries/lvgl/examples/others/ime/lv_example_ime_pinyin_1.c
Normal file
56
libraries/lvgl/examples/others/ime/lv_example_ime_pinyin_1.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_LABEL && LV_USE_TEXTAREA && LV_FONT_SIMSUN_16_CJK && LV_USE_IME_PINYIN && LV_BUILD_EXAMPLES
|
||||
|
||||
static void ta_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
lv_obj_t * kb = lv_event_get_user_data(e);
|
||||
|
||||
if(code == LV_EVENT_FOCUSED) {
|
||||
if(lv_indev_get_type(lv_indev_get_act()) != LV_INDEV_TYPE_KEYPAD) {
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_CANCEL) {
|
||||
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_state(ta, LV_STATE_FOCUSED);
|
||||
lv_indev_reset(NULL, ta); /*To forget the last clicked object to make it focusable again*/
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_ime_pinyin_1(void)
|
||||
{
|
||||
lv_obj_t * pinyin_ime = lv_ime_pinyin_create(lv_scr_act());
|
||||
lv_obj_set_style_text_font(pinyin_ime, &lv_font_simsun_16_cjk, 0);
|
||||
//lv_ime_pinyin_set_dict(pinyin_ime, your_dict); // Use a custom dictionary. If it is not set, the built-in dictionary will be used.
|
||||
|
||||
/* ta1 */
|
||||
lv_obj_t * ta1 = lv_textarea_create(lv_scr_act());
|
||||
lv_textarea_set_one_line(ta1, true);
|
||||
lv_obj_set_style_text_font(ta1, &lv_font_simsun_16_cjk, 0);
|
||||
lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
|
||||
/*Create a keyboard and add it to ime_pinyin*/
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
|
||||
lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
|
||||
lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
|
||||
|
||||
/*Get the cand_panel, and adjust its size and position*/
|
||||
lv_obj_t * cand_panel = lv_ime_pinyin_get_cand_panel(pinyin_ime);
|
||||
lv_obj_set_size(cand_panel, LV_PCT(100), LV_PCT(10));
|
||||
lv_obj_align_to(cand_panel, kb, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
|
||||
/*Try using ime_pinyin to output the Chinese below in the ta1 above*/
|
||||
lv_obj_t * cz_label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(cz_label,
|
||||
"嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
|
||||
lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
|
||||
lv_obj_set_width(cz_label, 310);
|
||||
lv_obj_align_to(cz_label, ta1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
58
libraries/lvgl/examples/others/ime/lv_example_ime_pinyin_2.c
Normal file
58
libraries/lvgl/examples/others/ime/lv_example_ime_pinyin_2.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_LABEL && LV_USE_TEXTAREA && LV_FONT_SIMSUN_16_CJK && LV_USE_IME_PINYIN && LV_IME_PINYIN_USE_K9_MODE && LV_BUILD_EXAMPLES
|
||||
|
||||
static void ta_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
lv_obj_t * kb = lv_event_get_user_data(e);
|
||||
|
||||
if(code == LV_EVENT_FOCUSED) {
|
||||
if(lv_indev_get_type(lv_indev_get_act()) != LV_INDEV_TYPE_KEYPAD) {
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
else if(code == LV_EVENT_READY) {
|
||||
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_state(ta, LV_STATE_FOCUSED);
|
||||
lv_indev_reset(NULL, ta); /*To forget the last clicked object to make it focusable again*/
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_ime_pinyin_2(void)
|
||||
{
|
||||
lv_obj_t * pinyin_ime = lv_ime_pinyin_create(lv_scr_act());
|
||||
lv_obj_set_style_text_font(pinyin_ime, &lv_font_simsun_16_cjk, 0);
|
||||
//lv_ime_pinyin_set_dict(pinyin_ime, your_dict); // Use a custom dictionary. If it is not set, the built-in dictionary will be used.
|
||||
|
||||
/* ta1 */
|
||||
lv_obj_t * ta1 = lv_textarea_create(lv_scr_act());
|
||||
lv_textarea_set_one_line(ta1, true);
|
||||
lv_obj_set_style_text_font(ta1, &lv_font_simsun_16_cjk, 0);
|
||||
lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
|
||||
/*Create a keyboard and add it to ime_pinyin*/
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
|
||||
lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
|
||||
lv_ime_pinyin_set_mode(pinyin_ime,
|
||||
LV_IME_PINYIN_MODE_K9); // Set to 9-key input mode. Default: 26-key input(k26) mode.
|
||||
lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);
|
||||
|
||||
/*Get the cand_panel, and adjust its size and position*/
|
||||
lv_obj_t * cand_panel = lv_ime_pinyin_get_cand_panel(pinyin_ime);
|
||||
lv_obj_set_size(cand_panel, LV_PCT(100), LV_PCT(10));
|
||||
lv_obj_align_to(cand_panel, kb, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
|
||||
/*Try using ime_pinyin to output the Chinese below in the ta1 above*/
|
||||
lv_obj_t * cz_label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(cz_label,
|
||||
"嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
|
||||
lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
|
||||
lv_obj_set_width(cz_label, 310);
|
||||
lv_obj_align_to(cz_label, ta1, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
6
libraries/lvgl/examples/others/imgfont/index.rst
Normal file
6
libraries/lvgl/examples/others/imgfont/index.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
Use emojis in a text.
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/imgfont/lv_example_imgfont_1
|
||||
:language: c
|
||||
|
||||
38
libraries/lvgl/examples/others/imgfont/lv_example_imgfont.h
Normal file
38
libraries/lvgl/examples/others/imgfont/lv_example_imgfont.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file lv_example_imgfont.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_IMGFONT_H
|
||||
#define LV_EXAMPLE_IMGFONT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_imgfont_1(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_IMGFONT_H*/
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "../../lv_examples.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if LV_BUILD_EXAMPLES
|
||||
#if LV_USE_IMGFONT
|
||||
|
||||
LV_IMG_DECLARE(emoji_F617)
|
||||
static bool get_imgfont_path(const lv_font_t * font, void * img_src,
|
||||
uint16_t len, uint32_t unicode, uint32_t unicode_next)
|
||||
{
|
||||
LV_UNUSED(font);
|
||||
LV_UNUSED(unicode_next);
|
||||
LV_ASSERT_NULL(img_src);
|
||||
|
||||
if(unicode == 0xF617) {
|
||||
memcpy(img_src, &emoji_F617, sizeof(lv_img_dsc_t));
|
||||
}
|
||||
else {
|
||||
char * path = (char *)img_src;
|
||||
snprintf(path, len, "%s/%04X.%s", "A:lvgl/examples/assets/emoji", unicode, "png");
|
||||
path[len - 1] = '\0';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* draw img in label or span obj
|
||||
*/
|
||||
void lv_example_imgfont_1(void)
|
||||
{
|
||||
lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path);
|
||||
if(imgfont == NULL) {
|
||||
LV_LOG_ERROR("imgfont init error");
|
||||
}
|
||||
|
||||
imgfont->fallback = LV_FONT_DEFAULT;
|
||||
|
||||
lv_obj_t * label1 = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label1, "12\uF600\uF617AB");
|
||||
lv_obj_set_style_text_font(label1, imgfont, LV_PART_MAIN);
|
||||
lv_obj_center(label1);
|
||||
}
|
||||
#else
|
||||
|
||||
void lv_example_imgfont_1(void)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, "imgfont is not installed");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
44
libraries/lvgl/examples/others/lv_example_others.h
Normal file
44
libraries/lvgl/examples/others/lv_example_others.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file lv_example_others.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_OTHERS_H
|
||||
#define LV_EXAMPLE_OTHERS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "snapshot/lv_example_snapshot.h"
|
||||
#include "monkey/lv_example_monkey.h"
|
||||
#include "gridnav/lv_example_gridnav.h"
|
||||
#include "fragment/lv_example_fragment.h"
|
||||
#include "imgfont/lv_example_imgfont.h"
|
||||
#include "msg/lv_example_msg.h"
|
||||
#include "ime/lv_example_ime_pinyin.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_OTHERS_H*/
|
||||
18
libraries/lvgl/examples/others/monkey/index.rst
Normal file
18
libraries/lvgl/examples/others/monkey/index.rst
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
Touchpad monkey example
|
||||
"""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/monkey/lv_example_monkey_1
|
||||
:language: c
|
||||
|
||||
Encoder monkey example
|
||||
"""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/monkey/lv_example_monkey_2
|
||||
:language: c
|
||||
|
||||
Button monkey example
|
||||
"""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/monkey/lv_example_monkey_3
|
||||
:language: c
|
||||
40
libraries/lvgl/examples/others/monkey/lv_example_monkey.h
Normal file
40
libraries/lvgl/examples/others/monkey/lv_example_monkey.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file lv_example_monkey.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_MONKEY_H
|
||||
#define LV_EXAMPLE_MONKEY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_monkey_1(void);
|
||||
void lv_example_monkey_2(void);
|
||||
void lv_example_monkey_3(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_MONKEY_H*/
|
||||
18
libraries/lvgl/examples/others/monkey/lv_example_monkey_1.c
Normal file
18
libraries/lvgl/examples/others/monkey/lv_example_monkey_1.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_MONKEY && LV_BUILD_EXAMPLES
|
||||
|
||||
void lv_example_monkey_1(void)
|
||||
{
|
||||
/*Create pointer monkey test*/
|
||||
lv_monkey_config_t config;
|
||||
lv_monkey_config_init(&config);
|
||||
config.type = LV_INDEV_TYPE_POINTER;
|
||||
config.period_range.min = 10;
|
||||
config.period_range.max = 100;
|
||||
lv_monkey_t * monkey = lv_monkey_create(&config);
|
||||
|
||||
/*Start monkey test*/
|
||||
lv_monkey_set_enable(monkey, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
25
libraries/lvgl/examples/others/monkey/lv_example_monkey_2.c
Normal file
25
libraries/lvgl/examples/others/monkey/lv_example_monkey_2.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_MONKEY && LV_BUILD_EXAMPLES
|
||||
|
||||
void lv_example_monkey_2(void)
|
||||
{
|
||||
/*Create encoder monkey test*/
|
||||
lv_monkey_config_t config;
|
||||
lv_monkey_config_init(&config);
|
||||
config.type = LV_INDEV_TYPE_ENCODER;
|
||||
config.period_range.min = 50;
|
||||
config.period_range.max = 500;
|
||||
config.input_range.min = -5;
|
||||
config.input_range.max = 5;
|
||||
lv_monkey_t * monkey = lv_monkey_create(&config);
|
||||
|
||||
/*Set the default group*/
|
||||
lv_group_t * group = lv_group_create();
|
||||
lv_indev_set_group(lv_monkey_get_indev(monkey), group);
|
||||
lv_group_set_default(group);
|
||||
|
||||
/*Start monkey test*/
|
||||
lv_monkey_set_enable(monkey, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
33
libraries/lvgl/examples/others/monkey/lv_example_monkey_3.c
Normal file
33
libraries/lvgl/examples/others/monkey/lv_example_monkey_3.c
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_MONKEY && LV_BUILD_EXAMPLES
|
||||
|
||||
void lv_example_monkey_3(void)
|
||||
{
|
||||
static lv_point_t btn_points[3];
|
||||
lv_coord_t hor_res = LV_HOR_RES;
|
||||
|
||||
/*Create button monkey test*/
|
||||
lv_monkey_config_t config;
|
||||
lv_monkey_config_init(&config);
|
||||
config.type = LV_INDEV_TYPE_BUTTON;
|
||||
config.period_range.min = 50;
|
||||
config.period_range.max = 500;
|
||||
config.input_range.min = 0;
|
||||
config.input_range.max = sizeof(btn_points) / sizeof(lv_point_t) - 1;
|
||||
lv_monkey_t * monkey = lv_monkey_create(&config);
|
||||
|
||||
/*Set the coordinates bound to the button*/
|
||||
btn_points[0].x = hor_res / 4;
|
||||
btn_points[0].y = 10;
|
||||
btn_points[1].x = hor_res / 2;
|
||||
btn_points[1].y = 10;
|
||||
btn_points[2].x = hor_res * 3 / 4;
|
||||
btn_points[2].y = 10;
|
||||
|
||||
lv_indev_set_button_points(lv_monkey_get_indev(monkey), btn_points);
|
||||
|
||||
/*Start monkey test*/
|
||||
lv_monkey_set_enable(monkey, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
20
libraries/lvgl/examples/others/msg/index.rst
Normal file
20
libraries/lvgl/examples/others/msg/index.rst
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Slider to label messaging
|
||||
"""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/msg/lv_example_msg_1
|
||||
:language: c
|
||||
|
||||
Handling login and its states
|
||||
"""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/msg/lv_example_msg_2
|
||||
:language: c
|
||||
|
||||
Setting the same value from many sources
|
||||
""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/msg/lv_example_msg_3
|
||||
:language: c
|
||||
|
||||
|
||||
40
libraries/lvgl/examples/others/msg/lv_example_msg.h
Normal file
40
libraries/lvgl/examples/others/msg/lv_example_msg.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file lv_example_msg.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_MSG_H
|
||||
#define LV_EXAMPLE_MSG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_msg_1(void);
|
||||
void lv_example_msg_2(void);
|
||||
void lv_example_msg_3(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_MSG_H*/
|
||||
49
libraries/lvgl/examples/others/msg/lv_example_msg_1.c
Normal file
49
libraries/lvgl/examples/others/msg/lv_example_msg_1.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_MSG && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES
|
||||
|
||||
/*Define a message ID*/
|
||||
#define MSG_NEW_TEMPERATURE 1
|
||||
|
||||
static void slider_event_cb(lv_event_t * e);
|
||||
static void label_event_cb(lv_event_t * e);
|
||||
|
||||
/**
|
||||
* A slider sends a message on value change and a label display's that value
|
||||
*/
|
||||
void lv_example_msg_1(void)
|
||||
{
|
||||
/*Create a slider in the center of the display*/
|
||||
lv_obj_t * slider = lv_slider_create(lv_scr_act());
|
||||
lv_obj_center(slider);
|
||||
lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
/*Create a label below the slider*/
|
||||
lv_obj_t * label = lv_label_create(lv_scr_act());
|
||||
lv_obj_add_event_cb(label, label_event_cb, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_label_set_text(label, "0%");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 30);
|
||||
|
||||
/*Subscribe the label to a message. Also use the user_data to set a format string here.*/
|
||||
lv_msg_subsribe_obj(MSG_NEW_TEMPERATURE, label, "%d °C");
|
||||
}
|
||||
|
||||
static void slider_event_cb(lv_event_t * e)
|
||||
{
|
||||
/*Notify all subscribers (only the label now) that the slider value has been changed*/
|
||||
lv_obj_t * slider = lv_event_get_target(e);
|
||||
int32_t v = lv_slider_get_value(slider);
|
||||
lv_msg_send(MSG_NEW_TEMPERATURE, &v);
|
||||
}
|
||||
|
||||
static void label_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
lv_msg_t * m = lv_event_get_msg(e);
|
||||
|
||||
const char * fmt = lv_msg_get_user_data(m);
|
||||
const int32_t * v = lv_msg_get_payload(m);
|
||||
|
||||
lv_label_set_text_fmt(label, fmt, *v);
|
||||
}
|
||||
|
||||
#endif
|
||||
171
libraries/lvgl/examples/others/msg/lv_example_msg_2.c
Normal file
171
libraries/lvgl/examples/others/msg/lv_example_msg_2.c
Normal file
@@ -0,0 +1,171 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_MSG && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES
|
||||
|
||||
/*Define a message ID*/
|
||||
#define MSG_LOGIN_ATTEMPT 1
|
||||
#define MSG_LOG_OUT 2
|
||||
#define MSG_LOGIN_ERROR 3
|
||||
#define MSG_LOGIN_OK 4
|
||||
|
||||
static void auth_manager(void * s, lv_msg_t * m);
|
||||
static void textarea_event_cb(lv_event_t * e);
|
||||
static void log_out_event_cb(lv_event_t * e);
|
||||
static void start_engine_msg_event_cb(lv_event_t * e);
|
||||
static void info_label_msg_event_cb(lv_event_t * e);
|
||||
|
||||
/**
|
||||
* Simple PIN login screen.
|
||||
* No global variables are used, all state changes are communicated via messages.
|
||||
*/
|
||||
void lv_example_msg_2(void)
|
||||
{
|
||||
lv_msg_subsribe(MSG_LOGIN_ATTEMPT, auth_manager, "hello");
|
||||
|
||||
/*Create a slider in the center of the display*/
|
||||
lv_obj_t * ta = lv_textarea_create(lv_scr_act());
|
||||
lv_obj_set_pos(ta, 10, 10);
|
||||
lv_obj_set_width(ta, 200);
|
||||
lv_textarea_set_one_line(ta, true);
|
||||
lv_textarea_set_password_mode(ta, true);
|
||||
lv_textarea_set_placeholder_text(ta, "The password is: hello");
|
||||
lv_obj_add_event_cb(ta, textarea_event_cb, LV_EVENT_ALL, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOGIN_ERROR, ta, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOGIN_OK, ta, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOG_OUT, ta, NULL);
|
||||
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_scr_act());
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
|
||||
lv_obj_t * btn;
|
||||
lv_obj_t * label;
|
||||
|
||||
/*Create a log out button which will be active only when logged in*/
|
||||
btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_pos(btn, 240, 10);
|
||||
lv_obj_add_event_cb(btn, log_out_event_cb, LV_EVENT_ALL, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOGIN_OK, btn, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOG_OUT, btn, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "LOG OUT");
|
||||
|
||||
/*Create a label to show info*/
|
||||
label = lv_label_create(lv_scr_act());
|
||||
lv_label_set_text(label, "");
|
||||
lv_obj_add_event_cb(label, info_label_msg_event_cb, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_obj_set_pos(label, 10, 60);
|
||||
lv_msg_subsribe_obj(MSG_LOGIN_ERROR, label, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOGIN_OK, label, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOG_OUT, label, NULL);
|
||||
|
||||
/*Create button which will be active only when logged in*/
|
||||
btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_set_pos(btn, 10, 80);
|
||||
lv_obj_add_event_cb(btn, start_engine_msg_event_cb, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE);
|
||||
lv_msg_subsribe_obj(MSG_LOGIN_OK, btn, NULL);
|
||||
lv_msg_subsribe_obj(MSG_LOG_OUT, btn, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "START ENGINE");
|
||||
|
||||
lv_msg_send(MSG_LOG_OUT, NULL);
|
||||
}
|
||||
|
||||
static void auth_manager(void * s, lv_msg_t * m)
|
||||
{
|
||||
LV_UNUSED(s);
|
||||
const char * pin_act = lv_msg_get_payload(m);
|
||||
const char * pin_expexted = lv_msg_get_user_data(m);
|
||||
if(strcmp(pin_act, pin_expexted) == 0) {
|
||||
lv_msg_send(MSG_LOGIN_OK, NULL);
|
||||
}
|
||||
else {
|
||||
lv_msg_send(MSG_LOGIN_ERROR, "Incorrect PIN");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void textarea_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if(code == LV_EVENT_READY) {
|
||||
lv_msg_send(MSG_LOGIN_ATTEMPT, lv_textarea_get_text(ta));
|
||||
}
|
||||
else if(code == LV_EVENT_MSG_RECEIVED) {
|
||||
lv_msg_t * m = lv_event_get_msg(e);
|
||||
switch(lv_msg_get_id(m)) {
|
||||
case MSG_LOGIN_ERROR:
|
||||
/*If there was an error, clean the text area*/
|
||||
if(strlen(lv_msg_get_payload(m))) lv_textarea_set_text(ta, "");
|
||||
break;
|
||||
case MSG_LOGIN_OK:
|
||||
lv_obj_add_state(ta, LV_STATE_DISABLED);
|
||||
lv_obj_clear_state(ta, LV_STATE_FOCUSED | LV_STATE_FOCUS_KEY);
|
||||
break;
|
||||
case MSG_LOG_OUT:
|
||||
lv_textarea_set_text(ta, "");
|
||||
lv_obj_clear_state(ta, LV_STATE_DISABLED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void log_out_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if(code == LV_EVENT_CLICKED) {
|
||||
lv_msg_send(MSG_LOG_OUT, NULL);
|
||||
}
|
||||
else if(code == LV_EVENT_MSG_RECEIVED) {
|
||||
lv_msg_t * m = lv_event_get_msg(e);
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
switch(lv_msg_get_id(m)) {
|
||||
case MSG_LOGIN_OK:
|
||||
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
||||
break;
|
||||
case MSG_LOG_OUT:
|
||||
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void start_engine_msg_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_msg_t * m = lv_event_get_msg(e);
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
switch(lv_msg_get_id(m)) {
|
||||
case MSG_LOGIN_OK:
|
||||
lv_obj_clear_state(btn, LV_STATE_DISABLED);
|
||||
break;
|
||||
case MSG_LOG_OUT:
|
||||
lv_obj_add_state(btn, LV_STATE_DISABLED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void info_label_msg_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
lv_msg_t * m = lv_event_get_msg(e);
|
||||
switch(lv_msg_get_id(m)) {
|
||||
case MSG_LOGIN_ERROR:
|
||||
lv_label_set_text(label, lv_msg_get_payload(m));
|
||||
lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_RED), 0);
|
||||
break;
|
||||
case MSG_LOGIN_OK:
|
||||
lv_label_set_text(label, "Login successful");
|
||||
lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_GREEN), 0);
|
||||
break;
|
||||
case MSG_LOG_OUT:
|
||||
lv_label_set_text(label, "Logged out");
|
||||
lv_obj_set_style_text_color(label, lv_palette_main(LV_PALETTE_GREY), 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
154
libraries/lvgl/examples/others/msg/lv_example_msg_3.c
Normal file
154
libraries/lvgl/examples/others/msg/lv_example_msg_3.c
Normal file
@@ -0,0 +1,154 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_MSG && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES
|
||||
|
||||
/*Define a message ID*/
|
||||
#define MSG_INC 1
|
||||
#define MSG_DEC 2
|
||||
#define MSG_SET 3
|
||||
#define MSG_UPDATE 4
|
||||
#define MSG_UPDATE_REQUEST 5
|
||||
|
||||
static void value_handler(void * s, lv_msg_t * m);
|
||||
static void value_handler(void * s, lv_msg_t * m);
|
||||
static void btn_event_cb(lv_event_t * e);
|
||||
static void label_event_cb(lv_event_t * e);
|
||||
static void slider_event_cb(lv_event_t * e);
|
||||
|
||||
/**
|
||||
* Show how an increment button, a decrement button, as slider can set a value
|
||||
* and a label display it.
|
||||
* The current value (i.e. the system's state) is stored only in one static variable in a function
|
||||
* and no global variables are required.
|
||||
*/
|
||||
void lv_example_msg_3(void)
|
||||
{
|
||||
|
||||
lv_msg_subsribe(MSG_INC, value_handler, NULL);
|
||||
lv_msg_subsribe(MSG_DEC, value_handler, NULL);
|
||||
lv_msg_subsribe(MSG_SET, value_handler, NULL);
|
||||
lv_msg_subsribe(MSG_UPDATE, value_handler, NULL);
|
||||
lv_msg_subsribe(MSG_UPDATE_REQUEST, value_handler, NULL);
|
||||
|
||||
lv_obj_t * panel = lv_obj_create(lv_scr_act());
|
||||
lv_obj_set_size(panel, 250, LV_SIZE_CONTENT);
|
||||
lv_obj_center(panel);
|
||||
lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
|
||||
|
||||
lv_obj_t * btn;
|
||||
lv_obj_t * label;
|
||||
|
||||
/*Up button*/
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_set_flex_grow(btn, 1);
|
||||
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_LEFT);
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Current value*/
|
||||
label = lv_label_create(panel);
|
||||
lv_obj_set_flex_grow(label, 2);
|
||||
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_label_set_text(label, "?");
|
||||
lv_msg_subsribe_obj(MSG_UPDATE, label, NULL);
|
||||
lv_obj_add_event_cb(label, label_event_cb, LV_EVENT_MSG_RECEIVED, NULL);
|
||||
|
||||
/*Down button*/
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_set_flex_grow(btn, 1);
|
||||
lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_RIGHT);
|
||||
lv_obj_center(label);
|
||||
|
||||
/*Slider*/
|
||||
lv_obj_t * slider = lv_slider_create(panel);
|
||||
lv_obj_set_flex_grow(slider, 1);
|
||||
lv_obj_add_flag(slider, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
|
||||
lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_ALL, NULL);
|
||||
lv_msg_subsribe_obj(MSG_UPDATE, slider, NULL);
|
||||
|
||||
|
||||
/* As there are new UI elements that don't know the system's state
|
||||
* send an UPDATE REQUEST message which will trigger an UPDATE message with the current value*/
|
||||
lv_msg_send(MSG_UPDATE_REQUEST, NULL);
|
||||
}
|
||||
|
||||
|
||||
static void value_handler(void * s, lv_msg_t * m)
|
||||
{
|
||||
LV_UNUSED(s);
|
||||
|
||||
static int32_t value = 10;
|
||||
int32_t old_value = value;
|
||||
switch(lv_msg_get_id(m)) {
|
||||
case MSG_INC:
|
||||
if(value < 100) value++;
|
||||
break;
|
||||
case MSG_DEC:
|
||||
if(value > 0) value--;
|
||||
break;
|
||||
case MSG_SET: {
|
||||
const int32_t * new_value = lv_msg_get_payload(m);
|
||||
value = *new_value;
|
||||
}
|
||||
break;
|
||||
case MSG_UPDATE_REQUEST:
|
||||
lv_msg_send(MSG_UPDATE, &value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(value != old_value) {
|
||||
lv_msg_send(MSG_UPDATE, &value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void btn_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if(code == LV_EVENT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) {
|
||||
if(lv_obj_get_index(btn) == 0) { /*First object is the dec. button*/
|
||||
lv_msg_send(MSG_DEC, NULL);
|
||||
}
|
||||
else {
|
||||
lv_msg_send(MSG_INC, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void label_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * label = lv_event_get_target(e);
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if(code == LV_EVENT_MSG_RECEIVED) {
|
||||
lv_msg_t * m = lv_event_get_msg(e);
|
||||
if(lv_msg_get_id(m) == MSG_UPDATE) {
|
||||
const int32_t * v = lv_msg_get_payload(m);
|
||||
lv_label_set_text_fmt(label, "%d %%", *v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void slider_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * slider = lv_event_get_target(e);
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
int32_t v = lv_slider_get_value(slider);
|
||||
lv_msg_send(MSG_SET, &v);
|
||||
}
|
||||
else if(code == LV_EVENT_MSG_RECEIVED) {
|
||||
lv_msg_t * m = lv_event_get_msg(e);
|
||||
if(lv_msg_get_id(m) == MSG_UPDATE) {
|
||||
const int32_t * v = lv_msg_get_payload(m);
|
||||
lv_slider_set_value(slider, *v, LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
8
libraries/lvgl/examples/others/snapshot/index.rst
Normal file
8
libraries/lvgl/examples/others/snapshot/index.rst
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
Simple snapshot example
|
||||
"""""""""""""""""""
|
||||
|
||||
.. lv_example:: others/snapshot/lv_example_snapshot_1
|
||||
:language: c
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file lv_example_snapshot.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EX_SNAPSHOT_H
|
||||
#define LV_EX_SNAPSHOT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_snapshot_1(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EX_GET_STARTED_H*/
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_SNAPSHOT && LV_BUILD_EXAMPLES
|
||||
|
||||
static void event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * snapshot_obj = lv_event_get_user_data(e);
|
||||
lv_obj_t * img = lv_event_get_target(e);
|
||||
|
||||
if(snapshot_obj) {
|
||||
lv_img_dsc_t * snapshot = (void *)lv_img_get_src(snapshot_obj);
|
||||
if(snapshot) {
|
||||
lv_snapshot_free(snapshot);
|
||||
}
|
||||
|
||||
/*Update the snapshot, we know parent of object is the container.*/
|
||||
snapshot = lv_snapshot_take(img->parent, LV_IMG_CF_TRUE_COLOR_ALPHA);
|
||||
if(snapshot == NULL)
|
||||
return;
|
||||
lv_img_set_src(snapshot_obj, snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_snapshot_1(void)
|
||||
{
|
||||
LV_IMG_DECLARE(img_star);
|
||||
lv_obj_t * root = lv_scr_act();
|
||||
lv_obj_set_style_bg_color(root, lv_palette_main(LV_PALETTE_LIGHT_BLUE), 0);
|
||||
|
||||
/*Create an image object to show snapshot*/
|
||||
lv_obj_t * snapshot_obj = lv_img_create(root);
|
||||
lv_obj_set_style_bg_color(snapshot_obj, lv_palette_main(LV_PALETTE_PURPLE), 0);
|
||||
lv_obj_set_style_bg_opa(snapshot_obj, LV_OPA_100, 0);
|
||||
lv_img_set_zoom(snapshot_obj, 128);
|
||||
lv_img_set_angle(snapshot_obj, 300);
|
||||
|
||||
/*Create the container and its children*/
|
||||
lv_obj_t * container = lv_obj_create(root);
|
||||
|
||||
lv_obj_center(container);
|
||||
lv_obj_set_size(container, 180, 180);
|
||||
lv_obj_set_flex_flow(container, LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_flex_align(container, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_style_radius(container, 50, 0);
|
||||
lv_obj_t * img;
|
||||
int i;
|
||||
for(i = 0; i < 4; i++) {
|
||||
img = lv_img_create(container);
|
||||
lv_img_set_src(img, &img_star);
|
||||
lv_obj_set_style_bg_color(img, lv_color_black(), 0);
|
||||
lv_obj_set_style_bg_opa(img, LV_OPA_COVER, 0);
|
||||
lv_obj_set_style_transform_zoom(img, 400, LV_STATE_PRESSED);
|
||||
lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_add_event_cb(img, event_cb, LV_EVENT_PRESSED, snapshot_obj);
|
||||
lv_obj_add_event_cb(img, event_cb, LV_EVENT_RELEASED, snapshot_obj);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
import gc
|
||||
import lvgl as lv
|
||||
from imagetools import get_png_info, open_png
|
||||
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Measure memory usage
|
||||
gc.enable()
|
||||
gc.collect()
|
||||
mem_free = gc.mem_free()
|
||||
|
||||
label = lv.label(lv.scr_act())
|
||||
label.align(lv.ALIGN.BOTTOM_MID, 0, -10)
|
||||
label.set_text(" memory free:" + str(mem_free/1024) + " kB")
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_star.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find star.png")
|
||||
sys.exit()
|
||||
|
||||
img_star = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
def event_cb(e, snapshot_obj):
|
||||
img = e.get_target()
|
||||
|
||||
if snapshot_obj:
|
||||
# no need to free the old source for snapshot_obj, gc will free it for us.
|
||||
|
||||
# take a new snapshot, overwrite the old one
|
||||
dsc = lv.snapshot_take(img.get_parent(), lv.img.CF.TRUE_COLOR_ALPHA)
|
||||
snapshot_obj.set_src(dsc)
|
||||
|
||||
gc.collect()
|
||||
mem_used = mem_free - gc.mem_free()
|
||||
label.set_text("memory used:" + str(mem_used/1024) + " kB")
|
||||
|
||||
root = lv.scr_act()
|
||||
root.set_style_bg_color(lv.palette_main(lv.PALETTE.LIGHT_BLUE), 0)
|
||||
|
||||
# Create an image object to show snapshot
|
||||
snapshot_obj = lv.img(root)
|
||||
snapshot_obj.set_style_bg_color(lv.palette_main(lv.PALETTE.PURPLE), 0)
|
||||
snapshot_obj.set_style_bg_opa(lv.OPA.COVER, 0)
|
||||
snapshot_obj.set_zoom(128)
|
||||
|
||||
# Create the container and its children
|
||||
container = lv.obj(root)
|
||||
container.align(lv.ALIGN.CENTER, 0, 0)
|
||||
container.set_size(180, 180)
|
||||
container.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
|
||||
container.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
||||
container.set_style_radius(50, 0)
|
||||
|
||||
for i in range(4):
|
||||
img = lv.img(container)
|
||||
img.set_src(img_star)
|
||||
img.set_style_bg_color(lv.palette_main(lv.PALETTE.GREY), 0)
|
||||
img.set_style_bg_opa(lv.OPA.COVER, 0)
|
||||
img.set_style_transform_zoom(400, lv.STATE.PRESSED)
|
||||
img.add_flag(img.FLAG.CLICKABLE)
|
||||
img.add_event_cb(lambda e: event_cb(e, snapshot_obj), lv.EVENT.PRESSED, None)
|
||||
img.add_event_cb(lambda e: event_cb(e, snapshot_obj), lv.EVENT.RELEASED, None)
|
||||
Reference in New Issue
Block a user