Update LVGL to v9.1.0
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
|
||||
Simple File Explorer
|
||||
--------------------
|
||||
|
||||
.. lv_example:: others/file_explorer/lv_example_file_explorer_1
|
||||
:language: c
|
||||
|
||||
Control File Explorer
|
||||
---------------------
|
||||
|
||||
.. lv_example:: others/file_explorer/lv_example_file_explorer_2
|
||||
:language: c
|
||||
|
||||
Custom sort
|
||||
-----------
|
||||
|
||||
.. lv_example:: others/file_explorer/lv_example_file_explorer_3
|
||||
:language: c
|
||||
+7
-7
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
* @file lv_example_msg.h
|
||||
* @file lv_example_file_explorer.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_MSG_H
|
||||
#define LV_EXAMPLE_MSG_H
|
||||
#ifndef LV_EX_FILE_EXPLORER_H
|
||||
#define LV_EX_FILE_EXPLORER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -25,9 +25,9 @@ extern "C" {
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_msg_1(void);
|
||||
void lv_example_msg_2(void);
|
||||
void lv_example_msg_3(void);
|
||||
void lv_example_file_explorer_1(void);
|
||||
void lv_example_file_explorer_2(void);
|
||||
void lv_example_file_explorer_3(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -37,4 +37,4 @@ void lv_example_msg_3(void);
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_MSG_H*/
|
||||
#endif /*LV_EX_FILE_EXPLORER_H*/
|
||||
@@ -0,0 +1,84 @@
|
||||
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_TABLE && LV_USE_FILE_EXPLORER && (LV_USE_FS_STDIO || LV_USE_FS_POSIX || LV_USE_FS_WIN32 || LV_USE_FS_FATFS) && LV_BUILD_EXAMPLES
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void file_explorer_event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
const char * cur_path = lv_file_explorer_get_current_path(obj);
|
||||
const char * sel_fn = lv_file_explorer_get_selected_file_name(obj);
|
||||
uint16_t path_len = strlen(cur_path);
|
||||
uint16_t fn_len = strlen(sel_fn);
|
||||
|
||||
if((path_len + fn_len) <= LV_FILE_EXPLORER_PATH_MAX_LEN) {
|
||||
char file_info[LV_FILE_EXPLORER_PATH_MAX_LEN];
|
||||
|
||||
strcpy(file_info, cur_path);
|
||||
strcat(file_info, sel_fn);
|
||||
|
||||
LV_LOG_USER("%s", file_info);
|
||||
}
|
||||
else LV_LOG_USER("%s%s", cur_path, sel_fn);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_file_explorer_1(void)
|
||||
{
|
||||
lv_obj_t * file_explorer = lv_file_explorer_create(lv_screen_active());
|
||||
lv_file_explorer_set_sort(file_explorer, LV_EXPLORER_SORT_KIND);
|
||||
|
||||
#if LV_USE_FS_WIN32
|
||||
lv_file_explorer_open_dir(file_explorer, "D:");
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, "C:/Users/Public/Desktop");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, "C:/Users/Public/Videos");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, "C:/Users/Public/Pictures");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, "C:/Users/Public/Music");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, "C:/Users/Public/Documents");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "D:");
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* linux */
|
||||
lv_file_explorer_open_dir(file_explorer, "A:/");
|
||||
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
char * envvar = "HOME";
|
||||
char home_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(home_dir, "A:");
|
||||
/* get the user's home directory from the HOME environment variable*/
|
||||
strcat(home_dir, getenv(envvar));
|
||||
LV_LOG_USER("home_dir: %s\n", home_dir);
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, home_dir);
|
||||
char video_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(video_dir, home_dir);
|
||||
strcat(video_dir, "/Videos");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, video_dir);
|
||||
char picture_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(picture_dir, home_dir);
|
||||
strcat(picture_dir, "/Pictures");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, picture_dir);
|
||||
char music_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(music_dir, home_dir);
|
||||
strcat(music_dir, "/Music");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, music_dir);
|
||||
char document_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(document_dir, home_dir);
|
||||
strcat(document_dir, "/Documents");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, document_dir);
|
||||
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "A:/");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,142 @@
|
||||
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_TABLE && LV_USE_DROPDOWN && LV_USE_FILE_EXPLORER && (LV_USE_FS_STDIO || LV_USE_FS_POSIX || LV_USE_FS_WIN32 || LV_USE_FS_FATFS) && LV_BUILD_EXAMPLES
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void file_explorer_event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
const char * cur_path = lv_file_explorer_get_current_path(obj);
|
||||
const char * sel_fn = lv_file_explorer_get_selected_file_name(obj);
|
||||
uint16_t path_len = strlen(cur_path);
|
||||
uint16_t fn_len = strlen(sel_fn);
|
||||
|
||||
if((path_len + fn_len) <= LV_FILE_EXPLORER_PATH_MAX_LEN) {
|
||||
char file_info[LV_FILE_EXPLORER_PATH_MAX_LEN];
|
||||
|
||||
strcpy(file_info, cur_path);
|
||||
strcat(file_info, sel_fn);
|
||||
|
||||
LV_LOG_USER("%s", file_info);
|
||||
}
|
||||
else LV_LOG_USER("%s%s", cur_path, sel_fn);
|
||||
}
|
||||
}
|
||||
|
||||
static void btn_event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
lv_obj_t * file_explorer = lv_event_get_user_data(e);
|
||||
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
if(lv_obj_has_state(btn, LV_STATE_CHECKED))
|
||||
lv_obj_add_flag(file_explorer, LV_OBJ_FLAG_HIDDEN);
|
||||
else
|
||||
lv_obj_remove_flag(file_explorer, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
static void dd_event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * dd = lv_event_get_target(e);
|
||||
lv_obj_t * fe_quick_access_obj = lv_event_get_user_data(e);
|
||||
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
char buf[32];
|
||||
lv_dropdown_get_selected_str(dd, buf, sizeof(buf));
|
||||
if(strcmp(buf, "NONE") == 0) {
|
||||
lv_file_explorer_set_sort(fe_quick_access_obj, LV_EXPLORER_SORT_NONE);
|
||||
}
|
||||
else if(strcmp(buf, "KIND") == 0) {
|
||||
lv_file_explorer_set_sort(fe_quick_access_obj, LV_EXPLORER_SORT_KIND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_file_explorer_2(void)
|
||||
{
|
||||
lv_obj_t * file_explorer = lv_file_explorer_create(lv_screen_active());
|
||||
|
||||
#if LV_USE_FS_WIN32
|
||||
lv_file_explorer_open_dir(file_explorer, "D:");
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, "C:/Users/Public/Desktop");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, "C:/Users/Public/Videos");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, "C:/Users/Public/Pictures");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, "C:/Users/Public/Music");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, "C:/Users/Public/Documents");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "D:");
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* linux */
|
||||
lv_file_explorer_open_dir(file_explorer, "A:/");
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
char * envvar = "HOME";
|
||||
char home_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(home_dir, "A:");
|
||||
/* get the user's home directory from the HOME environment variable*/
|
||||
strcat(home_dir, getenv(envvar));
|
||||
LV_LOG_USER("home_dir: %s\n", home_dir);
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, home_dir);
|
||||
char video_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(video_dir, home_dir);
|
||||
strcat(video_dir, "/Videos");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, video_dir);
|
||||
char picture_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(picture_dir, home_dir);
|
||||
strcat(picture_dir, "/Pictures");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, picture_dir);
|
||||
char music_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(music_dir, home_dir);
|
||||
strcat(music_dir, "/Music");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, music_dir);
|
||||
char document_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(document_dir, home_dir);
|
||||
strcat(document_dir, "/Documents");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, document_dir);
|
||||
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "A:/");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL);
|
||||
|
||||
/*Quick access status control button*/
|
||||
lv_obj_t * fe_quick_access_obj = lv_file_explorer_get_quick_access_area(file_explorer);
|
||||
lv_obj_t * fe_header_obj = lv_file_explorer_get_header(file_explorer);
|
||||
lv_obj_t * btn = lv_button_create(fe_header_obj);
|
||||
lv_obj_set_style_radius(btn, 2, 0);
|
||||
lv_obj_set_style_pad_all(btn, 4, 0);
|
||||
lv_obj_align(btn, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, LV_SYMBOL_LIST);
|
||||
lv_obj_center(label);
|
||||
|
||||
lv_obj_add_event_cb(btn, btn_event_handler, LV_EVENT_VALUE_CHANGED, fe_quick_access_obj);
|
||||
|
||||
/*Sort control*/
|
||||
static const char * opts = "NONE\n"
|
||||
"KIND";
|
||||
|
||||
lv_obj_t * dd = lv_dropdown_create(fe_header_obj);
|
||||
lv_obj_set_style_radius(dd, 4, 0);
|
||||
lv_obj_set_style_pad_all(dd, 0, 0);
|
||||
lv_obj_set_size(dd, LV_PCT(30), LV_SIZE_CONTENT);
|
||||
lv_dropdown_set_options_static(dd, opts);
|
||||
lv_obj_align(dd, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
|
||||
lv_obj_add_event_cb(dd, dd_event_handler, LV_EVENT_VALUE_CHANGED, file_explorer);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,126 @@
|
||||
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_TABLE && LV_USE_FILE_EXPLORER && (LV_USE_FS_STDIO || LV_USE_FS_POSIX || LV_USE_FS_WIN32 || LV_USE_FS_FATFS) && LV_BUILD_EXAMPLES
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void exch_table_item(lv_obj_t * tb, int16_t i, int16_t j)
|
||||
{
|
||||
const char * tmp;
|
||||
tmp = lv_table_get_cell_value(tb, i, 0);
|
||||
lv_table_set_cell_value(tb, 0, 2, tmp);
|
||||
lv_table_set_cell_value(tb, i, 0, lv_table_get_cell_value(tb, j, 0));
|
||||
lv_table_set_cell_value(tb, j, 0, lv_table_get_cell_value(tb, 0, 2));
|
||||
|
||||
tmp = lv_table_get_cell_value(tb, i, 1);
|
||||
lv_table_set_cell_value(tb, 0, 2, tmp);
|
||||
lv_table_set_cell_value(tb, i, 1, lv_table_get_cell_value(tb, j, 1));
|
||||
lv_table_set_cell_value(tb, j, 1, lv_table_get_cell_value(tb, 0, 2));
|
||||
}
|
||||
|
||||
/*Quick sort 3 way*/
|
||||
static void sort_by_file_kind(lv_obj_t * tb, int16_t lo, int16_t hi)
|
||||
{
|
||||
if(lo >= hi) return;
|
||||
|
||||
int16_t lt = lo;
|
||||
int16_t i = lo + 1;
|
||||
int16_t gt = hi;
|
||||
const char * v = lv_table_get_cell_value(tb, lo, 1);
|
||||
while(i <= gt) {
|
||||
if(strcmp(lv_table_get_cell_value(tb, i, 1), v) < 0)
|
||||
exch_table_item(tb, lt++, i++);
|
||||
else if(strcmp(lv_table_get_cell_value(tb, i, 1), v) > 0)
|
||||
exch_table_item(tb, i, gt--);
|
||||
else
|
||||
i++;
|
||||
}
|
||||
|
||||
sort_by_file_kind(tb, lo, lt - 1);
|
||||
sort_by_file_kind(tb, gt + 1, hi);
|
||||
}
|
||||
|
||||
static void file_explorer_event_handler(lv_event_t * e)
|
||||
{
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
|
||||
if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
const char * cur_path = lv_file_explorer_get_current_path(obj);
|
||||
const char * sel_fn = lv_file_explorer_get_selected_file_name(obj);
|
||||
uint16_t path_len = strlen(cur_path);
|
||||
uint16_t fn_len = strlen(sel_fn);
|
||||
|
||||
if((path_len + fn_len) <= LV_FILE_EXPLORER_PATH_MAX_LEN) {
|
||||
char file_info[LV_FILE_EXPLORER_PATH_MAX_LEN];
|
||||
|
||||
strcpy(file_info, cur_path);
|
||||
strcat(file_info, sel_fn);
|
||||
|
||||
LV_LOG_USER("%s", file_info);
|
||||
}
|
||||
else LV_LOG_USER("%s%s", cur_path, sel_fn);
|
||||
}
|
||||
else if(code == LV_EVENT_READY) {
|
||||
lv_obj_t * tb = lv_file_explorer_get_file_table(obj);
|
||||
uint16_t sum = lv_table_get_row_count(tb);
|
||||
|
||||
sort_by_file_kind(tb, 0, (sum - 1));
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_file_explorer_3(void)
|
||||
{
|
||||
lv_obj_t * file_explorer = lv_file_explorer_create(lv_screen_active());
|
||||
/*Before custom sort, please set the default sorting to NONE. The default is NONE.*/
|
||||
lv_file_explorer_set_sort(file_explorer, LV_EXPLORER_SORT_NONE);
|
||||
|
||||
#if LV_USE_FS_WIN32
|
||||
lv_file_explorer_open_dir(file_explorer, "D:");
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, "C:/Users/Public/Desktop");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, "C:/Users/Public/Videos");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, "C:/Users/Public/Pictures");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, "C:/Users/Public/Music");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, "C:/Users/Public/Documents");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "D:");
|
||||
#endif
|
||||
|
||||
#else
|
||||
/* linux */
|
||||
lv_file_explorer_open_dir(file_explorer, "A:/");
|
||||
#if LV_FILE_EXPLORER_QUICK_ACCESS
|
||||
char * envvar = "HOME";
|
||||
char home_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(home_dir, "A:");
|
||||
/* get the user's home directory from the HOME environment variable*/
|
||||
strcat(home_dir, getenv(envvar));
|
||||
LV_LOG_USER("home_dir: %s\n", home_dir);
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_HOME_DIR, home_dir);
|
||||
char video_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(video_dir, home_dir);
|
||||
strcat(video_dir, "/Videos");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_VIDEO_DIR, video_dir);
|
||||
char picture_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(picture_dir, home_dir);
|
||||
strcat(picture_dir, "/Pictures");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_PICTURES_DIR, picture_dir);
|
||||
char music_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(music_dir, home_dir);
|
||||
strcat(music_dir, "/Music");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_MUSIC_DIR, music_dir);
|
||||
char document_dir[LV_FS_MAX_PATH_LENGTH];
|
||||
strcpy(document_dir, home_dir);
|
||||
strcat(document_dir, "/Documents");
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_DOCS_DIR, document_dir);
|
||||
|
||||
lv_file_explorer_set_quick_access_path(file_explorer, LV_EXPLORER_FS_DIR, "A:/");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
lv_obj_add_event_cb(file_explorer, file_explorer_event_handler, LV_EVENT_ALL, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,16 +1,12 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
:language: c
|
||||
|
||||
@@ -24,7 +24,6 @@ extern "C" {
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_fragment_1(void);
|
||||
|
||||
void lv_example_fragment_2(void);
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -10,7 +10,7 @@ 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 void sample_container_delete(lv_event_t * e);
|
||||
|
||||
static lv_obj_t * root = NULL;
|
||||
|
||||
@@ -22,22 +22,21 @@ struct 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(struct sample_fragment_t)
|
||||
};
|
||||
.instance_size = sizeof(struct sample_fragment_t),
|
||||
};
|
||||
|
||||
void lv_example_fragment_1(void)
|
||||
{
|
||||
root = lv_obj_create(lv_scr_act());
|
||||
root = lv_obj_create(lv_screen_active());
|
||||
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_obj_add_event_cb(root, sample_container_delete, 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;
|
||||
@@ -51,10 +50,10 @@ static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * pa
|
||||
return label;
|
||||
}
|
||||
|
||||
static void sample_container_del(lv_event_t * e)
|
||||
static void sample_container_delete(lv_event_t * e)
|
||||
{
|
||||
lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e);
|
||||
lv_fragment_manager_del(manager);
|
||||
lv_fragment_manager_delete(manager);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
#include "../../lv_examples.h"
|
||||
|
||||
#if LV_USE_FRAGMENT && LV_USE_WIN && LV_BUILD_EXAMPLES
|
||||
#if LV_USE_FRAGMENT && LV_USE_WIN && LV_USE_GRID && LV_BUILD_EXAMPLES
|
||||
|
||||
static void sample_fragment_ctor(lv_fragment_t * self, void * args);
|
||||
|
||||
@@ -14,7 +14,7 @@ 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_container_delete(lv_event_t * e);
|
||||
|
||||
static void sample_fragment_inc_click(lv_event_t * e);
|
||||
|
||||
@@ -28,28 +28,28 @@ typedef struct 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)
|
||||
.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_t * root = lv_obj_create(lv_screen_active());
|
||||
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};
|
||||
static const int32_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
|
||||
static const int32_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_btn = lv_button_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_btn = lv_button_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);
|
||||
@@ -57,7 +57,7 @@ void lv_example_fragment_2(void)
|
||||
|
||||
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_obj_add_event_cb(root, sample_container_delete, LV_EVENT_DELETE, manager);
|
||||
|
||||
int depth = 0;
|
||||
lv_fragment_t * fragment = lv_fragment_create(&sample_cls, &depth);
|
||||
@@ -66,7 +66,6 @@ void lv_example_fragment_2(void)
|
||||
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);
|
||||
@@ -89,7 +88,7 @@ static lv_obj_t * sample_fragment_create_obj(lv_fragment_t * self, lv_obj_t * pa
|
||||
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_btn = lv_button_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);
|
||||
@@ -111,10 +110,10 @@ static void sample_pop_click(lv_event_t * e)
|
||||
lv_fragment_manager_pop(manager);
|
||||
}
|
||||
|
||||
static void sample_container_del(lv_event_t * e)
|
||||
static void sample_container_delete(lv_event_t * e)
|
||||
{
|
||||
lv_fragment_manager_t * manager = (lv_fragment_manager_t *) lv_event_get_user_data(e);
|
||||
lv_fragment_manager_del(manager);
|
||||
lv_fragment_manager_delete(manager);
|
||||
}
|
||||
|
||||
static void sample_fragment_inc_click(lv_event_t * e)
|
||||
|
||||
@@ -1,24 +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
|
||||
@@ -9,7 +9,7 @@ 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_obj_t * cont1 = lv_obj_create(lv_screen_active());
|
||||
lv_gridnav_add(cont1, LV_GRIDNAV_CTRL_NONE);
|
||||
|
||||
/*Use flex here, but works with grid or manually placed objects as well*/
|
||||
@@ -25,19 +25,19 @@ void lv_example_gridnav_1(void)
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < 10; i++) {
|
||||
lv_obj_t * obj = lv_btn_create(cont1);
|
||||
lv_obj_t * obj = lv_button_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);
|
||||
label = lv_label_create(obj);
|
||||
lv_label_set_text_fmt(label, "%"LV_PRIu32"", 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_obj_t * cont2 = lv_obj_create(lv_screen_active());
|
||||
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));
|
||||
|
||||
@@ -9,24 +9,23 @@ 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_obj_t * list1 = lv_list_create(lv_screen_active());
|
||||
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_t * item = lv_list_add_button(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_obj_t * list2 = lv_list_create(lv_screen_active());
|
||||
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);
|
||||
@@ -35,7 +34,7 @@ void lv_example_gridnav_2(void)
|
||||
|
||||
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_t * item = lv_list_add_button(list2, LV_SYMBOL_DIRECTORY, buf);
|
||||
lv_obj_set_style_bg_opa(item, 0, 0);
|
||||
lv_group_remove_obj(item);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
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);
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
if(k == LV_KEY_ENTER) {
|
||||
lv_group_focus_obj(obj);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ 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_obj_t * cont_main = lv_obj_create(lv_screen_active());
|
||||
lv_gridnav_add(cont_main, LV_GRIDNAV_CTRL_ROLLOVER | LV_GRIDNAV_CTRL_SCROLL_FIRST);
|
||||
|
||||
/*Only the container needs to be in a group*/
|
||||
@@ -36,17 +36,16 @@ void lv_example_gridnav_3(void)
|
||||
lv_obj_t * btn;
|
||||
lv_obj_t * label;
|
||||
|
||||
btn = lv_btn_create(cont_main);
|
||||
btn = lv_button_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);
|
||||
btn = lv_button_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);
|
||||
@@ -83,19 +82,16 @@ void lv_example_gridnav_3(void)
|
||||
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);
|
||||
btn = lv_button_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);
|
||||
btn = lv_button_create(cont_sub2);
|
||||
lv_group_remove_obj(btn);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Button 4");
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#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));
|
||||
LV_UNUSED(list); /*If logging is disabled*/
|
||||
LV_LOG_USER("Clicked: %s", lv_list_get_button_text(list, obj));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,9 +17,9 @@ 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_obj_t * list = lv_list_create(lv_screen_active());
|
||||
lv_gridnav_add(list, LV_GRIDNAV_CTRL_ROLLOVER);
|
||||
lv_obj_align(list, LV_ALIGN_LEFT_MID, 0, 10);
|
||||
lv_obj_align(list, LV_ALIGN_LEFT_MID, 10, 0);
|
||||
lv_group_add_obj(lv_group_get_default(), list);
|
||||
|
||||
uint32_t i;
|
||||
@@ -33,13 +33,13 @@ void lv_example_gridnav_4(void)
|
||||
}
|
||||
|
||||
lv_snprintf(buf, sizeof(buf), "File %d", i + 1);
|
||||
lv_obj_t * item = lv_list_add_btn(list, LV_SYMBOL_FILE, buf);
|
||||
lv_obj_t * item = lv_list_add_button(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 * btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_align(btn, LV_ALIGN_RIGHT_MID, -10, 0);
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Button");
|
||||
}
|
||||
|
||||
@@ -1,12 +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
|
||||
|
||||
@@ -8,32 +8,32 @@ static void ta_event_cb(lv_event_t * 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) {
|
||||
if(lv_indev_get_type(lv_indev_active()) != LV_INDEV_TYPE_KEYPAD) {
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_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_obj_remove_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_t * pinyin_ime = lv_ime_pinyin_create(lv_screen_active());
|
||||
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_obj_t * ta1 = lv_textarea_create(lv_screen_active());
|
||||
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_obj_t * kb = lv_keyboard_create(lv_screen_active());
|
||||
lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
|
||||
@@ -45,7 +45,7 @@ void lv_example_ime_pinyin_1(void)
|
||||
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_obj_t * cz_label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(cz_label,
|
||||
"嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
|
||||
lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
|
||||
|
||||
@@ -8,32 +8,32 @@ static void ta_event_cb(lv_event_t * 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) {
|
||||
if(lv_indev_get_type(lv_indev_active()) != LV_INDEV_TYPE_KEYPAD) {
|
||||
lv_keyboard_set_textarea(kb, ta);
|
||||
lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_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_obj_remove_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_t * pinyin_ime = lv_ime_pinyin_create(lv_screen_active());
|
||||
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_obj_t * ta1 = lv_textarea_create(lv_screen_active());
|
||||
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_obj_t * kb = lv_keyboard_create(lv_screen_active());
|
||||
lv_keyboard_set_textarea(kb, ta1);
|
||||
|
||||
lv_ime_pinyin_set_keyboard(pinyin_ime, kb);
|
||||
@@ -47,7 +47,7 @@ void lv_example_ime_pinyin_2(void)
|
||||
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_obj_t * cz_label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(cz_label,
|
||||
"嵌入式系统(Embedded System),\n是一种嵌入机械或电气系统内部、具有专一功能和实时计算性能的计算机系统。");
|
||||
lv_obj_set_style_text_font(cz_label, &lv_font_simsun_16_cjk, 0);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Use emojis in a text.
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""
|
||||
---------------------
|
||||
|
||||
.. lv_example:: others/imgfont/lv_example_imgfont_1
|
||||
:language: c
|
||||
|
||||
@@ -4,24 +4,30 @@
|
||||
#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)
|
||||
static const void * get_imgfont_path(const lv_font_t * font, uint32_t unicode, uint32_t unicode_next,
|
||||
int32_t * offset_y, void * user_data)
|
||||
{
|
||||
LV_UNUSED(font);
|
||||
LV_UNUSED(unicode_next);
|
||||
LV_ASSERT_NULL(img_src);
|
||||
LV_UNUSED(offset_y);
|
||||
LV_UNUSED(user_data);
|
||||
|
||||
LV_IMAGE_DECLARE(emoji_F617);
|
||||
|
||||
if(unicode < 0xF000) return NULL;
|
||||
|
||||
if(unicode == 0xF617) {
|
||||
memcpy(img_src, &emoji_F617, sizeof(lv_img_dsc_t));
|
||||
return &emoji_F617;
|
||||
}
|
||||
else {
|
||||
char * path = (char *)img_src;
|
||||
snprintf(path, len, "%s/%04X.%s", "A:lvgl/examples/assets/emoji", unicode, "png");
|
||||
path[len - 1] = '\0';
|
||||
else if(unicode == 0xF600) {
|
||||
#if LV_USE_FFMPEG
|
||||
return "lvgl/examples/assets/emoji/F600.png";
|
||||
#else
|
||||
return "A:lvgl/examples/assets/emoji/F600.png";
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,14 +35,15 @@ static bool get_imgfont_path(const lv_font_t * font, void * img_src,
|
||||
*/
|
||||
void lv_example_imgfont_1(void)
|
||||
{
|
||||
lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path);
|
||||
lv_font_t * imgfont = lv_imgfont_create(80, get_imgfont_path, NULL);
|
||||
if(imgfont == NULL) {
|
||||
LV_LOG_ERROR("imgfont init error");
|
||||
return;
|
||||
}
|
||||
|
||||
imgfont->fallback = LV_FONT_DEFAULT;
|
||||
|
||||
lv_obj_t * label1 = lv_label_create(lv_scr_act());
|
||||
lv_obj_t * label1 = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label1, "12\uF600\uF617AB");
|
||||
lv_obj_set_style_text_font(label1, imgfont, LV_PART_MAIN);
|
||||
lv_obj_center(label1);
|
||||
@@ -45,7 +52,7 @@ void lv_example_imgfont_1(void)
|
||||
|
||||
void lv_example_imgfont_1(void)
|
||||
{
|
||||
lv_obj_t * label = lv_label_create(lv_scr_act());
|
||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "imgfont is not installed");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
@@ -13,13 +13,14 @@ extern "C" {
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "snapshot/lv_example_snapshot.h"
|
||||
#include "monkey/lv_example_monkey.h"
|
||||
#include "gridnav/lv_example_gridnav.h"
|
||||
#include "file_explorer/lv_example_file_explorer.h"
|
||||
#include "fragment/lv_example_fragment.h"
|
||||
#include "imgfont/lv_example_imgfont.h"
|
||||
#include "msg/lv_example_msg.h"
|
||||
#include "gridnav/lv_example_gridnav.h"
|
||||
#include "ime/lv_example_ime_pinyin.h"
|
||||
#include "imgfont/lv_example_imgfont.h"
|
||||
#include "monkey/lv_example_monkey.h"
|
||||
#include "observer/lv_example_observer.h"
|
||||
#include "snapshot/lv_example_snapshot.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
|
||||
@@ -1,18 +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
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
void lv_example_monkey_3(void)
|
||||
{
|
||||
static lv_point_t btn_points[3];
|
||||
lv_coord_t hor_res = LV_HOR_RES;
|
||||
int32_t hor_res = LV_HOR_RES;
|
||||
|
||||
/*Create button monkey test*/
|
||||
lv_monkey_config_t config;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#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
|
||||
@@ -1,171 +0,0 @@
|
||||
#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
|
||||
@@ -1,154 +0,0 @@
|
||||
#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
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
Bind a slider's value to a label
|
||||
--------------------------------
|
||||
|
||||
.. lv_example:: others/observer/lv_example_observer_1
|
||||
:language: c
|
||||
|
||||
Handling login and its states
|
||||
-----------------------------
|
||||
|
||||
.. lv_example:: others/observer/lv_example_observer_2
|
||||
:language: c
|
||||
|
||||
Set time with 12/24 mode and AM/PM
|
||||
----------------------------------
|
||||
|
||||
.. lv_example:: others/observer/lv_example_observer_3
|
||||
:language: c
|
||||
|
||||
Custom tab view with state management
|
||||
-------------------------------------
|
||||
|
||||
.. lv_example:: others/observer/lv_example_observer_4
|
||||
:language: c
|
||||
|
||||
Firmware update process
|
||||
-----------------------
|
||||
|
||||
.. lv_example:: others/observer/lv_example_observer_5
|
||||
:language: c
|
||||
|
||||
Modular style update on theme change
|
||||
------------------------------------
|
||||
|
||||
.. lv_example:: others/observer/lv_example_observer_6
|
||||
:language: c
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file lv_example_observer.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_OBSERVER_H
|
||||
#define LV_EXAMPLE_OBSERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_observer_1(void);
|
||||
void lv_example_observer_2(void);
|
||||
void lv_example_observer_3(void);
|
||||
void lv_example_observer_4(void);
|
||||
void lv_example_observer_5(void);
|
||||
void lv_example_observer_6(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_OBSERVER_H*/
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_OBSERVER && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES
|
||||
|
||||
static lv_subject_t temperature_subject;
|
||||
|
||||
/**
|
||||
* A slider sends a message on value change and a label display's that value
|
||||
*/
|
||||
void lv_example_observer_1(void)
|
||||
{
|
||||
lv_subject_init_int(&temperature_subject, 28);
|
||||
|
||||
/*Create a slider in the center of the display*/
|
||||
lv_obj_t * slider = lv_slider_create(lv_screen_active());
|
||||
lv_obj_center(slider);
|
||||
lv_slider_bind_value(slider, &temperature_subject);
|
||||
|
||||
/*Create a label below the slider*/
|
||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 30);
|
||||
lv_label_bind_text(label, &temperature_subject, "%d °C");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_OBSERVER && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES
|
||||
|
||||
/*This the only interface between the UI and the application*/
|
||||
static lv_subject_t engine_subject;
|
||||
|
||||
static void app_init(void);
|
||||
static void ui_init(void);
|
||||
|
||||
/**
|
||||
* Simple PIN login screen to start an engine.
|
||||
* The only interface between the UI and the application is a single "subject".
|
||||
*/
|
||||
void lv_example_observer_2(void)
|
||||
{
|
||||
lv_subject_init_int(&engine_subject, 0);
|
||||
app_init();
|
||||
ui_init();
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
* APPLICATION
|
||||
*
|
||||
* This part contains a demo application logic.
|
||||
* It doesn't know anything about the internals of the UI
|
||||
* and uses any the `engine_subject` as an interface.
|
||||
* -------------------------------------------------*/
|
||||
static void engine_state_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
LV_UNUSED(observer);
|
||||
|
||||
int32_t v = lv_subject_get_int(subject);
|
||||
LV_UNUSED(v);
|
||||
/*In a real application set/clear a pin here*/
|
||||
LV_LOG_USER("Engine state: %" LV_PRId32, v);
|
||||
}
|
||||
|
||||
static void app_init(void)
|
||||
{
|
||||
lv_subject_add_observer(&engine_subject, engine_state_observer_cb, NULL);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
* USER INTERFACE
|
||||
*
|
||||
* This part contains only UI related code and data.
|
||||
* In a project it would a separate file and the
|
||||
* application couldn't see its internals
|
||||
* -------------------------------------------------*/
|
||||
|
||||
typedef enum {
|
||||
LOGGED_OUT,
|
||||
LOGGED_IN,
|
||||
AUTH_FAILED,
|
||||
} auth_state_t;
|
||||
|
||||
static lv_subject_t auth_state_subject;
|
||||
|
||||
static void textarea_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
if(strcmp(lv_textarea_get_text(ta), "hello") == 0) {
|
||||
lv_subject_set_int(&auth_state_subject, LOGGED_IN);
|
||||
}
|
||||
else {
|
||||
lv_subject_set_int(&auth_state_subject, AUTH_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
static void info_label_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
lv_obj_t * label = lv_observer_get_target(observer);
|
||||
switch(lv_subject_get_int(subject)) {
|
||||
case LOGGED_IN:
|
||||
lv_label_set_text(label, "Login successful");
|
||||
break;
|
||||
case LOGGED_OUT:
|
||||
lv_label_set_text(label, "Logged out");
|
||||
break;
|
||||
case AUTH_FAILED:
|
||||
lv_label_set_text(label, "Login failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void log_out_click_event_cb(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
lv_subject_set_int(&auth_state_subject, LOGGED_OUT);
|
||||
}
|
||||
|
||||
static void ui_init(void)
|
||||
{
|
||||
lv_subject_init_int(&auth_state_subject, LOGGED_OUT);
|
||||
|
||||
/*Create a slider in the center of the display*/
|
||||
lv_obj_t * ta = lv_textarea_create(lv_screen_active());
|
||||
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_READY, NULL);
|
||||
lv_obj_bind_state_if_eq(ta, &auth_state_subject, LV_STATE_DISABLED, LOGGED_IN);
|
||||
|
||||
lv_obj_t * kb = lv_keyboard_create(lv_screen_active());
|
||||
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_button_create(lv_screen_active());
|
||||
lv_obj_set_pos(btn, 220, 10);
|
||||
lv_obj_add_event_cb(btn, log_out_click_event_cb, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_bind_state_if_not_eq(btn, &auth_state_subject, LV_STATE_DISABLED, LOGGED_IN);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "LOG OUT");
|
||||
|
||||
/*Create a label to show info*/
|
||||
label = lv_label_create(lv_screen_active());
|
||||
lv_obj_set_pos(label, 10, 60);
|
||||
lv_subject_add_observer_obj(&auth_state_subject, info_label_observer_cb, label, NULL);
|
||||
|
||||
/*Create button which will be active only when logged in*/
|
||||
btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_pos(btn, 10, 80);
|
||||
lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE);
|
||||
lv_obj_bind_state_if_not_eq(btn, &auth_state_subject, LV_STATE_DISABLED, LOGGED_IN);
|
||||
lv_button_bind_checked(btn, &engine_subject);
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "START ENGINE");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_OBSERVER && LV_USE_SLIDER && LV_USE_LABEL && LV_USE_ROLLER && LV_USE_DROPDOWN && LV_FONT_MONTSERRAT_30 && LV_BUILD_EXAMPLES
|
||||
|
||||
static lv_subject_t hour_subject;
|
||||
static lv_subject_t minute_subject;
|
||||
static lv_subject_t format_subject;
|
||||
static lv_subject_t am_pm_subject;
|
||||
static lv_subject_t time_subject;
|
||||
static lv_subject_t * time_group_array_subject[] = {&hour_subject, &minute_subject, &format_subject, &am_pm_subject};
|
||||
const char * hour12_options = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12";
|
||||
const char * hour24_options =
|
||||
"00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23";
|
||||
const char * minute_options =
|
||||
"00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
|
||||
|
||||
static void set_btn_clicked_event_cb(lv_event_t * e);
|
||||
static void close_clicked_event_cb(lv_event_t * e);
|
||||
static void hour_roller_options_update(lv_observer_t * observer, lv_subject_t * subject);
|
||||
static void time_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
|
||||
typedef enum {
|
||||
TIME_FORMAT_12,
|
||||
TIME_FORMAT_24,
|
||||
} time_format_t;
|
||||
|
||||
typedef enum {
|
||||
TIME_AM,
|
||||
TIME_PM,
|
||||
} time_am_pm_t;
|
||||
|
||||
/**
|
||||
* Show how to handle a complex time setting with hour, minute, 12/24 hour mode, and AM/PM switch
|
||||
* In a real application the time can be displayed on multiple screens and it's not trivial
|
||||
* how and where to store the current values and how to get them.
|
||||
* In this example the widgets to set the time are create/deleted dynamically,
|
||||
* yet they always know what the current values are by using subjects.
|
||||
*/
|
||||
void lv_example_observer_3(void)
|
||||
{
|
||||
/*Initialize the subjects.
|
||||
*The UI will update these and read the current values from here,
|
||||
*however the application can update these values at any time and
|
||||
*the widgets will be updated automatically. */
|
||||
lv_subject_init_int(&hour_subject, 7);
|
||||
lv_subject_init_int(&minute_subject, 45);
|
||||
lv_subject_init_int(&format_subject, TIME_FORMAT_12);
|
||||
lv_subject_init_int(&am_pm_subject, TIME_AM);
|
||||
lv_subject_init_group(&time_subject, time_group_array_subject, 4);
|
||||
|
||||
/*Create the UI*/
|
||||
lv_obj_t * time_label = lv_label_create(lv_screen_active());
|
||||
lv_obj_set_style_text_font(time_label, &lv_font_montserrat_30, 0);
|
||||
lv_subject_add_observer_obj(&time_subject, time_observer_cb, time_label, NULL);
|
||||
lv_obj_set_pos(time_label, 24, 24);
|
||||
|
||||
lv_obj_t * set_btn = lv_button_create(lv_screen_active());
|
||||
lv_obj_set_pos(set_btn, 180, 24);
|
||||
lv_obj_add_event_cb(set_btn, set_btn_clicked_event_cb, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
lv_obj_t * set_label = lv_label_create(set_btn);
|
||||
lv_label_set_text(set_label, "Set");
|
||||
|
||||
/*Update some subjects to see if the UI is updated as well*/
|
||||
lv_subject_set_int(&hour_subject, 9);
|
||||
lv_subject_set_int(&minute_subject, 30);
|
||||
lv_subject_set_int(&am_pm_subject, TIME_PM);
|
||||
}
|
||||
|
||||
static void set_btn_clicked_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * set_btn = lv_event_get_target(e);
|
||||
lv_obj_add_state(set_btn, LV_STATE_DISABLED);
|
||||
|
||||
lv_obj_t * cont = lv_obj_create(lv_screen_active());
|
||||
lv_obj_set_size(cont, lv_pct(100), LV_SIZE_CONTENT);
|
||||
lv_obj_align(cont, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
|
||||
lv_obj_t * hour_roller = lv_roller_create(cont);
|
||||
lv_obj_add_flag(hour_roller, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
|
||||
lv_subject_add_observer_obj(&format_subject, hour_roller_options_update, hour_roller, NULL);
|
||||
lv_roller_bind_value(hour_roller, &hour_subject);
|
||||
lv_obj_set_pos(hour_roller, 0, 0);
|
||||
|
||||
lv_obj_t * min_roller = lv_roller_create(cont);
|
||||
lv_roller_set_options(min_roller, minute_options, LV_ROLLER_MODE_NORMAL);
|
||||
lv_roller_bind_value(min_roller, &minute_subject);
|
||||
lv_obj_set_pos(min_roller, 64, 0);
|
||||
|
||||
lv_obj_t * format_dropdown = lv_dropdown_create(cont);
|
||||
lv_dropdown_set_options(format_dropdown, "12\n24");
|
||||
lv_dropdown_bind_value(format_dropdown, &format_subject);
|
||||
lv_obj_set_pos(format_dropdown, 128, 0);
|
||||
lv_obj_set_width(format_dropdown, 80);
|
||||
|
||||
lv_obj_t * am_pm_dropdown = lv_dropdown_create(cont);
|
||||
lv_dropdown_set_options(am_pm_dropdown, "am\npm");
|
||||
lv_dropdown_bind_value(am_pm_dropdown, &am_pm_subject);
|
||||
lv_obj_bind_state_if_eq(am_pm_dropdown, &format_subject, LV_STATE_DISABLED, TIME_FORMAT_24);
|
||||
lv_obj_set_pos(am_pm_dropdown, 128, 48);
|
||||
lv_obj_set_width(am_pm_dropdown, 80);
|
||||
|
||||
lv_obj_t * close_btn = lv_button_create(cont);
|
||||
lv_obj_align(close_btn, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
/*Pass the set_btn as user_data to make it non-disabled on close*/
|
||||
lv_obj_add_event_cb(close_btn, close_clicked_event_cb, LV_EVENT_CLICKED, set_btn);
|
||||
|
||||
lv_obj_t * close_label = lv_label_create(close_btn);
|
||||
lv_label_set_text(close_label, LV_SYMBOL_CLOSE);
|
||||
}
|
||||
|
||||
static void close_clicked_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * set_btn = lv_event_get_user_data(e);
|
||||
lv_obj_t * close_btn = lv_event_get_target(e);
|
||||
lv_obj_t * cont = lv_obj_get_parent(close_btn);
|
||||
lv_obj_remove_state(set_btn, LV_STATE_DISABLED);
|
||||
lv_obj_delete(cont);
|
||||
}
|
||||
|
||||
/*Watch all related subject to display the current time correctly*/
|
||||
static void time_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
int32_t hour = lv_subject_get_int(lv_subject_get_group_element(subject, 0));
|
||||
int32_t minute = lv_subject_get_int(lv_subject_get_group_element(subject, 1));
|
||||
int32_t format = lv_subject_get_int(lv_subject_get_group_element(subject, 2));
|
||||
int32_t am_pm = lv_subject_get_int(lv_subject_get_group_element(subject, 3));
|
||||
|
||||
lv_obj_t * label = lv_observer_get_target(observer);
|
||||
|
||||
if(format == TIME_FORMAT_24) {
|
||||
lv_label_set_text_fmt(label, "%d:%02d", hour, minute);
|
||||
}
|
||||
else {
|
||||
lv_label_set_text_fmt(label, "%d:%02d %s", hour + 1, minute, am_pm == TIME_AM ? "am" : "pm");
|
||||
}
|
||||
}
|
||||
|
||||
/*Change the hour options on format change*/
|
||||
static void hour_roller_options_update(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
lv_obj_t * roller = lv_observer_get_target(observer);
|
||||
int32_t prev_selected = lv_roller_get_selected(roller);
|
||||
int32_t v = lv_subject_get_int(subject);
|
||||
if(v == TIME_FORMAT_12) {
|
||||
prev_selected--;
|
||||
if(prev_selected > 12) prev_selected -= 12;
|
||||
lv_roller_set_options(roller, hour12_options, LV_ROLLER_MODE_NORMAL);
|
||||
}
|
||||
else {
|
||||
prev_selected++;
|
||||
lv_roller_set_options(roller, hour24_options, LV_ROLLER_MODE_NORMAL);
|
||||
}
|
||||
|
||||
lv_roller_set_selected(roller, prev_selected, LV_ANIM_OFF);
|
||||
lv_obj_send_event(roller, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,205 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_OBSERVER && LV_USE_SLIDER && LV_USE_LABEL && LV_USE_ROLLER && LV_USE_DROPDOWN && LV_FONT_MONTSERRAT_30 && LV_BUILD_EXAMPLES
|
||||
|
||||
static void cont_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
static void btn_create(lv_obj_t * parent, const char * text);
|
||||
static void btn_click_event_cb(lv_event_t * e);
|
||||
static void btn_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
static void indicator_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
|
||||
static lv_subject_t current_tab_subject;
|
||||
static lv_subject_t slider_subject[4];
|
||||
static lv_subject_t dropdown_subject[3];
|
||||
static lv_subject_t roller_subject[2];
|
||||
|
||||
void lv_example_observer_4(void)
|
||||
{
|
||||
lv_subject_init_int(¤t_tab_subject, 0);
|
||||
lv_subject_init_int(&slider_subject[0], 0);
|
||||
lv_subject_init_int(&slider_subject[1], 0);
|
||||
lv_subject_init_int(&slider_subject[2], 0);
|
||||
lv_subject_init_int(&slider_subject[3], 0);
|
||||
lv_subject_init_int(&dropdown_subject[0], 0);
|
||||
lv_subject_init_int(&dropdown_subject[1], 0);
|
||||
lv_subject_init_int(&dropdown_subject[2], 0);
|
||||
lv_subject_init_int(&roller_subject[0], 0);
|
||||
lv_subject_init_int(&roller_subject[1], 0);
|
||||
|
||||
lv_obj_t * main_cont = lv_obj_create(lv_screen_active());
|
||||
lv_obj_remove_style_all(main_cont);
|
||||
lv_obj_set_size(main_cont, lv_pct(100), lv_pct(100));
|
||||
lv_obj_set_style_pad_all(main_cont, 0, 0);
|
||||
lv_obj_set_flex_flow(main_cont, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lv_obj_t * cont = lv_obj_create(main_cont);
|
||||
lv_obj_remove_style_all(cont);
|
||||
lv_obj_set_flex_grow(cont, 1);
|
||||
lv_obj_set_style_pad_all(cont, 8, 0);
|
||||
lv_obj_set_width(cont, lv_pct(100));
|
||||
lv_subject_add_observer_obj(¤t_tab_subject, cont_observer_cb, cont, NULL);
|
||||
lv_obj_set_scroll_dir(cont, LV_DIR_VER);
|
||||
|
||||
lv_obj_t * footer = lv_obj_create(main_cont);
|
||||
lv_obj_remove_style_all(footer);
|
||||
lv_obj_set_style_pad_column(footer, 8, 0);
|
||||
lv_obj_set_style_pad_all(footer, 8, 0);
|
||||
lv_obj_set_flex_flow(footer, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_size(footer, lv_pct(100), 60);
|
||||
lv_obj_align(footer, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
|
||||
btn_create(footer, "First");
|
||||
btn_create(footer, "Second");
|
||||
btn_create(footer, "Third");
|
||||
|
||||
lv_obj_t * indicator = lv_obj_create(footer);
|
||||
lv_obj_remove_style(indicator, NULL, 0);
|
||||
lv_obj_set_style_bg_opa(indicator, LV_OPA_40, 0);
|
||||
lv_subject_add_observer_obj(¤t_tab_subject, indicator_observer_cb, indicator, NULL);
|
||||
lv_obj_set_height(indicator, 10);
|
||||
lv_obj_align(indicator, LV_ALIGN_BOTTOM_LEFT, 0, 0);
|
||||
lv_obj_add_flag(indicator, LV_OBJ_FLAG_IGNORE_LAYOUT);
|
||||
|
||||
/*Be sure the indicator has the correct size*/
|
||||
lv_obj_update_layout(indicator);
|
||||
lv_subject_notify(¤t_tab_subject);
|
||||
}
|
||||
|
||||
static int32_t anim_get_x_cb(lv_anim_t * a)
|
||||
{
|
||||
return lv_obj_get_x_aligned(a->var);
|
||||
}
|
||||
|
||||
static void anim_set_x_cb(void * obj, int32_t v)
|
||||
{
|
||||
lv_obj_set_x(obj, v);
|
||||
}
|
||||
|
||||
static void cont_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
int32_t prev_v = lv_subject_get_previous_int(subject);
|
||||
int32_t cur_v = lv_subject_get_int(subject);
|
||||
lv_obj_t * cont = lv_observer_get_target(observer);
|
||||
|
||||
/*Animate out the previous content*/
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_duration(&a, 300);
|
||||
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
||||
lv_anim_set_exec_cb(&a, anim_set_x_cb);
|
||||
lv_anim_set_get_value_cb(&a, anim_get_x_cb);
|
||||
lv_anim_set_completed_cb(&a, lv_obj_delete_anim_completed_cb);
|
||||
|
||||
uint32_t i;
|
||||
uint32_t delay = 0;
|
||||
uint32_t child_cnt_prev = lv_obj_get_child_count(cont);
|
||||
for(i = 0; i < child_cnt_prev; i++) {
|
||||
lv_obj_t * child = lv_obj_get_child(cont, i);
|
||||
lv_anim_set_var(&a, child);
|
||||
if(prev_v < cur_v) {
|
||||
lv_anim_set_values(&a, 0, -20);
|
||||
}
|
||||
else {
|
||||
lv_anim_set_values(&a, 0, 20);
|
||||
}
|
||||
lv_anim_set_delay(&a, delay);
|
||||
lv_anim_start(&a);
|
||||
lv_obj_fade_out(child, 200, delay);
|
||||
delay += 50;
|
||||
}
|
||||
|
||||
/*Create the widgets according to the current value*/
|
||||
if(cur_v == 0) {
|
||||
for(i = 0; i < 4; i++) {
|
||||
lv_obj_t * slider = lv_slider_create(cont);
|
||||
lv_slider_bind_value(slider, &slider_subject[i]);
|
||||
lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 10 + i * 30);
|
||||
}
|
||||
}
|
||||
if(cur_v == 1) {
|
||||
for(i = 0; i < 3; i++) {
|
||||
lv_obj_t * dropdown = lv_dropdown_create(cont);
|
||||
lv_dropdown_bind_value(dropdown, &dropdown_subject[i]);
|
||||
lv_obj_align(dropdown, LV_ALIGN_TOP_MID, 0, i * 50);
|
||||
}
|
||||
}
|
||||
if(cur_v == 2) {
|
||||
for(i = 0; i < 2; i++) {
|
||||
lv_obj_t * roller = lv_roller_create(cont);
|
||||
lv_roller_bind_value(roller, &roller_subject[i]);
|
||||
lv_obj_align(roller, LV_ALIGN_CENTER, - 80 + i * 160, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*Animate in the new widgets*/
|
||||
lv_anim_set_completed_cb(&a, NULL);
|
||||
for(i = child_cnt_prev; i < lv_obj_get_child_count(cont); i++) {
|
||||
lv_obj_t * child = lv_obj_get_child(cont, i);
|
||||
lv_anim_set_var(&a, child);
|
||||
if(prev_v < cur_v) {
|
||||
lv_anim_set_values(&a, 20, 0);
|
||||
}
|
||||
else {
|
||||
lv_anim_set_values(&a, -20, -0);
|
||||
}
|
||||
lv_anim_set_delay(&a, delay);
|
||||
lv_anim_start(&a);
|
||||
lv_obj_fade_in(child, 200, delay);
|
||||
delay += 50;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void btn_create(lv_obj_t * parent, const char * text)
|
||||
{
|
||||
lv_obj_t * btn = lv_button_create(parent);
|
||||
lv_obj_set_flex_grow(btn, 1);
|
||||
lv_obj_set_height(btn, lv_pct(100));
|
||||
lv_obj_set_style_radius(btn, 0, 0);
|
||||
lv_subject_add_observer_obj(¤t_tab_subject, btn_observer_cb, btn, NULL);
|
||||
lv_obj_add_event_cb(btn, btn_click_event_cb, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, text);
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
static void btn_click_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
uint32_t idx = lv_obj_get_index(btn);
|
||||
lv_subject_set_int(¤t_tab_subject, idx);
|
||||
}
|
||||
|
||||
static void btn_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
int32_t prev_v = lv_subject_get_previous_int(subject);
|
||||
int32_t cur_v = lv_subject_get_int(subject);
|
||||
|
||||
lv_obj_t * btn = lv_observer_get_target(observer);
|
||||
int32_t idx = (int32_t)lv_obj_get_index(btn);
|
||||
|
||||
if(idx == prev_v) lv_obj_remove_state(btn, LV_STATE_CHECKED);
|
||||
if(idx == cur_v) lv_obj_add_state(btn, LV_STATE_CHECKED);
|
||||
}
|
||||
|
||||
static void indicator_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
int32_t cur_v = lv_subject_get_int(subject);
|
||||
lv_obj_t * indicator = lv_observer_get_target(observer);
|
||||
|
||||
lv_obj_t * footer = lv_obj_get_parent(indicator);
|
||||
lv_obj_t * btn_act = lv_obj_get_child(footer, cur_v);
|
||||
lv_obj_set_width(indicator, lv_obj_get_width(btn_act));
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_exec_cb(&a, anim_set_x_cb);
|
||||
lv_anim_set_duration(&a, 300);
|
||||
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
||||
lv_anim_set_var(&a, indicator);
|
||||
lv_anim_set_values(&a, lv_obj_get_x(indicator), lv_obj_get_x(btn_act));
|
||||
lv_anim_start(&a);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,167 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_OBSERVER && LV_USE_ARC && LV_USE_LABEL && LV_USE_BUTTON && LV_USE_SPINNER && LV_BUILD_EXAMPLES
|
||||
|
||||
typedef enum {
|
||||
FW_UPDATE_STATE_IDLE,
|
||||
FW_UPDATE_STATE_CONNECTING,
|
||||
FW_UPDATE_STATE_CONNECTED,
|
||||
FW_UPDATE_STATE_DOWNLOADING,
|
||||
FW_UPDATE_STATE_CANCEL,
|
||||
FW_UPDATE_STATE_READY,
|
||||
} fw_update_state_t;
|
||||
|
||||
static void fw_upload_manager_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
static void fw_update_btn_clicked_event_cb(lv_event_t * e);
|
||||
static void fw_update_close_event_cb(lv_event_t * e);
|
||||
static void fw_update_win_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
|
||||
static lv_subject_t fw_download_percent_subject;
|
||||
static lv_subject_t fw_update_status_subject;
|
||||
|
||||
/**
|
||||
* Show how to handle a complete firmware update process with observers.
|
||||
* Normally it's hard to implement a firmware update process because in some cases
|
||||
* - the App needs to was for the UI (wait for a button press)
|
||||
* - the UI needs to wait for the App (connecting or downloading)
|
||||
* With observers these complex mechanisms can be implemented a simple and clean way.
|
||||
*/
|
||||
void lv_example_observer_5(void)
|
||||
{
|
||||
lv_subject_init_int(&fw_download_percent_subject, 0);
|
||||
lv_subject_init_int(&fw_update_status_subject, FW_UPDATE_STATE_IDLE);
|
||||
|
||||
lv_subject_add_observer(&fw_update_status_subject, fw_upload_manager_observer_cb, NULL);
|
||||
|
||||
/*Create start FW update button*/
|
||||
lv_obj_t * btn = lv_btn_create(lv_screen_active());
|
||||
lv_obj_add_event_cb(btn, fw_update_btn_clicked_event_cb, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_center(btn);
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Firmware update");
|
||||
}
|
||||
|
||||
static void fw_update_btn_clicked_event_cb(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
lv_obj_t * win = lv_win_create(lv_screen_active());
|
||||
lv_obj_set_size(win, lv_pct(90), lv_pct(90));
|
||||
lv_obj_set_height(lv_win_get_header(win), 40);
|
||||
lv_obj_set_style_radius(win, 8, 0);
|
||||
lv_obj_set_style_shadow_width(win, 24, 0);
|
||||
lv_obj_set_style_shadow_offset_x(win, 2, 0);
|
||||
lv_obj_set_style_shadow_offset_y(win, 3, 0);
|
||||
lv_obj_set_style_shadow_color(win, lv_color_hex3(0x888), 0);
|
||||
lv_win_add_title(win, "Firmware update");
|
||||
lv_obj_t * btn = lv_win_add_button(win, LV_SYMBOL_CLOSE, 40);
|
||||
lv_obj_add_event_cb(btn, fw_update_close_event_cb, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_center(win);
|
||||
|
||||
lv_subject_set_int(&fw_update_status_subject, FW_UPDATE_STATE_IDLE);
|
||||
lv_subject_add_observer_obj(&fw_update_status_subject, fw_update_win_observer_cb, win, NULL);
|
||||
}
|
||||
|
||||
static void fw_update_close_event_cb(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
lv_subject_set_int(&fw_update_status_subject, FW_UPDATE_STATE_CANCEL);
|
||||
}
|
||||
|
||||
static void restart_btn_click_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * win = lv_event_get_user_data(e);
|
||||
lv_obj_delete(win);
|
||||
lv_subject_set_int(&fw_update_status_subject, FW_UPDATE_STATE_IDLE);
|
||||
}
|
||||
|
||||
static void fw_update_win_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
lv_obj_t * win = lv_observer_get_target(observer);
|
||||
lv_obj_t * cont = lv_win_get_content(win);
|
||||
fw_update_state_t status = lv_subject_get_int(&fw_update_status_subject);
|
||||
if(status == FW_UPDATE_STATE_IDLE) {
|
||||
lv_obj_clean(cont);
|
||||
lv_obj_t * spinner = lv_spinner_create(cont);
|
||||
lv_obj_center(spinner);
|
||||
lv_obj_set_size(spinner, 130, 130);
|
||||
|
||||
lv_obj_t * label = lv_label_create(cont);
|
||||
lv_label_set_text(label, "Connecting");
|
||||
lv_obj_center(label);
|
||||
|
||||
lv_subject_set_int(subject, FW_UPDATE_STATE_CONNECTING);
|
||||
}
|
||||
else if(status == FW_UPDATE_STATE_DOWNLOADING) {
|
||||
lv_obj_clean(cont);
|
||||
lv_obj_t * arc = lv_arc_create(cont);
|
||||
lv_arc_bind_value(arc, &fw_download_percent_subject);
|
||||
lv_obj_center(arc);
|
||||
lv_obj_set_size(arc, 130, 130);
|
||||
lv_obj_remove_flag(arc, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
||||
lv_obj_t * label = lv_label_create(cont);
|
||||
lv_label_bind_text(label, &fw_download_percent_subject, "%d %%");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
else if(status == FW_UPDATE_STATE_READY) {
|
||||
lv_obj_clean(cont);
|
||||
lv_obj_t * label = lv_label_create(cont);
|
||||
lv_label_set_text(label, "Firmware update is ready");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, -20);
|
||||
|
||||
lv_obj_t * btn = lv_button_create(cont);
|
||||
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 20);
|
||||
lv_obj_add_event_cb(btn, restart_btn_click_event_cb, LV_EVENT_CLICKED, win);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Restart");
|
||||
}
|
||||
else if(status == FW_UPDATE_STATE_CANCEL) {
|
||||
lv_obj_delete(win);
|
||||
}
|
||||
}
|
||||
|
||||
static void connect_timer_cb(lv_timer_t * t)
|
||||
{
|
||||
if(lv_subject_get_int(&fw_update_status_subject) != FW_UPDATE_STATE_CANCEL) {
|
||||
lv_subject_set_int(&fw_update_status_subject, FW_UPDATE_STATE_CONNECTED);
|
||||
}
|
||||
lv_timer_delete(t);
|
||||
}
|
||||
|
||||
static void download_timer_cb(lv_timer_t * t)
|
||||
{
|
||||
if(lv_subject_get_int(&fw_update_status_subject) == FW_UPDATE_STATE_CANCEL) {
|
||||
lv_timer_delete(t);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t v = lv_subject_get_int(&fw_download_percent_subject);
|
||||
if(v < 100) {
|
||||
lv_subject_set_int(&fw_download_percent_subject, v + 1);
|
||||
}
|
||||
else {
|
||||
lv_subject_set_int(&fw_update_status_subject, FW_UPDATE_STATE_READY);
|
||||
lv_timer_delete(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emulate connection and FW dowlading by timers
|
||||
*/
|
||||
static void fw_upload_manager_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
LV_UNUSED(subject);
|
||||
LV_UNUSED(observer);
|
||||
|
||||
fw_update_state_t state = lv_subject_get_int(&fw_update_status_subject);
|
||||
if(state == FW_UPDATE_STATE_CONNECTING) {
|
||||
lv_timer_create(connect_timer_cb, 2000, NULL);
|
||||
}
|
||||
else if(state == FW_UPDATE_STATE_CONNECTED) {
|
||||
lv_subject_set_int(&fw_download_percent_subject, 0);
|
||||
lv_subject_set_int(&fw_update_status_subject, FW_UPDATE_STATE_DOWNLOADING);
|
||||
lv_timer_create(download_timer_cb, 50, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,190 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_OBSERVER && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES
|
||||
|
||||
typedef enum {
|
||||
THEME_MODE_LIGHT,
|
||||
THEME_MODE_DARK,
|
||||
} theme_mode_t;
|
||||
|
||||
static lv_obj_t * my_panel_create(lv_obj_t * parent);
|
||||
static lv_obj_t * my_button_create(lv_obj_t * parent, const char * text, lv_event_cb_t event_cb);
|
||||
static void switch_theme_event_cb(lv_event_t * e);
|
||||
|
||||
static lv_subject_t theme_subject;
|
||||
|
||||
/**
|
||||
* Change between light and dark mode
|
||||
*/
|
||||
void lv_example_observer_6(void)
|
||||
{
|
||||
lv_subject_init_int(&theme_subject, THEME_MODE_DARK);
|
||||
|
||||
lv_obj_t * panel1 = my_panel_create(lv_screen_active());
|
||||
lv_obj_set_flex_flow(panel1, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(panel1, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_size(panel1, lv_pct(90), lv_pct(90));
|
||||
lv_obj_center(panel1);
|
||||
|
||||
my_button_create(panel1, "Button 1", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 2", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 3", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 4", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 5", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 6", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 7", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 8", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 9", switch_theme_event_cb);
|
||||
my_button_create(panel1, "Button 10", switch_theme_event_cb);
|
||||
}
|
||||
|
||||
static void switch_theme_event_cb(lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(e);
|
||||
if(lv_subject_get_int(&theme_subject) == THEME_MODE_LIGHT) lv_subject_set_int(&theme_subject, THEME_MODE_DARK);
|
||||
else lv_subject_set_int(&theme_subject, THEME_MODE_LIGHT);
|
||||
}
|
||||
|
||||
/*-----------------------------------------
|
||||
* my_panel.c
|
||||
*
|
||||
* It would be a separate file with its own
|
||||
* local types, data, and functions
|
||||
*------------------------------------------*/
|
||||
|
||||
typedef struct {
|
||||
lv_style_t style_main;
|
||||
lv_style_t style_scrollbar;
|
||||
} my_panel_styles_t;
|
||||
|
||||
static void my_panel_style_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
LV_UNUSED(subject);
|
||||
LV_UNUSED(observer);
|
||||
|
||||
theme_mode_t m = lv_subject_get_int(&theme_subject);
|
||||
my_panel_styles_t * styles = lv_observer_get_target(observer);
|
||||
if(m == THEME_MODE_LIGHT) {
|
||||
lv_style_set_bg_color(&styles->style_main, lv_color_hex3(0xfff));
|
||||
lv_style_set_shadow_color(&styles->style_main, lv_color_hex3(0x888));
|
||||
lv_style_set_text_color(&styles->style_main, lv_color_hex3(0x222));
|
||||
lv_style_set_bg_color(&styles->style_scrollbar, lv_color_hex3(0x888));
|
||||
}
|
||||
if(m == THEME_MODE_DARK) {
|
||||
lv_style_set_bg_color(&styles->style_main, lv_color_hex(0x040038));
|
||||
lv_style_set_shadow_color(&styles->style_main, lv_color_hex3(0xaaa));
|
||||
lv_style_set_text_color(&styles->style_main, lv_color_hex3(0xeee));
|
||||
lv_style_set_bg_color(&styles->style_scrollbar, lv_color_hex3(0xaaa));
|
||||
}
|
||||
|
||||
lv_obj_report_style_change(&styles->style_main);
|
||||
lv_obj_report_style_change(&styles->style_scrollbar);
|
||||
}
|
||||
|
||||
static lv_obj_t * my_panel_create(lv_obj_t * parent)
|
||||
{
|
||||
static bool inited = false;
|
||||
static my_panel_styles_t styles;
|
||||
if(!inited) {
|
||||
inited = true;
|
||||
|
||||
lv_style_init(&styles.style_main);
|
||||
lv_style_set_radius(&styles.style_main, 12);
|
||||
lv_style_set_bg_opa(&styles.style_main, LV_OPA_COVER);
|
||||
lv_style_set_shadow_width(&styles.style_main, 24);
|
||||
lv_style_set_shadow_offset_x(&styles.style_main, 4);
|
||||
lv_style_set_shadow_offset_y(&styles.style_main, 6);
|
||||
lv_style_set_pad_all(&styles.style_main, 12);
|
||||
lv_style_set_pad_gap(&styles.style_main, 16);
|
||||
|
||||
lv_style_init(&styles.style_scrollbar);
|
||||
lv_style_set_width(&styles.style_scrollbar, 4);
|
||||
lv_style_set_radius(&styles.style_scrollbar, 2);
|
||||
lv_style_set_pad_right(&styles.style_scrollbar, 8);
|
||||
lv_style_set_pad_ver(&styles.style_scrollbar, 8);
|
||||
lv_style_set_bg_opa(&styles.style_scrollbar, LV_OPA_50);
|
||||
|
||||
lv_subject_add_observer_with_target(&theme_subject, my_panel_style_observer_cb, &styles, NULL);
|
||||
}
|
||||
|
||||
lv_obj_t * panel = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(panel);
|
||||
lv_obj_add_style(panel, &styles.style_main, 0);
|
||||
lv_obj_add_style(panel, &styles.style_scrollbar, LV_PART_SCROLLBAR);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/*-----------------------------------------
|
||||
* my_button.c
|
||||
*
|
||||
* It would be a separate file with its own
|
||||
* local types, data, and functions
|
||||
*------------------------------------------*/
|
||||
|
||||
typedef struct {
|
||||
lv_style_t style_main;
|
||||
lv_style_t style_pressed;
|
||||
} my_button_styles_t;
|
||||
|
||||
static void my_button_style_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
{
|
||||
LV_UNUSED(subject);
|
||||
LV_UNUSED(observer);
|
||||
|
||||
theme_mode_t m = lv_subject_get_int(&theme_subject);
|
||||
my_button_styles_t * styles = lv_observer_get_target(observer);
|
||||
if(m == THEME_MODE_LIGHT) {
|
||||
lv_style_set_bg_color(&styles->style_main, lv_color_hex(0x3379de));
|
||||
lv_style_set_bg_grad_color(&styles->style_main, lv_color_hex(0xd249a5));
|
||||
lv_style_set_shadow_color(&styles->style_main, lv_color_hex(0x3379de));
|
||||
lv_style_set_text_color(&styles->style_main, lv_color_hex3(0xfff));
|
||||
|
||||
lv_style_set_color_filter_opa(&styles->style_pressed, LV_OPA_70);
|
||||
}
|
||||
if(m == THEME_MODE_DARK) {
|
||||
lv_style_set_bg_color(&styles->style_main, lv_color_hex(0xde1382));
|
||||
lv_style_set_bg_grad_color(&styles->style_main, lv_color_hex(0x4b0c72));
|
||||
lv_style_set_shadow_color(&styles->style_main, lv_color_hex(0x4b0c72));
|
||||
lv_style_set_text_color(&styles->style_main, lv_color_hex3(0xfff));
|
||||
|
||||
lv_style_set_color_filter_opa(&styles->style_pressed, LV_OPA_30);
|
||||
}
|
||||
|
||||
lv_obj_report_style_change(&styles->style_main);
|
||||
lv_obj_report_style_change(&styles->style_pressed);
|
||||
}
|
||||
|
||||
static lv_obj_t * my_button_create(lv_obj_t * parent, const char * text, lv_event_cb_t event_cb)
|
||||
{
|
||||
static bool inited = false;
|
||||
static my_button_styles_t styles;
|
||||
if(!inited) {
|
||||
inited = true;
|
||||
|
||||
lv_style_init(&styles.style_main);
|
||||
lv_style_set_radius(&styles.style_main, LV_RADIUS_CIRCLE);
|
||||
lv_style_set_bg_opa(&styles.style_main, LV_OPA_COVER);
|
||||
lv_style_set_bg_grad_dir(&styles.style_main, LV_GRAD_DIR_HOR);
|
||||
lv_style_set_shadow_width(&styles.style_main, 24);
|
||||
lv_style_set_shadow_offset_y(&styles.style_main, 6);
|
||||
lv_style_set_pad_hor(&styles.style_main, 32);
|
||||
lv_style_set_pad_ver(&styles.style_main, 12);
|
||||
|
||||
lv_style_init(&styles.style_pressed);
|
||||
lv_style_set_color_filter_dsc(&styles.style_pressed, &lv_color_filter_shade);
|
||||
lv_subject_add_observer_with_target(&theme_subject, my_button_style_observer_cb, &styles, NULL);
|
||||
}
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(parent);
|
||||
lv_obj_remove_style_all(btn);
|
||||
lv_obj_add_style(btn, &styles.style_main, 0);
|
||||
lv_obj_add_style(btn, &styles.style_pressed, LV_STATE_PRESSED);
|
||||
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, text);
|
||||
|
||||
return btn;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
typedef int dummy_int_t;
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
Simple snapshot example
|
||||
"""""""""""""""""""
|
||||
-----------------------
|
||||
|
||||
.. lv_example:: others/snapshot/lv_example_snapshot_1
|
||||
:language: c
|
||||
|
||||
@@ -7,31 +7,31 @@ static void event_cb(lv_event_t * 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);
|
||||
lv_draw_buf_t * snapshot = (lv_draw_buf_t *)lv_image_get_src(snapshot_obj);
|
||||
if(snapshot) {
|
||||
lv_snapshot_free(snapshot);
|
||||
lv_draw_buf_destroy(snapshot);
|
||||
}
|
||||
|
||||
/*Update the snapshot, we know parent of object is the container.*/
|
||||
snapshot = lv_snapshot_take(img->parent, LV_IMG_CF_TRUE_COLOR_ALPHA);
|
||||
snapshot = lv_snapshot_take(img->parent, LV_COLOR_FORMAT_ARGB8888);
|
||||
if(snapshot == NULL)
|
||||
return;
|
||||
lv_img_set_src(snapshot_obj, snapshot);
|
||||
lv_image_set_src(snapshot_obj, snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_example_snapshot_1(void)
|
||||
{
|
||||
LV_IMG_DECLARE(img_star);
|
||||
lv_obj_t * root = lv_scr_act();
|
||||
LV_IMAGE_DECLARE(img_star);
|
||||
lv_obj_t * root = lv_screen_active();
|
||||
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_t * snapshot_obj = lv_image_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);
|
||||
lv_image_set_scale(snapshot_obj, 128);
|
||||
lv_image_set_rotation(snapshot_obj, 300);
|
||||
|
||||
/*Create the container and its children*/
|
||||
lv_obj_t * container = lv_obj_create(root);
|
||||
@@ -44,11 +44,11 @@ void lv_example_snapshot_1(void)
|
||||
lv_obj_t * img;
|
||||
int i;
|
||||
for(i = 0; i < 4; i++) {
|
||||
img = lv_img_create(container);
|
||||
lv_img_set_src(img, &img_star);
|
||||
img = lv_image_create(container);
|
||||
lv_image_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_set_style_transform_scale(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);
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
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