mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Merge remote-tracking branch 'origin/dev-6.0' into long_txt
This commit is contained in:
commit
76e392edd5
@ -126,7 +126,10 @@ typedef int16_t lv_coord_t;
|
||||
/*1: Enable the Animations */
|
||||
#define LV_USE_ANIMATION 1
|
||||
#if LV_USE_ANIMATION
|
||||
|
||||
/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/
|
||||
typedef void * lv_anim_user_data_t;
|
||||
|
||||
#endif
|
||||
|
||||
/* 1: Enable shadow drawing*/
|
||||
@ -148,18 +151,30 @@ typedef void * lv_group_user_data_t;
|
||||
typedef void * lv_fs_drv_user_data_t;
|
||||
#endif
|
||||
|
||||
/*1: Add a `user_data` to drivers and objects*/
|
||||
#define LV_USE_USER_DATA 1
|
||||
|
||||
/*========================
|
||||
* Image decoder and cache
|
||||
*========================*/
|
||||
|
||||
/* 1: Enable indexed (palette) images */
|
||||
#define LV_IMG_CF_INDEXED 1
|
||||
|
||||
/* 1: Enable alpha indexed images */
|
||||
#define LV_IMG_CF_ALPHA 1
|
||||
|
||||
/* Default image cache size. Image caching keeps the images opened.
|
||||
* If only the built-in image formats are used there is no real advantage of caching.
|
||||
* (I.e. no new image decoder is added)
|
||||
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
|
||||
* However the opened images might consume additional RAM.
|
||||
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
|
||||
#define LV_IMG_CACHE_DEF_SIZE 1
|
||||
|
||||
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
|
||||
typedef void * lv_img_decoder_user_data_t;
|
||||
|
||||
/*1: Add a `user_data` to drivers and objects*/
|
||||
#define LV_USE_USER_DATA 1
|
||||
|
||||
/*=====================
|
||||
* Compiler settings
|
||||
*====================*/
|
||||
|
@ -2,7 +2,6 @@
|
||||
* GENERATED FILE, DO NOT EDIT IT!
|
||||
* @file lv_conf_checker.h
|
||||
* Make sure all the defines of lv_conf.h have a default value
|
||||
* \internal
|
||||
**/
|
||||
|
||||
#ifndef LV_CONF_CHECKER_H
|
||||
@ -175,6 +174,9 @@
|
||||
#define LV_USE_ANIMATION 1
|
||||
#endif
|
||||
#if LV_USE_ANIMATION
|
||||
|
||||
/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/
|
||||
|
||||
#endif
|
||||
|
||||
/* 1: Enable shadow drawing*/
|
||||
@ -202,6 +204,15 @@
|
||||
/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/
|
||||
#endif
|
||||
|
||||
/*1: Add a `user_data` to drivers and objects*/
|
||||
#ifndef LV_USE_USER_DATA
|
||||
#define LV_USE_USER_DATA 1
|
||||
#endif
|
||||
|
||||
/*========================
|
||||
* Image decoder and cache
|
||||
*========================*/
|
||||
|
||||
/* 1: Enable indexed (palette) images */
|
||||
#ifndef LV_IMG_CF_INDEXED
|
||||
#define LV_IMG_CF_INDEXED 1
|
||||
@ -212,13 +223,18 @@
|
||||
#define LV_IMG_CF_ALPHA 1
|
||||
#endif
|
||||
|
||||
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
|
||||
|
||||
/*1: Add a `user_data` to drivers and objects*/
|
||||
#ifndef LV_USE_USER_DATA
|
||||
#define LV_USE_USER_DATA 1
|
||||
/* Default image cache size. Image caching keeps the images opened.
|
||||
* If only the built-in image formats are used there is no real advantage of caching.
|
||||
* (I.e. no new image decoder is added)
|
||||
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
|
||||
* However the opened images might consume additional RAM.
|
||||
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
|
||||
#ifndef LV_IMG_CACHE_DEF_SIZE
|
||||
#define LV_IMG_CACHE_DEF_SIZE 1
|
||||
#endif
|
||||
|
||||
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
|
||||
|
||||
/*=====================
|
||||
* Compiler settings
|
||||
*====================*/
|
||||
@ -570,6 +586,12 @@
|
||||
#ifndef LV_USE_PAGE
|
||||
#define LV_USE_PAGE 1
|
||||
#endif
|
||||
#if LV_USE_PAGE != 0
|
||||
/*Focus default animation time [ms] (0: no animation)*/
|
||||
#ifndef LV_PAGE_DEF_ANIM_TIME
|
||||
# define LV_PAGE_DEF_ANIM_TIME 400
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Preload (dependencies: lv_arc, lv_anim)*/
|
||||
#ifndef LV_USE_PRELOAD
|
||||
|
@ -109,6 +109,7 @@ void lv_init(void)
|
||||
lv_indev_init();
|
||||
|
||||
lv_img_decoder_init();
|
||||
lv_img_cache_set_size(LV_IMG_CACHE_DEF_SIZE);
|
||||
|
||||
lv_initialized = true;
|
||||
LV_LOG_INFO("lv_init ready");
|
||||
|
@ -7,6 +7,7 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_img.h"
|
||||
#include "lv_img_cache.h"
|
||||
#include "../lv_misc/lv_log.h"
|
||||
|
||||
/*********************
|
||||
@ -445,29 +446,22 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
|
||||
lv_opa_t opa =
|
||||
opa_scale == LV_OPA_COVER ? style->image.opa : (uint16_t)((uint16_t)style->image.opa * opa_scale) >> 8;
|
||||
|
||||
lv_img_header_t header;
|
||||
lv_res_t header_res;
|
||||
header_res = lv_img_decoder_get_info(src, &header);
|
||||
if(header_res != LV_RES_OK) {
|
||||
LV_LOG_WARN("Image draw can't get image info");
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
bool chroma_keyed = lv_img_color_format_is_chroma_keyed(header.cf);
|
||||
bool alpha_byte = lv_img_color_format_has_alpha(header.cf);
|
||||
lv_img_cache_entry_t * cdsc = lv_img_cache_open(src, style);
|
||||
|
||||
if(cdsc == NULL) return LV_RES_INV;
|
||||
|
||||
|
||||
bool chroma_keyed = lv_img_color_format_is_chroma_keyed(cdsc->dsc.header.cf);
|
||||
bool alpha_byte = lv_img_color_format_has_alpha(cdsc->dsc.header.cf);
|
||||
|
||||
|
||||
|
||||
lv_img_decoder_dsc_t dsc;
|
||||
const uint8_t * img_data = lv_img_decoder_open(&dsc, src, style);
|
||||
if(img_data == LV_IMG_DECODER_OPEN_FAIL) {
|
||||
LV_LOG_WARN("Image draw cannot open the image resource");
|
||||
lv_img_decoder_close(&dsc);
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
/* The decoder open could open the image and gave the entire uncompressed image.
|
||||
* Just draw it!*/
|
||||
if(img_data) {
|
||||
lv_draw_map(coords, mask, img_data, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense);
|
||||
if(cdsc->img_data) {
|
||||
lv_draw_map(coords, mask, cdsc->img_data, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense);
|
||||
}
|
||||
/* The whole uncompressed image is not available. Try to read it line-by-line*/
|
||||
else {
|
||||
@ -486,9 +480,9 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
|
||||
lv_coord_t row;
|
||||
lv_res_t read_res;
|
||||
for(row = mask_com.y1; row <= mask_com.y2; row++) {
|
||||
read_res = lv_img_decoder_read_line(&dsc, x, y, width, buf);
|
||||
read_res = lv_img_decoder_read_line(&cdsc->dsc, x, y, width, buf);
|
||||
if(read_res != LV_RES_OK) {
|
||||
lv_img_decoder_close(&dsc);
|
||||
lv_img_decoder_close(&cdsc->dsc);
|
||||
LV_LOG_WARN("Image draw can't read the line");
|
||||
return LV_RES_INV;
|
||||
}
|
||||
@ -499,7 +493,5 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
|
||||
}
|
||||
}
|
||||
|
||||
lv_img_decoder_close(&dsc);
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
191
src/lv_draw/lv_img_cache.c
Normal file
191
src/lv_draw/lv_img_cache.c
Normal file
@ -0,0 +1,191 @@
|
||||
/**
|
||||
* @file lv_img_cache.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_img_cache.h"
|
||||
#include "../lv_hal/lv_hal_tick.h"
|
||||
#include "../lv_misc/lv_gc.h"
|
||||
|
||||
#if defined(LV_GC_INCLUDE)
|
||||
#include LV_GC_INCLUDE
|
||||
#endif /* LV_ENABLE_GC */
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
/*Decrement life with this value in every open*/
|
||||
#define LV_IMG_CACHE_AGING 1
|
||||
|
||||
/*Boost life by this factor (multiply time_to_open with this value)*/
|
||||
#define LV_IMG_CACHE_LIFE_GAIN 1
|
||||
|
||||
/*Don't let life to be greater than this limit because it would require a lot of time to
|
||||
* "die" from very high values */
|
||||
#define LV_IMG_CACHE_LIFE_LIMIT 1000
|
||||
|
||||
#if LV_IMG_CACHE_DEF_SIZE < 1
|
||||
#error "LV_IMG_CACHE_DEF_SIZE must be >= 1. See lv_conf.h"
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static uint16_t slot_num;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Open an image using the image decoder interface and cache it.
|
||||
* The image will be left open meaning if the image decoder open callback allocated memory then it will remain.
|
||||
* The image is closed if a new image is opened and the new image takes its place in the cache.
|
||||
* @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable
|
||||
* @param style style of the image
|
||||
* @return pointer to the cache entry or NULL if can open the image
|
||||
*/
|
||||
lv_img_cache_entry_t * lv_img_cache_open(const void * src, const lv_style_t * style)
|
||||
{
|
||||
if(slot_num == 0) {
|
||||
LV_LOG_WARN("lv_img_cache_open: the cache size is 0");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lv_img_cache_entry_t * cache = LV_GC_ROOT(_lv_img_cache_array);
|
||||
|
||||
/*Decrement all lifes. Make the entries older*/
|
||||
uint16_t i;
|
||||
for(i = 0; i < slot_num; i++) {
|
||||
if(cache[i].life > INT32_MIN + LV_IMG_CACHE_AGING) {
|
||||
cache[i].life -= LV_IMG_CACHE_AGING;
|
||||
}
|
||||
}
|
||||
|
||||
/*Is the image cached?*/
|
||||
lv_img_cache_entry_t * cached_src = NULL;
|
||||
for(i = 0; i < slot_num; i++) {
|
||||
if(cache[i].dsc.src == src) {
|
||||
/* If opened increment its life.
|
||||
* Image difficult to open should live longer to keep avoid frequent their recaching.
|
||||
* Therefore increase `life` with `time_to_open`*/
|
||||
cached_src = &cache[i];
|
||||
cached_src->life += cached_src->time_to_open * LV_IMG_CACHE_LIFE_GAIN ;
|
||||
if(cached_src->life > LV_IMG_CACHE_LIFE_LIMIT) cached_src->life = LV_IMG_CACHE_LIFE_LIMIT;
|
||||
LV_LOG_TRACE("image draw: image found in the cache");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*The image is not cached then cache it now*/
|
||||
if(cached_src == NULL) {
|
||||
/*Find an entry to reuse. Select the entry with the least life*/
|
||||
cached_src = &cache[0];
|
||||
for(i = 1; i < slot_num; i++) {
|
||||
if(cache[i].life < cached_src->life) {
|
||||
cached_src = &cache[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*Close the slot to reuse if it was opened (has a valid source)*/
|
||||
if(cached_src->dsc.src) {
|
||||
lv_img_decoder_close(&cached_src->dsc);
|
||||
LV_LOG_INFO("image draw: cache miss, close and reuse a slot");
|
||||
} else {
|
||||
LV_LOG_INFO("image draw: cache miss, cached in empty slot");
|
||||
}
|
||||
|
||||
/*Open the image and measure the time to open*/
|
||||
uint32_t t_start;
|
||||
t_start = lv_tick_get();
|
||||
const uint8_t * img_data = lv_img_decoder_open(&cached_src->dsc, src, style);
|
||||
if(img_data == LV_IMG_DECODER_OPEN_FAIL) {
|
||||
LV_LOG_WARN("Image draw cannot open the image resource");
|
||||
lv_img_decoder_close(&cached_src->dsc);
|
||||
memset(&cached_src->dsc, 0, sizeof(lv_img_decoder_dsc_t));
|
||||
memset(&cached_src, 0, sizeof(lv_img_cache_entry_t));
|
||||
cached_src->life = INT32_MIN; /*Make the empty entry very "weak" to force its use */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cached_src->img_data = img_data;
|
||||
cached_src->life = 0;
|
||||
cached_src->time_to_open = lv_tick_elaps(t_start);
|
||||
if(cached_src->time_to_open == 0) cached_src->time_to_open = 1;
|
||||
}
|
||||
|
||||
return cached_src;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of images to be cached.
|
||||
* More cached images mean more opened image at same time which might mean more memory usage.
|
||||
* E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache.
|
||||
* @param new_slot_num number of image to cache
|
||||
*/
|
||||
void lv_img_cache_set_size(uint16_t new_slot_num)
|
||||
{
|
||||
if(LV_GC_ROOT(_lv_img_cache_array) != NULL) {
|
||||
/*Clean the cache before free it*/
|
||||
lv_img_cache_invalidate_src(NULL);
|
||||
lv_mem_free(LV_GC_ROOT(_lv_img_cache_array));
|
||||
}
|
||||
|
||||
/*Reallocate the cache*/
|
||||
LV_GC_ROOT(_lv_img_cache_array) = lv_mem_alloc(sizeof(lv_img_cache_entry_t) * new_slot_num);
|
||||
lv_mem_assert(LV_GC_ROOT(_lv_img_cache_array));
|
||||
if(LV_GC_ROOT(_lv_img_cache_array) == NULL) {
|
||||
slot_num = 0;
|
||||
return;
|
||||
}
|
||||
slot_num = new_slot_num;
|
||||
|
||||
/*Clean the cache*/
|
||||
uint16_t i;
|
||||
for(i = 0; i < slot_num; i++) {
|
||||
memset(&LV_GC_ROOT(_lv_img_cache_array)[i].dsc, 0, sizeof(lv_img_decoder_dsc_t));
|
||||
memset(&LV_GC_ROOT(_lv_img_cache_array)[i], 0, sizeof(lv_img_cache_entry_t));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate an image source in the cache.
|
||||
* Useful if the image source is updated therefore it needs to be cached again.
|
||||
* @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable.
|
||||
*/
|
||||
void lv_img_cache_invalidate_src(const void * src)
|
||||
{
|
||||
|
||||
lv_img_cache_entry_t * cache = LV_GC_ROOT(_lv_img_cache_array);
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; i < slot_num; i++) {
|
||||
if(cache[i].dsc.src == src || src == NULL) {
|
||||
if(cache[i].dsc.src != NULL) {
|
||||
lv_img_decoder_close(&cache[i].dsc);
|
||||
}
|
||||
|
||||
memset(&cache[i].dsc, 0, sizeof(lv_img_decoder_dsc_t));
|
||||
memset(&cache[i], 0, sizeof(lv_img_cache_entry_t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
76
src/lv_draw/lv_img_cache.h
Normal file
76
src/lv_draw/lv_img_cache.h
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @file lv_img_cache.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_IMG_CACHE_H
|
||||
#define LV_IMG_CACHE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_img_decoder.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct
|
||||
{
|
||||
lv_img_decoder_dsc_t dsc;
|
||||
const uint8_t * img_data;
|
||||
|
||||
/* How much time did it take to open the image.*/
|
||||
uint32_t time_to_open;
|
||||
|
||||
/* Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used.
|
||||
* Decrement all lifes by one every in every `lv_img_cache_open`.
|
||||
* If life == 0 the entry can be reused,*/
|
||||
int32_t life;
|
||||
}lv_img_cache_entry_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Open an image using the image decoder interface and cache it.
|
||||
* The image will be left open meaning if the image decoder open callback allocated memory then it will remain.
|
||||
* The image is closed if a new image is opened and the new image takes its place in the cache.
|
||||
* @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable
|
||||
* @param style style of the image
|
||||
* @return pointer to the cache entry or NULL if can open the image
|
||||
*/
|
||||
lv_img_cache_entry_t * lv_img_cache_open(const void * src, const lv_style_t * style);
|
||||
|
||||
/**
|
||||
* Set the number of images to be cached.
|
||||
* More cached images mean more opened image at same time which might mean more memory usage.
|
||||
* E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache.
|
||||
* @param new_slot_num number of image to cache
|
||||
*/
|
||||
void lv_img_cache_set_size(uint16_t new_slot_num);
|
||||
|
||||
/**
|
||||
* Invalidate an image source in the cache.
|
||||
* Useful if the image source is updated therefore it needs to be cached again.
|
||||
* @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable.
|
||||
*/
|
||||
void lv_img_cache_invalidate_src(const void * src);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_IMG_CACHE_H*/
|
@ -331,6 +331,7 @@ static const uint8_t * lv_img_decoder_built_in_open(lv_img_decoder_t * decoder,
|
||||
* So simply give its pointer*/
|
||||
return ((lv_img_dsc_t *)dsc->src)->data;
|
||||
} else {
|
||||
|
||||
/*If it's a file it need to be read line by line later*/
|
||||
return NULL;
|
||||
}
|
||||
|
@ -39,6 +39,9 @@ enum {
|
||||
|
||||
typedef uint8_t lv_anim_enable_t;
|
||||
|
||||
/*Type of the animated value*/
|
||||
typedef lv_coord_t lv_anim_value_t;
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
|
||||
struct _lv_anim_t;
|
||||
|
@ -24,6 +24,7 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include "lv_mem.h"
|
||||
#include "lv_ll.h"
|
||||
#include "../lv_draw/lv_img_cache.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -38,6 +39,7 @@ extern "C" {
|
||||
prefix lv_ll_t _lv_anim_ll; \
|
||||
prefix lv_ll_t _lv_group_ll; \
|
||||
prefix lv_ll_t _lv_img_defoder_ll; \
|
||||
prefix lv_img_cache_entry_t * _lv_img_cache_array; \
|
||||
prefix void * _lv_task_act;
|
||||
|
||||
#define LV_NO_PREFIX
|
||||
|
@ -223,6 +223,9 @@ void lv_bar_set_anim_time(lv_obj_t * bar, uint16_t anim_time)
|
||||
#if LV_USE_ANIMATION
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
ext->anim_time = anim_time;
|
||||
#else
|
||||
(void)bar; /*Unused*/
|
||||
(void)anim_time; /*Unused*/
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -551,18 +551,23 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
/*If not dragged and it was not long press action then
|
||||
*change state and run the action*/
|
||||
if(lv_indev_is_dragging(param) == false) {
|
||||
uint32_t toggled = 0;
|
||||
if(ext->state == LV_BTN_STATE_PR && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
toggled = 0;
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
toggled = 1;
|
||||
} else if(ext->state == LV_BTN_STATE_PR && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
toggled = 1;
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
toggled = 0;
|
||||
}
|
||||
|
||||
if(tgl) {
|
||||
res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &toggled);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
|
||||
@ -605,10 +610,22 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
} else if(sign == LV_SIGNAL_CONTROL) {
|
||||
char c = *((char *)param);
|
||||
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
|
||||
if(lv_btn_get_toggle(btn)) lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
if(lv_btn_get_toggle(btn)) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
|
||||
uint32_t state = 1;
|
||||
res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &state);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
|
||||
} else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
|
||||
if(lv_btn_get_toggle(btn)) lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
if(lv_btn_get_toggle(btn)) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
|
||||
uint32_t state = 0;
|
||||
res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &state);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_CLEANUP) {
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
|
@ -313,6 +313,7 @@ static lv_res_t lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param)
|
||||
} else if(sign == LV_SIGNAL_CONTROL) {
|
||||
char c = *((char *)param);
|
||||
if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN || c == LV_KEY_LEFT || c == LV_KEY_UP) {
|
||||
/*Follow the backgrounds state with the bullet*/
|
||||
lv_btn_set_state(ext->bullet, lv_btn_get_state(cb));
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
||||
|
@ -27,6 +27,8 @@ extern "C" {
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**Default value of points. Can be used to not draw a point*/
|
||||
#define LV_CHART_POINT_DEF (LV_COORD_MIN)
|
||||
|
||||
/**Automatically calculate the tick length*/
|
||||
|
@ -676,6 +676,10 @@ static void lv_cont_refr_autofit(lv_obj_t * cont)
|
||||
/*Inform the parent about the new coordinates*/
|
||||
par->signal_cb(par, LV_SIGNAL_CHILD_CHG, cont);
|
||||
|
||||
if(lv_obj_get_auto_realign(cont)) {
|
||||
lv_obj_realign(cont);
|
||||
}
|
||||
|
||||
/*Tell the children the parent's size has changed*/
|
||||
LV_LL_READ(cont->child_ll, child_i)
|
||||
{
|
||||
|
@ -205,9 +205,6 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt)
|
||||
} else {
|
||||
lv_obj_invalidate(ddlist);
|
||||
}
|
||||
|
||||
uint32_t id = ext->sel_opt_id; /*Just to use uint32_t in event data*/
|
||||
lv_event_send(ddlist, LV_EVENT_VALUE_CHANGED, &id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,7 +131,7 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_obj_t * copy_img = lv_list_get_btn_img(copy_btn);
|
||||
if(copy_img) img_src = lv_img_get_src(copy_img);
|
||||
#endif
|
||||
lv_list_add(new_list, img_src, lv_list_get_btn_text(copy_btn), copy_btn->event_cb);
|
||||
lv_list_add_btn(new_list, img_src, lv_list_get_btn_text(copy_btn));
|
||||
copy_btn = lv_list_get_next_btn(copy, copy_btn);
|
||||
}
|
||||
|
||||
@ -171,10 +171,9 @@ void lv_list_clean(lv_obj_t * obj)
|
||||
* @param list pointer to list object
|
||||
* @param img_fn file name of an image before the text (NULL if unused)
|
||||
* @param txt text of the list element (NULL if unused)
|
||||
* @param event_cb specify the an event handler function. NULL if unused
|
||||
* @return pointer to the new list element which can be customized (a button)
|
||||
*/
|
||||
lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_event_cb_t event_cb)
|
||||
lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * txt)
|
||||
{
|
||||
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
||||
ext->size++;
|
||||
@ -192,7 +191,6 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt,
|
||||
lv_btn_set_style(liste, LV_BTN_STYLE_TGL_PR, ext->styles_btn[LV_BTN_STATE_TGL_PR]);
|
||||
lv_btn_set_style(liste, LV_BTN_STYLE_INA, ext->styles_btn[LV_BTN_STATE_INA]);
|
||||
|
||||
lv_obj_set_event_cb(liste, event_cb);
|
||||
lv_page_glue_obj(liste, true);
|
||||
lv_btn_set_layout(liste, LV_LAYOUT_ROW_M);
|
||||
lv_btn_set_fit2(liste, LV_FIT_FLOOD, LV_FIT_TIGHT);
|
||||
|
@ -104,10 +104,9 @@ void lv_list_clean(lv_obj_t * obj);
|
||||
* @param list pointer to list object
|
||||
* @param img_fn file name of an image before the text (NULL if unused)
|
||||
* @param txt text of the list element (NULL if unused)
|
||||
* @param event_cb specify the an event handler function. NULL if unused
|
||||
* @return pointer to the new list element which can be customized (a button)
|
||||
*/
|
||||
lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_event_cb_t event_cb);
|
||||
lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * txt);
|
||||
|
||||
/**
|
||||
* Remove the index of the button in the list
|
||||
|
@ -103,7 +103,6 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->edge_flash.style = &lv_style_plain_color;
|
||||
ext->anim_time = LV_PAGE_DEF_ANIM_TIME;
|
||||
#endif
|
||||
ext->arrow_scroll = 0;
|
||||
ext->scroll_prop = 0;
|
||||
ext->scroll_prop_ip = 0;
|
||||
|
||||
@ -149,7 +148,6 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal);
|
||||
|
||||
lv_page_set_sb_mode(new_page, copy_ext->sb.mode);
|
||||
lv_page_set_arrow_scroll(new_page, copy_ext->arrow_scroll);
|
||||
|
||||
lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG));
|
||||
lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL));
|
||||
@ -228,18 +226,6 @@ void lv_page_set_anim_time(lv_obj_t * page, uint16_t anim_time)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable scrolling with arrows if the page is in group (arrows:
|
||||
* LV_KEY_LEFT/RIGHT/UP/DOWN)
|
||||
* @param page pointer to a page object
|
||||
* @param en true: enable scrolling with arrows
|
||||
*/
|
||||
void lv_page_set_arrow_scroll(lv_obj_t * page, bool en)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
ext->arrow_scroll = en ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the scroll propagation feature. If enabled then the page will move its parent if there is
|
||||
* no more space to scroll.
|
||||
@ -338,17 +324,6 @@ lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page)
|
||||
return ext->sb.mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the the scrolling with arrows (LV_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not
|
||||
* @param page pointer to a page object
|
||||
* @return true: scrolling with arrows is enabled
|
||||
*/
|
||||
bool lv_page_get_arrow_scroll(const lv_obj_t * page)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
return ext->arrow_scroll ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scroll propagation property
|
||||
* @param page pointer to a Page
|
||||
@ -540,7 +515,7 @@ void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, lv_anim_enable_t anim_
|
||||
scrlable_x += page_w - obj_w;
|
||||
}
|
||||
|
||||
if(anim_en == LV_ANIM_ON && lv_page_get_anim_time(page) != 0) {
|
||||
if(anim_en == LV_ANIM_OFF || lv_page_get_anim_time(page) == 0) {
|
||||
lv_obj_set_y(ext->scrl, scrlable_y);
|
||||
lv_obj_set_x(ext->scrl, scrlable_x);
|
||||
} else {
|
||||
@ -878,18 +853,18 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
} else if(sign == LV_SIGNAL_CONTROL) {
|
||||
uint32_t c = *((uint32_t *)param);
|
||||
|
||||
if((c == LV_KEY_DOWN) && ext->arrow_scroll) {
|
||||
if(c == LV_KEY_DOWN) {
|
||||
lv_page_scroll_ver(page, -lv_obj_get_height(page) / 4);
|
||||
} else if((c == LV_KEY_UP) && ext->arrow_scroll) {
|
||||
} else if(c == LV_KEY_UP) {
|
||||
lv_page_scroll_ver(page, lv_obj_get_height(page) / 4);
|
||||
} else if((c == LV_KEY_RIGHT) && ext->arrow_scroll) {
|
||||
} else if(c == LV_KEY_RIGHT) {
|
||||
/*If the page can't be scrolled horizontally because it's not wide enough then scroll it
|
||||
* vertically*/
|
||||
if(lv_page_get_scrl_width(page) <= lv_obj_get_width(page))
|
||||
lv_page_scroll_ver(page, -lv_obj_get_height(page) / 4);
|
||||
else
|
||||
lv_page_scroll_hor(page, -lv_obj_get_width(page) / 4);
|
||||
} else if((c == LV_KEY_LEFT) && ext->arrow_scroll) {
|
||||
} else if(c == LV_KEY_LEFT) {
|
||||
/*If the page can't be scrolled horizontally because it's not wide enough then scroll it
|
||||
* vertically*/
|
||||
if(lv_page_get_scrl_width(page) <= lv_obj_get_width(page))
|
||||
@ -899,7 +874,7 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
||||
bool * editable = (bool *)param;
|
||||
*editable = lv_page_get_arrow_scroll(page);
|
||||
*editable = true;
|
||||
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
||||
lv_obj_type_t * buf = param;
|
||||
uint8_t i;
|
||||
|
@ -92,7 +92,6 @@ typedef struct
|
||||
uint16_t anim_time; /*Scroll animation time*/
|
||||
#endif
|
||||
|
||||
uint8_t arrow_scroll : 1; /*1: Enable scrolling with LV_KEY_LEFT/RIGHT/UP/DOWN*/
|
||||
uint8_t scroll_prop : 1; /*1: Propagate the scrolling the the parent if the edge is reached*/
|
||||
uint8_t scroll_prop_ip : 1; /*1: Scroll propagation is in progress (used by the library)*/
|
||||
} lv_page_ext_t;
|
||||
@ -155,14 +154,6 @@ void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode);
|
||||
*/
|
||||
void lv_page_set_anim_time(lv_obj_t * page, uint16_t anim_time);
|
||||
|
||||
/**
|
||||
* Enable/Disable scrolling with arrows if the page is in group (arrows:
|
||||
* LV_KEY_LEFT/RIGHT/UP/DOWN)
|
||||
* @param page pointer to a page object
|
||||
* @param en true: enable scrolling with arrows
|
||||
*/
|
||||
void lv_page_set_arrow_scroll(lv_obj_t * page, bool en);
|
||||
|
||||
/**
|
||||
* Enable the scroll propagation feature. If enabled then the page will move its parent if there is
|
||||
* no more space to scroll.
|
||||
@ -264,13 +255,6 @@ void lv_page_set_style(lv_obj_t * page, lv_page_style_t type, const lv_style_t *
|
||||
*/
|
||||
lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page);
|
||||
|
||||
/**
|
||||
* Get the the scrolling with arrows (LV_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not
|
||||
* @param page pointer to a page object
|
||||
* @return true: scrolling with arrows is enabled
|
||||
*/
|
||||
bool lv_page_get_arrow_scroll(const lv_obj_t * page);
|
||||
|
||||
/**
|
||||
* Get the scroll propagation property
|
||||
* @param page pointer to a Page
|
||||
|
@ -262,7 +262,7 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
|
||||
/*Save the current (old) value before slider signal modifies it. It will be required in the
|
||||
* later colcualtions*/
|
||||
* later calculations*/
|
||||
int16_t old_val;
|
||||
if(sign == LV_SIGNAL_PRESSING)
|
||||
old_val = ext->slider.drag_value;
|
||||
@ -321,46 +321,55 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
} else if(sign == LV_SIGNAL_PRESS_LOST) {
|
||||
if(lv_sw_get_state(sw)) {
|
||||
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
|
||||
lv_slider_set_value(sw, LV_SW_MAX_VALUE, true);
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_slider_set_value(sw, LV_SW_MAX_VALUE, LV_ANIM_ON);
|
||||
if(res != LV_RES_OK) return res;
|
||||
} else {
|
||||
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
lv_slider_set_value(sw, 0, true);
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_slider_set_value(sw, 0, LV_ANIM_ON);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_RELEASED) {
|
||||
/*If not dragged then toggle the switch*/
|
||||
if(ext->changed == 0) {
|
||||
if(lv_sw_get_state(sw))
|
||||
lv_sw_off(sw, true);
|
||||
else
|
||||
lv_sw_on(sw, true);
|
||||
int32_t state;
|
||||
if(lv_sw_get_state(sw)) {
|
||||
lv_sw_off(sw, LV_ANIM_ON);
|
||||
state = 0;
|
||||
}
|
||||
else {
|
||||
lv_sw_on(sw, LV_ANIM_ON);
|
||||
state = 1;
|
||||
}
|
||||
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
/*If the switch was dragged then calculate the new state based on the current position*/
|
||||
else {
|
||||
int16_t v = lv_slider_get_value(sw);
|
||||
if(v > LV_SW_MAX_VALUE / 2)
|
||||
lv_sw_on(sw, true);
|
||||
else
|
||||
lv_sw_off(sw, true);
|
||||
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
int32_t state;
|
||||
if(v > LV_SW_MAX_VALUE / 2) {
|
||||
lv_sw_on(sw, LV_ANIM_ON);
|
||||
state = 1;
|
||||
} else{
|
||||
lv_sw_off(sw, LV_ANIM_ON);
|
||||
state = 0;
|
||||
}
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_CONTROL) {
|
||||
char c = *((char *)param);
|
||||
uint32_t state;
|
||||
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
|
||||
lv_slider_set_value(sw, LV_SW_MAX_VALUE, true);
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
state = 1;
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
|
||||
if(res != LV_RES_OK) return res;
|
||||
} else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
|
||||
lv_slider_set_value(sw, 0, true);
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
state = 0;
|
||||
res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, &state);
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
||||
|
@ -335,12 +335,8 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an
|
||||
|
||||
const lv_style_t * style = lv_obj_get_style(ext->content);
|
||||
|
||||
lv_res_t res = LV_RES_OK;
|
||||
if(id >= ext->tab_cnt) id = ext->tab_cnt - 1;
|
||||
|
||||
if(id != ext->tab_cur) res = lv_event_send(tabview, LV_EVENT_VALUE_CHANGED, &id);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
lv_btnm_clear_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_TGL_STATE);
|
||||
|
||||
ext->tab_cur = id;
|
||||
@ -889,7 +885,7 @@ static void tabpage_pressing_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a tab's page or scrollable object is released or the press id lost
|
||||
* Called when a tab's page or scrollable object is released or the press is lost
|
||||
* @param tabview pointer to the btn view object
|
||||
* @param tabpage pointer to the page of a btn
|
||||
*/
|
||||
@ -925,7 +921,14 @@ static void tabpage_press_lost_handler(lv_obj_t * tabview, lv_obj_t * tabpage)
|
||||
if(tab_cur < ext->tab_cnt - 1) tab_cur++;
|
||||
}
|
||||
|
||||
lv_tabview_set_tab_act(tabview, tab_cur, true);
|
||||
uint32_t id_prev = lv_tabview_get_tab_act(tabview);
|
||||
lv_tabview_set_tab_act(tabview, tab_cur, LV_ANIM_ON);
|
||||
uint32_t id_new = lv_tabview_get_tab_act(tabview);
|
||||
|
||||
lv_res_t res = LV_RES_OK;
|
||||
if(id_prev != id_prev) res = lv_event_send(tabview, LV_EVENT_VALUE_CHANGED, &id_new);
|
||||
|
||||
if(res != LV_RES_OK) return;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -943,8 +946,17 @@ static void tab_btnm_event_cb(lv_obj_t * tab_btnm, lv_event_t event)
|
||||
lv_btnm_clear_btn_ctrl_all(tab_btnm, LV_BTNM_CTRL_TGL_STATE);
|
||||
lv_btnm_set_btn_ctrl(tab_btnm, btn_id, LV_BTNM_CTRL_TGL_STATE);
|
||||
|
||||
lv_obj_t * tab = lv_obj_get_parent(tab_btnm);
|
||||
lv_tabview_set_tab_act(tab, btn_id, true);
|
||||
lv_obj_t * tabview = lv_obj_get_parent(tab_btnm);
|
||||
|
||||
uint32_t id_prev = lv_tabview_get_tab_act(tabview);
|
||||
lv_tabview_set_tab_act(tabview, btn_id, LV_ANIM_ON);
|
||||
uint32_t id_new = lv_tabview_get_tab_act(tabview);
|
||||
|
||||
lv_res_t res = LV_RES_OK;
|
||||
if(id_prev != id_prev) res = lv_event_send(tabview, LV_EVENT_VALUE_CHANGED, &id_new);
|
||||
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1100,6 +1112,6 @@ static void tabview_realign(lv_obj_t * tabview)
|
||||
}
|
||||
}
|
||||
|
||||
lv_tabview_set_tab_act(tabview, ext->tab_cur, false);
|
||||
lv_tabview_set_tab_act(tabview, ext->tab_cur, LV_ANIM_OFF);
|
||||
}
|
||||
#endif
|
||||
|
@ -83,6 +83,7 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->act_id.x = 0;
|
||||
ext->act_id.y = 0;
|
||||
ext->valid_pos = NULL;
|
||||
ext->valid_pos_cnt = 0;
|
||||
|
||||
/*The signal and design functions are not copied so set them here*/
|
||||
lv_obj_set_signal_cb(new_tileview, lv_tileview_signal);
|
||||
@ -110,6 +111,8 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_tileview_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
ext->act_id.x = copy_ext->act_id.x;
|
||||
ext->act_id.y = copy_ext->act_id.y;
|
||||
ext->valid_pos = copy_ext->valid_pos;
|
||||
ext->valid_pos_cnt = copy_ext->valid_pos_cnt;
|
||||
#if LV_USE_ANIMATION
|
||||
ext->anim_time = copy_ext->anim_time;
|
||||
#endif
|
||||
@ -153,26 +156,27 @@ void lv_tileview_add_element(lv_obj_t * tileview, lv_obj_t * element)
|
||||
/**
|
||||
* Set the valid position's indices. The scrolling will be possible only to these positions.
|
||||
* @param tileview pointer to a Tileview object
|
||||
* @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1},
|
||||
* {LV_COORD_MIN, LV_COORD_MIN}};` Must be closed with `{LV_COORD_MIN, LV_COORD_MIN}`. Only the
|
||||
* @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1}`. Only the
|
||||
* pointer is saved so can't be a local variable.
|
||||
* @param valid_pos_cnt numner of elements in `valid_pos` array
|
||||
*/
|
||||
void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos)
|
||||
void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos, uint16_t valid_pos_cnt)
|
||||
{
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
ext->valid_pos = valid_pos;
|
||||
ext->valid_pos_cnt = valid_pos_cnt;
|
||||
|
||||
/*If valid pos. is selected do nothing*/
|
||||
uint16_t i;
|
||||
for(i = 0; valid_pos[i].x != LV_COORD_MIN; i++) {
|
||||
for(i = 0; i < valid_pos_cnt; i++) {
|
||||
if(valid_pos->x == ext->act_id.x && valid_pos->y == ext->act_id.y) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*Set a valid position if now an invalid is selected*/
|
||||
if(valid_pos->x != LV_COORD_MIN && valid_pos->y != LV_COORD_MIN) {
|
||||
lv_tileview_set_tile_act(tileview, valid_pos->x, valid_pos->y, false);
|
||||
if(valid_pos_cnt > 0) {
|
||||
lv_tileview_set_tile_act(tileview, valid_pos[0].x, valid_pos[0].y, LV_ANIM_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,10 +195,10 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, l
|
||||
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
|
||||
uint16_t i;
|
||||
uint32_t tile_id;
|
||||
bool valid = false;
|
||||
for(i = 0; ext->valid_pos[i].x != LV_COORD_MIN; i++) {
|
||||
if(ext->valid_pos[i].x == x && ext->valid_pos[i].y == y) {
|
||||
for(tile_id = 0; tile_id < ext->valid_pos_cnt; tile_id++) {
|
||||
if(ext->valid_pos[tile_id].x == x && ext->valid_pos[tile_id].y == y) {
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
@ -242,7 +246,7 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, l
|
||||
}
|
||||
|
||||
lv_res_t res = LV_RES_OK;
|
||||
res = lv_event_send(tileview, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
res = lv_event_send(tileview, LV_EVENT_VALUE_CHANGED, &tile_id);
|
||||
if(res != LV_RES_OK) return; /*Prevent the tile loading*/
|
||||
}
|
||||
|
||||
@ -256,7 +260,7 @@ void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, const
|
||||
{
|
||||
|
||||
switch(type) {
|
||||
case LV_TILEVIEW_STYLE_BG: lv_obj_set_style(tileview, style); break;
|
||||
case LV_TILEVIEW_STYLE_MAIN: lv_obj_set_style(tileview, style); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,7 +282,7 @@ const lv_style_t * lv_tileview_get_style(const lv_obj_t * tileview, lv_tileview_
|
||||
{
|
||||
const lv_style_t * style = NULL;
|
||||
switch(type) {
|
||||
case LV_TILEVIEW_STYLE_BG: style = lv_obj_get_style(tileview); break;
|
||||
case LV_TILEVIEW_STYLE_MAIN: style = lv_obj_get_style(tileview); break;
|
||||
default: style = NULL;
|
||||
}
|
||||
|
||||
@ -343,7 +347,7 @@ static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
lv_obj_t * tileview = lv_obj_get_parent(scrl);
|
||||
const lv_style_t * style_bg = lv_tileview_get_style(tileview, LV_TILEVIEW_STYLE_BG);
|
||||
const lv_style_t * style_bg = lv_tileview_get_style(tileview, LV_TILEVIEW_STYLE_MAIN);
|
||||
|
||||
/*Apply constraint on moving of the tileview*/
|
||||
if(sign == LV_SIGNAL_CORD_CHG) {
|
||||
@ -543,7 +547,7 @@ static bool set_valid_drag_dirs(lv_obj_t * tileview)
|
||||
ext->drag_right_en = 0;
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; ext->valid_pos[i].x != LV_COORD_MIN; i++) {
|
||||
for(i = 0; i < ext->valid_pos_cnt; i++) {
|
||||
if(ext->valid_pos[i].x == ext->act_id.x && ext->valid_pos[i].y == ext->act_id.y - 1) ext->drag_top_en = 1;
|
||||
if(ext->valid_pos[i].x == ext->act_id.x && ext->valid_pos[i].y == ext->act_id.y + 1) ext->drag_bottom_en = 1;
|
||||
if(ext->valid_pos[i].x == ext->act_id.x - 1 && ext->valid_pos[i].y == ext->act_id.y) ext->drag_left_en = 1;
|
||||
|
@ -37,6 +37,7 @@ typedef struct
|
||||
lv_page_ext_t page;
|
||||
/*New data for this type */
|
||||
const lv_point_t * valid_pos;
|
||||
uint16_t valid_pos_cnt;
|
||||
#if LV_USE_ANIMATION
|
||||
uint16_t anim_time;
|
||||
#endif
|
||||
@ -51,7 +52,7 @@ typedef struct
|
||||
|
||||
/*Styles*/
|
||||
enum {
|
||||
LV_TILEVIEW_STYLE_BG,
|
||||
LV_TILEVIEW_STYLE_MAIN,
|
||||
};
|
||||
typedef uint8_t lv_tileview_style_t;
|
||||
|
||||
@ -82,14 +83,15 @@ void lv_tileview_add_element(lv_obj_t * tileview, lv_obj_t * element);
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
|
||||
/**
|
||||
* Set the valid position's indices. The scrolling will be possible only to these positions.
|
||||
* @param tileview pointer to a Tileview object
|
||||
* @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1},
|
||||
* {LV_COORD_MIN, LV_COORD_MIN}};` Must be closed with `{LV_COORD_MIN, LV_COORD_MIN}`. Only the
|
||||
* @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1}`. Only the
|
||||
* pointer is saved so can't be a local variable.
|
||||
* @param valid_pos_cnt numner of elements in `valid_pos` array
|
||||
*/
|
||||
void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos);
|
||||
void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos, uint16_t valid_pos_cnt);
|
||||
|
||||
/**
|
||||
* Set the tile to be shown
|
||||
@ -110,6 +112,16 @@ static inline void lv_tileview_set_edge_flash(lv_obj_t * tileview, bool en)
|
||||
lv_page_set_edge_flash(tileview, en);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the animation time for the Tile view
|
||||
* @param tileview pointer to a page object
|
||||
* @param anim_time animation time in milliseconds
|
||||
*/
|
||||
static inline void lv_tileview_set_anim_time(lv_obj_t * tileview, uint16_t anim_time)
|
||||
{
|
||||
lv_page_set_anim_time(tileview, anim_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a tileview.
|
||||
* @param tileview pointer to tileview object
|
||||
@ -132,6 +144,16 @@ static inline bool lv_tileview_get_edge_flash(lv_obj_t * tileview)
|
||||
return lv_page_get_edge_flash(tileview);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the animation time for the Tile view
|
||||
* @param tileview pointer to a page object
|
||||
* @return animation time in milliseconds
|
||||
*/
|
||||
static inline uint16_t lv_tileview_get_anim_time(lv_obj_t * tileview)
|
||||
{
|
||||
return lv_page_get_anim_time(tileview);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style of a tileview.
|
||||
* @param tileview pointer to tileview object
|
||||
|
@ -82,7 +82,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->page = lv_page_create(new_win, NULL);
|
||||
lv_obj_set_protect(ext->page, LV_PROTECT_PARENT);
|
||||
lv_page_set_sb_mode(ext->page, LV_SB_MODE_AUTO);
|
||||
lv_page_set_arrow_scroll(ext->page, true);
|
||||
lv_page_set_style(ext->page, LV_PAGE_STYLE_BG, &lv_style_transp_fit);
|
||||
|
||||
/*Create a holder for the header*/
|
||||
ext->header = lv_obj_create(new_win, NULL);
|
||||
@ -94,20 +94,19 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->title = lv_label_create(ext->header, NULL);
|
||||
lv_label_set_text(ext->title, "My title");
|
||||
|
||||
|
||||
/*Set the default styles*/
|
||||
lv_theme_t * th = lv_theme_get_current();
|
||||
if(th) {
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_BG, th->style.win.bg);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_SB, th->style.win.sb);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, th->style.win.header);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, th->style.win.content.bg);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_SCRL, th->style.win.content.scrl);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT, th->style.win.content);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_BTN_REL, th->style.win.btn.rel);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_BTN_PR, th->style.win.btn.pr);
|
||||
} else {
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_BG, &lv_style_plain);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_BG, &lv_style_transp_fit);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT_SCRL, &lv_style_transp);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_CONTENT, &lv_style_transp);
|
||||
lv_win_set_style(new_win, LV_WIN_STYLE_HEADER, &lv_style_plain_color);
|
||||
}
|
||||
|
||||
@ -164,10 +163,9 @@ void lv_win_clean(lv_obj_t * obj)
|
||||
* Add control button to the header of the window
|
||||
* @param win pointer to a window object
|
||||
* @param img_src an image source ('lv_img_t' variable, path to file or a symbol)
|
||||
* @param event_cb specify the an event handler function. NULL if unused
|
||||
* @return pointer to the created button object
|
||||
*/
|
||||
lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, lv_event_cb_t event_cb)
|
||||
lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src)
|
||||
{
|
||||
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
||||
|
||||
@ -175,7 +173,6 @@ lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, lv_event_cb_t ev
|
||||
lv_btn_set_style(btn, LV_BTN_STYLE_REL, ext->style_btn_rel);
|
||||
lv_btn_set_style(btn, LV_BTN_STYLE_PR, ext->style_btn_pr);
|
||||
lv_obj_set_size(btn, ext->btn_size, ext->btn_size);
|
||||
lv_obj_set_event_cb(btn, event_cb);
|
||||
|
||||
lv_obj_t * img = lv_img_create(btn, NULL);
|
||||
lv_obj_set_click(img, false);
|
||||
@ -195,7 +192,7 @@ lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, lv_event_cb_t ev
|
||||
* @param btn pointer to the control button on teh widows header
|
||||
* @param evet the event type
|
||||
*/
|
||||
void lv_win_close_event(lv_obj_t * btn, lv_event_t event)
|
||||
void lv_win_close_event_cb(lv_obj_t * btn, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_RELEASED) {
|
||||
lv_obj_t * win = lv_win_get_from_btn(btn);
|
||||
@ -278,8 +275,7 @@ void lv_win_set_style(lv_obj_t * win, lv_win_style_t type, const lv_style_t * st
|
||||
lv_obj_set_style(win, style);
|
||||
lv_win_realign(win);
|
||||
break;
|
||||
case LV_WIN_STYLE_CONTENT_BG: lv_page_set_style(ext->page, LV_PAGE_STYLE_BG, style); break;
|
||||
case LV_WIN_STYLE_CONTENT_SCRL: lv_page_set_style(ext->page, LV_PAGE_STYLE_SCRL, style); break;
|
||||
case LV_WIN_STYLE_CONTENT: lv_page_set_style(ext->page, LV_PAGE_STYLE_SCRL, style); break;
|
||||
case LV_WIN_STYLE_SB: lv_page_set_style(ext->page, LV_PAGE_STYLE_SB, style); break;
|
||||
case LV_WIN_STYLE_HEADER:
|
||||
lv_obj_set_style(ext->header, style);
|
||||
@ -427,8 +423,7 @@ const lv_style_t * lv_win_get_style(const lv_obj_t * win, lv_win_style_t type)
|
||||
|
||||
switch(type) {
|
||||
case LV_WIN_STYLE_BG: style = lv_obj_get_style(win); break;
|
||||
case LV_WIN_STYLE_CONTENT_BG: style = lv_page_get_style(ext->page, LV_PAGE_STYLE_BG); break;
|
||||
case LV_WIN_STYLE_CONTENT_SCRL: style = lv_page_get_style(ext->page, LV_PAGE_STYLE_SCRL); break;
|
||||
case LV_WIN_STYLE_CONTENT: style = lv_page_get_style(ext->page, LV_PAGE_STYLE_SCRL); break;
|
||||
case LV_WIN_STYLE_SB: style = lv_page_get_style(ext->page, LV_PAGE_STYLE_SB); break;
|
||||
case LV_WIN_STYLE_HEADER: style = lv_obj_get_style(ext->header); break;
|
||||
case LV_WIN_STYLE_BTN_REL: style = ext->style_btn_rel; break;
|
||||
|
@ -68,8 +68,7 @@ typedef struct
|
||||
|
||||
enum {
|
||||
LV_WIN_STYLE_BG,
|
||||
LV_WIN_STYLE_CONTENT_BG,
|
||||
LV_WIN_STYLE_CONTENT_SCRL,
|
||||
LV_WIN_STYLE_CONTENT,
|
||||
LV_WIN_STYLE_SB,
|
||||
LV_WIN_STYLE_HEADER,
|
||||
LV_WIN_STYLE_BTN_REL,
|
||||
@ -103,10 +102,9 @@ void lv_win_clean(lv_obj_t * obj);
|
||||
* Add control button to the header of the window
|
||||
* @param win pointer to a window object
|
||||
* @param img_src an image source ('lv_img_t' variable, path to file or a symbol)
|
||||
* @param event_cb specify the an event handler function. NULL if unused
|
||||
* @return pointer to the created button object
|
||||
*/
|
||||
lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, lv_event_cb_t event_cb);
|
||||
lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src);
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
@ -117,7 +115,7 @@ lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, lv_event_cb_t ev
|
||||
* @param btn pointer to the control button on teh widows header
|
||||
* @param evet the event type
|
||||
*/
|
||||
void lv_win_close_event(lv_obj_t * btn, lv_event_t event);
|
||||
void lv_win_close_event_cb(lv_obj_t * btn, lv_event_t event);
|
||||
|
||||
/**
|
||||
* Set the title of a window
|
||||
|
@ -311,11 +311,7 @@ typedef struct
|
||||
lv_style_t * bg;
|
||||
lv_style_t * sb;
|
||||
lv_style_t * header;
|
||||
struct
|
||||
{
|
||||
lv_style_t * bg;
|
||||
lv_style_t * scrl;
|
||||
} content;
|
||||
lv_style_t * content;
|
||||
struct
|
||||
{
|
||||
lv_style_t * rel;
|
||||
|
@ -823,8 +823,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = &bg;
|
||||
theme.style.win.sb = &sb;
|
||||
theme.style.win.header = &header;
|
||||
theme.style.win.content.bg = &lv_style_transp;
|
||||
theme.style.win.content.scrl = &lv_style_transp;
|
||||
theme.style.win.content = &lv_style_transp;
|
||||
theme.style.win.btn.rel = &btn_rel;
|
||||
theme.style.win.btn.pr = &btn_pr;
|
||||
#endif
|
||||
|
@ -340,8 +340,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = &plain_bordered;
|
||||
theme.style.win.sb = &sb;
|
||||
theme.style.win.header = &lv_style_plain_color;
|
||||
theme.style.win.content.bg = &lv_style_transp;
|
||||
theme.style.win.content.scrl = &lv_style_transp;
|
||||
theme.style.win.content = &lv_style_transp;
|
||||
theme.style.win.btn.rel = &lv_style_btn_rel;
|
||||
theme.style.win.btn.pr = &lv_style_btn_pr;
|
||||
#endif
|
||||
|
@ -788,8 +788,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = theme.style.panel;
|
||||
theme.style.win.sb = &sb;
|
||||
theme.style.win.header = &header;
|
||||
theme.style.win.content.bg = &lv_style_transp;
|
||||
theme.style.win.content.scrl = &lv_style_transp;
|
||||
theme.style.win.content = &lv_style_transp;
|
||||
theme.style.win.btn.rel = &lv_style_transp;
|
||||
theme.style.win.btn.pr = ≺
|
||||
#endif
|
||||
|
@ -395,8 +395,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = &light_frame;
|
||||
theme.style.win.sb = &dark_frame;
|
||||
theme.style.win.header = &win_header;
|
||||
theme.style.win.content.bg = &lv_style_transp;
|
||||
theme.style.win.content.scrl = &lv_style_transp;
|
||||
theme.style.win.content = &lv_style_transp;
|
||||
theme.style.win.btn.rel = &light_frame;
|
||||
theme.style.win.btn.pr = &dark_frame;
|
||||
#endif
|
||||
|
@ -792,8 +792,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = &bg;
|
||||
theme.style.win.sb = &sb;
|
||||
theme.style.win.header = &win_header;
|
||||
theme.style.win.content.bg = &lv_style_transp;
|
||||
theme.style.win.content.scrl = &lv_style_transp;
|
||||
theme.style.win.content = &lv_style_transp;
|
||||
theme.style.win.btn.rel = &btn_rel;
|
||||
theme.style.win.btn.pr = &btn_pr;
|
||||
#endif
|
||||
|
@ -714,8 +714,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = &win_bg;
|
||||
theme.style.win.sb = &sb;
|
||||
theme.style.win.header = &win_header;
|
||||
theme.style.win.content.bg = &lv_style_transp;
|
||||
theme.style.win.content.scrl = &lv_style_transp;
|
||||
theme.style.win.content = &lv_style_transp;
|
||||
theme.style.win.btn.rel = &lv_style_transp;
|
||||
theme.style.win.btn.pr = &win_btn_pr;
|
||||
#endif
|
||||
|
@ -335,8 +335,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = &def;
|
||||
theme.style.win.sb = &def;
|
||||
theme.style.win.header = &def;
|
||||
theme.style.win.content.bg = &def;
|
||||
theme.style.win.content.scrl = &def;
|
||||
theme.style.win.content = &def;
|
||||
theme.style.win.btn.rel = &def;
|
||||
theme.style.win.btn.pr = &def;
|
||||
#endif
|
||||
|
@ -763,8 +763,7 @@ static void win_init(void)
|
||||
theme.style.win.bg = theme.style.panel;
|
||||
theme.style.win.sb = &sb;
|
||||
theme.style.win.header = &header;
|
||||
theme.style.win.content.bg = &lv_style_transp;
|
||||
theme.style.win.content.scrl = &lv_style_transp;
|
||||
theme.style.win.content = &lv_style_transp;
|
||||
theme.style.win.btn.rel = &rel;
|
||||
theme.style.win.btn.pr = ≺
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user