Merge remote-tracking branch 'upstream/dev-5.3' into dev-5.3
This commit is contained in:
@@ -27,7 +27,7 @@ In the simplest case you need 5 things:
|
||||
3. Register a function which can **read an input device**. (E.g. touch pad)
|
||||
4. Copy `lv_conf_templ.h` as `lv_conf.h` and set at least `LV_HOR_RES`, `LV_VER_RES` and `LV_COLOR_DEPTH`.
|
||||
5. Call `lv_task_handler()` periodically every few milliseconds.
|
||||
For a detailed description visit https://littlevgl.com/porting
|
||||
For a detailed description visit https://github.com/littlevgl/lvgl/wiki/Porting
|
||||
Or check the [Porting tutorial](https://github.com/littlevgl/lv_examples/blob/master/lv_tutorial/0_porting/lv_tutorial_porting.c)
|
||||
|
||||
## Project set-up
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
/* Memory size which will be used by the library
|
||||
* to store the graphical objects and other data */
|
||||
#define LV_MEM_CUSTOM 0 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/
|
||||
#define LV_MEM_CUSTOM 0 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
#define LV_MEM_SIZE (32U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
|
||||
#define LV_MEM_ATTR /*Complier prefix for big array declaration*/
|
||||
@@ -43,8 +43,8 @@
|
||||
* VDB makes the double buffering, you don't need to deal with it!
|
||||
* Typical size: ~1/10 screen */
|
||||
#define LV_VDB_SIZE (30 * LV_HOR_RES) /*Size of VDB in pixel count (1/10 screen size is good for first)*/
|
||||
#define LV_VDB_PX_BPP LV_COLOR_SIZE /*Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays. (Special formats are handles with `disp_drv->vdb_wr`)*/
|
||||
#define LV_VDB_ADR 0 /*Place VDB to a specific address (e.g. in external RAM) (0: allocate automatically into RAM; LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`)*/
|
||||
#define LV_VDB_PX_BPP LV_COLOR_SIZE /*Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays. (Special formats are handled with `disp_drv->vdb_wr`)*/
|
||||
#define LV_VDB_ADR 0 /*Place VDB to a specific address (e.g. in external RAM) (0: allocate automatically into RAM; LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`)*/
|
||||
|
||||
/* Use two Virtual Display buffers (VDB) parallelize rendering and flushing (optional)
|
||||
* The flushing should use DMA to write the frame buffer in the background*/
|
||||
@@ -73,7 +73,7 @@
|
||||
/*Color settings*/
|
||||
#define LV_COLOR_DEPTH 16 /*Color depth: 1/8/16/32*/
|
||||
#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
|
||||
#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/
|
||||
#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/
|
||||
#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/
|
||||
|
||||
/*Text settings*/
|
||||
@@ -91,6 +91,7 @@
|
||||
/*Compiler settings*/
|
||||
#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */
|
||||
#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */
|
||||
#define LV_ATTRIBUTE_FLUSH_READY /* Define a custom attribute to `lv_flush_ready` function */
|
||||
#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/
|
||||
#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */
|
||||
|
||||
@@ -101,7 +102,6 @@
|
||||
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
|
||||
#endif /*LV_TICK_CUSTOM*/
|
||||
|
||||
|
||||
/*Log settings*/
|
||||
#define USE_LV_LOG 1 /*Enable/disable the log module*/
|
||||
#if USE_LV_LOG
|
||||
@@ -112,9 +112,8 @@
|
||||
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
|
||||
*/
|
||||
#define LV_LOG_LEVEL LV_LOG_LEVEL_INFO
|
||||
/* 1: Print the log with 'printf'; 0: user need to register a callback*/
|
||||
|
||||
#define LV_LOG_PRINTF 0
|
||||
#define LV_LOG_PRINTF 0 /* 1: Print the log with 'printf'; 0: user need to register a callback*/
|
||||
#endif /*USE_LV_LOG*/
|
||||
|
||||
/*================
|
||||
@@ -175,6 +174,7 @@
|
||||
*==================*/
|
||||
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
|
||||
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
|
||||
#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
|
||||
|
||||
/*==================
|
||||
* LV OBJ X USAGE
|
||||
@@ -225,6 +225,12 @@
|
||||
#define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
|
||||
#endif
|
||||
|
||||
/*Tileview (dependencies: lv_page) */
|
||||
#define USE_LV_TILEVIEW 1
|
||||
#if USE_LV_TILEVIEW
|
||||
#define LV_TILEVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
|
||||
#endif
|
||||
|
||||
/*************************
|
||||
* Data visualizer objects
|
||||
*************************/
|
||||
@@ -262,6 +268,7 @@
|
||||
#if USE_LV_PRELOAD != 0
|
||||
#define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
|
||||
#define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
|
||||
#define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
|
||||
#endif
|
||||
|
||||
/*************************
|
||||
@@ -276,6 +283,9 @@
|
||||
|
||||
/*Image Button (dependencies: lv_btn*/
|
||||
#define USE_LV_IMGBTN 1
|
||||
#if USE_LV_IMGBTN
|
||||
#define LV_IMGBTN_TILED 1 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
|
||||
#endif
|
||||
|
||||
/*Button matrix (dependencies: -)*/
|
||||
#define USE_LV_BTNM 1
|
||||
@@ -314,7 +324,7 @@
|
||||
* Non-user section
|
||||
*************************/
|
||||
#ifdef _MSC_VER /* Disable warnings for Visual Studio*/
|
||||
# define _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#endif /*LV_CONF_H*/
|
||||
|
||||
@@ -122,8 +122,16 @@ void lv_group_remove_obj(lv_obj_t * obj)
|
||||
if(g == NULL) return;
|
||||
if(g->obj_focus == NULL) return; /*Just to be sure (Not possible if there is at least one object in the group)*/
|
||||
|
||||
/*Focus on the next object*/
|
||||
if(*g->obj_focus == obj) {
|
||||
lv_group_refocus(g);
|
||||
/*If this is the only object in the group then focus to nothing.*/
|
||||
if(lv_ll_get_head(&g->obj_ll) == g->obj_focus && lv_ll_get_tail(&g->obj_ll) == g->obj_focus) {
|
||||
(*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
}
|
||||
/*If there more objects in the group then focus to the next/prev object*/
|
||||
else {
|
||||
lv_group_refocus(g);
|
||||
}
|
||||
}
|
||||
|
||||
/* If the focuses object is still the same then it was the only object in the group but it will be deleted.
|
||||
|
||||
@@ -368,6 +368,10 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
if(data->state == LV_INDEV_STATE_PR &&
|
||||
i->proc.last_state == LV_INDEV_STATE_REL) {
|
||||
i->proc.pr_timestamp = lv_tick_get();
|
||||
lv_obj_t * focused = lv_group_get_focused(i->group);
|
||||
if(focused) {
|
||||
focused->signal_func(focused, LV_SIGNAL_PRESSED, indev_act);
|
||||
}
|
||||
}
|
||||
/*Pressing*/
|
||||
else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) {
|
||||
@@ -585,7 +589,10 @@ static void indev_proc_press(lv_indev_proc_t * proc)
|
||||
if(proc->reset_query != 0) return;
|
||||
}
|
||||
|
||||
if(pr_obj != NULL) {
|
||||
proc->act_obj = pr_obj; /*Save the pressed object*/
|
||||
proc->last_obj = proc->act_obj; /*Refresh the last_obj*/
|
||||
|
||||
if(proc->act_obj != NULL) {
|
||||
/* Save the time when the obj pressed.
|
||||
* It is necessary to count the long press time.*/
|
||||
proc->pr_timestamp = lv_tick_get();
|
||||
@@ -598,7 +605,7 @@ static void indev_proc_press(lv_indev_proc_t * proc)
|
||||
proc->vect.y = 0;
|
||||
|
||||
/*Search for 'top' attribute*/
|
||||
lv_obj_t * i = pr_obj;
|
||||
lv_obj_t * i = proc->act_obj;
|
||||
lv_obj_t * last_top = NULL;
|
||||
while(i != NULL) {
|
||||
if(i->top != 0) last_top = i;
|
||||
@@ -614,14 +621,11 @@ static void indev_proc_press(lv_indev_proc_t * proc)
|
||||
}
|
||||
|
||||
/*Send a signal about the press*/
|
||||
pr_obj->signal_func(pr_obj, LV_SIGNAL_PRESSED, indev_act);
|
||||
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSED, indev_act);
|
||||
if(proc->reset_query != 0) return;
|
||||
}
|
||||
}
|
||||
|
||||
proc->act_obj = pr_obj; /*Save the pressed object*/
|
||||
proc->last_obj = proc->act_obj; /*Refresh the last_obj*/
|
||||
|
||||
/*Calculate the vector*/
|
||||
proc->vect.x = proc->act_point.x - proc->last_point.x;
|
||||
proc->vect.y = proc->act_point.y - proc->last_point.y;
|
||||
@@ -821,11 +825,12 @@ static void indev_drag(lv_indev_proc_t * state)
|
||||
|
||||
if(lv_obj_get_drag(drag_obj) == false) return;
|
||||
|
||||
/*If still there is no drag then count the movement*/
|
||||
if(state->drag_range_out == 0) {
|
||||
state->drag_sum.x += state->vect.x;
|
||||
state->drag_sum.y += state->vect.y;
|
||||
/*Count the movement by drag*/
|
||||
state->drag_sum.x += state->vect.x;
|
||||
state->drag_sum.y += state->vect.y;
|
||||
|
||||
/*Enough move?*/
|
||||
if(state->drag_range_out == 0) {
|
||||
/*If a move is greater then LV_DRAG_LIMIT then begin the drag*/
|
||||
if(LV_MATH_ABS(state->drag_sum.x) >= LV_INDEV_DRAG_LIMIT ||
|
||||
LV_MATH_ABS(state->drag_sum.y) >= LV_INDEV_DRAG_LIMIT) {
|
||||
|
||||
224
lv_core/lv_obj.c
224
lv_core/lv_obj.c
@@ -200,6 +200,14 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
|
||||
LV_OBJ_DEF_HEIGHT;
|
||||
new_obj->ext_size = 0;
|
||||
|
||||
/*Init realign*/
|
||||
#if LV_OBJ_REALIGN
|
||||
new_obj->realign.align = LV_ALIGN_CENTER;
|
||||
new_obj->realign.xofs = 0;
|
||||
new_obj->realign.yofs = 0;
|
||||
new_obj->realign.base = NULL;
|
||||
new_obj->realign.auto_realign = 0;
|
||||
#endif
|
||||
/*Set appearance*/
|
||||
lv_theme_t * th = lv_theme_get_current();
|
||||
if(th) {
|
||||
@@ -360,10 +368,13 @@ lv_res_t lv_obj_del(lv_obj_t * obj)
|
||||
void lv_obj_clean(lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_t * child = lv_obj_get_child(obj, NULL);
|
||||
|
||||
lv_obj_t * child_next;
|
||||
while(child) {
|
||||
/* Read the next child before deleting the current
|
||||
* because the next couldn't be read from a deleted (invalid) node*/
|
||||
child_next = lv_obj_get_child(obj, child);
|
||||
lv_obj_del(child);
|
||||
child = lv_obj_get_child(obj, child);
|
||||
child = child_next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -578,6 +589,11 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
|
||||
|
||||
/*Invalidate the new area*/
|
||||
lv_obj_invalidate(obj);
|
||||
|
||||
/*Automatically realign the object if required*/
|
||||
#if LV_OBJ_REALIGN
|
||||
if(obj->realign.auto_realign) lv_obj_realign(obj);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -734,6 +750,194 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co
|
||||
new_y -= par_abs_y;
|
||||
|
||||
lv_obj_set_pos(obj, new_x, new_y);
|
||||
|
||||
#if LV_OBJ_REALIGN
|
||||
/*Save the last align parameters to use them in `lv_obj_realign`*/
|
||||
obj->realign.align = align;
|
||||
obj->realign.xofs = x_mod;
|
||||
obj->realign.yofs = y_mod;
|
||||
obj->realign.base = base;
|
||||
obj->realign.origo_align = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Align an object to an other object.
|
||||
* @param obj pointer to an object to align
|
||||
* @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it.
|
||||
* @param align type of alignment (see 'lv_align_t' enum)
|
||||
* @param x_mod x coordinate shift after alignment
|
||||
* @param y_mod y coordinate shift after alignment
|
||||
*/
|
||||
void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod)
|
||||
{
|
||||
lv_coord_t new_x = lv_obj_get_x(obj);
|
||||
lv_coord_t new_y = lv_obj_get_y(obj);
|
||||
|
||||
lv_coord_t obj_w_half = lv_obj_get_width(obj) / 2;
|
||||
lv_coord_t obj_h_half = lv_obj_get_height(obj) / 2;
|
||||
|
||||
if(base == NULL) {
|
||||
base = lv_obj_get_parent(obj);
|
||||
}
|
||||
|
||||
switch(align) {
|
||||
case LV_ALIGN_CENTER:
|
||||
new_x = lv_obj_get_width(base) / 2 - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) / 2 - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_IN_TOP_LEFT:
|
||||
new_x = -obj_w_half;
|
||||
new_y = -obj_h_half;
|
||||
break;
|
||||
case LV_ALIGN_IN_TOP_MID:
|
||||
new_x = lv_obj_get_width(base) / 2 - obj_w_half;
|
||||
new_y = -obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_IN_TOP_RIGHT:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = -obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_IN_BOTTOM_LEFT:
|
||||
new_x = -obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
case LV_ALIGN_IN_BOTTOM_MID:
|
||||
new_x = lv_obj_get_width(base) / 2 - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_IN_BOTTOM_RIGHT:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_IN_LEFT_MID:
|
||||
new_x = -obj_w_half;
|
||||
new_y = lv_obj_get_height(base) / 2 - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_IN_RIGHT_MID:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) / 2 - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_TOP_LEFT:
|
||||
new_x = -obj_w_half;
|
||||
new_y = -obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_TOP_MID:
|
||||
new_x = lv_obj_get_width(base) / 2 - obj_w_half;
|
||||
new_y = -obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_TOP_RIGHT:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_BOTTOM_LEFT:
|
||||
new_x = -obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_BOTTOM_MID:
|
||||
new_x = lv_obj_get_width(base) / 2 - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_BOTTOM_RIGHT:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_LEFT_TOP:
|
||||
new_x = - obj_w_half ;
|
||||
new_y = - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_LEFT_MID:
|
||||
new_x = - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) / 2 - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_LEFT_BOTTOM:
|
||||
new_x = - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_RIGHT_TOP:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = -obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_RIGHT_MID:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) / 2 - obj_h_half;
|
||||
break;
|
||||
|
||||
case LV_ALIGN_OUT_RIGHT_BOTTOM:
|
||||
new_x = lv_obj_get_width(base) - obj_w_half;
|
||||
new_y = lv_obj_get_height(base) - obj_h_half;
|
||||
break;
|
||||
}
|
||||
|
||||
/*Bring together the coordination system of base and obj*/
|
||||
lv_obj_t * par = lv_obj_get_parent(obj);
|
||||
lv_coord_t base_abs_x = base->coords.x1;
|
||||
lv_coord_t base_abs_y = base->coords.y1;
|
||||
lv_coord_t par_abs_x = par->coords.x1;
|
||||
lv_coord_t par_abs_y = par->coords.y1;
|
||||
new_x += x_mod + base_abs_x;
|
||||
new_y += y_mod + base_abs_y;
|
||||
new_x -= par_abs_x;
|
||||
new_y -= par_abs_y;
|
||||
|
||||
lv_obj_set_pos(obj, new_x, new_y);
|
||||
|
||||
#if LV_OBJ_REALIGN
|
||||
/*Save the last align parameters to use them in `lv_obj_realign`*/
|
||||
obj->realign.align = align;
|
||||
obj->realign.xofs = x_mod;
|
||||
obj->realign.yofs = y_mod;
|
||||
obj->realign.base = base;
|
||||
obj->realign.origo_align = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Realign the object based on the last `lv_obj_align` parameters.
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_realign(lv_obj_t * obj)
|
||||
{
|
||||
#if LV_OBJ_REALIGN
|
||||
if(obj->realign.origo_align) lv_obj_align_origo(obj, obj->realign.base, obj->realign.align, obj->realign.xofs, obj->realign.yofs);
|
||||
else lv_obj_align(obj, obj->realign.base, obj->realign.align, obj->realign.xofs, obj->realign.yofs);
|
||||
#else
|
||||
(void) obj;
|
||||
LV_LOG_WARN("lv_obj_realaign: no effect because LV_OBJ_REALIGN = 0");
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the automatic realign of the object when its size has changed based on the last `lv_obj_align` parameters.
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable auto realign; false: disable auto realign
|
||||
*/
|
||||
void lv_obj_set_auto_realign(lv_obj_t * obj, bool en)
|
||||
{
|
||||
#if LV_OBJ_REALIGN
|
||||
obj->realign.auto_realign = en ? 1 : 0;
|
||||
#else
|
||||
(void) obj;
|
||||
(void) en;
|
||||
LV_LOG_WARN("lv_obj_set_auto_realign: no effect because LV_OBJ_REALIGN = 0");
|
||||
#endif
|
||||
}
|
||||
|
||||
/*---------------------
|
||||
@@ -754,7 +958,6 @@ void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style)
|
||||
|
||||
/*Notify the object about the style change too*/
|
||||
lv_obj_refresh_style(obj);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1256,6 +1459,21 @@ lv_coord_t lv_obj_get_ext_size(const lv_obj_t * obj)
|
||||
return obj->ext_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the automatic realign property of the object.
|
||||
* @param obj pointer to an object
|
||||
* @return true: auto realign is enabled; false: auto realign is disabled
|
||||
*/
|
||||
bool lv_obj_get_auto_realign(lv_obj_t * obj)
|
||||
{
|
||||
#if LV_OBJ_REALIGN
|
||||
return obj->realign.auto_realign ? true : false;
|
||||
#else
|
||||
(void) obj;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*-----------------
|
||||
* Appearance get
|
||||
*---------------*/
|
||||
|
||||
@@ -112,6 +112,44 @@ typedef uint8_t lv_signal_t;
|
||||
|
||||
typedef lv_res_t (* lv_signal_func_t) (struct _lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||
|
||||
enum
|
||||
{
|
||||
LV_ALIGN_CENTER = 0,
|
||||
LV_ALIGN_IN_TOP_LEFT,
|
||||
LV_ALIGN_IN_TOP_MID,
|
||||
LV_ALIGN_IN_TOP_RIGHT,
|
||||
LV_ALIGN_IN_BOTTOM_LEFT,
|
||||
LV_ALIGN_IN_BOTTOM_MID,
|
||||
LV_ALIGN_IN_BOTTOM_RIGHT,
|
||||
LV_ALIGN_IN_LEFT_MID,
|
||||
LV_ALIGN_IN_RIGHT_MID,
|
||||
LV_ALIGN_OUT_TOP_LEFT,
|
||||
LV_ALIGN_OUT_TOP_MID,
|
||||
LV_ALIGN_OUT_TOP_RIGHT,
|
||||
LV_ALIGN_OUT_BOTTOM_LEFT,
|
||||
LV_ALIGN_OUT_BOTTOM_MID,
|
||||
LV_ALIGN_OUT_BOTTOM_RIGHT,
|
||||
LV_ALIGN_OUT_LEFT_TOP,
|
||||
LV_ALIGN_OUT_LEFT_MID,
|
||||
LV_ALIGN_OUT_LEFT_BOTTOM,
|
||||
LV_ALIGN_OUT_RIGHT_TOP,
|
||||
LV_ALIGN_OUT_RIGHT_MID,
|
||||
LV_ALIGN_OUT_RIGHT_BOTTOM,
|
||||
};
|
||||
typedef uint8_t lv_align_t;
|
||||
|
||||
#if LV_OBJ_REALIGN
|
||||
typedef struct {
|
||||
const struct _lv_obj_t * base;
|
||||
lv_coord_t xofs;
|
||||
lv_coord_t yofs;
|
||||
lv_align_t align;
|
||||
uint8_t auto_realign :1;
|
||||
uint8_t origo_align :1; /*1: the oigo (center of the object) was aligned with `lv_obj_align_origo`*/
|
||||
}lv_reailgn_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct _lv_obj_t
|
||||
{
|
||||
struct _lv_obj_t * par; /*Pointer to the parent object*/
|
||||
@@ -144,6 +182,9 @@ typedef struct _lv_obj_t
|
||||
lv_opa_t opa_scale; /*Scale down the opacity by this factor. Effects all children as well*/
|
||||
|
||||
lv_coord_t ext_size; /*EXTtend the size of the object in every direction. E.g. for shadow drawing*/
|
||||
#if LV_OBJ_REALIGN
|
||||
lv_reailgn_t realign;
|
||||
#endif
|
||||
|
||||
#ifdef LV_OBJ_FREE_NUM_TYPE
|
||||
LV_OBJ_FREE_NUM_TYPE free_num; /*Application specific identifier (set it freely)*/
|
||||
@@ -171,32 +212,6 @@ typedef struct {
|
||||
const char * type[LV_MAX_ANCESTOR_NUM]; /*[0]: the actual type, [1]: ancestor, [2] #1's ancestor ... [x]: "lv_obj" */
|
||||
} lv_obj_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LV_ALIGN_CENTER = 0,
|
||||
LV_ALIGN_IN_TOP_LEFT,
|
||||
LV_ALIGN_IN_TOP_MID,
|
||||
LV_ALIGN_IN_TOP_RIGHT,
|
||||
LV_ALIGN_IN_BOTTOM_LEFT,
|
||||
LV_ALIGN_IN_BOTTOM_MID,
|
||||
LV_ALIGN_IN_BOTTOM_RIGHT,
|
||||
LV_ALIGN_IN_LEFT_MID,
|
||||
LV_ALIGN_IN_RIGHT_MID,
|
||||
LV_ALIGN_OUT_TOP_LEFT,
|
||||
LV_ALIGN_OUT_TOP_MID,
|
||||
LV_ALIGN_OUT_TOP_RIGHT,
|
||||
LV_ALIGN_OUT_BOTTOM_LEFT,
|
||||
LV_ALIGN_OUT_BOTTOM_MID,
|
||||
LV_ALIGN_OUT_BOTTOM_RIGHT,
|
||||
LV_ALIGN_OUT_LEFT_TOP,
|
||||
LV_ALIGN_OUT_LEFT_MID,
|
||||
LV_ALIGN_OUT_LEFT_BOTTOM,
|
||||
LV_ALIGN_OUT_RIGHT_TOP,
|
||||
LV_ALIGN_OUT_RIGHT_MID,
|
||||
LV_ALIGN_OUT_RIGHT_BOTTOM,
|
||||
};
|
||||
typedef uint8_t lv_align_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LV_ANIM_NONE = 0,
|
||||
@@ -333,6 +348,28 @@ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h);
|
||||
*/
|
||||
void lv_obj_align(lv_obj_t * obj,const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod);
|
||||
|
||||
/**
|
||||
* Align an object to an other object.
|
||||
* @param obj pointer to an object to align
|
||||
* @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it.
|
||||
* @param align type of alignment (see 'lv_align_t' enum)
|
||||
* @param x_mod x coordinate shift after alignment
|
||||
* @param y_mod y coordinate shift after alignment
|
||||
*/
|
||||
void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod);
|
||||
|
||||
/**
|
||||
* Realign the object based on the last `lv_obj_align` parameters.
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_realign(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Enable the automatic realign of the object when its size has changed based on the last `lv_obj_align` parameters.
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable auto realign; false: disable auto realign
|
||||
*/
|
||||
void lv_obj_set_auto_realign(lv_obj_t * obj, bool en);
|
||||
|
||||
/*---------------------
|
||||
* Appearance set
|
||||
@@ -623,6 +660,13 @@ lv_coord_t lv_obj_get_height(const lv_obj_t * obj);
|
||||
*/
|
||||
lv_coord_t lv_obj_get_ext_size(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the automatic realign property of the object.
|
||||
* @param obj pointer to an object
|
||||
* @return true: auto realign is enabled; false: auto realign is disabled
|
||||
*/
|
||||
bool lv_obj_get_auto_realign(lv_obj_t * obj);
|
||||
|
||||
/*-----------------
|
||||
* Appearance get
|
||||
*---------------*/
|
||||
|
||||
@@ -515,10 +515,9 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p)
|
||||
|
||||
/* Redraw the object */
|
||||
lv_style_t * style = lv_obj_get_style(obj);
|
||||
if(style->body.opa != LV_OPA_TRANSP) {
|
||||
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_MAIN);
|
||||
//tick_wait_ms(100); /*DEBUG: Wait after every object draw to see the order of drawing*/
|
||||
}
|
||||
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_MAIN);
|
||||
//tick_wait_ms(100); /*DEBUG: Wait after every object draw to see the order of drawing*/
|
||||
|
||||
|
||||
/*Create a new 'obj_mask' without 'ext_size' because the children can't be visible there*/
|
||||
lv_obj_get_coords(obj, &obj_area);
|
||||
@@ -547,8 +546,7 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p)
|
||||
}
|
||||
|
||||
/* If all the children are redrawn make 'post draw' design */
|
||||
if(style->body.opa != LV_OPA_TRANSP) {
|
||||
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_POST);
|
||||
}
|
||||
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_POST);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef LV_ATTRIBUTE_FLUSH_READY
|
||||
#define LV_ATTRIBUTE_FLUSH_READY
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -152,7 +155,7 @@ void lv_vdb_set_adr(void * buf1, void * buf2)
|
||||
/**
|
||||
* Call in the display driver's 'disp_flush' function when the flushing is finished
|
||||
*/
|
||||
void lv_flush_ready(void)
|
||||
LV_ATTRIBUTE_FLUSH_READY void lv_flush_ready(void)
|
||||
{
|
||||
#if LV_VDB_DOUBLE == 0
|
||||
vdb_state = LV_VDB_STATE_ACTIVE;
|
||||
|
||||
@@ -214,31 +214,32 @@ static uint8_t hex_char_to_num(char hex)
|
||||
if(hex >= '0' && hex <= '9') {
|
||||
result = hex - '0';
|
||||
}
|
||||
else {
|
||||
if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/
|
||||
|
||||
if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/
|
||||
|
||||
switch(hex) {
|
||||
case 'A':
|
||||
result = 10;
|
||||
break;
|
||||
case 'B':
|
||||
result = 11;
|
||||
break;
|
||||
case 'C':
|
||||
result = 12;
|
||||
break;
|
||||
case 'D':
|
||||
result = 13;
|
||||
break;
|
||||
case 'E':
|
||||
result = 14;
|
||||
break;
|
||||
case 'F':
|
||||
result = 15;
|
||||
break;
|
||||
default:
|
||||
result = 0;
|
||||
break;
|
||||
switch(hex) {
|
||||
case 'A':
|
||||
result = 10;
|
||||
break;
|
||||
case 'B':
|
||||
result = 11;
|
||||
break;
|
||||
case 'C':
|
||||
result = 12;
|
||||
break;
|
||||
case 'D':
|
||||
result = 13;
|
||||
break;
|
||||
case 'E':
|
||||
result = 14;
|
||||
break;
|
||||
case 'F':
|
||||
result = 15;
|
||||
break;
|
||||
default:
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -46,7 +46,7 @@ typedef struct {
|
||||
**********************/
|
||||
static void line_draw_hor(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static void line_draw_ver(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static void line_init(line_draw_t * line, const lv_point_t * p1, const lv_point_t * p2);
|
||||
static bool line_next(line_draw_t * line);
|
||||
static bool line_next_y(line_draw_t * line);
|
||||
@@ -127,7 +127,44 @@ void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv
|
||||
}
|
||||
/*Arbitrary skew line*/
|
||||
else {
|
||||
line_draw_skew(&main_line, mask, style, opa_scale);
|
||||
bool dir_ori = false;
|
||||
#if LV_ANTIALIAS
|
||||
lv_point_t p_tmp;
|
||||
|
||||
if(main_line.hor) {
|
||||
if(main_line.p1.y < main_line.p2.y) {
|
||||
dir_ori = true;
|
||||
p_tmp.x = main_line.p2.x;
|
||||
p_tmp.y = main_line.p2.y - 1;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sy = LV_MATH_ABS(main_line.sy); /*The sign can change if the line becomes horizontal*/
|
||||
}
|
||||
else if(main_line.p1.y > main_line.p2.y) {
|
||||
dir_ori = false;
|
||||
p_tmp.x = main_line.p2.x;
|
||||
p_tmp.y = main_line.p2.y + 1;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sy = -LV_MATH_ABS(main_line.sy); /*The sign can change if the line becomes horizontal*/
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(main_line.p1.x < main_line.p2.x) {
|
||||
dir_ori = true;
|
||||
p_tmp.x = main_line.p2.x - 1;
|
||||
p_tmp.y = main_line.p2.y;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sx = LV_MATH_ABS(main_line.sx); /*The sign can change if the line becomes vertical*/
|
||||
}
|
||||
else if(main_line.p1.x > main_line.p2.x) {
|
||||
dir_ori = false;
|
||||
p_tmp.x = main_line.p2.x + 1;
|
||||
p_tmp.y = main_line.p2.y;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sx = -LV_MATH_ABS(main_line.sx); /*The sign can change if the line becomes vertical*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
line_draw_skew(&main_line, dir_ori, mask, style, opa_scale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +217,7 @@ static void line_draw_ver(line_draw_t * line, const lv_area_t * mask, const lv_s
|
||||
fill_fp(&draw_area, mask, style->line.color, opa);
|
||||
}
|
||||
|
||||
static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->line.opa : (uint16_t)((uint16_t) style->line.opa * opa_scale) >> 8;
|
||||
@@ -190,7 +227,7 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
||||
vect_main.y = main_line->p2.y - main_line->p1.y;
|
||||
|
||||
if(main_line->hor) {
|
||||
if(main_line->p1.y < main_line->p2.y) {
|
||||
if(main_line->p1.y < main_line->p2.y + dir_ori) {
|
||||
vect_norm.x = - vect_main.y;
|
||||
vect_norm.y = vect_main.x;
|
||||
} else {
|
||||
@@ -198,7 +235,7 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
||||
vect_norm.y = -vect_main.x;
|
||||
}
|
||||
} else {
|
||||
if(main_line->p1.x < main_line->p2.x) {
|
||||
if(main_line->p1.x < main_line->p2.x + dir_ori) {
|
||||
vect_norm.x = vect_main.y;
|
||||
vect_norm.y = - vect_main.x;
|
||||
} else {
|
||||
@@ -262,6 +299,8 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
||||
aa_last_corner = 0;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Make the coordinates relative to the center */
|
||||
for(i = 0; i < width; i++) {
|
||||
pattern[i].x -= pattern[width - 1].x / 2;
|
||||
@@ -314,39 +353,41 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
/*Add the last part of anti-aliasing for the perpendicular ending*/
|
||||
if(main_line->hor) {
|
||||
lv_coord_t seg_w = pattern[width_safe - 1].y - pattern[aa_last_corner].y;
|
||||
if(main_line->sy < 0) {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w,
|
||||
seg_w + main_line->sy, mask, style->line.color, opa);
|
||||
if(width != 0) { /*Due to rounding error with very thin lines it looks ugly*/
|
||||
if(main_line->hor) {
|
||||
lv_coord_t seg_w = pattern[width_safe - 1].y - pattern[aa_last_corner].y;
|
||||
if(main_line->sy < 0) {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w,
|
||||
seg_w + main_line->sy, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w,
|
||||
-(seg_w + main_line->sy), mask, style->line.color, opa);
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w,
|
||||
-(seg_w + main_line->sy), mask, style->line.color, opa);
|
||||
|
||||
} else {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
||||
seg_w + main_line->sy, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
||||
-(seg_w + main_line->sy), mask, style->line.color, opa);
|
||||
}
|
||||
} else {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
||||
seg_w + main_line->sy, mask, style->line.color, opa);
|
||||
lv_coord_t seg_w = pattern[width_safe - 1].x - pattern[aa_last_corner].x;
|
||||
if(main_line->sx < 0) {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w + main_line->sx, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-(seg_w + main_line->sx), mask, style->line.color, opa);
|
||||
|
||||
} else {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w + main_line->sx, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-(seg_w + main_line->sx), mask, style->line.color, opa);
|
||||
}
|
||||
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
||||
-(seg_w + main_line->sy), mask, style->line.color, opa);
|
||||
}
|
||||
} else {
|
||||
lv_coord_t seg_w = pattern[width_safe - 1].x - pattern[aa_last_corner].x;
|
||||
if(main_line->sx < 0) {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w + main_line->sx, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-(seg_w + main_line->sx), mask, style->line.color, opa);
|
||||
|
||||
} else {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w + main_line->sx, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-(seg_w + main_line->sx), mask, style->line.color, opa);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -376,7 +417,6 @@ static void line_draw_skew(line_draw_t * main_line, const lv_area_t * mask, cons
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
volatile lv_point_t prev_p;
|
||||
prev_p.x = main_line->p1.x;
|
||||
prev_p.y = main_line->p1.y;
|
||||
|
||||
@@ -71,7 +71,7 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_sty
|
||||
lv_draw_shadow(coords, mask, style, opa_scale);
|
||||
}
|
||||
#endif
|
||||
if(style->body.empty == 0) {
|
||||
if(style->body.empty == 0 && style->body.opa >= LV_OPA_MIN) {
|
||||
lv_draw_rect_main_mid(coords, mask, style, opa_scale);
|
||||
|
||||
if(style->body.radius != 0) {
|
||||
@@ -79,7 +79,7 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_sty
|
||||
}
|
||||
}
|
||||
|
||||
if(style->body.border.width != 0 && style->body.border.part != LV_BORDER_NONE) {
|
||||
if(style->body.border.width != 0 && style->body.border.part != LV_BORDER_NONE && style->body.border.opa >= LV_OPA_MIN) {
|
||||
lv_draw_rect_border_straight(coords, mask, style, opa_scale);
|
||||
|
||||
if(style->body.radius != 0) {
|
||||
|
||||
@@ -680,7 +680,7 @@ static inline lv_color_t color_mix_2_alpha(lv_color_t bg_color, lv_opa_t bg_opa,
|
||||
/*Save the parameters and the result. If they will be asked again don't compute again*/
|
||||
static lv_opa_t fg_opa_save = 0;
|
||||
static lv_opa_t bg_opa_save = 0;
|
||||
static lv_color_t c = {0};
|
||||
static lv_color_t c = {{0}};
|
||||
|
||||
if(fg_opa != fg_opa_save || bg_opa != bg_opa_save) {
|
||||
fg_opa_save = fg_opa;
|
||||
|
||||
@@ -109,6 +109,9 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
|
||||
{
|
||||
bool cont = false;
|
||||
|
||||
memset(data, 0, sizeof(lv_indev_data_t));
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
|
||||
if(indev->driver.read) {
|
||||
data->user_data = indev->driver.user_data;
|
||||
|
||||
@@ -117,7 +120,6 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
|
||||
LV_LOG_TRACE("idnev read finished");
|
||||
} else {
|
||||
LV_LOG_WARN("indev function registered");
|
||||
memset(data, 0, sizeof(lv_indev_data_t));
|
||||
}
|
||||
|
||||
return cont;
|
||||
|
||||
@@ -115,6 +115,19 @@ bool lv_anim_del(void * var, lv_anim_fp_t fp)
|
||||
return del;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of currently running animations
|
||||
* @return the number of running animations
|
||||
*/
|
||||
uint16_t lv_anim_count_running(void)
|
||||
{
|
||||
uint16_t cnt = 0;
|
||||
lv_anim_t * a;
|
||||
LL_READ(anim_ll, a) cnt++;
|
||||
|
||||
return cnt++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the time of an animation with a given speed and the start and end values
|
||||
* @param speed speed of animation in unit/sec
|
||||
@@ -183,6 +196,91 @@ int32_t lv_anim_path_ease_in_out(const lv_anim_t * a)
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with overshoot at the end
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_overshoot(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
|
||||
uint32_t t;
|
||||
if(a->time == a->act_time) t = 1024;
|
||||
else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time;
|
||||
|
||||
int32_t step = lv_bezier3(t, 0, 600, 1300, 1024);
|
||||
|
||||
int32_t new_value;
|
||||
new_value = (int32_t) step * (a->end - a->start);
|
||||
new_value = new_value >> 10;
|
||||
new_value += a->start;
|
||||
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with 3 bounces
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_bounce(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
uint32_t t;
|
||||
if(a->time == a->act_time) t = 1024;
|
||||
else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time;
|
||||
|
||||
int32_t diff = (a->end - a->start);
|
||||
|
||||
/*3 bounces has 5 parts: 3 down and 2 up. One part is t / 5 long*/
|
||||
|
||||
if(t >= 0 && t < 408){
|
||||
/*Go down*/
|
||||
t = (t * 2500) >> 10; /*[0..1024] range*/
|
||||
}
|
||||
else if(t >= 408 && t < 614) {
|
||||
/*First bounce back*/
|
||||
t -= 408;
|
||||
t = t * 5; /*to [0..1024] range*/
|
||||
t = 1024 - t;
|
||||
diff = diff / 6;
|
||||
}
|
||||
else if(t >= 614 && t < 819) {
|
||||
/*Fall back*/
|
||||
t -= 614;
|
||||
t = t * 5; /*to [0..1024] range*/
|
||||
diff = diff / 6;
|
||||
}
|
||||
else if(t >= 819 && t < 921) {
|
||||
/*Second bounce back*/
|
||||
t -= 819;
|
||||
t = t * 10; /*to [0..1024] range*/
|
||||
t = 1024 - t;
|
||||
diff = diff / 16;
|
||||
}
|
||||
else if(t >= 921 && t <= 1024) {
|
||||
/*Fall back*/
|
||||
t -= 921;
|
||||
t = t * 10; /*to [0..1024] range*/
|
||||
diff = diff / 16;
|
||||
}
|
||||
|
||||
if(t > 1024) t = 1024;
|
||||
|
||||
int32_t step = lv_bezier3(t, 1024, 1024, 800, 0);
|
||||
|
||||
int32_t new_value;
|
||||
|
||||
new_value = (int32_t) step * diff;
|
||||
new_value = new_value >> 10;
|
||||
new_value = a->end - new_value;
|
||||
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying step characteristic.
|
||||
* (Set end value on the end of the animation)
|
||||
|
||||
@@ -99,6 +99,12 @@ void lv_anim_create(lv_anim_t * anim_p);
|
||||
*/
|
||||
bool lv_anim_del(void * var, lv_anim_fp_t fp);
|
||||
|
||||
/**
|
||||
* Get the number of currently running animations
|
||||
* @return the number of running animations
|
||||
*/
|
||||
uint16_t lv_anim_count_running(void);
|
||||
|
||||
/**
|
||||
* Calculate the time of an animation with a given speed and the start and end values
|
||||
* @param speed speed of animation in unit/sec
|
||||
@@ -123,6 +129,20 @@ int32_t lv_anim_path_linear(const lv_anim_t *a);
|
||||
*/
|
||||
int32_t lv_anim_path_ease_in_out(const lv_anim_t *a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with overshoot at the end
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_overshoot(const lv_anim_t * a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with 3 bounces
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_bounce(const lv_anim_t * a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying step characteristic.
|
||||
* (Set end value on the end of the animation)
|
||||
|
||||
@@ -34,7 +34,7 @@ extern "C" {
|
||||
|
||||
// Check GCC
|
||||
#ifdef __GNUC__
|
||||
# if __x86_64__ || __ppc64__
|
||||
# if defined(__x86_64__) || defined(__ppc64__)
|
||||
# define LV_MEM_ENV64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -340,16 +340,27 @@ lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm)
|
||||
return ext->action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pressed button
|
||||
* @param btnm pointer to button matrix object
|
||||
* @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset)
|
||||
*/
|
||||
uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm)
|
||||
{
|
||||
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
|
||||
return ext->btn_id_pr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the toggled button
|
||||
* @param btnm pointer to button matrix object
|
||||
* @return index of the currently toggled button (0: if unset)
|
||||
* @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset)
|
||||
*/
|
||||
uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm)
|
||||
{
|
||||
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
|
||||
|
||||
if(ext->toggle == 0) return 0;
|
||||
if(ext->toggle == 0) return LV_BTNM_PR_NONE;
|
||||
else return ext->btn_id_tgl;
|
||||
}
|
||||
|
||||
@@ -581,7 +592,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
}
|
||||
|
||||
#if USE_LV_GROUP
|
||||
/*Leave the clicked button as pressed if this the focused object in a group*/
|
||||
/*Leave the clicked button when releases if this not the focused object in a group*/
|
||||
lv_group_t * g = lv_obj_get_group(btnm);
|
||||
if(lv_group_get_focused(g) != btnm) {
|
||||
ext->btn_id_pr = LV_BTNM_PR_NONE;
|
||||
|
||||
@@ -147,11 +147,17 @@ const char ** lv_btnm_get_map(const lv_obj_t * btnm);
|
||||
*/
|
||||
lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm);
|
||||
|
||||
/**
|
||||
* Get the pressed button
|
||||
* @param btnm pointer to button matrix object
|
||||
* @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset)
|
||||
*/
|
||||
uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm);
|
||||
|
||||
/**
|
||||
* Get the toggled button
|
||||
* @param btnm pointer to button matrix object
|
||||
* @return index of the currently toggled button (0: if unset)
|
||||
* @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset)
|
||||
*/
|
||||
uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm);
|
||||
|
||||
|
||||
@@ -801,7 +801,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar);
|
||||
label_area.y1 = calendar->coords.y1 + get_header_height(calendar) +
|
||||
ext->style_day_names->body.padding.ver + lv_font_get_height(ext->style_day_names->text.font) +
|
||||
ext->style_day_names->body.padding.ver + style_bg->body.padding.inner;
|
||||
ext->style_day_names->body.padding.ver;
|
||||
label_area.y2 = label_area.y1 + lv_font_get_height(style_bg->text.font);
|
||||
|
||||
lv_coord_t w = lv_obj_get_width(calendar) - 2 * hpad;
|
||||
|
||||
@@ -34,6 +34,7 @@ static void lv_chart_draw_div(lv_obj_t * chart, const lv_area_t * mask);
|
||||
static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask);
|
||||
static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask);
|
||||
static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask);
|
||||
static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -57,8 +58,6 @@ static lv_signal_func_t ancestor_signal;
|
||||
*/
|
||||
lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
{
|
||||
|
||||
|
||||
LV_LOG_TRACE("chart create started");
|
||||
|
||||
/*Create the ancestor basic object*/
|
||||
@@ -152,6 +151,8 @@ lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ser->start_point = 0;
|
||||
|
||||
uint16_t i;
|
||||
lv_coord_t * p_tmp = ser->points;
|
||||
for(i = 0; i < ext->point_cnt; i++) {
|
||||
@@ -178,8 +179,11 @@ void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie)
|
||||
return;
|
||||
for(uint32_t i = 0; i < ext->point_cnt; i++)
|
||||
{
|
||||
serie->points[i] = -1;
|
||||
serie->points[i] = LV_CHART_POINT_DEF;
|
||||
}
|
||||
|
||||
serie->start_point = 0;
|
||||
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -253,18 +257,44 @@ void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt)
|
||||
if(point_cnt < 1) point_cnt = 1;
|
||||
|
||||
LL_READ_BACK(ext->series_ll, ser) {
|
||||
ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt);
|
||||
lv_mem_assert(ser->points);
|
||||
if(ser->points == NULL) return;
|
||||
/*Initialize the new points*/
|
||||
if(point_cnt > point_cnt_old) {
|
||||
for(i = point_cnt_old - 1; i < point_cnt; i++) {
|
||||
ser->points[i] = def;
|
||||
if(ser->start_point != 0) {
|
||||
lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * point_cnt);
|
||||
lv_mem_assert(new_points);
|
||||
if(new_points == NULL) return;
|
||||
|
||||
if(point_cnt >= point_cnt_old) {
|
||||
for(i = 0; i < point_cnt_old; i++) {
|
||||
new_points[i] = ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/
|
||||
}
|
||||
for(i = point_cnt_old; i < point_cnt; i++) {
|
||||
new_points[i] = def; /*Fill up the rest with default value*/
|
||||
}
|
||||
} else {
|
||||
for(i = 0; i < point_cnt; i++) {
|
||||
new_points[i] = ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/
|
||||
}
|
||||
}
|
||||
|
||||
/*Switch over pointer from old to new*/
|
||||
lv_mem_free(ser->points);
|
||||
ser->points = new_points;
|
||||
} else {
|
||||
ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt);
|
||||
lv_mem_assert(ser->points);
|
||||
if(ser->points == NULL) return;
|
||||
/*Initialize the new points*/
|
||||
if(point_cnt > point_cnt_old) {
|
||||
for(i = point_cnt_old - 1; i < point_cnt; i++) {
|
||||
ser->points[i] = def;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ser->start_point = 0;
|
||||
}
|
||||
|
||||
ext->point_cnt = point_cnt;
|
||||
|
||||
lv_chart_refresh(chart);
|
||||
}
|
||||
|
||||
@@ -322,6 +352,7 @@ void lv_chart_init_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t
|
||||
for(i = 0; i < ext->point_cnt; i++) {
|
||||
ser->points[i] = y;
|
||||
}
|
||||
ser->start_point = 0;
|
||||
lv_chart_refresh(chart);
|
||||
}
|
||||
|
||||
@@ -335,27 +366,24 @@ void lv_chart_set_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t *
|
||||
{
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
|
||||
memcpy(ser->points, y_array, ext->point_cnt * (sizeof(lv_coord_t)));
|
||||
ser->start_point = 0;
|
||||
lv_chart_refresh(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift all data right and set the most right data on a data line
|
||||
* Shift all data left and set the rightmost data on a data line
|
||||
* @param chart pointer to chart object
|
||||
* @param ser pointer to a data series on 'chart'
|
||||
* @param y the new value of the most right data
|
||||
* @param y the new value of the rightmost data
|
||||
*/
|
||||
void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y)
|
||||
{
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; i < ext->point_cnt - 1; i++) {
|
||||
ser->points[i] = ser->points[i + 1];
|
||||
}
|
||||
ser->points[ser->start_point] = y; /*This was the place of the former left most value, after shifting it is the rightmost*/
|
||||
ser->start_point = (ser->start_point + 1) % ext->point_cnt;
|
||||
|
||||
ser->points[ext->point_cnt - 1] = y;
|
||||
lv_chart_refresh(chart);
|
||||
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -460,6 +488,7 @@ static bool lv_chart_design(lv_obj_t * chart, const lv_area_t * mask, lv_design_
|
||||
if(ext->type & LV_CHART_TYPE_LINE) lv_chart_draw_lines(chart, mask);
|
||||
if(ext->type & LV_CHART_TYPE_COLUMN) lv_chart_draw_cols(chart, mask);
|
||||
if(ext->type & LV_CHART_TYPE_POINT) lv_chart_draw_points(chart, mask);
|
||||
if(ext->type & LV_CHART_TYPE_VERTICAL_LINE) lv_chart_draw_vertical_lines(chart, mask);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -580,6 +609,8 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask)
|
||||
lv_coord_t x_ofs = chart->coords.x1;
|
||||
lv_coord_t y_ofs = chart->coords.y1;
|
||||
int32_t y_tmp;
|
||||
lv_coord_t p_prev;
|
||||
lv_coord_t p_act;
|
||||
lv_chart_series_t * ser;
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(chart);
|
||||
lv_style_t style;
|
||||
@@ -593,7 +624,9 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask)
|
||||
|
||||
p1.x = 0 + x_ofs;
|
||||
p2.x = 0 + x_ofs;
|
||||
y_tmp = (int32_t)((int32_t) ser->points[0] - ext->ymin) * h;
|
||||
|
||||
p_prev = ser->start_point;
|
||||
y_tmp = (int32_t)((int32_t) ser->points[p_prev] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
p2.y = h - y_tmp + y_ofs;
|
||||
|
||||
@@ -603,12 +636,16 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const lv_area_t * mask)
|
||||
|
||||
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
|
||||
|
||||
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
|
||||
p_act = (ser->start_point + i) % ext->point_cnt;
|
||||
|
||||
y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
p2.y = h - y_tmp + y_ofs;
|
||||
|
||||
if(ser->points[i - 1] >= 0 && ser->points[i] >= 0)
|
||||
if(ser->points[p_prev] != LV_CHART_POINT_DEF && ser->points[p_act] != LV_CHART_POINT_DEF)
|
||||
lv_draw_line(&p1, &p2, mask, &style, opa_scale);
|
||||
|
||||
p_prev = p_act;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -629,6 +666,7 @@ static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask)
|
||||
lv_coord_t x_ofs = chart->coords.x1;
|
||||
lv_coord_t y_ofs = chart->coords.y1;
|
||||
int32_t y_tmp;
|
||||
lv_coord_t p_act;
|
||||
lv_chart_series_t * ser;
|
||||
uint8_t series_cnt = 0;
|
||||
lv_style_t style_point;
|
||||
@@ -649,14 +687,14 @@ static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask)
|
||||
cir_a.x1 = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
|
||||
cir_a.x2 = cir_a.x1 + style_point.body.radius;
|
||||
cir_a.x1 -= style_point.body.radius;
|
||||
|
||||
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
|
||||
p_act = (ser->start_point + i) % ext->point_cnt;
|
||||
y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
cir_a.y1 = h - y_tmp + y_ofs;
|
||||
cir_a.y2 = cir_a.y1 + style_point.body.radius;
|
||||
cir_a.y1 -= style_point.body.radius;
|
||||
|
||||
if(ser->points[i] >= 0)
|
||||
if(ser->points[p_act] != LV_CHART_POINT_DEF)
|
||||
lv_draw_rect(&cir_a, mask, &style_point, lv_obj_get_opa_scale(chart));
|
||||
}
|
||||
series_cnt++;
|
||||
@@ -693,6 +731,7 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask)
|
||||
col_a.y2 = chart->coords.y2;
|
||||
|
||||
lv_coord_t x_act;
|
||||
printf("\n", y_tmp);
|
||||
|
||||
/*Go through all points*/
|
||||
for(i = 0; i < ext->point_cnt; i ++) {
|
||||
@@ -707,15 +746,92 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const lv_area_t * mask)
|
||||
col_a.x2 = col_a.x1 + col_w;
|
||||
x_act += col_w;
|
||||
|
||||
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
|
||||
lv_coord_t p_act = (ser->start_point + i) % ext->point_cnt;
|
||||
y_tmp = (int32_t)((int32_t) ser->points[p_act] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
printf("ytmp:%d\n", y_tmp);
|
||||
col_a.y1 = h - y_tmp + chart->coords.y1;
|
||||
|
||||
mask_ret = lv_area_intersect(&col_mask, mask, &col_a);
|
||||
if(mask_ret != false && ser->points[i] >= 0) {
|
||||
if(mask_ret != false && ser->points[p_act] != LV_CHART_POINT_DEF) {
|
||||
lv_draw_rect(&chart->coords, &col_mask, &rects, lv_obj_get_opa_scale(chart));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the data lines as vertical lines on a chart if there is only 1px between point
|
||||
* @param obj pointer to chart object
|
||||
*/
|
||||
static void lv_chart_draw_vertical_lines(lv_obj_t * chart, const lv_area_t * mask)
|
||||
{
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart);
|
||||
|
||||
uint16_t i;
|
||||
lv_point_t p1;
|
||||
lv_point_t p2;
|
||||
lv_coord_t w = lv_obj_get_width(chart);
|
||||
lv_coord_t h = lv_obj_get_height(chart);
|
||||
lv_coord_t x_ofs = chart->coords.x1;
|
||||
lv_coord_t y_ofs = chart->coords.y1;
|
||||
int32_t y_tmp;
|
||||
lv_chart_series_t * ser;
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(chart);
|
||||
lv_style_t style;
|
||||
lv_style_copy(&style, &lv_style_plain);
|
||||
style.line.opa = ext->series.opa;
|
||||
style.line.width = ext->series.width;
|
||||
|
||||
/*Go through all data lines*/
|
||||
LL_READ_BACK(ext->series_ll, ser) {
|
||||
style.line.color = ser->color;
|
||||
|
||||
p1.x = 0 + x_ofs;
|
||||
p2.x = 0 + x_ofs;
|
||||
y_tmp = (int32_t)((int32_t) ser->points[0] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
p2.y = h - y_tmp + y_ofs;
|
||||
|
||||
if(ext->point_cnt == w)
|
||||
{
|
||||
for(i = 0; i < ext->point_cnt; i++)
|
||||
{
|
||||
|
||||
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
p2.y = h - y_tmp + y_ofs;
|
||||
|
||||
if(p1.y == p2.y)
|
||||
{
|
||||
p2.x++;
|
||||
}
|
||||
|
||||
lv_draw_line(&p1, &p2, mask, &style, opa_scale);
|
||||
|
||||
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
|
||||
p1.x = p2.x;
|
||||
p1.y = p2.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 1; i < ext->point_cnt; i ++) {
|
||||
p1.x = p2.x;
|
||||
p1.y = p2.y;
|
||||
|
||||
p2.x = ((w * i) / (ext->point_cnt - 1)) + x_ofs;
|
||||
|
||||
y_tmp = (int32_t)((int32_t) ser->points[i] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
p2.y = h - y_tmp + y_ofs;
|
||||
|
||||
if(ser->points[i - 1] >= 0 && ser->points[i] >= 0)
|
||||
{
|
||||
lv_draw_line(&p1, &p2, mask, &style, opa_scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -36,6 +36,7 @@ typedef struct
|
||||
{
|
||||
lv_coord_t * points;
|
||||
lv_color_t color;
|
||||
uint16_t start_point;
|
||||
} lv_chart_series_t;
|
||||
|
||||
/*Data of chart */
|
||||
@@ -49,12 +50,12 @@ typedef struct
|
||||
uint8_t hdiv_cnt; /*Number of horizontal division lines*/
|
||||
uint8_t vdiv_cnt; /*Number of vertical division lines*/
|
||||
uint16_t point_cnt; /*Point number in a data line*/
|
||||
uint8_t type :3; /*Line, column or point chart (from 'lv_chart_type_t')*/
|
||||
uint8_t type :4; /*Line, column or point chart (from 'lv_chart_type_t')*/
|
||||
struct {
|
||||
lv_coord_t width; /*Line width or point radius*/
|
||||
uint8_t num; /*Number of data lines in dl_ll*/
|
||||
lv_opa_t opa; /*Opacity of data lines*/
|
||||
lv_opa_t dark; /*Dark level of the point/column bottoms*/
|
||||
uint8_t num; /*Number of data lines in dl_ll*/
|
||||
lv_opa_t opa; /*Opacity of data lines*/
|
||||
lv_opa_t dark; /*Dark level of the point/column bottoms*/
|
||||
} series;
|
||||
} lv_chart_ext_t;
|
||||
|
||||
@@ -64,6 +65,7 @@ enum
|
||||
LV_CHART_TYPE_LINE = 0x01,
|
||||
LV_CHART_TYPE_COLUMN = 0x02,
|
||||
LV_CHART_TYPE_POINT = 0x04,
|
||||
LV_CHART_TYPE_VERTICAL_LINE = 0x08,
|
||||
};
|
||||
typedef uint8_t lv_chart_type_t;
|
||||
|
||||
|
||||
@@ -164,7 +164,9 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img)
|
||||
|
||||
/* If the new and the old src are the same then it was only a refresh.*/
|
||||
if(ext->src != src_img) {
|
||||
lv_mem_free(ext->src);
|
||||
if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_mem_free(ext->src); /*If memory was allocated because of the previous `src_type` then free it*/
|
||||
}
|
||||
char * new_str = lv_mem_alloc(strlen(src_img) + 1);
|
||||
lv_mem_assert(new_str);
|
||||
if(new_str == NULL) return;
|
||||
|
||||
@@ -61,11 +61,14 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_imgbtn);
|
||||
|
||||
/*Initialize the allocated 'ext' */
|
||||
ext->img_src[LV_BTN_STATE_REL] = NULL;
|
||||
ext->img_src[LV_BTN_STATE_PR] = NULL;
|
||||
ext->img_src[LV_BTN_STATE_TGL_REL] = NULL;
|
||||
ext->img_src[LV_BTN_STATE_TGL_PR] = NULL;;
|
||||
ext->img_src[LV_BTN_STATE_INA] = NULL;
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
memset(ext->img_src, 0, sizeof(ext->img_src));
|
||||
#else
|
||||
memset(ext->img_src_left, 0, sizeof(ext->img_src_left));
|
||||
memset(ext->img_src_mid, 0, sizeof(ext->img_src_mid));
|
||||
memset(ext->img_src_right, 0, sizeof(ext->img_src_right));
|
||||
#endif
|
||||
|
||||
ext->act_cf = LV_IMG_CF_UNKOWN;
|
||||
|
||||
/*The signal and design functions are not copied so set them here*/
|
||||
@@ -79,12 +82,13 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
/*Copy an existing image button*/
|
||||
else {
|
||||
lv_imgbtn_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
|
||||
lv_imgbtn_set_src(new_imgbtn, LV_BTN_STATE_REL, copy_ext->img_src[LV_BTN_STATE_REL]);
|
||||
lv_imgbtn_set_src(new_imgbtn, LV_BTN_STATE_PR, copy_ext->img_src[LV_BTN_STATE_PR]);
|
||||
lv_imgbtn_set_src(new_imgbtn, LV_BTN_STATE_TGL_REL, copy_ext->img_src[LV_BTN_STATE_TGL_REL]);
|
||||
lv_imgbtn_set_src(new_imgbtn, LV_BTN_STATE_TGL_PR, copy_ext->img_src[LV_BTN_STATE_TGL_PR]);
|
||||
lv_imgbtn_set_src(new_imgbtn, LV_BTN_STATE_INA, copy_ext->img_src[LV_BTN_STATE_INA]);
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
memset(ext->img_src, 0, sizeof(ext->img_src));
|
||||
#else
|
||||
memcpy(ext->img_src_left, copy_ext->img_src_left, sizeof(ext->img_src_left));
|
||||
memcpy(ext->img_src_mid, copy_ext->img_src_mid, sizeof(ext->img_src_mid));
|
||||
memcpy(ext->img_src_right, copy_ext->img_src_right, sizeof(ext->img_src_right));
|
||||
#endif
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_imgbtn);
|
||||
}
|
||||
@@ -98,6 +102,7 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
/**
|
||||
* Set images for a state of the image button
|
||||
* @param imgbtn pointer to an image button object
|
||||
@@ -113,6 +118,28 @@ void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src
|
||||
refr_img(imgbtn);
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Set images for a state of the image button
|
||||
* @param imgbtn pointer to an image button object
|
||||
* @param state for which state set the new image (from `lv_btn_state_t`) `
|
||||
* @param src_left pointer to an image source for the left side of the button (a C array or path to a file)
|
||||
* @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file)
|
||||
* @param src_right pointer to an image source for the right side of the button (a C array or path to a file)
|
||||
*/
|
||||
void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right)
|
||||
{
|
||||
lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn);
|
||||
|
||||
ext->img_src_left[state] = src_left;
|
||||
ext->img_src_mid[state] = src_mid;
|
||||
ext->img_src_right[state] = src_right;
|
||||
|
||||
refr_img(imgbtn);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set a style of a image button.
|
||||
* @param imgbtn pointer to image button object
|
||||
@@ -138,7 +165,7 @@ const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state)
|
||||
{
|
||||
lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn);
|
||||
|
||||
return ext->img_src[state];
|
||||
return NULL;//ext->img_src[state];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,10 +218,62 @@ static bool lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * mask, lv_desig
|
||||
/*Just draw an image*/
|
||||
lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn);
|
||||
lv_btn_state_t state = lv_imgbtn_get_state(imgbtn);
|
||||
const void * src = ext->img_src[state];
|
||||
lv_style_t * style = lv_imgbtn_get_style(imgbtn, state);
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(imgbtn);
|
||||
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
const void * src = ext->img_src[state];
|
||||
lv_draw_img(&imgbtn->coords, mask, src, style, opa_scale);
|
||||
#else
|
||||
const void * src;
|
||||
lv_img_header_t header;
|
||||
lv_area_t coords;
|
||||
lv_coord_t left_w = 0;
|
||||
lv_coord_t right_w = 0;
|
||||
|
||||
src = ext->img_src_left[state];
|
||||
if(src) {
|
||||
lv_img_dsc_get_info(src, &header);
|
||||
left_w = header.w;
|
||||
coords.x1 = imgbtn->coords.x1;
|
||||
coords.y1 = imgbtn->coords.y1;
|
||||
coords.x2 = coords.x1 + header.w - 1;
|
||||
coords.y2 = coords.y1 + header.h - 1;
|
||||
lv_draw_img(&coords, mask, src, style, opa_scale);
|
||||
}
|
||||
|
||||
src = ext->img_src_right[state];
|
||||
if(src) {
|
||||
lv_img_dsc_get_info(src, &header);
|
||||
right_w = header.w;
|
||||
coords.x1 = imgbtn->coords.x2 - header.w + 1;
|
||||
coords.y1 = imgbtn->coords.y1;
|
||||
coords.x2 = imgbtn->coords.x2;
|
||||
coords.y2 = imgbtn->coords.y1 + header.h - 1;
|
||||
lv_draw_img(&coords, mask, src, style, opa_scale);
|
||||
}
|
||||
|
||||
src = ext->img_src_mid[state];
|
||||
if(src) {
|
||||
lv_coord_t obj_w = lv_obj_get_width(imgbtn);
|
||||
lv_coord_t i;
|
||||
lv_img_dsc_get_info(src, &header);
|
||||
|
||||
coords.x1 = imgbtn->coords.x1 + left_w ;
|
||||
coords.y1 = imgbtn->coords.y1;
|
||||
coords.x2 = coords.x1 + header.w - 1;
|
||||
coords.y2 = imgbtn->coords.y1 + header.h - 1;
|
||||
|
||||
for(i = 0; i < obj_w - right_w - left_w; i += header.w) {
|
||||
lv_draw_img(&coords, mask, src, style, opa_scale);
|
||||
coords.x1 = coords.x2 + 1;
|
||||
coords.x2 += header.w;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
@@ -243,17 +322,27 @@ static void refr_img(lv_obj_t * imgbtn)
|
||||
lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn);
|
||||
lv_btn_state_t state = lv_imgbtn_get_state(imgbtn);
|
||||
lv_img_header_t header;
|
||||
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
const void * src = ext->img_src[state];
|
||||
#else
|
||||
const void * src = ext->img_src_mid[state];
|
||||
#endif
|
||||
|
||||
lv_res_t info_res;
|
||||
info_res = lv_img_dsc_get_info(src, &header);
|
||||
if(info_res == LV_RES_OK) {
|
||||
ext->act_cf = header.cf;
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
lv_obj_set_size(imgbtn, header.w, header.h);
|
||||
#else
|
||||
lv_obj_set_height(imgbtn, header.h);
|
||||
#endif
|
||||
} else {
|
||||
ext->act_cf = LV_IMG_CF_UNKOWN;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,13 @@ extern "C" {
|
||||
typedef struct {
|
||||
lv_btn_ext_t btn; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
const void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/
|
||||
#else
|
||||
const void * img_src_left[LV_BTN_STATE_NUM]; /*Store left side images to each state*/
|
||||
const void * img_src_mid[LV_BTN_STATE_NUM]; /*Store center images to each state*/
|
||||
const void * img_src_right[LV_BTN_STATE_NUM]; /*Store right side images to each state*/
|
||||
#endif
|
||||
lv_img_cf_t act_cf; /*Color format of the currently active image*/
|
||||
} lv_imgbtn_ext_t;
|
||||
|
||||
@@ -78,6 +84,7 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy);
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
#if LV_IMGBTN_TILED == 0
|
||||
/**
|
||||
* Set images for a state of the image button
|
||||
* @param imgbtn pointer to an image button object
|
||||
@@ -85,6 +92,18 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy);
|
||||
* @param src pointer to an image source (a C array or path to a file)
|
||||
*/
|
||||
void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src);
|
||||
#else
|
||||
/**
|
||||
* Set images for a state of the image button
|
||||
* @param imgbtn pointer to an image button object
|
||||
* @param state for which state set the new image (from `lv_btn_state_t`) `
|
||||
* @param src_left pointer to an image source for the left side of the button (a C array or path to a file)
|
||||
* @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file)
|
||||
* @param src_right pointer to an image source for the right side of the button (a C array or path to a file)
|
||||
*/
|
||||
void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Enable the toggled states. On release the button will change from/to toggled state.
|
||||
|
||||
@@ -341,6 +341,9 @@ void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, lv_style_t * style
|
||||
case LV_LIST_STYLE_SB:
|
||||
lv_page_set_style(list, LV_PAGE_STYLE_SB, style);
|
||||
break;
|
||||
case LV_LIST_STYLE_EDGE_FLASH:
|
||||
lv_page_set_style(list, LV_PAGE_STYLE_EDGE_FLASH, style);
|
||||
break;
|
||||
case LV_LIST_STYLE_BTN_REL:
|
||||
ext->styles_btn[LV_BTN_STATE_REL] = style;
|
||||
btn_style_refr = LV_BTN_STYLE_REL;
|
||||
@@ -571,6 +574,9 @@ lv_style_t * lv_list_get_style(const lv_obj_t * list, lv_list_style_t type)
|
||||
case LV_LIST_STYLE_SB:
|
||||
style = lv_page_get_style(list, LV_PAGE_STYLE_SCRL);
|
||||
break;
|
||||
case LV_LIST_STYLE_EDGE_FLASH:
|
||||
style = lv_page_get_style(list, LV_PAGE_STYLE_EDGE_FLASH);
|
||||
break;
|
||||
case LV_LIST_STYLE_BTN_REL:
|
||||
style = ext->styles_btn[LV_BTN_STATE_REL];
|
||||
break;
|
||||
@@ -854,9 +860,11 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
if(sign == LV_SIGNAL_RELEASED) {
|
||||
|
||||
#if USE_LV_GROUP
|
||||
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
||||
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
||||
ext->page.scroll_prop_ip = 0;
|
||||
|
||||
#if USE_LV_GROUP
|
||||
lv_group_t * g = lv_obj_get_group(list);
|
||||
if(lv_group_get_focused(g) == list && lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
||||
/* Is the list is focused then be sure only the button being released
|
||||
@@ -877,22 +885,25 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para
|
||||
* to mark it as selected (pressed state)*/
|
||||
last_clicked_btn = btn;
|
||||
#endif
|
||||
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
||||
if(lv_indev_is_dragging(lv_indev_get_act()) == false && ext->single_selected_mode)
|
||||
{
|
||||
lv_list_btn_single_selected(btn);
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_LV_GROUP
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
else if(sign == LV_SIGNAL_PRESS_LOST) {
|
||||
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
||||
lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
|
||||
ext->page.scroll_prop_ip = 0;
|
||||
}
|
||||
else if(sign == LV_SIGNAL_CLEANUP) {
|
||||
|
||||
#if USE_LV_GROUP
|
||||
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
||||
lv_obj_t * sel = lv_list_get_btn_selected(list);
|
||||
if(sel == btn) lv_list_set_btn_selected(list, lv_list_get_next_btn(list, btn));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ enum {
|
||||
LV_LIST_STYLE_BG,
|
||||
LV_LIST_STYLE_SCRL,
|
||||
LV_LIST_STYLE_SB,
|
||||
LV_LIST_STYLE_EDGE_FLASH,
|
||||
LV_LIST_STYLE_BTN_REL,
|
||||
LV_LIST_STYLE_BTN_PR,
|
||||
LV_LIST_STYLE_BTN_TGL_REL,
|
||||
@@ -165,6 +166,16 @@ static inline void lv_list_set_scroll_propagation(lv_obj_t * list, bool en)
|
||||
lv_page_set_scroll_propagation(list, en);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the edge flash effect. (Show an arc when the an edge is reached)
|
||||
* @param list pointer to a List
|
||||
* @param en true or false to enable/disable end flash
|
||||
*/
|
||||
static inline void lv_list_set_edge_flash(lv_obj_t * list, bool en)
|
||||
{
|
||||
lv_page_set_edge_flash(list, en);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a list
|
||||
* @param list pointer to a list object
|
||||
@@ -272,6 +283,16 @@ static inline bool lv_list_get_scroll_propagation(lv_obj_t * list)
|
||||
return lv_page_get_scroll_propagation(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scroll propagation property
|
||||
* @param list pointer to a List
|
||||
* @return true or false
|
||||
*/
|
||||
static inline bool lv_list_get_edge_flash(lv_obj_t * list)
|
||||
{
|
||||
return lv_page_get_edge_flash(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a style of a list
|
||||
* @param list pointer to a list object
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_PAGE_SB_MIN_SIZE (LV_DPI / 8)
|
||||
#define LV_PAGE_SCROLL_ANIM_TIME 200 /*[ms] Scroll anim time on `lv_page_scroll_up/down/left/rigth`*/
|
||||
#define LV_PAGE_SB_MIN_SIZE (LV_DPI / 8)
|
||||
#define LV_PAGE_SCROLL_ANIM_TIME 200 /*[ms] Scroll anim time on `lv_page_scroll_up/down/left/rigth`*/
|
||||
#define LV_PAGE_END_FLASH_SIZE (LV_DPI / 4)
|
||||
#define LV_PAGE_END_ANIM_TIME 300
|
||||
#define LV_PAGE_END_ANIM_WAIT_TIME 300
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -34,6 +37,8 @@ static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mo
|
||||
static bool lv_scrl_design(lv_obj_t * scrl, const lv_area_t * mask, lv_design_mode_t mode);
|
||||
static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
|
||||
static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
|
||||
static void edge_flash_anim(void * page, int32_t v);
|
||||
static void edge_flash_anim_end(void * page);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -79,6 +84,13 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->sb.ver_draw = 0;
|
||||
ext->sb.style = &lv_style_pretty;
|
||||
ext->sb.mode = LV_SB_MODE_AUTO;
|
||||
ext->edge_flash.enabled = 0;
|
||||
ext->edge_flash.bottom_ip = 0;
|
||||
ext->edge_flash.top_ip = 0;
|
||||
ext->edge_flash.left_ip = 0;
|
||||
ext->edge_flash.right_ip = 0;
|
||||
ext->edge_flash.state = 0;
|
||||
ext->edge_flash.style = &lv_style_plain_color;
|
||||
ext->arrow_scroll = 0;
|
||||
ext->scroll_prop = 0;
|
||||
ext->scroll_prop_ip = 0;
|
||||
@@ -166,7 +178,7 @@ void lv_page_clean(lv_obj_t * obj)
|
||||
/**
|
||||
* Set a release action for the page
|
||||
* @param page pointer to a page object
|
||||
* @param rel_action a function to call when the page is released
|
||||
* @param rel_action a function to call when the page is release
|
||||
*/
|
||||
void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action)
|
||||
{
|
||||
@@ -231,6 +243,17 @@ void lv_page_set_scroll_propagation(lv_obj_t * page, bool en)
|
||||
ext->scroll_prop = en ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the edge flash effect. (Show an arc when the an edge is reached)
|
||||
* @param page pointer to a Page
|
||||
* @param en true or false to enable/disable end flash
|
||||
*/
|
||||
void lv_page_set_edge_flash(lv_obj_t * page, bool en)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
ext->edge_flash.enabled = en ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a page
|
||||
* @param page pointer to a page object
|
||||
@@ -256,6 +279,9 @@ void lv_page_set_style(lv_obj_t * page, lv_page_style_t type, lv_style_t * style
|
||||
lv_obj_refresh_ext_size(page);
|
||||
lv_obj_invalidate(page);
|
||||
break;
|
||||
case LV_PAGE_STYLE_EDGE_FLASH:
|
||||
ext->edge_flash.style = style;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,6 +356,17 @@ bool lv_page_get_scroll_propagation(lv_obj_t * page)
|
||||
return ext->scroll_prop == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the edge flash effect property.
|
||||
* @param page pointer to a Page
|
||||
* return true or false
|
||||
*/
|
||||
bool lv_page_get_edge_flash(lv_obj_t * page)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
return ext->edge_flash.enabled == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get that width which can be set to the children to still not cause overflow (show scrollbars)
|
||||
* @param page pointer to a page object
|
||||
@@ -377,6 +414,9 @@ lv_style_t * lv_page_get_style(const lv_obj_t * page, lv_page_style_t type)
|
||||
case LV_PAGE_STYLE_SB:
|
||||
style = ext->sb.style;
|
||||
break;
|
||||
case LV_PAGE_STYLE_EDGE_FLASH:
|
||||
style = ext->edge_flash.style;
|
||||
break;
|
||||
default:
|
||||
style = NULL;
|
||||
break;
|
||||
@@ -531,6 +571,34 @@ void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Not intended to use directly by the user but by other object types internally.
|
||||
* Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set
|
||||
* @param page
|
||||
*/
|
||||
void lv_page_start_edge_flash(lv_obj_t * page)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
if(ext->edge_flash.enabled) {
|
||||
lv_anim_t a;
|
||||
a.var = page;
|
||||
a.start = 0;
|
||||
a.end = LV_PAGE_END_FLASH_SIZE;
|
||||
a.fp = (lv_anim_fp_t)edge_flash_anim;
|
||||
a.path = lv_anim_path_linear;
|
||||
a.end_cb = edge_flash_anim_end;
|
||||
a.act_time = 0;
|
||||
a.time = LV_PAGE_END_ANIM_TIME;
|
||||
a.playback = 1;
|
||||
a.playback_pause = LV_PAGE_END_ANIM_WAIT_TIME;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -592,6 +660,46 @@ static bool lv_page_design(lv_obj_t * page, const lv_area_t * mask, lv_design_mo
|
||||
sb_area.y2 += page->coords.y1;
|
||||
lv_draw_rect(&sb_area, mask, ext->sb.style, lv_obj_get_opa_scale(page));
|
||||
}
|
||||
|
||||
|
||||
lv_coord_t page_w = lv_obj_get_width(page);
|
||||
lv_coord_t page_h = lv_obj_get_height(page);
|
||||
lv_area_t flash_area;
|
||||
|
||||
if(ext->edge_flash.top_ip) {
|
||||
flash_area.x1 = page->coords.x1 - page_w;
|
||||
flash_area.x2 = page->coords.x2 + page_w;
|
||||
flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state;
|
||||
flash_area.y2 = page->coords.y1 + ext->edge_flash.state;
|
||||
}
|
||||
else if(ext->edge_flash.bottom_ip) {
|
||||
flash_area.x1 = page->coords.x1 - page_w;
|
||||
flash_area.x2 = page->coords.x2 + page_w;
|
||||
flash_area.y1 = page->coords.y2 - ext->edge_flash.state;
|
||||
flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state;
|
||||
}
|
||||
else if(ext->edge_flash.right_ip) {
|
||||
flash_area.x1 = page->coords.x2 - ext->edge_flash.state;
|
||||
flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state;
|
||||
flash_area.y1 = page->coords.y1 - page_h;
|
||||
flash_area.y2 = page->coords.y2 + page_h;
|
||||
}
|
||||
else if(ext->edge_flash.left_ip) {
|
||||
flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state;
|
||||
flash_area.x2 = page->coords.x1 + ext->edge_flash.state;
|
||||
flash_area.y1 = page->coords.y1 - page_h;
|
||||
flash_area.y2 = page->coords.y2 + page_h;
|
||||
}
|
||||
|
||||
if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || ext->edge_flash.bottom_ip) {
|
||||
lv_style_t flash_style;
|
||||
lv_style_copy(&flash_style, ext->edge_flash.style);
|
||||
flash_style.body.radius = LV_RADIUS_CIRCLE;
|
||||
uint32_t opa = (flash_style.body.opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE;
|
||||
flash_style.body.opa = opa;
|
||||
lv_draw_rect(&flash_area, mask, &flash_style, lv_obj_get_opa_scale(page));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -800,7 +908,7 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi
|
||||
}
|
||||
|
||||
/*scrollable width smaller then page width? -> align to left*/
|
||||
if(lv_area_get_width(&scrl_coords) + 2 * hpad < lv_area_get_width(&page_coords)) {
|
||||
if(lv_area_get_width(&scrl_coords) + 2 * hpad <= lv_area_get_width(&page_coords)) {
|
||||
if(scrl_coords.x1 != page_coords.x1 + hpad) {
|
||||
new_x = hpad;
|
||||
refr_x = true;
|
||||
@@ -817,15 +925,27 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi
|
||||
else if(scrl_coords.x2 < page_coords.x2 - hpad) {
|
||||
new_x = lv_area_get_width(&page_coords) - lv_area_get_width(&scrl_coords) - hpad; /* Right align */
|
||||
refr_x = true;
|
||||
if(page_ext->edge_flash.enabled &&
|
||||
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
|
||||
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
|
||||
lv_page_start_edge_flash(page);
|
||||
page_ext->edge_flash.right_ip = 1;
|
||||
}
|
||||
}
|
||||
else if(scrl_coords.x1 > page_coords.x1 + hpad) {
|
||||
new_x = hpad; /*Left align*/
|
||||
refr_x = true;
|
||||
if(page_ext->edge_flash.enabled &&
|
||||
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
|
||||
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
|
||||
lv_page_start_edge_flash(page);
|
||||
page_ext->edge_flash.left_ip = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*scrollable height smaller then page height? -> align to left*/
|
||||
if(lv_area_get_height(&scrl_coords) + 2 * vpad < lv_area_get_height(&page_coords)) {
|
||||
if(lv_area_get_height(&scrl_coords) + 2 * vpad <= lv_area_get_height(&page_coords)) {
|
||||
if(scrl_coords.y1 != page_coords.y1 + vpad) {
|
||||
new_y = vpad;
|
||||
refr_y = true;
|
||||
@@ -842,10 +962,22 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi
|
||||
else if(scrl_coords.y2 < page_coords.y2 - vpad) {
|
||||
new_y = lv_area_get_height(&page_coords) - lv_area_get_height(&scrl_coords) - vpad; /* Bottom align */
|
||||
refr_y = true;
|
||||
if(page_ext->edge_flash.enabled &&
|
||||
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
|
||||
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
|
||||
lv_page_start_edge_flash(page);
|
||||
page_ext->edge_flash.bottom_ip = 1;
|
||||
}
|
||||
}
|
||||
else if(scrl_coords.y1 > page_coords.y1 + vpad) {
|
||||
new_y = vpad; /*Top align*/
|
||||
refr_y = true;
|
||||
if(page_ext->edge_flash.enabled &&
|
||||
page_ext->edge_flash.left_ip == 0 && page_ext->edge_flash.right_ip == 0 &&
|
||||
page_ext->edge_flash.top_ip == 0 && page_ext->edge_flash.bottom_ip == 0) {
|
||||
lv_page_start_edge_flash(page);
|
||||
page_ext->edge_flash.top_ip = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1017,4 +1149,21 @@ static void lv_page_sb_refresh(lv_obj_t * page)
|
||||
}
|
||||
}
|
||||
|
||||
static void edge_flash_anim(void * page, int32_t v)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
ext->edge_flash.state = v;
|
||||
lv_obj_invalidate(page);
|
||||
}
|
||||
|
||||
static void edge_flash_anim_end(void * page)
|
||||
{
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
ext->edge_flash.top_ip = 0;
|
||||
ext->edge_flash.bottom_ip = 0;
|
||||
ext->edge_flash.left_ip = 0;
|
||||
ext->edge_flash.right_ip = 0;
|
||||
lv_obj_invalidate(page);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -65,6 +65,16 @@ typedef struct
|
||||
uint8_t ver_draw :1; /*1: vertical scrollbar is visible now (Handled by the library)*/
|
||||
lv_sb_mode_t mode:3; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/
|
||||
} sb;
|
||||
struct {
|
||||
uint16_t state; /*Store the current size of the edge flash effect*/
|
||||
lv_style_t *style; /*Style of edge flash effect (usually homogeneous circle)*/
|
||||
uint8_t enabled :1; /*1: Show a flash animation on the edge*/
|
||||
uint8_t top_ip :1; /*Used internally to show that top most position is reached (flash is In Progress)*/
|
||||
uint8_t bottom_ip :1; /*Used internally to show that bottom most position is reached (flash is In Progress)*/
|
||||
uint8_t right_ip :1; /*Used internally to show that right most position is reached (flash is In Progress)*/
|
||||
uint8_t left_ip :1; /*Used internally to show that left most position is reached (flash is In Progress)*/
|
||||
}edge_flash;
|
||||
|
||||
uint8_t arrow_scroll :1; /*1: Enable scrolling with LV_GROUP_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)*/
|
||||
@@ -74,6 +84,7 @@ enum {
|
||||
LV_PAGE_STYLE_BG,
|
||||
LV_PAGE_STYLE_SCRL,
|
||||
LV_PAGE_STYLE_SB,
|
||||
LV_PAGE_STYLE_EDGE_FLASH,
|
||||
};
|
||||
typedef uint8_t lv_page_style_t;
|
||||
|
||||
@@ -155,6 +166,13 @@ void lv_page_set_arrow_scroll(lv_obj_t * page, bool en);
|
||||
*/
|
||||
void lv_page_set_scroll_propagation(lv_obj_t * page, bool en);
|
||||
|
||||
/**
|
||||
* Enable the edge flash effect. (Show an arc when the an edge is reached)
|
||||
* @param page pointer to a Page
|
||||
* @param en true or false to enable/disable end flash
|
||||
*/
|
||||
void lv_page_set_edge_flash(lv_obj_t * page, bool en);
|
||||
|
||||
/**
|
||||
* Set the fit attribute of the scrollable part of a page.
|
||||
* It means it can set its size automatically to involve all children.
|
||||
@@ -233,6 +251,13 @@ bool lv_page_get_arrow_scroll(const lv_obj_t * page);
|
||||
*/
|
||||
bool lv_page_get_scroll_propagation(lv_obj_t * page);
|
||||
|
||||
/**
|
||||
* Get the edge flash effect property.
|
||||
* @param page pointer to a Page
|
||||
* return true or false
|
||||
*/
|
||||
bool lv_page_get_edge_flash(lv_obj_t * page);
|
||||
|
||||
/**
|
||||
* Get that width which can be set to the children to still not cause overflow (show scrollbars)
|
||||
* @param page pointer to a page object
|
||||
@@ -338,6 +363,12 @@ void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist);
|
||||
*/
|
||||
void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist);
|
||||
|
||||
/**
|
||||
* Not intended to use directly by the user but by other object types internally.
|
||||
* Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set
|
||||
* @param page
|
||||
*/
|
||||
void lv_page_start_edge_flash(lv_obj_t * page);
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -24,6 +24,12 @@
|
||||
#ifndef LV_PRELOAD_DEF_SPIN_TIME
|
||||
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
|
||||
#endif
|
||||
|
||||
#ifndef LV_PRELOAD_DEF_ANIM
|
||||
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC /*animation type*/
|
||||
#endif
|
||||
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@@ -73,26 +79,12 @@ lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
|
||||
/*Initialize the allocated 'ext' */
|
||||
ext->arc_length = LV_PRELOAD_DEF_ARC_LENGTH;
|
||||
ext->anim_type = LV_PRELOAD_DEF_ANIM;
|
||||
|
||||
/*The signal and design functions are not copied so set them here*/
|
||||
lv_obj_set_signal_func(new_preload, lv_preload_signal);
|
||||
lv_obj_set_design_func(new_preload, lv_preload_design);
|
||||
#if USE_LV_ANIMATION
|
||||
lv_anim_t a;
|
||||
a.var = new_preload;
|
||||
a.start = 0;
|
||||
a.end = 360;
|
||||
a.fp = (lv_anim_fp_t)lv_preload_spinner_animation;
|
||||
a.path = lv_anim_path_ease_in_out;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = LV_PRELOAD_DEF_SPIN_TIME;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 1;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
#endif
|
||||
|
||||
|
||||
/*Init the new pre loader pre loader*/
|
||||
if(copy == NULL) {
|
||||
@@ -106,6 +98,8 @@ lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_obj_set_style(new_preload, &lv_style_pretty_color);
|
||||
}
|
||||
|
||||
ext->time = LV_PRELOAD_DEF_SPIN_TIME;
|
||||
|
||||
}
|
||||
/*Copy an existing pre loader*/
|
||||
else {
|
||||
@@ -116,6 +110,8 @@ lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_obj_refresh_style(new_preload);
|
||||
}
|
||||
|
||||
lv_preload_set_animation_type(new_preload, ext->anim_type);
|
||||
|
||||
|
||||
LV_LOG_INFO("preload created");
|
||||
|
||||
@@ -148,22 +144,7 @@ void lv_preload_set_spin_time(lv_obj_t * preload, uint16_t time)
|
||||
lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload);
|
||||
|
||||
ext->time = time;
|
||||
#if USE_LV_ANIMATION
|
||||
lv_anim_t a;
|
||||
a.var = preload;
|
||||
a.start = 0;
|
||||
a.end = 360;
|
||||
a.fp = (lv_anim_fp_t)lv_preload_spinner_animation;
|
||||
a.path = lv_anim_path_ease_in_out;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 1;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
#endif
|
||||
lv_preload_set_animation_type(preload, ext->anim_type);
|
||||
}
|
||||
/*=====================
|
||||
* Setter functions
|
||||
@@ -178,12 +159,85 @@ void lv_preload_set_spin_time(lv_obj_t * preload, uint16_t time)
|
||||
void lv_preload_set_style(lv_obj_t * preload, lv_preload_style_t type, lv_style_t * style)
|
||||
{
|
||||
switch(type) {
|
||||
case LV_PRELOAD_STYLE_MAIN:
|
||||
lv_arc_set_style(preload, LV_ARC_STYLE_MAIN, style);
|
||||
break;
|
||||
case LV_PRELOAD_STYLE_MAIN:
|
||||
lv_arc_set_style(preload, LV_ARC_STYLE_MAIN, style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the animation type of a preloadeer.
|
||||
* @param preload pointer to pre loader object
|
||||
* @param type animation type of the preload
|
||||
* */
|
||||
void lv_preload_set_animation_type(lv_obj_t * preload, lv_preloader_type_t type)
|
||||
{
|
||||
#if USE_LV_ANIMATION
|
||||
lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload);
|
||||
|
||||
/*delete previous animation*/
|
||||
//lv_anim_del(preload, NULL);
|
||||
switch(type)
|
||||
{
|
||||
case LV_PRELOAD_TYPE_FILLSPIN_ARC:
|
||||
{
|
||||
ext->anim_type = LV_PRELOAD_TYPE_FILLSPIN_ARC;
|
||||
lv_anim_t a;
|
||||
a.var = preload;
|
||||
a.start = 0;
|
||||
a.end = 360;
|
||||
a.fp = (lv_anim_fp_t)lv_preload_spinner_animation;
|
||||
a.path = lv_anim_path_ease_in_out;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = ext->time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 1;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
|
||||
lv_anim_t b;
|
||||
b.var = preload;
|
||||
b.start = ext->arc_length;
|
||||
b.end = 360 - ext->arc_length;
|
||||
b.fp = (lv_anim_fp_t)lv_preload_set_arc_length;
|
||||
b.path = lv_anim_path_ease_in_out;
|
||||
b.end_cb = NULL;
|
||||
b.act_time = 0;
|
||||
b.time = ext->time;
|
||||
b.playback = 1;
|
||||
b.playback_pause = 0;
|
||||
b.repeat = 1;
|
||||
b.repeat_pause = 0;
|
||||
lv_anim_create(&b);
|
||||
break;
|
||||
}
|
||||
case LV_PRELOAD_TYPE_SPINNING_ARC:
|
||||
default:
|
||||
{
|
||||
ext->anim_type = LV_PRELOAD_TYPE_SPINNING_ARC;
|
||||
lv_anim_t a;
|
||||
a.var = preload;
|
||||
a.start = 0;
|
||||
a.end = 360;
|
||||
a.fp = (lv_anim_fp_t)lv_preload_spinner_animation;
|
||||
a.path = lv_anim_path_ease_in_out;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = ext->time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 1;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //USE_LV_ANIMATION
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -220,17 +274,28 @@ lv_style_t * lv_preload_get_style(const lv_obj_t * preload, lv_preload_style_t t
|
||||
lv_style_t * style = NULL;
|
||||
|
||||
switch(type) {
|
||||
case LV_PRELOAD_STYLE_MAIN:
|
||||
style = lv_arc_get_style(preload, LV_ARC_STYLE_MAIN);
|
||||
break;
|
||||
default:
|
||||
style = NULL;
|
||||
break;
|
||||
case LV_PRELOAD_STYLE_MAIN:
|
||||
style = lv_arc_get_style(preload, LV_ARC_STYLE_MAIN);
|
||||
break;
|
||||
default:
|
||||
style = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the animation type of a preloadeer.
|
||||
* @param preload pointer to pre loader object
|
||||
* @return animation type
|
||||
* */
|
||||
lv_preloader_type_t lv_preload_get_animation_type(lv_obj_t * preload)
|
||||
{
|
||||
lv_preload_ext_t * ext = lv_obj_get_ext_attr(preload);
|
||||
return ext->anim_type;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
@@ -43,6 +43,7 @@ extern "C" {
|
||||
|
||||
enum {
|
||||
LV_PRELOAD_TYPE_SPINNING_ARC,
|
||||
LV_PRELOAD_TYPE_FILLSPIN_ARC,
|
||||
};
|
||||
typedef uint8_t lv_preloader_type_t;
|
||||
|
||||
@@ -52,6 +53,7 @@ typedef struct {
|
||||
/*New data for this type */
|
||||
uint16_t arc_length; /*Length of the spinning indicator in degree*/
|
||||
uint16_t time; /*Time of one round*/
|
||||
lv_preloader_type_t anim_type; /*Type of the arc animation*/
|
||||
} lv_preload_ext_t;
|
||||
|
||||
|
||||
@@ -103,6 +105,13 @@ void lv_preload_set_spin_time(lv_obj_t * preload, uint16_t time);
|
||||
* */
|
||||
void lv_preload_set_style(lv_obj_t * preload, lv_preload_style_t type, lv_style_t *style);
|
||||
|
||||
/**
|
||||
* Set the animation type of a preloadeer.
|
||||
* @param preload pointer to pre loader object
|
||||
* @param type animation type of the preload
|
||||
* */
|
||||
void lv_preload_set_animation_type(lv_obj_t * preload, lv_preloader_type_t type);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -127,6 +136,13 @@ uint16_t lv_preload_get_spin_time(const lv_obj_t * preload);
|
||||
* */
|
||||
lv_style_t * lv_preload_get_style(const lv_obj_t * preload, lv_preload_style_t type);
|
||||
|
||||
/**
|
||||
* Get the animation type of a preloadeer.
|
||||
* @param preload pointer to pre loader object
|
||||
* @return animation type
|
||||
* */
|
||||
lv_preloader_type_t lv_preload_get_animation_type(lv_obj_t * preload);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
163
lv_objx/lv_sw.c
163
lv_objx/lv_sw.c
@@ -7,6 +7,7 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_sw.h"
|
||||
|
||||
#if USE_LV_SW != 0
|
||||
|
||||
/*Testing of dependencies*/
|
||||
@@ -15,6 +16,7 @@
|
||||
#endif
|
||||
|
||||
#include "../lv_themes/lv_theme.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -28,6 +30,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param);
|
||||
static void lv_sw_anim_to_value(lv_obj_t * sw, int16_t value);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -66,6 +69,7 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
|
||||
/*Initialize the allocated 'ext' */
|
||||
ext->changed = 0;
|
||||
ext->anim_time = 0;
|
||||
ext->style_knob_off = ext->slider.style_knob;
|
||||
ext->style_knob_on = ext->slider.style_knob;
|
||||
|
||||
@@ -77,6 +81,7 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_slider_set_range(new_sw, 0, 1);
|
||||
lv_obj_set_size(new_sw, 2 * LV_DPI / 3, LV_DPI / 3);
|
||||
lv_slider_set_knob_in(new_sw, true);
|
||||
lv_slider_set_range(new_sw, 0, LV_SWITCH_SLIDER_ANIM_MAX);
|
||||
|
||||
/*Set the default styles*/
|
||||
lv_theme_t * th = lv_theme_get_current();
|
||||
@@ -95,9 +100,12 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
lv_sw_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
ext->style_knob_off = copy_ext->style_knob_off;
|
||||
ext->style_knob_on = copy_ext->style_knob_on;
|
||||
ext->anim_time = copy_ext->anim_time;
|
||||
|
||||
if(lv_sw_get_state(new_sw)) lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
|
||||
else lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
|
||||
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_sw);
|
||||
}
|
||||
@@ -117,10 +125,9 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
*/
|
||||
void lv_sw_on(lv_obj_t * sw)
|
||||
{
|
||||
if(lv_sw_get_state(sw)) return; /*Do nothing is already turned on*/
|
||||
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
lv_slider_set_value(sw, 1);
|
||||
lv_slider_set_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
|
||||
|
||||
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
|
||||
}
|
||||
|
||||
@@ -130,10 +137,36 @@ void lv_sw_on(lv_obj_t * sw)
|
||||
*/
|
||||
void lv_sw_off(lv_obj_t * sw)
|
||||
{
|
||||
if(!lv_sw_get_state(sw)) return; /*Do nothing is already turned off*/
|
||||
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
lv_slider_set_value(sw, 0);
|
||||
|
||||
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn ON the switch with an animation
|
||||
* @param sw pointer to a switch object
|
||||
*/
|
||||
void lv_sw_on_anim(lv_obj_t * sw)
|
||||
{
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
|
||||
if(lv_sw_get_anim_time(sw) > 0) lv_sw_anim_to_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
|
||||
else lv_slider_set_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
|
||||
|
||||
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn OFF the switch with an animation
|
||||
* @param sw pointer to a switch object
|
||||
*/
|
||||
void lv_sw_off_anim(lv_obj_t * sw)
|
||||
{
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
if(lv_sw_get_anim_time(sw) > 0) lv_sw_anim_to_value(sw, 0);
|
||||
else lv_slider_set_value(sw, 0);
|
||||
|
||||
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
}
|
||||
|
||||
@@ -165,6 +198,15 @@ void lv_sw_set_style(lv_obj_t * sw, lv_sw_style_t type, lv_style_t * style)
|
||||
}
|
||||
}
|
||||
|
||||
void lv_sw_set_anim_time(lv_obj_t *sw, uint16_t anim_time)
|
||||
{
|
||||
#if USE_LV_ANIMATION == 0
|
||||
anim_time = 0;
|
||||
#endif
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
ext->anim_time = anim_time;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -200,6 +242,18 @@ lv_style_t * lv_sw_get_style(const lv_obj_t * sw, lv_sw_style_t type)
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
uint16_t lv_sw_get_anim_time(const lv_obj_t *sw)
|
||||
{
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
return ext->anim_time;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -217,6 +271,7 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
|
||||
/*Save the current (old) value before slider signal modifies it*/
|
||||
int16_t old_val;
|
||||
|
||||
if(sign == LV_SIGNAL_PRESSING) old_val = ext->slider.drag_value;
|
||||
else old_val = lv_slider_get_value(sw);
|
||||
|
||||
@@ -231,40 +286,80 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
||||
} else if(sign == LV_SIGNAL_PRESSING) {
|
||||
int16_t act_val = ext->slider.drag_value;
|
||||
if(act_val != old_val) ext->changed = 1;
|
||||
} else if(sign == LV_SIGNAL_PRESS_LOST) {
|
||||
}
|
||||
else if(sign == LV_SIGNAL_PRESSED) {
|
||||
|
||||
/*Save the x coordinate of the pressed point to see if the switch was slid*/
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
if(indev) {
|
||||
lv_point_t p;
|
||||
lv_indev_get_point(indev, &p);
|
||||
ext->start_x = p.x;
|
||||
}
|
||||
ext->slided = 0;
|
||||
ext->changed = 0;
|
||||
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
|
||||
else lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
} else if(sign == LV_SIGNAL_RELEASED) {
|
||||
if(ext->changed == 0) {
|
||||
int16_t v = lv_slider_get_value(sw);
|
||||
if(v == 0) lv_slider_set_value(sw, 1);
|
||||
else lv_slider_set_value(sw, 0);
|
||||
}
|
||||
else if(sign == LV_SIGNAL_PRESSING) {
|
||||
/*See if the switch was slid*/
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
if(indev) {
|
||||
lv_point_t p = {0,0};
|
||||
lv_indev_get_point(indev, &p);
|
||||
if(LV_MATH_ABS(p.x - ext->start_x) > LV_INDEV_DRAG_LIMIT) ext->slided = 1;
|
||||
}
|
||||
|
||||
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
|
||||
else lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
/*If didn't slide then revert the min/max value. So click without slide won't move the switch as a slider*/
|
||||
if(ext->slided == 0) {
|
||||
if(lv_sw_get_state(sw)) ext->slider.drag_value = LV_SWITCH_SLIDER_ANIM_MAX;
|
||||
else ext->slider.drag_value = 0;
|
||||
}
|
||||
|
||||
ext->changed = 0;
|
||||
/*If explicitly changed (by slide) don't need to be toggled on release*/
|
||||
int16_t threshold = LV_SWITCH_SLIDER_ANIM_MAX / 2;
|
||||
if((old_val < threshold && ext->slider.drag_value > threshold) ||
|
||||
(old_val > threshold && ext->slider.drag_value < threshold))
|
||||
{
|
||||
ext->changed = 1;
|
||||
}
|
||||
}
|
||||
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_sw_anim_to_value(sw, LV_SWITCH_SLIDER_ANIM_MAX);
|
||||
}
|
||||
else {
|
||||
lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
lv_sw_anim_to_value(sw, 0);
|
||||
}
|
||||
}
|
||||
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_anim(sw);
|
||||
else lv_sw_on_anim(sw);
|
||||
}
|
||||
/*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_SWITCH_SLIDER_ANIM_MAX / 2) lv_sw_on_anim(sw);
|
||||
else lv_sw_off_anim(sw);
|
||||
|
||||
if(slider_action != NULL) res = slider_action(sw);
|
||||
if(slider_action != NULL) res = slider_action(sw);
|
||||
}
|
||||
|
||||
} else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
|
||||
char c = *((char *)param);
|
||||
if(c == LV_GROUP_KEY_ENTER) {
|
||||
if(old_val) lv_sw_off(sw);
|
||||
else lv_sw_on(sw);
|
||||
if(old_val) lv_sw_off_anim(sw);
|
||||
else lv_sw_on_anim(sw);
|
||||
|
||||
if(slider_action) res = slider_action(sw);
|
||||
} else if(c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_RIGHT) {
|
||||
lv_sw_on(sw);
|
||||
lv_sw_on_anim(sw);
|
||||
if(slider_action) res = slider_action(sw);
|
||||
} else if(c == LV_GROUP_KEY_DOWN || c == LV_GROUP_KEY_LEFT) {
|
||||
lv_sw_off(sw);
|
||||
lv_sw_off_anim(sw);
|
||||
if(slider_action) res = slider_action(sw);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
||||
@@ -285,4 +380,24 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void lv_sw_anim_to_value(lv_obj_t * sw, int16_t value)
|
||||
{
|
||||
lv_anim_t a;
|
||||
lv_sw_ext_t * ext = lv_obj_get_ext_attr(sw);
|
||||
a.var = sw;
|
||||
a.start = ext->slider.bar.cur_value;
|
||||
a.end = value;
|
||||
a.fp = (lv_anim_fp_t)lv_slider_set_value;
|
||||
a.path = lv_anim_path_linear;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = lv_sw_get_anim_time(sw);
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,7 @@ extern "C" {
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_SWITCH_SLIDER_ANIM_MAX 1000
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -41,9 +42,14 @@ typedef struct
|
||||
{
|
||||
lv_slider_ext_t slider; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/
|
||||
lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/
|
||||
uint8_t changed :1; /*Indicates the switch explicitly changed by drag*/
|
||||
lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/
|
||||
lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/
|
||||
lv_coord_t start_x;
|
||||
uint8_t changed :1; /*Indicates the switch state explicitly changed by drag*/
|
||||
uint8_t slided :1;
|
||||
#if USE_LV_ANIMATION
|
||||
uint16_t anim_time; /*switch animation time */
|
||||
#endif
|
||||
} lv_sw_ext_t;
|
||||
|
||||
enum {
|
||||
@@ -82,6 +88,18 @@ void lv_sw_on(lv_obj_t *sw);
|
||||
*/
|
||||
void lv_sw_off(lv_obj_t *sw);
|
||||
|
||||
/**
|
||||
* Turn ON the switch with an animation
|
||||
* @param sw pointer to a switch object
|
||||
*/
|
||||
void lv_sw_on_anim(lv_obj_t * sw);
|
||||
|
||||
/**
|
||||
* Turn OFF the switch with an animation
|
||||
* @param sw pointer to a switch object
|
||||
*/
|
||||
void lv_sw_off_anim(lv_obj_t * sw);
|
||||
|
||||
/**
|
||||
* Set a function which will be called when the switch is toggled by the user
|
||||
* @param sw pointer to switch object
|
||||
@@ -100,6 +118,16 @@ static inline void lv_sw_set_action(lv_obj_t * sw, lv_action_t action)
|
||||
*/
|
||||
void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style);
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
/**
|
||||
* Set the animation time of the switch
|
||||
* @param sw pointer to a switch object
|
||||
* @param anim_time animation time
|
||||
* @return style pointer to a style
|
||||
*/
|
||||
void lv_sw_set_anim_time(lv_obj_t *sw, uint16_t anim_time);
|
||||
#endif
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -111,7 +139,7 @@ void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style);
|
||||
*/
|
||||
static inline bool lv_sw_get_state(const lv_obj_t *sw)
|
||||
{
|
||||
return lv_bar_get_value(sw) == 0 ? false : true;
|
||||
return lv_bar_get_value(sw) < LV_SWITCH_SLIDER_ANIM_MAX / 2 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,6 +160,15 @@ static inline lv_action_t lv_sw_get_action(const lv_obj_t * slider)
|
||||
*/
|
||||
lv_style_t * lv_sw_get_style(const lv_obj_t *sw, lv_sw_style_t type);
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
/**
|
||||
* Get the animation time of the switch
|
||||
* @param sw pointer to a switch object
|
||||
* @return style pointer to a style
|
||||
*/
|
||||
uint16_t lv_sw_get_anim_time(const lv_obj_t *sw);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -199,6 +199,10 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c)
|
||||
return;
|
||||
}
|
||||
|
||||
/*Disable edge flash. If a new line was added it could show edge flash effect*/
|
||||
bool edge_flash_en = lv_ta_get_edge_flash(ta);
|
||||
lv_ta_set_edge_flash(ta, false);
|
||||
|
||||
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
|
||||
uint32_t letter_buf[2];
|
||||
letter_buf[0] = c;
|
||||
@@ -237,6 +241,9 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c)
|
||||
|
||||
/*Move the cursor after the new character*/
|
||||
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + 1);
|
||||
|
||||
/*Revert the original edge flash state*/
|
||||
lv_ta_set_edge_flash(ta, edge_flash_en);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,6 +267,10 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
||||
return;
|
||||
}
|
||||
|
||||
/*Disable edge flash. If a new line was added it could show edge flash effect*/
|
||||
bool edge_flash_en = lv_ta_get_edge_flash(ta);
|
||||
lv_ta_set_edge_flash(ta, false);
|
||||
|
||||
/*Insert the text*/
|
||||
lv_label_ins_text(ext->label, ext->cursor.pos, txt);
|
||||
|
||||
@@ -293,6 +304,9 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
||||
|
||||
/*Move the cursor after the new text*/
|
||||
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + lv_txt_get_encoded_length(txt));
|
||||
|
||||
/*Revert the original edge flash state*/
|
||||
lv_ta_set_edge_flash(ta, edge_flash_en);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -632,6 +646,9 @@ void lv_ta_set_style(lv_obj_t * ta, lv_ta_style_t type, lv_style_t * style)
|
||||
case LV_TA_STYLE_SB:
|
||||
lv_page_set_style(ta, LV_PAGE_STYLE_SB, style);
|
||||
break;
|
||||
case LV_TA_STYLE_EDGE_FLASH:
|
||||
lv_page_set_style(ta, LV_PAGE_STYLE_EDGE_FLASH, style);
|
||||
break;
|
||||
case LV_TA_STYLE_CURSOR:
|
||||
ext->cursor.style = style;
|
||||
lv_obj_refresh_ext_size(lv_page_get_scrl(ta)); /*Refresh ext. size because of cursor drawing*/
|
||||
@@ -760,6 +777,9 @@ lv_style_t * lv_ta_get_style(const lv_obj_t * ta, lv_ta_style_t type)
|
||||
case LV_TA_STYLE_SB:
|
||||
style = lv_page_get_style(ta, LV_PAGE_STYLE_SB);
|
||||
break;
|
||||
case LV_TA_STYLE_EDGE_FLASH:
|
||||
style = lv_page_get_style(ta, LV_PAGE_STYLE_EDGE_FLASH);
|
||||
break;
|
||||
case LV_TA_STYLE_CURSOR:
|
||||
style = ext->cursor.style;
|
||||
break;
|
||||
|
||||
@@ -76,6 +76,7 @@ typedef struct
|
||||
enum {
|
||||
LV_TA_STYLE_BG,
|
||||
LV_TA_STYLE_SB,
|
||||
LV_TA_STYLE_EDGE_FLASH,
|
||||
LV_TA_STYLE_CURSOR,
|
||||
};
|
||||
typedef uint8_t lv_ta_style_t;
|
||||
@@ -213,6 +214,16 @@ static inline void lv_ta_set_scroll_propagation(lv_obj_t * ta, bool en)
|
||||
lv_page_set_scroll_propagation(ta, en);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the edge flash effect. (Show an arc when the an edge is reached)
|
||||
* @param page pointer to a Text Area
|
||||
* @param en true or false to enable/disable end flash
|
||||
*/
|
||||
static inline void lv_ta_set_edge_flash(lv_obj_t * ta, bool en)
|
||||
{
|
||||
lv_page_set_edge_flash(ta, en);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a text area
|
||||
* @param ta pointer to a text area object
|
||||
@@ -318,6 +329,16 @@ static inline bool lv_ta_get_scroll_propagation(lv_obj_t * ta)
|
||||
return lv_page_get_scroll_propagation(ta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scroll propagation property
|
||||
* @param ta pointer to a Text area
|
||||
* @return true or false
|
||||
*/
|
||||
static inline bool lv_ta_get_edge_flash(lv_obj_t * ta)
|
||||
{
|
||||
return lv_page_get_edge_flash(ta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a style of a text area
|
||||
* @param ta pointer to a text area object
|
||||
|
||||
569
lv_objx/lv_tileview.c
Normal file
569
lv_objx/lv_tileview.c
Normal file
@@ -0,0 +1,569 @@
|
||||
/**
|
||||
* @file lv_tileview.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_tileview.h"
|
||||
#if USE_LV_TILEVIEW != 0
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "lv_cont.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#if USE_LV_ANIMATION
|
||||
# ifndef LV_TILEVIEW_ANIM_TIME
|
||||
# define LV_TILEVIEW_ANIM_TIME 300 /*Animation time loading a tile [ms] (0: no animation) */
|
||||
# endif
|
||||
#else
|
||||
# undef LV_TILEVIEW_ANIM_TIME
|
||||
# define LV_TILEVIEW_ANIM_TIME 0 /*No animations*/
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_res_t lv_tileview_signal(lv_obj_t * tileview, lv_signal_t sign, void * param);
|
||||
static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);
|
||||
static lv_res_t element_signal_func(lv_obj_t * element, lv_signal_t sign, void * param);
|
||||
static void drag_end_handler(lv_obj_t * tileview);
|
||||
static bool set_valid_drag_dirs(lv_obj_t * tileview);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_signal_func_t ancestor_signal;
|
||||
static lv_signal_func_t ancestor_scrl_signal;
|
||||
static lv_design_func_t ancestor_design;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a tileview object
|
||||
* @param par pointer to an object, it will be the parent of the new tileview
|
||||
* @param copy pointer to a tileview object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created tileview
|
||||
*/
|
||||
lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
{
|
||||
LV_LOG_TRACE("tileview create started");
|
||||
|
||||
/*Create the ancestor of tileview*/
|
||||
lv_obj_t * new_tileview = lv_page_create(par, copy);
|
||||
lv_mem_assert(new_tileview);
|
||||
if(new_tileview == NULL) return NULL;
|
||||
|
||||
/*Allocate the tileview type specific extended data*/
|
||||
lv_tileview_ext_t * ext = lv_obj_allocate_ext_attr(new_tileview, sizeof(lv_tileview_ext_t));
|
||||
lv_mem_assert(ext);
|
||||
if(ext == NULL) return NULL;
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_tileview);
|
||||
if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_tileview));
|
||||
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_tileview);
|
||||
|
||||
/*Initialize the allocated 'ext' */
|
||||
ext->anim_time = LV_TILEVIEW_ANIM_TIME;
|
||||
ext->action = NULL;
|
||||
ext->act_id.x = 0;
|
||||
ext->act_id.y = 0;
|
||||
ext->valid_pos = NULL;
|
||||
|
||||
/*The signal and design functions are not copied so set them here*/
|
||||
lv_obj_set_signal_func(new_tileview, lv_tileview_signal);
|
||||
lv_obj_set_signal_func(lv_page_get_scrl(new_tileview), lv_tileview_scrl_signal);
|
||||
|
||||
/*Init the new tileview*/
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_size(new_tileview, LV_HOR_RES, LV_VER_RES);
|
||||
|
||||
lv_obj_set_drag_throw(lv_page_get_scrl(new_tileview), false);
|
||||
lv_page_set_scrl_fit(new_tileview, true, true);
|
||||
lv_page_set_style(new_tileview, LV_PAGE_STYLE_BG, &lv_style_transp_tight);
|
||||
lv_page_set_style(new_tileview, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight);
|
||||
}
|
||||
/*Copy an existing tileview*/
|
||||
else {
|
||||
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->action = copy_ext->action;
|
||||
ext->anim_time = copy_ext->anim_time;
|
||||
|
||||
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_tileview);
|
||||
}
|
||||
|
||||
LV_LOG_INFO("tileview created");
|
||||
|
||||
return new_tileview;
|
||||
}
|
||||
|
||||
/*======================
|
||||
* Add/remove functions
|
||||
*=====================*/
|
||||
|
||||
/**
|
||||
* Register an object on the tileview. The register object will able to slide the tileview
|
||||
* @param element pointer to an object
|
||||
*/
|
||||
void lv_tileview_add_element(lv_obj_t * element)
|
||||
{
|
||||
lv_obj_set_free_ptr(element, lv_obj_get_signal_func(element));
|
||||
lv_obj_set_signal_func(element, element_signal_func);
|
||||
lv_obj_set_drag_parent(element, true);
|
||||
}
|
||||
|
||||
|
||||
/*=====================
|
||||
* 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 pointer is saved so can't be a local variable.
|
||||
*/
|
||||
void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos)
|
||||
{
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
ext->valid_pos = valid_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tile to be shown
|
||||
* @param tileview pointer to a tileview object
|
||||
* @param x column id (0, 1, 2...)
|
||||
* @param y line id (0, 1, 2...)
|
||||
* @param anim_en true: move with animation
|
||||
*/
|
||||
void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, bool anim_en)
|
||||
{
|
||||
#if USE_LV_ANIMATION == 0
|
||||
anim_en = false;
|
||||
#endif
|
||||
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
|
||||
|
||||
uint16_t i;
|
||||
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) {
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(valid == false) return; /*Don't load not valid tiles*/
|
||||
|
||||
lv_res_t res = LV_RES_OK;
|
||||
if(ext->action) res = ext->action(tileview, x, y);
|
||||
if(res != LV_RES_OK) return; /*Prevent the tile loading*/
|
||||
|
||||
ext->act_id.x = x;
|
||||
ext->act_id.y = y;
|
||||
|
||||
lv_coord_t x_coord = -x * lv_obj_get_width(tileview);
|
||||
lv_coord_t y_coord = -y * lv_obj_get_height(tileview);
|
||||
lv_obj_t * scrl = lv_page_get_scrl(tileview);
|
||||
if(anim_en) {
|
||||
#if USE_LV_ANIMATION
|
||||
lv_coord_t x_act = lv_obj_get_x(scrl);
|
||||
lv_coord_t y_act = lv_obj_get_y(scrl);
|
||||
|
||||
lv_anim_t a;
|
||||
a.var = scrl;
|
||||
a.fp = (lv_anim_fp_t)lv_obj_set_x;
|
||||
a.path = lv_anim_path_linear;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = ext->anim_time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
|
||||
if(x_coord != x_act) {
|
||||
a.start = x_act;
|
||||
a.end = x_coord;
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
|
||||
if(y_coord != y_act) {
|
||||
a.start = y_act;
|
||||
a.end = y_coord;
|
||||
a.fp = (lv_anim_fp_t)lv_obj_set_y;
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
lv_obj_set_size(tileview, x_coord, y_coord);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_tileview_set_tile_load_action(lv_obj_t * tileview, lv_tileview_action_t action)
|
||||
{
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
ext->action = action;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a tileview.
|
||||
* @param tileview pointer to tileview object
|
||||
* @param type which style should be set
|
||||
* @param style pointer to a style
|
||||
*/
|
||||
void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, lv_style_t * style)
|
||||
{
|
||||
|
||||
switch(type) {
|
||||
case LV_TILEVIEW_STYLE_BG:
|
||||
lv_obj_set_style(tileview, style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/*
|
||||
* New object specific "get" functions come here
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get style of a tileview.
|
||||
* @param tileview pointer to tileview object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to the style
|
||||
*/
|
||||
lv_style_t * lv_tileview_get_style(const lv_obj_t * tileview, lv_tileview_style_t type)
|
||||
{
|
||||
lv_style_t * style = NULL;
|
||||
switch(type) {
|
||||
case LV_TILEVIEW_STYLE_BG:
|
||||
style = lv_obj_get_style(tileview);
|
||||
break;
|
||||
default:
|
||||
style = NULL;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/*
|
||||
* New object specific "other" functions come here
|
||||
*/
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Signal function of the tileview
|
||||
* @param tileview pointer to a tileview object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static lv_res_t lv_tileview_signal(lv_obj_t * tileview, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_signal(tileview, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
||||
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
||||
lv_obj_type_t * buf = param;
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
|
||||
if(buf->type[i] == NULL) break;
|
||||
}
|
||||
buf->type[i] = "lv_tileview";
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the tileview scrollable
|
||||
* @param tileview pointer to the scrollable part of the tileview object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static lv_res_t lv_tileview_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
|
||||
{
|
||||
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_scrl_signal(scrl, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
lv_obj_t * tileview = lv_obj_get_parent(scrl);
|
||||
|
||||
/*Apply constraint on moving of the tileview*/
|
||||
if(sign == LV_SIGNAL_CORD_CHG) {
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
if(indev) {
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
|
||||
/*Set horizontal drag constraint if no vertical constraint an dragged to valid x direction */
|
||||
if(ext->drag_ver == 0 &&
|
||||
((ext->drag_right_en && indev->proc.drag_sum.x <= -LV_INDEV_DRAG_LIMIT) ||
|
||||
(ext->drag_left_en && indev->proc.drag_sum.x >= LV_INDEV_DRAG_LIMIT))) {
|
||||
ext->drag_hor = 1;
|
||||
}
|
||||
/*Set vertical drag constraint if no horizontal constraint an dragged to valid y direction */
|
||||
if(ext->drag_hor == 0 &&
|
||||
((ext->drag_bottom_en && indev->proc.drag_sum.y <= -LV_INDEV_DRAG_LIMIT) ||
|
||||
(ext->drag_top_en && indev->proc.drag_sum.y >= LV_INDEV_DRAG_LIMIT))) {
|
||||
ext->drag_ver = 1;
|
||||
}
|
||||
|
||||
if(ext->drag_hor) {
|
||||
ext->page.edge_flash.top_ip = 0;
|
||||
ext->page.edge_flash.bottom_ip = 0;
|
||||
}
|
||||
|
||||
if(ext->drag_ver) {
|
||||
ext->page.edge_flash.right_ip = 0;
|
||||
ext->page.edge_flash.left_ip = 0;
|
||||
}
|
||||
|
||||
lv_coord_t x = lv_obj_get_x(scrl);
|
||||
lv_coord_t y = lv_obj_get_y(scrl);
|
||||
lv_coord_t h = lv_obj_get_height(tileview);
|
||||
lv_coord_t w = lv_obj_get_width(tileview);
|
||||
if(ext->drag_top_en == 0) {
|
||||
if(y > -(ext->act_id.y * h) && indev->proc.vect.y > 0 && ext->drag_hor == 0) {
|
||||
if(ext->page.edge_flash.enabled &&
|
||||
ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 &&
|
||||
ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) {
|
||||
ext->page.edge_flash.top_ip = 1;
|
||||
lv_page_start_edge_flash(tileview);
|
||||
}
|
||||
|
||||
lv_obj_set_y(scrl, -ext->act_id.y * h);
|
||||
}
|
||||
}
|
||||
if(ext->drag_bottom_en == 0 && indev->proc.vect.y < 0 && ext->drag_hor == 0) {
|
||||
if(y < -(ext->act_id.y * h)) {
|
||||
if(ext->page.edge_flash.enabled &&
|
||||
ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 &&
|
||||
ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) {
|
||||
ext->page.edge_flash.bottom_ip = 1;
|
||||
lv_page_start_edge_flash(tileview);
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_set_y(scrl, -ext->act_id.y * h);
|
||||
}
|
||||
if(ext->drag_left_en == 0) {
|
||||
if(x > -(ext->act_id.x * w) && indev->proc.vect.x > 0 && ext->drag_ver == 0) {
|
||||
if(ext->page.edge_flash.enabled &&
|
||||
ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 &&
|
||||
ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) {
|
||||
ext->page.edge_flash.left_ip = 1;
|
||||
lv_page_start_edge_flash(tileview);
|
||||
}
|
||||
|
||||
lv_obj_set_x(scrl, -ext->act_id.x * w);
|
||||
}
|
||||
}
|
||||
if(ext->drag_right_en == 0 && indev->proc.vect.x < 0 && ext->drag_ver == 0) {
|
||||
if(x < -(ext->act_id.x * w)) {
|
||||
if(ext->page.edge_flash.enabled &&
|
||||
ext->page.edge_flash.left_ip == 0 && ext->page.edge_flash.right_ip == 0 &&
|
||||
ext->page.edge_flash.top_ip == 0 && ext->page.edge_flash.bottom_ip == 0) {
|
||||
ext->page.edge_flash.right_ip = 1;
|
||||
lv_page_start_edge_flash(tileview);
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_set_x(scrl, -ext->act_id.x * w);
|
||||
}
|
||||
|
||||
/*Apply the drag constraints*/
|
||||
if(ext->drag_ver == 0) lv_obj_set_y(scrl, - ext->act_id.y * lv_obj_get_height(tileview));
|
||||
if(ext->drag_hor == 0) lv_obj_set_x(scrl, - ext->act_id.x * lv_obj_get_width(tileview));
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is applied called for the elements of the tileview. Used when the element is
|
||||
* @param element
|
||||
* @param sign
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
static lv_res_t element_signal_func(lv_obj_t * element, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
lv_signal_func_t sign_func = lv_obj_get_free_ptr(element);
|
||||
res = sign_func(element, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
/*Initialize some variables on PRESS*/
|
||||
if(sign == LV_SIGNAL_PRESSED) {
|
||||
/*Get the tileview from the element*/
|
||||
lv_obj_t * tileview = lv_obj_get_parent(element);
|
||||
while(tileview) {
|
||||
if(lv_obj_get_signal_func(tileview) != lv_tileview_signal) tileview = lv_obj_get_parent(tileview);
|
||||
else break;
|
||||
}
|
||||
|
||||
if(tileview) {
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
ext->drag_hor = 0;
|
||||
ext->drag_ver = 0;
|
||||
set_valid_drag_dirs(tileview);
|
||||
}
|
||||
}
|
||||
|
||||
/*Animate the tabview to the correct location on RELEASE*/
|
||||
else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED) {
|
||||
|
||||
/*Get the tileview from the element*/
|
||||
lv_obj_t * tileview = lv_obj_get_parent(element);
|
||||
while(tileview) {
|
||||
if(lv_obj_get_signal_func(tileview) != lv_tileview_signal) tileview = lv_obj_get_parent(tileview);
|
||||
else break;
|
||||
}
|
||||
|
||||
if(tileview) {
|
||||
/* If the element was dragged and it moved the tileview finish the drag manually to
|
||||
* let the tileview to finish the move.*/
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
if(indev->proc.drag_in_prog && (ext->drag_hor || ext->drag_ver)) {
|
||||
|
||||
lv_obj_t * drag_obj = element;
|
||||
while(lv_obj_get_drag_parent(drag_obj)) {
|
||||
drag_obj = lv_obj_get_parent(drag_obj);
|
||||
if(drag_obj == NULL) break;
|
||||
}
|
||||
indev->proc.drag_in_prog = 0;
|
||||
if(drag_obj) drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, NULL);
|
||||
}
|
||||
|
||||
drag_end_handler(tileview);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user releases an element of the tileview after dragging it.
|
||||
* @param tileview pointer to a tileview object
|
||||
*/
|
||||
static void drag_end_handler(lv_obj_t * tileview)
|
||||
{
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
lv_point_t point_act;
|
||||
lv_indev_get_point(indev, &point_act);
|
||||
lv_obj_t * scrl = lv_page_get_scrl(tileview);
|
||||
lv_point_t p;
|
||||
|
||||
p.x = - (scrl->coords.x1 - LV_HOR_RES / 2);
|
||||
p.y = - (scrl->coords.y1 - LV_VER_RES / 2);
|
||||
|
||||
/*From the drag vector (drag throw) predict the end position*/
|
||||
if(ext->drag_hor) {
|
||||
lv_point_t vect;
|
||||
lv_indev_get_vect(indev, &vect);
|
||||
lv_coord_t predict = 0;
|
||||
|
||||
while(vect.x != 0) {
|
||||
predict += vect.x;
|
||||
vect.x = vect.x * (100 - LV_INDEV_DRAG_THROW) / 100;
|
||||
}
|
||||
|
||||
p.x -= predict;
|
||||
}
|
||||
else if(ext->drag_ver) {
|
||||
lv_point_t vect;
|
||||
lv_indev_get_vect(indev, &vect);
|
||||
lv_coord_t predict = 0;
|
||||
|
||||
while(vect.y != 0) {
|
||||
predict += vect.y;
|
||||
vect.y = vect.y * (100 - LV_INDEV_DRAG_THROW) / 100;
|
||||
}
|
||||
|
||||
p.y -= predict;
|
||||
}
|
||||
|
||||
/*Get the index of the tile*/
|
||||
p.x = p.x / lv_obj_get_width(tileview);
|
||||
p.y = p.y / lv_obj_get_height(tileview);
|
||||
|
||||
/*Max +- move*/
|
||||
lv_coord_t x_move = p.x - ext->act_id.x;
|
||||
lv_coord_t y_move = p.y - ext->act_id.y;
|
||||
if(x_move < -1) x_move = -1;
|
||||
if(x_move > 1) x_move = 1;
|
||||
if(y_move < -1) y_move = -1;
|
||||
if(y_move > 1) y_move = 1;
|
||||
|
||||
/*Set the new tile*/
|
||||
lv_tileview_set_tile_act(tileview, ext->act_id.x + x_move, ext->act_id.y + y_move,true);
|
||||
}
|
||||
|
||||
static bool set_valid_drag_dirs(lv_obj_t * tileview)
|
||||
{
|
||||
|
||||
lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview);
|
||||
if(ext->valid_pos == NULL) return false;
|
||||
|
||||
ext->drag_bottom_en = 0;
|
||||
ext->drag_top_en = 0;
|
||||
ext->drag_left_en = 0;
|
||||
ext->drag_right_en = 0;
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; ext->valid_pos[i].x != LV_COORD_MIN; 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;
|
||||
if(ext->valid_pos[i].x == ext->act_id.x + 1 && ext->valid_pos[i].y == ext->act_id.y) ext->drag_right_en = 1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
163
lv_objx/lv_tileview.h
Normal file
163
lv_objx/lv_tileview.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* @file lv_tileview.h
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LV_TILEVIEW_H
|
||||
#define LV_TILEVIEW_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_LV_TILEVIEW != 0
|
||||
|
||||
#include "../lv_objx/lv_page.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
|
||||
|
||||
/* parametes: pointer to a tileview object, x, y (tile coordinates to load)
|
||||
* return: LV_RES_INV: to prevent the loading of the tab; LV_RES_OK: if everything is fine*/
|
||||
typedef lv_res_t (*lv_tileview_action_t)(lv_obj_t *, lv_coord_t, lv_coord_t);
|
||||
|
||||
/*Data of tileview*/
|
||||
typedef struct {
|
||||
lv_page_ext_t page;
|
||||
/*New data for this type */
|
||||
const lv_point_t * valid_pos;
|
||||
uint16_t anim_time;
|
||||
lv_tileview_action_t action;
|
||||
lv_point_t act_id;
|
||||
uint8_t drag_top_en :1;
|
||||
uint8_t drag_bottom_en :1;
|
||||
uint8_t drag_left_en :1;
|
||||
uint8_t drag_right_en :1;
|
||||
uint8_t drag_hor :1;
|
||||
uint8_t drag_ver :1;
|
||||
} lv_tileview_ext_t;
|
||||
|
||||
|
||||
/*Styles*/
|
||||
enum {
|
||||
LV_TILEVIEW_STYLE_BG,
|
||||
};
|
||||
typedef uint8_t lv_tileview_style_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a tileview objects
|
||||
* @param par pointer to an object, it will be the parent of the new tileview
|
||||
* @param copy pointer to a tileview object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created tileview
|
||||
*/
|
||||
lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy);
|
||||
|
||||
/*======================
|
||||
* Add/remove functions
|
||||
*=====================*/
|
||||
|
||||
/**
|
||||
* Register an object on the tileview. The register object will able to slide the tileview
|
||||
* @param element pointer to an object
|
||||
*/
|
||||
void lv_tileview_add_element(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 pointer is saved so can't be a local variable.
|
||||
*/
|
||||
void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos);
|
||||
|
||||
/**
|
||||
* Set the tile to be shown
|
||||
* @param tileview pointer to a tileview object
|
||||
* @param x column id (0, 1, 2...)
|
||||
* @param y line id (0, 1, 2...)
|
||||
* @param anim_en true: move with animation
|
||||
*/
|
||||
void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, bool anim_en);
|
||||
|
||||
/**
|
||||
* Enable the edge flash effect. (Show an arc when the an edge is reached)
|
||||
* @param tileview pointer to a Tileview
|
||||
* @param en true or false to enable/disable end flash
|
||||
*/
|
||||
static inline void lv_tileview_set_edge_flash(lv_obj_t * tileview, bool en)
|
||||
{
|
||||
lv_page_set_edge_flash(tileview, en);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a tileview.
|
||||
* @param tileview pointer to tileview object
|
||||
* @param type which style should be set
|
||||
* @param style pointer to a style
|
||||
*/
|
||||
void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, lv_style_t *style);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the scroll propagation property
|
||||
* @param tileview pointer to a Tileview
|
||||
* @return true or false
|
||||
*/
|
||||
static inline bool lv_tileview_get_edge_flash(lv_obj_t * tileview)
|
||||
{
|
||||
return lv_page_get_edge_flash(tileview);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style of a tileview.
|
||||
* @param tileview pointer to tileview object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to the style
|
||||
*/
|
||||
lv_style_t * lv_tileview_get_style(const lv_obj_t * tileview, lv_tileview_style_t type);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_TILEVIEW*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_TILEVIEW_H*/
|
||||
@@ -299,6 +299,18 @@ void lv_win_set_style(lv_obj_t * win, lv_win_style_t type, lv_style_t * style)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set drag status of a window. If set to 'true' window can be dragged like on a PC.
|
||||
* @param win pointer to a window object
|
||||
* @param drag_en whether dragging is enabled
|
||||
*/
|
||||
void lv_win_set_drag(lv_obj_t *win, bool drag_en)
|
||||
{
|
||||
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
||||
lv_obj_t * win_header = ext->header;
|
||||
lv_obj_set_drag_parent(win_header, drag_en);
|
||||
lv_obj_set_drag(win, drag_en);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
|
||||
@@ -157,6 +157,12 @@ void lv_win_set_sb_mode(lv_obj_t *win, lv_sb_mode_t sb_mode);
|
||||
*/
|
||||
void lv_win_set_style(lv_obj_t *win, lv_win_style_t type, lv_style_t *style);
|
||||
|
||||
/**
|
||||
* Set drag status of a window. If set to 'true' window can be dragged like on a PC.
|
||||
* @param win pointer to a window object
|
||||
* @param drag_en whether dragging is enabled
|
||||
*/
|
||||
void lv_win_set_drag(lv_obj_t *win, bool drag_en);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
@@ -220,6 +226,16 @@ lv_coord_t lv_win_get_width(lv_obj_t * win);
|
||||
*/
|
||||
lv_style_t * lv_win_get_style(const lv_obj_t *win, lv_win_style_t type);
|
||||
|
||||
/**
|
||||
* Get drag status of a window. If set to 'true' window can be dragged like on a PC.
|
||||
* @param win pointer to a window object
|
||||
* @return whether window is draggable
|
||||
*/
|
||||
static inline bool lv_win_get_drag(const lv_obj_t *win)
|
||||
{
|
||||
return lv_obj_get_drag(win);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
@@ -73,7 +73,7 @@ void lv_theme_set_current(lv_theme_t * th)
|
||||
uint16_t i;
|
||||
lv_style_t ** cur_th_style_p = (lv_style_t **) ¤t_theme;
|
||||
for(i = 0; i < style_num; i++) {
|
||||
uint64_t adr = (uint64_t)&th_styles[i];
|
||||
uintptr_t adr = (uintptr_t)&th_styles[i];
|
||||
memcpy(&cur_th_style_p[i], &adr, sizeof(lv_style_t *));
|
||||
}
|
||||
inited = true;
|
||||
@@ -84,7 +84,7 @@ void lv_theme_set_current(lv_theme_t * th)
|
||||
uint16_t i;
|
||||
lv_style_t ** th_style = (lv_style_t **) th;
|
||||
for(i = 0; i < style_num; i++) {
|
||||
uint64_t s = (uint64_t)th_style[i];
|
||||
uintptr_t s = (uintptr_t)th_style[i];
|
||||
if(s) memcpy(&th_styles[i], (void *)s, sizeof(lv_style_t));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user