Update lvgl to v8.4.0
This commit is contained in:
@@ -45,7 +45,6 @@ typedef struct {
|
||||
uint32_t grow_dsc_calc : 1;
|
||||
} track_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
@@ -72,7 +71,6 @@ lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE;
|
||||
lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE;
|
||||
lv_style_prop_t LV_STYLE_FLEX_GROW;
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
@@ -97,6 +95,7 @@ void lv_flex_init(void)
|
||||
LV_STYLE_FLEX_MAIN_PLACE = lv_style_register_prop(LV_STYLE_PROP_LAYOUT_REFR);
|
||||
LV_STYLE_FLEX_CROSS_PLACE = lv_style_register_prop(LV_STYLE_PROP_LAYOUT_REFR);
|
||||
LV_STYLE_FLEX_TRACK_PLACE = lv_style_register_prop(LV_STYLE_PROP_LAYOUT_REFR);
|
||||
LV_STYLE_FLEX_GROW = lv_style_register_prop(LV_STYLE_PROP_LAYOUT_REFR);
|
||||
}
|
||||
|
||||
void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow)
|
||||
@@ -120,7 +119,6 @@ void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow)
|
||||
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
|
||||
}
|
||||
|
||||
|
||||
void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
@@ -161,7 +159,6 @@ void lv_style_set_flex_grow(lv_style_t * style, uint8_t value)
|
||||
lv_style_set_prop(style, LV_STYLE_FLEX_GROW, v);
|
||||
}
|
||||
|
||||
|
||||
void lv_obj_set_style_flex_flow(lv_obj_t * obj, lv_flex_flow_t value, lv_style_selector_t selector)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
@@ -370,7 +367,6 @@ static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id
|
||||
t->track_fix_main_size += item_size + item_gap;
|
||||
}
|
||||
|
||||
|
||||
t->track_cross_size = LV_MAX(get_cross_size(item), t->track_cross_size);
|
||||
t->item_cnt++;
|
||||
}
|
||||
@@ -444,7 +440,6 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool rtl = lv_obj_get_style_base_dir(cont, LV_PART_MAIN) == LV_BASE_DIR_RTL ? true : false;
|
||||
|
||||
lv_coord_t main_pos = 0;
|
||||
@@ -470,8 +465,14 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i
|
||||
}
|
||||
}
|
||||
|
||||
if(f->row) item->w_layout = 1;
|
||||
else item->h_layout = 1;
|
||||
if(f->row) {
|
||||
item->w_layout = 1;
|
||||
item->h_layout = 0;
|
||||
}
|
||||
else {
|
||||
item->h_layout = 1;
|
||||
item->w_layout = 0;
|
||||
}
|
||||
|
||||
if(s != area_get_main_size(&item->coords)) {
|
||||
lv_obj_invalidate(item);
|
||||
@@ -505,7 +506,6 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i
|
||||
|
||||
if(f->row && rtl) main_pos -= area_get_main_size(&item->coords);
|
||||
|
||||
|
||||
/*Handle percentage value of translate*/
|
||||
lv_coord_t tr_x = lv_obj_get_style_translate_x(item, LV_PART_MAIN);
|
||||
lv_coord_t tr_y = lv_obj_get_style_translate_y(item, LV_PART_MAIN);
|
||||
|
||||
@@ -139,7 +139,6 @@ static inline uint8_t lv_obj_get_style_flex_grow(const lv_obj_t * obj, uint32_t
|
||||
return (uint8_t)v.num;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -40,7 +40,6 @@ typedef struct {
|
||||
lv_coord_t grid_h;
|
||||
} _lv_grid_calc_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
@@ -126,7 +125,6 @@ lv_style_prop_t LV_STYLE_GRID_CELL_Y_ALIGN;
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
void lv_grid_init(void)
|
||||
{
|
||||
LV_LAYOUT_GRID = lv_layout_register(grid_update, NULL);
|
||||
@@ -172,7 +170,6 @@ void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t x_align, uint8_t col_p
|
||||
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
|
||||
}
|
||||
|
||||
|
||||
void lv_style_set_grid_row_dsc_array(lv_style_t * style, const lv_coord_t value[])
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
@@ -205,7 +202,6 @@ void lv_style_set_grid_column_align(lv_style_t * style, lv_grid_align_t value)
|
||||
lv_style_set_prop(style, LV_STYLE_GRID_COLUMN_ALIGN, v);
|
||||
}
|
||||
|
||||
|
||||
void lv_style_set_grid_cell_column_pos(lv_style_t * style, lv_coord_t value)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
@@ -270,7 +266,6 @@ void lv_obj_set_style_grid_column_dsc_array(lv_obj_t * obj, const lv_coord_t val
|
||||
lv_obj_set_local_style_prop(obj, LV_STYLE_GRID_COLUMN_DSC_ARRAY, v, selector);
|
||||
}
|
||||
|
||||
|
||||
void lv_obj_set_style_grid_row_align(lv_obj_t * obj, lv_grid_align_t value, lv_style_selector_t selector)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
@@ -287,7 +282,6 @@ void lv_obj_set_style_grid_column_align(lv_obj_t * obj, lv_grid_align_t value, l
|
||||
lv_obj_set_local_style_prop(obj, LV_STYLE_GRID_COLUMN_ALIGN, v, selector);
|
||||
}
|
||||
|
||||
|
||||
void lv_obj_set_style_grid_cell_column_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector)
|
||||
{
|
||||
lv_style_value_t v = {
|
||||
@@ -336,7 +330,6 @@ void lv_obj_set_style_grid_cell_y_align(lv_obj_t * obj, lv_coord_t value, lv_sty
|
||||
lv_obj_set_local_style_prop(obj, LV_STYLE_GRID_CELL_Y_ALIGN, v, selector);
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -548,7 +541,6 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN);
|
||||
lv_coord_t cont_h = lv_obj_get_content_height(cont) - row_gap * (c->row_num - 1);
|
||||
lv_coord_t free_h = cont_h - grid_h;
|
||||
@@ -561,6 +553,8 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c)
|
||||
if(IS_FR(x)) {
|
||||
lv_coord_t f = GET_FR(x);
|
||||
c->h[i] = (free_h * f) / row_fr_cnt;
|
||||
last_fr_i = i;
|
||||
last_fr_x = f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +583,6 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t *
|
||||
lv_grid_align_t col_align = get_cell_col_align(item);
|
||||
lv_grid_align_t row_align = get_cell_row_align(item);
|
||||
|
||||
|
||||
lv_coord_t col_x1 = c->x[col_pos];
|
||||
lv_coord_t col_x2 = c->x[col_pos + col_span - 1] + c->w[col_pos + col_span - 1];
|
||||
lv_coord_t col_w = col_x2 - col_x1;
|
||||
@@ -598,7 +591,6 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t *
|
||||
lv_coord_t row_y2 = c->y[row_pos + row_span - 1] + c->h[row_pos + row_span - 1];
|
||||
lv_coord_t row_h = row_y2 - row_y1;
|
||||
|
||||
|
||||
/*If the item has RTL base dir switch start and end*/
|
||||
if(lv_obj_get_style_base_dir(item, LV_PART_MAIN) == LV_BASE_DIR_RTL) {
|
||||
if(col_align == LV_GRID_ALIGN_START) col_align = LV_GRID_ALIGN_END;
|
||||
@@ -776,5 +768,4 @@ static uint32_t count_tracks(const lv_coord_t * templ)
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
#endif /*LV_USE_GRID*/
|
||||
|
||||
@@ -34,7 +34,6 @@ typedef struct {
|
||||
static lv_res_t decoder_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header);
|
||||
static lv_res_t decoder_open(lv_img_decoder_t * dec, lv_img_decoder_dsc_t * dsc);
|
||||
|
||||
|
||||
static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc,
|
||||
lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
|
||||
|
||||
@@ -114,7 +113,6 @@ static lv_res_t decoder_info(lv_img_decoder_t * decoder, const void * src, lv_im
|
||||
return LV_RES_INV; /*If didn't succeeded earlier then it's an error*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open a PNG image and return the decided image
|
||||
* @param src can be file name or pointer to a C array
|
||||
@@ -190,7 +188,6 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
|
||||
return LV_RES_INV; /*If not returned earlier then it failed*/
|
||||
}
|
||||
|
||||
|
||||
static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc,
|
||||
lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
||||
{
|
||||
@@ -203,7 +200,14 @@ static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc
|
||||
lv_fs_seek(&b->f, p, LV_FS_SEEK_SET);
|
||||
lv_fs_read(&b->f, buf, len * (b->bpp / 8), NULL);
|
||||
|
||||
#if LV_COLOR_DEPTH == 32
|
||||
#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 1
|
||||
for(unsigned int i = 0; i < len * (b->bpp / 8); i += 2) {
|
||||
buf[i] = buf[i] ^ buf[i + 1];
|
||||
buf[i + 1] = buf[i] ^ buf[i + 1];
|
||||
buf[i] = buf[i] ^ buf[i + 1];
|
||||
}
|
||||
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
if(b->bpp == 32) {
|
||||
lv_coord_t i;
|
||||
for(i = 0; i < len; i++) {
|
||||
@@ -235,7 +239,6 @@ static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Free the allocated resources
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,332 @@
|
||||
/**
|
||||
* @file lv_fs_littlefs.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../../lvgl.h"
|
||||
|
||||
#if LV_USE_FS_LITTLEFS
|
||||
#include "lfs.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
#if LV_FS_LITTLEFS_LETTER == '\0'
|
||||
#error "LV_FS_LITTLEFS_LETTER must be an upper case ASCII letter"
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
static void fs_init(void);
|
||||
|
||||
static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode);
|
||||
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p);
|
||||
|
||||
static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br);
|
||||
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
|
||||
|
||||
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence);
|
||||
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
|
||||
|
||||
static void * fs_dir_open(lv_fs_drv_t * drv, const char * path);
|
||||
static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn);
|
||||
static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void lv_fs_littlefs_init(void)
|
||||
{
|
||||
/*----------------------------------------------------
|
||||
* Initialize your storage device and File System
|
||||
* -------------------------------------------------*/
|
||||
fs_init();
|
||||
|
||||
/*---------------------------------------------------
|
||||
* Register the file system interface in LVGL
|
||||
*--------------------------------------------------*/
|
||||
|
||||
/*Add a simple drive to open images*/
|
||||
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
/*Set up fields...*/
|
||||
fs_drv.letter = LV_FS_LITTLEFS_LETTER;
|
||||
fs_drv.cache_size = LV_FS_LITTLEFS_CACHE_SIZE;
|
||||
|
||||
fs_drv.open_cb = fs_open;
|
||||
fs_drv.close_cb = fs_close;
|
||||
fs_drv.read_cb = fs_read;
|
||||
fs_drv.write_cb = fs_write;
|
||||
fs_drv.seek_cb = fs_seek;
|
||||
fs_drv.tell_cb = fs_tell;
|
||||
|
||||
fs_drv.dir_open_cb = fs_dir_open;
|
||||
fs_drv.dir_close_cb = fs_dir_close;
|
||||
fs_drv.dir_read_cb = fs_dir_read;
|
||||
|
||||
/*#if LV_USE_USER_DATA*/
|
||||
fs_drv.user_data = NULL;
|
||||
/*#endif*/
|
||||
|
||||
lv_fs_drv_register(&fs_drv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to attach registered driver to lfs_t structure by driver-label
|
||||
* @param label the label assigned to the driver when it was registered
|
||||
* @param lfs_p the pointer to the lfs_t structure initialized by external code/library
|
||||
* @return pointer to a driver descriptor or NULL on error
|
||||
*/
|
||||
lv_fs_drv_t * lv_fs_littlefs_set_driver(char label, void * lfs_p)
|
||||
{
|
||||
lv_fs_drv_t * drv_p = lv_fs_get_drv(label);
|
||||
if(drv_p != NULL) drv_p->user_data = (lfs_t *) lfs_p;
|
||||
return drv_p;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/*Initialize your Storage device and File system.*/
|
||||
static void fs_init(void)
|
||||
{
|
||||
/* Initialize the internal flash or SD-card and LittleFS itself.
|
||||
* Better to do it in your code to keep this library untouched for easy updating */
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
|
||||
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
|
||||
* @return pointer to a file descriptor or NULL on error
|
||||
*/
|
||||
static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
uint32_t flags = 0;
|
||||
|
||||
flags = mode == LV_FS_MODE_RD ? LFS_O_RDONLY
|
||||
: mode == LV_FS_MODE_WR ? LFS_O_WRONLY
|
||||
: mode == (LV_FS_MODE_WR | LV_FS_MODE_RD) ? LFS_O_RDWR : 0;
|
||||
|
||||
lfs_file_t * file_p = lv_mem_alloc(sizeof(lfs_file_t));
|
||||
if(file_p == NULL) return NULL;
|
||||
|
||||
int result = lfs_file_open(lfs_p, file_p, path, flags);
|
||||
|
||||
if(result != LFS_ERR_OK) {
|
||||
lv_mem_free(file_p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return file_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an opened file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable. (opened with fs_open)
|
||||
* @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
|
||||
int result = lfs_file_close(lfs_p, file_p);
|
||||
lv_mem_free(file_p);
|
||||
/*lv_mem_free( lfs_p );*/ /*allocated and freed by outside-code*/
|
||||
|
||||
if(result != LFS_ERR_OK) return LV_FS_RES_UNKNOWN;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from an opened file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable.
|
||||
* @param buf pointer to a memory block where to store the read data
|
||||
* @param btr number of Bytes To Read
|
||||
* @param br the real number of read bytes (Byte Read)
|
||||
* @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
|
||||
lfs_ssize_t result = lfs_file_read(lfs_p, file_p, buf, btr);
|
||||
if(result < 0) return LV_FS_RES_UNKNOWN;
|
||||
|
||||
*br = (uint32_t) result;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into a file
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable
|
||||
* @param buf pointer to a buffer with the bytes to write
|
||||
* @param btw Bytes To Write
|
||||
* @param bw the number of real written bytes (Bytes Written). NULL if unused.
|
||||
* @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
|
||||
{
|
||||
#ifndef LFS_READONLY
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
|
||||
lfs_ssize_t result = lfs_file_write(lfs_p, file_p, buf, btw);
|
||||
if(result < 0 || lfs_file_sync(lfs_p, file_p) < 0) return LV_FS_RES_UNKNOWN;
|
||||
|
||||
*bw = (uint32_t) result;
|
||||
return LV_FS_RES_OK;
|
||||
#else
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the read write pointer. Also expand the file size if necessary.
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable. (opened with fs_open )
|
||||
* @param pos the new position of read write pointer
|
||||
* @param whence tells from where to interpret the `pos`. See @lv_fs_whence_t
|
||||
* @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
|
||||
int lfs_whence = whence == LV_FS_SEEK_SET ? LFS_SEEK_SET
|
||||
: whence == LV_FS_SEEK_CUR ? LFS_SEEK_CUR
|
||||
: whence == LV_FS_SEEK_END ? LFS_SEEK_END : 0;
|
||||
|
||||
lfs_soff_t result = lfs_file_seek(lfs_p, file_p, pos, lfs_whence);
|
||||
if(result < 0) return LV_FS_RES_UNKNOWN;
|
||||
|
||||
/*pos = result;*/ /*not supported by lv_fs*/
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the position of the read write pointer
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param file_p pointer to a file_t variable.
|
||||
* @param pos_p pointer to where to store the result
|
||||
* @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
|
||||
lfs_soff_t result = lfs_file_tell(lfs_p, file_p);
|
||||
if(result < 0) return LV_FS_RES_UNKNOWN;
|
||||
|
||||
*pos_p = (uint32_t) result;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a 'lv_fs_dir_t' variable for directory reading
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param path path to a directory
|
||||
* @return pointer to the directory read descriptor or NULL on error
|
||||
*/
|
||||
static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
|
||||
lfs_dir_t * dir_p = lv_mem_alloc(sizeof(lfs_dir_t));
|
||||
if(dir_p == NULL) return NULL;
|
||||
|
||||
int result = lfs_dir_open(lfs_p, dir_p, path);
|
||||
if(result != LFS_ERR_OK) {
|
||||
lv_mem_free(dir_p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dir_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next filename form a directory.
|
||||
* The name of the directories will begin with '/'
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param rddir_p pointer to an initialized 'lv_fs_dir_t' variable
|
||||
* @param fn pointer to a buffer to store the filename
|
||||
* @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * rddir_p, char * fn)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
struct lfs_info info;
|
||||
int result;
|
||||
|
||||
info.name[0] = '\0';
|
||||
|
||||
do {
|
||||
result = lfs_dir_read(lfs_p, rddir_p, &info);
|
||||
if(result > 0) {
|
||||
if(info.type == LFS_TYPE_DIR) {
|
||||
fn[0] = '/';
|
||||
strcpy(&fn[1], info.name);
|
||||
}
|
||||
else strcpy(fn, info.name);
|
||||
}
|
||||
else if(result == 0) fn[0] = '\0'; /*dir-scan ended*/
|
||||
else return LV_FS_RES_UNKNOWN;
|
||||
|
||||
} while(!strcmp(fn, "/.") || !strcmp(fn, "/.."));
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the directory reading
|
||||
* @param drv pointer to a driver where this function belongs
|
||||
* @param rddir_p pointer to an initialized 'lv_fs_dir_t' variable
|
||||
* @return LV_FS_RES_OK: no error or any error from @lv_fs_res_t enum
|
||||
*/
|
||||
static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * rddir_p)
|
||||
{
|
||||
lfs_t * lfs_p = drv->user_data;
|
||||
|
||||
int result = lfs_dir_close(lfs_p, rddir_p);
|
||||
lv_mem_free(rddir_p);
|
||||
|
||||
if(result != LFS_ERR_OK) return LV_FS_RES_UNKNOWN;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
#else /*LV_USE_FS_LITTLEFS == 0*/
|
||||
|
||||
#if defined(LV_FS_LITTLEFS_LETTER) && LV_FS_LITTLEFS_LETTER != '\0'
|
||||
#warning "LV_USE_FS_LITTLEFS is not enabled but LV_FS_LITTLEFS_LETTER is set"
|
||||
#endif
|
||||
|
||||
#endif /*LV_USE_FS_POSIX*/
|
||||
@@ -3,7 +3,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
@@ -104,15 +103,15 @@ static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
|
||||
LV_UNUSED(drv);
|
||||
|
||||
uint32_t flags = 0;
|
||||
if(mode == LV_FS_MODE_WR) flags = O_WRONLY;
|
||||
if(mode == LV_FS_MODE_WR) flags = O_WRONLY | O_CREAT;
|
||||
else if(mode == LV_FS_MODE_RD) flags = O_RDONLY;
|
||||
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = O_RDWR;
|
||||
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = O_RDWR | O_CREAT;
|
||||
|
||||
/*Make the path relative to the current directory (the projects root folder)*/
|
||||
char buf[256];
|
||||
lv_snprintf(buf, sizeof(buf), LV_FS_POSIX_PATH "%s", path);
|
||||
|
||||
int f = open(buf, flags);
|
||||
int f = open(buf, flags, 0666);
|
||||
if(f < 0) return NULL;
|
||||
|
||||
return (void *)(lv_uintptr_t)f;
|
||||
@@ -176,8 +175,8 @@ static lv_fs_res_t fs_write(lv_fs_drv_t * drv, void * file_p, const void * buf,
|
||||
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence)
|
||||
{
|
||||
LV_UNUSED(drv);
|
||||
lseek((lv_uintptr_t)file_p, pos, whence);
|
||||
return LV_FS_RES_OK;
|
||||
off_t offset = lseek((lv_uintptr_t)file_p, pos, whence);
|
||||
return offset < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,8 +190,9 @@ static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs
|
||||
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
|
||||
{
|
||||
LV_UNUSED(drv);
|
||||
*pos_p = lseek((lv_uintptr_t)file_p, 0, SEEK_CUR);
|
||||
return LV_FS_RES_OK;
|
||||
off_t offset = lseek((lv_uintptr_t)file_p, 0, SEEK_CUR);
|
||||
*pos_p = offset;
|
||||
return offset < 0 ? LV_FS_RES_FS_ERR : LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
@@ -219,14 +218,14 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
|
||||
return handle;
|
||||
#else
|
||||
handle->dir_p = INVALID_HANDLE_VALUE;
|
||||
WIN32_FIND_DATA fdata;
|
||||
WIN32_FIND_DATAA fdata;
|
||||
|
||||
/*Make the path relative to the current directory (the projects root folder)*/
|
||||
char buf[MAX_PATH_LEN];
|
||||
lv_snprintf(buf, sizeof(buf), LV_FS_STDIO_PATH "%s\\*", path);
|
||||
|
||||
strcpy(handle->next_fn, "");
|
||||
handle->dir_p = FindFirstFile(buf, &fdata);
|
||||
handle->dir_p = FindFirstFileA(buf, &fdata);
|
||||
do {
|
||||
if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
|
||||
continue;
|
||||
@@ -278,9 +277,9 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
|
||||
strcpy(fn, handle->next_fn);
|
||||
|
||||
strcpy(handle->next_fn, "");
|
||||
WIN32_FIND_DATA fdata;
|
||||
WIN32_FIND_DATAA fdata;
|
||||
|
||||
if(FindNextFile(handle->dir_p, &fdata) == false) return LV_FS_RES_OK;
|
||||
if(FindNextFileA(handle->dir_p, &fdata) == false) return LV_FS_RES_OK;
|
||||
do {
|
||||
if(strcmp(fdata.cFileName, ".") == 0 || strcmp(fdata.cFileName, "..") == 0) {
|
||||
continue;
|
||||
@@ -294,7 +293,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while(FindNextFile(handle->dir_p, &fdata));
|
||||
} while(FindNextFileA(handle->dir_p, &fdata));
|
||||
|
||||
#endif
|
||||
return LV_FS_RES_OK;
|
||||
@@ -326,4 +325,3 @@ static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p)
|
||||
#endif
|
||||
|
||||
#endif /*LV_USE_FS_POSIX*/
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
@@ -64,7 +63,7 @@ void lv_fs_win32_init(void)
|
||||
* Register the file system interface in LVGL
|
||||
*--------------------------------------------------*/
|
||||
|
||||
/*Add a simple drive to open images*/
|
||||
/*Add a simple driver to open images*/
|
||||
static lv_fs_drv_t fs_drv; /*A driver descriptor*/
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
@@ -362,7 +361,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
|
||||
dir_handle_t * handle = (dir_handle_t *)lv_mem_alloc(sizeof(dir_handle_t));
|
||||
handle->dir_p = INVALID_HANDLE_VALUE;
|
||||
handle->next_error = LV_FS_RES_OK;
|
||||
WIN32_FIND_DATA fdata;
|
||||
WIN32_FIND_DATAA fdata;
|
||||
|
||||
/*Make the path relative to the current directory (the projects root folder)*/
|
||||
char buf[MAX_PATH_LEN];
|
||||
@@ -373,7 +372,7 @@ static void * fs_dir_open(lv_fs_drv_t * drv, const char * path)
|
||||
#endif
|
||||
|
||||
strcpy(handle->next_fn, "");
|
||||
handle->dir_p = FindFirstFile(buf, &fdata);
|
||||
handle->dir_p = FindFirstFileA(buf, &fdata);
|
||||
do {
|
||||
if(is_dots_name(fdata.cFileName)) {
|
||||
continue;
|
||||
@@ -416,7 +415,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
|
||||
lv_fs_res_t current_error = handle->next_error;
|
||||
strcpy(handle->next_fn, "");
|
||||
|
||||
WIN32_FIND_DATA fdata;
|
||||
WIN32_FIND_DATAA fdata;
|
||||
|
||||
while(FindNextFileA(handle->dir_p, &fdata)) {
|
||||
if(is_dots_name(fdata.cFileName)) {
|
||||
|
||||
@@ -31,6 +31,11 @@ extern "C" {
|
||||
void lv_fs_fatfs_init(void);
|
||||
#endif
|
||||
|
||||
#if LV_USE_FS_LITTLEFS != '\0'
|
||||
void lv_fs_littlefs_init(void);
|
||||
lv_fs_drv_t * lv_fs_littlefs_set_driver(char label, void * lfs_p);
|
||||
#endif
|
||||
|
||||
#if LV_USE_FS_STDIO != '\0'
|
||||
void lv_fs_stdio_init(void);
|
||||
#endif
|
||||
|
||||
@@ -160,6 +160,7 @@ static gd_GIF * gif_open(gd_GIF * gif_base)
|
||||
#endif
|
||||
}
|
||||
gif->anim_start = f_gif_seek(gif, 0, LV_FS_SEEK_CUR);
|
||||
gif->loop_count = -1;
|
||||
goto ok;
|
||||
fail:
|
||||
f_gif_close(gif_base);
|
||||
@@ -239,6 +240,7 @@ read_application_ext(gd_GIF *gif)
|
||||
{
|
||||
char app_id[8];
|
||||
char app_auth_code[3];
|
||||
uint16_t loop_count;
|
||||
|
||||
/* Discard block size (always 0x0B). */
|
||||
f_gif_seek(gif, 1, LV_FS_SEEK_CUR);
|
||||
@@ -249,7 +251,15 @@ read_application_ext(gd_GIF *gif)
|
||||
if (!strncmp(app_id, "NETSCAPE", sizeof(app_id))) {
|
||||
/* Discard block size (0x03) and constant byte (0x01). */
|
||||
f_gif_seek(gif, 2, LV_FS_SEEK_CUR);
|
||||
gif->loop_count = read_num(gif);
|
||||
loop_count = read_num(gif);
|
||||
if(gif->loop_count < 0) {
|
||||
if(loop_count == 0) {
|
||||
gif->loop_count = 0;
|
||||
}
|
||||
else{
|
||||
gif->loop_count = loop_count + 1;
|
||||
}
|
||||
}
|
||||
/* Skip block terminator. */
|
||||
f_gif_seek(gif, 1, LV_FS_SEEK_CUR);
|
||||
} else if (gif->application) {
|
||||
@@ -568,9 +578,16 @@ gd_get_frame(gd_GIF *gif)
|
||||
dispose(gif);
|
||||
f_gif_read(gif, &sep, 1);
|
||||
while (sep != ',') {
|
||||
if (sep == ';')
|
||||
return 0;
|
||||
if (sep == '!')
|
||||
if (sep == ';') {
|
||||
f_gif_seek(gif, gif->anim_start, LV_FS_SEEK_SET);
|
||||
if(gif->loop_count == 1 || gif->loop_count < 0) {
|
||||
return 0;
|
||||
}
|
||||
else if(gif->loop_count > 1) {
|
||||
gif->loop_count--;
|
||||
}
|
||||
}
|
||||
else if (sep == '!')
|
||||
read_ext(gif);
|
||||
else return -1;
|
||||
f_gif_read(gif, &sep, 1);
|
||||
@@ -598,6 +615,7 @@ gd_render_frame(gd_GIF *gif, uint8_t *buffer)
|
||||
void
|
||||
gd_rewind(gd_GIF *gif)
|
||||
{
|
||||
gif->loop_count = -1;
|
||||
f_gif_seek(gif, gif->anim_start, LV_FS_SEEK_SET);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct gd_GIF {
|
||||
int32_t anim_start;
|
||||
uint16_t width, height;
|
||||
uint16_t depth;
|
||||
uint16_t loop_count;
|
||||
int32_t loop_count;
|
||||
gd_GCE gce;
|
||||
gd_Palette *palette;
|
||||
gd_Palette lct, gct;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
@@ -99,6 +98,8 @@ void lv_gif_restart(lv_obj_t * obj)
|
||||
{
|
||||
lv_gif_t * gifobj = (lv_gif_t *) obj;
|
||||
gd_rewind(gifobj->gif);
|
||||
lv_timer_resume(gifobj->timer);
|
||||
lv_timer_reset(gifobj->timer);
|
||||
}
|
||||
|
||||
/**********************
|
||||
@@ -111,6 +112,7 @@ static void lv_gif_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
|
||||
lv_gif_t * gifobj = (lv_gif_t *) obj;
|
||||
|
||||
gifobj->gif = NULL;
|
||||
gifobj->timer = lv_timer_create(next_frame_task_cb, 10, obj);
|
||||
lv_timer_pause(gifobj->timer);
|
||||
}
|
||||
@@ -120,7 +122,8 @@ static void lv_gif_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
LV_UNUSED(class_p);
|
||||
lv_gif_t * gifobj = (lv_gif_t *) obj;
|
||||
lv_img_cache_invalidate_src(&gifobj->imgdsc);
|
||||
gd_close_gif(gifobj->gif);
|
||||
if(gifobj->gif)
|
||||
gd_close_gif(gifobj->gif);
|
||||
lv_timer_del(gifobj->timer);
|
||||
}
|
||||
|
||||
@@ -136,14 +139,9 @@ static void next_frame_task_cb(lv_timer_t * t)
|
||||
int has_next = gd_get_frame(gifobj->gif);
|
||||
if(has_next == 0) {
|
||||
/*It was the last repeat*/
|
||||
if(gifobj->gif->loop_count == 1) {
|
||||
lv_res_t res = lv_event_send(obj, LV_EVENT_READY, NULL);
|
||||
if(res != LV_FS_RES_OK) return;
|
||||
}
|
||||
else {
|
||||
if(gifobj->gif->loop_count > 1) gifobj->gif->loop_count--;
|
||||
gd_rewind(gifobj->gif);
|
||||
}
|
||||
lv_res_t res = lv_event_send(obj, LV_EVENT_READY, NULL);
|
||||
lv_timer_pause(t);
|
||||
if(res != LV_FS_RES_OK) return;
|
||||
}
|
||||
|
||||
gd_render_frame(gifobj->gif, (uint8_t *)gifobj->imgdsc.data);
|
||||
|
||||
@@ -22,6 +22,7 @@ extern "C" {
|
||||
#include "freetype/lv_freetype.h"
|
||||
#include "rlottie/lv_rlottie.h"
|
||||
#include "ffmpeg/lv_ffmpeg.h"
|
||||
#include "tiny_ttf/lv_tiny_ttf.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
|
||||
@@ -5754,7 +5754,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
|
||||
adam7 = (unsigned char*)lodepng_malloc(passstart[7]);
|
||||
if(!adam7 && passstart[7]) error = 83; /*alloc fail*/
|
||||
|
||||
if(!error) {
|
||||
if(!error && adam7) {
|
||||
unsigned i;
|
||||
|
||||
Adam7_interlace(adam7, in, w, h, bpp);
|
||||
|
||||
@@ -103,20 +103,39 @@ static lv_res_t decoder_info(struct _lv_img_decoder_t * decoder, const void * sr
|
||||
else if(src_type == LV_IMG_SRC_VARIABLE) {
|
||||
const lv_img_dsc_t * img_dsc = src;
|
||||
const uint32_t data_size = img_dsc->data_size;
|
||||
const uint32_t * size = ((uint32_t *)img_dsc->data) + 4;
|
||||
const uint8_t magic[] = {0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a};
|
||||
if(data_size < sizeof(magic)) return LV_RES_INV;
|
||||
if(memcmp(magic, img_dsc->data, sizeof(magic))) return LV_RES_INV;
|
||||
header->always_zero = 0;
|
||||
header->cf = img_dsc->header.cf; /*Save the color format*/
|
||||
header->w = img_dsc->header.w; /*Save the color width*/
|
||||
header->h = img_dsc->header.h; /*Save the color height*/
|
||||
|
||||
if(img_dsc->header.cf) {
|
||||
header->cf = img_dsc->header.cf; /*Save the color format*/
|
||||
}
|
||||
else {
|
||||
header->cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
|
||||
}
|
||||
|
||||
if(img_dsc->header.w) {
|
||||
header->w = img_dsc->header.w; /*Save the image width*/
|
||||
}
|
||||
else {
|
||||
header->w = (lv_coord_t)((size[0] & 0xff000000) >> 24) + ((size[0] & 0x00ff0000) >> 8);
|
||||
}
|
||||
|
||||
if(img_dsc->header.h) {
|
||||
header->h = img_dsc->header.h; /*Save the color height*/
|
||||
}
|
||||
else {
|
||||
header->h = (lv_coord_t)((size[1] & 0xff000000) >> 24) + ((size[1] & 0x00ff0000) >> 8);
|
||||
}
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
return LV_RES_INV; /*If didn't succeeded earlier then it's an error*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open a PNG image and return the decided image
|
||||
* @param src can be file name or pointer to a C array
|
||||
@@ -142,13 +161,13 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
|
||||
|
||||
error = lodepng_load_file(&png_data, &png_data_size, fn); /*Load the file*/
|
||||
if(error) {
|
||||
LV_LOG_WARN("error %u: %s\n", error, lodepng_error_text(error));
|
||||
LV_LOG_WARN("error %" LV_PRIu32 ": %s\n", error, lodepng_error_text(error));
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
/*Decode the PNG image*/
|
||||
uint32_t png_width; /*Will be the width of the decoded image*/
|
||||
uint32_t png_height; /*Will be the width of the decoded image*/
|
||||
unsigned png_width; /*Will be the width of the decoded image*/
|
||||
unsigned png_height; /*Will be the width of the decoded image*/
|
||||
|
||||
/*Decode the loaded image in ARGB8888 */
|
||||
error = lodepng_decode32(&img_data, &png_width, &png_height, png_data, png_data_size);
|
||||
@@ -157,7 +176,7 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
|
||||
if(img_data != NULL) {
|
||||
lv_mem_free(img_data);
|
||||
}
|
||||
LV_LOG_WARN("error %u: %s\n", error, lodepng_error_text(error));
|
||||
LV_LOG_WARN("error %" LV_PRIu32 ": %s\n", error, lodepng_error_text(error));
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
@@ -170,8 +189,8 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
|
||||
/*If it's a PNG file in a C array...*/
|
||||
else if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
|
||||
const lv_img_dsc_t * img_dsc = dsc->src;
|
||||
uint32_t png_width; /*No used, just required by he decoder*/
|
||||
uint32_t png_height; /*No used, just required by he decoder*/
|
||||
unsigned png_width; /*No used, just required by he decoder*/
|
||||
unsigned png_height; /*No used, just required by he decoder*/
|
||||
|
||||
/*Decode the image in ARGB8888 */
|
||||
error = lodepng_decode32(&img_data, &png_width, &png_height, img_dsc->data, img_dsc->data_size);
|
||||
@@ -254,5 +273,3 @@ static void convert_color_depth(uint8_t * img, uint32_t px_cnt)
|
||||
}
|
||||
|
||||
#endif /*LV_USE_PNG*/
|
||||
|
||||
|
||||
|
||||
@@ -178,7 +178,6 @@ lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_le
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
void lv_qrcode_delete(lv_obj_t * qrcode)
|
||||
{
|
||||
lv_obj_del(qrcode);
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
* Software.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "qrcodegen.h"
|
||||
#include "../../../misc/lv_assert.h"
|
||||
|
||||
#ifndef QRCODEGEN_TEST
|
||||
#define testable static // Keep functions private
|
||||
@@ -127,12 +127,12 @@ static const int PENALTY_N4 = 10;
|
||||
// Public function - see documentation comment in header file.
|
||||
bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) {
|
||||
|
||||
|
||||
size_t textLen = strlen(text);
|
||||
if (textLen == 0)
|
||||
return qrcodegen_encodeSegmentsAdvanced(NULL, 0, ecl, minVersion, maxVersion, mask, boostEcl, tempBuffer, qrcode);
|
||||
size_t bufLen = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion);
|
||||
|
||||
|
||||
struct qrcodegen_Segment seg;
|
||||
if (qrcodegen_isNumeric(text)) {
|
||||
if (qrcodegen_calcSegmentBufferSize(qrcodegen_Mode_NUMERIC, textLen) > bufLen)
|
||||
@@ -155,7 +155,7 @@ bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode
|
||||
seg.data = tempBuffer;
|
||||
}
|
||||
return qrcodegen_encodeSegmentsAdvanced(&seg, 1, ecl, minVersion, maxVersion, mask, boostEcl, tempBuffer, qrcode);
|
||||
|
||||
|
||||
fail:
|
||||
qrcode[0] = 0; // Set size to invalid value for safety
|
||||
return false;
|
||||
@@ -165,7 +165,7 @@ fail:
|
||||
// Public function - see documentation comment in header file.
|
||||
bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[],
|
||||
enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) {
|
||||
|
||||
|
||||
struct qrcodegen_Segment seg;
|
||||
seg.mode = qrcodegen_Mode_BYTE;
|
||||
seg.bitLength = calcSegmentBitLength(seg.mode, dataLen);
|
||||
@@ -182,7 +182,7 @@ bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcod
|
||||
// Appends the given number of low-order bits of the given value to the given byte-based
|
||||
// bit buffer, increasing the bit length. Requires 0 <= numBits <= 16 and val < 2^numBits.
|
||||
testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen) {
|
||||
assert(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0);
|
||||
LV_ASSERT(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0);
|
||||
for (int i = numBits - 1; i >= 0; i--, (*bitLen)++)
|
||||
buffer[*bitLen >> 3] |= ((val >> i) & 1) << (7 - (*bitLen & 7));
|
||||
}
|
||||
@@ -202,10 +202,10 @@ bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len,
|
||||
// Public function - see documentation comment in header file.
|
||||
bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl,
|
||||
int minVersion, int maxVersion, int mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]) {
|
||||
assert(segs != NULL || len == 0);
|
||||
assert(qrcodegen_VERSION_MIN <= minVersion && minVersion <= maxVersion && maxVersion <= qrcodegen_VERSION_MAX);
|
||||
assert(0 <= (int)ecl && (int)ecl <= 3 && -1 <= (int)mask && (int)mask <= 7);
|
||||
|
||||
LV_ASSERT(segs != NULL || len == 0);
|
||||
LV_ASSERT(qrcodegen_VERSION_MIN <= minVersion && minVersion <= maxVersion && maxVersion <= qrcodegen_VERSION_MAX);
|
||||
LV_ASSERT(0 <= (int)ecl && (int)ecl <= 3 && -1 <= (int)mask && (int)mask <= 7);
|
||||
|
||||
// Find the minimal version number to use
|
||||
int version, dataUsedBits;
|
||||
for (version = minVersion; ; version++) {
|
||||
@@ -218,14 +218,14 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
|
||||
return false;
|
||||
}
|
||||
}
|
||||
assert(dataUsedBits != -1);
|
||||
|
||||
LV_ASSERT(dataUsedBits != -1);
|
||||
|
||||
// Increase the error correction level while the data still fits in the current version number
|
||||
for (int i = (int)qrcodegen_Ecc_MEDIUM; i <= (int)qrcodegen_Ecc_HIGH; i++) { // From low to high
|
||||
if (boostEcl && dataUsedBits <= getNumDataCodewords(version, (enum qrcodegen_Ecc)i) * 8)
|
||||
ecl = (enum qrcodegen_Ecc)i;
|
||||
}
|
||||
|
||||
|
||||
// Concatenate all segments to create the data bit string
|
||||
memset(qrcode, 0, qrcodegen_BUFFER_LEN_FOR_VERSION(version) * sizeof(qrcode[0]));
|
||||
int bitLen = 0;
|
||||
@@ -236,29 +236,29 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
|
||||
for (int j = 0; j < seg->bitLength; j++)
|
||||
appendBitsToBuffer((seg->data[j >> 3] >> (7 - (j & 7))) & 1, 1, qrcode, &bitLen);
|
||||
}
|
||||
assert(bitLen == dataUsedBits);
|
||||
|
||||
LV_ASSERT(bitLen == dataUsedBits);
|
||||
|
||||
// Add terminator and pad up to a byte if applicable
|
||||
int dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
|
||||
assert(bitLen <= dataCapacityBits);
|
||||
LV_ASSERT(bitLen <= dataCapacityBits);
|
||||
int terminatorBits = dataCapacityBits - bitLen;
|
||||
if (terminatorBits > 4)
|
||||
terminatorBits = 4;
|
||||
appendBitsToBuffer(0, terminatorBits, qrcode, &bitLen);
|
||||
appendBitsToBuffer(0, (8 - bitLen % 8) % 8, qrcode, &bitLen);
|
||||
assert(bitLen % 8 == 0);
|
||||
|
||||
LV_ASSERT(bitLen % 8 == 0);
|
||||
|
||||
// Pad with alternating bytes until data capacity is reached
|
||||
for (uint8_t padByte = 0xEC; bitLen < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
|
||||
appendBitsToBuffer(padByte, 8, qrcode, &bitLen);
|
||||
|
||||
|
||||
// Draw function and data codeword modules
|
||||
addEccAndInterleave(qrcode, version, ecl, tempBuffer);
|
||||
initializeFunctionModules(version, qrcode);
|
||||
drawCodewords(tempBuffer, getNumRawDataModules(version) / 8, qrcode);
|
||||
drawWhiteFunctionModules(qrcode, version);
|
||||
initializeFunctionModules(version, tempBuffer);
|
||||
|
||||
|
||||
// Handle masking
|
||||
if (mask == qrcodegen_Mask_AUTO) { // Automatically choose best mask
|
||||
long minPenalty = LONG_MAX;
|
||||
@@ -274,7 +274,7 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
|
||||
applyMask(tempBuffer, qrcode, msk); // Undoes the mask due to XOR
|
||||
}
|
||||
}
|
||||
assert(0 <= (int)mask && (int)mask <= 7);
|
||||
LV_ASSERT(0 <= (int)mask && (int)mask <= 7);
|
||||
applyMask(tempBuffer, qrcode, mask);
|
||||
drawFormatBits(ecl, mask, qrcode);
|
||||
return true;
|
||||
@@ -290,14 +290,14 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
|
||||
// be clobbered by this function. The final answer is stored in result[0 : rawCodewords].
|
||||
testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ecc ecl, uint8_t result[]) {
|
||||
// Calculate parameter numbers
|
||||
assert(0 <= (int)ecl && (int)ecl < 4 && qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX);
|
||||
LV_ASSERT(0 <= (int)ecl && (int)ecl < 4 && qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX);
|
||||
int numBlocks = NUM_ERROR_CORRECTION_BLOCKS[(int)ecl][version];
|
||||
int blockEccLen = ECC_CODEWORDS_PER_BLOCK [(int)ecl][version];
|
||||
int rawCodewords = getNumRawDataModules(version) / 8;
|
||||
int dataLen = getNumDataCodewords(version, ecl);
|
||||
int numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
||||
int shortBlockDataLen = rawCodewords / numBlocks - blockEccLen;
|
||||
|
||||
|
||||
// Split data into blocks, calculate ECC, and interleave
|
||||
// (not concatenate) the bytes into a single sequence
|
||||
uint8_t generator[qrcodegen_REED_SOLOMON_DEGREE_MAX];
|
||||
@@ -323,7 +323,7 @@ testable void addEccAndInterleave(uint8_t data[], int version, enum qrcodegen_Ec
|
||||
// for the given version number and error correction level. The result is in the range [9, 2956].
|
||||
testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl) {
|
||||
int v = version, e = (int)ecl;
|
||||
assert(0 <= e && e < 4);
|
||||
LV_ASSERT(0 <= e && e < 4);
|
||||
return getNumRawDataModules(v) / 8
|
||||
- ECC_CODEWORDS_PER_BLOCK [e][v]
|
||||
* NUM_ERROR_CORRECTION_BLOCKS[e][v];
|
||||
@@ -334,7 +334,7 @@ testable int getNumDataCodewords(int version, enum qrcodegen_Ecc ecl) {
|
||||
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
||||
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
||||
testable int getNumRawDataModules(int ver) {
|
||||
assert(qrcodegen_VERSION_MIN <= ver && ver <= qrcodegen_VERSION_MAX);
|
||||
LV_ASSERT(qrcodegen_VERSION_MIN <= ver && ver <= qrcodegen_VERSION_MAX);
|
||||
int result = (16 * ver + 128) * ver + 64;
|
||||
if (ver >= 2) {
|
||||
int numAlign = ver / 7 + 2;
|
||||
@@ -352,10 +352,10 @@ testable int getNumRawDataModules(int ver) {
|
||||
// Calculates the Reed-Solomon generator polynomial of the given degree, storing in result[0 : degree].
|
||||
testable void calcReedSolomonGenerator(int degree, uint8_t result[]) {
|
||||
// Start with the monomial x^0
|
||||
assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX);
|
||||
LV_ASSERT(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX);
|
||||
memset(result, 0, degree * sizeof(result[0]));
|
||||
result[degree - 1] = 1;
|
||||
|
||||
|
||||
// Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
|
||||
// drop the highest term, and store the rest of the coefficients in order of descending powers.
|
||||
// Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
|
||||
@@ -376,9 +376,9 @@ testable void calcReedSolomonGenerator(int degree, uint8_t result[]) {
|
||||
// polynomials are in big endian and the generator has an implicit leading 1 term, storing the result in result[0 : degree].
|
||||
testable void calcReedSolomonRemainder(const uint8_t data[], int dataLen,
|
||||
const uint8_t generator[], int degree, uint8_t result[]) {
|
||||
|
||||
|
||||
// Perform polynomial division
|
||||
assert(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX);
|
||||
LV_ASSERT(1 <= degree && degree <= qrcodegen_REED_SOLOMON_DEGREE_MAX);
|
||||
memset(result, 0, degree * sizeof(result[0]));
|
||||
for (int i = 0; i < dataLen; i++) {
|
||||
uint8_t factor = data[i] ^ result[0];
|
||||
@@ -415,16 +415,16 @@ testable void initializeFunctionModules(int version, uint8_t qrcode[]) {
|
||||
int qrsize = version * 4 + 17;
|
||||
memset(qrcode, 0, ((qrsize * qrsize + 7) / 8 + 1) * sizeof(qrcode[0]));
|
||||
qrcode[0] = (uint8_t)qrsize;
|
||||
|
||||
|
||||
// Fill horizontal and vertical timing patterns
|
||||
fillRectangle(6, 0, 1, qrsize, qrcode);
|
||||
fillRectangle(0, 6, qrsize, 1, qrcode);
|
||||
|
||||
|
||||
// Fill 3 finder patterns (all corners except bottom right) and format bits
|
||||
fillRectangle(0, 0, 9, 9, qrcode);
|
||||
fillRectangle(qrsize - 8, 0, 8, 9, qrcode);
|
||||
fillRectangle(0, qrsize - 8, 9, 8, qrcode);
|
||||
|
||||
|
||||
// Fill numerous alignment patterns
|
||||
uint8_t alignPatPos[7];
|
||||
int numAlign = getAlignmentPatternPositions(version, alignPatPos);
|
||||
@@ -435,7 +435,7 @@ testable void initializeFunctionModules(int version, uint8_t qrcode[]) {
|
||||
fillRectangle(alignPatPos[i] - 2, alignPatPos[j] - 2, 5, 5, qrcode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fill version blocks
|
||||
if (version >= 7) {
|
||||
fillRectangle(qrsize - 11, 0, 3, 6, qrcode);
|
||||
@@ -454,7 +454,7 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) {
|
||||
setModule(qrcode, 6, i, false);
|
||||
setModule(qrcode, i, 6, false);
|
||||
}
|
||||
|
||||
|
||||
// Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
|
||||
for (int dy = -4; dy <= 4; dy++) {
|
||||
for (int dx = -4; dx <= 4; dx++) {
|
||||
@@ -468,7 +468,7 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Draw numerous alignment patterns
|
||||
uint8_t alignPatPos[7];
|
||||
int numAlign = getAlignmentPatternPositions(version, alignPatPos);
|
||||
@@ -482,7 +482,7 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Draw version blocks
|
||||
if (version >= 7) {
|
||||
// Calculate error correction code and pack bits
|
||||
@@ -490,8 +490,8 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) {
|
||||
for (int i = 0; i < 12; i++)
|
||||
rem = (rem << 1) ^ ((rem >> 11) * 0x1F25);
|
||||
long bits = (long)version << 12 | rem; // uint18
|
||||
assert(bits >> 18 == 0);
|
||||
|
||||
LV_ASSERT(bits >> 18 == 0);
|
||||
|
||||
// Draw two copies
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
@@ -510,15 +510,15 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) {
|
||||
// the format bits, unlike drawWhiteFunctionModules() which might skip black modules.
|
||||
static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uint8_t qrcode[]) {
|
||||
// Calculate error correction code and pack bits
|
||||
assert(0 <= (int)mask && (int)mask <= 7);
|
||||
LV_ASSERT(0 <= (int)mask && (int)mask <= 7);
|
||||
static const int table[] = {1, 0, 3, 2};
|
||||
int data = table[(int)ecl] << 3 | (int)mask; // errCorrLvl is uint2, mask is uint3
|
||||
int rem = data;
|
||||
for (int i = 0; i < 10; i++)
|
||||
rem = (rem << 1) ^ ((rem >> 9) * 0x537);
|
||||
int bits = (data << 10 | rem) ^ 0x5412; // uint15
|
||||
assert(bits >> 15 == 0);
|
||||
|
||||
LV_ASSERT(bits >> 15 == 0);
|
||||
|
||||
// Draw first copy
|
||||
for (int i = 0; i <= 5; i++)
|
||||
setModule(qrcode, 8, i, getBit(bits, i));
|
||||
@@ -527,7 +527,7 @@ static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uin
|
||||
setModule(qrcode, 7, 8, getBit(bits, 8));
|
||||
for (int i = 9; i < 15; i++)
|
||||
setModule(qrcode, 14 - i, 8, getBit(bits, i));
|
||||
|
||||
|
||||
// Draw second copy
|
||||
int qrsize = qrcodegen_getSize(qrcode);
|
||||
for (int i = 0; i < 8; i++)
|
||||
@@ -591,7 +591,7 @@ static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(i == dataLen * 8);
|
||||
LV_ASSERT(i == dataLen * 8);
|
||||
}
|
||||
|
||||
|
||||
@@ -601,7 +601,7 @@ static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) {
|
||||
// the same mask value a second time will undo the mask. A final well-formed
|
||||
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
||||
static void applyMask(const uint8_t functionModules[], uint8_t qrcode[], enum qrcodegen_Mask mask) {
|
||||
assert(0 <= (int)mask && (int)mask <= 7); // Disallows qrcodegen_Mask_AUTO
|
||||
LV_ASSERT(0 <= (int)mask && (int)mask <= 7); // Disallows qrcodegen_Mask_AUTO
|
||||
int qrsize = qrcodegen_getSize(qrcode);
|
||||
for (int y = 0; y < qrsize; y++) {
|
||||
for (int x = 0; x < qrsize; x++) {
|
||||
@@ -617,7 +617,7 @@ static void applyMask(const uint8_t functionModules[], uint8_t qrcode[], enum qr
|
||||
case 5: invert = x * y % 2 + x * y % 3 == 0; break;
|
||||
case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break;
|
||||
case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
|
||||
default: assert(false); return;
|
||||
default: LV_ASSERT(false); return;
|
||||
}
|
||||
bool val = getModule(qrcode, x, y);
|
||||
setModule(qrcode, x, y, val ^ invert);
|
||||
@@ -631,7 +631,7 @@ static void applyMask(const uint8_t functionModules[], uint8_t qrcode[], enum qr
|
||||
static long getPenaltyScore(const uint8_t qrcode[]) {
|
||||
int qrsize = qrcodegen_getSize(qrcode);
|
||||
long result = 0;
|
||||
|
||||
|
||||
// Adjacent modules in row having same color, and finder-like patterns
|
||||
for (int y = 0; y < qrsize; y++) {
|
||||
unsigned char runHistory[7] = {0};
|
||||
@@ -684,7 +684,7 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
|
||||
if (hasFinderLikePattern(runHistory))
|
||||
result += PENALTY_N3;
|
||||
}
|
||||
|
||||
|
||||
// 2*2 blocks of modules having same color
|
||||
for (int y = 0; y < qrsize - 1; y++) {
|
||||
for (int x = 0; x < qrsize - 1; x++) {
|
||||
@@ -695,7 +695,7 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
|
||||
result += PENALTY_N2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Balance of black and white modules
|
||||
int black = 0;
|
||||
for (int y = 0; y < qrsize; y++) {
|
||||
@@ -737,9 +737,9 @@ static bool hasFinderLikePattern(const unsigned char runHistory[7]) {
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
int qrcodegen_getSize(const uint8_t qrcode[]) {
|
||||
assert(qrcode != NULL);
|
||||
LV_ASSERT(qrcode != NULL);
|
||||
int result = qrcode[0];
|
||||
assert((qrcodegen_VERSION_MIN * 4 + 17) <= result
|
||||
LV_ASSERT((qrcodegen_VERSION_MIN * 4 + 17) <= result
|
||||
&& result <= (qrcodegen_VERSION_MAX * 4 + 17));
|
||||
return result;
|
||||
}
|
||||
@@ -747,7 +747,7 @@ int qrcodegen_getSize(const uint8_t qrcode[]) {
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y) {
|
||||
assert(qrcode != NULL);
|
||||
LV_ASSERT(qrcode != NULL);
|
||||
int qrsize = qrcode[0];
|
||||
return (0 <= x && x < qrsize && 0 <= y && y < qrsize) && getModule(qrcode, x, y);
|
||||
}
|
||||
@@ -756,7 +756,7 @@ bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y) {
|
||||
// Gets the module at the given coordinates, which must be in bounds.
|
||||
testable bool getModule(const uint8_t qrcode[], int x, int y) {
|
||||
int qrsize = qrcode[0];
|
||||
assert(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize);
|
||||
LV_ASSERT(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize);
|
||||
int index = y * qrsize + x;
|
||||
return getBit(qrcode[(index >> 3) + 1], index & 7);
|
||||
}
|
||||
@@ -765,7 +765,7 @@ testable bool getModule(const uint8_t qrcode[], int x, int y) {
|
||||
// Sets the module at the given coordinates, which must be in bounds.
|
||||
testable void setModule(uint8_t qrcode[], int x, int y, bool isBlack) {
|
||||
int qrsize = qrcode[0];
|
||||
assert(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize);
|
||||
LV_ASSERT(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize);
|
||||
int index = y * qrsize + x;
|
||||
int bitIndex = index & 7;
|
||||
int byteIndex = (index >> 3) + 1;
|
||||
@@ -795,7 +795,7 @@ static bool getBit(int x, int i) {
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
bool qrcodegen_isAlphanumeric(const char *text) {
|
||||
assert(text != NULL);
|
||||
LV_ASSERT(text != NULL);
|
||||
for (; *text != '\0'; text++) {
|
||||
if (strchr(ALPHANUMERIC_CHARSET, *text) == NULL)
|
||||
return false;
|
||||
@@ -806,7 +806,7 @@ bool qrcodegen_isAlphanumeric(const char *text) {
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
bool qrcodegen_isNumeric(const char *text) {
|
||||
assert(text != NULL);
|
||||
LV_ASSERT(text != NULL);
|
||||
for (; *text != '\0'; text++) {
|
||||
if (*text < '0' || *text > '9')
|
||||
return false;
|
||||
@@ -820,7 +820,7 @@ size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars
|
||||
int temp = calcSegmentBitLength(mode, numChars);
|
||||
if (temp == -1)
|
||||
return SIZE_MAX;
|
||||
assert(0 <= temp && temp <= INT16_MAX);
|
||||
LV_ASSERT(0 <= temp && temp <= INT16_MAX);
|
||||
return ((size_t)temp + 7) / 8;
|
||||
}
|
||||
|
||||
@@ -849,10 +849,10 @@ testable int calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars) {
|
||||
else if (mode == qrcodegen_Mode_ECI && numChars == 0)
|
||||
result = 3 * 8;
|
||||
else { // Invalid argument
|
||||
assert(false);
|
||||
LV_ASSERT(false);
|
||||
return -1;
|
||||
}
|
||||
assert(result >= 0);
|
||||
LV_ASSERT(result >= 0);
|
||||
if ((unsigned int)result > (unsigned int)INT16_MAX)
|
||||
return -1;
|
||||
return (int)result;
|
||||
@@ -861,11 +861,11 @@ testable int calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars) {
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]) {
|
||||
assert(data != NULL || len == 0);
|
||||
LV_ASSERT(data != NULL || len == 0);
|
||||
struct qrcodegen_Segment result;
|
||||
result.mode = qrcodegen_Mode_BYTE;
|
||||
result.bitLength = calcSegmentBitLength(result.mode, len);
|
||||
assert(result.bitLength != -1);
|
||||
LV_ASSERT(result.bitLength != -1);
|
||||
result.numChars = (int)len;
|
||||
if (len > 0)
|
||||
memcpy(buf, data, len * sizeof(buf[0]));
|
||||
@@ -876,22 +876,22 @@ struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, u
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]) {
|
||||
assert(digits != NULL);
|
||||
LV_ASSERT(digits != NULL);
|
||||
struct qrcodegen_Segment result;
|
||||
size_t len = strlen(digits);
|
||||
result.mode = qrcodegen_Mode_NUMERIC;
|
||||
int bitLen = calcSegmentBitLength(result.mode, len);
|
||||
assert(bitLen != -1);
|
||||
LV_ASSERT(bitLen != -1);
|
||||
result.numChars = (int)len;
|
||||
if (bitLen > 0)
|
||||
memset(buf, 0, ((size_t)bitLen + 7) / 8 * sizeof(buf[0]));
|
||||
result.bitLength = 0;
|
||||
|
||||
|
||||
unsigned int accumData = 0;
|
||||
int accumCount = 0;
|
||||
for (; *digits != '\0'; digits++) {
|
||||
char c = *digits;
|
||||
assert('0' <= c && c <= '9');
|
||||
LV_ASSERT('0' <= c && c <= '9');
|
||||
accumData = accumData * 10 + (unsigned int)(c - '0');
|
||||
accumCount++;
|
||||
if (accumCount == 3) {
|
||||
@@ -902,7 +902,7 @@ struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]
|
||||
}
|
||||
if (accumCount > 0) // 1 or 2 digits remaining
|
||||
appendBitsToBuffer(accumData, accumCount * 3 + 1, buf, &result.bitLength);
|
||||
assert(result.bitLength == bitLen);
|
||||
LV_ASSERT(result.bitLength == bitLen);
|
||||
result.data = buf;
|
||||
return result;
|
||||
}
|
||||
@@ -910,22 +910,22 @@ struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]
|
||||
|
||||
// Public function - see documentation comment in header file.
|
||||
struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]) {
|
||||
assert(text != NULL);
|
||||
LV_ASSERT(text != NULL);
|
||||
struct qrcodegen_Segment result;
|
||||
size_t len = strlen(text);
|
||||
result.mode = qrcodegen_Mode_ALPHANUMERIC;
|
||||
int bitLen = calcSegmentBitLength(result.mode, len);
|
||||
assert(bitLen != -1);
|
||||
LV_ASSERT(bitLen != -1);
|
||||
result.numChars = (int)len;
|
||||
if (bitLen > 0)
|
||||
memset(buf, 0, ((size_t)bitLen + 7) / 8 * sizeof(buf[0]));
|
||||
result.bitLength = 0;
|
||||
|
||||
|
||||
unsigned int accumData = 0;
|
||||
int accumCount = 0;
|
||||
for (; *text != '\0'; text++) {
|
||||
const char *temp = strchr(ALPHANUMERIC_CHARSET, *text);
|
||||
assert(temp != NULL);
|
||||
LV_ASSERT(temp != NULL);
|
||||
accumData = accumData * 45 + (unsigned int)(temp - ALPHANUMERIC_CHARSET);
|
||||
accumCount++;
|
||||
if (accumCount == 2) {
|
||||
@@ -936,7 +936,7 @@ struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t bu
|
||||
}
|
||||
if (accumCount > 0) // 1 character remaining
|
||||
appendBitsToBuffer(accumData, 6, buf, &result.bitLength);
|
||||
assert(result.bitLength == bitLen);
|
||||
LV_ASSERT(result.bitLength == bitLen);
|
||||
result.data = buf;
|
||||
return result;
|
||||
}
|
||||
@@ -949,7 +949,7 @@ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]) {
|
||||
result.numChars = 0;
|
||||
result.bitLength = 0;
|
||||
if (assignVal < 0) {
|
||||
assert(false);
|
||||
LV_ASSERT(false);
|
||||
} else if (assignVal < (1 << 7)) {
|
||||
memset(buf, 0, 1 * sizeof(buf[0]));
|
||||
appendBitsToBuffer(assignVal, 8, buf, &result.bitLength);
|
||||
@@ -963,7 +963,7 @@ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]) {
|
||||
appendBitsToBuffer(assignVal >> 10, 11, buf, &result.bitLength);
|
||||
appendBitsToBuffer(assignVal & 0x3FF, 10, buf, &result.bitLength);
|
||||
} else {
|
||||
assert(false);
|
||||
LV_ASSERT(false);
|
||||
}
|
||||
result.data = buf;
|
||||
return result;
|
||||
@@ -974,22 +974,22 @@ struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]) {
|
||||
// Returns a non-negative number if successful. Otherwise returns -1 if a segment has too
|
||||
// many characters to fit its length field, or the total bits exceeds INT16_MAX.
|
||||
testable int getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int version) {
|
||||
assert(segs != NULL || len == 0);
|
||||
LV_ASSERT(segs != NULL || len == 0);
|
||||
long result = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
int numChars = segs[i].numChars;
|
||||
int bitLength = segs[i].bitLength;
|
||||
assert(0 <= numChars && numChars <= INT16_MAX);
|
||||
assert(0 <= bitLength && bitLength <= INT16_MAX);
|
||||
LV_ASSERT(0 <= numChars && numChars <= INT16_MAX);
|
||||
LV_ASSERT(0 <= bitLength && bitLength <= INT16_MAX);
|
||||
int ccbits = numCharCountBits(segs[i].mode, version);
|
||||
assert(0 <= ccbits && ccbits <= 16);
|
||||
LV_ASSERT(0 <= ccbits && ccbits <= 16);
|
||||
if (numChars >= (1L << ccbits))
|
||||
return -1; // The segment's length doesn't fit the field's bit width
|
||||
result += 4L + ccbits + bitLength;
|
||||
if (result > INT16_MAX)
|
||||
return -1; // The sum might overflow an int type
|
||||
}
|
||||
assert(0 <= result && result <= INT16_MAX);
|
||||
LV_ASSERT(0 <= result && result <= INT16_MAX);
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
@@ -997,7 +997,7 @@ testable int getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int
|
||||
// Returns the bit width of the character count field for a segment in the given mode
|
||||
// in a QR Code at the given version number. The result is in the range [0, 16].
|
||||
static int numCharCountBits(enum qrcodegen_Mode mode, int version) {
|
||||
assert(qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX);
|
||||
LV_ASSERT(qrcodegen_VERSION_MIN <= version && version <= qrcodegen_VERSION_MAX);
|
||||
int i = (version + 7) / 17;
|
||||
switch (mode) {
|
||||
case qrcodegen_Mode_NUMERIC : { static const int temp[] = {10, 12, 14}; return temp[i]; }
|
||||
@@ -1005,7 +1005,7 @@ static int numCharCountBits(enum qrcodegen_Mode mode, int version) {
|
||||
case qrcodegen_Mode_BYTE : { static const int temp[] = { 8, 16, 16}; return temp[i]; }
|
||||
case qrcodegen_Mode_KANJI : { static const int temp[] = { 8, 10, 12}; return temp[i]; }
|
||||
case qrcodegen_Mode_ECI : return 0;
|
||||
default: assert(false); return -1; // Dummy value
|
||||
default: LV_ASSERT(false); return -1; // Dummy value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,6 @@ static void lv_rlottie_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob
|
||||
lv_obj_update_layout(obj);
|
||||
}
|
||||
|
||||
|
||||
static void lv_rlottie_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_UNUSED(class_p);
|
||||
|
||||
@@ -85,7 +85,6 @@ typedef struct {
|
||||
uint32_t raw_sjpg_data_next_read_pos; //Used for all types.
|
||||
} io_source_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t * sjpeg_data;
|
||||
uint32_t sjpeg_data_size;
|
||||
@@ -440,7 +439,6 @@ static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t *
|
||||
JRESULT rc = jd_prepare(&jd_tmp, input_func, workb_temp, (size_t)TJPGD_WORKBUFF_SIZE, &io_source_temp);
|
||||
lv_mem_free(workb_temp);
|
||||
|
||||
|
||||
if(rc == JDR_OK) {
|
||||
sjpeg->sjpeg_x_res = jd_tmp.width;
|
||||
sjpeg->sjpeg_y_res = jd_tmp.height;
|
||||
@@ -508,14 +506,12 @@ end:
|
||||
uint8_t buff[22];
|
||||
memset(buff, 0, sizeof(buff));
|
||||
|
||||
|
||||
lv_fs_file_t lv_file;
|
||||
lv_fs_res_t res = lv_fs_open(&lv_file, fn, LV_FS_MODE_RD);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
return 78;
|
||||
}
|
||||
|
||||
|
||||
uint32_t rn;
|
||||
res = lv_fs_read(&lv_file, buff, 22, &rn);
|
||||
if(res != LV_FS_RES_OK || rn != 22) {
|
||||
@@ -647,7 +643,6 @@ end:
|
||||
|
||||
lv_mem_free(workb_temp);
|
||||
|
||||
|
||||
if(rc == JDR_OK) {
|
||||
sjpeg->sjpeg_x_res = jd_tmp.width;
|
||||
sjpeg->sjpeg_y_res = jd_tmp.height;
|
||||
@@ -787,7 +782,6 @@ static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc
|
||||
#else
|
||||
#error Unsupported LV_COLOR_DEPTH
|
||||
|
||||
|
||||
#endif // LV_COLOR_DEPTH
|
||||
return LV_RES_OK;
|
||||
}
|
||||
@@ -852,7 +846,6 @@ static lv_res_t decoder_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc
|
||||
#else
|
||||
#error Unsupported LV_COLOR_DEPTH
|
||||
|
||||
|
||||
#endif // LV_COLOR_DEPTH
|
||||
|
||||
return LV_RES_OK;
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
#include "lv_tiny_ttf.h"
|
||||
|
||||
#if LV_USE_TINY_TTF
|
||||
#include <stdio.h>
|
||||
#include "../../../misc/lv_lru.h"
|
||||
|
||||
#define STB_RECT_PACK_IMPLEMENTATION
|
||||
#define STBRP_STATIC
|
||||
#define STBTT_STATIC
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STBTT_HEAP_FACTOR_SIZE_32 50
|
||||
#define STBTT_HEAP_FACTOR_SIZE_128 20
|
||||
#define STBTT_HEAP_FACTOR_SIZE_DEFAULT 10
|
||||
#define STBTT_malloc(x, u) ((void)(u), lv_mem_alloc(x))
|
||||
#define STBTT_free(x, u) ((void)(u), lv_mem_free(x))
|
||||
#define TTF_MALLOC(x) (lv_mem_alloc(x))
|
||||
#define TTF_FREE(x) (lv_mem_free(x))
|
||||
|
||||
#if LV_TINY_TTF_FILE_SUPPORT
|
||||
/* a hydra stream that can be in memory or from a file*/
|
||||
typedef struct ttf_cb_stream {
|
||||
lv_fs_file_t * file;
|
||||
const void * data;
|
||||
size_t size;
|
||||
size_t position;
|
||||
} ttf_cb_stream_t;
|
||||
|
||||
static void ttf_cb_stream_read(ttf_cb_stream_t * stream, void * data, size_t to_read)
|
||||
{
|
||||
if(stream->file != NULL) {
|
||||
uint32_t br;
|
||||
lv_fs_read(stream->file, data, to_read, &br);
|
||||
}
|
||||
else {
|
||||
if(to_read + stream->position >= stream->size) {
|
||||
to_read = stream->size - stream->position;
|
||||
}
|
||||
lv_memcpy(data, ((const unsigned char *)stream->data + stream->position), to_read);
|
||||
stream->position += to_read;
|
||||
}
|
||||
}
|
||||
static void ttf_cb_stream_seek(ttf_cb_stream_t * stream, size_t position)
|
||||
{
|
||||
if(stream->file != NULL) {
|
||||
lv_fs_seek(stream->file, position, LV_FS_SEEK_SET);
|
||||
}
|
||||
else {
|
||||
if(position > stream->size) {
|
||||
stream->position = stream->size;
|
||||
}
|
||||
else {
|
||||
stream->position = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* for stream support */
|
||||
#define STBTT_STREAM_TYPE ttf_cb_stream_t *
|
||||
#define STBTT_STREAM_SEEK(s, x) ttf_cb_stream_seek(s, x);
|
||||
#define STBTT_STREAM_READ(s, x, y) ttf_cb_stream_read(s, x, y);
|
||||
#endif /*LV_TINY_TTF_FILE_SUPPORT*/
|
||||
|
||||
#include "stb_rect_pack.h"
|
||||
#include "stb_truetype_htcw.h"
|
||||
|
||||
typedef struct ttf_font_desc {
|
||||
lv_fs_file_t file;
|
||||
#if LV_TINY_TTF_FILE_SUPPORT
|
||||
ttf_cb_stream_t stream;
|
||||
#else
|
||||
const uint8_t * stream;
|
||||
#endif
|
||||
stbtt_fontinfo info;
|
||||
float scale;
|
||||
int ascent;
|
||||
int descent;
|
||||
lv_lru_t * bitmap_cache;
|
||||
} ttf_font_desc_t;
|
||||
|
||||
typedef struct ttf_bitmap_cache_key {
|
||||
uint32_t unicode_letter;
|
||||
lv_coord_t line_height;
|
||||
} ttf_bitmap_cache_key_t;
|
||||
|
||||
static bool ttf_get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter,
|
||||
uint32_t unicode_letter_next)
|
||||
{
|
||||
if(unicode_letter < 0x20 ||
|
||||
unicode_letter == 0xf8ff || /*LV_SYMBOL_DUMMY*/
|
||||
unicode_letter == 0x200c) { /*ZERO WIDTH NON-JOINER*/
|
||||
dsc_out->box_w = 0;
|
||||
dsc_out->adv_w = 0;
|
||||
dsc_out->box_h = 0; /*height of the bitmap in [px]*/
|
||||
dsc_out->ofs_x = 0; /*X offset of the bitmap in [pf]*/
|
||||
dsc_out->ofs_y = 0; /*Y offset of the bitmap in [pf]*/
|
||||
dsc_out->bpp = 0;
|
||||
dsc_out->is_placeholder = false;
|
||||
return true;
|
||||
}
|
||||
ttf_font_desc_t * dsc = (ttf_font_desc_t *)font->dsc;
|
||||
int g1 = stbtt_FindGlyphIndex(&dsc->info, (int)unicode_letter);
|
||||
if(g1 == 0) {
|
||||
/* Glyph not found */
|
||||
return false;
|
||||
}
|
||||
int x1, y1, x2, y2;
|
||||
|
||||
stbtt_GetGlyphBitmapBox(&dsc->info, g1, dsc->scale, dsc->scale, &x1, &y1, &x2, &y2);
|
||||
int g2 = 0;
|
||||
if(unicode_letter_next != 0) {
|
||||
g2 = stbtt_FindGlyphIndex(&dsc->info, (int)unicode_letter_next);
|
||||
}
|
||||
int advw, lsb;
|
||||
stbtt_GetGlyphHMetrics(&dsc->info, g1, &advw, &lsb);
|
||||
int k = stbtt_GetGlyphKernAdvance(&dsc->info, g1, g2);
|
||||
dsc_out->adv_w = (uint16_t)floor((((float)advw + (float)k) * dsc->scale) +
|
||||
0.5f); /*Horizontal space required by the glyph in [px]*/
|
||||
|
||||
dsc_out->adv_w = (uint16_t)floor((((float)advw + (float)k) * dsc->scale) +
|
||||
0.5f); /*Horizontal space required by the glyph in [px]*/
|
||||
dsc_out->box_w = (x2 - x1 + 1); /*width of the bitmap in [px]*/
|
||||
dsc_out->box_h = (y2 - y1 + 1); /*height of the bitmap in [px]*/
|
||||
dsc_out->ofs_x = x1; /*X offset of the bitmap in [pf]*/
|
||||
dsc_out->ofs_y = -y2; /*Y offset of the bitmap measured from the as line*/
|
||||
dsc_out->bpp = 8; /*Bits per pixel: 1/2/4/8*/
|
||||
dsc_out->is_placeholder = false;
|
||||
return true; /*true: glyph found; false: glyph was not found*/
|
||||
}
|
||||
|
||||
static const uint8_t * ttf_get_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter)
|
||||
{
|
||||
ttf_font_desc_t * dsc = (ttf_font_desc_t *)font->dsc;
|
||||
const stbtt_fontinfo * info = (const stbtt_fontinfo *)&dsc->info;
|
||||
int g1 = stbtt_FindGlyphIndex(info, (int)unicode_letter);
|
||||
if(g1 == 0) {
|
||||
/* Glyph not found */
|
||||
return NULL;
|
||||
}
|
||||
int x1, y1, x2, y2;
|
||||
stbtt_GetGlyphBitmapBox(info, g1, dsc->scale, dsc->scale, &x1, &y1, &x2, &y2);
|
||||
int w, h;
|
||||
w = x2 - x1 + 1;
|
||||
h = y2 - y1 + 1;
|
||||
uint32_t stride = w;
|
||||
/*Try to load from cache*/
|
||||
ttf_bitmap_cache_key_t cache_key;
|
||||
lv_memset(&cache_key, 0, sizeof(cache_key)); /*Zero padding*/
|
||||
cache_key.unicode_letter = unicode_letter;
|
||||
cache_key.line_height = font->line_height;
|
||||
uint8_t * buffer = NULL;
|
||||
lv_lru_get(dsc->bitmap_cache, &cache_key, sizeof(cache_key), (void **)&buffer);
|
||||
if(buffer) {
|
||||
return buffer;
|
||||
}
|
||||
LV_LOG_TRACE("cache miss for letter: %u", unicode_letter);
|
||||
/*Prepare space in cache*/
|
||||
size_t szb = h * stride;
|
||||
buffer = lv_mem_alloc(szb);
|
||||
if(!buffer) {
|
||||
LV_LOG_ERROR("failed to allocate cache value");
|
||||
return NULL;
|
||||
}
|
||||
lv_memset(buffer, 0, szb);
|
||||
if(LV_LRU_OK != lv_lru_set(dsc->bitmap_cache, &cache_key, sizeof(cache_key), buffer, szb)) {
|
||||
LV_LOG_ERROR("failed to add cache value");
|
||||
lv_mem_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
/*Render into cache*/
|
||||
stbtt_MakeGlyphBitmap(info, buffer, w, h, stride, dsc->scale, dsc->scale, g1);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static lv_font_t * lv_tiny_ttf_create(const char * path, const void * data, size_t data_size, lv_coord_t font_size,
|
||||
size_t cache_size)
|
||||
{
|
||||
if((path == NULL && data == NULL) || 0 >= font_size) {
|
||||
LV_LOG_ERROR("tiny_ttf: invalid argument\n");
|
||||
return NULL;
|
||||
}
|
||||
ttf_font_desc_t * dsc = (ttf_font_desc_t *)TTF_MALLOC(sizeof(ttf_font_desc_t));
|
||||
if(dsc == NULL) {
|
||||
LV_LOG_ERROR("tiny_ttf: out of memory\n");
|
||||
return NULL;
|
||||
}
|
||||
#if LV_TINY_TTF_FILE_SUPPORT
|
||||
if(path != NULL) {
|
||||
if(LV_FS_RES_OK != lv_fs_open(&dsc->file, path, LV_FS_MODE_RD)) {
|
||||
LV_LOG_ERROR("tiny_ttf: unable to open %s\n", path);
|
||||
goto err_after_dsc;
|
||||
}
|
||||
dsc->stream.file = &dsc->file;
|
||||
}
|
||||
else {
|
||||
dsc->stream.file = NULL;
|
||||
dsc->stream.data = (const uint8_t *)data;
|
||||
dsc->stream.size = data_size;
|
||||
dsc->stream.position = 0;
|
||||
}
|
||||
if(0 == stbtt_InitFont(&dsc->info, &dsc->stream, stbtt_GetFontOffsetForIndex(&dsc->stream, 0))) {
|
||||
LV_LOG_ERROR("tiny_ttf: init failed\n");
|
||||
goto err_after_dsc;
|
||||
}
|
||||
|
||||
#else
|
||||
dsc->stream = (const uint8_t *)data;
|
||||
LV_UNUSED(data_size);
|
||||
if(0 == stbtt_InitFont(&dsc->info, dsc->stream, stbtt_GetFontOffsetForIndex(dsc->stream, 0))) {
|
||||
LV_LOG_ERROR("tiny_ttf: init failed\n");
|
||||
goto err_after_dsc;
|
||||
}
|
||||
#endif
|
||||
|
||||
dsc->bitmap_cache = lv_lru_create(cache_size, font_size * font_size, lv_mem_free, lv_mem_free);
|
||||
if(dsc->bitmap_cache == NULL) {
|
||||
LV_LOG_ERROR("failed to create lru cache");
|
||||
goto err_after_dsc;
|
||||
}
|
||||
|
||||
lv_font_t * out_font = (lv_font_t *)TTF_MALLOC(sizeof(lv_font_t));
|
||||
if(out_font == NULL) {
|
||||
LV_LOG_ERROR("tiny_ttf: out of memory\n");
|
||||
goto err_after_bitmap_cache;
|
||||
}
|
||||
lv_memset(out_font, 0, sizeof(lv_font_t));
|
||||
out_font->get_glyph_dsc = ttf_get_glyph_dsc_cb;
|
||||
out_font->get_glyph_bitmap = ttf_get_glyph_bitmap_cb;
|
||||
out_font->dsc = dsc;
|
||||
lv_tiny_ttf_set_size(out_font, font_size);
|
||||
return out_font;
|
||||
err_after_bitmap_cache:
|
||||
lv_lru_del(dsc->bitmap_cache);
|
||||
err_after_dsc:
|
||||
TTF_FREE(dsc);
|
||||
return NULL;
|
||||
}
|
||||
#if LV_TINY_TTF_FILE_SUPPORT
|
||||
lv_font_t * lv_tiny_ttf_create_file_ex(const char * path, lv_coord_t font_size, size_t cache_size)
|
||||
{
|
||||
return lv_tiny_ttf_create(path, NULL, 0, font_size, cache_size);
|
||||
}
|
||||
lv_font_t * lv_tiny_ttf_create_file(const char * path, lv_coord_t font_size)
|
||||
{
|
||||
return lv_tiny_ttf_create_file_ex(path, font_size, 4096);
|
||||
}
|
||||
#endif /*LV_TINY_TTF_FILE_SUPPORT*/
|
||||
lv_font_t * lv_tiny_ttf_create_data_ex(const void * data, size_t data_size, lv_coord_t font_size, size_t cache_size)
|
||||
{
|
||||
return lv_tiny_ttf_create(NULL, data, data_size, font_size, cache_size);
|
||||
}
|
||||
lv_font_t * lv_tiny_ttf_create_data(const void * data, size_t data_size, lv_coord_t font_size)
|
||||
{
|
||||
return lv_tiny_ttf_create_data_ex(data, data_size, font_size, 4096);
|
||||
}
|
||||
void lv_tiny_ttf_set_size(lv_font_t * font, lv_coord_t font_size)
|
||||
{
|
||||
if(font_size <= 0) {
|
||||
LV_LOG_ERROR("invalid font size: %"PRIx32, font_size);
|
||||
return;
|
||||
}
|
||||
ttf_font_desc_t * dsc = (ttf_font_desc_t *)font->dsc;
|
||||
dsc->scale = stbtt_ScaleForMappingEmToPixels(&dsc->info, font_size);
|
||||
int line_gap = 0;
|
||||
stbtt_GetFontVMetrics(&dsc->info, &dsc->ascent, &dsc->descent, &line_gap);
|
||||
font->line_height = (lv_coord_t)(dsc->scale * (dsc->ascent - dsc->descent + line_gap));
|
||||
font->base_line = (lv_coord_t)(dsc->scale * (line_gap - dsc->descent));
|
||||
}
|
||||
void lv_tiny_ttf_destroy(lv_font_t * font)
|
||||
{
|
||||
if(font != NULL) {
|
||||
if(font->dsc != NULL) {
|
||||
ttf_font_desc_t * ttf = (ttf_font_desc_t *)font->dsc;
|
||||
#if LV_TINY_TTF_FILE_SUPPORT
|
||||
if(ttf->stream.file != NULL) {
|
||||
lv_fs_close(&ttf->file);
|
||||
}
|
||||
#endif
|
||||
lv_lru_del(ttf->bitmap_cache);
|
||||
TTF_FREE(ttf);
|
||||
}
|
||||
TTF_FREE(font);
|
||||
}
|
||||
}
|
||||
#endif /*LV_USE_TINY_TTF*/
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @file lv_tiny_ttf.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_TINY_TTF_H
|
||||
#define LV_TINY_TTF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../../lvgl.h"
|
||||
|
||||
#if LV_USE_TINY_TTF
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
#if LV_TINY_TTF_FILE_SUPPORT
|
||||
/* create a font from the specified file or path with the specified line height.*/
|
||||
lv_font_t * lv_tiny_ttf_create_file(const char * path, lv_coord_t font_size);
|
||||
|
||||
/* create a font from the specified file or path with the specified line height with the specified cache size.*/
|
||||
lv_font_t * lv_tiny_ttf_create_file_ex(const char * path, lv_coord_t font_size, size_t cache_size);
|
||||
#endif /*LV_TINY_TTF_FILE_SUPPORT*/
|
||||
|
||||
/* create a font from the specified data pointer with the specified line height.*/
|
||||
lv_font_t * lv_tiny_ttf_create_data(const void * data, size_t data_size, lv_coord_t font_size);
|
||||
|
||||
/* create a font from the specified data pointer with the specified line height and the specified cache size.*/
|
||||
lv_font_t * lv_tiny_ttf_create_data_ex(const void * data, size_t data_size, lv_coord_t font_size, size_t cache_size);
|
||||
|
||||
/* set the size of the font to a new font_size*/
|
||||
void lv_tiny_ttf_set_size(lv_font_t * font, lv_coord_t font_size);
|
||||
|
||||
/* destroy a font previously created with lv_tiny_ttf_create_xxxx()*/
|
||||
void lv_tiny_ttf_destroy(lv_font_t * font);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_TINY_TTF*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_TINY_TTF_H*/
|
||||
@@ -0,0 +1,633 @@
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// @cond
|
||||
/**
|
||||
* Tells Doxygen to ignore a duplicate declaration
|
||||
*/
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
/// @endcond
|
||||
|
||||
typedef int stbrp_coord;
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#endif
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context * context, stbrp_rect * rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect {
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context * context, int width, int height, stbrp_node * nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context * context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context * context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum {
|
||||
STBRP_HEURISTIC_Skyline_default = 0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node {
|
||||
stbrp_coord x, y;
|
||||
stbrp_node * next;
|
||||
};
|
||||
|
||||
struct stbrp_context {
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node * active_head;
|
||||
stbrp_node * free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum {
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context * context, int heuristic)
|
||||
{
|
||||
switch(context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context * context, int allow_out_of_mem)
|
||||
{
|
||||
if(allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes - 1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context * context, int width, int height, stbrp_node * nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < num_nodes - 1; ++i)
|
||||
nodes[i].next = &nodes[i + 1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
context->extra[1].y = (1 << 30);
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context * c, stbrp_node * first, int x0, int width, int * pwaste)
|
||||
{
|
||||
stbrp_node * node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while(node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while(node->x < x1) {
|
||||
if(node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visited
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if(node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
}
|
||||
else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if(under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int x, y;
|
||||
stbrp_node ** prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context * c, int width, int height)
|
||||
{
|
||||
int best_waste = (1 << 30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node ** prev, * node, * tail, ** best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if(width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while(node->x + width <= c->width) {
|
||||
int y, waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if(c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if(y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// best-fit
|
||||
if(y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if(y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if(c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while(tail->x < width)
|
||||
tail = tail->next;
|
||||
while(tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y, waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while(node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if(y + height <= c->height) {
|
||||
if(y <= best_y) {
|
||||
if(y < best_y || waste < best_waste || (waste == best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
STBRP_ASSERT(y <= best_y);
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context * context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node * node, * cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if(res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord)(res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if(cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node * next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
}
|
||||
else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while(cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node * next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if(cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord)(res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while(cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count = 0;
|
||||
cur = context->active_head;
|
||||
while(cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while(cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes + 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void * a, const void * b)
|
||||
{
|
||||
const stbrp_rect * p = (const stbrp_rect *) a;
|
||||
const stbrp_rect * q = (const stbrp_rect *) b;
|
||||
if(p->h > q->h)
|
||||
return -1;
|
||||
if(p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void * a, const void * b)
|
||||
{
|
||||
const stbrp_rect * p = (const stbrp_rect *) a;
|
||||
const stbrp_rect * q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context * context, stbrp_rect * rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for(i = 0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for(i = 0; i < num_rects; ++i) {
|
||||
if(rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
}
|
||||
else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if(fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
}
|
||||
else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for(i = 0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if(!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,10 @@ void lv_extra_init(void)
|
||||
lv_fs_fatfs_init();
|
||||
#endif
|
||||
|
||||
#if LV_USE_FS_LITTLEFS != '\0'
|
||||
lv_fs_littlefs_init();
|
||||
#endif
|
||||
|
||||
#if LV_USE_FS_STDIO != '\0'
|
||||
lv_fs_stdio_init();
|
||||
#endif
|
||||
|
||||
@@ -1 +1 @@
|
||||
CSRCS += $(shell find -L $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/extra -name \*.c)
|
||||
CSRCS += $(shell find -L $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/extra -name "*.c")
|
||||
|
||||
@@ -266,7 +266,6 @@ lv_fragment_t * lv_fragment_manager_find_by_container(lv_fragment_manager_t * ma
|
||||
*/
|
||||
lv_fragment_t * lv_fragment_manager_get_parent_fragment(lv_fragment_manager_t * manager);
|
||||
|
||||
|
||||
/**
|
||||
* Create a fragment instance.
|
||||
*
|
||||
@@ -325,7 +324,6 @@ void lv_fragment_del_obj(lv_fragment_t * fragment);
|
||||
*/
|
||||
void lv_fragment_recreate_obj(lv_fragment_t * fragment);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -36,7 +36,6 @@ struct _lv_fragment_manager_t {
|
||||
lv_ll_t stack;
|
||||
};
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
@@ -127,23 +126,25 @@ void lv_fragment_manager_remove(lv_fragment_manager_t * manager, lv_fragment_t *
|
||||
bool was_top = false;
|
||||
if(states->in_stack) {
|
||||
void * stack_top = _lv_ll_get_tail(&manager->stack);
|
||||
lv_fragment_stack_item_t * stack = NULL;
|
||||
_LV_LL_READ_BACK(&manager->stack, stack) {
|
||||
if(stack->states == states) {
|
||||
was_top = stack_top == stack;
|
||||
void * stack_prev = _lv_ll_get_prev(&manager->stack, stack);
|
||||
lv_fragment_stack_item_t * item = NULL;
|
||||
_LV_LL_READ_BACK(&manager->stack, item) {
|
||||
if(item->states == states) {
|
||||
was_top = stack_top == item;
|
||||
void * stack_prev = _lv_ll_get_prev(&manager->stack, item);
|
||||
if(!stack_prev) break;
|
||||
prev = ((lv_fragment_stack_item_t *) stack_prev)->states;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(stack) {
|
||||
_lv_ll_remove(&manager->stack, stack);
|
||||
if(item) {
|
||||
_lv_ll_remove(&manager->stack, item);
|
||||
lv_mem_free(item);
|
||||
}
|
||||
}
|
||||
item_del_obj(states);
|
||||
item_del_fragment(states);
|
||||
_lv_ll_remove(&manager->attached, states);
|
||||
lv_mem_free(states);
|
||||
if(prev && was_top) {
|
||||
item_create_obj(prev);
|
||||
}
|
||||
@@ -185,14 +186,15 @@ void lv_fragment_manager_replace(lv_fragment_manager_t * manager, lv_fragment_t
|
||||
bool lv_fragment_manager_send_event(lv_fragment_manager_t * manager, int code, void * userdata)
|
||||
{
|
||||
LV_ASSERT_NULL(manager);
|
||||
lv_fragment_stack_item_t * top = _lv_ll_get_tail(&manager->stack);
|
||||
if(!top) return false;
|
||||
lv_fragment_managed_states_t * states = top->states;
|
||||
lv_fragment_t * instance = states->instance;
|
||||
if(!instance) return false;
|
||||
if(lv_fragment_manager_send_event(instance->child_manager, code, userdata)) return true;
|
||||
if(!states->cls->event_cb) return false;
|
||||
return states->cls->event_cb(instance, code, userdata);
|
||||
lv_fragment_managed_states_t * p = NULL;
|
||||
_LV_LL_READ_BACK(&manager->attached, p) {
|
||||
if(!p->obj_created || p->destroying_obj) continue;
|
||||
lv_fragment_t * instance = p->instance;
|
||||
if(!instance) continue;
|
||||
if(lv_fragment_manager_send_event(instance->child_manager, code, userdata)) return true;
|
||||
if(p->cls->event_cb && p->cls->event_cb(instance, code, userdata)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t lv_fragment_manager_get_stack_size(lv_fragment_manager_t * manager)
|
||||
@@ -255,24 +257,23 @@ static void item_del_fragment(lv_fragment_managed_states_t * item)
|
||||
item->instance = NULL;
|
||||
}
|
||||
|
||||
|
||||
static lv_fragment_managed_states_t * fragment_attach(lv_fragment_manager_t * manager, lv_fragment_t * fragment,
|
||||
lv_obj_t * const * container)
|
||||
{
|
||||
LV_ASSERT(manager);
|
||||
LV_ASSERT(fragment);
|
||||
LV_ASSERT(fragment->managed == NULL);
|
||||
lv_fragment_managed_states_t * item = _lv_ll_ins_tail(&manager->attached);
|
||||
lv_memset_00(item, sizeof(lv_fragment_managed_states_t));
|
||||
item->cls = fragment->cls;
|
||||
item->manager = manager;
|
||||
item->container = container;
|
||||
item->instance = fragment;
|
||||
fragment->managed = item;
|
||||
lv_fragment_managed_states_t * states = _lv_ll_ins_tail(&manager->attached);
|
||||
lv_memset_00(states, sizeof(lv_fragment_managed_states_t));
|
||||
states->cls = fragment->cls;
|
||||
states->manager = manager;
|
||||
states->container = container;
|
||||
states->instance = fragment;
|
||||
fragment->managed = states;
|
||||
if(fragment->cls->attached_cb) {
|
||||
fragment->cls->attached_cb(fragment);
|
||||
}
|
||||
return item;
|
||||
return states;
|
||||
}
|
||||
|
||||
#endif /*LV_USE_FRAGMENT*/
|
||||
|
||||
@@ -217,6 +217,7 @@ static void gridnav_event_cb(lv_event_t * e)
|
||||
if(dsc->focused_obj == NULL) dsc->focused_obj = find_first_focusable(obj);
|
||||
if(dsc->focused_obj) {
|
||||
lv_obj_add_state(dsc->focused_obj, LV_STATE_FOCUSED | LV_STATE_FOCUS_KEY);
|
||||
lv_obj_clear_state(dsc->focused_obj, LV_STATE_PRESSED); /*Be sure the focuses obj is not stuck in pressed state*/
|
||||
lv_obj_scroll_to_view(dsc->focused_obj, LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
@@ -348,7 +349,7 @@ static lv_obj_t * find_last_focusable(lv_obj_t * obj)
|
||||
{
|
||||
uint32_t child_cnt = lv_obj_get_child_cnt(obj);
|
||||
int32_t i;
|
||||
for(i = child_cnt - 1; i >= 0; i++) {
|
||||
for(i = child_cnt - 1; i >= 0; i--) {
|
||||
lv_obj_t * child = lv_obj_get_child(obj, i);
|
||||
if(obj_is_focuable(child)) return child;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* @file lv_ime_pinyin.h
|
||||
*
|
||||
*/
|
||||
#ifndef LV_IME_PINYIN_H
|
||||
#define LV_IME_PINYIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../../lvgl.h"
|
||||
|
||||
#if LV_USE_IME_PINYIN != 0
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_IME_PINYIN_K9_MAX_INPUT 7
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef enum {
|
||||
LV_IME_PINYIN_MODE_K26,
|
||||
LV_IME_PINYIN_MODE_K9,
|
||||
} lv_ime_pinyin_mode_t;
|
||||
|
||||
/*Data of pinyin_dict*/
|
||||
typedef struct {
|
||||
const char * const py;
|
||||
const char * const py_mb;
|
||||
} lv_pinyin_dict_t;
|
||||
|
||||
/*Data of 9-key input(k9) mode*/
|
||||
typedef struct {
|
||||
char py_str[7];
|
||||
} ime_pinyin_k9_py_str_t;
|
||||
|
||||
/*Data of lv_ime_pinyin*/
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
lv_obj_t * kb;
|
||||
lv_obj_t * cand_panel;
|
||||
lv_pinyin_dict_t * dict;
|
||||
lv_ll_t k9_legal_py_ll;
|
||||
char * cand_str; /* Candidate string */
|
||||
char input_char[16]; /* Input box character */
|
||||
#if LV_IME_PINYIN_USE_K9_MODE
|
||||
char k9_input_str[LV_IME_PINYIN_K9_MAX_INPUT]; /* 9-key input(k9) mode input string */
|
||||
uint16_t k9_py_ll_pos; /* Current pinyin map pages(k9) */
|
||||
uint16_t k9_legal_py_count; /* Count of legal Pinyin numbers(k9) */
|
||||
uint16_t k9_input_str_len; /* 9-key input(k9) mode input string max len */
|
||||
#endif
|
||||
uint16_t ta_count; /* The number of characters entered in the text box this time */
|
||||
uint16_t cand_num; /* Number of candidates */
|
||||
uint16_t py_page; /* Current pinyin map pages(k26) */
|
||||
uint16_t py_num[26]; /* Number and length of Pinyin */
|
||||
uint16_t py_pos[26]; /* Pinyin position */
|
||||
uint8_t mode : 1; /* Set mode, 1: 26-key input(k26), 0: 9-key input(k9). Default: 1. */
|
||||
} lv_ime_pinyin_t;
|
||||
|
||||
/***********************
|
||||
* GLOBAL VARIABLES
|
||||
***********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t * lv_ime_pinyin_create(lv_obj_t * parent);
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set the keyboard of Pinyin input method.
|
||||
* @param obj pointer to a Pinyin input method object
|
||||
* @param dict pointer to a Pinyin input method keyboard
|
||||
*/
|
||||
void lv_ime_pinyin_set_keyboard(lv_obj_t * obj, lv_obj_t * kb);
|
||||
|
||||
/**
|
||||
* Set the dictionary of Pinyin input method.
|
||||
* @param obj pointer to a Pinyin input method object
|
||||
* @param dict pointer to a Pinyin input method dictionary
|
||||
*/
|
||||
void lv_ime_pinyin_set_dict(lv_obj_t * obj, lv_pinyin_dict_t * dict);
|
||||
|
||||
/**
|
||||
* Set mode, 26-key input(k26) or 9-key input(k9).
|
||||
* @param obj pointer to a Pinyin input method object
|
||||
* @param mode the mode from 'lv_ime_pinyin_mode_t'
|
||||
*/
|
||||
void lv_ime_pinyin_set_mode(lv_obj_t * obj, lv_ime_pinyin_mode_t mode);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set the dictionary of Pinyin input method.
|
||||
* @param obj pointer to a Pinyin IME object
|
||||
* @return pointer to the Pinyin IME keyboard
|
||||
*/
|
||||
lv_obj_t * lv_ime_pinyin_get_kb(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Set the dictionary of Pinyin input method.
|
||||
* @param obj pointer to a Pinyin input method object
|
||||
* @return pointer to the Pinyin input method candidate panel
|
||||
*/
|
||||
lv_obj_t * lv_ime_pinyin_get_cand_panel(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Set the dictionary of Pinyin input method.
|
||||
* @param obj pointer to a Pinyin input method object
|
||||
* @return pointer to the Pinyin input method dictionary
|
||||
*/
|
||||
lv_pinyin_dict_t * lv_ime_pinyin_get_dict(lv_obj_t * obj);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_IME_PINYIN*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_USE_IME_PINYIN*/
|
||||
@@ -19,6 +19,7 @@ extern "C" {
|
||||
#include "fragment/lv_fragment.h"
|
||||
#include "imgfont/lv_imgfont.h"
|
||||
#include "msg/lv_msg.h"
|
||||
#include "ime/lv_ime_pinyin.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
|
||||
@@ -94,6 +94,25 @@ void lv_msg_unsubscribe(void * s)
|
||||
lv_mem_free(s);
|
||||
}
|
||||
|
||||
uint32_t lv_msg_unsubscribe_obj(uint32_t msg_id, lv_obj_t * obj)
|
||||
{
|
||||
uint32_t cnt = 0;
|
||||
sub_dsc_t * s = _lv_ll_get_head(&subs_ll);
|
||||
while(s) {
|
||||
sub_dsc_t * s_next = _lv_ll_get_next(&subs_ll, s);
|
||||
if(s->callback == obj_notify_cb &&
|
||||
(s->msg_id == LV_MSG_ID_ANY || s->msg_id == msg_id) &&
|
||||
(obj == NULL || s->_priv_data == obj)) {
|
||||
lv_msg_unsubscribe(s);
|
||||
cnt++;
|
||||
}
|
||||
|
||||
s = s_next;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void lv_msg_send(uint32_t msg_id, const void * payload)
|
||||
{
|
||||
lv_msg_t m;
|
||||
@@ -129,8 +148,6 @@ lv_msg_t * lv_event_get_msg(lv_event_t * e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
@@ -19,6 +19,8 @@ extern "C" {
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_MSG_ID_ANY UINT32_MAX
|
||||
LV_EXPORT_CONST_INT(LV_MSG_ID_ANY);
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -70,6 +72,14 @@ void * lv_msg_subsribe_obj(uint32_t msg_id, lv_obj_t * obj, void * user_data);
|
||||
*/
|
||||
void lv_msg_unsubscribe(void * s);
|
||||
|
||||
/**
|
||||
* Unsubscribe an object from a message ID
|
||||
* @param msg_id the message ID to unsubcribe from or `LV_MSG_ID_ANY` for any message ID
|
||||
* @param obj the object to unsubscribe or NULL for any object
|
||||
* @return number of unsubscriptions
|
||||
*/
|
||||
uint32_t lv_msg_unsubscribe_obj(uint32_t msg_id, lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Send a message with a given ID and payload
|
||||
* @param msg_id ID of the message to send
|
||||
@@ -105,6 +115,17 @@ void * lv_msg_get_user_data(lv_msg_t * m);
|
||||
*/
|
||||
lv_msg_t * lv_event_get_msg(lv_event_t * e);
|
||||
|
||||
/*Fix typo*/
|
||||
static inline void * lv_msg_subscribe(uint32_t msg_id, lv_msg_subscribe_cb_t cb, void * user_data)
|
||||
{
|
||||
return lv_msg_subsribe(msg_id, cb, user_data);
|
||||
}
|
||||
|
||||
static inline void * lv_msg_subscribe_obj(uint32_t msg_id, lv_obj_t * obj, void * user_data)
|
||||
{
|
||||
return lv_msg_subsribe_obj(msg_id, obj, user_data);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
|
||||
@@ -45,7 +45,9 @@
|
||||
*/
|
||||
uint32_t lv_snapshot_buf_size_needed(lv_obj_t * obj, lv_img_cf_t cf)
|
||||
{
|
||||
LV_ASSERT_NULL(obj);
|
||||
switch(cf) {
|
||||
case LV_IMG_CF_TRUE_COLOR:
|
||||
case LV_IMG_CF_TRUE_COLOR_ALPHA:
|
||||
case LV_IMG_CF_ALPHA_1BIT:
|
||||
case LV_IMG_CF_ALPHA_2BIT:
|
||||
@@ -71,20 +73,22 @@ uint32_t lv_snapshot_buf_size_needed(lv_obj_t * obj, lv_img_cf_t cf)
|
||||
|
||||
/** Take snapshot for object with its children, save image info to provided buffer.
|
||||
*
|
||||
* @param obj The object to generate snapshot.
|
||||
* @param cf color format for generated image.
|
||||
* @param dsc image descriptor to store the image result.
|
||||
* @param buf the buffer to store image data.
|
||||
* @param buff_size provided buffer size in bytes.
|
||||
* @param obj The object to generate snapshot.
|
||||
* @param cf color format for generated image.
|
||||
* @param dsc image descriptor to store the image result.
|
||||
* @param buf the buffer to store image data.
|
||||
* @param buf_size provided buffer size in bytes.
|
||||
*
|
||||
* @return LV_RES_OK on success, LV_RES_INV on error.
|
||||
*/
|
||||
lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buff_size)
|
||||
lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buf_size)
|
||||
{
|
||||
LV_ASSERT(dsc);
|
||||
LV_ASSERT(buf);
|
||||
LV_ASSERT_NULL(obj);
|
||||
LV_ASSERT_NULL(dsc);
|
||||
LV_ASSERT_NULL(buf);
|
||||
|
||||
switch(cf) {
|
||||
case LV_IMG_CF_TRUE_COLOR:
|
||||
case LV_IMG_CF_TRUE_COLOR_ALPHA:
|
||||
case LV_IMG_CF_ALPHA_1BIT:
|
||||
case LV_IMG_CF_ALPHA_2BIT:
|
||||
@@ -95,8 +99,8 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
if(lv_snapshot_buf_size_needed(obj, cf) > buff_size)
|
||||
return LV_RES_INV;
|
||||
uint32_t buf_size_needed = lv_snapshot_buf_size_needed(obj, cf);
|
||||
if(buf_size_needed == 0 || buf_size < buf_size_needed) return LV_RES_INV;
|
||||
|
||||
/*Width and height determine snapshot image size.*/
|
||||
lv_coord_t w = lv_obj_get_width(obj);
|
||||
@@ -109,7 +113,7 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
|
||||
lv_obj_get_coords(obj, &snapshot_area);
|
||||
lv_area_increase(&snapshot_area, ext_size, ext_size);
|
||||
|
||||
lv_memset(buf, 0x00, buff_size);
|
||||
lv_memset(buf, 0x00, buf_size);
|
||||
lv_memset_00(dsc, sizeof(lv_img_dsc_t));
|
||||
|
||||
lv_disp_t * obj_disp = lv_obj_get_disp(obj);
|
||||
@@ -124,7 +128,6 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
|
||||
lv_memset_00(&fake_disp, sizeof(lv_disp_t));
|
||||
fake_disp.driver = &driver;
|
||||
|
||||
|
||||
lv_draw_ctx_t * draw_ctx = lv_mem_alloc(obj_disp->driver->draw_ctx_size);
|
||||
LV_ASSERT_MALLOC(draw_ctx);
|
||||
if(draw_ctx == NULL) return LV_RES_INV;
|
||||
@@ -138,13 +141,14 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
|
||||
lv_disp_t * refr_ori = _lv_refr_get_disp_refreshing();
|
||||
_lv_refr_set_disp_refreshing(&fake_disp);
|
||||
|
||||
lv_refr_obj(draw_ctx, obj);
|
||||
lv_obj_redraw(draw_ctx, obj);
|
||||
|
||||
_lv_refr_set_disp_refreshing(refr_ori);
|
||||
obj_disp->driver->draw_ctx_deinit(fake_disp.driver, draw_ctx);
|
||||
lv_mem_free(draw_ctx);
|
||||
|
||||
dsc->data = buf;
|
||||
dsc->data_size = buf_size_needed;
|
||||
dsc->header.w = w;
|
||||
dsc->header.h = h;
|
||||
dsc->header.cf = cf;
|
||||
@@ -160,20 +164,23 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t *
|
||||
*/
|
||||
lv_img_dsc_t * lv_snapshot_take(lv_obj_t * obj, lv_img_cf_t cf)
|
||||
{
|
||||
uint32_t buff_size = lv_snapshot_buf_size_needed(obj, cf);
|
||||
LV_ASSERT_NULL(obj);
|
||||
uint32_t buf_size = lv_snapshot_buf_size_needed(obj, cf);
|
||||
|
||||
void * buf = lv_mem_alloc(buff_size);
|
||||
void * buf = lv_mem_alloc(buf_size);
|
||||
LV_ASSERT_MALLOC(buf);
|
||||
if(buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lv_img_dsc_t * dsc = lv_mem_alloc(sizeof(lv_img_dsc_t));
|
||||
LV_ASSERT_MALLOC(buf);
|
||||
if(dsc == NULL) {
|
||||
lv_mem_free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(lv_snapshot_take_to_buf(obj, cf, dsc, buf, buff_size) == LV_RES_INV) {
|
||||
if(lv_snapshot_take_to_buf(obj, cf, dsc, buf, buf_size) == LV_RES_INV) {
|
||||
lv_mem_free(buf);
|
||||
lv_mem_free(dsc);
|
||||
return NULL;
|
||||
|
||||
@@ -61,16 +61,15 @@ uint32_t lv_snapshot_buf_size_needed(lv_obj_t * obj, lv_img_cf_t cf);
|
||||
|
||||
/** Take snapshot for object with its children, save image info to provided buffer.
|
||||
*
|
||||
* @param obj The object to generate snapshot.
|
||||
* @param cf color format for generated image.
|
||||
* @param dsc image descriptor to store the image result.
|
||||
* @param buff the buffer to store image data.
|
||||
* @param buff_size provided buffer size in bytes.
|
||||
* @param obj The object to generate snapshot.
|
||||
* @param cf color format for generated image.
|
||||
* @param dsc image descriptor to store the image result.
|
||||
* @param buf the buffer to store image data.
|
||||
* @param buf_size provided buffer size in bytes.
|
||||
*
|
||||
* @return LV_RES_OK on success, LV_RES_INV on error.
|
||||
*/
|
||||
lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buff_size);
|
||||
|
||||
lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buf_size);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -43,7 +43,6 @@ typedef struct {
|
||||
#endif
|
||||
} my_theme_styles_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
@@ -77,7 +76,6 @@ static void style_init(void)
|
||||
lv_style_set_bg_color(&styles->scr, COLOR_SCR);
|
||||
lv_style_set_text_color(&styles->scr, COLOR_DIM);
|
||||
|
||||
|
||||
style_init_reset(&styles->transp);
|
||||
lv_style_set_bg_opa(&styles->transp, LV_OPA_TRANSP);
|
||||
|
||||
@@ -130,7 +128,6 @@ static void style_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
@@ -169,7 +166,6 @@ lv_theme_t * lv_theme_basic_init(lv_disp_t * disp)
|
||||
return (lv_theme_t *)&theme;
|
||||
}
|
||||
|
||||
|
||||
static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
{
|
||||
LV_UNUSED(th);
|
||||
|
||||
@@ -179,7 +179,6 @@ static lv_color_t color_card;
|
||||
static lv_color_t color_grey;
|
||||
static bool inited = false;
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
@@ -188,7 +187,6 @@ static bool inited = false;
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
static lv_color_t dark_color_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t c, lv_opa_t opa)
|
||||
{
|
||||
LV_UNUSED(f);
|
||||
@@ -628,7 +626,6 @@ static void style_init(void)
|
||||
lv_style_set_transform_width(&styles->list_item_grow, PAD_DEF);
|
||||
#endif
|
||||
|
||||
|
||||
#if LV_USE_LED
|
||||
style_init_reset(&styles->led);
|
||||
lv_style_set_bg_opa(&styles->led, LV_OPA_COVER);
|
||||
@@ -694,7 +691,6 @@ bool lv_theme_default_is_inited(void)
|
||||
return LV_GC_ROOT(_lv_theme_default_styles) == NULL ? false : true;
|
||||
}
|
||||
|
||||
|
||||
static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
{
|
||||
LV_UNUSED(th);
|
||||
@@ -739,7 +735,6 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if LV_USE_CALENDAR
|
||||
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_calendar_class)) {
|
||||
/*No style*/
|
||||
@@ -978,7 +973,6 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if LV_USE_SPINNER
|
||||
else if(lv_obj_check_type(obj, &lv_spinner_class)) {
|
||||
lv_obj_add_style(obj, &styles->arc_indic, 0);
|
||||
|
||||
@@ -52,7 +52,6 @@ typedef struct {
|
||||
#endif
|
||||
} my_theme_styles_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
@@ -159,7 +158,6 @@ static void style_init(bool dark_bg, const lv_font_t * font)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
@@ -196,7 +194,6 @@ lv_theme_t * lv_theme_mono_init(lv_disp_t * disp, bool dark_bg, const lv_font_t
|
||||
return (lv_theme_t *)&theme;
|
||||
}
|
||||
|
||||
|
||||
static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
{
|
||||
LV_UNUSED(th);
|
||||
|
||||
@@ -64,7 +64,7 @@ lv_obj_t * lv_animimg_create(lv_obj_t * parent)
|
||||
return obj;
|
||||
}
|
||||
|
||||
void lv_animimg_set_src(lv_obj_t * obj, lv_img_dsc_t * dsc[], uint8_t num)
|
||||
void lv_animimg_set_src(lv_obj_t * obj, const void * dsc[], uint8_t num)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_animimg_t * animimg = (lv_animimg_t *)obj;
|
||||
|
||||
@@ -37,11 +37,10 @@ typedef struct {
|
||||
lv_img_t img;
|
||||
lv_anim_t anim;
|
||||
/*picture sequence */
|
||||
lv_img_dsc_t ** dsc;
|
||||
const void ** dsc;
|
||||
int8_t pic_count;
|
||||
} lv_animimg_t;
|
||||
|
||||
|
||||
/*Image parts*/
|
||||
enum {
|
||||
LV_ANIM_IMG_PART_MAIN,
|
||||
@@ -69,7 +68,7 @@ lv_obj_t * lv_animimg_create(lv_obj_t * parent);
|
||||
* @param dsc pointer to a series images
|
||||
* @param num images' number
|
||||
*/
|
||||
void lv_animimg_set_src(lv_obj_t * img, lv_img_dsc_t * dsc[], uint8_t num);
|
||||
void lv_animimg_set_src(lv_obj_t * img, const void * dsc[], uint8_t num);
|
||||
|
||||
/**
|
||||
* Startup the image animation.
|
||||
|
||||
@@ -232,7 +232,6 @@ lv_res_t lv_calendar_get_pressed_date(const lv_obj_t * obj, lv_calendar_date_t *
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
@@ -66,6 +66,45 @@ lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent)
|
||||
return obj;
|
||||
}
|
||||
|
||||
void lv_calendar_header_dropdown_set_year_list(lv_obj_t * parent, const char * years_list)
|
||||
{
|
||||
bool child_found = false;
|
||||
uint32_t idx = 0;
|
||||
lv_obj_t * child = NULL;
|
||||
|
||||
const uint32_t calendar_child_count = lv_obj_get_child_cnt(parent);
|
||||
|
||||
/* Search for the header dropdown */
|
||||
for(idx = 0; idx < calendar_child_count; idx++) {
|
||||
child = lv_obj_get_child(parent, idx);
|
||||
if(lv_obj_check_type(child, &lv_calendar_header_dropdown_class)) {
|
||||
child_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!child_found) return;
|
||||
|
||||
child_found = false;
|
||||
const uint32_t header_child_count = lv_obj_get_child_cnt(child);
|
||||
|
||||
/* Search for the year dropdown */
|
||||
for(idx = 0; idx < header_child_count; idx++) {
|
||||
child = lv_obj_get_child(child, idx);
|
||||
if(lv_obj_check_type(child, &lv_dropdown_class)) {
|
||||
child_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!child_found) return;
|
||||
|
||||
lv_dropdown_clear_options(child);
|
||||
lv_dropdown_set_options(child, years_list);
|
||||
|
||||
lv_obj_invalidate(parent);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -120,7 +159,14 @@ static void year_event_cb(lv_event_t * e)
|
||||
const lv_calendar_date_t * d;
|
||||
d = lv_calendar_get_showed_date(calendar);
|
||||
lv_calendar_date_t newd = *d;
|
||||
newd.year = 2023 - sel;
|
||||
|
||||
/* Get the first year on the options list
|
||||
* NOTE: Assumes the first 4 digits in the option list are numbers */
|
||||
const char * year_p = lv_dropdown_get_options(dropdown);
|
||||
const uint32_t year = (year_p[0] - '0') * 1000 + (year_p[1] - '0') * 100 + (year_p[2] - '0') * 10 +
|
||||
(year_p[3] - '0');
|
||||
|
||||
newd.year = year - sel;
|
||||
|
||||
lv_calendar_set_showed_date(calendar, newd.year, newd.month);
|
||||
}
|
||||
@@ -132,7 +178,14 @@ static void value_changed_event_cb(lv_event_t * e)
|
||||
const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar);
|
||||
|
||||
lv_obj_t * year_dd = lv_obj_get_child(header, 0);
|
||||
lv_dropdown_set_selected(year_dd, 2023 - cur_date->year);
|
||||
|
||||
/* Get the first year on the options list
|
||||
* NOTE: Assumes the first 4 digits in the option list are numbers */
|
||||
const char * year_p = lv_dropdown_get_options(year_dd);
|
||||
const uint32_t year = (year_p[0] - '0') * 1000 + (year_p[1] - '0') * 100 + (year_p[2] - '0') * 10 +
|
||||
(year_p[3] - '0');
|
||||
|
||||
lv_dropdown_set_selected(year_dd, year - cur_date->year);
|
||||
|
||||
lv_obj_t * month_dd = lv_obj_get_child(header, 1);
|
||||
lv_dropdown_set_selected(month_dd, cur_date->month - 1);
|
||||
|
||||
@@ -36,6 +36,15 @@ extern const lv_obj_class_t lv_calendar_header_dropdown_class;
|
||||
*/
|
||||
lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent);
|
||||
|
||||
/**
|
||||
* Sets a custom calendar year list
|
||||
* @param parent pointer to a calendar object
|
||||
* @param years_list pointer to an const char array with the years list, see lv_dropdown set_options for more information.
|
||||
* E.g. `const char * years = "2023\n2022\n2021\n2020\n2019"
|
||||
* Only the pointer will be saved so this variable can't be local which will be destroyed later.
|
||||
*/
|
||||
void lv_calendar_header_dropdown_set_year_list(lv_obj_t * parent, const char * years_list);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -181,7 +181,6 @@ void lv_chart_set_div_line_count(lv_obj_t * obj, uint8_t hdiv, uint8_t vdiv)
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
|
||||
void lv_chart_set_zoom_x(lv_obj_t * obj, uint16_t zoom_x)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
@@ -261,10 +260,10 @@ uint16_t lv_chart_get_point_count(const lv_obj_t * obj)
|
||||
|
||||
uint16_t lv_chart_get_x_start_point(const lv_obj_t * obj, lv_chart_series_t * ser)
|
||||
{
|
||||
LV_UNUSED(obj);
|
||||
LV_ASSERT_NULL(ser);
|
||||
lv_chart_t * chart = (lv_chart_t *)obj;
|
||||
|
||||
return ser->start_point;
|
||||
return chart->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
|
||||
}
|
||||
|
||||
void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_point_t * p_out)
|
||||
@@ -292,28 +291,34 @@ void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint1
|
||||
}
|
||||
else if(chart->type == LV_CHART_TYPE_BAR) {
|
||||
uint32_t ser_cnt = _lv_ll_get_len(&chart->series_ll);
|
||||
int32_t ser_gap = ((int32_t)lv_obj_get_style_pad_column(obj,
|
||||
LV_PART_ITEMS) * chart->zoom_x) >> 8; /*Gap between the column on the ~same X*/
|
||||
int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj,
|
||||
LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/
|
||||
lv_coord_t block_w = (w - ((chart->point_cnt - 1) * block_gap)) / chart->point_cnt;
|
||||
lv_coord_t col_w = block_w / ser_cnt;
|
||||
/*Gap between the column on the X tick*/
|
||||
int32_t ser_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_ITEMS) * chart->zoom_x) >> 8;
|
||||
|
||||
p_out->x = (int32_t)((int32_t)w * id) / chart->point_cnt;
|
||||
/*Gap between the columns on adjacent X ticks*/
|
||||
int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_MAIN) * chart->zoom_x) >> 8;
|
||||
|
||||
lv_coord_t block_w = (w - ((chart->point_cnt - 1) * block_gap)) / chart->point_cnt;
|
||||
|
||||
lv_chart_series_t * ser_i = NULL;
|
||||
uint32_t ser_idx = 0;
|
||||
_LV_LL_READ_BACK(&chart->series_ll, ser_i) {
|
||||
if(ser_i == ser) break;
|
||||
p_out->x += col_w;
|
||||
ser_idx++;
|
||||
}
|
||||
|
||||
p_out->x += (col_w - ser_gap) / 2;
|
||||
p_out->x = (int32_t)((int32_t)(w + block_gap) * id) / chart->point_cnt;
|
||||
p_out->x += block_w * ser_idx / ser_cnt;
|
||||
|
||||
lv_coord_t col_w = (block_w - (ser_gap * (ser_cnt - 1))) / ser_cnt;
|
||||
p_out->x += col_w / 2;
|
||||
}
|
||||
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
p_out->x += lv_obj_get_style_pad_left(obj, LV_PART_MAIN) + border_width;
|
||||
p_out->x -= lv_obj_get_scroll_left(obj);
|
||||
|
||||
uint32_t start_point = lv_chart_get_x_start_point(obj, ser);
|
||||
id = ((int32_t)start_point + id) % chart->point_cnt;
|
||||
int32_t temp_y = 0;
|
||||
temp_y = (int32_t)((int32_t)ser->y_points[id] - chart->ymin[ser->y_axis_sec]) * h;
|
||||
temp_y = temp_y / (chart->ymax[ser->y_axis_sec] - chart->ymin[ser->y_axis_sec]);
|
||||
@@ -383,6 +388,7 @@ void lv_chart_remove_series(lv_obj_t * obj, lv_chart_series_t * series)
|
||||
|
||||
lv_chart_t * chart = (lv_chart_t *)obj;
|
||||
if(!series->y_ext_buf_assigned && series->y_points) lv_mem_free(series->y_points);
|
||||
if(!series->x_ext_buf_assigned && series->x_points) lv_mem_free(series->x_points);
|
||||
|
||||
_lv_ll_remove(&chart->series_ll, series);
|
||||
lv_mem_free(series);
|
||||
@@ -399,7 +405,6 @@ void lv_chart_hide_series(lv_obj_t * chart, lv_chart_series_t * series, bool hid
|
||||
lv_chart_refresh(chart);
|
||||
}
|
||||
|
||||
|
||||
void lv_chart_set_series_color(lv_obj_t * chart, lv_chart_series_t * series, lv_color_t color)
|
||||
{
|
||||
LV_ASSERT_OBJ(chart, MY_CLASS);
|
||||
@@ -476,7 +481,6 @@ void lv_chart_set_cursor_pos(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_po
|
||||
lv_chart_refresh(chart);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the coordinate of the cursor with respect
|
||||
* to the origin of series area of the chart.
|
||||
@@ -514,7 +518,6 @@ lv_point_t lv_chart_get_cursor_point(lv_obj_t * chart, lv_chart_cursor_t * curso
|
||||
* Set/Get value(s)
|
||||
*====================*/
|
||||
|
||||
|
||||
void lv_chart_set_all_value(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t value)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
@@ -904,7 +907,7 @@ static void draw_series_line(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
if(LV_MIN(point_w, point_h) > line_dsc_default.width / 2) line_dsc_default.raw_end = 1;
|
||||
if(line_dsc_default.width == 1) line_dsc_default.raw_end = 1;
|
||||
|
||||
/*If there are more points than pixels draw only vertical lines*/
|
||||
/*If there are at least as much points as pixels then draw only vertical lines*/
|
||||
bool crowded_mode = chart->point_cnt >= w ? true : false;
|
||||
|
||||
/*Go through all data lines*/
|
||||
@@ -913,7 +916,7 @@ static void draw_series_line(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
line_dsc_default.color = ser->color;
|
||||
point_dsc_default.bg_color = ser->color;
|
||||
|
||||
lv_coord_t start_point = chart->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
|
||||
lv_coord_t start_point = lv_chart_get_x_start_point(obj, ser);
|
||||
|
||||
p1.x = x_ofs;
|
||||
p2.x = x_ofs;
|
||||
@@ -1075,7 +1078,7 @@ static void draw_series_scatter(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
line_dsc_default.color = ser->color;
|
||||
point_dsc_default.bg_color = ser->color;
|
||||
|
||||
lv_coord_t start_point = chart->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
|
||||
lv_coord_t start_point = lv_chart_get_x_start_point(obj, ser);
|
||||
|
||||
p1.x = x_ofs;
|
||||
p2.x = x_ofs;
|
||||
@@ -1182,7 +1185,6 @@ static void draw_series_bar(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
const lv_area_t * clip_area_ori = draw_ctx->clip_area;
|
||||
draw_ctx->clip_area = &clip_area;
|
||||
|
||||
|
||||
lv_chart_t * chart = (lv_chart_t *)obj;
|
||||
|
||||
uint16_t i;
|
||||
@@ -1197,11 +1199,14 @@ static void draw_series_bar(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj,
|
||||
LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/
|
||||
lv_coord_t block_w = (w - ((chart->point_cnt - 1) * block_gap)) / chart->point_cnt;
|
||||
lv_coord_t col_w = block_w / ser_cnt;
|
||||
int32_t ser_gap = ((int32_t)lv_obj_get_style_pad_column(obj,
|
||||
LV_PART_ITEMS) * chart->zoom_x) >> 8; /*Gap between the column on the ~same X*/
|
||||
lv_coord_t x_ofs = pad_left - lv_obj_get_scroll_left(obj);
|
||||
lv_coord_t y_ofs = pad_top - lv_obj_get_scroll_top(obj);
|
||||
LV_PART_ITEMS) * chart->zoom_x) >> 8; /*Gap between the columns on the ~same X*/
|
||||
lv_coord_t col_w = (block_w - (ser_cnt - 1) * ser_gap) / ser_cnt;
|
||||
if(col_w < 1) col_w = 1;
|
||||
|
||||
lv_coord_t border_w = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
lv_coord_t x_ofs = pad_left - lv_obj_get_scroll_left(obj) + border_w;
|
||||
lv_coord_t y_ofs = pad_top - lv_obj_get_scroll_top(obj) + border_w;
|
||||
|
||||
lv_draw_rect_dsc_t col_dsc;
|
||||
lv_draw_rect_dsc_init(&col_dsc);
|
||||
@@ -1220,18 +1225,19 @@ static void draw_series_bar(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
|
||||
/*Go through all points*/
|
||||
for(i = 0; i < chart->point_cnt; i++) {
|
||||
lv_coord_t x_act = (int32_t)((int32_t)(w + block_gap) * i) / (chart->point_cnt) + obj->coords.x1 + x_ofs;
|
||||
lv_coord_t x_act = (int32_t)((int32_t)(w - block_w) * i) / (chart->point_cnt - 1) + obj->coords.x1 + x_ofs;
|
||||
|
||||
part_draw_dsc.id = i;
|
||||
|
||||
/*Draw the current point of all data line*/
|
||||
_LV_LL_READ_BACK(&chart->series_ll, ser) {
|
||||
if(ser->hidden) continue;
|
||||
lv_coord_t start_point = chart->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
|
||||
|
||||
lv_coord_t start_point = lv_chart_get_x_start_point(obj, ser);
|
||||
|
||||
col_a.x1 = x_act;
|
||||
col_a.x2 = col_a.x1 + col_w - ser_gap - 1;
|
||||
x_act += col_w;
|
||||
col_a.x2 = col_a.x1 + col_w - 1;
|
||||
x_act += col_w + ser_gap;
|
||||
|
||||
if(col_a.x2 < clip_area.x1) continue;
|
||||
if(col_a.x1 > clip_area.x2) break;
|
||||
@@ -1325,7 +1331,8 @@ static void draw_cursors(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
cy += obj->coords.y1;
|
||||
|
||||
lv_area_t point_area;
|
||||
if(point_w && point_h) {
|
||||
bool draw_point = point_w && point_h;
|
||||
if(draw_point) {
|
||||
point_area.x1 = cx - point_w;
|
||||
point_area.x2 = cx + point_w;
|
||||
point_area.y1 = cy - point_h;
|
||||
@@ -1345,7 +1352,11 @@ static void draw_cursors(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
|
||||
lv_draw_line(draw_ctx, &line_dsc_tmp, &p1, &p2);
|
||||
lv_draw_rect(draw_ctx, &point_dsc_tmp, &point_area);
|
||||
|
||||
if(draw_point) {
|
||||
lv_draw_rect(draw_ctx, &point_dsc_tmp, &point_area);
|
||||
}
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc);
|
||||
}
|
||||
|
||||
@@ -1357,7 +1368,11 @@ static void draw_cursors(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
|
||||
lv_draw_line(draw_ctx, &line_dsc_tmp, &p1, &p2);
|
||||
lv_draw_rect(draw_ctx, &point_dsc_tmp, &point_area);
|
||||
|
||||
if(draw_point) {
|
||||
lv_draw_rect(draw_ctx, &point_dsc_tmp, &point_area);
|
||||
}
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc);
|
||||
}
|
||||
}
|
||||
@@ -1371,8 +1386,10 @@ static void draw_y_ticks(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, lv_chart_axis
|
||||
|
||||
lv_chart_tick_dsc_t * t = get_tick_gsc(obj, axis);
|
||||
|
||||
if(t->major_cnt <= 1) return;
|
||||
if(!t->label_en && !t->major_len && !t->minor_len) return;
|
||||
if(t->major_cnt <= 1) return;
|
||||
uint32_t total_tick_num = (t->major_cnt - 1) * (t->minor_cnt);
|
||||
if(total_tick_num == 0) return;
|
||||
|
||||
uint8_t sec_axis = axis == LV_CHART_AXIS_PRIMARY_Y ? 0 : 1;
|
||||
|
||||
@@ -1422,7 +1439,6 @@ static void draw_y_ticks(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, lv_chart_axis
|
||||
part_draw_dsc.line_dsc = &line_dsc;
|
||||
part_draw_dsc.label_dsc = &label_dsc;
|
||||
|
||||
uint32_t total_tick_num = (t->major_cnt - 1) * (t->minor_cnt);
|
||||
for(i = 0; i <= total_tick_num; i++) {
|
||||
/*draw a line at moving y position*/
|
||||
p2.y = p1.y = y_ofs + (int32_t)((int32_t)(h - line_dsc.width) * i) / total_tick_num;
|
||||
@@ -1503,6 +1519,8 @@ static void draw_x_ticks(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, lv_chart_axis
|
||||
lv_chart_tick_dsc_t * t = get_tick_gsc(obj, axis);
|
||||
if(t->major_cnt <= 1) return;
|
||||
if(!t->label_en && !t->major_len && !t->minor_len) return;
|
||||
uint32_t total_tick_num = (t->major_cnt - 1) * (t->minor_cnt);
|
||||
if(total_tick_num == 0) return;
|
||||
|
||||
uint32_t i;
|
||||
lv_point_t p1;
|
||||
@@ -1511,7 +1529,6 @@ static void draw_x_ticks(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, lv_chart_axis
|
||||
lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN) + lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
lv_coord_t w = ((int32_t)lv_obj_get_content_width(obj) * chart->zoom_x) >> 8;
|
||||
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_TICKS, &label_dsc);
|
||||
@@ -1521,16 +1538,16 @@ static void draw_x_ticks(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, lv_chart_axis
|
||||
lv_coord_t label_gap;
|
||||
if(axis == LV_CHART_AXIS_PRIMARY_X) {
|
||||
label_gap = t->label_en ? lv_obj_get_style_pad_bottom(obj, LV_PART_TICKS) : 0;
|
||||
y_ofs = obj->coords.y2;
|
||||
y_ofs = obj->coords.y2 + 1;
|
||||
}
|
||||
else {
|
||||
label_gap = t->label_en ? lv_obj_get_style_pad_top(obj, LV_PART_TICKS) : 0;
|
||||
y_ofs = obj->coords.y1;
|
||||
y_ofs = obj->coords.y1 - 1;
|
||||
}
|
||||
|
||||
if(axis == LV_CHART_AXIS_PRIMARY_X) {
|
||||
if(y_ofs > draw_ctx->clip_area->y2) return;
|
||||
if(y_ofs + label_gap + label_dsc.font->line_height + t->major_len < draw_ctx->clip_area->y1) return;
|
||||
if(y_ofs + label_gap + label_dsc.font->line_height + t->major_len < draw_ctx->clip_area->y1) return;
|
||||
}
|
||||
|
||||
lv_draw_line_dsc_t line_dsc;
|
||||
@@ -1555,12 +1572,12 @@ static void draw_x_ticks(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, lv_chart_axis
|
||||
int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj,
|
||||
LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the columns on ~adjacent X*/
|
||||
lv_coord_t block_w = (w + block_gap) / (chart->point_cnt);
|
||||
|
||||
x_ofs += (block_w - block_gap) / 2;
|
||||
w -= block_w - block_gap;
|
||||
}
|
||||
|
||||
p1.y = y_ofs;
|
||||
uint32_t total_tick_num = (t->major_cnt - 1) * t->minor_cnt;
|
||||
for(i = 0; i <= total_tick_num; i++) { /*one extra loop - it may not exist in the list, empty label*/
|
||||
bool major = false;
|
||||
if(i % t->minor_cnt == 0) major = true;
|
||||
@@ -1623,7 +1640,6 @@ static void draw_x_ticks(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, lv_chart_axis
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
|
||||
}
|
||||
|
||||
|
||||
if(p1.x + line_dsc.width / 2 >= obj->coords.x1 &&
|
||||
p2.x - line_dsc.width / 2 <= obj->coords.x2) {
|
||||
lv_draw_line(draw_ctx, &line_dsc, &p1, &p2);
|
||||
@@ -1704,11 +1720,13 @@ static void invalidate_point(lv_obj_t * obj, uint16_t i)
|
||||
lv_area_t col_a;
|
||||
int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj,
|
||||
LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/
|
||||
|
||||
lv_coord_t block_w = (w + block_gap) / chart->point_cnt;
|
||||
|
||||
lv_coord_t bwidth = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
lv_coord_t x_act;
|
||||
x_act = (int32_t)((int32_t)(block_w) * i) ;
|
||||
x_act += obj->coords.x1 + lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
x_act += obj->coords.x1 + bwidth + lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
|
||||
lv_obj_get_coords(obj, &col_a);
|
||||
col_a.x1 = x_act - scroll_left;
|
||||
@@ -1785,5 +1803,4 @@ lv_chart_tick_dsc_t * get_tick_gsc(lv_obj_t * obj, lv_chart_axis_t axis)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -98,7 +98,6 @@ typedef struct {
|
||||
uint32_t label_en : 1;
|
||||
} lv_chart_tick_dsc_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
lv_ll_t series_ll; /**< Linked list for the series (stores lv_chart_series_t)*/
|
||||
@@ -315,8 +314,6 @@ void lv_chart_set_x_start_point(lv_obj_t * obj, lv_chart_series_t * ser, uint16_
|
||||
*/
|
||||
lv_chart_series_t * lv_chart_get_series_next(const lv_obj_t * chart, const lv_chart_series_t * ser);
|
||||
|
||||
|
||||
|
||||
/*=====================
|
||||
* Cursor
|
||||
*====================*/
|
||||
|
||||
@@ -160,7 +160,6 @@ void lv_colorwheel_set_mode_fixed(lv_obj_t * obj, bool fixed)
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
|
||||
/**
|
||||
* Get the current selected hsv of a color wheel.
|
||||
* @param colorwheel pointer to color wheel object
|
||||
@@ -536,8 +535,6 @@ static void lv_colorwheel_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void next_color_mode(lv_obj_t * obj)
|
||||
{
|
||||
lv_colorwheel_t * colorwheel = (lv_colorwheel_t *)obj;
|
||||
@@ -613,7 +610,6 @@ static lv_res_t double_click_reset(lv_obj_t * obj)
|
||||
* We replace division by 255 by a division by 256, a.k.a a shift right by 8 bits.
|
||||
* This is wrong, but since this is only used to compute the pixels on the screen and not the final color, it's ok.
|
||||
*/
|
||||
static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t * r, uint8_t * g, uint8_t * b);
|
||||
static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t * r, uint8_t * g, uint8_t * b)
|
||||
{
|
||||
if(!s) {
|
||||
@@ -652,6 +648,11 @@ static lv_color_t angle_to_mode_color_fast(lv_obj_t * obj, uint16_t angle)
|
||||
uint8_t r = 0, g = 0, b = 0;
|
||||
static uint16_t h = 0;
|
||||
static uint8_t s = 0, v = 0, m = 255;
|
||||
static uint16_t angle_saved = 0xffff;
|
||||
|
||||
/*If the angle is different recalculate scaling*/
|
||||
if(angle_saved != angle) m = 255;
|
||||
angle_saved = angle;
|
||||
|
||||
switch(ext->mode) {
|
||||
default:
|
||||
|
||||
@@ -32,7 +32,6 @@ enum {
|
||||
};
|
||||
typedef uint8_t lv_colorwheel_mode_t;
|
||||
|
||||
|
||||
/*Data of color picker*/
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
@@ -139,4 +138,3 @@ bool lv_colorwheel_get_color_mode_fixed(lv_obj_t * obj);
|
||||
#endif
|
||||
|
||||
#endif /*LV_COLORWHEEL_H*/
|
||||
|
||||
|
||||
@@ -112,7 +112,6 @@ void lv_imgbtn_set_state(lv_obj_t * obj, lv_imgbtn_state_t state)
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
|
||||
/**
|
||||
* Get the left image in a given state
|
||||
* @param obj pointer to an image button object
|
||||
@@ -156,7 +155,6 @@ const void * lv_imgbtn_get_src_right(lv_obj_t * obj, lv_imgbtn_state_t state)
|
||||
return imgbtn->img_src_right[state];
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -173,7 +171,6 @@ static void lv_imgbtn_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj
|
||||
imgbtn->act_cf = LV_IMG_CF_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
static void lv_imgbtn_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
{
|
||||
LV_UNUSED(class_p);
|
||||
@@ -205,6 +202,15 @@ static void lv_imgbtn_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
p->x = LV_MAX(p->x, header.w);
|
||||
}
|
||||
}
|
||||
/*Sent when the widget is checked due to LV_OBJ_FLAG_CHECKABLE */
|
||||
else if(code == LV_EVENT_VALUE_CHANGED) {
|
||||
if(lv_obj_has_state(obj, LV_STATE_CHECKED)) {
|
||||
lv_imgbtn_set_state(obj, LV_IMGBTN_STATE_CHECKED_RELEASED);
|
||||
}
|
||||
else {
|
||||
lv_imgbtn_set_state(obj, LV_IMGBTN_STATE_RELEASED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_main(lv_event_t * e)
|
||||
@@ -266,7 +272,6 @@ static void draw_main(lv_event_t * e)
|
||||
clip_area_center.y1 = coords.y1;
|
||||
clip_area_center.y2 = coords.y2;
|
||||
|
||||
|
||||
bool comm_res;
|
||||
comm_res = _lv_area_intersect(&clip_area_center, &clip_area_center, draw_ctx->clip_area);
|
||||
if(comm_res) {
|
||||
|
||||
@@ -77,7 +77,6 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * parent);
|
||||
void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_imgbtn_state_t state, const void * src_left, const void * src_mid,
|
||||
const void * src_right);
|
||||
|
||||
|
||||
/**
|
||||
* Use this function instead of `lv_obj_add/clear_state` to set a state manually
|
||||
* @param imgbtn pointer to an image button object
|
||||
@@ -113,7 +112,6 @@ const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_imgbtn_state_t state
|
||||
*/
|
||||
const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_imgbtn_state_t state);
|
||||
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
@@ -73,7 +73,7 @@ static const lv_btnmatrix_ctrl_t default_kb_ctrl_uc_map[] = {
|
||||
};
|
||||
|
||||
static const char * const default_kb_map_spec[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", LV_SYMBOL_BACKSPACE, "\n",
|
||||
"abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
|
||||
"abc", "+", "&", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
|
||||
"\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n",
|
||||
LV_SYMBOL_KEYBOARD, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""
|
||||
};
|
||||
|
||||
@@ -178,6 +178,7 @@ static void lv_led_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_MAIN, &rect_dsc);
|
||||
|
||||
/*Use the original colors brightness to modify color->led*/
|
||||
rect_dsc.bg_color = lv_color_mix(led->color, lv_color_black(), lv_color_brightness(rect_dsc.bg_color));
|
||||
rect_dsc.bg_grad.stops[0].color = lv_color_mix(led->color, lv_color_black(),
|
||||
lv_color_brightness(rect_dsc.bg_grad.stops[0].color));
|
||||
rect_dsc.bg_grad.stops[1].color = lv_color_mix(led->color, lv_color_black(),
|
||||
@@ -187,6 +188,7 @@ static void lv_led_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
rect_dsc.outline_color = lv_color_mix(led->color, lv_color_black(), lv_color_brightness(rect_dsc.outline_color));
|
||||
|
||||
/*Mix. the color with black proportionally with brightness*/
|
||||
rect_dsc.bg_color = lv_color_mix(rect_dsc.bg_color, lv_color_black(), led->bright);
|
||||
rect_dsc.bg_grad.stops[0].color = lv_color_mix(rect_dsc.bg_grad.stops[0].color, lv_color_black(), led->bright);
|
||||
rect_dsc.bg_grad.stops[1].color = lv_color_mix(rect_dsc.bg_grad.stops[1].color, lv_color_black(), led->bright);
|
||||
rect_dsc.border_color = lv_color_mix(rect_dsc.border_color, lv_color_black(), led->bright);
|
||||
|
||||
@@ -17,7 +17,6 @@ extern "C" {
|
||||
|
||||
#if LV_USE_LED
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@@ -112,5 +111,4 @@ uint8_t lv_led_get_brightness(const lv_obj_t * obj);
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*LV_LED_H*/
|
||||
|
||||
@@ -195,6 +195,11 @@ void lv_menu_set_page(lv_obj_t * obj, lv_obj_t * page)
|
||||
|
||||
lv_menu_t * menu = (lv_menu_t *)obj;
|
||||
|
||||
/* Guard against setting the same page again */
|
||||
if(menu->main_page == page) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Hide previous page */
|
||||
if(menu->main_page != NULL) {
|
||||
lv_obj_set_parent(menu->main_page, menu->storage);
|
||||
|
||||
@@ -336,7 +336,7 @@ static void draw_arcs(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, const lv_area_t
|
||||
scale_center.x = scale_area->x1 + r_out;
|
||||
scale_center.y = scale_area->y1 + r_out;
|
||||
|
||||
lv_opa_t opa_main = lv_obj_get_style_opa(obj, LV_PART_MAIN);
|
||||
lv_opa_t opa_main = lv_obj_get_style_opa_recursive(obj, LV_PART_MAIN);
|
||||
lv_meter_indicator_t * indic;
|
||||
|
||||
lv_obj_draw_part_dsc_t part_draw_dsc;
|
||||
@@ -360,6 +360,8 @@ static void draw_arcs(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, const lv_area_t
|
||||
int32_t end_angle = lv_map(indic->end_value, scale->min, scale->max, scale->rotation,
|
||||
scale->rotation + scale->angle_range);
|
||||
|
||||
arc_dsc.start_angle = start_angle;
|
||||
arc_dsc.end_angle = end_angle;
|
||||
part_draw_dsc.radius = r_out + indic->type_data.arc.r_mod;
|
||||
part_draw_dsc.sub_part_ptr = indic;
|
||||
part_draw_dsc.p1 = &scale_center;
|
||||
@@ -404,7 +406,7 @@ static void draw_ticks_and_labels(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, cons
|
||||
_LV_LL_READ_BACK(&meter->scale_ll, scale) {
|
||||
part_draw_dsc.sub_part_ptr = scale;
|
||||
|
||||
lv_coord_t r_out = r_edge + scale->r_mod;
|
||||
lv_coord_t r_out = r_edge;
|
||||
lv_coord_t r_in_minor = r_out - scale->tick_length;
|
||||
lv_coord_t r_in_major = r_out - scale->tick_major_length;
|
||||
|
||||
@@ -473,32 +475,20 @@ static void draw_ticks_and_labels(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, cons
|
||||
}
|
||||
}
|
||||
|
||||
/*`* 256` for extra precision*/
|
||||
int32_t angle_upscale = ((i * scale->angle_range) << 8) / (scale->tick_cnt - 1);
|
||||
|
||||
int32_t angle_low = (angle_upscale >> 8);
|
||||
int32_t angle_high = angle_low + 1;
|
||||
int32_t angle_rem = angle_upscale & 0xFF;
|
||||
|
||||
/*Interpolate sine and cos*/
|
||||
int32_t sin_low = lv_trigo_sin(angle_low + scale->rotation);
|
||||
int32_t sin_high = lv_trigo_sin(angle_high + scale->rotation);
|
||||
int32_t sin_mid = (sin_low * (256 - angle_rem) + sin_high * angle_rem) >> 8;
|
||||
|
||||
int32_t cos_low = lv_trigo_cos(angle_low + scale->rotation);
|
||||
int32_t cos_high = lv_trigo_cos(angle_high + scale->rotation);
|
||||
int32_t cos_mid = (cos_low * (256 - angle_rem) + cos_high * angle_rem) >> 8;
|
||||
int32_t angle_upscale = ((i * scale->angle_range) * 10) / (scale->tick_cnt - 1) + + scale->rotation * 10;
|
||||
|
||||
line_dsc.color = line_color;
|
||||
line_dsc.width = line_width;
|
||||
/*Use the interpolated angle to get the outer x and y coordinates.
|
||||
*Draw a little bit longer lines to be sure the mask will clip them correctly*/
|
||||
lv_point_t p_outer;
|
||||
p_outer.x = (int32_t)(((int32_t)cos_mid * (r_out + line_width) + 127) >> (LV_TRIGO_SHIFT)) + p_center.x;
|
||||
p_outer.y = (int32_t)(((int32_t)sin_mid * (r_out + line_width) + 127) >> (LV_TRIGO_SHIFT)) + p_center.y;
|
||||
|
||||
part_draw_dsc.p1 = &p_outer;
|
||||
/*Draw a little bit longer lines to be sure the mask will clip them correctly
|
||||
*and to get a better precision*/
|
||||
lv_point_t p_outer;
|
||||
p_outer.x = p_center.x + r_out + LV_MAX(LV_DPI_DEF, r_out);
|
||||
p_outer.y = p_center.y;
|
||||
lv_point_transform(&p_outer, angle_upscale, 256, &p_center);
|
||||
|
||||
part_draw_dsc.p1 = &p_center;
|
||||
part_draw_dsc.p2 = &p_outer;
|
||||
part_draw_dsc.id = i;
|
||||
part_draw_dsc.label_dsc = &label_dsc;
|
||||
|
||||
@@ -507,8 +497,9 @@ static void draw_ticks_and_labels(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, cons
|
||||
lv_draw_mask_remove_id(outer_mask_id);
|
||||
uint32_t r_text = r_in_major - scale->label_gap;
|
||||
lv_point_t p;
|
||||
p.x = (int32_t)((int32_t)((int32_t)cos_mid * r_text + 127) >> LV_TRIGO_SHIFT) + p_center.x;
|
||||
p.y = (int32_t)((int32_t)((int32_t)sin_mid * r_text + 127) >> LV_TRIGO_SHIFT) + p_center.y;
|
||||
p.x = p_center.x + r_text;
|
||||
p.y = p_center.y;
|
||||
lv_point_transform(&p, angle_upscale, 256, &p_center);
|
||||
|
||||
lv_draw_label_dsc_t label_dsc_tmp;
|
||||
lv_memcpy(&label_dsc_tmp, &label_dsc, sizeof(label_dsc_tmp));
|
||||
@@ -522,7 +513,8 @@ static void draw_ticks_and_labels(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, cons
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
|
||||
|
||||
lv_point_t label_size;
|
||||
lv_txt_get_size(&label_size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
lv_txt_get_size(&label_size, part_draw_dsc.text, label_dsc_tmp.font, label_dsc_tmp.letter_space,
|
||||
label_dsc_tmp.line_space,
|
||||
LV_COORD_MAX, LV_TEXT_FLAG_NONE);
|
||||
|
||||
lv_area_t label_cord;
|
||||
@@ -557,7 +549,6 @@ static void draw_ticks_and_labels(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, cons
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void draw_needles(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, const lv_area_t * scale_area)
|
||||
{
|
||||
lv_meter_t * meter = (lv_meter_t *)obj;
|
||||
@@ -574,12 +565,13 @@ static void draw_needles(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, const lv_area
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
lv_obj_init_draw_img_dsc(obj, LV_PART_ITEMS, &img_dsc);
|
||||
lv_opa_t opa_main = lv_obj_get_style_opa(obj, LV_PART_MAIN);
|
||||
lv_opa_t opa_main = lv_obj_get_style_opa_recursive(obj, LV_PART_MAIN);
|
||||
|
||||
lv_obj_draw_part_dsc_t part_draw_dsc;
|
||||
lv_obj_draw_dsc_init(&part_draw_dsc, draw_ctx);
|
||||
part_draw_dsc.class_p = MY_CLASS;
|
||||
part_draw_dsc.p1 = &scale_center;
|
||||
part_draw_dsc.part = LV_PART_INDICATOR;
|
||||
|
||||
lv_meter_indicator_t * indic;
|
||||
_LV_LL_READ_BACK(&meter->indicator_ll, indic) {
|
||||
@@ -596,12 +588,12 @@ static void draw_needles(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, const lv_area
|
||||
line_dsc.width = indic->type_data.needle_line.width;
|
||||
line_dsc.opa = indic->opa > LV_OPA_MAX ? opa_main : (opa_main * indic->opa) >> 8;
|
||||
|
||||
part_draw_dsc.id = LV_METER_DRAW_PART_NEEDLE_LINE;
|
||||
part_draw_dsc.type = LV_METER_DRAW_PART_NEEDLE_LINE;
|
||||
part_draw_dsc.line_dsc = &line_dsc;
|
||||
part_draw_dsc.p2 = &p_end;
|
||||
|
||||
part_draw_dsc.p1 = &scale_center;
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
|
||||
lv_draw_line(draw_ctx, &line_dsc, &scale_center, &p_end);
|
||||
lv_draw_line(draw_ctx, &line_dsc, part_draw_dsc.p1, &p_end);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc);
|
||||
}
|
||||
else if(indic->type == LV_METER_INDICATOR_TYPE_NEEDLE_IMG) {
|
||||
@@ -623,6 +615,7 @@ static void draw_needles(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx, const lv_area
|
||||
if(angle > 3600) angle -= 3600;
|
||||
img_dsc.angle = angle;
|
||||
|
||||
part_draw_dsc.type = LV_METER_DRAW_PART_NEEDLE_IMG;
|
||||
part_draw_dsc.img_dsc = &img_dsc;
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);
|
||||
@@ -657,7 +650,6 @@ static void inv_arc(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t old_va
|
||||
lv_obj_invalidate_area(obj, &a);
|
||||
}
|
||||
|
||||
|
||||
static void inv_line(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value)
|
||||
{
|
||||
lv_area_t scale_area;
|
||||
|
||||
@@ -42,7 +42,6 @@ typedef struct {
|
||||
uint16_t tick_major_width;
|
||||
|
||||
int16_t label_gap;
|
||||
int16_t label_color;
|
||||
|
||||
int32_t min;
|
||||
int32_t max;
|
||||
@@ -212,7 +211,6 @@ lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t
|
||||
lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color,
|
||||
int16_t r_mod);
|
||||
|
||||
|
||||
/**
|
||||
* Add a scale line indicator the scale. It will modify the ticks.
|
||||
* @param obj pointer to a meter object
|
||||
|
||||
@@ -106,6 +106,9 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char *
|
||||
}
|
||||
|
||||
mbox->content = lv_obj_class_create_obj(&lv_msgbox_content_class, obj);
|
||||
LV_ASSERT_MALLOC(mbox->content);
|
||||
if(mbox->content == NULL) return NULL;
|
||||
lv_obj_class_init_obj(mbox->content);
|
||||
|
||||
bool has_txt = txt && strlen(txt) > 0;
|
||||
if(has_txt) {
|
||||
@@ -135,7 +138,6 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char *
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
lv_obj_t * lv_msgbox_get_title(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
@@ -779,7 +779,7 @@ static void lv_draw_span(lv_obj_t * obj, lv_draw_ctx_t * draw_ctx)
|
||||
lv_coord_t max_width = lv_area_get_width(&coords);
|
||||
lv_coord_t indent = convert_indent_pct(obj, max_width);
|
||||
lv_coord_t max_w = max_width - indent; /* first line need minus indent */
|
||||
lv_opa_t obj_opa = lv_obj_get_style_opa(obj, LV_PART_MAIN);
|
||||
lv_opa_t obj_opa = lv_obj_get_style_opa_recursive(obj, LV_PART_MAIN);
|
||||
|
||||
/* coords of draw span-txt */
|
||||
lv_point_t txt_pos;
|
||||
|
||||
@@ -221,7 +221,6 @@ uint32_t lv_spangroup_get_expand_width(lv_obj_t * obj, uint32_t max_width);
|
||||
*/
|
||||
lv_coord_t lv_spangroup_get_expand_height(lv_obj_t * obj, lv_coord_t width);
|
||||
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
@@ -157,7 +157,7 @@ void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max)
|
||||
* @param spinbox pointer to spinbox
|
||||
* @param pos selected position in spinbox
|
||||
*/
|
||||
void lv_spinbox_set_pos(lv_obj_t * obj, uint8_t pos)
|
||||
void lv_spinbox_set_cursor_pos(lv_obj_t * obj, uint8_t pos)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_spinbox_t * spinbox = (lv_spinbox_t *)obj;
|
||||
@@ -434,9 +434,6 @@ static void lv_spinbox_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
else if(c == LV_KEY_DOWN) {
|
||||
lv_spinbox_decrement(obj);
|
||||
}
|
||||
else {
|
||||
lv_textarea_add_char(obj, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max);
|
||||
* @param obj pointer to spinbox
|
||||
* @param pos selected position in spinbox
|
||||
*/
|
||||
void lv_spinbox_set_pos(lv_obj_t * obj, uint8_t pos);
|
||||
void lv_spinbox_set_cursor_pos(lv_obj_t * obj, uint8_t pos);
|
||||
|
||||
/**
|
||||
* Set direction of digit step when clicking an encoder button while in editing mode
|
||||
@@ -170,6 +170,10 @@ void lv_spinbox_decrement(lv_obj_t * obj);
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/* It was ambiguous in MicroPython. See https://github.com/lvgl/lvgl/issues/3301
|
||||
* TODO remove in v9*/
|
||||
#define lv_spinbox_set_pos lv_spinbox_set_cursor_pos
|
||||
|
||||
#endif /*LV_USE_SPINBOX*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -58,7 +58,6 @@ lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_leng
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -89,13 +88,11 @@ static void lv_spinner_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob
|
||||
lv_arc_set_rotation(obj, 270);
|
||||
}
|
||||
|
||||
|
||||
static void arc_anim_start_angle(void * obj, int32_t v)
|
||||
{
|
||||
lv_arc_set_start_angle(obj, (uint16_t) v);
|
||||
}
|
||||
|
||||
|
||||
static void arc_anim_end_angle(void * obj, int32_t v)
|
||||
{
|
||||
lv_arc_set_end_angle(obj, (uint16_t) v);
|
||||
|
||||
@@ -77,8 +77,8 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name)
|
||||
|
||||
lv_obj_t * btns = lv_tabview_get_tab_btns(obj);
|
||||
|
||||
char ** old_map = tabview->map;
|
||||
char ** new_map;
|
||||
const char ** old_map = (const char **)tabview->map;
|
||||
const char ** new_map;
|
||||
|
||||
/*top or bottom dir*/
|
||||
if(tabview->tab_pos & LV_DIR_VER) {
|
||||
@@ -121,9 +121,25 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name)
|
||||
return page;
|
||||
}
|
||||
|
||||
void lv_tabview_rename_tab(lv_obj_t * obj, uint32_t id, const char * new_name)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_tabview_t * tabview = (lv_tabview_t *)obj;
|
||||
|
||||
if(id >= tabview->tab_cnt) return;
|
||||
if(tabview->tab_pos & LV_DIR_HOR) id *= 2;
|
||||
|
||||
lv_mem_free((void *)tabview->map[id]);
|
||||
tabview->map[id] = lv_mem_alloc(strlen(new_name) + 1);
|
||||
strcpy((void *)tabview->map[id], new_name);
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
void lv_tabview_set_act(lv_obj_t * obj, uint32_t id, lv_anim_enable_t anim_en)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
if(obj->being_deleted) return;
|
||||
|
||||
lv_tabview_t * tabview = (lv_tabview_t *)obj;
|
||||
|
||||
if(id >= tabview->tab_cnt) {
|
||||
@@ -257,18 +273,17 @@ static void lv_tabview_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj
|
||||
uint32_t i;
|
||||
if(tabview->tab_pos & LV_DIR_VER) {
|
||||
for(i = 0; i < tabview->tab_cnt; i++) {
|
||||
lv_mem_free(tabview->map[i]);
|
||||
lv_mem_free((void *)tabview->map[i]);
|
||||
tabview->map[i] = NULL;
|
||||
}
|
||||
}
|
||||
if(tabview->tab_pos & LV_DIR_HOR) {
|
||||
for(i = 0; i < tabview->tab_cnt; i++) {
|
||||
lv_mem_free(tabview->map[i * 2]);
|
||||
lv_mem_free((void *)tabview->map[i * 2]);
|
||||
tabview->map[i * 2] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lv_mem_free(tabview->map);
|
||||
tabview->map = NULL;
|
||||
}
|
||||
@@ -287,14 +302,13 @@ static void lv_tabview_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void btns_value_changed_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * btns = lv_event_get_target(e);
|
||||
|
||||
lv_obj_t * tv = lv_obj_get_parent(btns);
|
||||
uint32_t id = lv_btnmatrix_get_selected_btn(btns);
|
||||
lv_tabview_set_act(tv, id, LV_ANIM_ON);
|
||||
lv_tabview_set_act(tv, id, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
static void cont_scroll_end_event_cb(lv_event_t * e)
|
||||
@@ -308,6 +322,11 @@ static void cont_scroll_end_event_cb(lv_event_t * e)
|
||||
lv_tabview_set_act(tv, lv_tabview_get_tab_act(tv), LV_ANIM_OFF);
|
||||
}
|
||||
else if(code == LV_EVENT_SCROLL_END) {
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
if(indev && indev->proc.state == LV_INDEV_STATE_PRESSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
lv_point_t p;
|
||||
lv_obj_get_scroll_end(cont, &p);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ extern "C" {
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
char ** map;
|
||||
const char ** map;
|
||||
uint16_t tab_cnt;
|
||||
uint16_t tab_cur;
|
||||
lv_dir_t tab_pos;
|
||||
@@ -42,6 +42,8 @@ lv_obj_t * lv_tabview_create(lv_obj_t * parent, lv_dir_t tab_pos, lv_coord_t tab
|
||||
|
||||
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tv, const char * name);
|
||||
|
||||
void lv_tabview_rename_tab(lv_obj_t * obj, uint32_t tab_id, const char * new_name);
|
||||
|
||||
lv_obj_t * lv_tabview_get_content(lv_obj_t * tv);
|
||||
|
||||
lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_tileview.h"
|
||||
#include "../../../core/lv_indev.h"
|
||||
#if LV_USE_TILEVIEW
|
||||
|
||||
/*********************
|
||||
@@ -157,6 +158,11 @@ static void tileview_event_cb(lv_event_t * e)
|
||||
lv_tileview_t * tv = (lv_tileview_t *) obj;
|
||||
|
||||
if(code == LV_EVENT_SCROLL_END) {
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
if(indev && indev->proc.state == LV_INDEV_STATE_PRESSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
lv_coord_t w = lv_obj_get_content_width(obj);
|
||||
lv_coord_t h = lv_obj_get_content_height(obj);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "lv_win.h"
|
||||
#if LV_USE_WIN
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@@ -107,4 +106,3 @@ static void lv_win_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ extern const lv_obj_class_t lv_win_class;
|
||||
|
||||
lv_obj_t * lv_win_create(lv_obj_t * parent, lv_coord_t header_height);
|
||||
|
||||
|
||||
lv_obj_t * lv_win_add_title(lv_obj_t * win, const char * txt);
|
||||
lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user