prototype argument renameing
This commit is contained in:
@@ -59,12 +59,12 @@ void anim_init(void)
|
||||
*/
|
||||
void anim_create(anim_t * anim_p)
|
||||
{
|
||||
anim_t * new_anim_dp = ll_ins_head(&anim_ll);
|
||||
dm_assert(new_anim_dp);
|
||||
anim_t * new_anim = ll_ins_head(&anim_ll);
|
||||
dm_assert(new_anim);
|
||||
|
||||
memcpy(new_anim_dp, anim_p, sizeof(anim_t));
|
||||
memcpy(new_anim, anim_p, sizeof(anim_t));
|
||||
|
||||
new_anim_dp->fp(new_anim_dp->p, new_anim_dp->start);
|
||||
new_anim->fp(new_anim->p, new_anim->start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ static void dispi_task(void);
|
||||
static void dispi_proc_point(lv_dispi_t * dispi_p, cord_t x, cord_t y);
|
||||
static void dispi_proc_press(lv_dispi_t * dispi_p);
|
||||
static void disi_proc_release(lv_dispi_t * dispi_p);
|
||||
static lv_obj_t* dispi_search_obj(const lv_dispi_t * dispi_p, lv_obj_t* obj_dp);
|
||||
static lv_obj_t * dispi_search_obj(const lv_dispi_t * dispi_p, lv_obj_t * obj);
|
||||
static void dispi_drag(lv_dispi_t * dispi_p);
|
||||
static void dispi_drag_throw(lv_dispi_t * dispi_p);
|
||||
|
||||
@@ -154,8 +154,8 @@ static void dispi_proc_point(lv_dispi_t * dispi_p, cord_t x, cord_t y)
|
||||
#endif
|
||||
/*Handle the reset query*/
|
||||
if(lv_dispi_reset_now != false) {
|
||||
dispi_p->act_obj_dp = NULL;
|
||||
dispi_p->last_obj_dp = NULL;
|
||||
dispi_p->act_obj = NULL;
|
||||
dispi_p->last_obj = NULL;
|
||||
dispi_p->drag_in_prog = 0;
|
||||
dispi_p->long_press_sent = 0;
|
||||
dispi_p->press_time_stamp = 0;
|
||||
@@ -188,15 +188,15 @@ static void dispi_proc_point(lv_dispi_t * dispi_p, cord_t x, cord_t y)
|
||||
*/
|
||||
static void dispi_proc_press(lv_dispi_t * dispi_p)
|
||||
{
|
||||
lv_obj_t* pr_obj_dp = dispi_p->act_obj_dp;
|
||||
lv_obj_t * pr_obj = dispi_p->act_obj;
|
||||
|
||||
/*If there is no last object then search*/
|
||||
if(dispi_p->act_obj_dp == NULL) {
|
||||
pr_obj_dp = dispi_search_obj(dispi_p, lv_scr_act());
|
||||
if(dispi_p->act_obj == NULL) {
|
||||
pr_obj = dispi_search_obj(dispi_p, lv_scr_act());
|
||||
}
|
||||
/*If there is last object but it can not be dragged also search*/
|
||||
else if(lv_obj_get_drag(dispi_p->act_obj_dp) == false) {/*Now act_obj_dp != NULL*/
|
||||
pr_obj_dp = dispi_search_obj(dispi_p, lv_scr_act());
|
||||
else if(lv_obj_get_drag(dispi_p->act_obj) == false) {/*Now act_obj != NULL*/
|
||||
pr_obj = dispi_search_obj(dispi_p, lv_scr_act());
|
||||
}
|
||||
/*If a dragable object was the last then keep it*/
|
||||
else {
|
||||
@@ -204,18 +204,18 @@ static void dispi_proc_press(lv_dispi_t * dispi_p)
|
||||
}
|
||||
|
||||
/*If a new object was found reset some variables and send a pressed signal*/
|
||||
if(pr_obj_dp != dispi_p->act_obj_dp) {
|
||||
if(pr_obj != dispi_p->act_obj) {
|
||||
|
||||
dispi_p->last_point.x = dispi_p->act_point.x;
|
||||
dispi_p->last_point.y = dispi_p->act_point.y;
|
||||
|
||||
/*If a new object found the previous was lost, so send a signal*/
|
||||
if(dispi_p->act_obj_dp != NULL) {
|
||||
dispi_p->act_obj_dp->signal_f(dispi_p->act_obj_dp,
|
||||
if(dispi_p->act_obj != NULL) {
|
||||
dispi_p->act_obj->signal_f(dispi_p->act_obj,
|
||||
LV_SIGNAL_PRESS_LOST, dispi_p);
|
||||
}
|
||||
|
||||
if(pr_obj_dp != NULL) {
|
||||
if(pr_obj != NULL) {
|
||||
/* Save the time when the obj pressed.
|
||||
* It is necessary to count the long press time.*/
|
||||
dispi_p->press_time_stamp = systick_get();
|
||||
@@ -225,7 +225,7 @@ static void dispi_proc_press(lv_dispi_t * dispi_p)
|
||||
dispi_p->vect_sum.y = 0;
|
||||
|
||||
/*Search for 'top' attribute*/
|
||||
lv_obj_t * i = pr_obj_dp;
|
||||
lv_obj_t * i = pr_obj;
|
||||
lv_obj_t * last_top = NULL;
|
||||
while(i != NULL){
|
||||
if(i->top_en != 0) last_top = i;
|
||||
@@ -234,36 +234,36 @@ static void dispi_proc_press(lv_dispi_t * dispi_p)
|
||||
|
||||
if(last_top != NULL) {
|
||||
/*Move the last_top object to the foreground*/
|
||||
lv_obj_t * par_dp =lv_obj_get_parent(last_top);
|
||||
lv_obj_t * par =lv_obj_get_parent(last_top);
|
||||
/*After list change it will be the new head*/
|
||||
ll_chg_list(&par_dp->child_ll, &par_dp->child_ll, last_top);
|
||||
ll_chg_list(&par->child_ll, &par->child_ll, last_top);
|
||||
lv_obj_inv(last_top);
|
||||
}
|
||||
|
||||
/*Send a signal about the press*/
|
||||
pr_obj_dp->signal_f(pr_obj_dp, LV_SIGNAL_PRESSED, dispi_p);
|
||||
pr_obj->signal_f(pr_obj, LV_SIGNAL_PRESSED, dispi_p);
|
||||
}
|
||||
}
|
||||
|
||||
/*The reset can be set in the signal function.
|
||||
* In case of reset query ignore the remaining parts.*/
|
||||
if(lv_dispi_reset_qry == false) {
|
||||
dispi_p->act_obj_dp = pr_obj_dp; /*Save the pressed object*/
|
||||
dispi_p->last_obj_dp = dispi_p->act_obj_dp; /*Refresh the last_obj*/
|
||||
dispi_p->act_obj = pr_obj; /*Save the pressed object*/
|
||||
dispi_p->last_obj = dispi_p->act_obj; /*Refresh the last_obj*/
|
||||
|
||||
/*Calculate the vector*/
|
||||
dispi_p->vect.x = dispi_p->act_point.x - dispi_p->last_point.x;
|
||||
dispi_p->vect.y = dispi_p->act_point.y - dispi_p->last_point.y;
|
||||
|
||||
/*If there is active object and it can be dragged run the drag*/
|
||||
if(dispi_p->act_obj_dp != NULL) {
|
||||
if(dispi_p->act_obj != NULL) {
|
||||
dispi_drag(dispi_p);
|
||||
|
||||
/*If there is no drag then check for long press time*/
|
||||
if(dispi_p->drag_in_prog == 0 && dispi_p->long_press_sent == 0) {
|
||||
/*Send a signal about the long press if enough time elapsed*/
|
||||
if(systick_elaps(dispi_p->press_time_stamp) > LV_DISPI_LONG_PRESS_TIME) {
|
||||
pr_obj_dp->signal_f(pr_obj_dp, LV_SIGNAL_LONG_PRESS, dispi_p);
|
||||
pr_obj->signal_f(pr_obj, LV_SIGNAL_LONG_PRESS, dispi_p);
|
||||
|
||||
/*Mark the signal sending to do not send it again*/
|
||||
dispi_p->long_press_sent = 1;
|
||||
@@ -280,17 +280,17 @@ static void dispi_proc_press(lv_dispi_t * dispi_p)
|
||||
static void disi_proc_release(lv_dispi_t * dispi_p)
|
||||
{
|
||||
/*Forgot the act obj and send a released signal */
|
||||
if(dispi_p->act_obj_dp != NULL) {
|
||||
dispi_p->act_obj_dp->signal_f(dispi_p->act_obj_dp,
|
||||
if(dispi_p->act_obj != NULL) {
|
||||
dispi_p->act_obj->signal_f(dispi_p->act_obj,
|
||||
LV_SIGNAL_RELEASED, dispi_p);
|
||||
|
||||
dispi_p->act_obj_dp = NULL;
|
||||
dispi_p->act_obj = NULL;
|
||||
dispi_p->press_time_stamp = 0;
|
||||
}
|
||||
|
||||
/*The reset can be set in the signal function.
|
||||
* In case of reset query ignore the remaining parts.*/
|
||||
if(dispi_p->last_obj_dp != NULL && lv_dispi_reset_qry == false) {
|
||||
if(dispi_p->last_obj != NULL && lv_dispi_reset_qry == false) {
|
||||
dispi_drag_throw(dispi_p);
|
||||
}
|
||||
}
|
||||
@@ -298,19 +298,19 @@ static void disi_proc_release(lv_dispi_t * dispi_p)
|
||||
/**
|
||||
* Search the most top, clickable object on the last point of a display input
|
||||
* @param dispi_p pointer to a display input
|
||||
* @param obj_dp pointer to a start object, typically the screen
|
||||
* @param obj pointer to a start object, typically the screen
|
||||
* @return pointer to the found object or NULL if there was no suitable object
|
||||
*/
|
||||
static lv_obj_t* dispi_search_obj(const lv_dispi_t * dispi_p, lv_obj_t* obj_dp)
|
||||
static lv_obj_t * dispi_search_obj(const lv_dispi_t * dispi_p, lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_t* found_p = NULL;
|
||||
lv_obj_t * found_p = NULL;
|
||||
|
||||
/*If the point is on this object*/
|
||||
/*Check its children too*/
|
||||
if(area_is_point_on(&obj_dp->cords, &dispi_p->act_point)) {
|
||||
lv_obj_t* i;
|
||||
if(area_is_point_on(&obj->cords, &dispi_p->act_point)) {
|
||||
lv_obj_t * i;
|
||||
|
||||
LL_READ(obj_dp->child_ll, i) {
|
||||
LL_READ(obj->child_ll, i) {
|
||||
found_p = dispi_search_obj(dispi_p, i);
|
||||
|
||||
/*If a child was found then break*/
|
||||
@@ -321,14 +321,14 @@ static lv_obj_t* dispi_search_obj(const lv_dispi_t * dispi_p, lv_obj_t* obj_dp)
|
||||
|
||||
/*If then the children was not ok, but this obj is clickable
|
||||
* and it or its parent is not hidden then save this object*/
|
||||
if(found_p == NULL && lv_obj_get_click(obj_dp) != false) {
|
||||
lv_obj_t * i = obj_dp;
|
||||
if(found_p == NULL && lv_obj_get_click(obj) != false) {
|
||||
lv_obj_t * i = obj;
|
||||
while(i != NULL) {
|
||||
if(lv_obj_get_hidden(i) == true) break;
|
||||
i = lv_obj_get_parent(i);
|
||||
}
|
||||
/*No parent found with hidden == true*/
|
||||
if(i == NULL) found_p = obj_dp;
|
||||
if(i == NULL) found_p = obj;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -337,19 +337,19 @@ static lv_obj_t* dispi_search_obj(const lv_dispi_t * dispi_p, lv_obj_t* obj_dp)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the dragging of dispi_p->act_obj_dp
|
||||
* Handle the dragging of dispi_p->act_obj
|
||||
* @param dispi_p pointer to a display input
|
||||
*/
|
||||
static void dispi_drag(lv_dispi_t * dispi_p)
|
||||
{
|
||||
lv_obj_t* par_dp = lv_obj_get_parent(dispi_p->act_obj_dp);
|
||||
lv_obj_t* drag_obj_dp = dispi_p->act_obj_dp;
|
||||
lv_obj_t * par = lv_obj_get_parent(dispi_p->act_obj);
|
||||
lv_obj_t * drag_obj = dispi_p->act_obj;
|
||||
|
||||
if(lv_obj_get_drag_parent(dispi_p->act_obj_dp) != false) {
|
||||
drag_obj_dp = par_dp;
|
||||
if(lv_obj_get_drag_parent(dispi_p->act_obj) != false) {
|
||||
drag_obj = par;
|
||||
}
|
||||
|
||||
if(lv_obj_get_drag(drag_obj_dp) == false) return;
|
||||
if(lv_obj_get_drag(drag_obj) == false) return;
|
||||
|
||||
/*If still there is no drag then count the movement*/
|
||||
if(dispi_p->drag_in_prog == 0) {
|
||||
@@ -361,7 +361,7 @@ static void dispi_drag(lv_dispi_t * dispi_p)
|
||||
abs(dispi_p->vect_sum.y) >= LV_DISPI_DRAG_LIMIT)
|
||||
{
|
||||
dispi_p->drag_in_prog = 1;
|
||||
drag_obj_dp->signal_f(drag_obj_dp,
|
||||
drag_obj->signal_f(drag_obj,
|
||||
LV_SIGNAL_DRAG_BEGIN, dispi_p);
|
||||
}
|
||||
}
|
||||
@@ -372,9 +372,9 @@ static void dispi_drag(lv_dispi_t * dispi_p)
|
||||
if(dispi_p->vect.x != 0 ||
|
||||
dispi_p->vect.y != 0) {
|
||||
/*Get the coordinates of the object end modify them*/
|
||||
cord_t act_x = lv_obj_get_x(drag_obj_dp) + dispi_p->vect.x;
|
||||
cord_t act_y = lv_obj_get_y(drag_obj_dp) + dispi_p->vect.y;
|
||||
lv_obj_set_pos(drag_obj_dp, act_x, act_y);
|
||||
cord_t act_x = lv_obj_get_x(drag_obj) + dispi_p->vect.x;
|
||||
cord_t act_y = lv_obj_get_y(drag_obj) + dispi_p->vect.y;
|
||||
lv_obj_set_pos(drag_obj, act_x, act_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -388,17 +388,17 @@ static void dispi_drag_throw(lv_dispi_t * dispi_p)
|
||||
if(dispi_p->drag_in_prog == 0) return;
|
||||
|
||||
/*Set new position if the vector is not zero*/
|
||||
lv_obj_t* par_dp = lv_obj_get_parent(dispi_p->last_obj_dp);
|
||||
lv_obj_t* drag_obj_dp = dispi_p->last_obj_dp;
|
||||
lv_obj_t * par = lv_obj_get_parent(dispi_p->last_obj);
|
||||
lv_obj_t * drag_obj = dispi_p->last_obj;
|
||||
|
||||
if(lv_obj_get_drag_parent(dispi_p->last_obj_dp) != false) {
|
||||
drag_obj_dp = par_dp;
|
||||
if(lv_obj_get_drag_parent(dispi_p->last_obj) != false) {
|
||||
drag_obj = par;
|
||||
}
|
||||
|
||||
/*Return if the drag throw is not enabled*/
|
||||
if(lv_obj_get_drag_throw(drag_obj_dp) == false ){
|
||||
if(lv_obj_get_drag_throw(drag_obj) == false ){
|
||||
dispi_p->drag_in_prog = 0;
|
||||
drag_obj_dp->signal_f(drag_obj_dp, LV_SIGNAL_DRAG_END, dispi_p);
|
||||
drag_obj->signal_f(drag_obj, LV_SIGNAL_DRAG_END, dispi_p);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -410,13 +410,13 @@ static void dispi_drag_throw(lv_dispi_t * dispi_p)
|
||||
dispi_p->vect.y != 0)
|
||||
{
|
||||
/*Get the coordinates and modify them*/
|
||||
cord_t act_x = lv_obj_get_x(drag_obj_dp) + dispi_p->vect.x;
|
||||
cord_t act_y = lv_obj_get_y(drag_obj_dp) + dispi_p->vect.y;
|
||||
lv_obj_set_pos(drag_obj_dp, act_x, act_y);
|
||||
cord_t act_x = lv_obj_get_x(drag_obj) + dispi_p->vect.x;
|
||||
cord_t act_y = lv_obj_get_y(drag_obj) + dispi_p->vect.y;
|
||||
lv_obj_set_pos(drag_obj, act_x, act_y);
|
||||
}
|
||||
/*If the vectors become 0 -> drag_in_prog = 0 and send a drag end signal*/
|
||||
else {
|
||||
dispi_p->drag_in_prog = 0;
|
||||
drag_obj_dp->signal_f(drag_obj_dp, LV_SIGNAL_DRAG_END, dispi_p);
|
||||
drag_obj->signal_f(drag_obj, LV_SIGNAL_DRAG_END, dispi_p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ typedef struct
|
||||
point_t last_point;
|
||||
point_t vect;
|
||||
point_t vect_sum;
|
||||
lv_obj_t* act_obj_dp;
|
||||
lv_obj_t* last_obj_dp;
|
||||
lv_obj_t * act_obj;
|
||||
lv_obj_t * last_obj;
|
||||
uint32_t press_time_stamp;
|
||||
|
||||
/*Flags*/
|
||||
|
||||
800
lv_obj/lv_obj.c
800
lv_obj/lv_obj.c
File diff suppressed because it is too large
Load Diff
128
lv_obj/lv_obj.h
128
lv_obj/lv_obj.h
@@ -59,7 +59,7 @@ typedef enum
|
||||
LV_DESIGN_COVER_CHK,
|
||||
}lv_design_mode_t;
|
||||
|
||||
typedef bool (* lv_design_f_t) (struct __LV_OBJ_T* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
typedef bool (* lv_design_f_t) (struct __lv_obj_t * obj, const area_t * mask_p, lv_design_mode_t mode);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -75,11 +75,11 @@ typedef enum
|
||||
LV_SIGNAL_STYLE_CHG,
|
||||
}lv_signal_t;
|
||||
|
||||
typedef bool (* lv_signal_f_t) (struct __LV_OBJ_T* obj_dp, lv_signal_t sign, void * param);
|
||||
typedef bool (* lv_signal_f_t) (struct __lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||
|
||||
typedef struct __LV_OBJ_T
|
||||
{
|
||||
struct __LV_OBJ_T* par_dp;
|
||||
struct __lv_obj_t * par;
|
||||
ll_dsc_t child_ll;
|
||||
|
||||
area_t cords;
|
||||
@@ -87,7 +87,7 @@ typedef struct __LV_OBJ_T
|
||||
lv_signal_f_t signal_f;
|
||||
lv_design_f_t design_f;
|
||||
|
||||
void * ext_dp; /*The object attributes can be extended here*/
|
||||
void * ext; /*The object attributes can be extended here*/
|
||||
void * style_p; /*Object specific style*/
|
||||
|
||||
#if LV_OBJ_FREE_P != 0
|
||||
@@ -165,86 +165,86 @@ typedef enum
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_init(void);
|
||||
void lv_obj_inv(lv_obj_t* obj_dp);
|
||||
void lv_obj_refr_style(lv_obj_t* obj_dp);
|
||||
void lv_obj_inv(lv_obj_t * obj);
|
||||
void lv_obj_refr_style(lv_obj_t * obj);
|
||||
void lv_style_refr_all(void * style_p);
|
||||
|
||||
/*Create and delete*/
|
||||
lv_obj_t* lv_obj_create(lv_obj_t* parent_dp, lv_obj_t * copy_dp);
|
||||
void lv_obj_del(lv_obj_t* obj_dp);
|
||||
lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy);
|
||||
void lv_obj_del(lv_obj_t * obj);
|
||||
|
||||
/*Virtual functions*/
|
||||
bool lv_obj_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
bool lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||
|
||||
/*SETTER FUNCTIONS*/
|
||||
/*Parent/children set*/
|
||||
void lv_obj_set_parent(lv_obj_t* obj_dp, lv_obj_t* parent_dp);
|
||||
void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent);
|
||||
/*Coordinate set (set_cord_f will be called)*/
|
||||
void lv_obj_set_pos(lv_obj_t* obj_dp, cord_t x, cord_t y);
|
||||
void lv_obj_set_pos_us(lv_obj_t* obj_dp, cord_t x, cord_t y);
|
||||
void lv_obj_set_x(lv_obj_t* obj_dp, cord_t x);
|
||||
void lv_obj_set_x_us(lv_obj_t* obj_dp, cord_t x);
|
||||
void lv_obj_set_y(lv_obj_t* obj_dp, cord_t y);
|
||||
void lv_obj_set_y_us(lv_obj_t* obj_dp, cord_t y);
|
||||
void lv_obj_set_size(lv_obj_t* obj_dp, cord_t w, cord_t h);
|
||||
void lv_obj_set_size_us(lv_obj_t* obj_dp, cord_t w, cord_t h);
|
||||
void lv_obj_set_width(lv_obj_t* obj_dp, cord_t w);
|
||||
void lv_obj_set_width_us(lv_obj_t* obj_dp, cord_t w);
|
||||
void lv_obj_set_height(lv_obj_t* obj_dp, cord_t h);
|
||||
void lv_obj_set_height_us(lv_obj_t* obj_dp, cord_t h);
|
||||
void lv_obj_align(lv_obj_t* obj_dp,lv_obj_t* base_dp, lv_align_t align, cord_t x_mod, cord_t y_mod);
|
||||
void lv_obj_align_us(lv_obj_t* obj_dp,lv_obj_t* base_dp, lv_align_t align, cord_t x_mod, cord_t y_mod);
|
||||
void lv_obj_set_pos(lv_obj_t * obj, cord_t x, cord_t y);
|
||||
void lv_obj_set_pos_us(lv_obj_t * obj, cord_t x, cord_t y);
|
||||
void lv_obj_set_x(lv_obj_t * obj, cord_t x);
|
||||
void lv_obj_set_x_us(lv_obj_t * obj, cord_t x);
|
||||
void lv_obj_set_y(lv_obj_t * obj, cord_t y);
|
||||
void lv_obj_set_y_us(lv_obj_t * obj, cord_t y);
|
||||
void lv_obj_set_size(lv_obj_t * obj, cord_t w, cord_t h);
|
||||
void lv_obj_set_size_us(lv_obj_t * obj, cord_t w, cord_t h);
|
||||
void lv_obj_set_width(lv_obj_t * obj, cord_t w);
|
||||
void lv_obj_set_width_us(lv_obj_t * obj, cord_t w);
|
||||
void lv_obj_set_height(lv_obj_t * obj, cord_t h);
|
||||
void lv_obj_set_height_us(lv_obj_t * obj, cord_t h);
|
||||
void lv_obj_align(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod, cord_t y_mod);
|
||||
void lv_obj_align_us(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod, cord_t y_mod);
|
||||
/*Appearance set*/
|
||||
void lv_obj_set_hidden(lv_obj_t* obj_dp, bool hidden_en);
|
||||
void lv_obj_set_opa(lv_obj_t* obj_dp, opa_t opa);
|
||||
void lv_obj_set_opar(lv_obj_t* obj_dp, opa_t opa);
|
||||
void lv_obj_set_hidden(lv_obj_t * obj, bool hidden_en);
|
||||
void lv_obj_set_opa(lv_obj_t * obj, opa_t opa);
|
||||
void lv_obj_set_opar(lv_obj_t * obj, opa_t opa);
|
||||
/*Attribute set*/
|
||||
void lv_obj_set_click(lv_obj_t* obj_dp, bool click_en);
|
||||
void lv_obj_set_top(lv_obj_t* obj_dp, bool click_en);
|
||||
void lv_obj_set_drag(lv_obj_t* obj_dp, bool drag_en);
|
||||
void lv_obj_set_drag_throw(lv_obj_t* obj_dp, bool dragthr_en);
|
||||
void lv_obj_set_drag_parent(lv_obj_t* obj_dp, bool dragpar_en);
|
||||
void lv_obj_set_signal_f(lv_obj_t* obj_dp, lv_signal_f_t fp);
|
||||
void lv_obj_set_design_f(lv_obj_t* obj_dp, lv_design_f_t fp);
|
||||
void lv_obj_set_click(lv_obj_t * obj, bool click_en);
|
||||
void lv_obj_set_top(lv_obj_t * obj, bool click_en);
|
||||
void lv_obj_set_drag(lv_obj_t * obj, bool drag_en);
|
||||
void lv_obj_set_drag_throw(lv_obj_t * obj, bool dragthr_en);
|
||||
void lv_obj_set_drag_parent(lv_obj_t * obj, bool dragpar_en);
|
||||
void lv_obj_set_signal_f(lv_obj_t * obj, lv_signal_f_t fp);
|
||||
void lv_obj_set_design_f(lv_obj_t * obj, lv_design_f_t fp);
|
||||
/*Other set*/
|
||||
void * lv_obj_alloc_ext(lv_obj_t* obj_dp, uint16_t ext_size);
|
||||
void lv_obj_set_style(lv_obj_t* obj_dp, void * style_p);
|
||||
void * lv_obj_iso_style(lv_obj_t * obj_dp, uint32_t style_size);
|
||||
void lv_obj_set_free_num(lv_obj_t* obj_dp, uint8_t free_num);
|
||||
void lv_obj_set_free_p(lv_obj_t* obj_dp, void * free_p);
|
||||
void lv_obj_anim(lv_obj_t * obj_dp, lv_anim_builtin_t anim, uint16_t time, uint16_t delay, void (*cb) (lv_obj_t *));
|
||||
void * lv_obj_alloc_ext(lv_obj_t * obj, uint16_t ext_size);
|
||||
void lv_obj_set_style(lv_obj_t * obj, void * style_p);
|
||||
void * lv_obj_iso_style(lv_obj_t * obj, uint32_t style_size);
|
||||
void lv_obj_set_free_num(lv_obj_t * obj, uint8_t free_num);
|
||||
void lv_obj_set_free_p(lv_obj_t * obj, void * free_p);
|
||||
void lv_obj_anim(lv_obj_t * obj, lv_anim_builtin_t anim, uint16_t time, uint16_t delay, void (*cb) (lv_obj_t *));
|
||||
|
||||
/*GETTER FUNCTIONS*/
|
||||
/*Screen get*/
|
||||
lv_obj_t* lv_scr_act(void);
|
||||
void lv_scr_load(lv_obj_t* scr_dp);
|
||||
lv_obj_t * lv_scr_act(void);
|
||||
void lv_scr_load(lv_obj_t * scr);
|
||||
/*Parent/children get*/
|
||||
lv_obj_t* lv_obj_get_scr(lv_obj_t* obj_dp);
|
||||
lv_obj_t* lv_obj_get_parent(lv_obj_t* obj_dp);
|
||||
lv_obj_t * lv_obj_get_child(lv_obj_t * obj_dp, lv_obj_t * child_dp);
|
||||
lv_obj_t * lv_obj_get_scr(lv_obj_t * obj);
|
||||
lv_obj_t * lv_obj_get_parent(lv_obj_t * obj);
|
||||
lv_obj_t * lv_obj_get_child(lv_obj_t * obj, lv_obj_t * child);
|
||||
/*Coordinate get*/
|
||||
void lv_obj_get_cords(lv_obj_t* obj_dp, area_t * cords_p);
|
||||
cord_t lv_obj_get_x(lv_obj_t* obj_dp);
|
||||
cord_t lv_obj_get_y(lv_obj_t* obj_dp);
|
||||
cord_t lv_obj_get_width(lv_obj_t* obj_dp);
|
||||
cord_t lv_obj_get_height(lv_obj_t* obj_dp);
|
||||
void lv_obj_get_cords(lv_obj_t * obj, area_t * cords_p);
|
||||
cord_t lv_obj_get_x(lv_obj_t * obj);
|
||||
cord_t lv_obj_get_y(lv_obj_t * obj);
|
||||
cord_t lv_obj_get_width(lv_obj_t * obj);
|
||||
cord_t lv_obj_get_height(lv_obj_t * obj);
|
||||
/*Appearance get*/
|
||||
bool lv_obj_get_hidden(lv_obj_t* obj_dp);
|
||||
opa_t lv_obj_get_opa(lv_obj_t* obj_dp);
|
||||
bool lv_obj_get_hidden(lv_obj_t * obj);
|
||||
opa_t lv_obj_get_opa(lv_obj_t * obj);
|
||||
/*Attribute get*/
|
||||
bool lv_obj_get_click(lv_obj_t* obj_dp);
|
||||
bool lv_obj_get_top(lv_obj_t* obj_dp);
|
||||
bool lv_obj_get_drag(lv_obj_t* obj_dp);
|
||||
bool lv_obj_get_drag_throw(lv_obj_t* obj_dp);
|
||||
bool lv_obj_get_drag_parent(lv_obj_t* obj_dp);
|
||||
bool lv_obj_get_click(lv_obj_t * obj);
|
||||
bool lv_obj_get_top(lv_obj_t * obj);
|
||||
bool lv_obj_get_drag(lv_obj_t * obj);
|
||||
bool lv_obj_get_drag_throw(lv_obj_t * obj);
|
||||
bool lv_obj_get_drag_parent(lv_obj_t * obj);
|
||||
|
||||
/*Virtual functions get*/
|
||||
lv_design_f_t lv_obj_get_design_f(lv_obj_t* obj_dp);
|
||||
lv_signal_f_t lv_obj_get_signal_f(lv_obj_t* obj_dp);
|
||||
lv_design_f_t lv_obj_get_design_f(lv_obj_t * obj);
|
||||
lv_signal_f_t lv_obj_get_signal_f(lv_obj_t * obj);
|
||||
/*Other get*/
|
||||
void * lv_obj_get_ext(lv_obj_t* obj_dp);
|
||||
void * lv_obj_get_style(lv_obj_t* obj_dp);
|
||||
uint8_t lv_obj_get_free_num(lv_obj_t* obj_dp);
|
||||
void * lv_obj_get_ext(lv_obj_t * obj);
|
||||
void * lv_obj_get_style(lv_obj_t * obj);
|
||||
uint8_t lv_obj_get_free_num(lv_obj_t * obj);
|
||||
|
||||
lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p);
|
||||
|
||||
@@ -252,7 +252,7 @@ lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p);
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#define LV_SA(obj_dp, style_type) ((style_type *) obj_dp->style_p)
|
||||
#define LV_EA(obj_dp, ext_type) ((ext_type *) obj_dp->ext_dp)
|
||||
#define LV_SA(obj, style_type) ((style_type *) obj->style_p)
|
||||
#define LV_EA(obj, ext_type) ((ext_type *) obj->ext)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,9 +38,9 @@ static void lv_refr_area_no_vdb(const area_t * area_p);
|
||||
static void lv_refr_area_with_vdb(const area_t * area_p);
|
||||
static void lv_refr_area_part_vdb(const area_t * area_p);
|
||||
#endif
|
||||
static lv_obj_t* lv_refr_get_top_obj(const area_t * area_p, lv_obj_t* obj_dp);
|
||||
static void lv_refr_make(lv_obj_t* top_p, const area_t * mask_p);
|
||||
static void lv_refr_obj(lv_obj_t* obj_dp, const area_t * mask_ori_p);
|
||||
static lv_obj_t * lv_refr_get_top_obj(const area_t * area_p, lv_obj_t * obj);
|
||||
static void lv_refr_make(lv_obj_t * top_p, const area_t * mask_p);
|
||||
static void lv_refr_obj(lv_obj_t * obj, const area_t * mask_ori_p);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -219,7 +219,7 @@ static void lv_refr_areas(lv_join_t * area_a, uint32_t area_num)
|
||||
*/
|
||||
static void lv_refr_area_no_vdb(const area_t * area_p)
|
||||
{
|
||||
lv_obj_t* top_p;
|
||||
lv_obj_t * top_p;
|
||||
|
||||
/*Get top object which is not covered by others*/
|
||||
top_p = lv_refr_get_top_obj(area_p, lv_scr_act());
|
||||
@@ -283,7 +283,7 @@ static void lv_refr_area_with_vdb(const area_t * area_p)
|
||||
static void lv_refr_area_part_vdb(const area_t * area_p)
|
||||
{
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
lv_obj_t* top_p;
|
||||
lv_obj_t * top_p;
|
||||
|
||||
/*Get the new mask from the original area and the act. VDB
|
||||
It will be a part of 'area_p'*/
|
||||
@@ -305,21 +305,21 @@ static void lv_refr_area_part_vdb(const area_t * area_p)
|
||||
/**
|
||||
* Search the most top object which fully covers an area
|
||||
* @param area_p pointer to an area
|
||||
* @param obj_dp the first object to start the searching (typically a screen)
|
||||
* @param obj the first object to start the searching (typically a screen)
|
||||
* @return
|
||||
*/
|
||||
static lv_obj_t* lv_refr_get_top_obj(const area_t * area_p, lv_obj_t* obj_dp)
|
||||
static lv_obj_t * lv_refr_get_top_obj(const area_t * area_p, lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_t* i;
|
||||
lv_obj_t* found_p = NULL;
|
||||
lv_obj_t * i;
|
||||
lv_obj_t * found_p = NULL;
|
||||
|
||||
/*If this object is fully cover the draw area check the children too */
|
||||
if(obj_dp->opa == OPA_COVER &&
|
||||
obj_dp->hidden == 0 &&
|
||||
LV_SA(obj_dp, lv_objs_t)->transp == 0 &&
|
||||
obj_dp->design_f(obj_dp, area_p, LV_DESIGN_COVER_CHK) != false)
|
||||
if(obj->opa == OPA_COVER &&
|
||||
obj->hidden == 0 &&
|
||||
LV_SA(obj, lv_objs_t)->transp == 0 &&
|
||||
obj->design_f(obj, area_p, LV_DESIGN_COVER_CHK) != false)
|
||||
{
|
||||
LL_READ(obj_dp->child_ll, i) {
|
||||
LL_READ(obj->child_ll, i) {
|
||||
found_p = lv_refr_get_top_obj(area_p, i);
|
||||
|
||||
/*If a children is ok then break*/
|
||||
@@ -330,7 +330,7 @@ static lv_obj_t* lv_refr_get_top_obj(const area_t * area_p, lv_obj_t* obj_dp)
|
||||
|
||||
/*If there is no better children use this object*/
|
||||
if(found_p == NULL) {
|
||||
found_p = obj_dp;
|
||||
found_p = obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ static lv_obj_t* lv_refr_get_top_obj(const area_t * area_p, lv_obj_t* obj_dp)
|
||||
* @param top_p pointer to an objects. Start the drawing from it.
|
||||
* @param mask_p pointer to an area, the objects will be drawn only here
|
||||
*/
|
||||
static void lv_refr_make(lv_obj_t* top_p, const area_t * mask_p)
|
||||
static void lv_refr_make(lv_obj_t * top_p, const area_t * mask_p)
|
||||
{
|
||||
/* Normally always will be a top_obj (at least the screen)
|
||||
* but in special cases (e.g. if the screen has alpha) it won't.
|
||||
@@ -353,60 +353,60 @@ static void lv_refr_make(lv_obj_t* top_p, const area_t * mask_p)
|
||||
lv_refr_obj(top_p, mask_p);
|
||||
|
||||
/*Draw the 'younger' objects because they can be on top_obj */
|
||||
lv_obj_t* par_dp;
|
||||
lv_obj_t* i;
|
||||
lv_obj_t* border_p = top_p;
|
||||
lv_obj_t * par;
|
||||
lv_obj_t * i;
|
||||
lv_obj_t * border_p = top_p;
|
||||
|
||||
par_dp = lv_obj_get_parent(top_p);
|
||||
par = lv_obj_get_parent(top_p);
|
||||
|
||||
/*Do until not reach the screen*/
|
||||
while(par_dp != NULL) {
|
||||
while(par != NULL) {
|
||||
/*object before border_p has to be redrawn*/
|
||||
i = ll_get_prev(&(par_dp->child_ll), border_p);
|
||||
i = ll_get_prev(&(par->child_ll), border_p);
|
||||
|
||||
while(i != NULL) {
|
||||
/*Refresh the objects*/
|
||||
lv_refr_obj(i, mask_p);
|
||||
i = ll_get_prev(&(par_dp->child_ll), i);
|
||||
i = ll_get_prev(&(par->child_ll), i);
|
||||
}
|
||||
|
||||
/*The new border will be there last parents,
|
||||
*so the 'younger' brothers of parent will be refreshed*/
|
||||
border_p = par_dp;
|
||||
border_p = par;
|
||||
/*Go a level deeper*/
|
||||
par_dp = lv_obj_get_parent(par_dp);
|
||||
par = lv_obj_get_parent(par);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh an object an all of its children. (Called recursively)
|
||||
* @param obj_dp pointer to an object to refresh
|
||||
* @param obj pointer to an object to refresh
|
||||
* @param mask_ori_p pointer to an area, the objects will be drawn only here
|
||||
*/
|
||||
static void lv_refr_obj(lv_obj_t* obj_dp, const area_t * mask_ori_p)
|
||||
static void lv_refr_obj(lv_obj_t * obj, const area_t * mask_ori_p)
|
||||
{
|
||||
/*Do not refresh hidden objects*/
|
||||
if(obj_dp->hidden != 0) return;
|
||||
if(obj->hidden != 0) return;
|
||||
|
||||
bool union_ok; /* Store the return value of area_union */
|
||||
/* Truncate the original mask to the coordinates of the parent
|
||||
* because the parent and its children are visible only here */
|
||||
area_t mask_parent;
|
||||
union_ok = area_union(&mask_parent, mask_ori_p, &obj_dp->cords);
|
||||
union_ok = area_union(&mask_parent, mask_ori_p, &obj->cords);
|
||||
|
||||
/*Draw the parent and its children only if they ore on 'mask_parent'*/
|
||||
if(union_ok != false) {
|
||||
|
||||
/* Redraw the object */
|
||||
if(obj_dp->opa != OPA_TRANSP && LV_SA(obj_dp, lv_objs_t)->transp == 0) {
|
||||
obj_dp->design_f(obj_dp, &mask_parent, LV_DESIGN_DRAW_MAIN);
|
||||
if(obj->opa != OPA_TRANSP && LV_SA(obj, lv_objs_t)->transp == 0) {
|
||||
obj->design_f(obj, &mask_parent, LV_DESIGN_DRAW_MAIN);
|
||||
}
|
||||
|
||||
area_t mask_child; /*Mask from obj_dp and its child*/
|
||||
lv_obj_t* child_p;
|
||||
LL_READ_BACK(obj_dp->child_ll, child_p)
|
||||
area_t mask_child; /*Mask from obj and its child*/
|
||||
lv_obj_t * child_p;
|
||||
LL_READ_BACK(obj->child_ll, child_p)
|
||||
{
|
||||
/* Get the union (common parts) of original mask (from obj_dp)
|
||||
/* Get the union (common parts) of original mask (from obj)
|
||||
* and its child */
|
||||
union_ok = area_union(&mask_child, &mask_parent, &child_p->cords);
|
||||
|
||||
@@ -418,8 +418,8 @@ static void lv_refr_obj(lv_obj_t* obj_dp, const area_t * mask_ori_p)
|
||||
}
|
||||
|
||||
/* If all the children are redrawn call make 'post draw' design */
|
||||
if(obj_dp->opa != OPA_TRANSP && LV_SA(obj_dp, lv_objs_t)->transp == 0) {
|
||||
obj_dp->design_f(obj_dp, &mask_parent, LV_DESIGN_DRAW_POST);
|
||||
if(obj->opa != OPA_TRANSP && LV_SA(obj, lv_objs_t)->transp == 0) {
|
||||
obj->design_f(obj, &mask_parent, LV_DESIGN_DRAW_POST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
238
lv_objx/lv_btn.c
238
lv_objx/lv_btn.c
@@ -24,8 +24,8 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_btn_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static void lv_btn_style_load(lv_obj_t * obj_dp, lv_rects_t * rects_p);
|
||||
static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_btn_style_load(lv_obj_t * btn, lv_rects_t * rects);
|
||||
static void lv_btns_init(void);
|
||||
|
||||
/**********************
|
||||
@@ -45,127 +45,127 @@ static lv_btns_t lv_btns_border;
|
||||
|
||||
/**
|
||||
* Create a button objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new button
|
||||
* @param copy_dp pointer to a button object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new button
|
||||
* @param copy pointer to a button object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created button
|
||||
*/
|
||||
lv_obj_t* lv_btn_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
lv_obj_t* new_obj_dp;
|
||||
lv_obj_t * new_btn;
|
||||
|
||||
new_obj_dp = lv_rect_create(par_dp, copy_dp);
|
||||
new_btn = lv_rect_create(par, copy);
|
||||
/*Allocate the extended data*/
|
||||
lv_obj_alloc_ext(new_obj_dp, sizeof(lv_btn_ext_t));
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_btn_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_btn_design);
|
||||
lv_obj_alloc_ext(new_btn, sizeof(lv_btn_ext_t));
|
||||
lv_obj_set_signal_f(new_btn, lv_btn_signal);
|
||||
lv_obj_set_design_f(new_btn, lv_btn_design);
|
||||
|
||||
lv_btn_ext_t * btn_ext_dp = lv_obj_get_ext(new_obj_dp);
|
||||
btn_ext_dp->lpr_exec = 0;
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(new_btn);
|
||||
ext->lpr_exec = 0;
|
||||
|
||||
/*If no copy do the basic initialization*/
|
||||
if(copy_dp == NULL)
|
||||
if(copy == NULL)
|
||||
{
|
||||
btn_ext_dp->state = LV_BTN_STATE_REL;
|
||||
btn_ext_dp->pr_action = NULL;
|
||||
btn_ext_dp->rel_action = NULL;
|
||||
btn_ext_dp->lpr_action = NULL;
|
||||
btn_ext_dp->tgl = 0;
|
||||
lv_obj_set_style(new_obj_dp, lv_btns_get(LV_BTNS_DEF, NULL));
|
||||
lv_rect_set_layout(new_obj_dp, LV_RECT_LAYOUT_CENTER);
|
||||
ext->state = LV_BTN_STATE_REL;
|
||||
ext->pr_action = NULL;
|
||||
ext->rel_action = NULL;
|
||||
ext->lpr_action = NULL;
|
||||
ext->tgl = 0;
|
||||
lv_obj_set_style(new_btn, lv_btns_get(LV_BTNS_DEF, NULL));
|
||||
lv_rect_set_layout(new_btn, LV_RECT_LAYOUT_CENTER);
|
||||
}
|
||||
/*Copy 'copy_dp'*/
|
||||
/*Copy 'copy'*/
|
||||
else{
|
||||
lv_btn_ext_t * ori_btn_ext = lv_obj_get_ext(copy_dp);
|
||||
btn_ext_dp->state = ori_btn_ext->state;
|
||||
btn_ext_dp->pr_action = ori_btn_ext->pr_action;
|
||||
btn_ext_dp->rel_action = ori_btn_ext->rel_action;
|
||||
btn_ext_dp->lpr_action = ori_btn_ext->lpr_action;
|
||||
btn_ext_dp->tgl = ori_btn_ext->tgl;
|
||||
lv_btn_ext_t * ori_btn_ext = lv_obj_get_ext(copy);
|
||||
ext->state = ori_btn_ext->state;
|
||||
ext->pr_action = ori_btn_ext->pr_action;
|
||||
ext->rel_action = ori_btn_ext->rel_action;
|
||||
ext->lpr_action = ori_btn_ext->lpr_action;
|
||||
ext->tgl = ori_btn_ext->tgl;
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_btn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the button
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_btn_signal(lv_obj_t * obj_dp, lv_signal_t sign, void* param)
|
||||
bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void* param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_rect_signal(obj_dp, sign, param);
|
||||
valid = lv_rect_signal(btn, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_btn_state_t state = lv_btn_get_state(obj_dp);
|
||||
lv_btn_ext_t * btn_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
bool tgl = lv_btn_get_tgl(obj_dp);
|
||||
lv_btn_state_t state = lv_btn_get_state(btn);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
|
||||
bool tgl = lv_btn_get_tgl(btn);
|
||||
|
||||
switch (sign){
|
||||
case LV_SIGNAL_PRESSED:
|
||||
/*Refresh the state*/
|
||||
if(btn_ext_dp->state == LV_BTN_STATE_REL) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_PR);
|
||||
} else if(btn_ext_dp->state == LV_BTN_STATE_TGL_REL) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_PR);
|
||||
if(ext->state == LV_BTN_STATE_REL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_PR);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_REL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR);
|
||||
}
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(btn);
|
||||
|
||||
btn_ext_dp->lpr_exec = 0;
|
||||
ext->lpr_exec = 0;
|
||||
/*Call the press action, here 'param' is the caller dispi*/
|
||||
if(btn_ext_dp->pr_action != NULL && state != LV_BTN_STATE_INA) {
|
||||
valid = btn_ext_dp->pr_action(obj_dp, param);
|
||||
if(ext->pr_action != NULL && state != LV_BTN_STATE_INA) {
|
||||
valid = ext->pr_action(btn, param);
|
||||
}
|
||||
break;
|
||||
|
||||
case LV_SIGNAL_PRESS_LOST:
|
||||
/*Refresh the state*/
|
||||
if(btn_ext_dp->state == LV_BTN_STATE_PR) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
|
||||
} else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
|
||||
if(ext->state == LV_BTN_STATE_PR) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PR) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
}
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(btn);
|
||||
break;
|
||||
|
||||
case LV_SIGNAL_RELEASED:
|
||||
/*If not dragged and it was not long press action then
|
||||
*change state and run the action*/
|
||||
if(lv_dispi_is_dragging(param) == false && btn_ext_dp->lpr_exec == 0) {
|
||||
if(btn_ext_dp->state == LV_BTN_STATE_PR && tgl == false) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
|
||||
} else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR && tgl == false) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
|
||||
} else if(btn_ext_dp->state == LV_BTN_STATE_PR && tgl == true) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
|
||||
} else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR && tgl == true) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
|
||||
if(lv_dispi_is_dragging(param) == false && ext->lpr_exec == 0) {
|
||||
if(ext->state == LV_BTN_STATE_PR && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == false) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
} else if(ext->state == LV_BTN_STATE_PR && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PR && tgl == true) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
}
|
||||
|
||||
|
||||
if(btn_ext_dp->rel_action != NULL && state != LV_BTN_STATE_INA) {
|
||||
valid = btn_ext_dp->rel_action(obj_dp, param);
|
||||
if(ext->rel_action != NULL && state != LV_BTN_STATE_INA) {
|
||||
valid = ext->rel_action(btn, param);
|
||||
}
|
||||
} else { /*If dragged change back the state*/
|
||||
if(btn_ext_dp->state == LV_BTN_STATE_PR) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
|
||||
} else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR) {
|
||||
lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
|
||||
if(ext->state == LV_BTN_STATE_PR) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_REL);
|
||||
} else if(ext->state == LV_BTN_STATE_TGL_PR) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
}
|
||||
}
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(btn);
|
||||
break;
|
||||
case LV_SIGNAL_LONG_PRESS:
|
||||
/*Call the long press action, here 'param' is the caller dispi*/
|
||||
if(btn_ext_dp->lpr_action != NULL && state != LV_BTN_STATE_INA) {
|
||||
btn_ext_dp->lpr_exec = 1;
|
||||
valid = btn_ext_dp->lpr_action(obj_dp, param);
|
||||
if(ext->lpr_action != NULL && state != LV_BTN_STATE_INA) {
|
||||
ext->lpr_exec = 1;
|
||||
valid = ext->lpr_action(btn, param);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -183,63 +183,63 @@ bool lv_btn_signal(lv_obj_t * obj_dp, lv_signal_t sign, void* param)
|
||||
|
||||
/**
|
||||
* Enable the toggled states
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @param tgl true: enable toggled states, false: disable
|
||||
*/
|
||||
void lv_btn_set_tgl(lv_obj_t* obj_dp, bool tgl)
|
||||
void lv_btn_set_tgl(lv_obj_t * btn, bool tgl)
|
||||
{
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
|
||||
|
||||
btn_p->tgl = tgl != false ? 1 : 0;
|
||||
ext->tgl = tgl != false ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the state of the button
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @param state the new state of the button (from lv_btn_state_t enum)
|
||||
*/
|
||||
void lv_btn_set_state(lv_obj_t* obj_dp, lv_btn_state_t state)
|
||||
void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)
|
||||
{
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
|
||||
|
||||
btn_p->state = state;
|
||||
lv_obj_inv(obj_dp);
|
||||
ext->state = state;
|
||||
lv_obj_inv(btn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function to call when the button is pressed
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @param pr_action pointer to function
|
||||
*/
|
||||
void lv_btn_set_pr_action(lv_obj_t* obj_dp, bool (*pr_action)(lv_obj_t*, lv_dispi_t *))
|
||||
void lv_btn_set_pr_action(lv_obj_t * btn, bool (*pr_action)(lv_obj_t *, lv_dispi_t *))
|
||||
{
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
|
||||
|
||||
btn_p->pr_action = pr_action;
|
||||
ext->pr_action = pr_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function to call when the button is released
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @param pr_action pointer to function
|
||||
*/
|
||||
void lv_btn_set_rel_action(lv_obj_t* obj_dp, bool (*rel_action)(lv_obj_t*, lv_dispi_t *))
|
||||
void lv_btn_set_rel_action(lv_obj_t * btn, bool (*rel_action)(lv_obj_t *, lv_dispi_t *))
|
||||
{
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(btn);
|
||||
|
||||
btn_p->rel_action = rel_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function to call when the button is long pressed
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @param pr_action pointer to function
|
||||
*/
|
||||
void lv_btn_set_lpr_action(lv_obj_t* obj_dp, bool (*lpr_action)(lv_obj_t*, lv_dispi_t *))
|
||||
void lv_btn_set_lpr_action(lv_obj_t * btn, bool (*lpr_action)(lv_obj_t *, lv_dispi_t *))
|
||||
{
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
|
||||
|
||||
btn_p->lpr_action = lpr_action;
|
||||
ext->lpr_action = lpr_action;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -248,35 +248,35 @@ void lv_btn_set_lpr_action(lv_obj_t* obj_dp, bool (*lpr_action)(lv_obj_t*, lv_di
|
||||
|
||||
/**
|
||||
* Get the current state of the button
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @return the state of the button (from lv_btn_state_t enum)
|
||||
*/
|
||||
lv_btn_state_t lv_btn_get_state(lv_obj_t* obj_dp)
|
||||
lv_btn_state_t lv_btn_get_state(lv_obj_t * btn)
|
||||
{
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
|
||||
|
||||
return btn_p->state;
|
||||
return ext->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the toggle enable attribute of the button
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param btn pointer to a button object
|
||||
* @return ture: toggle enabled, false: disabled
|
||||
*/
|
||||
bool lv_btn_get_tgl(lv_obj_t* obj_dp)
|
||||
bool lv_btn_get_tgl(lv_obj_t * btn)
|
||||
{
|
||||
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext(btn);
|
||||
|
||||
return btn_p->tgl != 0 ? true : false;
|
||||
return ext->tgl != 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_btns_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_btns_t style
|
||||
*/
|
||||
lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p)
|
||||
lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -286,7 +286,7 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p)
|
||||
style_inited = true;
|
||||
}
|
||||
|
||||
lv_btns_t *style_p;
|
||||
lv_btns_t * style_p;
|
||||
|
||||
switch(style) {
|
||||
case LV_BTNS_DEF:
|
||||
@@ -302,9 +302,9 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p)
|
||||
style_p = &lv_btns_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_btns_t));
|
||||
else memcpy(copy_p, &lv_btns_def, sizeof(lv_btns_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_btns_t));
|
||||
else memcpy(copy, &lv_btns_def, sizeof(lv_btns_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -316,7 +316,7 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the buttons
|
||||
* @param obj_dp pointer to an object
|
||||
* @param btn pointer to a button object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -324,9 +324,9 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_btn_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
lv_btns_t * btns_p = lv_obj_get_style(obj_dp);
|
||||
lv_btns_t * btns_p = lv_obj_get_style(btn);
|
||||
|
||||
/* Because of the radius it is not sure the area is covered*/
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
@@ -334,47 +334,47 @@ static bool lv_btn_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod
|
||||
area_t area_tmp;
|
||||
|
||||
/*Check horizontally without radius*/
|
||||
lv_obj_get_cords(obj_dp, &area_tmp);
|
||||
lv_obj_get_cords(btn, &area_tmp);
|
||||
area_tmp.x1 += r;
|
||||
area_tmp.x2 -= r;
|
||||
if(area_is_in(mask_p, &area_tmp) == true) return true;
|
||||
if(area_is_in(mask, &area_tmp) == true) return true;
|
||||
|
||||
/*Check vertically without radius*/
|
||||
lv_obj_get_cords(obj_dp, &area_tmp);
|
||||
lv_obj_get_cords(btn, &area_tmp);
|
||||
area_tmp.y1 += r;
|
||||
area_tmp.y2 -= r;
|
||||
if(area_is_in(mask_p, &area_tmp) == true) return true;
|
||||
if(area_is_in(mask, &area_tmp) == true) return true;
|
||||
|
||||
return false;
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
opa_t opa = lv_obj_get_opa(obj_dp);
|
||||
opa_t opa = lv_obj_get_opa(btn);
|
||||
area_t area;
|
||||
lv_obj_get_cords(obj_dp, &area);
|
||||
lv_obj_get_cords(btn, &area);
|
||||
|
||||
lv_rects_t rects_tmp;
|
||||
|
||||
lv_btn_style_load(obj_dp, &rects_tmp);
|
||||
lv_btn_style_load(btn, &rects_tmp);
|
||||
|
||||
/*Draw the rectangle*/
|
||||
lv_draw_rect(&area, mask_p, &rects_tmp, opa);
|
||||
lv_draw_rect(&area, mask, &rects_tmp, opa);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the corresponding style according to the state to 'rects' in 'lv_btns_t'
|
||||
* @param obj_dp pointer to a button object
|
||||
* @param obj pointer to a button object
|
||||
*/
|
||||
static void lv_btn_style_load(lv_obj_t * obj_dp, lv_rects_t * rects_p)
|
||||
static void lv_btn_style_load(lv_obj_t * btn, lv_rects_t * rects)
|
||||
{
|
||||
lv_btn_state_t state = lv_btn_get_state(obj_dp);
|
||||
lv_btns_t * btns_p = lv_obj_get_style(obj_dp);
|
||||
lv_btn_state_t state = lv_btn_get_state(btn);
|
||||
lv_btns_t * ext = lv_obj_get_style(btn);
|
||||
|
||||
/*Load the style*/
|
||||
memcpy(rects_p, &btns_p->rects, sizeof(lv_rects_t));
|
||||
rects_p->objs.color = btns_p->mcolor[state];
|
||||
rects_p->gcolor = btns_p->gcolor[state];
|
||||
rects_p->bcolor = btns_p->bcolor[state];
|
||||
memcpy(rects, &ext->rects, sizeof(lv_rects_t));
|
||||
rects->objs.color = ext->mcolor[state];
|
||||
rects->gcolor = ext->gcolor[state];
|
||||
rects->bcolor = ext->bcolor[state];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,14 +33,17 @@ typedef enum
|
||||
LV_BTN_STATE_NUM,
|
||||
}lv_btn_state_t;
|
||||
|
||||
/*Style of button*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rects_t rects; /*To be compatible with the ancestor*/
|
||||
lv_rects_t rects; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
color_t mcolor[LV_BTN_STATE_NUM];
|
||||
color_t gcolor[LV_BTN_STATE_NUM];
|
||||
color_t bcolor[LV_BTN_STATE_NUM];
|
||||
}lv_btns_t;
|
||||
|
||||
/*Built-in styles of button*/
|
||||
typedef enum
|
||||
{
|
||||
LV_BTNS_DEF,
|
||||
@@ -48,12 +51,14 @@ typedef enum
|
||||
LV_BTNS_BORDER,
|
||||
}lv_btns_builtin_t;
|
||||
|
||||
/*Data of button*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rect_ext_t rect_ext;
|
||||
bool (*pr_action)(lv_obj_t*, lv_dispi_t *);
|
||||
bool (*rel_action)(lv_obj_t*, lv_dispi_t *);
|
||||
bool (*lpr_action)(lv_obj_t*, lv_dispi_t *);
|
||||
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
bool (*pr_action)(lv_obj_t *, lv_dispi_t *);
|
||||
bool (*rel_action)(lv_obj_t *, lv_dispi_t *);
|
||||
bool (*lpr_action)(lv_obj_t *, lv_dispi_t *);
|
||||
|
||||
lv_btn_state_t state;
|
||||
uint8_t tgl :1; /*1: Toggle enabled*/
|
||||
@@ -64,19 +69,19 @@ typedef struct
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/*Create function*/
|
||||
lv_obj_t* lv_btn_create(lv_obj_t* par_dp, lv_obj_t * c_dp);
|
||||
lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
|
||||
bool lv_btn_signal(lv_obj_t * obj_dp, lv_signal_t sign, void * param);
|
||||
lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p);
|
||||
bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param);
|
||||
lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy);
|
||||
|
||||
void lv_btn_set_tgl(lv_obj_t* obj_dp, bool tgl);
|
||||
void lv_btn_set_state(lv_obj_t* obj_dp, lv_btn_state_t state);
|
||||
void lv_btn_set_pr_action(lv_obj_t* obi_p, bool (*pr_action)(lv_obj_t*, lv_dispi_t *));
|
||||
void lv_btn_set_rel_action(lv_obj_t* obj_dp, bool (*rel_action)(lv_obj_t*, lv_dispi_t *));
|
||||
void lv_btn_set_lpr_action(lv_obj_t* obj_dp, bool (*lpr_action)(lv_obj_t*, lv_dispi_t *));
|
||||
void lv_btn_set_tgl(lv_obj_t * btn, bool tgl);
|
||||
void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);
|
||||
void lv_btn_set_pr_action(lv_obj_t * btn, bool (*pr_action)(lv_obj_t *, lv_dispi_t *));
|
||||
void lv_btn_set_rel_action(lv_obj_t * btn, bool (*rel_action)(lv_obj_t *, lv_dispi_t *));
|
||||
void lv_btn_set_lpr_action(lv_obj_t * btn, bool (*lpr_action)(lv_obj_t *, lv_dispi_t *));
|
||||
|
||||
bool lv_btn_get_tgl(lv_obj_t* obj_dp);
|
||||
lv_btn_state_t lv_btn_get_state(lv_obj_t* obj_dp);
|
||||
bool lv_btn_get_tgl(lv_obj_t * btn);
|
||||
lv_btn_state_t lv_btn_get_state(lv_obj_t * btn);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
**********************/
|
||||
|
||||
#if 0 /*Not necessary*/
|
||||
static bool lv_btnm_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_t mode);
|
||||
#endif
|
||||
static uint8_t lv_btnm_get_width_unit(const char * btn_str);
|
||||
static void lv_btnm_create_btns(lv_obj_t * obj_dp, const char ** map_p);
|
||||
static bool lv_btnm_btn_release_action(lv_obj_t * obj_dp, lv_dispi_t * dispi_p);
|
||||
static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map);
|
||||
static bool lv_btnm_btn_release_action(lv_obj_t * btnm, lv_dispi_t * dispi);
|
||||
static void lv_btnms_init(void);
|
||||
|
||||
/**********************
|
||||
@@ -53,52 +53,52 @@ static const char * lv_btnm_def_map[] = {"Btn1","Btn2", "Btn3","\n",
|
||||
|
||||
/**
|
||||
* Create a button matrix objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new button matrix
|
||||
* @param copy_dp pointer to a button matrix object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new button matrix
|
||||
* @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created button matrix
|
||||
*/
|
||||
lv_obj_t* lv_btnm_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor object*/
|
||||
lv_obj_t* new_obj_dp = lv_rect_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_btnm = lv_rect_create(par, copy);
|
||||
dm_assert(new_btnm);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_btnm_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_btnm_ext_t));
|
||||
dm_assert(ext_dp);
|
||||
lv_btnm_ext_t * ext = lv_obj_alloc_ext(new_btnm, sizeof(lv_btnm_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_btnm_signal);
|
||||
lv_obj_set_signal_f(new_btnm, lv_btnm_signal);
|
||||
|
||||
/* Keep the rectangle design function
|
||||
* lv_obj_set_design_f(new_obj_dp, lv_btnm_design); */
|
||||
* lv_obj_set_design_f(new_obj, lv_btnm_design); */
|
||||
|
||||
/*Init the new button matrix object*/
|
||||
if(copy_dp == NULL) {
|
||||
lv_obj_set_size(new_obj_dp, LV_HOR_RES / 2, LV_VER_RES / 2);
|
||||
lv_obj_set_style(new_obj_dp, lv_btnms_get(LV_BTNMS_DEF, NULL));
|
||||
lv_btnm_set_map(new_obj_dp, lv_btnm_def_map);
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_size(new_btnm, LV_HOR_RES / 2, LV_VER_RES / 2);
|
||||
lv_obj_set_style(new_btnm, lv_btnms_get(LV_BTNMS_DEF, NULL));
|
||||
lv_btnm_set_map(new_btnm, lv_btnm_def_map);
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_btnm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the button matrix
|
||||
* @param obj_dp pointer to a button matrix object
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return true: the object is still valid (not deleted), false: the object become invalid
|
||||
*/
|
||||
bool lv_btnm_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_rect_signal(obj_dp, sign, param);
|
||||
valid = lv_rect_signal(btnm, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -109,7 +109,7 @@ bool lv_btnm_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
break;
|
||||
case LV_SIGNAL_STYLE_CHG:
|
||||
case LV_SIGNAL_CORD_CHG:
|
||||
lv_btnm_set_map(obj_dp, LV_EA(obj_dp, lv_btnm_ext_t)->map_p);
|
||||
lv_btnm_set_map(btnm, LV_EA(btnm, lv_btnm_ext_t)->map_p);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -125,46 +125,46 @@ bool lv_btnm_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Set a new map. Buttons will be created/deleted according to the map.
|
||||
* @param obj_dp pointer to a button matrix object
|
||||
* @param map_p pointer a string array. Tha last string hast be: "".
|
||||
* Use "\n" to begin a new line.
|
||||
* Use "\003" octal numbers to set relative
|
||||
* the width of a button. (max. 9 -> \011)
|
||||
* (e.g. const char * str[] = {"a", "b", "\n", "\004c", "d", ""}).
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @param map pointer a string array. Tha last string hast be: "".
|
||||
* Use "\n" to begin a new line.
|
||||
* Use "\003" octal numbers to set relative
|
||||
* the width of a button. (max. 9 -> \011)
|
||||
* (e.g. const char * str[] = {"a", "b", "\n", "\004c", "d", ""}).
|
||||
*/
|
||||
void lv_btnm_set_map(lv_obj_t * obj_dp, const char ** map_p)
|
||||
void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
|
||||
{
|
||||
if(map_p == NULL) return;
|
||||
if(map == NULL) return;
|
||||
|
||||
LV_EA(obj_dp, lv_btnm_ext_t)->map_p = map_p;
|
||||
LV_EA(btnm, lv_btnm_ext_t)->map_p = map;
|
||||
|
||||
/*Analyze the map and create the required number of buttons*/
|
||||
lv_btnm_create_btns(obj_dp, map_p);
|
||||
lv_btnm_create_btns(btnm, map);
|
||||
|
||||
/*Set size and positions of the buttons*/
|
||||
lv_btnms_t * btnms_p = lv_obj_get_style(obj_dp);
|
||||
cord_t max_w = lv_obj_get_width(obj_dp) - 2 * btnms_p->rects.hpad;
|
||||
cord_t max_h = lv_obj_get_height(obj_dp) - 2 * btnms_p->rects.vpad;
|
||||
cord_t act_y = btnms_p->rects.vpad;
|
||||
lv_btnms_t * btnms = lv_obj_get_style(btnm);
|
||||
cord_t max_w = lv_obj_get_width(btnm) - 2 * btnms->bg.hpad;
|
||||
cord_t max_h = lv_obj_get_height(btnm) - 2 * btnms->bg.vpad;
|
||||
cord_t act_y = btnms->bg.vpad;
|
||||
uint8_t btn_cnt_tot = 0; /*Used to set free number of the buttons*/
|
||||
|
||||
/*Count the lines to calculate button height*/
|
||||
uint8_t line_cnt = 1;
|
||||
uint8_t li;
|
||||
for(li = 0; strlen(map_p[li]) != 0; li++) {
|
||||
if(strcmp(map_p[li], "\n") == 0) line_cnt ++;
|
||||
for(li = 0; strlen(map[li]) != 0; li++) {
|
||||
if(strcmp(map[li], "\n") == 0) line_cnt ++;
|
||||
}
|
||||
|
||||
cord_t btn_h = max_h - ((line_cnt - 1) * btnms_p->rects.opad);
|
||||
cord_t btn_h = max_h - ((line_cnt - 1) * btnms->bg.opad);
|
||||
btn_h = btn_h / line_cnt;
|
||||
|
||||
/* Count the units and the buttons in a line
|
||||
* (A button can be 1,2,3... unit wide)*/
|
||||
uint16_t unit_cnt;
|
||||
uint16_t btn_cnt;
|
||||
const char ** map_p_tmp = map_p;
|
||||
lv_obj_t * btn_dp;
|
||||
btn_dp = ll_get_head(&obj_dp->child_ll);
|
||||
const char ** map_p_tmp = map;
|
||||
lv_obj_t * btn;
|
||||
btn = ll_get_head(&btnm->child_ll);
|
||||
|
||||
/*Count the units and the buttons in a line*/
|
||||
while(1) {
|
||||
@@ -179,29 +179,29 @@ void lv_btnm_set_map(lv_obj_t * obj_dp, const char ** map_p)
|
||||
/*Only deal with the non empty lines*/
|
||||
if(btn_cnt != 0) {
|
||||
/*Calculate the unit width*/
|
||||
cord_t unit_w = max_w - ((btn_cnt-1) * btnms_p->rects.opad);
|
||||
cord_t unit_w = max_w - ((btn_cnt-1) * btnms->bg.opad);
|
||||
unit_w = unit_w / unit_cnt;
|
||||
|
||||
/*Set the button size and positions and set the texts*/
|
||||
uint16_t i;
|
||||
lv_obj_t * label_dp;
|
||||
cord_t act_x = btnms_p->rects.hpad;
|
||||
lv_obj_t * label;
|
||||
cord_t act_x = btnms->bg.hpad;
|
||||
for(i = 0; i < btn_cnt; i++) {
|
||||
lv_obj_set_size(btn_dp, unit_w * lv_btnm_get_width_unit(map_p_tmp[i]), btn_h);
|
||||
lv_obj_align(btn_dp, NULL, LV_ALIGN_IN_TOP_LEFT, act_x, act_y);
|
||||
lv_obj_set_free_num(btn_dp, btn_cnt_tot);
|
||||
lv_obj_set_style(btn_dp, &btnms_p->btns);
|
||||
act_x += lv_obj_get_width(btn_dp) + btnms_p->rects.opad;
|
||||
lv_obj_set_size(btn, unit_w * lv_btnm_get_width_unit(map_p_tmp[i]), btn_h);
|
||||
lv_obj_align(btn, NULL, LV_ALIGN_IN_TOP_LEFT, act_x, act_y);
|
||||
lv_obj_set_free_num(btn, btn_cnt_tot);
|
||||
lv_obj_set_style(btn, &btnms->btn);
|
||||
act_x += lv_obj_get_width(btn) + btnms->bg.opad;
|
||||
|
||||
label_dp = lv_obj_get_child(btn_dp, NULL); /*Get the label on the button (the only child)*/
|
||||
lv_obj_set_style(label_dp, &btnms_p->labels);
|
||||
lv_label_set_text(label_dp, map_p_tmp[i]);
|
||||
label = lv_obj_get_child(btn, NULL); /*Get the label on the button (the only child)*/
|
||||
lv_obj_set_style(label, &btnms->btn_label);
|
||||
lv_label_set_text(label, map_p_tmp[i]);
|
||||
|
||||
btn_dp = ll_get_next(&obj_dp->child_ll, btn_dp); /*Go to the next button*/
|
||||
btn = ll_get_next(&btnm->child_ll, btn); /*Go to the next button*/
|
||||
btn_cnt_tot ++;
|
||||
}
|
||||
}
|
||||
act_y += btn_h + btnms_p->rects.opad;
|
||||
act_y += btn_h + btnms->bg.opad;
|
||||
if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/
|
||||
map_p_tmp = &map_p_tmp[btn_cnt + 1]; /*Set the map to the next line*/
|
||||
}
|
||||
@@ -210,12 +210,12 @@ void lv_btnm_set_map(lv_obj_t * obj_dp, const char ** map_p)
|
||||
|
||||
/**
|
||||
* Set a new callback function for the buttons (It will be called when a button is released)
|
||||
* @param obj_dp: pointer to button matrix object
|
||||
* @param btnm: pointer to button matrix object
|
||||
* @param cb pointer to a callback function
|
||||
*/
|
||||
void lv_btnm_set_cb(lv_obj_t * obj_dp, lv_btnm_callback_t cb)
|
||||
void lv_btnm_set_cb(lv_obj_t * btnm, lv_btnm_callback_t cb)
|
||||
{
|
||||
LV_EA(obj_dp, lv_btnm_ext_t)->cb = cb;
|
||||
LV_EA(btnm, lv_btnm_ext_t)->cb = cb;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -224,32 +224,32 @@ void lv_btnm_set_cb(lv_obj_t * obj_dp, lv_btnm_callback_t cb)
|
||||
|
||||
/**
|
||||
* Get the current map of a button matrix
|
||||
* @param obj_dp pointer to a button matrix object
|
||||
* @param btnm pointer to a button matrix object
|
||||
* @return the current map
|
||||
*/
|
||||
const char ** lv_btnm_get_map(lv_obj_t * obj_dp)
|
||||
const char ** lv_btnm_get_map(lv_obj_t * btnm)
|
||||
{
|
||||
return LV_EA(obj_dp, lv_btnm_ext_t)->map_p;
|
||||
return LV_EA(btnm, lv_btnm_ext_t)->map_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a the callback function of the buttons on a button matrix
|
||||
* @param obj_dp: pointer to button matrix object
|
||||
* @param btnm: pointer to button matrix object
|
||||
* @return pointer to the callback function
|
||||
*/
|
||||
lv_btnm_callback_t lv_btnm_get_cb(lv_obj_t * obj_dp)
|
||||
lv_btnm_callback_t lv_btnm_get_cb(lv_obj_t * btnm)
|
||||
{
|
||||
return LV_EA(obj_dp, lv_btnm_ext_t)->cb;
|
||||
return LV_EA(btnm, lv_btnm_ext_t)->cb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_btnms_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_btnms_t style
|
||||
*/
|
||||
lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy_p)
|
||||
lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -269,9 +269,9 @@ lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy_p)
|
||||
style_p = &lv_btnms_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_btnms_t));
|
||||
else memcpy(copy_p, &lv_btnms_def, sizeof(lv_btnms_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_btnms_t));
|
||||
else memcpy(copy, &lv_btnms_def, sizeof(lv_btnms_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -284,7 +284,7 @@ lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy_p)
|
||||
#if 0 /*Not necessary*/
|
||||
/**
|
||||
* Handle the drawing related tasks of the button matrixs
|
||||
* @param obj_dp pointer to an object
|
||||
* @param obj pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -292,14 +292,13 @@ lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_btnm_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_btnm_design(lv_obj_t * obj, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*Draw the object*/
|
||||
|
||||
return true;
|
||||
@@ -313,23 +312,23 @@ static bool lv_btnm_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo
|
||||
static void lv_btnms_init(void)
|
||||
{
|
||||
/*Default style*/
|
||||
lv_rects_get(LV_RECTS_DEF, &lv_btnms_def.rects); /*Background rectangle style*/
|
||||
lv_btns_get(LV_BTNS_DEF, &lv_btnms_def.btns); /*Button style*/
|
||||
lv_labels_get(LV_LABELS_BTN, &lv_btnms_def.labels); /*BUtton label style*/
|
||||
lv_rects_get(LV_RECTS_DEF, &lv_btnms_def.bg); /*Background rectangle style*/
|
||||
lv_btns_get(LV_BTNS_DEF, &lv_btnms_def.btn); /*Button style*/
|
||||
lv_labels_get(LV_LABELS_BTN, &lv_btnms_def.btn_label); /*BUtton label style*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the required number of buttons according to a map
|
||||
* @param obj_dp pointer to button matrix object
|
||||
* @param btnm pointer to button matrix object
|
||||
* @param map_p pointer to a string array
|
||||
*/
|
||||
static void lv_btnm_create_btns(lv_obj_t * obj_dp, const char ** map_p)
|
||||
static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map)
|
||||
{
|
||||
/*Count the buttons in the map*/
|
||||
uint16_t btn_cnt = 0;
|
||||
uint16_t i = 0;
|
||||
while(strlen(map_p[i]) != 0) {
|
||||
if(strcmp(map_p[i], "\n") != 0) { /*Not count line breaks*/
|
||||
while(strlen(map[i]) != 0) {
|
||||
if(strcmp(map[i], "\n") != 0) { /*Not count line breaks*/
|
||||
btn_cnt ++;
|
||||
}
|
||||
i++;
|
||||
@@ -337,23 +336,23 @@ static void lv_btnm_create_btns(lv_obj_t * obj_dp, const char ** map_p)
|
||||
|
||||
/*Get the current number of children of the button matrix*/
|
||||
uint16_t child_cnt = 0;
|
||||
lv_obj_t * child_dp = NULL;
|
||||
lv_obj_t * child = NULL;
|
||||
while(1) {
|
||||
child_dp = lv_obj_get_child(obj_dp, child_dp);
|
||||
if(child_dp != NULL) child_cnt ++;
|
||||
child = lv_obj_get_child(btnm, child);
|
||||
if(child != NULL) child_cnt ++;
|
||||
else break;
|
||||
}
|
||||
|
||||
/*Create or delete buttons to finally get 'btn_cnt' children*/
|
||||
if(child_cnt < btn_cnt) { /*Create buttons*/
|
||||
for(i = 0; i < btn_cnt - child_cnt; i++) {
|
||||
lv_obj_t * btn_dp = lv_btn_create(obj_dp, NULL);
|
||||
lv_btn_set_rel_action(btn_dp, lv_btnm_btn_release_action);
|
||||
lv_label_create(btn_dp, NULL);
|
||||
lv_obj_t * btn = lv_btn_create(btnm, NULL);
|
||||
lv_btn_set_rel_action(btn, lv_btnm_btn_release_action);
|
||||
lv_label_create(btn, NULL);
|
||||
}
|
||||
} else if(child_cnt > btn_cnt) { /*Delete buttons*/
|
||||
for(i = 0; i < child_cnt - btn_cnt; i++) {
|
||||
lv_obj_del(lv_obj_get_child(obj_dp, NULL));
|
||||
lv_obj_del(lv_obj_get_child(btnm, NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,18 +373,18 @@ static uint8_t lv_btnm_get_width_unit(const char * btn_str)
|
||||
|
||||
/**
|
||||
* Called when button is released
|
||||
* @param obj_dp pointer to the released button
|
||||
* @param dispi_p pointer to the caller display input.
|
||||
* @param btn pointer to the released button of the button matrix
|
||||
* @param dispi pointer to the caller display input.
|
||||
* @return true: if the button remains valid (the button matrix or the button is not deleted)
|
||||
*/
|
||||
static bool lv_btnm_btn_release_action(lv_obj_t * obj_dp, lv_dispi_t * dispi_p)
|
||||
static bool lv_btnm_btn_release_action(lv_obj_t * btn, lv_dispi_t * dispi)
|
||||
{
|
||||
lv_obj_t * btnm_dp = lv_obj_get_parent(obj_dp);
|
||||
lv_btnm_ext_t * ext_dp = lv_obj_get_ext(btnm_dp);
|
||||
uint8_t id = lv_obj_get_free_num(obj_dp);
|
||||
lv_obj_t * btnm = lv_obj_get_parent(btn);
|
||||
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
|
||||
uint8_t id = lv_obj_get_free_num(btn);
|
||||
bool ret;
|
||||
if(ext_dp->cb != NULL) {
|
||||
ret = ext_dp->cb(btnm_dp, obj_dp, id); /*Call the set callback function*/
|
||||
if(ext->cb != NULL) {
|
||||
ret = ext->cb(btnm, btn, id); /*Call the set callback function*/
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
/*Style of button matrix*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rects_t rects; /*Style of ancestor*/
|
||||
lv_rects_t bg; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
lv_btns_t btns;
|
||||
lv_labels_t labels;
|
||||
lv_btns_t btn;
|
||||
lv_labels_t btn_label;
|
||||
}lv_btnms_t;
|
||||
|
||||
/*Built-in styles of button matrix*/
|
||||
@@ -54,7 +54,7 @@ typedef bool (*lv_btnm_callback_t) (lv_obj_t *, lv_obj_t *, uint16_t);
|
||||
/*Data of button matrix*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rect_ext_t rect; /*Ext. of ancestor*/
|
||||
lv_rect_ext_t bg; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
const char ** map_p; /*Pointer to the current map*/
|
||||
lv_btnm_callback_t cb;
|
||||
@@ -63,15 +63,15 @@ typedef struct
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_btnm_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_btnm_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy_p);
|
||||
lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param);
|
||||
lv_btnms_t * lv_btnms_get(lv_btnms_builtin_t style, lv_btnms_t * copy);
|
||||
|
||||
void lv_btnm_set_map(lv_obj_t * obj_dp, const char ** map_p);
|
||||
void lv_btnm_set_cb(lv_obj_t * obj_dp, lv_btnm_callback_t cb);
|
||||
void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);
|
||||
void lv_btnm_set_cb(lv_obj_t * btnm, lv_btnm_callback_t cb);
|
||||
|
||||
const char ** lv_btnm_get_map(lv_obj_t * obj_dp);
|
||||
lv_btnm_callback_t lv_btnm_get_cb(lv_obj_t * obj_dp);
|
||||
const char ** lv_btnm_get_map(lv_obj_t * btnm);
|
||||
lv_btnm_callback_t lv_btnm_get_cb(lv_obj_t * btnm);
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
#if 0 /*The ancestor design function is used */
|
||||
static bool lv_cb_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_cb_design(lv_obj_t * cb, const area_t * mask, lv_design_mode_t mode);
|
||||
#endif
|
||||
static void lv_cbs_init(void);
|
||||
|
||||
@@ -48,61 +48,61 @@ static lv_cbs_t lv_cbs_def =
|
||||
|
||||
/**
|
||||
* Create a check box objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new check box
|
||||
* @param copy_dp pointer to a check box object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new check box
|
||||
* @param copy pointer to a check box object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created check box
|
||||
*/
|
||||
lv_obj_t * lv_cb_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor basic object*/
|
||||
lv_obj_t* new_obj_dp = lv_btn_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_cb = lv_btn_create(par, copy);
|
||||
dm_assert(new_cb);
|
||||
|
||||
lv_cb_ext_t * ext = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_cb_ext_t));
|
||||
lv_cb_ext_t * ext = lv_obj_alloc_ext(new_cb, sizeof(lv_cb_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_cb_signal);
|
||||
lv_obj_set_signal_f(new_cb, lv_cb_signal);
|
||||
|
||||
/*Init the new checkbox object*/
|
||||
if(copy_dp == NULL) {
|
||||
lv_rect_set_layout(new_obj_dp, LV_RECT_LAYOUT_ROW_M);
|
||||
lv_rect_set_fit(new_obj_dp, true, true);
|
||||
lv_btn_set_tgl(new_obj_dp, true);
|
||||
if(copy == NULL) {
|
||||
lv_rect_set_layout(new_cb, LV_RECT_LAYOUT_ROW_M);
|
||||
lv_rect_set_fit(new_cb, true, true);
|
||||
lv_btn_set_tgl(new_cb, true);
|
||||
|
||||
ext->bullet = lv_btn_create(new_obj_dp, NULL);
|
||||
ext->bullet = lv_btn_create(new_cb, NULL);
|
||||
lv_obj_set_click(ext->bullet, false);
|
||||
|
||||
ext->label = lv_label_create(new_obj_dp, NULL);
|
||||
ext->label = lv_label_create(new_cb, NULL);
|
||||
lv_label_set_text(ext->label, "Check box");
|
||||
|
||||
lv_obj_set_style(new_obj_dp, lv_cbs_get(LV_CBS_DEF, NULL));
|
||||
lv_obj_set_style(new_cb, lv_cbs_get(LV_CBS_DEF, NULL));
|
||||
} else {
|
||||
lv_cb_ext_t * copy_ext = lv_obj_get_ext(copy_dp);
|
||||
ext->bullet = lv_btn_create(new_obj_dp, copy_ext->bullet);
|
||||
ext->label = lv_label_create(new_obj_dp, copy_ext->label);
|
||||
lv_cb_ext_t * copy_ext = lv_obj_get_ext(copy);
|
||||
ext->bullet = lv_btn_create(new_cb, copy_ext->bullet);
|
||||
ext->label = lv_label_create(new_cb, copy_ext->label);
|
||||
}
|
||||
|
||||
lv_obj_align_us(new_obj_dp, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_align_us(new_cb, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
return new_obj_dp;
|
||||
return new_cb;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signal function of the check box
|
||||
* @param obj_dp pointer to a check box object
|
||||
* @param cb pointer to a check box object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_cb_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_btn_signal(obj_dp, sign, param);
|
||||
valid = lv_btn_signal(cb, sign, param);
|
||||
|
||||
lv_cb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_cbs_t * style_p = lv_obj_get_style(obj_dp);
|
||||
lv_cb_ext_t * ext = lv_obj_get_ext(cb);
|
||||
lv_cbs_t * cbs = lv_obj_get_style(cb);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -112,12 +112,12 @@ bool lv_cb_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
case LV_SIGNAL_RELEASED:
|
||||
case LV_SIGNAL_LONG_PRESS:
|
||||
case LV_SIGNAL_PRESS_LOST:
|
||||
lv_btn_set_state(ext_dp->bullet, lv_btn_get_state(obj_dp));
|
||||
lv_btn_set_state(ext->bullet, lv_btn_get_state(cb));
|
||||
break;
|
||||
case LV_SIGNAL_STYLE_CHG:
|
||||
lv_obj_set_size(ext_dp->bullet, style_p->bullet_size, style_p->bullet_size);
|
||||
lv_obj_set_style(ext_dp->bullet, &style_p->bullet);
|
||||
lv_obj_set_style(ext_dp->label, &style_p->label);
|
||||
lv_obj_set_size(ext->bullet, cbs->bullet_size, cbs->bullet_size);
|
||||
lv_obj_set_style(ext->bullet, &cbs->bullet);
|
||||
lv_obj_set_style(ext->label, &cbs->label);
|
||||
break;
|
||||
case LV_SIGNAL_CLEANUP:
|
||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
||||
@@ -137,13 +137,13 @@ bool lv_cb_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Set the text of a check box
|
||||
* @param obj_dp pointer to a check box
|
||||
* @param cb pointer to a check box
|
||||
* @param txt the text of the check box
|
||||
*/
|
||||
void lv_cb_set_text(lv_obj_t * obj_dp, const char * txt)
|
||||
void lv_cb_set_text(lv_obj_t * cb, const char * txt)
|
||||
{
|
||||
lv_cb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_label_set_text(ext_dp->label, txt);
|
||||
lv_cb_ext_t * ext = lv_obj_get_ext(cb);
|
||||
lv_label_set_text(ext->label, txt);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,22 +153,22 @@ void lv_cb_set_text(lv_obj_t * obj_dp, const char * txt)
|
||||
|
||||
/**
|
||||
* Get the text of a check box
|
||||
* @param obj_dp pointer to check box object
|
||||
* @param cb pointer to check box object
|
||||
* @return pointer to the text of the check box
|
||||
*/
|
||||
const char * lv_cb_get_text(lv_obj_t * obj_dp)
|
||||
const char * lv_cb_get_text(lv_obj_t * cb)
|
||||
{
|
||||
lv_cb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
return lv_label_get_text(ext_dp->label);
|
||||
lv_cb_ext_t * ext = lv_obj_get_ext(cb);
|
||||
return lv_label_get_text(ext->label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_cbs_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_cbs_t style
|
||||
*/
|
||||
lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy_p)
|
||||
lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -188,9 +188,9 @@ lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy_p)
|
||||
style_p = &lv_cbs_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_cbs_t));
|
||||
else memcpy(copy_p, &lv_cbs_def, sizeof(lv_cbs_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_cbs_t));
|
||||
else memcpy(copy, &lv_cbs_def, sizeof(lv_cbs_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -202,7 +202,7 @@ lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy_p)
|
||||
#if 0 /*The ancestor design function is used */
|
||||
/**
|
||||
* Handle the drawing related tasks of the check boxes
|
||||
* @param obj_dp pointer to an object
|
||||
* @param cb pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -210,14 +210,13 @@ lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_cb_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_cb_design(lv_obj_t * cb, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*Draw the object*/
|
||||
|
||||
return true;
|
||||
@@ -231,7 +230,7 @@ static void lv_cbs_init(void)
|
||||
/*Default style*/
|
||||
|
||||
/*Bg style*/
|
||||
lv_rects_get(LV_RECTS_TRANSP, &lv_cbs_def.bg);
|
||||
lv_btns_get(LV_RECTS_TRANSP, &lv_cbs_def.bg);
|
||||
lv_cbs_def.bg.rects.hpad = 0 * LV_STYLE_MULT;
|
||||
lv_cbs_def.bg.rects.vpad = 0 * LV_STYLE_MULT;
|
||||
lv_cbs_def.bg.rects.opad = 5 * LV_STYLE_MULT;
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
/*Style of check box*/
|
||||
typedef struct
|
||||
{
|
||||
lv_btns_t bg;
|
||||
lv_btns_t bg; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
lv_btns_t bullet;
|
||||
lv_labels_t label;
|
||||
cord_t bullet_size;
|
||||
@@ -42,7 +43,8 @@ typedef enum
|
||||
/*Data of check box*/
|
||||
typedef struct
|
||||
{
|
||||
lv_btn_ext_t btn_ext;
|
||||
lv_btn_ext_t bg_btn; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_obj_t * bullet;
|
||||
lv_obj_t * label;
|
||||
}lv_cb_ext_t;
|
||||
@@ -50,11 +52,11 @@ typedef struct
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_cb_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_cb_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
void lv_cb_set_text(lv_obj_t * obj_dp, const char * txt);
|
||||
const char * lv_cb_get_text(lv_obj_t * obj_dp);
|
||||
lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy_p);
|
||||
lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_cb_signal(lv_obj_t * cb, lv_signal_t sign, void * param);
|
||||
void lv_cb_set_text(lv_obj_t * cb, const char * txt);
|
||||
const char * lv_cb_get_text(lv_obj_t * cb);
|
||||
lv_cbs_t * lv_cbs_get(lv_cbs_builtin_t style, lv_cbs_t * copy);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_chart_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_chart_design(lv_obj_t * chart, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_charts_init(void);
|
||||
static void lv_chart_draw_div(lv_obj_t* obj_dp, const area_t * mask_p);
|
||||
static void lv_chart_draw_lines(lv_obj_t* obj_dp, const area_t * mask_p);
|
||||
static void lv_chart_draw_points(lv_obj_t* obj_dp, const area_t * mask_p);
|
||||
static void lv_chart_draw_cols(lv_obj_t* obj_dp, const area_t * mask_p);
|
||||
static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask);
|
||||
static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask);
|
||||
static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask);
|
||||
static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask);
|
||||
|
||||
|
||||
/**********************
|
||||
@@ -56,77 +56,77 @@ static lv_design_f_t ancestor_design_fp;
|
||||
|
||||
/**
|
||||
* Create a chart background objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new chart background
|
||||
* @param copy_dp pointer to a chart background object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new chart background
|
||||
* @param copy pointer to a chart background object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created chart background
|
||||
*/
|
||||
lv_obj_t* lv_chart_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor basic object*/
|
||||
lv_obj_t * new_obj_dp = lv_rect_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_chart = lv_rect_create(par, copy);
|
||||
dm_assert(new_chart);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_chart_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_chart_ext_t));
|
||||
dm_assert(ext_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_alloc_ext(new_chart, sizeof(lv_chart_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
if(ancestor_design_fp == NULL) {
|
||||
ancestor_design_fp = lv_obj_get_design_f(new_obj_dp);
|
||||
ancestor_design_fp = lv_obj_get_design_f(new_chart);
|
||||
}
|
||||
|
||||
ll_init(&ext_dp->dl_ll, sizeof(cord_t *));
|
||||
ext_dp->dl_num = 0;
|
||||
ll_init(&ext->dl_ll, sizeof(cord_t *));
|
||||
ext->dl_num = 0;
|
||||
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_chart_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_chart_design);
|
||||
lv_obj_set_signal_f(new_chart, lv_chart_signal);
|
||||
lv_obj_set_design_f(new_chart, lv_chart_design);
|
||||
|
||||
/*Init the new chart background object*/
|
||||
if(copy_dp == NULL) {
|
||||
ext_dp->type = LV_CHART_LINE;
|
||||
lv_obj_set_style(new_obj_dp, lv_charts_get(LV_CHARTS_DEF, NULL));
|
||||
ext_dp->ymin = LV_CHART_YMIN_DEF;
|
||||
ext_dp->ymax = LV_CHART_YMAX_DEF;
|
||||
ext_dp->hdiv_num = LV_CHART_HDIV_DEF;
|
||||
ext_dp->vdiv_num = LV_CHART_VDIV_DEF;
|
||||
ext_dp->pnum = LV_CHART_PNUM_DEF;
|
||||
if(copy == NULL) {
|
||||
ext->type = LV_CHART_LINE;
|
||||
lv_obj_set_style(new_chart, lv_charts_get(LV_CHARTS_DEF, NULL));
|
||||
ext->ymin = LV_CHART_YMIN_DEF;
|
||||
ext->ymax = LV_CHART_YMAX_DEF;
|
||||
ext->hdiv_num = LV_CHART_HDIV_DEF;
|
||||
ext->vdiv_num = LV_CHART_VDIV_DEF;
|
||||
ext->pnum = LV_CHART_PNUM_DEF;
|
||||
} else {
|
||||
lv_chart_ext_t * ext_copy_dp = lv_obj_get_ext(copy_dp);
|
||||
ext_dp->type = ext_copy_dp->type;
|
||||
ext_dp->ymin = ext_copy_dp->ymin;
|
||||
ext_dp->ymax = ext_copy_dp->ymax;
|
||||
ext_dp->hdiv_num = ext_copy_dp->hdiv_num;
|
||||
ext_dp->vdiv_num = ext_copy_dp->vdiv_num;
|
||||
ext_dp->pnum = ext_copy_dp->pnum;
|
||||
lv_chart_ext_t * ext_copy = lv_obj_get_ext(copy);
|
||||
ext->type = ext_copy->type;
|
||||
ext->ymin = ext_copy->ymin;
|
||||
ext->ymax = ext_copy->ymax;
|
||||
ext->hdiv_num = ext_copy->hdiv_num;
|
||||
ext->vdiv_num = ext_copy->vdiv_num;
|
||||
ext->pnum = ext_copy->pnum;
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_chart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the chart background
|
||||
* @param obj_dp pointer to a chart background object
|
||||
* @param chart pointer to a chart background object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_chart_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_rect_signal(obj_dp, sign, param);
|
||||
valid = lv_rect_signal(chart, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
cord_t ** datal;
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CLEANUP:
|
||||
LL_READ(ext_dp->dl_ll, datal) {
|
||||
LL_READ(ext->dl_ll, datal) {
|
||||
dm_free(*datal);
|
||||
}
|
||||
|
||||
ll_clear(&ext_dp->dl_ll);
|
||||
ll_clear(&ext->dl_ll);
|
||||
|
||||
break;
|
||||
default:
|
||||
@@ -137,35 +137,40 @@ bool lv_chart_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
return valid;
|
||||
}
|
||||
|
||||
cord_t * lv_chart_add_dataline(lv_obj_t* obj_dp)
|
||||
/**
|
||||
* Allocate and add a data line t the chart
|
||||
* @param chart pointer to a chart object
|
||||
* @return pointer to the allocated data lie (an array for the data points)
|
||||
*/
|
||||
cord_t * lv_chart_add_dataline(lv_obj_t * chart)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
cord_t ** dl_dp = ll_ins_head(&ext_dp->dl_ll);
|
||||
cord_t def = (ext_dp->ymax - ext_dp->ymin) >> 2; /*1/4 range as default value*/
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
cord_t ** dl = ll_ins_head(&ext->dl_ll);
|
||||
cord_t def = (ext->ymax - ext->ymin) >> 2; /*1/4 range as default value*/
|
||||
|
||||
if(dl_dp == NULL) return NULL;
|
||||
if(dl == NULL) return NULL;
|
||||
|
||||
*dl_dp = dm_alloc(sizeof(cord_t) * ext_dp->pnum);
|
||||
*dl = dm_alloc(sizeof(cord_t) * ext->pnum);
|
||||
|
||||
uint16_t i;
|
||||
cord_t * p_tmp = *dl_dp;
|
||||
for(i = 0; i < ext_dp->pnum; i++) {
|
||||
cord_t * p_tmp = *dl;
|
||||
for(i = 0; i < ext->pnum; i++) {
|
||||
*p_tmp = def;
|
||||
p_tmp++;
|
||||
}
|
||||
|
||||
ext_dp->dl_num++;
|
||||
ext->dl_num++;
|
||||
|
||||
return *dl_dp;
|
||||
return *dl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh a chart if its data line has changed
|
||||
* @param obj_dp pionter to chart object
|
||||
* @param chart pointer to chart object
|
||||
*/
|
||||
void lv_chart_refr(lv_obj_t * obj_dp)
|
||||
void lv_chart_refr(lv_obj_t * chart)
|
||||
{
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(chart);
|
||||
}
|
||||
/*=====================
|
||||
* Setter functions
|
||||
@@ -173,88 +178,88 @@ void lv_chart_refr(lv_obj_t * obj_dp)
|
||||
|
||||
/**
|
||||
* Set the number of horizontal and vertical division lines
|
||||
* @param obj_dp pointer to a graph background object
|
||||
* @param chart pointer to a graph background object
|
||||
* @param hdiv number of horizontal division lines
|
||||
* @param vdiv number of vertical division lines
|
||||
*/
|
||||
void lv_chart_set_hvdiv(lv_obj_t * obj_dp, uint8_t hdiv, uint8_t vdiv)
|
||||
void lv_chart_set_hvdiv(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
|
||||
ext_dp->hdiv_num = hdiv;
|
||||
ext_dp->vdiv_num = vdiv;
|
||||
ext->hdiv_num = hdiv;
|
||||
ext->vdiv_num = vdiv;
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimal and maximal x and y values
|
||||
* @param obj_dp pointer to a graph background object
|
||||
* @param chart pointer to a graph background object
|
||||
* @param xmin x minimum value
|
||||
* @param xmax x maximum value
|
||||
* @param ymin y minimum value
|
||||
* @param ymax y maximum value
|
||||
*/
|
||||
void lv_chart_set_range(lv_obj_t * obj_dp, cord_t ymin, cord_t ymax)
|
||||
void lv_chart_set_range(lv_obj_t * chart, cord_t ymin, cord_t ymax)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
|
||||
ext_dp->ymin = ymin;
|
||||
ext_dp->ymax = ymax;
|
||||
ext->ymin = ymin;
|
||||
ext->ymax = ymax;
|
||||
|
||||
lv_chart_refr(obj_dp);
|
||||
lv_chart_refr(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new type for a chart
|
||||
* @param obj_dp pointer to a chart object
|
||||
* @param type ew type of the chart (from 'lv_chart_type_t' enum)
|
||||
* @param chart pointer to a chart object
|
||||
* @param type new type of the chart (from 'lv_chart_type_t' enum)
|
||||
*/
|
||||
void lv_chart_set_type(lv_obj_t * obj_dp, lv_chart_type_t type)
|
||||
void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
ext_dp->type = type;
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
ext->type = type;
|
||||
|
||||
lv_chart_refr(obj_dp);
|
||||
lv_chart_refr(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of points on a data line on a chart
|
||||
* @param obj_dp pointer r to chart object
|
||||
* @param chart pointer r to chart object
|
||||
* @param pnum new number of points on the data lines
|
||||
*/
|
||||
void lv_chart_set_pnum(lv_obj_t * obj_dp, uint16_t pnum)
|
||||
void lv_chart_set_pnum(lv_obj_t * chart, uint16_t pnum)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
cord_t ** y_data;
|
||||
|
||||
if(pnum < 1) pnum = 1;
|
||||
|
||||
LL_READ_BACK(ext_dp->dl_ll, y_data) {
|
||||
LL_READ_BACK(ext->dl_ll, y_data) {
|
||||
*y_data = dm_realloc(*y_data, sizeof(cord_t) * pnum);
|
||||
}
|
||||
|
||||
ext_dp->pnum = pnum;
|
||||
lv_chart_refr(obj_dp);
|
||||
ext->pnum = pnum;
|
||||
lv_chart_refr(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift all data right and set the most right data on a data line
|
||||
* @param obj_dp pointer to chart object
|
||||
* @param dl_p pointer to a data line on 'obj_dp'
|
||||
* @param chart pointer to chart object
|
||||
* @param dl pointer to a data line on 'chart'
|
||||
* @param y the new value of the most right data
|
||||
*/
|
||||
void lv_chart_set_next(lv_obj_t * obj_dp, cord_t * dl_p, cord_t y)
|
||||
void lv_chart_set_next(lv_obj_t * chart, cord_t * dl, cord_t y)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; i < ext_dp->pnum - 1; i++) {
|
||||
dl_p[i] = dl_p[i + 1];
|
||||
for(i = 0; i < ext->pnum - 1; i++) {
|
||||
dl[i] = dl[i + 1];
|
||||
}
|
||||
|
||||
dl_p[ext_dp->pnum - 1] = y;
|
||||
lv_chart_refr(obj_dp);
|
||||
dl[ext->pnum - 1] = y;
|
||||
lv_chart_refr(chart);
|
||||
|
||||
}
|
||||
|
||||
@@ -265,10 +270,10 @@ void lv_chart_set_next(lv_obj_t * obj_dp, cord_t * dl_p, cord_t y)
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_charts_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_charts_t style
|
||||
*/
|
||||
lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy_p)
|
||||
lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -288,9 +293,9 @@ lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy_p)
|
||||
style_p = &lv_charts_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_charts_t));
|
||||
else memcpy(copy_p, &lv_charts_def, sizeof(lv_charts_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_charts_t));
|
||||
else memcpy(copy, &lv_charts_def, sizeof(lv_charts_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -298,26 +303,26 @@ lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy_p)
|
||||
|
||||
/**
|
||||
* Get the type of a chart
|
||||
* @param obj_dp pointer to chart object
|
||||
* @param chart pointer to chart object
|
||||
* @return type of the chart (from 'lv_chart_t' enum)
|
||||
*/
|
||||
lv_chart_type_t lv_chart_get_type(lv_obj_t * obj_dp)
|
||||
lv_chart_type_t lv_chart_get_type(lv_obj_t * chart)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
|
||||
return ext_dp->type;
|
||||
return ext->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data point number per data line on chart
|
||||
* @param obj_dp pointer to chart object
|
||||
* @param chart pointer to chart object
|
||||
* @return point number on each data line
|
||||
*/
|
||||
uint16_t lv_chart_get_pnum(lv_obj_t * obj_dp)
|
||||
uint16_t lv_chart_get_pnum(lv_obj_t * chart)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
|
||||
return ext_dp->pnum;
|
||||
return ext->pnum;
|
||||
}
|
||||
|
||||
/**********************
|
||||
@@ -327,7 +332,7 @@ uint16_t lv_chart_get_pnum(lv_obj_t * obj_dp)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the chart backgrounds
|
||||
* @param obj_dp pointer to an object
|
||||
* @param chart pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -335,30 +340,30 @@ uint16_t lv_chart_get_pnum(lv_obj_t * obj_dp)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_chart_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_chart_design(lv_obj_t * chart, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return ancestor_design_fp(obj_dp, mask_p, mode);
|
||||
return ancestor_design_fp(chart, mask, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
/*Draw the rectangle ancient*/
|
||||
ancestor_design_fp(obj_dp, mask_p, mode);
|
||||
ancestor_design_fp(chart, mask, mode);
|
||||
|
||||
/*Draw the object*/
|
||||
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
|
||||
lv_chart_draw_div(obj_dp, mask_p);
|
||||
lv_chart_draw_div(chart, mask);
|
||||
|
||||
switch(ext_dp->type) {
|
||||
switch(ext->type) {
|
||||
case LV_CHART_LINE:
|
||||
lv_chart_draw_lines(obj_dp, mask_p);
|
||||
lv_chart_draw_lines(chart, mask);
|
||||
break;
|
||||
case LV_CHART_COL:
|
||||
lv_chart_draw_cols(obj_dp, mask_p);
|
||||
lv_chart_draw_cols(chart, mask);
|
||||
break;
|
||||
case LV_CHART_POINT:
|
||||
lv_chart_draw_points(obj_dp, mask_p);
|
||||
lv_chart_draw_points(chart, mask);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -369,59 +374,58 @@ static bool lv_chart_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_m
|
||||
|
||||
/**
|
||||
* Draw the division lines on chart background
|
||||
* @param obj_dp pointer to chart object
|
||||
* @param mask_p mask, inherited from the design function
|
||||
* @param chart pointer to chart object
|
||||
* @param mask mask, inherited from the design function
|
||||
*/
|
||||
static void lv_chart_draw_div(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
static void lv_chart_draw_div(lv_obj_t * chart, const area_t * mask)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_charts_t * style_p = lv_obj_get_style(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
lv_charts_t * style = lv_obj_get_style(chart);
|
||||
|
||||
uint8_t div_i;
|
||||
point_t p1;
|
||||
point_t p2;
|
||||
cord_t w = lv_obj_get_width(obj_dp);
|
||||
cord_t h = lv_obj_get_height(obj_dp);
|
||||
opa_t div_opa = (uint16_t)lv_obj_get_opa(obj_dp) * style_p->div_line_opa / 100;
|
||||
cord_t x_ofs = lv_obj_get_x(obj_dp);
|
||||
cord_t y_ofs = lv_obj_get_y(obj_dp);
|
||||
cord_t w = lv_obj_get_width(chart);
|
||||
cord_t h = lv_obj_get_height(chart);
|
||||
opa_t div_opa = (uint16_t)lv_obj_get_opa(chart) * style->div_line_opa / 100;
|
||||
cord_t x_ofs = lv_obj_get_x(chart);
|
||||
cord_t y_ofs = lv_obj_get_y(chart);
|
||||
p1.x = 0 + x_ofs;
|
||||
p2.x = w + x_ofs;
|
||||
for(div_i = 1; div_i <= ext_dp->hdiv_num; div_i ++) {
|
||||
p1.y = (int32_t)((int32_t)h * div_i) / (ext_dp->hdiv_num + 1);
|
||||
for(div_i = 1; div_i <= ext->hdiv_num; div_i ++) {
|
||||
p1.y = (int32_t)((int32_t)h * div_i) / (ext->hdiv_num + 1);
|
||||
p1.y += y_ofs;
|
||||
p2.y = p1.y;
|
||||
lv_draw_line(&p1, &p2, mask_p, &style_p->div_lines, div_opa);
|
||||
lv_draw_line(&p1, &p2, mask, &style->div_line, div_opa);
|
||||
}
|
||||
|
||||
p1.y = 0 + y_ofs;
|
||||
p2.y = h + y_ofs;
|
||||
for(div_i = 1; div_i <= ext_dp->vdiv_num; div_i ++) {
|
||||
p1.x = (int32_t)((int32_t)w * div_i) / (ext_dp->vdiv_num + 1);
|
||||
for(div_i = 1; div_i <= ext->vdiv_num; div_i ++) {
|
||||
p1.x = (int32_t)((int32_t)w * div_i) / (ext->vdiv_num + 1);
|
||||
p1.x += x_ofs;
|
||||
p2.x = p1.x;
|
||||
lv_draw_line(&p1, &p2, mask_p, &style_p->div_lines, div_opa);
|
||||
lv_draw_line(&p1, &p2, mask, &style->div_line, div_opa);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the data lines as lines on a chart
|
||||
* @param obj_dp pointer to chart object
|
||||
* @param mask_p mask, inherited from the design function
|
||||
* @param obj pointer to chart object
|
||||
*/
|
||||
static void lv_chart_draw_lines(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_charts_t * style_p = lv_obj_get_style(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
lv_charts_t * style_p = lv_obj_get_style(chart);
|
||||
|
||||
uint8_t i;
|
||||
point_t p1;
|
||||
point_t p2;
|
||||
cord_t w = lv_obj_get_width(obj_dp);
|
||||
cord_t h = lv_obj_get_height(obj_dp);
|
||||
opa_t opa = (uint16_t)lv_obj_get_opa(obj_dp) * style_p->data_opa / 100;
|
||||
cord_t x_ofs = lv_obj_get_x(obj_dp);
|
||||
cord_t y_ofs = lv_obj_get_y(obj_dp);
|
||||
cord_t w = lv_obj_get_width(chart);
|
||||
cord_t h = lv_obj_get_height(chart);
|
||||
opa_t opa = (uint16_t)lv_obj_get_opa(chart) * style_p->data_opa / 100;
|
||||
cord_t x_ofs = lv_obj_get_x(chart);
|
||||
cord_t y_ofs = lv_obj_get_y(chart);
|
||||
int32_t y_tmp;
|
||||
cord_t ** y_data;
|
||||
uint8_t dl_cnt = 0;
|
||||
@@ -429,28 +433,27 @@ static void lv_chart_draw_lines(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
lv_lines_get(LV_LINES_CHART, &lines);
|
||||
|
||||
/*Go through all data lines*/
|
||||
LL_READ_BACK(ext_dp->dl_ll, y_data) {
|
||||
|
||||
LL_READ_BACK(ext->dl_ll, y_data) {
|
||||
lines.objs.color = style_p->color[dl_cnt];
|
||||
lines.width = style_p->width;
|
||||
|
||||
p1.x = 0 + x_ofs;
|
||||
p2.x = 0 + x_ofs;
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[0] - ext_dp->ymin) * h;
|
||||
y_tmp = y_tmp / (ext_dp->ymax - ext_dp->ymin);
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[0] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
p2.y = h - y_tmp + y_ofs;
|
||||
|
||||
for(i = 1; i < ext_dp->pnum; i ++) {
|
||||
for(i = 1; i < ext->pnum; i ++) {
|
||||
p1.x = p2.x;
|
||||
p1.y = p2.y;
|
||||
|
||||
p2.x = (w / (ext_dp->pnum - 1)) * i + x_ofs;
|
||||
p2.x = (w / (ext->pnum - 1)) * i + x_ofs;
|
||||
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext_dp->ymin) * h;
|
||||
y_tmp = y_tmp / (ext_dp->ymax - ext_dp->ymin);
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
p2.y = h - y_tmp + y_ofs;
|
||||
|
||||
lv_draw_line(&p1, &p2, mask_p, &lines, opa);
|
||||
lv_draw_line(&p1, &p2, mask, &lines, opa);
|
||||
}
|
||||
dl_cnt++;
|
||||
}
|
||||
@@ -458,21 +461,21 @@ static void lv_chart_draw_lines(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
|
||||
/**
|
||||
* Draw the data lines as points on a chart
|
||||
* @param obj_dp pointer to chart object
|
||||
* @param mask_p mask, inherited from the design function
|
||||
* @param chart pointer to chart object
|
||||
* @param mask mask, inherited from the design function
|
||||
*/
|
||||
static void lv_chart_draw_points(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_charts_t * style_p = lv_obj_get_style(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
lv_charts_t * style_p = lv_obj_get_style(chart);
|
||||
|
||||
uint8_t i;
|
||||
area_t cir_a;
|
||||
cord_t w = lv_obj_get_width(obj_dp);
|
||||
cord_t h = lv_obj_get_height(obj_dp);
|
||||
opa_t opa = (uint16_t)lv_obj_get_opa(obj_dp) * style_p->data_opa / 100;
|
||||
cord_t x_ofs = lv_obj_get_x(obj_dp);
|
||||
cord_t y_ofs = lv_obj_get_y(obj_dp);
|
||||
cord_t w = lv_obj_get_width(chart);
|
||||
cord_t h = lv_obj_get_height(chart);
|
||||
opa_t opa = (uint16_t)lv_obj_get_opa(chart) * style_p->data_opa / 100;
|
||||
cord_t x_ofs = lv_obj_get_x(chart);
|
||||
cord_t y_ofs = lv_obj_get_y(chart);
|
||||
int32_t y_tmp;
|
||||
cord_t ** y_data;
|
||||
uint8_t dl_cnt = 0;
|
||||
@@ -485,22 +488,22 @@ static void lv_chart_draw_points(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
rects.round = LV_RECT_CIRCLE;
|
||||
|
||||
/*Go through all data lines*/
|
||||
LL_READ_BACK(ext_dp->dl_ll, y_data) {
|
||||
LL_READ_BACK(ext->dl_ll, y_data) {
|
||||
rects.objs.color = style_p->color[dl_cnt];
|
||||
rects.gcolor = color_mix(COLOR_BLACK, style_p->color[dl_cnt], style_p->dark_eff);
|
||||
|
||||
for(i = 0; i < ext_dp->pnum; i ++) {
|
||||
cir_a.x1 = (w / (ext_dp->pnum - 1)) * i + x_ofs;
|
||||
for(i = 0; i < ext->pnum; i ++) {
|
||||
cir_a.x1 = (w / (ext->pnum - 1)) * i + x_ofs;
|
||||
cir_a.x2 = cir_a.x1 + rad;
|
||||
cir_a.x1 -= rad;
|
||||
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext_dp->ymin) * h;
|
||||
y_tmp = y_tmp / (ext_dp->ymax - ext_dp->ymin);
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[i] - 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 + rad;
|
||||
cir_a.y1 -= rad;
|
||||
|
||||
lv_draw_rect(&cir_a, mask_p, &rects, opa);
|
||||
lv_draw_rect(&cir_a, mask, &rects, opa);
|
||||
}
|
||||
dl_cnt++;
|
||||
}
|
||||
@@ -508,57 +511,57 @@ static void lv_chart_draw_points(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
|
||||
/**
|
||||
* Draw the data lines as columns on a chart
|
||||
* @param obj_dp pointer to chart object
|
||||
* @param mask_p mask, inherited from the design function
|
||||
* @param chart pointer to chart object
|
||||
* @param mask mask, inherited from the design function
|
||||
*/
|
||||
static void lv_chart_draw_cols(lv_obj_t* obj_dp, const area_t * mask_p)
|
||||
static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask)
|
||||
{
|
||||
lv_chart_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_charts_t * style_p = lv_obj_get_style(obj_dp);
|
||||
lv_chart_ext_t * ext = lv_obj_get_ext(chart);
|
||||
lv_charts_t * style_p = lv_obj_get_style(chart);
|
||||
|
||||
uint8_t i;
|
||||
area_t col_a;
|
||||
area_t col_mask;
|
||||
bool mask_ret;
|
||||
cord_t w = lv_obj_get_width(obj_dp);
|
||||
cord_t h = lv_obj_get_height(obj_dp);
|
||||
opa_t opa = (uint16_t)lv_obj_get_opa(obj_dp) * style_p->data_opa / 100;
|
||||
cord_t w = lv_obj_get_width(chart);
|
||||
cord_t h = lv_obj_get_height(chart);
|
||||
opa_t opa = (uint16_t)lv_obj_get_opa(chart) * style_p->data_opa / 100;
|
||||
int32_t y_tmp;
|
||||
cord_t ** y_data;
|
||||
uint8_t dl_cnt = 0;
|
||||
lv_rects_t rects;
|
||||
cord_t x_ofs = w / ((ext_dp->dl_num + 1) * ext_dp->pnum) / 2; /*Shift with a half col.*/
|
||||
cord_t x_ofs = w / ((ext->dl_num + 1) * ext->pnum) / 2; /*Shift with a half col.*/
|
||||
|
||||
lv_rects_get(LV_RECTS_DEF, &rects);
|
||||
rects.bwidth = 0;
|
||||
rects.empty = 0;
|
||||
rects.round = 0;
|
||||
|
||||
col_a.y2 = obj_dp->cords.y2;
|
||||
col_a.y2 = chart->cords.y2;
|
||||
|
||||
/*Go through all data lines*/
|
||||
LL_READ_BACK(ext_dp->dl_ll, y_data) {
|
||||
LL_READ_BACK(ext->dl_ll, y_data) {
|
||||
rects.objs.color = style_p->color[dl_cnt];
|
||||
rects.gcolor = color_mix(COLOR_BLACK, style_p->color[dl_cnt], style_p->dark_eff);
|
||||
|
||||
for(i = 0; i < ext_dp->pnum; i ++) {
|
||||
for(i = 0; i < ext->pnum; i ++) {
|
||||
/*Calculate the x coordinates. Suppose (dl_num + 1) * pnum columns */
|
||||
col_a.x1 = (int32_t)((int32_t)w * (i * (ext_dp->dl_num + 1) + dl_cnt)) /
|
||||
(ext_dp->pnum * (ext_dp->dl_num + 1)) + obj_dp->cords.x1;
|
||||
col_a.x2 = (int32_t)((int32_t)w * (i * (ext_dp->dl_num + 1) + dl_cnt + 1 )) /
|
||||
(ext_dp->pnum * (ext_dp->dl_num + 1)) + obj_dp->cords.x1 - 1;
|
||||
col_a.x1 = (int32_t)((int32_t)w * (i * (ext->dl_num + 1) + dl_cnt)) /
|
||||
(ext->pnum * (ext->dl_num + 1)) + chart->cords.x1;
|
||||
col_a.x2 = (int32_t)((int32_t)w * (i * (ext->dl_num + 1) + dl_cnt + 1 )) /
|
||||
(ext->pnum * (ext->dl_num + 1)) + chart->cords.x1 - 1;
|
||||
|
||||
col_a.x1 += x_ofs;
|
||||
col_a.x2 += x_ofs;
|
||||
|
||||
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext_dp->ymin) * h;
|
||||
y_tmp = y_tmp / (ext_dp->ymax - ext_dp->ymin);
|
||||
col_a.y1 = h - y_tmp + obj_dp->cords.y1;
|
||||
y_tmp = (int32_t)((int32_t) (*y_data)[i] - ext->ymin) * h;
|
||||
y_tmp = y_tmp / (ext->ymax - ext->ymin);
|
||||
col_a.y1 = h - y_tmp + chart->cords.y1;
|
||||
|
||||
mask_ret = area_union(&col_mask, mask_p, &col_a);
|
||||
mask_ret = area_union(&col_mask, mask, &col_a);
|
||||
if(mask_ret != false) {
|
||||
lv_draw_rect(&obj_dp->cords, &col_mask, &rects, opa);
|
||||
lv_draw_rect(&chart->cords, &col_mask, &rects, opa);
|
||||
}
|
||||
}
|
||||
dl_cnt++;
|
||||
@@ -572,15 +575,15 @@ static void lv_charts_init(void)
|
||||
{
|
||||
/*Default style*/
|
||||
/* Background */
|
||||
lv_rects_get(LV_RECTS_DEF, &lv_charts_def.bg_rects);
|
||||
lv_charts_def.bg_rects.objs.color = COLOR_MAKE(0x60, 0x80, 0xA0);
|
||||
lv_charts_def.bg_rects.gcolor = COLOR_WHITE;
|
||||
lv_charts_def.bg_rects.bcolor = COLOR_BLACK;
|
||||
lv_rects_get(LV_RECTS_DEF, &lv_charts_def.bg);
|
||||
lv_charts_def.bg.objs.color = COLOR_MAKE(0x60, 0x80, 0xA0);
|
||||
lv_charts_def.bg.gcolor = COLOR_WHITE;
|
||||
lv_charts_def.bg.bcolor = COLOR_BLACK;
|
||||
|
||||
/* Div. line */
|
||||
lv_lines_get(LV_LINES_DECOR, &lv_charts_def.div_lines);
|
||||
lv_charts_def.div_lines.width = 1 * LV_STYLE_MULT;
|
||||
lv_charts_def.div_lines.objs.color = COLOR_BLACK;
|
||||
lv_lines_get(LV_LINES_DECOR, &lv_charts_def.div_line);
|
||||
lv_charts_def.div_line.width = 1 * LV_STYLE_MULT;
|
||||
lv_charts_def.div_line.objs.color = COLOR_BLACK;
|
||||
lv_charts_def.div_line_opa = OPA_COVER;
|
||||
|
||||
/*Data lines*/
|
||||
|
||||
@@ -35,11 +35,12 @@ typedef enum
|
||||
/*Style of chart background*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rects_t bg_rects;
|
||||
lv_lines_t div_lines;
|
||||
lv_rects_t bg; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
lv_lines_t div_line;
|
||||
uint8_t div_line_opa; /*Percentage of obj. opacity*/
|
||||
color_t color[LV_CHART_DL_NUM]; /*Line/Point/Col color */
|
||||
uint16_t width; /*Line width or point radius*/
|
||||
uint16_t width; /*Line width or point radius*/
|
||||
opa_t data_opa; /*Line/Point/Col opacity in the percentage of obj. opacity*/
|
||||
uint8_t dark_eff; /*Dark effect on the bottom of ó points and columns*/
|
||||
}lv_charts_t;
|
||||
@@ -53,12 +54,12 @@ typedef enum
|
||||
/*Data of chart background*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rect_ext_t rect_ext;
|
||||
lv_rect_ext_t bg; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
cord_t ymin;
|
||||
cord_t ymax;
|
||||
uint8_t hdiv_num;
|
||||
uint8_t vdiv_num;
|
||||
|
||||
ll_dsc_t dl_ll; /*Linked list for the data line pointers (stores cord_t * )*/
|
||||
uint16_t pnum; /*Point number in a data line*/
|
||||
uint8_t type :2; /*Line, column or point chart*/
|
||||
@@ -68,22 +69,22 @@ typedef struct
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_chart_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_chart_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy_p);
|
||||
lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param);
|
||||
lv_charts_t * lv_charts_get(lv_charts_builtin_t style, lv_charts_t * copy);
|
||||
|
||||
cord_t * lv_chart_add_dataline(lv_obj_t* obj_dp);
|
||||
cord_t * lv_chart_add_dataline(lv_obj_t * chart);
|
||||
|
||||
void lv_chart_refr(lv_obj_t * obj_dp);
|
||||
void lv_chart_refr(lv_obj_t * chart);
|
||||
|
||||
void lv_chart_set_type(lv_obj_t * obj_dp, lv_chart_type_t type);
|
||||
void lv_chart_set_hvdiv(lv_obj_t * obj_dp, uint8_t hdiv, uint8_t vdiv);
|
||||
void lv_chart_set_range(lv_obj_t * obj_dp, cord_t ymin, cord_t ymax);
|
||||
void lv_chart_set_pnum(lv_obj_t * obj_dp, uint16_t pnum);
|
||||
void lv_chart_set_next(lv_obj_t * obj_dp, cord_t * dl_p, cord_t y);
|
||||
void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type);
|
||||
void lv_chart_set_hvdiv(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv);
|
||||
void lv_chart_set_range(lv_obj_t * chart, cord_t ymin, cord_t ymax);
|
||||
void lv_chart_set_pnum(lv_obj_t * chart, uint16_t pnum);
|
||||
void lv_chart_set_next(lv_obj_t * chart, cord_t * dl, cord_t y);
|
||||
|
||||
lv_chart_type_t lv_chart_get_type(lv_obj_t * obj_dp);
|
||||
uint16_t lv_chart_get_pnum(lv_obj_t * obj_dp);
|
||||
lv_chart_type_t lv_chart_get_type(lv_obj_t * chart);
|
||||
uint16_t lv_chart_get_pnum(lv_obj_t * chart);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
151
lv_objx/lv_img.c
151
lv_objx/lv_img.c
@@ -25,7 +25,7 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_imgs_init(void);
|
||||
|
||||
/**********************
|
||||
@@ -45,68 +45,67 @@ static lv_imgs_t lv_imgs_dark;
|
||||
|
||||
/**
|
||||
* Create an image objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new button
|
||||
* @param copy_dp pointer to a rectangle object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new button
|
||||
* @param copy pointer to a rectangle object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created image
|
||||
*/
|
||||
lv_obj_t* lv_img_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
lv_obj_t* new_obj_dp = NULL;
|
||||
lv_obj_t * new_img = NULL;
|
||||
|
||||
/*Create a basic object*/
|
||||
new_obj_dp = lv_obj_create(par_dp, NULL);
|
||||
new_img = lv_obj_create(par, NULL);
|
||||
|
||||
/*Extend the basic object to image object*/
|
||||
lv_obj_alloc_ext(new_obj_dp, sizeof(lv_img_ext_t));
|
||||
lv_obj_alloc_ext(new_img, sizeof(lv_img_ext_t));
|
||||
|
||||
/*Init the new object*/
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_img_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_img_design);
|
||||
lv_obj_set_signal_f(new_img, lv_img_signal);
|
||||
lv_obj_set_design_f(new_img, lv_img_design);
|
||||
|
||||
lv_img_ext_t * img_ext_dp = lv_obj_get_ext(new_obj_dp);
|
||||
lv_img_ext_t * img_ext = lv_obj_get_ext(new_img);
|
||||
|
||||
if(copy_dp == NULL) {
|
||||
img_ext_dp->fn_dp = NULL;
|
||||
img_ext_dp->w = lv_obj_get_width(new_obj_dp);
|
||||
img_ext_dp->h = lv_obj_get_height(new_obj_dp);
|
||||
img_ext_dp->transp = 0;
|
||||
if(copy == NULL) {
|
||||
img_ext->fn = NULL;
|
||||
img_ext->w = lv_obj_get_width(new_img);
|
||||
img_ext->h = lv_obj_get_height(new_img);
|
||||
img_ext->transp = 0;
|
||||
|
||||
/*Enable auto size for non screens*/
|
||||
if(par_dp != NULL) {
|
||||
img_ext_dp->auto_size = 1;
|
||||
if(par != NULL) {
|
||||
img_ext->auto_size = 1;
|
||||
} else {
|
||||
img_ext_dp->auto_size = 0;
|
||||
img_ext->auto_size = 0;
|
||||
}
|
||||
lv_obj_set_style(new_obj_dp, lv_imgs_get(LV_IMGS_DEF, NULL));
|
||||
lv_obj_set_style(new_img, lv_imgs_get(LV_IMGS_DEF, NULL));
|
||||
} else {
|
||||
img_ext_dp->auto_size = LV_EA(copy_dp, lv_img_ext_t)->auto_size;
|
||||
lv_img_set_file(new_obj_dp, LV_EA(copy_dp, lv_img_ext_t)->fn_dp);
|
||||
img_ext->auto_size = LV_EA(copy, lv_img_ext_t)->auto_size;
|
||||
lv_img_set_file(new_img, LV_EA(copy, lv_img_ext_t)->fn);
|
||||
}
|
||||
|
||||
|
||||
return new_obj_dp;
|
||||
return new_img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the image
|
||||
* @param obj_dp pointer to animage object
|
||||
* @param img pointer to animage object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_img_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid = true;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_obj_signal(obj_dp, sign, param);
|
||||
valid = lv_obj_signal(img, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_img_ext_t * img_p = lv_obj_get_ext(obj_dp);
|
||||
lv_img_ext_t * img_p = lv_obj_get_ext(img);
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CLEANUP:
|
||||
dm_free(img_p->fn_dp);
|
||||
dm_free(img_p->fn);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -119,10 +118,10 @@ bool lv_img_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
/**
|
||||
* Return with a pointer to built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_imgs_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_imgs_t style
|
||||
*/
|
||||
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy_p)
|
||||
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -148,9 +147,9 @@ lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy_p)
|
||||
style_p = &lv_imgs_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_imgs_t));
|
||||
else memcpy(copy_p, &lv_imgs_def, sizeof(lv_imgs_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_imgs_t));
|
||||
else memcpy(copy, &lv_imgs_def, sizeof(lv_imgs_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -159,14 +158,14 @@ lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy_p)
|
||||
/**
|
||||
* Create a file to the RAMFS from a picture data
|
||||
* @param fn file name of the new file (e.g. "pic1", will be available at "U:/pic1")
|
||||
* @param data_p pointer to a color map with lv_img_raw_header_t header
|
||||
* @param data pointer to a color map with lv_img_raw_header_t header
|
||||
* @return result of the file operation. FS_RES_OK or any error from fs_res_t
|
||||
*/
|
||||
fs_res_t lv_img_create_file(const char * fn, const color_int_t * data_p)
|
||||
fs_res_t lv_img_create_file(const char * fn, const color_int_t * data)
|
||||
{
|
||||
const lv_img_raw_header_t * raw_p = (lv_img_raw_header_t *) data_p;
|
||||
const lv_img_raw_header_t * raw_p = (lv_img_raw_header_t *) data;
|
||||
fs_res_t res;
|
||||
res = ufs_create_const(fn, data_p, raw_p->w * raw_p->h * sizeof(color_t));
|
||||
res = ufs_create_const(fn, data, raw_p->w * raw_p->h * sizeof(color_t));
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -177,12 +176,12 @@ fs_res_t lv_img_create_file(const char * fn, const color_int_t * data_p)
|
||||
|
||||
/**
|
||||
* Set a file to the image
|
||||
* @param obj_dp pointer to an image object
|
||||
* @param img pointer to an image object
|
||||
* @param fn file name in the RAMFS to set as picture (e.g. "U:/pic1").
|
||||
*/
|
||||
void lv_img_set_file(lv_obj_t* obj_dp, const char * fn)
|
||||
void lv_img_set_file(lv_obj_t * img, const char * fn)
|
||||
{
|
||||
lv_img_ext_t * img_ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_img_ext_t * ext = lv_obj_get_ext(img);
|
||||
|
||||
fs_file_t file;
|
||||
fs_res_t res;
|
||||
@@ -196,43 +195,43 @@ void lv_img_set_file(lv_obj_t* obj_dp, const char * fn)
|
||||
|
||||
if(res != FS_RES_OK || rn != sizeof(header)) {
|
||||
/*Create a dummy header*/
|
||||
header.w = lv_obj_get_width(obj_dp);
|
||||
header.h = lv_obj_get_height(obj_dp);
|
||||
header.w = lv_obj_get_width(img);
|
||||
header.h = lv_obj_get_height(img);
|
||||
header.transp = 0;
|
||||
}
|
||||
|
||||
fs_close(&file);
|
||||
|
||||
img_ext_p->w = header.w;
|
||||
img_ext_p->h = header.h;
|
||||
img_ext_p->transp = header.transp;
|
||||
ext->w = header.w;
|
||||
ext->h = header.h;
|
||||
ext->transp = header.transp;
|
||||
#if LV_UPSCALE_MAP != 0
|
||||
img_ext_p->w *= LV_DOWNSCALE;
|
||||
img_ext_p->h *= LV_DOWNSCALE;
|
||||
ext->w *= LV_DOWNSCALE;
|
||||
ext->h *= LV_DOWNSCALE;
|
||||
#endif
|
||||
if(fn != NULL) {
|
||||
img_ext_p->fn_dp = dm_realloc(img_ext_p->fn_dp, strlen(fn) + 1);
|
||||
strcpy(img_ext_p->fn_dp, fn);
|
||||
ext->fn = dm_realloc(ext->fn, strlen(fn) + 1);
|
||||
strcpy(ext->fn, fn);
|
||||
} else {
|
||||
img_ext_p->fn_dp = NULL;
|
||||
ext->fn = NULL;
|
||||
}
|
||||
|
||||
|
||||
if(lv_img_get_auto_size(obj_dp) != false) {
|
||||
lv_obj_set_size(obj_dp, img_ext_p->w, img_ext_p->h);
|
||||
if(lv_img_get_auto_size(img) != false) {
|
||||
lv_obj_set_size(img, ext->w, ext->h);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the auto size feature. If enabled the object size will be same as the picture size.
|
||||
* @param obj_dp pointer to an image
|
||||
* @param en true: auto size enable, false: auto size disable
|
||||
* Enable the auto size feature.
|
||||
* If enabled the object size will be same as the picture size.
|
||||
* @param img pointer to an image
|
||||
* @param autotosize true: auto size enable, false: auto size disable
|
||||
*/
|
||||
void lv_img_set_auto_size(lv_obj_t* obj_dp, bool en)
|
||||
void lv_img_set_auto_size(lv_obj_t * img, bool autotosize)
|
||||
{
|
||||
lv_img_ext_t * img_ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_img_ext_t * ext = lv_obj_get_ext(img);
|
||||
|
||||
img_ext_p->auto_size = (en == false ? 0 : 1);
|
||||
ext->auto_size = (autotosize == false ? 0 : 1);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -241,14 +240,14 @@ void lv_img_set_auto_size(lv_obj_t* obj_dp, bool en)
|
||||
|
||||
/**
|
||||
* Get the auto size enable attribute
|
||||
* @param obj_dp pinter to an image
|
||||
* @param img pointer to an image
|
||||
* @return true: auto size is enabled, false: auto size is disabled
|
||||
*/
|
||||
bool lv_img_get_auto_size(lv_obj_t* obj_dp)
|
||||
bool lv_img_get_auto_size(lv_obj_t * img)
|
||||
{
|
||||
lv_img_ext_t * img_ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_img_ext_t * ext = lv_obj_get_ext(img);
|
||||
|
||||
return img_ext_p->auto_size == 0 ? false : true;
|
||||
return ext->auto_size == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**********************
|
||||
@@ -257,7 +256,7 @@ bool lv_img_get_auto_size(lv_obj_t* obj_dp)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the images
|
||||
* @param obj_dp pointer to an object
|
||||
* @param img pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -265,33 +264,33 @@ bool lv_img_get_auto_size(lv_obj_t* obj_dp)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
lv_imgs_t * imgs_p = lv_obj_get_style(obj_dp);
|
||||
lv_img_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_imgs_t * imgs_p = lv_obj_get_style(img);
|
||||
lv_img_ext_t * ext = lv_obj_get_ext(img);
|
||||
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
if(ext_p->transp == 0) {
|
||||
if(ext->transp == 0) {
|
||||
bool cover;
|
||||
cover = area_is_in(mask_p, &obj_dp->cords);
|
||||
cover = area_is_in(mask, &img->cords);
|
||||
return cover;
|
||||
}
|
||||
else return false;
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
area_t cords;
|
||||
|
||||
lv_obj_get_cords(obj_dp, &cords);
|
||||
opa_t opa = lv_obj_get_opa(obj_dp);
|
||||
lv_obj_get_cords(img, &cords);
|
||||
opa_t opa = lv_obj_get_opa(img);
|
||||
|
||||
area_t cords_tmp;
|
||||
cords_tmp.y1 = cords.y1;
|
||||
cords_tmp.y2 = cords.y1 + ext_p->h - 1;
|
||||
cords_tmp.y2 = cords.y1 + ext->h - 1;
|
||||
|
||||
for(; cords_tmp.y1 < cords.y2; cords_tmp.y1 += ext_p->h, cords_tmp.y2 += ext_p->h) {
|
||||
for(; cords_tmp.y1 < cords.y2; cords_tmp.y1 += ext->h, cords_tmp.y2 += ext->h) {
|
||||
cords_tmp.x1 = cords.x1;
|
||||
cords_tmp.x2 = cords.x1 + ext_p->w - 1;
|
||||
for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += ext_p->w, cords_tmp.x2 += ext_p->w) {
|
||||
lv_draw_img(&cords_tmp, mask_p, imgs_p, opa, ext_p->fn_dp);
|
||||
cords_tmp.x2 = cords.x1 + ext->w - 1;
|
||||
for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) {
|
||||
lv_draw_img(&cords_tmp, mask, imgs_p, opa, ext->fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,26 +18,20 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_IMG_DECLARE(var_name) extern const color_int_t var_name[];
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Style of template*/
|
||||
typedef struct
|
||||
{
|
||||
lv_objs_t objs;
|
||||
lv_objs_t objs; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
opa_t recolor_opa;
|
||||
}lv_imgs_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* fn_dp;
|
||||
cord_t w;
|
||||
cord_t h;
|
||||
uint8_t auto_size :1;
|
||||
uint8_t transp :1; /*Transp. bit in the images header (library handles this)*/
|
||||
}lv_img_ext_t;
|
||||
|
||||
/*Built-in styles of template*/
|
||||
typedef enum
|
||||
{
|
||||
LV_IMGS_DEF,
|
||||
@@ -45,6 +39,19 @@ typedef enum
|
||||
LV_IMGS_DARK,
|
||||
}lv_imgs_builtin_t;
|
||||
|
||||
/*Data of template*/
|
||||
typedef struct
|
||||
{
|
||||
/*No ext. because inherited from the base object*/ /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
char* fn;
|
||||
cord_t w;
|
||||
cord_t h;
|
||||
uint8_t auto_size :1;
|
||||
uint8_t transp :1; /*Transp. bit in the images header (library handles this)*/
|
||||
}lv_img_ext_t;
|
||||
|
||||
/*Image header*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t w;
|
||||
@@ -58,20 +65,21 @@ typedef struct
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/*Create function*/
|
||||
lv_obj_t* lv_img_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
|
||||
bool lv_img_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
void lv_img_set_file(lv_obj_t* obj_p, const char * fn);
|
||||
bool lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param);
|
||||
void lv_img_set_file(lv_obj_t * img, const char * fn);
|
||||
fs_res_t lv_img_create_file(const char * fn, const color_int_t * data_p);
|
||||
void lv_img_set_auto_size(lv_obj_t* obj_dp, bool en);
|
||||
void lv_img_set_auto_size(lv_obj_t * img, bool autotosize);
|
||||
|
||||
bool lv_img_get_auto_size(lv_obj_t* obj_dp);
|
||||
bool lv_img_get_auto_size(lv_obj_t * img);
|
||||
|
||||
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy_p);
|
||||
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
#define LV_IMG_DECLARE(var_name) extern const color_int_t var_name[];
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_label_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_labels_init(void);
|
||||
|
||||
/**********************
|
||||
@@ -47,67 +47,67 @@ static lv_labels_t lv_labels_txt;
|
||||
|
||||
/**
|
||||
* Create a label objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new label
|
||||
* @param copy_dp pointer to a button object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new label
|
||||
* @param copy pointer to a button object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created button
|
||||
*/
|
||||
lv_obj_t* lv_label_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create a basic object*/
|
||||
lv_obj_t* new_obj = lv_obj_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj);
|
||||
lv_obj_t * new_label = lv_obj_create(par, copy);
|
||||
dm_assert(new_label);
|
||||
|
||||
/*Extend the basic object to a label object*/
|
||||
lv_obj_alloc_ext(new_obj, sizeof(lv_label_ext_t));
|
||||
lv_obj_alloc_ext(new_label, sizeof(lv_label_ext_t));
|
||||
|
||||
lv_label_ext_t * label_p = lv_obj_get_ext(new_obj);
|
||||
label_p->txt_dp = NULL;
|
||||
lv_label_ext_t * label_p = lv_obj_get_ext(new_label);
|
||||
label_p->txt = NULL;
|
||||
|
||||
lv_obj_set_design_f(new_obj, lv_label_design);
|
||||
lv_obj_set_signal_f(new_obj, lv_label_signal);
|
||||
lv_obj_set_design_f(new_label, lv_label_design);
|
||||
lv_obj_set_signal_f(new_label, lv_label_signal);
|
||||
|
||||
/*Init the new label*/
|
||||
if(copy_dp == NULL) {
|
||||
lv_obj_set_opa(new_obj, OPA_COVER);
|
||||
lv_obj_set_click(new_obj, false);
|
||||
lv_obj_set_style(new_obj, lv_labels_get(LV_LABELS_DEF, NULL));
|
||||
lv_label_set_fixw(new_obj, false);
|
||||
lv_label_set_text(new_obj, "Text");
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_opa(new_label, OPA_COVER);
|
||||
lv_obj_set_click(new_label, false);
|
||||
lv_obj_set_style(new_label, lv_labels_get(LV_LABELS_DEF, NULL));
|
||||
lv_label_set_fixw(new_label, false);
|
||||
lv_label_set_text(new_label, "Text");
|
||||
}
|
||||
/*Copy 'ori_dp' if not NULL*/
|
||||
/*Copy 'copy' if not NULL*/
|
||||
else {
|
||||
lv_label_set_fixw(new_obj, lv_label_get_fixw(copy_dp));
|
||||
lv_label_set_text(new_obj, lv_label_get_text(copy_dp));
|
||||
lv_label_set_fixw(new_label, lv_label_get_fixw(copy));
|
||||
lv_label_set_text(new_label, lv_label_get_text(copy));
|
||||
}
|
||||
return new_obj;
|
||||
return new_label;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signal function of the label
|
||||
* @param obj_dp pointer to a label object
|
||||
* @param label pointer to a label object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_label_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_obj_signal(obj_dp, sign, param);
|
||||
valid = lv_obj_signal(label, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_label_ext_t * label_p = lv_obj_get_ext(obj_dp);
|
||||
lv_label_ext_t * label_p = lv_obj_get_ext(label);
|
||||
/*No signal handling*/
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CLEANUP:
|
||||
dm_free(label_p->txt_dp);
|
||||
label_p->txt_dp = NULL;
|
||||
dm_free(label_p->txt);
|
||||
label_p->txt = NULL;
|
||||
break;
|
||||
case LV_SIGNAL_STYLE_CHG:
|
||||
lv_label_set_text(obj_dp, NULL);
|
||||
lv_label_set_text(label, NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -124,27 +124,26 @@ bool lv_label_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Set a new text for a label
|
||||
* @param obj_dp pointer to a label object
|
||||
* @param label pointer to a label object
|
||||
* @param text '\0' terminated character string. If NULL then refresh with the current text.
|
||||
*/
|
||||
void lv_label_set_text(lv_obj_t * obj_dp, const char * text)
|
||||
void lv_label_set_text(lv_obj_t * label, const char * text)
|
||||
{
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(label);
|
||||
|
||||
lv_label_ext_t * label_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
|
||||
if(text == label_ext_dp->txt_dp) text = NULL;
|
||||
if(text == ext->txt) text = NULL;
|
||||
|
||||
if(text != NULL) {
|
||||
uint32_t len = strlen(text) + 1;
|
||||
if(label_ext_dp->txt_dp != NULL) {
|
||||
dm_free(label_ext_dp->txt_dp);
|
||||
if(ext->txt != NULL) {
|
||||
dm_free(ext->txt);
|
||||
}
|
||||
label_ext_dp->txt_dp = dm_alloc(len);
|
||||
strcpy(label_ext_dp->txt_dp, text);
|
||||
ext->txt = dm_alloc(len);
|
||||
strcpy(ext->txt, text);
|
||||
} else {
|
||||
text = label_ext_dp->txt_dp;
|
||||
text = ext->txt;
|
||||
}
|
||||
|
||||
/*If 'text" still NULL then nothing to do: return*/
|
||||
@@ -152,30 +151,30 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text)
|
||||
|
||||
uint32_t line_start = 0;
|
||||
uint32_t new_line_start = 0;
|
||||
cord_t max_length = lv_obj_get_width(obj_dp);
|
||||
lv_labels_t * labels_p = lv_obj_get_style(obj_dp);
|
||||
const font_t * font_p = font_get(labels_p->font);
|
||||
uint8_t letter_height = font_get_height(font_p);
|
||||
cord_t max_length = lv_obj_get_width(label);
|
||||
lv_labels_t * labels = lv_obj_get_style(label);
|
||||
const font_t * font = font_get(labels->font);
|
||||
uint8_t letter_height = font_get_height(font);
|
||||
cord_t new_height = 0;
|
||||
cord_t longest_line = 0;
|
||||
cord_t act_line_length;
|
||||
|
||||
/*If the fix width is not enabled the set the max length to very big */
|
||||
if(label_ext_dp->fixw == 0) {
|
||||
if(ext->fixw == 0) {
|
||||
max_length = LV_CORD_MAX;
|
||||
}
|
||||
|
||||
/*Calc. the height and longest line*/;
|
||||
while (text[line_start] != '\0')
|
||||
{
|
||||
new_line_start += txt_get_next_line(&text[line_start], font_p, labels_p->letter_space, max_length);
|
||||
new_line_start += txt_get_next_line(&text[line_start], font, labels->letter_space, max_length);
|
||||
new_height += letter_height;
|
||||
new_height += labels_p->line_space;
|
||||
new_height += labels->line_space;
|
||||
|
||||
/*If no fix width then calc. the longest line */
|
||||
if(label_ext_dp->fixw == false) {
|
||||
if(ext->fixw == false) {
|
||||
act_line_length = txt_get_width(&text[line_start], new_line_start - line_start,
|
||||
font_p, labels_p->letter_space);
|
||||
font, labels->letter_space);
|
||||
if(act_line_length > longest_line) {
|
||||
longest_line = act_line_length;
|
||||
}
|
||||
@@ -185,29 +184,29 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text)
|
||||
}
|
||||
|
||||
/*Correction with the last line space*/
|
||||
new_height -= labels_p->line_space;
|
||||
new_height -= labels->line_space;
|
||||
|
||||
if(label_ext_dp->fixw == 0) {
|
||||
if(ext->fixw == 0) {
|
||||
/*Refresh the full size */
|
||||
lv_obj_set_size(obj_dp, longest_line, new_height);
|
||||
lv_obj_set_size(label, longest_line, new_height);
|
||||
} else {
|
||||
/*With fix width only the height can change*/
|
||||
lv_obj_set_height(obj_dp, new_height);
|
||||
lv_obj_set_height(label, new_height);
|
||||
}
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fix width attribute
|
||||
* If enabled the text will be automatically broken to fit to the size
|
||||
* @param obj_dp pointer to a label object
|
||||
* @param label pointer to a label object
|
||||
* @param fixw true: enable fix width for the label
|
||||
*/
|
||||
void lv_label_set_fixw(lv_obj_t * obj_dp, bool fixw)
|
||||
void lv_label_set_fixw(lv_obj_t * label, bool fixw)
|
||||
{
|
||||
lv_label_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
ext_p->fixw = fixw == false ? 0 : 1;
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
ext->fixw = fixw == false ? 0 : 1;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -216,56 +215,56 @@ void lv_label_set_fixw(lv_obj_t * obj_dp, bool fixw)
|
||||
|
||||
/**
|
||||
* Get the text of a label
|
||||
* @param obj_dp pointer to a label object
|
||||
* @param label pointer to a label object
|
||||
* @return the text of the label
|
||||
*/
|
||||
const char * lv_label_get_text(lv_obj_t* obj_dp)
|
||||
const char * lv_label_get_text(lv_obj_t * label)
|
||||
{
|
||||
lv_label_ext_t * label_p = lv_obj_get_ext(obj_dp);
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
|
||||
return label_p->txt_dp;
|
||||
return ext->txt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fix width attribute of a label
|
||||
* @param obj_dp pointer to a label object
|
||||
* @param label pointer to a label object
|
||||
* @return true: fix width is enabled
|
||||
*/
|
||||
bool lv_label_get_fixw(lv_obj_t * obj_dp)
|
||||
bool lv_label_get_fixw(lv_obj_t * label)
|
||||
{
|
||||
lv_label_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
return ext_p->fixw == 0 ? false: true;
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
return ext->fixw == 0 ? false: true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relative x and y coordinates of a letter
|
||||
* @param obj_dp pointer to a label object
|
||||
* @param label pointer to a label object
|
||||
* @param index index of the letter (0 ... text length)
|
||||
* @param pos_p store the result here (E.g. index = 0 gives 0;0 coordinates)
|
||||
* @param pos store the result here (E.g. index = 0 gives 0;0 coordinates)
|
||||
*/
|
||||
void lv_label_get_letter_pos(lv_obj_t * obj_dp, uint16_t index, point_t * pos_p)
|
||||
void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
|
||||
{
|
||||
const char * text = lv_label_get_text(obj_dp);
|
||||
lv_label_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
const char * text = lv_label_get_text(label);
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
uint32_t line_start = 0;
|
||||
uint32_t new_line_start = 0;
|
||||
cord_t max_length = lv_obj_get_width(obj_dp);
|
||||
lv_labels_t * labels_p = lv_obj_get_style(obj_dp);
|
||||
const font_t * font_p = font_get(labels_p->font);
|
||||
uint8_t letter_height = font_get_height(font_p);
|
||||
cord_t max_length = lv_obj_get_width(label);
|
||||
lv_labels_t * labels = lv_obj_get_style(label);
|
||||
const font_t * font = font_get(labels->font);
|
||||
uint8_t letter_height = font_get_height(font);
|
||||
cord_t y = 0;
|
||||
|
||||
/*If the fix width is not enabled the set the max length to very big */
|
||||
if(ext_p->fixw == 0) {
|
||||
if(ext->fixw == 0) {
|
||||
max_length = LV_CORD_MAX;
|
||||
}
|
||||
|
||||
/*Search the line of the index letter */;
|
||||
while (text[new_line_start] != '\0') {
|
||||
new_line_start += txt_get_next_line(&text[line_start], font_p, labels_p->letter_space, max_length);
|
||||
new_line_start += txt_get_next_line(&text[line_start], font, labels->letter_space, max_length);
|
||||
if(index < new_line_start || text[new_line_start] == '\0') break; /*The line of 'index' letter begins at 'line_start'*/
|
||||
|
||||
y += letter_height + labels_p->line_space;
|
||||
y += letter_height + labels->line_space;
|
||||
line_start = new_line_start;
|
||||
}
|
||||
|
||||
@@ -273,65 +272,65 @@ void lv_label_get_letter_pos(lv_obj_t * obj_dp, uint16_t index, point_t * pos_p)
|
||||
cord_t x = 0;
|
||||
uint32_t i;
|
||||
for(i = line_start; i < index; i++) {
|
||||
x += font_get_width(font_p, text[i]) + labels_p->letter_space;
|
||||
x += font_get_width(font, text[i]) + labels->letter_space;
|
||||
}
|
||||
|
||||
if(labels_p->mid != 0) {
|
||||
if(labels->mid != 0) {
|
||||
cord_t line_w;
|
||||
line_w = txt_get_width(&text[line_start], new_line_start - line_start,
|
||||
font_p, labels_p->letter_space);
|
||||
x += lv_obj_get_width(obj_dp) / 2 - line_w / 2;
|
||||
font, labels->letter_space);
|
||||
x += lv_obj_get_width(label) / 2 - line_w / 2;
|
||||
}
|
||||
|
||||
pos_p->x = x;
|
||||
pos_p->y = y;
|
||||
pos->x = x;
|
||||
pos->y = y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index of letter on a relative point of a label
|
||||
* @param obj_dp pointer to label object
|
||||
* @param pos_p pointer to point with coordinates on a the label
|
||||
* @param label pointer to label object
|
||||
* @param pos pointer to point with coordinates on a the label
|
||||
* @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter)
|
||||
*/
|
||||
uint16_t lv_label_get_letter_on(lv_obj_t * obj_dp, point_t * pos_p)
|
||||
uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
|
||||
{
|
||||
const char * text = lv_label_get_text(obj_dp);
|
||||
lv_label_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
const char * text = lv_label_get_text(label);
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
uint32_t line_start = 0;
|
||||
uint32_t new_line_start = 0;
|
||||
cord_t max_length = lv_obj_get_width(obj_dp);
|
||||
lv_labels_t * labels_p = lv_obj_get_style(obj_dp);
|
||||
const font_t * font_p = font_get(labels_p->font);
|
||||
uint8_t letter_height = font_get_height(font_p);
|
||||
cord_t max_length = lv_obj_get_width(label);
|
||||
lv_labels_t * labels = lv_obj_get_style(label);
|
||||
const font_t * font = font_get(labels->font);
|
||||
uint8_t letter_height = font_get_height(font);
|
||||
cord_t y = 0;
|
||||
|
||||
/*If the fix width is not enabled the set the max length to very big */
|
||||
if(ext_p->fixw == 0) {
|
||||
if(ext->fixw == 0) {
|
||||
max_length = LV_CORD_MAX;
|
||||
}
|
||||
|
||||
/*Search the line of the index letter */;
|
||||
while (text[line_start] != '\0') {
|
||||
new_line_start += txt_get_next_line(&text[line_start], font_p, labels_p->letter_space, max_length);
|
||||
if(pos_p->y <= y + letter_height + labels_p->line_space) break; /*The line is found ('line_start')*/
|
||||
y += letter_height + labels_p->line_space;
|
||||
new_line_start += txt_get_next_line(&text[line_start], font, labels->letter_space, max_length);
|
||||
if(pos->y <= y + letter_height + labels->line_space) break; /*The line is found ('line_start')*/
|
||||
y += letter_height + labels->line_space;
|
||||
line_start = new_line_start;
|
||||
}
|
||||
|
||||
/*Calculate the x coordinate*/
|
||||
cord_t x = 0;
|
||||
if(labels_p->mid != 0) {
|
||||
if(labels->mid != 0) {
|
||||
cord_t line_w;
|
||||
line_w = txt_get_width(&text[line_start], new_line_start - line_start,
|
||||
font_p, labels_p->letter_space);
|
||||
x += lv_obj_get_width(obj_dp) / 2 - line_w / 2;
|
||||
font, labels->letter_space);
|
||||
x += lv_obj_get_width(label) / 2 - line_w / 2;
|
||||
}
|
||||
|
||||
uint32_t i;
|
||||
for(i = line_start; i < new_line_start-1; i++) {
|
||||
x += font_get_width(font_p, text[i]) + labels_p->letter_space;
|
||||
if(pos_p->x < x) break;
|
||||
x += font_get_width(font, text[i]) + labels->letter_space;
|
||||
if(pos->x < x) break;
|
||||
|
||||
}
|
||||
|
||||
@@ -342,10 +341,10 @@ uint16_t lv_label_get_letter_on(lv_obj_t * obj_dp, point_t * pos_p)
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_labels_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_labels_t style
|
||||
*/
|
||||
lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p)
|
||||
lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -374,9 +373,9 @@ lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p)
|
||||
style_p = &lv_labels_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_labels_t));
|
||||
else memcpy(copy_p, &lv_labels_def, sizeof(lv_labels_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_labels_t));
|
||||
else memcpy(copy, &lv_labels_def, sizeof(lv_labels_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -389,7 +388,7 @@ lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the labels
|
||||
* @param obj_dp pointer to an object
|
||||
* @param label pointer to a label object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -397,19 +396,19 @@ lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_label_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
/* A label never covers an area */
|
||||
if(mode == LV_DESIGN_COVER_CHK) return false;
|
||||
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
/*TEST: draw a background for the label*/
|
||||
/*lv_vfill(&obj_dp->cords, mask_p, COLOR_LIME, OPA_COVER); */
|
||||
/*lv_vfill(&obj->cords, mask_p, COLOR_LIME, OPA_COVER); */
|
||||
|
||||
area_t cords;
|
||||
lv_obj_get_cords(obj_dp, &cords);
|
||||
opa_t opa= lv_obj_get_opa(obj_dp);
|
||||
const char * txt = lv_label_get_text(obj_dp);
|
||||
lv_draw_label(&cords, mask_p, lv_obj_get_style(obj_dp), opa, txt);
|
||||
lv_obj_get_cords(label, &cords);
|
||||
opa_t opa= lv_obj_get_opa(label);
|
||||
const char * txt = lv_label_get_text(label);
|
||||
lv_draw_label(&cords, mask, lv_obj_get_style(label), opa, txt);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,21 +23,18 @@
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Style of label*/
|
||||
typedef struct
|
||||
{
|
||||
lv_objs_t objs;
|
||||
lv_objs_t objs; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
font_types_t font;
|
||||
uint16_t letter_space;
|
||||
uint16_t line_space;
|
||||
uint8_t mid :1;
|
||||
}lv_labels_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * txt_dp;
|
||||
uint8_t fixw :1;
|
||||
}lv_label_ext_t;
|
||||
|
||||
/*Built-in styles of label*/
|
||||
typedef enum
|
||||
{
|
||||
LV_LABELS_DEF,
|
||||
@@ -45,24 +42,30 @@ typedef enum
|
||||
LV_LABELS_TXT,
|
||||
LV_LABELS_TITLE,
|
||||
}lv_labels_builtin_t;
|
||||
|
||||
/*Data of label*/
|
||||
typedef struct
|
||||
{
|
||||
/*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
char * txt;
|
||||
uint8_t fixw :1;
|
||||
}lv_label_ext_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/*Create function*/
|
||||
lv_obj_t* lv_label_create(lv_obj_t* par_dp, lv_obj_t * ori_dp);
|
||||
lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param);
|
||||
lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy);
|
||||
|
||||
bool lv_label_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
|
||||
|
||||
void lv_label_set_text(lv_obj_t* obj_dp, const char * text);
|
||||
void lv_label_set_fixw(lv_obj_t * obj_dp, bool fixw);
|
||||
const char * lv_label_get_text(lv_obj_t* obj_dp);
|
||||
bool lv_label_get_fixw(lv_obj_t * obj_dp);
|
||||
void lv_label_get_letter_pos(lv_obj_t * obj_dp, uint16_t index, point_t * pos_p);
|
||||
uint16_t lv_label_get_letter_on(lv_obj_t * obj_dp, point_t * pos_p);
|
||||
|
||||
lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p);
|
||||
void lv_label_set_text(lv_obj_t * label, const char * text);
|
||||
void lv_label_set_fixw(lv_obj_t * label, bool fixw);
|
||||
const char * lv_label_get_text(lv_obj_t * label);
|
||||
bool lv_label_get_fixw(lv_obj_t * label);
|
||||
void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos);
|
||||
uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
142
lv_objx/lv_led.c
142
lv_objx/lv_led.c
@@ -3,12 +3,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*Search an replace: led -> object normal name with lower case (e.g. button, label etc.)
|
||||
* led -> object short name with lower case(e.g. btn, label etc)
|
||||
* LED -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
@@ -33,7 +27,7 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_led_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_leds_init(void);
|
||||
|
||||
/**********************
|
||||
@@ -57,51 +51,51 @@ static lv_leds_t lv_leds_green;
|
||||
|
||||
/**
|
||||
* Create a led objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new led
|
||||
* @param copy_dp pointer to a led object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new led
|
||||
* @param copy pointer to a led object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created led
|
||||
*/
|
||||
lv_obj_t* lv_led_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor basic object*/
|
||||
lv_obj_t* new_obj_dp = lv_rect_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_led = lv_rect_create(par, copy);
|
||||
dm_assert(new_led);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_led_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_led_ext_t));
|
||||
dm_assert(ext_dp);
|
||||
lv_led_ext_t * ext = lv_obj_alloc_ext(new_led, sizeof(lv_led_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_led_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_led_design);
|
||||
lv_obj_set_signal_f(new_led, lv_led_signal);
|
||||
lv_obj_set_design_f(new_led, lv_led_design);
|
||||
|
||||
/*Init the new led object*/
|
||||
if(copy_dp == NULL) {
|
||||
ext_dp->bright = LV_LED_BRIGHTNESS_DEF;
|
||||
lv_obj_set_style(new_obj_dp, lv_leds_get(LV_LEDS_DEF, NULL));
|
||||
lv_obj_set_size_us(new_obj_dp, 40, 40);
|
||||
if(copy == NULL) {
|
||||
ext->bright = LV_LED_BRIGHTNESS_DEF;
|
||||
lv_obj_set_style(new_led, lv_leds_get(LV_LEDS_DEF, NULL));
|
||||
lv_obj_set_size_us(new_led, 40, 40);
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
lv_led_ext_t * copy_ext_p = lv_obj_get_ext(copy_dp);
|
||||
ext_dp->bright = copy_ext_p->bright;
|
||||
lv_led_ext_t * copy_ext = lv_obj_get_ext(copy);
|
||||
ext->bright = copy_ext->bright;
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_led;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the led
|
||||
* @param obj_dp pointer to a led object
|
||||
* @param led pointer to a led object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return true: the object is still valid (not deleted), false: the object become invalid
|
||||
*/
|
||||
bool lv_led_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_rect_signal(obj_dp, sign, param);
|
||||
valid = lv_rect_signal(led, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -124,47 +118,47 @@ bool lv_led_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Set the brightness of a LED object
|
||||
* @param obj_dp pointer to a LED object
|
||||
* @param led pointer to a LED object
|
||||
* @param bright 0 (max. dark) ... 255 (max. light)
|
||||
*/
|
||||
void lv_led_set_bright(lv_obj_t * obj_dp, uint8_t bright)
|
||||
void lv_led_set_bright(lv_obj_t * led, uint8_t bright)
|
||||
{
|
||||
/*Set the brightness*/
|
||||
lv_led_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
ext_dp->bright = bright;
|
||||
lv_led_ext_t * ext = lv_obj_get_ext(led);
|
||||
ext->bright = bright;
|
||||
|
||||
/*Invalidate the object there fore it will be redrawn*/
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(led);
|
||||
}
|
||||
|
||||
/**
|
||||
* Light on a LED
|
||||
* @param obj_dp pointer to a LED object
|
||||
* @param led pointer to a LED object
|
||||
*/
|
||||
void lv_led_on(lv_obj_t * obj_dp)
|
||||
void lv_led_on(lv_obj_t * led)
|
||||
{
|
||||
lv_led_set_bright(obj_dp, LV_LED_BRIGHTNESS_ON);
|
||||
lv_led_set_bright(led, LV_LED_BRIGHTNESS_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Light off a LED
|
||||
* @param obj_dp pointer to a LED object
|
||||
* @param led pointer to a LED object
|
||||
*/
|
||||
void lv_led_off(lv_obj_t * obj_dp)
|
||||
void lv_led_off(lv_obj_t * led)
|
||||
{
|
||||
lv_led_set_bright(obj_dp, LV_LED_BRIGHTNESS_OFF);
|
||||
lv_led_set_bright(led, LV_LED_BRIGHTNESS_OFF);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggle the state of a LED
|
||||
* @param obj_dp pointer to a LED object
|
||||
* @param led pointer to a LED object
|
||||
*/
|
||||
void lv_led_tgl(lv_obj_t * obj_dp)
|
||||
void lv_led_tgl(lv_obj_t * led)
|
||||
{
|
||||
uint8_t bright = lv_led_get_bright(obj_dp);
|
||||
if(bright > 60) lv_led_off(obj_dp);
|
||||
else lv_led_on(obj_dp);
|
||||
uint8_t bright = lv_led_get_bright(led);
|
||||
if(bright > 60) lv_led_off(led);
|
||||
else lv_led_on(led);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -173,22 +167,22 @@ void lv_led_tgl(lv_obj_t * obj_dp)
|
||||
|
||||
/**
|
||||
* Get the brightness of a LEd object
|
||||
* @param obj_dp pointer to LED object
|
||||
* @param led pointer to LED object
|
||||
* @return bright 0 (max. dark) ... 255 (max. light)
|
||||
*/
|
||||
uint8_t lv_led_get_bright(lv_obj_t * obj_dp)
|
||||
uint8_t lv_led_get_bright(lv_obj_t * led)
|
||||
{
|
||||
lv_led_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
return ext_dp->bright;
|
||||
lv_led_ext_t * ext = lv_obj_get_ext(led);
|
||||
return ext->bright;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_leds_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_leds_t style
|
||||
*/
|
||||
lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy_p)
|
||||
lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -212,9 +206,9 @@ lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy_p)
|
||||
style_p = &lv_leds_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_leds_t));
|
||||
else memcpy(copy_p, &lv_leds_def, sizeof(lv_leds_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_leds_t));
|
||||
else memcpy(copy, &lv_leds_def, sizeof(lv_leds_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -226,7 +220,7 @@ lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy_p)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the leds
|
||||
* @param obj_dp pointer to an object
|
||||
* @param led pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -234,27 +228,27 @@ lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_led_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return false;
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
/*Make darker colors in a temporary style according to the brightness*/
|
||||
lv_led_ext_t * led_ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_leds_t * leds_p = lv_obj_get_style(obj_dp);
|
||||
lv_led_ext_t * ext = lv_obj_get_ext(led);
|
||||
lv_leds_t * style = lv_obj_get_style(led);
|
||||
lv_leds_t leds_tmp;
|
||||
|
||||
memcpy(&leds_tmp, leds_p, sizeof(leds_tmp));
|
||||
memcpy(&leds_tmp, style, sizeof(leds_tmp));
|
||||
|
||||
leds_tmp.rects.objs.color = color_mix(leds_tmp.rects.objs.color, COLOR_BLACK, led_ext_p->bright);
|
||||
leds_tmp.rects.gcolor = color_mix(leds_tmp.rects.gcolor, COLOR_BLACK, led_ext_p->bright);
|
||||
leds_tmp.bg_rect.objs.color = color_mix(leds_tmp.bg_rect.objs.color, COLOR_BLACK, ext->bright);
|
||||
leds_tmp.bg_rect.gcolor = color_mix(leds_tmp.bg_rect.gcolor, COLOR_BLACK, ext->bright);
|
||||
|
||||
opa_t opa = lv_obj_get_opa(obj_dp);
|
||||
opa_t opa = lv_obj_get_opa(led);
|
||||
area_t area;
|
||||
lv_obj_get_cords(obj_dp, &area);
|
||||
lv_obj_get_cords(led, &area);
|
||||
|
||||
lv_draw_rect(&area, mask_p, &leds_tmp.rects, opa);
|
||||
lv_draw_rect(&area, mask, &leds_tmp.bg_rect, opa);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -265,22 +259,22 @@ static bool lv_led_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod
|
||||
static void lv_leds_init(void)
|
||||
{
|
||||
/*Default style*/
|
||||
lv_rects_get(LV_RECTS_DEF, &lv_leds_def.rects);
|
||||
lv_leds_def.rects.objs.color = COLOR_RED;
|
||||
lv_leds_def.rects.gcolor = COLOR_MARRON,
|
||||
lv_leds_def.rects.bcolor = COLOR_WHITE;
|
||||
lv_leds_def.rects.bwidth = 4 * LV_STYLE_MULT;
|
||||
lv_leds_def.rects.bopa = 50;
|
||||
lv_leds_def.rects.round = LV_RECT_CIRCLE;
|
||||
lv_leds_def.rects.hpad = 0;
|
||||
lv_leds_def.rects.vpad = 0;
|
||||
lv_leds_def.rects.opad = 0;
|
||||
lv_rects_get(LV_RECTS_DEF, &lv_leds_def.bg_rect);
|
||||
lv_leds_def.bg_rect.objs.color = COLOR_RED;
|
||||
lv_leds_def.bg_rect.gcolor = COLOR_MARRON,
|
||||
lv_leds_def.bg_rect.bcolor = COLOR_WHITE;
|
||||
lv_leds_def.bg_rect.bwidth = 4 * LV_STYLE_MULT;
|
||||
lv_leds_def.bg_rect.bopa = 50;
|
||||
lv_leds_def.bg_rect.round = LV_RECT_CIRCLE;
|
||||
lv_leds_def.bg_rect.hpad = 0;
|
||||
lv_leds_def.bg_rect.vpad = 0;
|
||||
lv_leds_def.bg_rect.opad = 0;
|
||||
|
||||
/* Green style */
|
||||
memcpy(&lv_leds_green, &lv_leds_def, sizeof(lv_leds_t));
|
||||
lv_leds_green.rects.objs.color = COLOR_LIME;
|
||||
lv_leds_green.rects.gcolor = COLOR_GREEN;
|
||||
lv_leds_green.rects.bcolor = COLOR_WHITE;
|
||||
lv_leds_green.bg_rect.objs.color = COLOR_LIME;
|
||||
lv_leds_green.bg_rect.gcolor = COLOR_GREEN;
|
||||
lv_leds_green.bg_rect.bcolor = COLOR_WHITE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,13 +3,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*Search an replace: led -> object normal name with lower case (e.g. button, label etc.)
|
||||
* led -> object short name with lower case(e.g. btn, label etc)
|
||||
* LED -> object short name with upper case (e.g. BTN, LABEL etc.)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_LED_H
|
||||
#define LV_LED_H
|
||||
|
||||
@@ -32,7 +25,7 @@
|
||||
/*Style of led*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rects_t rects;/*Style of ancestor*/
|
||||
lv_rects_t bg_rect;/*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
}lv_leds_t;
|
||||
|
||||
@@ -55,16 +48,16 @@ typedef struct
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_led_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_led_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy_p);
|
||||
lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_led_signal(lv_obj_t * led, lv_signal_t sign, void * param);
|
||||
lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy);
|
||||
|
||||
void lv_led_set_bright(lv_obj_t * obj_dp, uint8_t bright);
|
||||
uint8_t lv_led_get_bright(lv_obj_t * obj_dp);
|
||||
void lv_led_set_bright(lv_obj_t * led, uint8_t bright);
|
||||
uint8_t lv_led_get_bright(lv_obj_t * led);
|
||||
|
||||
void lv_led_on(lv_obj_t * obj_dp);
|
||||
void lv_led_off(lv_obj_t * obj_dp);
|
||||
void lv_led_tgl(lv_obj_t * obj_dp);
|
||||
void lv_led_on(lv_obj_t * led);
|
||||
void lv_led_off(lv_obj_t * led);
|
||||
void lv_led_tgl(lv_obj_t * led);
|
||||
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_line_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_lines_init(void);
|
||||
|
||||
/**********************
|
||||
@@ -53,55 +53,55 @@ static lv_lines_t lv_lines_chart;
|
||||
|
||||
/**
|
||||
* Create a line objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new line
|
||||
* @param par pointer to an object, it will be the parent of the new line
|
||||
* @return pointer to the created line
|
||||
*/
|
||||
lv_obj_t* lv_line_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create a basic object*/
|
||||
lv_obj_t* new_obj_dp = lv_obj_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_line = lv_obj_create(par, copy);
|
||||
dm_assert(new_line);
|
||||
|
||||
/*Extend the basic object to rectangle object*/
|
||||
lv_line_ext_t *ext_p = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_line_ext_t));
|
||||
lv_obj_set_design_f(new_obj_dp, lv_line_design);
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_line_signal);
|
||||
lv_line_ext_t * ext = lv_obj_alloc_ext(new_line, sizeof(lv_line_ext_t));
|
||||
lv_obj_set_design_f(new_line, lv_line_design);
|
||||
lv_obj_set_signal_f(new_line, lv_line_signal);
|
||||
|
||||
/*Init the new rectangle*/
|
||||
if(copy_dp == NULL) {
|
||||
ext_p->point_num = 0;
|
||||
ext_p->point_p = NULL;
|
||||
ext_p->auto_size = 1;
|
||||
ext_p->y_inv = 0;
|
||||
ext_p->upscale = 0;
|
||||
lv_obj_set_style(new_obj_dp, lv_lines_get(LV_LINES_DEF, NULL));
|
||||
if(copy == NULL) {
|
||||
ext->point_num = 0;
|
||||
ext->point_p = NULL;
|
||||
ext->auto_size = 1;
|
||||
ext->y_inv = 0;
|
||||
ext->upscale = 0;
|
||||
lv_obj_set_style(new_line, lv_lines_get(LV_LINES_DEF, NULL));
|
||||
}
|
||||
/*Copy 'copy_p' is not NULL*/
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
lv_line_set_auto_size(new_obj_dp,lv_line_get_auto_size(copy_dp));
|
||||
lv_line_set_y_inv(new_obj_dp,lv_line_get_y_inv(copy_dp));
|
||||
lv_line_set_auto_size(new_obj_dp,lv_line_get_auto_size(copy_dp));
|
||||
lv_line_set_upscale(new_obj_dp,lv_line_get_upscale(copy_dp));
|
||||
lv_line_set_points(new_obj_dp, LV_EA(copy_dp, lv_line_ext_t)->point_p,
|
||||
LV_EA(copy_dp, lv_line_ext_t)->point_num);
|
||||
lv_line_set_auto_size(new_line,lv_line_get_auto_size(copy));
|
||||
lv_line_set_y_inv(new_line,lv_line_get_y_inv(copy));
|
||||
lv_line_set_auto_size(new_line,lv_line_get_auto_size(copy));
|
||||
lv_line_set_upscale(new_line,lv_line_get_upscale(copy));
|
||||
lv_line_set_points(new_line, LV_EA(copy, lv_line_ext_t)->point_p,
|
||||
LV_EA(copy, lv_line_ext_t)->point_num);
|
||||
}
|
||||
|
||||
|
||||
return new_obj_dp;
|
||||
return new_line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the line
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param line pointer to a line object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_line_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_obj_signal(obj_dp, sign, param);
|
||||
valid = lv_obj_signal(line, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -121,23 +121,23 @@ bool lv_line_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Set an array of points. The line object will connect these points.
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param line pointer to a line object
|
||||
* @param point_a an array of points. Only the address is saved,
|
||||
* so the array can be a local variable which will be destroyed
|
||||
* @param point_num number of points in 'point_a'
|
||||
*/
|
||||
void lv_line_set_points(lv_obj_t* obj_dp, const point_t * point_a, uint16_t point_num)
|
||||
void lv_line_set_points(lv_obj_t * line, const point_t * point_a, uint16_t point_num)
|
||||
{
|
||||
lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
ext_p->point_p = point_a;
|
||||
ext_p->point_num = point_num;
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
ext->point_p = point_a;
|
||||
ext->point_num = point_num;
|
||||
|
||||
uint8_t us = 1;
|
||||
if(ext_p->upscale != 0) {
|
||||
if(ext->upscale != 0) {
|
||||
us = LV_DOWNSCALE;
|
||||
}
|
||||
|
||||
if(point_num > 0 && ext_p->auto_size != 0) {
|
||||
if(point_num > 0 && ext->auto_size != 0) {
|
||||
uint16_t i;
|
||||
cord_t xmax = LV_CORD_MIN;
|
||||
cord_t ymax = LV_CORD_MIN;
|
||||
@@ -146,26 +146,26 @@ void lv_line_set_points(lv_obj_t* obj_dp, const point_t * point_a, uint16_t poin
|
||||
ymax = max(point_a[i].y * us, ymax);
|
||||
}
|
||||
|
||||
lv_lines_t * lines_p = lv_obj_get_style(obj_dp);
|
||||
lv_obj_set_size(obj_dp, xmax + lines_p->width, ymax + lines_p->width);
|
||||
lv_lines_t * lines = lv_obj_get_style(line);
|
||||
lv_obj_set_size(line, xmax + lines->width, ymax + lines->width);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable (or disable) the auto-size option. The size of the object will fit to its points.
|
||||
* (set width to x max and height to y max)
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param en true: auto size is enabled, false: auto size is disabled
|
||||
* @param line pointer to a line object
|
||||
* @param autosize true: auto size is enabled, false: auto size is disabled
|
||||
*/
|
||||
void lv_line_set_auto_size(lv_obj_t * obj_dp, bool en)
|
||||
void lv_line_set_auto_size(lv_obj_t * line, bool autosize)
|
||||
{
|
||||
lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp);
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
|
||||
line_p->auto_size = en == false ? 0 : 1;
|
||||
ext->auto_size = autosize == false ? 0 : 1;
|
||||
|
||||
/*Refresh the object*/
|
||||
if(en != false) {
|
||||
lv_line_set_points(obj_dp, line_p->point_p, line_p->point_num);
|
||||
if(autosize != false) {
|
||||
lv_line_set_points(line, ext->point_p, ext->point_num);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,31 +173,31 @@ void lv_line_set_auto_size(lv_obj_t * obj_dp, bool en)
|
||||
* Enable (or disable) the y coordinate inversion.
|
||||
* If enabled then y will be subtracted from the height of the object,
|
||||
* therefore the y=0 coordinate will be on the bottom.
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param en true: enable the y inversion, false:disable the y inversion
|
||||
* @param line pointer to a line object
|
||||
* @param yinv true: enable the y inversion, false:disable the y inversion
|
||||
*/
|
||||
void lv_line_set_y_inv(lv_obj_t * obj_dp, bool en)
|
||||
void lv_line_set_y_inv(lv_obj_t * line, bool yinv)
|
||||
{
|
||||
lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp);
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
|
||||
line_p->y_inv = en == false ? 0 : 1;
|
||||
ext->y_inv = yinv == false ? 0 : 1;
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(line);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable (or disable) the point coordinate upscaling (compensate LV_DOWNSCALE).
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param en true: enable the point coordinate upscaling
|
||||
* @param line pointer to a line object
|
||||
* @param unscale true: enable the point coordinate upscaling
|
||||
*/
|
||||
void lv_line_set_upscale(lv_obj_t * obj_dp, bool en)
|
||||
void lv_line_set_upscale(lv_obj_t * line, bool unscale)
|
||||
{
|
||||
lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
|
||||
ext_p->upscale = en == false ? 0 : 1;
|
||||
ext->upscale = unscale == false ? 0 : 1;
|
||||
|
||||
/*Refresh to point to handle auto size*/
|
||||
lv_line_set_points(obj_dp, ext_p->point_p, ext_p->point_num);
|
||||
lv_line_set_points(line, ext->point_p, ext->point_num);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -206,47 +206,47 @@ void lv_line_set_upscale(lv_obj_t * obj_dp, bool en)
|
||||
|
||||
/**
|
||||
* Get the auto size attribute
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param line pointer to a line object
|
||||
* @return true: auto size is enabled, false: disabled
|
||||
*/
|
||||
bool lv_line_get_auto_size(lv_obj_t * obj_dp)
|
||||
bool lv_line_get_auto_size(lv_obj_t * line)
|
||||
{
|
||||
lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp);
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
|
||||
return line_p->auto_size == 0 ? false : true;
|
||||
return ext->auto_size == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the y inversion attribute
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param line pointer to a line object
|
||||
* @return true: y inversion is enabled, false: disabled
|
||||
*/
|
||||
bool lv_line_get_y_inv(lv_obj_t * obj_dp)
|
||||
bool lv_line_get_y_inv(lv_obj_t * line)
|
||||
{
|
||||
lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp);
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
|
||||
return line_p->y_inv == 0 ? false : true;
|
||||
return ext->y_inv == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the point upscale enable attribute
|
||||
* @param obj_dp pointer to a line object
|
||||
* @param obj pointer to a line object
|
||||
* @return true: point coordinate upscale is enabled, false: disabled
|
||||
*/
|
||||
bool lv_line_get_upscale(lv_obj_t * obj_dp)
|
||||
bool lv_line_get_upscale(lv_obj_t * line)
|
||||
{
|
||||
lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
|
||||
return ext_p->upscale == 0 ? false : true;
|
||||
return ext->upscale == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_lines_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_lines_t style
|
||||
*/
|
||||
lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy_p)
|
||||
lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -272,9 +272,9 @@ lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy_p)
|
||||
style_p = &lv_lines_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_lines_t));
|
||||
else memcpy(copy_p, &lv_lines_def, sizeof(lv_lines_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_lines_t));
|
||||
else memcpy(copy, &lv_lines_def, sizeof(lv_lines_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -285,7 +285,7 @@ lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy_p)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the lines
|
||||
* @param obj_dp pointer to an object
|
||||
* @param line pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -293,45 +293,45 @@ lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_line_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_line_design(lv_obj_t * line, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
/*A line never covers an area*/
|
||||
if(mode == LV_DESIGN_COVER_CHK) return false;
|
||||
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_line_ext_t * ext = lv_obj_get_ext(line);
|
||||
|
||||
if(ext_p->point_num == 0 || ext_p->point_p == NULL) return false;
|
||||
if(ext->point_num == 0 || ext->point_p == NULL) return false;
|
||||
|
||||
lv_lines_t * lines_p = lv_obj_get_style(obj_dp);
|
||||
lv_lines_t * lines = lv_obj_get_style(line);
|
||||
|
||||
opa_t opa = lv_obj_get_opa(obj_dp);
|
||||
opa_t opa = lv_obj_get_opa(line);
|
||||
area_t area;
|
||||
lv_obj_get_cords(obj_dp, &area);
|
||||
lv_obj_get_cords(line, &area);
|
||||
cord_t x_ofs = area.x1;
|
||||
cord_t y_ofs = area.y1;
|
||||
point_t p1;
|
||||
point_t p2;
|
||||
cord_t h = lv_obj_get_height(obj_dp);
|
||||
cord_t h = lv_obj_get_height(line);
|
||||
uint16_t i;
|
||||
uint8_t us = 1;
|
||||
if(ext_p->upscale != 0) {
|
||||
if(ext->upscale != 0) {
|
||||
us = LV_DOWNSCALE;
|
||||
}
|
||||
|
||||
/*Read all pints and draw the lines*/
|
||||
for (i = 0; i < ext_p->point_num - 1; i++) {
|
||||
for (i = 0; i < ext->point_num - 1; i++) {
|
||||
|
||||
p1.x = ext_p->point_p[i].x * us + x_ofs;
|
||||
p2.x = ext_p->point_p[i + 1].x * us + x_ofs;
|
||||
p1.x = ext->point_p[i].x * us + x_ofs;
|
||||
p2.x = ext->point_p[i + 1].x * us + x_ofs;
|
||||
|
||||
if(ext_p->y_inv == 0) {
|
||||
p1.y = ext_p->point_p[i].y * us + y_ofs;
|
||||
p2.y = ext_p->point_p[i + 1].y * us + y_ofs;
|
||||
if(ext->y_inv == 0) {
|
||||
p1.y = ext->point_p[i].y * us + y_ofs;
|
||||
p2.y = ext->point_p[i + 1].y * us + y_ofs;
|
||||
} else {
|
||||
p1.y = h - ext_p->point_p[i].y * us + y_ofs;
|
||||
p2.y = h - ext_p->point_p[i + 1].y * us + y_ofs;
|
||||
p1.y = h - ext->point_p[i].y * us + y_ofs;
|
||||
p2.y = h - ext->point_p[i + 1].y * us + y_ofs;
|
||||
}
|
||||
lv_draw_line(&p1, &p2, mask_p, lines_p, opa);
|
||||
lv_draw_line(&p1, &p2, mask, lines, opa);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -21,21 +21,15 @@
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
/*Style of line*/
|
||||
typedef struct
|
||||
{
|
||||
const point_t * point_p;
|
||||
uint16_t point_num;
|
||||
uint8_t auto_size :1;
|
||||
uint8_t y_inv :1;
|
||||
uint8_t upscale :1;
|
||||
}lv_line_ext_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
lv_objs_t objs;
|
||||
lv_objs_t objs; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
uint16_t width;
|
||||
}lv_lines_t;
|
||||
|
||||
/*Built-in styles of line*/
|
||||
typedef enum
|
||||
{
|
||||
LV_LINES_DEF,
|
||||
@@ -43,19 +37,30 @@ typedef enum
|
||||
LV_LINES_CHART,
|
||||
}lv_lines_builtin_t;
|
||||
|
||||
/*Data of line*/
|
||||
typedef struct
|
||||
{
|
||||
/*Inherited from 'base_obj' so inherited ext.*/ /*Ext. of ancestor*/
|
||||
const point_t * point_array;
|
||||
uint16_t point_num;
|
||||
uint8_t auto_size :1;
|
||||
uint8_t y_inv :1;
|
||||
uint8_t upscale :1;
|
||||
}lv_line_ext_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_line_create(lv_obj_t * par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_line_signal(lv_obj_t * obj_dp, lv_signal_t sign, void * param);
|
||||
lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy_p);
|
||||
void lv_line_set_points(lv_obj_t * obj_dp, const point_t * point_a, uint16_t point_num);
|
||||
void lv_line_set_auto_size(lv_obj_t * obj_dp, bool en);
|
||||
void lv_line_set_y_inv(lv_obj_t * obj_dp, bool en);
|
||||
void lv_line_set_upscale(lv_obj_t * obj_dp, bool en);
|
||||
bool lv_line_get_auto_size(lv_obj_t * obj_dp);
|
||||
bool lv_line_get_y_inv(lv_obj_t * obj_dp);
|
||||
bool lv_line_get_upscale(lv_obj_t * obj_dp);
|
||||
lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param);
|
||||
lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy);
|
||||
void lv_line_set_points(lv_obj_t * line, const point_t * point_a, uint16_t point_num);
|
||||
void lv_line_set_auto_size(lv_obj_t * line, bool autosize);
|
||||
void lv_line_set_y_inv(lv_obj_t * line, bool yinv);
|
||||
void lv_line_set_upscale(lv_obj_t * line, bool unscale);
|
||||
bool lv_line_get_auto_size(lv_obj_t * line);
|
||||
bool lv_line_get_y_inv(lv_obj_t * line);
|
||||
bool lv_line_get_upscale(lv_obj_t * line);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
#if 0
|
||||
static bool lv_list_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_t mode);
|
||||
#endif
|
||||
static void lv_lists_init(void);
|
||||
|
||||
@@ -50,45 +50,45 @@ static lv_lists_t lv_lists_tight;
|
||||
|
||||
/**
|
||||
* Create a list objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new list
|
||||
* @param copy_dp pointer to a list object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new list
|
||||
* @param copy pointer to a list object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created list
|
||||
*/
|
||||
lv_obj_t* lv_list_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor basic object*/
|
||||
lv_obj_t * new_obj_dp = lv_page_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_list_ext_t * ext_p= lv_obj_alloc_ext(new_obj_dp, sizeof(lv_list_ext_t));
|
||||
lv_obj_t * new_list = lv_page_create(par, copy);
|
||||
dm_assert(new_list);
|
||||
lv_list_ext_t * ext = lv_obj_alloc_ext(new_list, sizeof(lv_list_ext_t));
|
||||
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_list_signal);
|
||||
lv_obj_set_signal_f(new_list, lv_list_signal);
|
||||
|
||||
/*Init the new list object*/
|
||||
if(copy_dp == NULL) {
|
||||
ext_p->fit = LV_LIST_FIT_LONGEST;
|
||||
lv_obj_set_size_us(new_obj_dp, 100, 150);
|
||||
lv_obj_set_style(new_obj_dp, lv_lists_get(LV_LISTS_DEF, NULL));
|
||||
lv_rect_set_layout(LV_EA(new_obj_dp, lv_list_ext_t)->page_ext.scrolling_dp, LV_LIST_LAYOUT_DEF);
|
||||
if(copy == NULL) {
|
||||
ext ->fit = LV_LIST_FIT_LONGEST;
|
||||
lv_obj_set_size_us(new_list, 100, 150);
|
||||
lv_obj_set_style(new_list, lv_lists_get(LV_LISTS_DEF, NULL));
|
||||
lv_rect_set_layout(LV_EA(new_list, lv_list_ext_t)->page_ext.scrolling, LV_LIST_LAYOUT_DEF);
|
||||
} else {
|
||||
lv_list_ext_t * copy_ext_dp = lv_obj_get_ext(copy_dp);
|
||||
ext_p->fit = copy_ext_dp->fit;
|
||||
lv_list_ext_t * copy_ext = lv_obj_get_ext(copy);
|
||||
ext ->fit = copy_ext->fit;
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the list
|
||||
* @param obj_dp pointer to a list object
|
||||
* @param list pointer to a list object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_list_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_page_signal(obj_dp, sign, param);
|
||||
valid = lv_page_signal(list, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -104,48 +104,48 @@ bool lv_list_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Add a list element to the list
|
||||
* @param obj_dp pointer to list object
|
||||
* @param list pointer to list object
|
||||
* @param img_fn file name of an image before the text (NULL if unused)
|
||||
* @param txt text of the list element (NULL if unused)
|
||||
* @param rel_action pointer to release action function (like with lv_btn)
|
||||
* @return pointer to the new list element which can be customized (a button)
|
||||
*/
|
||||
lv_obj_t * lv_list_add(lv_obj_t * obj_dp, const char * img_fn, const char * txt, bool (*rel_action)(lv_obj_t*, lv_dispi_t *))
|
||||
lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, bool (*rel_action)(lv_obj_t *, lv_dispi_t *))
|
||||
{
|
||||
lv_lists_t * lists_p = lv_obj_get_style(obj_dp);
|
||||
lv_list_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_lists_t * lists = lv_obj_get_style(list);
|
||||
lv_list_ext_t * ext = lv_obj_get_ext(list);
|
||||
|
||||
/*Create a list element with the image an the text*/
|
||||
lv_obj_t * liste;
|
||||
liste = lv_btn_create(obj_dp, NULL);
|
||||
lv_obj_set_style(liste, &lists_p->liste_btns);
|
||||
liste = lv_btn_create(list, NULL);
|
||||
lv_obj_set_style(liste, &lists->liste_btn);
|
||||
lv_btn_set_rel_action(liste, rel_action);
|
||||
lv_page_glue_obj(liste, true);
|
||||
lv_rect_set_layout(liste, lists_p->liste_layout);
|
||||
lv_rect_set_layout(liste, lists->liste_layout);
|
||||
lv_rect_set_fit(liste, true, true); /*hor. fit might be disabled later*/
|
||||
|
||||
if(img_fn != NULL) {
|
||||
lv_obj_t * img = lv_img_create(liste, NULL);
|
||||
lv_img_set_file(img, img_fn);
|
||||
lv_obj_set_style(img, &lists_p->liste_imgs);
|
||||
lv_obj_set_style(img, &lists->liste_img);
|
||||
lv_obj_set_click(img, false);
|
||||
}
|
||||
|
||||
if(txt != NULL) {
|
||||
lv_obj_t * label = lv_label_create(liste, NULL);
|
||||
lv_label_set_text(label, txt);
|
||||
lv_obj_set_style(label,&lists_p->liste_labels);
|
||||
lv_obj_set_style(label,&lists->liste_label);
|
||||
lv_obj_set_click(label, false);
|
||||
}
|
||||
|
||||
/*Make the size adjustment*/
|
||||
if(ext_p->fit == LV_LIST_FIT_HOLDER) {
|
||||
if(ext->fit == LV_LIST_FIT_HOLDER) {
|
||||
/*Now the width will be adjusted*/
|
||||
lv_rect_set_fit(liste, false, true);
|
||||
cord_t w = lv_obj_get_width(obj_dp);
|
||||
w -= lists_p->pages.bg_rects.hpad * 2;
|
||||
cord_t w = lv_obj_get_width(list);
|
||||
w -= lists->bg_page.bg_rects.hpad * 2;
|
||||
lv_obj_set_width(liste, w);
|
||||
} else if(ext_p->fit == LV_LIST_FIT_LONGEST) {
|
||||
} else if(ext->fit == LV_LIST_FIT_LONGEST) {
|
||||
/*In this case the width will be adjusted*/
|
||||
lv_rect_set_fit(liste, false, true);
|
||||
|
||||
@@ -174,45 +174,45 @@ lv_obj_t * lv_list_add(lv_obj_t * obj_dp, const char * img_fn, const char * txt,
|
||||
|
||||
/**
|
||||
* Move the list elements up by one
|
||||
* @param obj_dp pointer a to list object
|
||||
* @param list pointer a to list object
|
||||
*/
|
||||
void lv_list_up(lv_obj_t * obj_dp)
|
||||
void lv_list_up(lv_obj_t * list)
|
||||
{
|
||||
/*Search the first list element which 'y' coordinate is below the parent
|
||||
* and position the list to show this element on the bottom*/
|
||||
lv_obj_t * h = lv_obj_get_parent(obj_dp);
|
||||
lv_obj_t * h = lv_obj_get_parent(list);
|
||||
lv_obj_t * e;
|
||||
lv_obj_t * e_prev = NULL;
|
||||
e = lv_obj_get_child(obj_dp, NULL);
|
||||
e = lv_obj_get_child(list, NULL);
|
||||
while(e != NULL) {
|
||||
if(e->cords.y2 <= h->cords.y2) {
|
||||
if(e_prev != NULL)
|
||||
lv_obj_set_y(obj_dp, lv_obj_get_height(h) -
|
||||
lv_obj_set_y(list, lv_obj_get_height(h) -
|
||||
(lv_obj_get_y(e_prev) + lv_obj_get_height(e_prev)));
|
||||
break;
|
||||
}
|
||||
e_prev = e;
|
||||
e = lv_obj_get_child(obj_dp, e);
|
||||
e = lv_obj_get_child(list, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the list elements down by one
|
||||
* @param obj_dp pointer to a list object
|
||||
* @param list pointer to a list object
|
||||
*/
|
||||
void lv_list_down(lv_obj_t * obj_dp)
|
||||
void lv_list_down(lv_obj_t * list)
|
||||
{
|
||||
/*Search the first list element which 'y' coordinate is above the parent
|
||||
* and position the list to show this element on the top*/
|
||||
lv_obj_t * h = lv_obj_get_parent(obj_dp);
|
||||
lv_obj_t * h = lv_obj_get_parent(list);
|
||||
lv_obj_t * e;
|
||||
e = lv_obj_get_child(obj_dp, NULL);
|
||||
e = lv_obj_get_child(list, NULL);
|
||||
while(e != NULL) {
|
||||
if(e->cords.y1 < h->cords.y1) {
|
||||
lv_obj_set_y(obj_dp, -lv_obj_get_y(e));
|
||||
lv_obj_set_y(list, -lv_obj_get_y(e));
|
||||
break;
|
||||
}
|
||||
e = lv_obj_get_child(obj_dp, e);
|
||||
e = lv_obj_get_child(list, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,14 +222,14 @@ void lv_list_down(lv_obj_t * obj_dp)
|
||||
|
||||
/**
|
||||
* Set the list element fitting of a list
|
||||
* @param obj_dp pointer to a list object
|
||||
* @param list pointer to a list object
|
||||
* @param fit type of fitting (from lv_list_fit_t)
|
||||
*/
|
||||
void lv_list_set_fit(lv_obj_t * obj_dp, lv_list_fit_t fit)
|
||||
void lv_list_set_fit(lv_obj_t * list, lv_list_fit_t fit)
|
||||
{
|
||||
lv_list_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_list_ext_t * ext = lv_obj_get_ext(list);
|
||||
|
||||
ext_p->fit = fit;
|
||||
ext->fit = fit;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,12 +239,12 @@ void lv_list_set_fit(lv_obj_t * obj_dp, lv_list_fit_t fit)
|
||||
|
||||
/**
|
||||
* Get the fit type of a list
|
||||
* @param obj_dp pointer to list object
|
||||
* @param list pointer to list object
|
||||
* @return the fit (from lv_list_fit_t)
|
||||
*/
|
||||
lv_list_fit_t lv_list_get_fit(lv_obj_t * obj_dp)
|
||||
lv_list_fit_t lv_list_get_fit(lv_obj_t * list)
|
||||
{
|
||||
return LV_EA(obj_dp, lv_list_ext_t)->fit;
|
||||
return LV_EA(list, lv_list_ext_t)->fit;
|
||||
}
|
||||
|
||||
|
||||
@@ -254,7 +254,7 @@ lv_list_fit_t lv_list_get_fit(lv_obj_t * obj_dp)
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_lists_t style
|
||||
*/
|
||||
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy_p)
|
||||
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * list)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -278,9 +278,9 @@ lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy_p)
|
||||
style_p = &lv_lists_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_lists_t));
|
||||
else memcpy(copy_p, &lv_lists_def, sizeof(lv_lists_t));
|
||||
if(list != NULL) {
|
||||
if(style_p != NULL) memcpy(list, style_p, sizeof(lv_lists_t));
|
||||
else memcpy(list, &lv_lists_def, sizeof(lv_lists_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -294,7 +294,7 @@ lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy_p)
|
||||
#if 0 /*A new design function is not necessary*/
|
||||
/**
|
||||
* Handle the drawing related tasks of the lists
|
||||
* @param obj_dp pointer to an object
|
||||
* @param list pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -302,7 +302,7 @@ lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_list_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_list_design(lv_obj_t * list, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
@@ -321,32 +321,32 @@ static bool lv_list_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo
|
||||
static void lv_lists_init(void)
|
||||
{
|
||||
/*Default style*/
|
||||
lv_pages_get(LV_PAGES_TRANSP, &lv_lists_def.pages);
|
||||
lv_lists_def.pages.bg_rects.vpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_def.pages.bg_rects.hpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_def.pages.bg_rects.opad = 0 * LV_STYLE_MULT;
|
||||
lv_pages_get(LV_PAGES_TRANSP, &lv_lists_def.bg_page);
|
||||
lv_lists_def.bg_page.bg_rects.vpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_def.bg_page.bg_rects.hpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_def.bg_page.bg_rects.opad = 0 * LV_STYLE_MULT;
|
||||
|
||||
lv_lists_def.pages.scrable_rects.vpad = 10 * LV_STYLE_MULT;
|
||||
lv_lists_def.pages.scrable_rects.hpad = 10 * LV_STYLE_MULT;
|
||||
lv_lists_def.pages.scrable_rects.opad = 5 * LV_STYLE_MULT;
|
||||
lv_lists_def.bg_page.scrable_rects.vpad = 10 * LV_STYLE_MULT;
|
||||
lv_lists_def.bg_page.scrable_rects.hpad = 10 * LV_STYLE_MULT;
|
||||
lv_lists_def.bg_page.scrable_rects.opad = 5 * LV_STYLE_MULT;
|
||||
|
||||
lv_btns_get(LV_BTNS_DEF, &lv_lists_def.liste_btns); /*List element button style*/
|
||||
lv_btns_get(LV_BTNS_DEF, &lv_lists_def.liste_btn); /*List element button style*/
|
||||
|
||||
lv_labels_get(LV_LABELS_BTN, &lv_lists_def.liste_labels); /*List element label style*/
|
||||
lv_lists_def.liste_labels.mid = 0;
|
||||
lv_labels_get(LV_LABELS_BTN, &lv_lists_def.liste_label); /*List element label style*/
|
||||
lv_lists_def.liste_label.mid = 0;
|
||||
|
||||
lv_imgs_get(LV_IMGS_DEF, &lv_lists_def.liste_imgs); /*Lit element image style*/
|
||||
lv_imgs_get(LV_IMGS_DEF, &lv_lists_def.liste_img); /*Lit element image style*/
|
||||
|
||||
lv_lists_def.liste_layout = LV_RECT_LAYOUT_ROW_M;
|
||||
|
||||
memcpy(&lv_lists_tight, &lv_lists_def, sizeof(lv_lists_t));
|
||||
lv_lists_tight.pages.bg_rects.vpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.pages.bg_rects.hpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.pages.bg_rects.opad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.bg_page.bg_rects.vpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.bg_page.bg_rects.hpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.bg_page.bg_rects.opad = 0 * LV_STYLE_MULT;
|
||||
|
||||
lv_lists_tight.pages.scrable_rects.vpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.pages.scrable_rects.hpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.pages.scrable_rects.opad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.bg_page.scrable_rects.vpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.bg_page.scrable_rects.hpad = 0 * LV_STYLE_MULT;
|
||||
lv_lists_tight.bg_page.scrable_rects.opad = 0 * LV_STYLE_MULT;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -26,17 +26,18 @@
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Style of LIST*/
|
||||
/*Style of list*/
|
||||
typedef struct
|
||||
{
|
||||
lv_pages_t pages; /*Ancestor page style*/
|
||||
lv_btns_t liste_btns;
|
||||
lv_labels_t liste_labels;
|
||||
lv_imgs_t liste_imgs;
|
||||
lv_pages_t bg_page; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
lv_btns_t liste_btn;
|
||||
lv_labels_t liste_label;
|
||||
lv_imgs_t liste_img;
|
||||
lv_rect_layout_t liste_layout;
|
||||
}lv_lists_t;
|
||||
|
||||
/*Built-in styles of LISTATE*/
|
||||
/*Built-in styles of list*/
|
||||
typedef enum
|
||||
{
|
||||
LV_LISTS_DEF,
|
||||
@@ -51,27 +52,26 @@ typedef enum
|
||||
LV_LIST_FIT_LONGEST,
|
||||
}lv_list_fit_t;
|
||||
|
||||
|
||||
/*Data of LIST*/
|
||||
/*Data of list*/
|
||||
typedef struct
|
||||
{
|
||||
lv_page_ext_t page_ext;
|
||||
lv_page_ext_t page_ext; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
uint8_t fit; /*Width adjustment of list elements (from lv_list_adjsut_t)*/
|
||||
}lv_list_ext_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_list_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_list_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_obj_t * lv_list_add(lv_obj_t * obj_dp, const char * img_fn, const char * txt, bool (*rel_action)(lv_obj_t*, lv_dispi_t *));
|
||||
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy_p);
|
||||
lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param);
|
||||
lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, bool (*rel_action)(lv_obj_t *, lv_dispi_t *));
|
||||
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy);
|
||||
|
||||
void lv_list_down(lv_obj_t * obj_dp);
|
||||
void lv_list_up(lv_obj_t * obj_dp);
|
||||
void lv_list_set_fit(lv_obj_t * obj_dp, lv_list_fit_t fit);
|
||||
lv_list_fit_t lv_list_get_fit(lv_obj_t * obj_dp);
|
||||
void lv_list_down(lv_obj_t * list);
|
||||
void lv_list_up(lv_obj_t * list);
|
||||
void lv_list_set_fit(lv_obj_t * list, lv_list_fit_t fit);
|
||||
lv_list_fit_t lv_list_get_fit(lv_obj_t * list);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -28,14 +28,13 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_templ_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_temps_init(void);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_templs_t lv_templs_def =
|
||||
{ /*Create a default style*/ };
|
||||
static lv_templs_t lv_templs_def; /*Default template style*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -51,50 +50,50 @@ static lv_templs_t lv_templs_def =
|
||||
|
||||
/**
|
||||
* Create a template objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new template
|
||||
* @param copy_dp pointer to a template object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new template
|
||||
* @param copy pointer to a template object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created template
|
||||
*/
|
||||
lv_obj_t * lv_templ_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_templ_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor object*/
|
||||
lv_obj_t* new_obj_dp = lv_obj_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
/*Create the ancestor templect*/
|
||||
lv_templ_t * new_templ = lv_templ_create(par, copy);
|
||||
dm_assert(new_templ);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_templ_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_templ_ext_t));
|
||||
dm_assert(ext_dp);
|
||||
/*Allocate the templect type specific extended data*/
|
||||
lv_templ_ext_t * ext = lv_templ_alloc_ext(new_templ, sizeof(lv_templ_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
/*The signal and design functions are not copied so set them here*/
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_templ_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_templ_design);
|
||||
lv_templ_set_signal_f(new_templ, lv_templ_signal);
|
||||
lv_templ_set_design_f(new_templ, lv_templ_design);
|
||||
|
||||
/*Init the new template object*/
|
||||
if(copy_dp == NULL) {
|
||||
/*Init the new template templect*/
|
||||
if(copy == NULL) {
|
||||
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
/*Copy an existing templect*/
|
||||
else {
|
||||
lv_templ_ext_t * copy_ext_dp = lv_obj_get_ext(copy_dp);
|
||||
lv_templ_ext_t * copy_ext = lv_templ_get_ext(copy);
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_templ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the template
|
||||
* @param obj_dp pointer to a template object
|
||||
* @param templ pointer to a template object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return true: the object is still valid (not deleted), false: the object become invalid
|
||||
*/
|
||||
bool lv_templ_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
/* TODO update it to the ancestor's signal function*/
|
||||
valid = lv_obj_signal(obj_dp, sign, param);
|
||||
valid = lv_obj_signal(templ, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -123,10 +122,10 @@ bool lv_templ_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_templs_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_templs_t style
|
||||
*/
|
||||
lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy_p)
|
||||
lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -146,9 +145,9 @@ lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy_p)
|
||||
style_p = &lv_templs_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_templs_t));
|
||||
else memcpy(copy_p, &lv_templs_def, sizeof(lv_templs_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_templs_t));
|
||||
else memcpy(copy, &lv_templs_def, sizeof(lv_templs_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -161,7 +160,7 @@ lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy_p)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the templates
|
||||
* @param obj_dp pointer to an object
|
||||
* @param templ pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -169,7 +168,7 @@ lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_templ_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
|
||||
@@ -52,9 +52,9 @@ typedef struct
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t * lv_templ_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_templ_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy_p);
|
||||
lv_obj_t * lv_templ_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param);
|
||||
lv_templs_t * lv_templs_get(lv_templs_builtin_t style, lv_templs_t * copy);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_page_sb_refresh(lv_obj_t* main_dp);
|
||||
static bool lv_page_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_scrolling_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param);
|
||||
static void lv_pages_init(void);;
|
||||
static void lv_page_sb_refresh(lv_obj_t * main);
|
||||
static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode);
|
||||
static bool lv_scrolling_signal(lv_obj_t * page, lv_signal_t sign, void* param);
|
||||
static void lv_pages_init(void);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -52,108 +52,108 @@ static lv_design_f_t ancestor_design_f;
|
||||
|
||||
/**
|
||||
* Create a page objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new page
|
||||
* @param copy_dp pointer to a page object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new page
|
||||
* @param copy pointer to a page object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created page
|
||||
*/
|
||||
lv_obj_t* lv_page_create(lv_obj_t * par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor object*/
|
||||
lv_obj_t * new_obj_dp = lv_rect_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_page = lv_rect_create(par, copy);
|
||||
dm_assert(new_page);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_page_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_page_ext_t));
|
||||
dm_assert(ext_dp);
|
||||
lv_page_ext_t * ext = lv_obj_alloc_ext(new_page, sizeof(lv_page_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
if(ancestor_design_f == NULL) {
|
||||
ancestor_design_f = lv_obj_get_design_f(new_obj_dp);
|
||||
ancestor_design_f = lv_obj_get_design_f(new_page);
|
||||
}
|
||||
|
||||
/*Init the new page object*/
|
||||
if(copy_dp == NULL) {
|
||||
lv_pages_t * style = lv_pages_get(LV_PAGES_DEF, NULL);
|
||||
ext_dp->scrolling_dp = lv_rect_create(new_obj_dp, NULL);
|
||||
lv_obj_set_signal_f(ext_dp->scrolling_dp, lv_scrolling_signal);
|
||||
lv_obj_set_drag(ext_dp->scrolling_dp, true);
|
||||
lv_obj_set_drag_throw(ext_dp->scrolling_dp, true);
|
||||
lv_rect_set_fit(ext_dp->scrolling_dp, true, true);
|
||||
lv_obj_set_style(ext_dp->scrolling_dp, &style->scrable_rects);
|
||||
if(copy == NULL) {
|
||||
lv_pages_t * pages = lv_pages_get(LV_PAGES_DEF, NULL);
|
||||
ext->scrolling = lv_rect_create(new_page, NULL);
|
||||
lv_obj_set_signal_f(ext->scrolling, lv_scrolling_signal);
|
||||
lv_obj_set_drag(ext->scrolling, true);
|
||||
lv_obj_set_drag_throw(ext->scrolling, true);
|
||||
lv_rect_set_fit(ext->scrolling, true, true);
|
||||
lv_obj_set_style(ext->scrolling, &pages->scrable_rects);
|
||||
|
||||
/* Add the signal function only if 'scrolling_dp' is created
|
||||
/* Add the signal function only if 'scrolling' is created
|
||||
* because everything has to be ready before any signal is received*/
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_page_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_page_design);
|
||||
lv_obj_set_style(new_obj_dp, style);
|
||||
lv_obj_set_signal_f(new_page, lv_page_signal);
|
||||
lv_obj_set_design_f(new_page, lv_page_design);
|
||||
lv_obj_set_style(new_page, pages);
|
||||
} else {
|
||||
lv_page_ext_t * copy_ext_dp = lv_obj_get_ext(copy_dp);
|
||||
ext_dp->scrolling_dp = lv_rect_create(new_obj_dp, copy_ext_dp->scrolling_dp);
|
||||
lv_obj_set_signal_f(ext_dp->scrolling_dp, lv_scrolling_signal);
|
||||
lv_page_ext_t * copy_ext = lv_obj_get_ext(copy);
|
||||
ext->scrolling = lv_rect_create(new_page, copy_ext->scrolling);
|
||||
lv_obj_set_signal_f(ext->scrolling, lv_scrolling_signal);
|
||||
|
||||
/* Add the signal function only if 'scrolling_dp' is created
|
||||
/* Add the signal function only if 'scrolling' is created
|
||||
* because everything has to be ready before any signal is received*/
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_page_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_page_design);
|
||||
lv_obj_set_style(new_obj_dp, lv_obj_get_style(copy_dp));
|
||||
lv_obj_set_signal_f(new_page, lv_page_signal);
|
||||
lv_obj_set_design_f(new_page, lv_page_design);
|
||||
lv_obj_set_style(new_page, lv_obj_get_style(copy));
|
||||
}
|
||||
|
||||
lv_page_sb_refresh(new_obj_dp);
|
||||
lv_page_sb_refresh(new_page);
|
||||
|
||||
return new_obj_dp;
|
||||
return new_page;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Signal function of the page
|
||||
* @param obj_dp pointer to a page object
|
||||
* @param page pointer to a page object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
|
||||
bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool obj_valid = true;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
obj_valid = lv_rect_signal(obj_dp, sign, param);
|
||||
obj_valid = lv_rect_signal(page, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(obj_valid != false) {
|
||||
lv_page_ext_t * page_ext_p = lv_obj_get_ext(obj_dp);
|
||||
lv_pages_t * pages_p = lv_obj_get_style(obj_dp);
|
||||
lv_page_ext_t * ext = lv_obj_get_ext(page);
|
||||
lv_pages_t * pages = lv_obj_get_style(page);
|
||||
lv_obj_t * child;
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CHILD_CHG: /*Be sure, only scrollable object is on the page*/
|
||||
child = lv_obj_get_child(obj_dp, NULL);
|
||||
child = lv_obj_get_child(page, NULL);
|
||||
while(child != NULL) {
|
||||
if(child != page_ext_p->scrolling_dp) {
|
||||
if(child != ext->scrolling) {
|
||||
lv_obj_t * tmp = child;
|
||||
child = lv_obj_get_child(obj_dp, child); /*Get the next child before move this*/
|
||||
lv_obj_set_parent(tmp, page_ext_p->scrolling_dp);
|
||||
child = lv_obj_get_child(page, child); /*Get the next child before move this*/
|
||||
lv_obj_set_parent(tmp, ext->scrolling);
|
||||
} else {
|
||||
child = lv_obj_get_child(obj_dp, child);
|
||||
child = lv_obj_get_child(page, child);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LV_SIGNAL_STYLE_CHG:
|
||||
area_set_height(&page_ext_p->sbh, pages_p->sb_width);
|
||||
area_set_width(&page_ext_p->sbv, pages_p->sb_width);
|
||||
lv_obj_set_style(page_ext_p->scrolling_dp, &pages_p->scrable_rects);
|
||||
area_set_height(&ext->sbh, pages->sb_width);
|
||||
area_set_width(&ext->sbv, pages->sb_width);
|
||||
lv_obj_set_style(ext->scrolling, &pages->scrable_rects);
|
||||
|
||||
if(pages_p->sb_mode == LV_PAGE_SB_MODE_ON) {
|
||||
page_ext_p->sbh_draw = 1;
|
||||
page_ext_p->sbv_draw = 1;
|
||||
if(pages->sb_mode == LV_PAGE_SB_MODE_ON) {
|
||||
ext->sbh_draw = 1;
|
||||
ext->sbv_draw = 1;
|
||||
} else {
|
||||
page_ext_p->sbh_draw = 0;
|
||||
page_ext_p->sbv_draw = 0;
|
||||
ext->sbh_draw = 0;
|
||||
ext->sbv_draw = 0;
|
||||
}
|
||||
|
||||
lv_page_sb_refresh(obj_dp);
|
||||
lv_page_sb_refresh(page);
|
||||
break;
|
||||
|
||||
case LV_SIGNAL_CORD_CHG:
|
||||
lv_page_sb_refresh(obj_dp);
|
||||
lv_page_sb_refresh(page);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -166,16 +166,16 @@ bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
|
||||
|
||||
/**
|
||||
* Signal function of the scrollable part of a page
|
||||
* @param obj_dp pointer to the scrollable object
|
||||
* @param scrolling pointer to the scrollable object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
static bool lv_scrolling_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
|
||||
static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* param)
|
||||
{
|
||||
bool obj_valid = true;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
obj_valid = lv_rect_signal(obj_dp, sign, param);
|
||||
obj_valid = lv_rect_signal(scrolling, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -187,18 +187,18 @@ static bool lv_scrolling_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
|
||||
bool refr_y = false;
|
||||
area_t page_cords;
|
||||
area_t obj_cords;
|
||||
lv_obj_t * page_p = lv_obj_get_parent(obj_dp);
|
||||
lv_pages_t * pages_p = lv_obj_get_style(page_p);
|
||||
lv_page_ext_t * page_ext_dp = lv_obj_get_ext(page_p);
|
||||
cord_t hpad = pages_p->bg_rects.hpad;
|
||||
cord_t vpad = pages_p->bg_rects.vpad;
|
||||
lv_obj_t * page = lv_obj_get_parent(scrolling);
|
||||
lv_pages_t * pages = lv_obj_get_style(page);
|
||||
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
|
||||
cord_t hpad = pages->bg_rects.hpad;
|
||||
cord_t vpad = pages->bg_rects.vpad;
|
||||
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CORD_CHG:
|
||||
new_x = lv_obj_get_x(obj_dp);
|
||||
new_y = lv_obj_get_y(obj_dp);
|
||||
lv_obj_get_cords(obj_dp, &obj_cords);
|
||||
lv_obj_get_cords(page_p, &page_cords);
|
||||
new_x = lv_obj_get_x(scrolling);
|
||||
new_y = lv_obj_get_y(scrolling);
|
||||
lv_obj_get_cords(scrolling, &obj_cords);
|
||||
lv_obj_get_cords(page, &page_cords);
|
||||
|
||||
/*scrollable width smaller then page width? -> align to left*/
|
||||
if(area_get_width(&obj_cords) + 2 * hpad < area_get_width(&page_cords)) {
|
||||
@@ -236,31 +236,31 @@ static bool lv_scrolling_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
|
||||
}
|
||||
}
|
||||
if(refr_x != false || refr_y != false) {
|
||||
lv_obj_set_pos(obj_dp, new_x, new_y);
|
||||
lv_obj_set_pos(scrolling, new_x, new_y);
|
||||
}
|
||||
|
||||
lv_page_sb_refresh(page_p);
|
||||
lv_page_sb_refresh(page);
|
||||
break;
|
||||
|
||||
case LV_SIGNAL_DRAG_BEGIN:
|
||||
if(pages_p->sb_mode == LV_PAGE_SB_MODE_AUTO ) {
|
||||
if(area_get_height(&page_ext_dp->sbv) < lv_obj_get_height(obj_dp) - pages_p->sb_width) {
|
||||
page_ext_dp->sbv_draw = 1;
|
||||
lv_inv_area(&page_ext_dp->sbv);
|
||||
if(pages->sb_mode == LV_PAGE_SB_MODE_AUTO ) {
|
||||
if(area_get_height(&page_ext->sbv) < lv_obj_get_height(scrolling) - pages->sb_width) {
|
||||
page_ext->sbv_draw = 1;
|
||||
lv_inv_area(&page_ext->sbv);
|
||||
}
|
||||
if(area_get_width(&page_ext_dp->sbh) < lv_obj_get_width(obj_dp) - pages_p->sb_width) {
|
||||
page_ext_dp->sbh_draw = 1;
|
||||
lv_inv_area(&page_ext_dp->sbh);
|
||||
if(area_get_width(&page_ext->sbh) < lv_obj_get_width(scrolling) - pages->sb_width) {
|
||||
page_ext->sbh_draw = 1;
|
||||
lv_inv_area(&page_ext->sbh);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LV_SIGNAL_DRAG_END:
|
||||
if(pages_p->sb_mode == LV_PAGE_SB_MODE_AUTO) {
|
||||
page_ext_dp->sbh_draw = 0;
|
||||
page_ext_dp->sbv_draw = 0;
|
||||
lv_inv_area(&page_ext_dp->sbh);
|
||||
lv_inv_area(&page_ext_dp->sbv);
|
||||
if(pages->sb_mode == LV_PAGE_SB_MODE_AUTO) {
|
||||
page_ext->sbh_draw = 0;
|
||||
page_ext->sbv_draw = 0;
|
||||
lv_inv_area(&page_ext->sbh);
|
||||
lv_inv_area(&page_ext->sbv);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -278,13 +278,13 @@ static bool lv_scrolling_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
|
||||
|
||||
/**
|
||||
* Glue the object to the page. After it the page can be moved (dragged) with this object too.
|
||||
* @param obj_dp pointer to an object on a page
|
||||
* @param en true: enable glue, false: disable glue
|
||||
* @param page pointer to an object on a page
|
||||
* @param glue true: enable glue, false: disable glue
|
||||
*/
|
||||
void lv_page_glue_obj(lv_obj_t* obj_dp, bool en)
|
||||
void lv_page_glue_obj(lv_obj_t * page, bool glue)
|
||||
{
|
||||
lv_obj_set_drag_parent(obj_dp, en);
|
||||
lv_obj_set_drag(obj_dp, en);
|
||||
lv_obj_set_drag_parent(page, glue);
|
||||
lv_obj_set_drag(page, glue);
|
||||
}
|
||||
|
||||
|
||||
@@ -295,10 +295,10 @@ void lv_page_glue_obj(lv_obj_t* obj_dp, bool en)
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_pages_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_pages_t style
|
||||
*/
|
||||
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy)
|
||||
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -321,9 +321,9 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy)
|
||||
style_p = &lv_pages_def;
|
||||
}
|
||||
|
||||
if(to_copy != NULL) {
|
||||
if(style_p != NULL) memcpy(to_copy, style_p, sizeof(lv_pages_t));
|
||||
else memcpy(to_copy, &lv_pages_def, sizeof(lv_pages_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_pages_t));
|
||||
else memcpy(copy, &lv_pages_def, sizeof(lv_pages_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -335,7 +335,7 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the pages
|
||||
* @param obj_dp pointer to an object
|
||||
* @param page pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -343,24 +343,24 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_page_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
return ancestor_design_f(obj_dp, mask_p, mode);
|
||||
return ancestor_design_f(page, mask, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
ancestor_design_f(obj_dp, mask_p, mode);
|
||||
ancestor_design_f(page, mask, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_POST) { /*Draw the scroll bars finally*/
|
||||
lv_page_ext_t * page_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_pages_t * pages_p = lv_obj_get_style(obj_dp);
|
||||
opa_t sb_opa = lv_obj_get_opa(obj_dp) * pages_p->sb_opa /100;
|
||||
lv_page_ext_t * ext = lv_obj_get_ext(page);
|
||||
lv_pages_t * style = lv_obj_get_style(page);
|
||||
opa_t sb_opa = lv_obj_get_opa(page) * style->sb_opa /100;
|
||||
|
||||
/*Draw the scrollbars*/
|
||||
if(page_ext_dp->sbh_draw != 0) {
|
||||
lv_draw_rect(&page_ext_dp->sbh, mask_p, &pages_p->sb_rects, sb_opa);
|
||||
if(ext->sbh_draw != 0) {
|
||||
lv_draw_rect(&ext->sbh, mask, &style->sb_rects, sb_opa);
|
||||
}
|
||||
|
||||
if(page_ext_dp->sbv_draw != 0) {
|
||||
lv_draw_rect(&page_ext_dp->sbv, mask_p, &pages_p->sb_rects, sb_opa);
|
||||
if(ext->sbv_draw != 0) {
|
||||
lv_draw_rect(&ext->sbv, mask, &style->sb_rects, sb_opa);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,68 +368,63 @@ static bool lv_page_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the pages
|
||||
* @param obj_dp pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
||||
* @param return true/false, depends on 'mode'
|
||||
* Refresh the position and size of the scroll bars.
|
||||
* @param page pointer to a page object
|
||||
*/
|
||||
static void lv_page_sb_refresh(lv_obj_t* page_dp)
|
||||
static void lv_page_sb_refresh(lv_obj_t * page)
|
||||
{
|
||||
lv_page_ext_t * page_ext_dp = lv_obj_get_ext(page_dp);
|
||||
lv_pages_t * pages_p = lv_obj_get_style(page_dp);
|
||||
lv_obj_t* scrolling_dp = page_ext_dp->scrolling_dp;
|
||||
lv_page_ext_t * page_ext = lv_obj_get_ext(page);
|
||||
lv_pages_t * pages = lv_obj_get_style(page);
|
||||
lv_obj_t * scrolling = page_ext->scrolling;
|
||||
cord_t size_tmp;
|
||||
cord_t scrolling_w = lv_obj_get_width(scrolling_dp);
|
||||
cord_t scrolling_h = lv_obj_get_height(scrolling_dp);
|
||||
cord_t hpad = pages_p->bg_rects.hpad;
|
||||
cord_t vpad = pages_p->bg_rects.vpad;
|
||||
cord_t obj_w = lv_obj_get_width(page_dp);
|
||||
cord_t obj_h = lv_obj_get_height(page_dp);
|
||||
cord_t page_x0 = page_dp->cords.x1;
|
||||
cord_t page_y0 = page_dp->cords.y1;
|
||||
cord_t scrolling_w = lv_obj_get_width(scrolling);
|
||||
cord_t scrolling_h = lv_obj_get_height(scrolling);
|
||||
cord_t hpad = pages->bg_rects.hpad;
|
||||
cord_t vpad = pages->bg_rects.vpad;
|
||||
cord_t obj_w = lv_obj_get_width(page);
|
||||
cord_t obj_h = lv_obj_get_height(page);
|
||||
cord_t page_x0 = page->cords.x1;
|
||||
cord_t page_y0 = page->cords.y1;
|
||||
|
||||
lv_inv_area(&page_ext_dp->sbh);
|
||||
lv_inv_area(&page_ext_dp->sbv);
|
||||
lv_inv_area(&page_ext->sbh);
|
||||
lv_inv_area(&page_ext->sbv);
|
||||
|
||||
/*Horizontal scrollbar*/
|
||||
if(scrolling_w <= obj_w - 2 * hpad) { /*Full sized scroll bar*/
|
||||
area_set_width(&page_ext_dp->sbh, obj_w - pages_p->sb_width);
|
||||
area_set_pos(&page_ext_dp->sbh, page_x0, page_y0 + obj_h - pages_p->sb_width);
|
||||
area_set_width(&page_ext->sbh, obj_w - pages->sb_width);
|
||||
area_set_pos(&page_ext->sbh, page_x0, page_y0 + obj_h - pages->sb_width);
|
||||
} else {
|
||||
if(pages_p->sb_mode == LV_PAGE_SB_MODE_ON) {
|
||||
page_ext_dp->sbh_draw = 1;
|
||||
if(pages->sb_mode == LV_PAGE_SB_MODE_ON) {
|
||||
page_ext->sbh_draw = 1;
|
||||
}
|
||||
size_tmp = (((obj_w - hpad) * (obj_w - pages_p->sb_width)) / scrolling_w);
|
||||
area_set_width(&page_ext_dp->sbh, size_tmp);
|
||||
size_tmp = (((obj_w - hpad) * (obj_w - pages->sb_width)) / scrolling_w);
|
||||
area_set_width(&page_ext->sbh, size_tmp);
|
||||
|
||||
area_set_pos(&page_ext_dp->sbh, page_x0 +
|
||||
( -(lv_obj_get_x(scrolling_dp) - hpad) * (obj_w - size_tmp - pages_p->sb_width)) /
|
||||
area_set_pos(&page_ext->sbh, page_x0 +
|
||||
( -(lv_obj_get_x(scrolling) - hpad) * (obj_w - size_tmp - pages->sb_width)) /
|
||||
(scrolling_w - obj_w + 2 * hpad),
|
||||
page_y0 + obj_h - pages_p->sb_width);
|
||||
page_y0 + obj_h - pages->sb_width);
|
||||
}
|
||||
|
||||
/*Vertical scrollbar*/
|
||||
if(scrolling_h <= obj_h - 2 * vpad) { /*Full sized scroll bar*/
|
||||
area_set_height(&page_ext_dp->sbv, obj_h - pages_p->sb_width);
|
||||
area_set_pos(&page_ext_dp->sbv, page_x0 + obj_w - pages_p->sb_width, 0);
|
||||
area_set_height(&page_ext->sbv, obj_h - pages->sb_width);
|
||||
area_set_pos(&page_ext->sbv, page_x0 + obj_w - pages->sb_width, 0);
|
||||
} else {
|
||||
if(pages_p->sb_mode == LV_PAGE_SB_MODE_ON) {
|
||||
page_ext_dp->sbv_draw = 1;
|
||||
if(pages->sb_mode == LV_PAGE_SB_MODE_ON) {
|
||||
page_ext->sbv_draw = 1;
|
||||
}
|
||||
size_tmp = (((obj_h - vpad) * (obj_h - pages_p->sb_width)) / scrolling_h);
|
||||
area_set_height(&page_ext_dp->sbv, size_tmp);
|
||||
size_tmp = (((obj_h - vpad) * (obj_h - pages->sb_width)) / scrolling_h);
|
||||
area_set_height(&page_ext->sbv, size_tmp);
|
||||
|
||||
area_set_pos(&page_ext_dp->sbv, page_x0 + obj_w - pages_p->sb_width,
|
||||
area_set_pos(&page_ext->sbv, page_x0 + obj_w - pages->sb_width,
|
||||
page_y0 +
|
||||
(-(lv_obj_get_y(scrolling_dp) - vpad) * (obj_h - size_tmp - pages_p->sb_width)) /
|
||||
(-(lv_obj_get_y(scrolling) - vpad) * (obj_h - size_tmp - pages->sb_width)) /
|
||||
(scrolling_h - obj_h + 2 * vpad));
|
||||
}
|
||||
|
||||
lv_inv_area(&page_ext_dp->sbh);
|
||||
lv_inv_area(&page_ext_dp->sbv);
|
||||
lv_inv_area(&page_ext->sbh);
|
||||
lv_inv_area(&page_ext->sbv);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,7 @@ typedef enum
|
||||
LV_PAGE_SB_MODE_AUTO,
|
||||
}lv_page_sb_mode_t;
|
||||
|
||||
/*Style of page*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rects_t bg_rects; /*Style of ancestor*/
|
||||
@@ -40,32 +41,35 @@ typedef struct
|
||||
uint8_t sb_opa;
|
||||
}lv_pages_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_obj_t * scrolling_dp; /*The scrollable object on the background*/
|
||||
area_t sbh; /*Horizontal scrollbar*/
|
||||
area_t sbv; /*Vertical scrollbar*/
|
||||
uint8_t sbh_draw :1; /*1: horizontal scrollbar is visible now*/
|
||||
uint8_t sbv_draw :1; /*1: vertical scrollbar is visible now*/
|
||||
}lv_page_ext_t;
|
||||
|
||||
/*Built-in styles of page*/
|
||||
typedef enum
|
||||
{
|
||||
LV_PAGES_DEF,
|
||||
LV_PAGES_TRANSP,
|
||||
}lv_pages_builtin_t;
|
||||
|
||||
/*Data of page*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_obj_t * scrolling; /*The scrollable object on the background*/
|
||||
area_t sbh; /*Horizontal scrollbar*/
|
||||
area_t sbv; /*Vertical scrollbar*/
|
||||
uint8_t sbh_draw :1; /*1: horizontal scrollbar is visible now*/
|
||||
uint8_t sbv_draw :1; /*1: vertical scrollbar is visible now*/
|
||||
}lv_page_ext_t;
|
||||
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/*Create function*/
|
||||
lv_obj_t* lv_page_create(lv_obj_t* par_dp, lv_obj_t * ori_dp);
|
||||
void lv_page_glue_obj(lv_obj_t* page_p, bool en);
|
||||
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy);
|
||||
bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
void lv_page_glue_obj(lv_obj_t * page, bool glue);
|
||||
lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * copy);
|
||||
bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
154
lv_objx/lv_pb.c
154
lv_objx/lv_pb.c
@@ -28,14 +28,14 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_pb_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_pb_design(lv_obj_t * pb, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_pbs_init(void);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_design_f_t ancestor_design_fp;
|
||||
static lv_pbs_t lv_pbs_def;
|
||||
static lv_design_f_t ancestor_design_fp;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -51,78 +51,78 @@ static lv_pbs_t lv_pbs_def;
|
||||
|
||||
/**
|
||||
* Create a progress bar objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new progress bar
|
||||
* @param copy_dp pointer to a progress bar object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new progress bar
|
||||
* @param copy pointer to a progress bar object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created progress bar
|
||||
*/
|
||||
lv_obj_t* lv_pb_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_pb_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor basic object*/
|
||||
lv_obj_t* new_obj_dp = lv_rect_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_pb = lv_rect_create(par, copy);
|
||||
dm_assert(new_pb);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_pb_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_pb_ext_t));
|
||||
dm_assert(ext_dp);
|
||||
lv_pb_ext_t * ext = lv_obj_alloc_ext(new_pb, sizeof(lv_pb_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
/* Save the rectangle design function.
|
||||
* It will be used in the progress bar design function*/
|
||||
if(ancestor_design_fp == NULL) {
|
||||
ancestor_design_fp = lv_obj_get_design_f(new_obj_dp);
|
||||
ancestor_design_fp = lv_obj_get_design_f(new_pb);
|
||||
}
|
||||
|
||||
/*Init the new progress bar object*/
|
||||
if(copy_dp == NULL) {
|
||||
ext_dp->format_dp = dm_alloc(strlen(LV_PB_DEF_FORMAT) + 1);
|
||||
strcpy(ext_dp->format_dp, LV_PB_DEF_FORMAT);
|
||||
ext_dp->min_value = 0;
|
||||
ext_dp->max_value = 100;
|
||||
ext_dp->act_value = 0;
|
||||
if(copy == NULL) {
|
||||
ext->format = dm_alloc(strlen(LV_PB_DEF_FORMAT) + 1);
|
||||
strcpy(ext->format, LV_PB_DEF_FORMAT);
|
||||
ext->min_value = 0;
|
||||
ext->max_value = 100;
|
||||
ext->act_value = 0;
|
||||
|
||||
lv_label_create(new_obj_dp, NULL);
|
||||
lv_label_create(new_pb, NULL);
|
||||
|
||||
lv_rect_set_layout(new_obj_dp, LV_RECT_LAYOUT_CENTER);
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_pb_signal);
|
||||
lv_obj_set_style(new_obj_dp, lv_pbs_get(LV_PBS_DEF, NULL));
|
||||
lv_obj_set_design_f(new_obj_dp, lv_pb_design);
|
||||
lv_rect_set_layout(new_pb, LV_RECT_LAYOUT_CENTER);
|
||||
lv_obj_set_signal_f(new_pb, lv_pb_signal);
|
||||
lv_obj_set_style(new_pb, lv_pbs_get(LV_PBS_DEF, NULL));
|
||||
lv_obj_set_design_f(new_pb, lv_pb_design);
|
||||
|
||||
lv_pb_set_value(new_obj_dp, ext_dp->act_value);
|
||||
lv_pb_set_value(new_pb, ext->act_value);
|
||||
} else {
|
||||
lv_pb_ext_t * ext_copy_dp = lv_obj_get_ext(copy_dp);
|
||||
ext_dp->format_dp = dm_alloc(strlen(ext_copy_dp->format_dp) + 1);
|
||||
strcpy(ext_dp->format_dp, ext_copy_dp->format_dp);
|
||||
ext_dp->min_value = ext_copy_dp->min_value;
|
||||
ext_dp->max_value = ext_copy_dp->max_value;
|
||||
ext_dp->act_value = ext_copy_dp->act_value;
|
||||
lv_pb_ext_t * ext_copy = lv_obj_get_ext(copy);
|
||||
ext->format = dm_alloc(strlen(ext_copy->format) + 1);
|
||||
strcpy(ext->format, ext_copy->format);
|
||||
ext->min_value = ext_copy->min_value;
|
||||
ext->max_value = ext_copy->max_value;
|
||||
ext->act_value = ext_copy->act_value;
|
||||
|
||||
}
|
||||
return new_obj_dp;
|
||||
return new_pb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the progress bar
|
||||
* @param obj_dp pointer to a progress bar object
|
||||
* @param pb pointer to a progress bar object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_pb_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_pb_signal(lv_obj_t * pb, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_rect_signal(obj_dp, sign, param);
|
||||
valid = lv_rect_signal(pb, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_pb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_pb_ext_t * ext = lv_obj_get_ext(pb);
|
||||
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CORD_CHG:
|
||||
lv_pb_set_value(obj_dp, ext_dp->act_value);
|
||||
lv_pb_set_value(pb, ext->act_value);
|
||||
break;
|
||||
case LV_SIGNAL_CLEANUP:
|
||||
dm_free(ext_dp->format_dp);
|
||||
dm_free(ext->format);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -138,51 +138,51 @@ bool lv_pb_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Set a new value on the progress bar
|
||||
* @param obj_dp pointer to a progress bar object
|
||||
* @param pb pointer to a progress bar object
|
||||
* @param value new value
|
||||
*/
|
||||
void lv_pb_set_value(lv_obj_t * obj_dp, uint16_t value)
|
||||
void lv_pb_set_value(lv_obj_t * pb, uint16_t value)
|
||||
{
|
||||
lv_pb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
ext_dp->act_value = value > ext_dp->max_value ? ext_dp->max_value : value;
|
||||
lv_pb_ext_t * ext = lv_obj_get_ext(pb);
|
||||
ext->act_value = value > ext->max_value ? ext->max_value : value;
|
||||
|
||||
char buf[LV_PB_TXT_MAX_LENGTH];
|
||||
sprintf(buf, ext_dp->format_dp, ext_dp->act_value);
|
||||
lv_label_set_text(lv_obj_get_child(obj_dp, NULL), buf);
|
||||
sprintf(buf, ext->format, ext->act_value);
|
||||
lv_label_set_text(lv_obj_get_child(pb, NULL), buf);
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(pb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set minimum and the maximum values of a progress bar
|
||||
* @param obj_dp pointer to he progress bar object
|
||||
* @param pb pointer to he progress bar object
|
||||
* @param min minimum value
|
||||
* @param max maximum value
|
||||
*/
|
||||
void lv_pb_set_min_max_value(lv_obj_t * obj_dp, uint16_t min, uint16_t max)
|
||||
void lv_pb_set_min_max_value(lv_obj_t * pb, uint16_t min, uint16_t max)
|
||||
{
|
||||
lv_pb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
ext_dp->max_value = max;
|
||||
ext_dp->max_value = max;
|
||||
if(ext_dp->act_value > max) {
|
||||
ext_dp->act_value = max;
|
||||
lv_pb_set_value(obj_dp, ext_dp->act_value);
|
||||
lv_pb_ext_t * ext = lv_obj_get_ext(pb);
|
||||
ext->max_value = max;
|
||||
ext->max_value = max;
|
||||
if(ext->act_value > max) {
|
||||
ext->act_value = max;
|
||||
lv_pb_set_value(pb, ext->act_value);
|
||||
}
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(pb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set format string for the label of the progress bar
|
||||
* @param obj_dp pointer to progress bar object
|
||||
* @param pb pointer to progress bar object
|
||||
* @param format a printf-like format string with one number (e.g. "Loading (%d)")
|
||||
*/
|
||||
void lv_pb_set_format(lv_obj_t * obj_dp, const char * format)
|
||||
void lv_pb_set_format(lv_obj_t * pb, const char * format)
|
||||
{
|
||||
lv_pb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
dm_free(ext_dp->format_dp);
|
||||
ext_dp->format_dp = dm_alloc(strlen(format) + 1);
|
||||
strcpy(ext_dp->format_dp, format);
|
||||
lv_pb_set_value(obj_dp, ext_dp->act_value);
|
||||
lv_pb_ext_t * ext = lv_obj_get_ext(pb);
|
||||
dm_free(ext->format);
|
||||
ext->format = dm_alloc(strlen(format) + 1);
|
||||
strcpy(ext->format, format);
|
||||
lv_pb_set_value(pb, ext->act_value);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
@@ -191,22 +191,22 @@ void lv_pb_set_format(lv_obj_t * obj_dp, const char * format)
|
||||
|
||||
/**
|
||||
* Get the value of a progress bar
|
||||
* @param obj_dp pointer to a progress bar object
|
||||
* @param pb pointer to a progress bar object
|
||||
* @return the value of the progress bar
|
||||
*/
|
||||
uint16_t lv_pb_get_value(lv_obj_t * obj_dp)
|
||||
uint16_t lv_pb_get_value(lv_obj_t * pb)
|
||||
{
|
||||
lv_pb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
return ext_dp->act_value;
|
||||
lv_pb_ext_t * ext = lv_obj_get_ext(pb);
|
||||
return ext->act_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_pbs_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_pbs_t style
|
||||
*/
|
||||
lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy_p)
|
||||
lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -226,9 +226,9 @@ lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy_p)
|
||||
style_p = &lv_pbs_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_pbs_t));
|
||||
else memcpy(copy_p, &lv_pbs_def, sizeof(lv_pbs_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_pbs_t));
|
||||
else memcpy(copy, &lv_pbs_def, sizeof(lv_pbs_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -241,7 +241,7 @@ lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy_p)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the progress bars
|
||||
* @param obj_dp pointer to an object
|
||||
* @param pb pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -249,26 +249,26 @@ lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_pb_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_pb_design(lv_obj_t * pb, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(ancestor_design_fp == NULL) return false;
|
||||
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return ancestor_design_fp(obj_dp, mask_p, mode);
|
||||
return ancestor_design_fp(pb, mask, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
ancestor_design_fp(obj_dp, mask_p, mode);
|
||||
ancestor_design_fp(pb, mask, mode);
|
||||
|
||||
lv_pb_ext_t * ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_pb_ext_t * ext = lv_obj_get_ext(pb);
|
||||
area_t bar_area;
|
||||
uint32_t tmp;
|
||||
area_cpy(&bar_area, &obj_dp->cords);
|
||||
tmp = (uint32_t)ext_dp->act_value * lv_obj_get_width(obj_dp);
|
||||
tmp = (uint32_t) tmp / (ext_dp->max_value - ext_dp->min_value);
|
||||
area_cpy(&bar_area, &pb->cords);
|
||||
tmp = (uint32_t)ext->act_value * lv_obj_get_width(pb);
|
||||
tmp = (uint32_t) tmp / (ext->max_value - ext->min_value);
|
||||
bar_area.x2 = bar_area.x1 + (cord_t) tmp;
|
||||
|
||||
lv_pbs_t * style_p = lv_obj_get_style(obj_dp);
|
||||
lv_draw_rect(&bar_area, mask_p, &style_p->bar, OPA_COVER);
|
||||
lv_pbs_t * style_p = lv_obj_get_style(pb);
|
||||
lv_draw_rect(&bar_area, mask, &style_p->bar, OPA_COVER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,22 +41,23 @@ typedef enum
|
||||
/*Data of progress bar*/
|
||||
typedef struct
|
||||
{
|
||||
lv_rect_ext_t rect_ext;
|
||||
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
uint16_t act_value;
|
||||
uint16_t min_value;
|
||||
uint16_t max_value;
|
||||
char * format_dp; /*Format string of the label*/
|
||||
char * format; /*Format string of the label*/
|
||||
}lv_pb_ext_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_pb_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_pb_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
void lv_pb_set_value(lv_obj_t * obj_dp, uint16_t value);
|
||||
void lv_pb_set_min_max_value(lv_obj_t * obj_dp, uint16_t min, uint16_t max);
|
||||
void lv_pb_set_format(lv_obj_t * obj_dp, const char * format);
|
||||
uint16_t lv_pb_get_value(lv_obj_t * obj_dp);
|
||||
lv_obj_t * lv_pb_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_pb_signal(lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||
void lv_pb_set_value(lv_obj_t * obj, uint16_t value);
|
||||
void lv_pb_set_min_max_value(lv_obj_t * obj, uint16_t min, uint16_t max);
|
||||
void lv_pb_set_format(lv_obj_t * obj, const char * format);
|
||||
uint16_t lv_pb_get_value(lv_obj_t * obj);
|
||||
lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy_p);
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -6,20 +6,22 @@
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_conf.h"
|
||||
|
||||
#if USE_LV_RECT != 0
|
||||
|
||||
#include <lvgl/lv_misc/area.h>
|
||||
#include <misc/mem/dyn_mem.h>
|
||||
#include <misc/mem/linked_list.h>
|
||||
#include <misc/others/color.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#if USE_LV_RECT != 0
|
||||
|
||||
#include "lv_rect.h"
|
||||
#include "../lv_draw/lv_draw.h"
|
||||
#include "../lv_draw/lv_draw_vbasic.h"
|
||||
#include "../lv_misc/area.h"
|
||||
|
||||
#include "misc/mem/dyn_mem.h"
|
||||
#include "misc/mem/linked_list.h"
|
||||
#include "misc/others/color.h"
|
||||
#include "misc/math/math_base.h"
|
||||
|
||||
/*********************
|
||||
@@ -33,14 +35,14 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_rects_init(void);
|
||||
static void lv_rect_refr_layout(lv_obj_t * obj_dp);
|
||||
static void lv_rect_layout_col(lv_obj_t * obj_dp);
|
||||
static void lv_rect_layout_row(lv_obj_t * obj_dp);
|
||||
static void lv_rect_layout_center(lv_obj_t * obj_dp);
|
||||
static void lv_rect_layout_grid(lv_obj_t * obj_dp);
|
||||
static void lv_rect_refr_autofit(lv_obj_t * obj_dp);
|
||||
static void lv_rect_refr_layout(lv_obj_t * rect);
|
||||
static void lv_rect_layout_col(lv_obj_t * rect);
|
||||
static void lv_rect_layout_row(lv_obj_t * rect);
|
||||
static void lv_rect_layout_center(lv_obj_t * rect);
|
||||
static void lv_rect_layout_grid(lv_obj_t * rect);
|
||||
static void lv_rect_refr_autofit(lv_obj_t * rect);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -63,47 +65,49 @@ static lv_rects_t lv_rects_border;
|
||||
|
||||
/**
|
||||
* Create a label objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new label
|
||||
* @param copy_dp pointer to a rectangle object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new label
|
||||
* @param copy pointer to a rectangle object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created label
|
||||
*/
|
||||
lv_obj_t* lv_rect_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_rect_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create a basic object*/
|
||||
lv_obj_t* new_obj_dp = lv_obj_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_alloc_ext(new_obj_dp, sizeof(lv_rect_ext_t));
|
||||
lv_rect_ext_t * rect_ext_dp = lv_obj_get_ext(new_obj_dp);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_rect_design);
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_rect_signal);
|
||||
lv_obj_t * new_rect = lv_obj_create(par, copy);
|
||||
dm_assert(new_rect);
|
||||
lv_obj_alloc_ext(new_rect, sizeof(lv_rect_ext_t));
|
||||
lv_rect_ext_t * rect_ext = lv_obj_get_ext(new_rect);
|
||||
lv_obj_set_design_f(new_rect, lv_rect_design);
|
||||
lv_obj_set_signal_f(new_rect, lv_rect_signal);
|
||||
|
||||
/*Init the new rectangle*/
|
||||
if(copy_dp == NULL) {
|
||||
lv_obj_set_style(new_obj_dp, lv_rects_get(LV_RECTS_DEF, NULL));
|
||||
rect_ext_dp->hfit_en = 0;
|
||||
rect_ext_dp->vfit_en = 0;
|
||||
} else {
|
||||
lv_rect_ext_t * ori_rect_ext = lv_obj_get_ext(copy_dp);
|
||||
rect_ext_dp->hfit_en = ori_rect_ext->hfit_en;
|
||||
rect_ext_dp->vfit_en = ori_rect_ext->vfit_en;
|
||||
rect_ext_dp->layout = ori_rect_ext->layout;
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_style(new_rect, lv_rects_get(LV_RECTS_DEF, NULL));
|
||||
rect_ext->hfit_en = 0;
|
||||
rect_ext->vfit_en = 0;
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
lv_rect_ext_t * ori_rect_ext = lv_obj_get_ext(copy);
|
||||
rect_ext->hfit_en = ori_rect_ext->hfit_en;
|
||||
rect_ext->vfit_en = ori_rect_ext->vfit_en;
|
||||
rect_ext->layout = ori_rect_ext->layout;
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_rect;
|
||||
}
|
||||
uint32_t sign_cnt = 0;
|
||||
|
||||
/**
|
||||
* Signal function of the rectangle
|
||||
* @param obj_dp pointer to a rectangle object
|
||||
* @param rect pointer to a rectangle object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
*/
|
||||
bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_rect_signal(lv_obj_t * rect, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_obj_signal(obj_dp, sign, param);
|
||||
valid = lv_obj_signal(rect, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
@@ -111,16 +115,14 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_STYLE_CHG: /*Recalculate the padding if the style changed*/
|
||||
case LV_SIGNAL_CHILD_CHG:
|
||||
sign_cnt++;
|
||||
lv_rect_refr_layout(obj_dp);
|
||||
lv_rect_refr_autofit(obj_dp);
|
||||
lv_rect_refr_layout(rect);
|
||||
lv_rect_refr_autofit(rect);
|
||||
break;
|
||||
case LV_SIGNAL_CORD_CHG:
|
||||
sign_cnt++;
|
||||
if(lv_obj_get_width(obj_dp) != area_get_width(param) ||
|
||||
lv_obj_get_height(obj_dp) != area_get_height(param)) {
|
||||
lv_rect_refr_layout(obj_dp);
|
||||
lv_rect_refr_autofit(obj_dp);
|
||||
if(lv_obj_get_width(rect) != area_get_width(param) ||
|
||||
lv_obj_get_height(rect) != area_get_height(param)) {
|
||||
lv_rect_refr_layout(rect);
|
||||
lv_rect_refr_autofit(rect);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -139,73 +141,84 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
void lv_rect_set_layout(lv_obj_t * obj_dp, lv_rect_layout_t layout)
|
||||
/**
|
||||
* Set the layout on a rectangle
|
||||
* @param rect pointer to a rectangle object
|
||||
* @param layout a layout from 'lv_rect_layout_t'
|
||||
*/
|
||||
void lv_rect_set_layout(lv_obj_t * rect, lv_rect_layout_t layout)
|
||||
{
|
||||
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
ext_p->layout = layout;
|
||||
lv_rect_ext_t * ext = lv_obj_get_ext(rect);
|
||||
ext->layout = layout;
|
||||
|
||||
/*Send a signal to run the paddig calculations*/
|
||||
obj_dp->signal_f(obj_dp, LV_SIGNAL_CHILD_CHG, NULL);
|
||||
/*Send a signal to refresh the layout*/
|
||||
rect->signal_f(rect, LV_SIGNAL_CHILD_CHG, NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable the horizontal or vertical padding
|
||||
* @param obj_dp pointer to a rectangle object
|
||||
* Enable the horizontal or vertical fit.
|
||||
* The rectangle size will be set to involve the children horizontally or vertically.
|
||||
* @param rect pointer to a rectangle object
|
||||
* @param hor_en true: enable the horizontal padding
|
||||
* @param ver_en true: enable the vertical padding
|
||||
*/
|
||||
void lv_rect_set_fit(lv_obj_t * obj_dp, bool hor_en, bool ver_en)
|
||||
void lv_rect_set_fit(lv_obj_t * rect, bool hor_en, bool ver_en)
|
||||
{
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
ext_p->hfit_en = hor_en == false ? 0 : 1;
|
||||
ext_p->vfit_en = ver_en == false ? 0 : 1;
|
||||
lv_obj_inv(rect);
|
||||
lv_rect_ext_t * ext = lv_obj_get_ext(rect);
|
||||
ext->hfit_en = hor_en == false ? 0 : 1;
|
||||
ext->vfit_en = ver_en == false ? 0 : 1;
|
||||
|
||||
/*Send a signal to run the paddig calculations*/
|
||||
obj_dp->signal_f(obj_dp, LV_SIGNAL_CORD_CHG, obj_dp);
|
||||
/*Send a signal to set a new size*/
|
||||
rect->signal_f(rect, LV_SIGNAL_CORD_CHG, rect);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
lv_rect_layout_t lv_rect_get_layout(lv_obj_t * obj_dp)
|
||||
/**
|
||||
* Get the layout of a rectangle
|
||||
* @param rect pointer to rectangle object
|
||||
* @return the layout from 'lv_rect_layout_t'
|
||||
*/
|
||||
lv_rect_layout_t lv_rect_get_layout(lv_obj_t * rect)
|
||||
{
|
||||
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
return ext_p->layout;
|
||||
lv_rect_ext_t * ext = lv_obj_get_ext(rect);
|
||||
return ext->layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get horizontal padding enable attribute of a rectangle
|
||||
* @param obj_dp pointer to a rectangle object
|
||||
* Get horizontal fit enable attribute of a rectangle
|
||||
* @param rect pointer to a rectangle object
|
||||
* @return true: horizontal padding is enabled
|
||||
*/
|
||||
bool lv_rect_get_hfit(lv_obj_t * obj_dp)
|
||||
bool lv_rect_get_hfit(lv_obj_t * rect)
|
||||
{
|
||||
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
return ext_p->hfit_en == 0 ? false : true;
|
||||
lv_rect_ext_t * ext = lv_obj_get_ext(rect);
|
||||
return ext->hfit_en == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get vertical padding enable attribute of a rectangle
|
||||
* @param obj_dp pointer to a rectangle object
|
||||
* Get vertical fit enable attribute of a rectangle
|
||||
* @param obj pointer to a rectangle object
|
||||
* @return true: vertical padding is enabled
|
||||
*/
|
||||
bool lv_rect_get_vfit(lv_obj_t * obj_dp)
|
||||
bool lv_rect_get_vfit(lv_obj_t * rect)
|
||||
{
|
||||
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
return ext_p->vfit_en == 0 ? false : true;
|
||||
lv_rect_ext_t * ext = lv_obj_get_ext(rect);
|
||||
return ext->vfit_en == 0 ? false : true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_rects_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_rects_t style
|
||||
*/
|
||||
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p)
|
||||
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -231,9 +244,9 @@ lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p)
|
||||
style_p = &lv_rects_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_rects_t));
|
||||
else memcpy(copy_p, &lv_rects_def, sizeof(lv_rects_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_rects_t));
|
||||
else memcpy(copy, &lv_rects_def, sizeof(lv_rects_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -246,7 +259,7 @@ lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p)
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the rectangles
|
||||
* @param obj_dp pointer to an object
|
||||
* @param rect pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -254,39 +267,335 @@ lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
/* Because of the radius it is not sure the area is covered*/
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
if(LV_SA(obj_dp, lv_rects_t)->empty != 0) return false;
|
||||
if(LV_SA(rect, lv_rects_t)->empty != 0) return false;
|
||||
|
||||
uint16_t r = LV_SA(obj_dp, lv_rects_t)->round;
|
||||
uint16_t r = LV_SA(rect, lv_rects_t)->round;
|
||||
area_t area_tmp;
|
||||
|
||||
/*Check horizontally without radius*/
|
||||
lv_obj_get_cords(obj_dp, &area_tmp);
|
||||
lv_obj_get_cords(rect, &area_tmp);
|
||||
area_tmp.x1 += r;
|
||||
area_tmp.x2 -= r;
|
||||
if(area_is_in(mask_p, &area_tmp) == true) return true;
|
||||
if(area_is_in(mask, &area_tmp) == true) return true;
|
||||
|
||||
/*Check vertically without radius*/
|
||||
lv_obj_get_cords(obj_dp, &area_tmp);
|
||||
lv_obj_get_cords(rect, &area_tmp);
|
||||
area_tmp.y1 += r;
|
||||
area_tmp.y2 -= r;
|
||||
if(area_is_in(mask_p, &area_tmp) == true) return true;
|
||||
if(area_is_in(mask, &area_tmp) == true) return true;
|
||||
|
||||
return false;
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
opa_t opa = lv_obj_get_opa(obj_dp);
|
||||
opa_t opa = lv_obj_get_opa(rect);
|
||||
area_t area;
|
||||
lv_obj_get_cords(obj_dp, &area);
|
||||
lv_obj_get_cords(rect, &area);
|
||||
|
||||
/*Draw the rectangle*/
|
||||
lv_draw_rect(&area, mask_p, lv_obj_get_style(obj_dp), opa);
|
||||
lv_draw_rect(&area, mask, lv_obj_get_style(rect), opa);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the layout of a rectangle
|
||||
* @param rect pointer to an object which layout should be refreshed
|
||||
*/
|
||||
static void lv_rect_refr_layout(lv_obj_t * rect)
|
||||
{
|
||||
lv_rect_layout_t type = lv_rect_get_layout(rect);
|
||||
|
||||
if(type == LV_RECT_LAYOUT_OFF) return;
|
||||
|
||||
if(type == LV_RECT_LAYOUT_CENTER) {
|
||||
lv_rect_layout_center(rect);
|
||||
} else if(type == LV_RECT_LAYOUT_COL_L || type == LV_RECT_LAYOUT_COL_M || type == LV_RECT_LAYOUT_COL_R) {
|
||||
lv_rect_layout_col(rect);
|
||||
} else if(type == LV_RECT_LAYOUT_ROW_T || type == LV_RECT_LAYOUT_ROW_M || type == LV_RECT_LAYOUT_ROW_B) {
|
||||
lv_rect_layout_row(rect);
|
||||
} else if(type == LV_RECT_LAYOUT_GRID) {
|
||||
lv_rect_layout_grid(rect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle column type layouts
|
||||
* @param rect pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_col(lv_obj_t * rect)
|
||||
{
|
||||
lv_rect_layout_t type = lv_rect_get_layout(rect);
|
||||
lv_obj_t * child;
|
||||
|
||||
/*Adjust margin and get the alignment type*/
|
||||
lv_align_t align;
|
||||
lv_rects_t * style = lv_obj_get_style(rect);
|
||||
cord_t hpad_corr;
|
||||
|
||||
switch(type) {
|
||||
case LV_RECT_LAYOUT_COL_L:
|
||||
hpad_corr = style->hpad;
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_COL_M:
|
||||
hpad_corr = 0;
|
||||
align = LV_ALIGN_IN_TOP_MID;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_COL_R:
|
||||
hpad_corr = -style->hpad;
|
||||
align = LV_ALIGN_IN_TOP_RIGHT;
|
||||
break;
|
||||
default:
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
rect->child_chg_off = 1;
|
||||
/* Align the children */
|
||||
cord_t last_cord = style->vpad;
|
||||
LL_READ_BACK(rect->child_ll, child) {
|
||||
if(lv_obj_get_hidden(child) != false) continue;
|
||||
|
||||
lv_obj_align(child, rect, align, hpad_corr , last_cord);
|
||||
last_cord += lv_obj_get_height(child) + style->opad;
|
||||
}
|
||||
|
||||
rect->child_chg_off = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle row type layouts
|
||||
* @param rect pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_row(lv_obj_t * rect)
|
||||
{
|
||||
lv_rect_layout_t type = lv_rect_get_layout(rect);
|
||||
lv_obj_t * child;
|
||||
|
||||
/*Adjust margin and get the alignment type*/
|
||||
lv_align_t align;
|
||||
lv_rects_t * style = lv_obj_get_style(rect);
|
||||
cord_t vpad_corr = style->vpad;
|
||||
|
||||
switch(type) {
|
||||
case LV_RECT_LAYOUT_ROW_T:
|
||||
vpad_corr = style->vpad;
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_ROW_M:
|
||||
vpad_corr = 0;
|
||||
align = LV_ALIGN_IN_LEFT_MID;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_ROW_B:
|
||||
vpad_corr = -style->vpad;
|
||||
align = LV_ALIGN_IN_BOTTOM_LEFT;
|
||||
break;
|
||||
default:
|
||||
vpad_corr = 0;
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
rect->child_chg_off = 1;
|
||||
|
||||
/* Align the children */
|
||||
cord_t last_cord = style->hpad;
|
||||
LL_READ_BACK(rect->child_ll, child) {
|
||||
if(lv_obj_get_hidden(child) != false) continue;
|
||||
|
||||
lv_obj_align(child, rect, align, last_cord, vpad_corr);
|
||||
last_cord += lv_obj_get_width(child) + style->opad;
|
||||
}
|
||||
|
||||
rect->child_chg_off = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the center layout
|
||||
* @param rect pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_center(lv_obj_t * rect)
|
||||
{
|
||||
lv_obj_t * child;
|
||||
lv_rects_t * style = lv_obj_get_style(rect);
|
||||
uint32_t obj_num = 0;
|
||||
cord_t h_tot = 0;
|
||||
|
||||
LL_READ(rect->child_ll, child) {
|
||||
h_tot += lv_obj_get_height(child) + style->opad;
|
||||
obj_num ++;
|
||||
}
|
||||
|
||||
if(obj_num == 0) return;
|
||||
|
||||
h_tot -= style->opad;
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
rect->child_chg_off = 1;
|
||||
|
||||
/* Align the children */
|
||||
cord_t last_cord = - (h_tot / 2);
|
||||
LL_READ_BACK(rect->child_ll, child) {
|
||||
if(lv_obj_get_hidden(child) != false) continue;
|
||||
|
||||
lv_obj_align(child, rect, LV_ALIGN_CENTER, 0, last_cord + lv_obj_get_height(child) / 2);
|
||||
last_cord += lv_obj_get_height(child) + style->opad;
|
||||
}
|
||||
|
||||
rect->child_chg_off = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the grid layout. Put as many object as possible in row
|
||||
* then begin a new row
|
||||
* @param rect pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_grid(lv_obj_t * rect)
|
||||
{
|
||||
lv_obj_t * child_rs; /* Row starter child */
|
||||
lv_obj_t * child_rc; /* Row closer child */
|
||||
lv_obj_t * child_tmp; /* Temporary child */
|
||||
lv_rects_t * style = lv_obj_get_style(rect);
|
||||
cord_t w_obj = lv_obj_get_width(rect);
|
||||
cord_t act_y = style->vpad;
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
|
||||
child_rs = ll_get_tail(&rect->child_ll); /*Set the row starter child*/
|
||||
if(child_rs == NULL) return; /*Return if no child*/
|
||||
|
||||
rect->child_chg_off = 1;
|
||||
|
||||
child_rc = child_rs; /*Initially the the row starter and closer is the same*/
|
||||
while(child_rs != NULL) {
|
||||
cord_t h_row = 0;
|
||||
cord_t w_row = style->hpad * 2; /*The width is minimum the left-right hpad*/
|
||||
uint32_t obj_num = 0;
|
||||
|
||||
/*Find the row closer object and collect some data*/ do {
|
||||
if(lv_obj_get_hidden(child_rc) == false) {
|
||||
if(w_row + lv_obj_get_width(child_rc) > w_obj) break; /*If the next object is already not fit then break*/
|
||||
w_row += lv_obj_get_width(child_rc) + style->opad; /*Add the object width + opad*/
|
||||
h_row = max(h_row, lv_obj_get_height(child_rc)); /*Search the highest object*/
|
||||
obj_num ++;
|
||||
}
|
||||
child_rc = ll_get_prev(&rect->child_ll, child_rc); /*Load the next object*/
|
||||
if(obj_num == 0) child_rs = child_rc; /*If the first object was hidden (or too long) then set the next as first */
|
||||
}while(child_rc != NULL);
|
||||
|
||||
/*Step back one child because the last is already not fit*/
|
||||
if(child_rc != NULL && obj_num != 0) child_rc = ll_get_next(&rect->child_ll, child_rc);
|
||||
|
||||
/*If the object is too long then align it to the middle*/
|
||||
if(obj_num == 0) {
|
||||
if(child_rc != NULL) {
|
||||
h_row = lv_obj_get_height(child_rc);
|
||||
lv_obj_align(child_rc, rect, LV_ALIGN_IN_TOP_MID, 0, act_y);
|
||||
}
|
||||
}
|
||||
/*If here is only one object in the row then align it to the left*/
|
||||
else if (obj_num == 1) {
|
||||
lv_obj_align(child_rs, rect, LV_ALIGN_IN_TOP_LEFT, style->hpad, act_y);
|
||||
}
|
||||
/* Align the children (from child_rs to child_rc)*/
|
||||
else {
|
||||
w_row -= style->opad * obj_num;
|
||||
cord_t new_opad = (w_obj - w_row) / (obj_num - 1);
|
||||
cord_t act_x = style->hpad; /*x init*/
|
||||
child_tmp = child_rs;
|
||||
do{
|
||||
if(lv_obj_get_hidden(child_tmp) == false) {
|
||||
lv_obj_align(child_tmp, rect, LV_ALIGN_IN_TOP_LEFT, act_x, act_y);
|
||||
act_x += lv_obj_get_width(child_tmp) + new_opad;
|
||||
}
|
||||
child_tmp = ll_get_prev(&rect->child_ll, child_tmp);
|
||||
}while(child_tmp != child_rc);
|
||||
|
||||
}
|
||||
|
||||
if(child_rc == NULL) break;
|
||||
act_y += style->opad + h_row; /*y increment*/
|
||||
child_rs = ll_get_prev(&rect->child_ll, child_rc); /*Go to the next object*/
|
||||
child_rc = child_rs;
|
||||
}
|
||||
rect->child_chg_off = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle auto fit. Set the size of the object to involve all children.
|
||||
* @param rect pointer to an object which size will be modified
|
||||
*/
|
||||
void lv_rect_refr_autofit(lv_obj_t * rect)
|
||||
{
|
||||
lv_rect_ext_t * ext = lv_obj_get_ext(rect);
|
||||
|
||||
if(ext->hfit_en == 0 &&
|
||||
ext->vfit_en == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
area_t rect_cords;
|
||||
area_t ori;
|
||||
lv_rects_t * style = lv_obj_get_style(rect);
|
||||
lv_obj_t * i;
|
||||
cord_t hpad = style->hpad;
|
||||
cord_t vpad = style->vpad;
|
||||
|
||||
/*Search the side coordinates of the children*/
|
||||
lv_obj_get_cords(rect, &ori);
|
||||
lv_obj_get_cords(rect, &rect_cords);
|
||||
|
||||
rect_cords.x1 = LV_CORD_MAX;
|
||||
rect_cords.y1 = LV_CORD_MAX;
|
||||
rect_cords.x2 = LV_CORD_MIN;
|
||||
rect_cords.y2 = LV_CORD_MIN;
|
||||
|
||||
LL_READ(rect->child_ll, i) {
|
||||
if(lv_obj_get_hidden(i) != false) continue;
|
||||
rect_cords.x1 = min(rect_cords.x1, i->cords.x1);
|
||||
rect_cords.y1 = min(rect_cords.y1, i->cords.y1);
|
||||
rect_cords.x2 = max(rect_cords.x2, i->cords.x2);
|
||||
rect_cords.y2 = max(rect_cords.y2, i->cords.y2);
|
||||
}
|
||||
|
||||
/*If the value is not the init value then the page has >=1 child.*/
|
||||
if(rect_cords.x1 != LV_CORD_MAX) {
|
||||
if(ext->hfit_en != 0) {
|
||||
rect_cords.x1 -= hpad;
|
||||
rect_cords.x2 += hpad;
|
||||
} else {
|
||||
rect_cords.x1 = rect->cords.x1;
|
||||
rect_cords.x2 = rect->cords.x2;
|
||||
}
|
||||
if(ext->vfit_en != 0) {
|
||||
rect_cords.y1 -= vpad;
|
||||
rect_cords.y2 += vpad;
|
||||
} else {
|
||||
rect_cords.y1 = rect->cords.y1;
|
||||
rect_cords.y2 = rect->cords.y2;
|
||||
}
|
||||
|
||||
lv_obj_inv(rect);
|
||||
area_cpy(&rect->cords, &rect_cords);
|
||||
lv_obj_inv(rect);
|
||||
|
||||
/*Notify the object about its new coordinates*/
|
||||
rect->signal_f(rect, LV_SIGNAL_CORD_CHG, &ori);
|
||||
|
||||
/*Inform the parent about the new coordinates*/
|
||||
lv_obj_t * par = lv_obj_get_parent(rect);
|
||||
par->signal_f(par, LV_SIGNAL_CHILD_CHG, rect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the rectangle styles
|
||||
*/
|
||||
@@ -318,303 +627,4 @@ static void lv_rects_init(void)
|
||||
lv_rects_border.round = 4 * LV_STYLE_MULT;
|
||||
lv_rects_border.empty = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the layout of a rectangle
|
||||
* @param obj_dp pointer to an object which layout should be refreshed
|
||||
*/
|
||||
static void lv_rect_refr_layout(lv_obj_t * obj_dp)
|
||||
{
|
||||
lv_rect_layout_t type = lv_rect_get_layout(obj_dp);
|
||||
|
||||
if(type == LV_RECT_LAYOUT_OFF) return;
|
||||
|
||||
if(type == LV_RECT_LAYOUT_CENTER) {
|
||||
lv_rect_layout_center(obj_dp);
|
||||
} else if(type == LV_RECT_LAYOUT_COL_L || type == LV_RECT_LAYOUT_COL_M || type == LV_RECT_LAYOUT_COL_R) {
|
||||
lv_rect_layout_col(obj_dp);
|
||||
} else if(type == LV_RECT_LAYOUT_ROW_T || type == LV_RECT_LAYOUT_ROW_M || type == LV_RECT_LAYOUT_ROW_B) {
|
||||
lv_rect_layout_row(obj_dp);
|
||||
} else if(type == LV_RECT_LAYOUT_GRID) {
|
||||
lv_rect_layout_grid(obj_dp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle column type layouts
|
||||
* @param obj_dp pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_col(lv_obj_t * obj_dp)
|
||||
{
|
||||
lv_rect_layout_t type = lv_rect_get_layout(obj_dp);
|
||||
lv_obj_t * child;
|
||||
|
||||
/*Adjust margin and get the alignment type*/
|
||||
lv_align_t align;
|
||||
lv_rects_t * rects_p = lv_obj_get_style(obj_dp);
|
||||
cord_t hpad_corr;
|
||||
switch(type) {
|
||||
case LV_RECT_LAYOUT_COL_L:
|
||||
hpad_corr = rects_p->hpad;
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_COL_M:
|
||||
hpad_corr = 0;
|
||||
align = LV_ALIGN_IN_TOP_MID;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_COL_R:
|
||||
hpad_corr = -rects_p->hpad;
|
||||
align = LV_ALIGN_IN_TOP_RIGHT;
|
||||
break;
|
||||
default:
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
obj_dp->child_chg_off = 1;
|
||||
/* Align the children */
|
||||
cord_t last_cord = rects_p->vpad;
|
||||
LL_READ_BACK(obj_dp->child_ll, child) {
|
||||
if(lv_obj_get_hidden(child) != false) continue;
|
||||
|
||||
lv_obj_align(child, obj_dp, align, hpad_corr , last_cord);
|
||||
last_cord += lv_obj_get_height(child) + rects_p->opad;
|
||||
}
|
||||
|
||||
obj_dp->child_chg_off = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle row type layouts
|
||||
* @param obj_dp pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_row(lv_obj_t * obj_dp)
|
||||
{
|
||||
lv_rect_layout_t type = lv_rect_get_layout(obj_dp);
|
||||
lv_obj_t * child;
|
||||
|
||||
/*Adjust margin and get the alignment type*/
|
||||
lv_align_t align;
|
||||
lv_rects_t * rects_p = lv_obj_get_style(obj_dp);
|
||||
cord_t vpad_corr = rects_p->vpad;
|
||||
switch(type) {
|
||||
case LV_RECT_LAYOUT_ROW_T:
|
||||
vpad_corr = rects_p->vpad;
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_ROW_M:
|
||||
vpad_corr = 0;
|
||||
align = LV_ALIGN_IN_LEFT_MID;
|
||||
break;
|
||||
case LV_RECT_LAYOUT_ROW_B:
|
||||
vpad_corr = -rects_p->vpad;
|
||||
align = LV_ALIGN_IN_BOTTOM_LEFT;
|
||||
break;
|
||||
default:
|
||||
vpad_corr = 0;
|
||||
align = LV_ALIGN_IN_TOP_LEFT;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
obj_dp->child_chg_off = 1;
|
||||
|
||||
|
||||
/* Align the children */
|
||||
cord_t last_cord = rects_p->hpad;
|
||||
LL_READ_BACK(obj_dp->child_ll, child) {
|
||||
if(lv_obj_get_hidden(child) != false) continue;
|
||||
|
||||
lv_obj_align(child, obj_dp, align, last_cord, vpad_corr);
|
||||
last_cord += lv_obj_get_width(child) + rects_p->opad;
|
||||
}
|
||||
|
||||
obj_dp->child_chg_off = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the center layout
|
||||
* @param obj_dp pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_center(lv_obj_t * obj_dp)
|
||||
{
|
||||
lv_obj_t * child;
|
||||
lv_rects_t * rects_p = lv_obj_get_style(obj_dp);
|
||||
uint32_t obj_num = 0;
|
||||
cord_t h_tot = 0;
|
||||
|
||||
LL_READ(obj_dp->child_ll, child) {
|
||||
h_tot += lv_obj_get_height(child) + rects_p->opad;
|
||||
obj_num ++;
|
||||
}
|
||||
|
||||
if(obj_num == 0) return;
|
||||
|
||||
h_tot -= rects_p->opad;
|
||||
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
obj_dp->child_chg_off = 1;
|
||||
|
||||
/* Align the children */
|
||||
cord_t last_cord = - (h_tot / 2);
|
||||
LL_READ_BACK(obj_dp->child_ll, child) {
|
||||
if(lv_obj_get_hidden(child) != false) continue;
|
||||
|
||||
lv_obj_align(child, obj_dp, LV_ALIGN_CENTER, 0, last_cord + lv_obj_get_height(child) / 2);
|
||||
last_cord += lv_obj_get_height(child) + rects_p->opad;
|
||||
}
|
||||
|
||||
obj_dp->child_chg_off = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle the grid layout. Put as many object as possible in row
|
||||
* then begin a new row
|
||||
* @param obj_dp pointer to an object which layout should be handled
|
||||
*/
|
||||
static void lv_rect_layout_grid(lv_obj_t * obj_dp)
|
||||
{
|
||||
lv_obj_t * child_rs; /* Row starter child */
|
||||
lv_obj_t * child_rc; /* Row closer child */
|
||||
lv_obj_t * child_tmp; /* Temporary child */
|
||||
lv_rects_t * rects_p = lv_obj_get_style(obj_dp);
|
||||
cord_t w_obj = lv_obj_get_width(obj_dp);
|
||||
cord_t act_y = rects_p->vpad;
|
||||
/* Disable child change action because the children will be moved a lot
|
||||
* an unnecessary child change signals could be sent*/
|
||||
|
||||
child_rs = ll_get_tail(&obj_dp->child_ll); /*Set the row starter child*/
|
||||
if(child_rs == NULL) return; /*Return if no child*/
|
||||
|
||||
obj_dp->child_chg_off = 1;
|
||||
|
||||
child_rc = child_rs; /*Initially the the row starter and closer is the same*/
|
||||
while(child_rs != NULL) {
|
||||
cord_t h_row = 0;
|
||||
cord_t w_row = rects_p->hpad * 2; /*The width is minimum the left-right hpad*/
|
||||
uint32_t obj_num = 0;
|
||||
|
||||
/*Find the row closer object and collect some data*/ do {
|
||||
if(lv_obj_get_hidden(child_rc) == false) {
|
||||
if(w_row + lv_obj_get_width(child_rc) > w_obj) break; /*If the next object is already not fit then break*/
|
||||
w_row += lv_obj_get_width(child_rc) + rects_p->opad; /*Add the object width + opad*/
|
||||
h_row = max(h_row, lv_obj_get_height(child_rc)); /*Search the highest object*/
|
||||
obj_num ++;
|
||||
}
|
||||
child_rc = ll_get_prev(&obj_dp->child_ll, child_rc); /*Load the next object*/
|
||||
if(obj_num == 0) child_rs = child_rc; /*If the first object was hidden (or too long) then set the next as first */
|
||||
}while(child_rc != NULL);
|
||||
|
||||
/*Step back one child because the last is already not fit*/
|
||||
if(child_rc != NULL && obj_num != 0) child_rc = ll_get_next(&obj_dp->child_ll, child_rc);
|
||||
|
||||
/*If the object is too long then align it to the middle*/
|
||||
if(obj_num == 0) {
|
||||
if(child_rc != NULL) {
|
||||
h_row = lv_obj_get_height(child_rc);
|
||||
lv_obj_align(child_rc, obj_dp, LV_ALIGN_IN_TOP_MID, 0, act_y);
|
||||
}
|
||||
}
|
||||
/*If here is only one object in the row then align it to the left*/
|
||||
else if (obj_num == 1) {
|
||||
lv_obj_align(child_rs, obj_dp, LV_ALIGN_IN_TOP_LEFT, rects_p->hpad, act_y);
|
||||
}
|
||||
/* Align the children (from child_rs to child_rc)*/
|
||||
else {
|
||||
w_row -= rects_p->opad * obj_num;
|
||||
cord_t new_opad = (w_obj - w_row) / (obj_num - 1);
|
||||
cord_t act_x = rects_p->hpad; /*x init*/
|
||||
child_tmp = child_rs;
|
||||
do{
|
||||
if(lv_obj_get_hidden(child_tmp) == false) {
|
||||
lv_obj_align(child_tmp, obj_dp, LV_ALIGN_IN_TOP_LEFT, act_x, act_y);
|
||||
act_x += lv_obj_get_width(child_tmp) + new_opad;
|
||||
}
|
||||
child_tmp = ll_get_prev(&obj_dp->child_ll, child_tmp);
|
||||
}while(child_tmp != child_rc);
|
||||
|
||||
}
|
||||
|
||||
if(child_rc == NULL) break;
|
||||
act_y += rects_p->opad + h_row; /*y increment*/
|
||||
child_rs = ll_get_prev(&obj_dp->child_ll, child_rc); /*Go to the next object*/
|
||||
child_rc = child_rs;
|
||||
}
|
||||
obj_dp->child_chg_off = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle auto fit. Set the size of the object to involve all children.
|
||||
* @param obj_dp pointer to an object which size will be modified
|
||||
*/
|
||||
void lv_rect_refr_autofit(lv_obj_t * obj_dp)
|
||||
{
|
||||
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
|
||||
|
||||
if(ext_p->hfit_en == 0 &&
|
||||
ext_p->vfit_en == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
area_t rect_cords;
|
||||
area_t ori;
|
||||
lv_rects_t * rects_p = lv_obj_get_style(obj_dp);
|
||||
lv_obj_t * i;
|
||||
cord_t hpad = rects_p->hpad;
|
||||
cord_t vpad = rects_p->vpad;
|
||||
|
||||
/*Search the side coordinates of the children*/
|
||||
lv_obj_get_cords(obj_dp, &ori);
|
||||
lv_obj_get_cords(obj_dp, &rect_cords);
|
||||
|
||||
rect_cords.x1 = LV_CORD_MAX;
|
||||
rect_cords.y1 = LV_CORD_MAX;
|
||||
rect_cords.x2 = LV_CORD_MIN;
|
||||
rect_cords.y2 = LV_CORD_MIN;
|
||||
|
||||
LL_READ(obj_dp->child_ll, i) {
|
||||
if(lv_obj_get_hidden(i) != false) continue;
|
||||
rect_cords.x1 = min(rect_cords.x1, i->cords.x1);
|
||||
rect_cords.y1 = min(rect_cords.y1, i->cords.y1);
|
||||
rect_cords.x2 = max(rect_cords.x2, i->cords.x2);
|
||||
rect_cords.y2 = max(rect_cords.y2, i->cords.y2);
|
||||
}
|
||||
|
||||
/*If the value is not the init value then the page has >=1 child.*/
|
||||
if(rect_cords.x1 != LV_CORD_MAX) {
|
||||
if(ext_p->hfit_en != 0) {
|
||||
rect_cords.x1 -= hpad;
|
||||
rect_cords.x2 += hpad;
|
||||
} else {
|
||||
rect_cords.x1 = obj_dp->cords.x1;
|
||||
rect_cords.x2 = obj_dp->cords.x2;
|
||||
}
|
||||
if(ext_p->vfit_en != 0) {
|
||||
rect_cords.y1 -= vpad;
|
||||
rect_cords.y2 += vpad;
|
||||
} else {
|
||||
rect_cords.y1 = obj_dp->cords.y1;
|
||||
rect_cords.y2 = obj_dp->cords.y2;
|
||||
}
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
area_cpy(&obj_dp->cords, &rect_cords);
|
||||
lv_obj_inv(obj_dp);
|
||||
|
||||
/*Notify the object about its new coordinates*/
|
||||
obj_dp->signal_f(obj_dp, LV_SIGNAL_CORD_CHG, &ori);
|
||||
|
||||
/*Inform the parent about the new coordinates*/
|
||||
lv_obj_t * par_dp = lv_obj_get_parent(obj_dp);
|
||||
par_dp->signal_f(par_dp, LV_SIGNAL_CHILD_CHG, obj_dp);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,9 +37,11 @@ typedef enum
|
||||
LV_RECT_LAYOUT_GRID,
|
||||
}lv_rect_layout_t;
|
||||
|
||||
/*Style of template*/
|
||||
typedef struct
|
||||
{
|
||||
lv_objs_t objs;
|
||||
lv_objs_t objs; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
color_t gcolor;
|
||||
color_t bcolor;
|
||||
uint16_t bwidth;
|
||||
@@ -51,14 +53,7 @@ typedef struct
|
||||
uint8_t empty :1;
|
||||
}lv_rects_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t layout :5;
|
||||
uint8_t hfit_en :1;
|
||||
uint8_t vfit_en :1;
|
||||
}lv_rect_ext_t;
|
||||
|
||||
/*Built-in styles of template*/
|
||||
typedef enum
|
||||
{
|
||||
LV_RECTS_DEF,
|
||||
@@ -66,21 +61,30 @@ typedef enum
|
||||
LV_RECTS_BORDER,
|
||||
}lv_rects_builtin_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
uint8_t layout :5;
|
||||
uint8_t hfit_en :1;
|
||||
uint8_t vfit_en :1;
|
||||
}lv_rect_ext_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/*Create function*/
|
||||
lv_obj_t* lv_rect_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_obj_t * lv_rect_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_rect_signal(lv_obj_t * rect, lv_signal_t sign, void * param);
|
||||
|
||||
void lv_rect_set_fit(lv_obj_t * obj_dp, bool hor_en, bool ver_en);
|
||||
void lv_rect_set_layout(lv_obj_t * obj_dp, lv_rect_layout_t layout);
|
||||
void lv_rect_set_fit(lv_obj_t * rect, bool hor_en, bool ver_en);
|
||||
void lv_rect_set_layout(lv_obj_t * rect, lv_rect_layout_t layout);
|
||||
|
||||
lv_rect_layout_t lv_rect_get_layout(lv_obj_t * obj_dp);
|
||||
bool lv_rect_get_hfit(lv_obj_t * obj_dp);
|
||||
bool lv_rect_get_vfit(lv_obj_t * obj_dp);
|
||||
|
||||
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p);
|
||||
lv_rect_layout_t lv_rect_get_layout(lv_obj_t * rect);
|
||||
bool lv_rect_get_hfit(lv_obj_t * rect);
|
||||
bool lv_rect_get_vfit(lv_obj_t * rect);
|
||||
lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
339
lv_objx/lv_ta.c
339
lv_objx/lv_ta.c
@@ -25,9 +25,9 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_ta_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static bool lv_ta_label_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
|
||||
static void lv_ta_save_valid_cursor_x(lv_obj_t * obj_dp);
|
||||
static bool lv_ta_design(lv_obj_t * ta, const area_t * mask, lv_design_mode_t mode);
|
||||
static bool lv_ta_label_design(lv_obj_t * label, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_ta_save_valid_cursor_x(lv_obj_t * ta);
|
||||
static void lv_tas_init(void);
|
||||
|
||||
/**********************
|
||||
@@ -52,92 +52,91 @@ lv_design_f_t label_design_f;
|
||||
|
||||
/**
|
||||
* Create a text area objects
|
||||
* @param par_dp pointer to an object, it will be the parent of the new text area
|
||||
* @param copy_dp pointer to a text area object, if not NULL then the new object will be copied from it
|
||||
* @param par pointer to an object, it will be the parent of the new text area
|
||||
* @param copy pointer to a text area object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created text area
|
||||
*/
|
||||
lv_obj_t* lv_ta_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
|
||||
lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
{
|
||||
/*Create the ancestor object*/
|
||||
lv_obj_t* new_obj_dp = lv_page_create(par_dp, copy_dp);
|
||||
dm_assert(new_obj_dp);
|
||||
lv_obj_t * new_ta = lv_page_create(par, copy);
|
||||
dm_assert(new_ta);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_ta_ext_t * ext_dp = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_ta_ext_t));
|
||||
dm_assert(ext_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_alloc_ext(new_ta, sizeof(lv_ta_ext_t));
|
||||
dm_assert(ext);
|
||||
|
||||
if(ancestor_design_f == NULL) {
|
||||
ancestor_design_f = lv_obj_get_design_f(new_obj_dp);
|
||||
ancestor_design_f = lv_obj_get_design_f(new_ta);
|
||||
}
|
||||
|
||||
lv_obj_set_signal_f(new_obj_dp, lv_ta_signal);
|
||||
lv_obj_set_design_f(new_obj_dp, lv_ta_design);
|
||||
lv_obj_set_signal_f(new_ta, lv_ta_signal);
|
||||
lv_obj_set_design_f(new_ta, lv_ta_design);
|
||||
|
||||
ext_dp->cursor_valid_x = 0;
|
||||
ext_dp->cursor_pos = 0;
|
||||
ext->cursor_valid_x = 0;
|
||||
ext->cursor_pos = 0;
|
||||
|
||||
/*Init the new text area object*/
|
||||
if(copy_dp == NULL) {
|
||||
ext_dp->label_dp = lv_label_create(new_obj_dp, NULL);
|
||||
if(copy == NULL) {
|
||||
ext->label = lv_label_create(new_ta, NULL);
|
||||
if(label_design_f == NULL) {
|
||||
label_design_f = lv_obj_get_design_f(ext_dp->label_dp);
|
||||
label_design_f = lv_obj_get_design_f(ext->label);
|
||||
}
|
||||
lv_obj_set_design_f(ext_dp->label_dp, lv_ta_label_design);
|
||||
lv_label_set_fixw(ext_dp->label_dp, true);
|
||||
lv_label_set_text(ext_dp->label_dp, "abc aaaa bbbb ccc\n123\nABC\nxyz\nwww\n007\nalma\n:)\naaaaaa");
|
||||
lv_page_glue_obj(ext_dp->label_dp, true);
|
||||
lv_obj_set_click(ext_dp->label_dp, true);
|
||||
lv_obj_set_style(new_obj_dp, lv_tas_get(LV_TAS_DEF, NULL));
|
||||
|
||||
lv_obj_set_design_f(ext->label, lv_ta_label_design);
|
||||
lv_label_set_fixw(ext->label, true);
|
||||
lv_label_set_text(ext->label, "abc aaaa bbbb ccc\n123\nABC\nxyz\nwww\n007\nalma\n:)\naaaaaa");
|
||||
lv_page_glue_obj(ext->label, true);
|
||||
lv_obj_set_click(ext->label, true);
|
||||
lv_obj_set_style(new_ta, lv_tas_get(LV_TAS_DEF, NULL));
|
||||
}
|
||||
/*Copy an existing object*/
|
||||
else {
|
||||
lv_ta_ext_t * copy_ext_dp = lv_obj_get_ext(copy_dp);
|
||||
ext_dp->label_dp = lv_label_create(new_obj_dp, copy_ext_dp->label_dp);
|
||||
lv_obj_set_design_f(ext_dp->label_dp, lv_ta_label_design);
|
||||
lv_page_glue_obj(ext_dp->label_dp, true);
|
||||
lv_ta_ext_t * copy_ext = lv_obj_get_ext(copy);
|
||||
ext->label = lv_label_create(new_ta, copy_ext->label);
|
||||
lv_obj_set_design_f(ext->label, lv_ta_label_design);
|
||||
lv_page_glue_obj(ext->label, true);
|
||||
|
||||
/*Refresh the style when everything is ready*/
|
||||
lv_obj_set_style(new_obj_dp, lv_obj_get_style(copy_dp));
|
||||
lv_obj_set_style(new_ta, lv_obj_get_style(copy));
|
||||
}
|
||||
|
||||
return new_obj_dp;
|
||||
return new_ta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the text area
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return true: the object is still valid (not deleted), false: the object become invalid
|
||||
*/
|
||||
bool lv_ta_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
valid = lv_page_signal(obj_dp, sign, param);
|
||||
valid = lv_page_signal(ta, sign, param);
|
||||
|
||||
/* The object can be deleted so check its validity and then
|
||||
* make the object specific signal handling */
|
||||
if(valid != false) {
|
||||
lv_ta_ext_t * ta_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_tas_t * tas_p = lv_obj_get_style(obj_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
lv_tas_t * style = lv_obj_get_style(ta);
|
||||
switch(sign) {
|
||||
case LV_SIGNAL_CLEANUP:
|
||||
lv_obj_del(ta_ext_dp->label_dp);
|
||||
lv_obj_del(ext->label);
|
||||
break;
|
||||
case LV_SIGNAL_STYLE_CHG:
|
||||
lv_obj_set_style(ta_ext_dp->label_dp, &tas_p->labels);
|
||||
lv_obj_set_width(ta_ext_dp->label_dp, lv_obj_get_width(obj_dp) - 2 *
|
||||
(tas_p->pages.bg_rects.hpad + tas_p->pages.scrable_rects.hpad));
|
||||
lv_label_set_text(ta_ext_dp->label_dp, NULL);
|
||||
lv_obj_set_style(ext->label, &style->label);
|
||||
lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 *
|
||||
(style->pages.bg_rects.hpad + style->pages.scrable_rects.hpad));
|
||||
lv_label_set_text(ext->label, NULL);
|
||||
break;
|
||||
/*Set the label width according to the text area width*/
|
||||
case LV_SIGNAL_CORD_CHG:
|
||||
lv_obj_set_width(ta_ext_dp->label_dp, lv_obj_get_width(obj_dp) - 2 *
|
||||
(tas_p->pages.bg_rects.hpad + tas_p->pages.scrable_rects.hpad));
|
||||
lv_label_set_text(ta_ext_dp->label_dp, NULL);
|
||||
lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 *
|
||||
(style->pages.bg_rects.hpad + style->pages.scrable_rects.hpad));
|
||||
lv_label_set_text(ext->label, NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -153,201 +152,201 @@ bool lv_ta_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
|
||||
|
||||
/**
|
||||
* Insert a character to the current cursor position
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
* @param c a character
|
||||
*/
|
||||
void lv_ta_add_char(lv_obj_t * obj_dp, char c)
|
||||
void lv_ta_add_char(lv_obj_t * ta, char c)
|
||||
{
|
||||
lv_ta_ext_t * ta_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
|
||||
/*Insert the character*/
|
||||
char buf[LV_TA_MAX_LENGTH];
|
||||
const char * label_txt = lv_label_get_text(ta_dp->label_dp);
|
||||
const char * label_txt = lv_label_get_text(ext->label);
|
||||
|
||||
memcpy(buf, label_txt, ta_dp->cursor_pos);
|
||||
buf[ta_dp->cursor_pos] = c;
|
||||
memcpy(buf+ta_dp->cursor_pos+1, label_txt+ta_dp->cursor_pos, strlen(label_txt) - ta_dp->cursor_pos + 1);
|
||||
memcpy(buf, label_txt, ext->cursor_pos);
|
||||
buf[ext->cursor_pos] = c;
|
||||
memcpy(buf+ext->cursor_pos+1, label_txt+ext->cursor_pos, strlen(label_txt) - ext->cursor_pos + 1);
|
||||
|
||||
/*Refresh the label*/
|
||||
lv_label_set_text(ta_dp->label_dp, buf);
|
||||
lv_label_set_text(ext->label, buf);
|
||||
|
||||
/*Move the cursor after the new character*/
|
||||
lv_ta_set_cursor_pos(obj_dp, lv_ta_get_cursor_pos(obj_dp) + 1);
|
||||
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + 1);
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(obj_dp);
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a text to the current cursor position
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
* @param txt a '\0' terminated string to insert
|
||||
*/
|
||||
void lv_ta_add_text(lv_obj_t * obj_dp, const char * txt)
|
||||
void lv_ta_add_text(lv_obj_t * ta, const char * txt)
|
||||
{
|
||||
lv_ta_ext_t * ta_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
|
||||
/*Insert the text*/
|
||||
char buf[LV_TA_MAX_LENGTH];
|
||||
const char * label_txt = lv_label_get_text(ta_dp->label_dp);
|
||||
const char * label_txt = lv_label_get_text(ext->label);
|
||||
uint16_t label_len = strlen(label_txt);
|
||||
uint16_t txt_len = strlen(txt);
|
||||
|
||||
memcpy(buf, label_txt, ta_dp->cursor_pos);
|
||||
memcpy(buf+ta_dp->cursor_pos, txt, txt_len);
|
||||
memcpy(buf+ta_dp->cursor_pos + txt_len, label_txt+ta_dp->cursor_pos, label_len - ta_dp->cursor_pos + 1);
|
||||
memcpy(buf, label_txt, ext->cursor_pos);
|
||||
memcpy(buf+ext->cursor_pos, txt, txt_len);
|
||||
memcpy(buf+ext->cursor_pos + txt_len, label_txt+ext->cursor_pos, label_len - ext->cursor_pos + 1);
|
||||
|
||||
/*Refresh the label*/
|
||||
lv_label_set_text(ta_dp->label_dp, buf);
|
||||
lv_label_set_text(ext->label, buf);
|
||||
|
||||
/*Move the cursor after the new text*/
|
||||
lv_ta_set_cursor_pos(obj_dp, lv_ta_get_cursor_pos(obj_dp) + txt_len);
|
||||
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) + txt_len);
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(obj_dp);
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a the left character from the current cursor position
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
*/
|
||||
void lv_ta_del(lv_obj_t * obj_dp)
|
||||
void lv_ta_del(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ta_dp = lv_obj_get_ext(obj_dp);
|
||||
uint16_t cur_pos = ta_dp->cursor_pos;
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
uint16_t cur_pos = ext->cursor_pos;
|
||||
|
||||
if(cur_pos == 0) return;
|
||||
|
||||
/*Delete a character*/
|
||||
char buf[LV_TA_MAX_LENGTH];
|
||||
const char * label_txt = lv_label_get_text(ta_dp->label_dp);
|
||||
const char * label_txt = lv_label_get_text(ext->label);
|
||||
uint16_t label_len = strlen(label_txt);
|
||||
memcpy(buf, label_txt, cur_pos - 1);
|
||||
memcpy(buf+cur_pos - 1, label_txt + cur_pos, label_len - cur_pos + 1);
|
||||
|
||||
/*Refresh the label*/
|
||||
lv_label_set_text(ta_dp->label_dp, buf);
|
||||
lv_label_set_text(ext->label, buf);
|
||||
|
||||
/*Move the cursor to the place of the deleted character*/
|
||||
lv_ta_set_cursor_pos(obj_dp, lv_ta_get_cursor_pos(obj_dp) - 1);
|
||||
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) - 1);
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(obj_dp);
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cursor position
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param obj pointer to a text area object
|
||||
* @param pos the new cursor position in character index
|
||||
*/
|
||||
void lv_ta_set_cursor_pos(lv_obj_t * obj_dp, uint16_t pos)
|
||||
void lv_ta_set_cursor_pos(lv_obj_t * ta, uint16_t pos)
|
||||
{
|
||||
lv_ta_ext_t * ta_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
uint16_t txt_len = strlen(lv_label_get_text(ta_ext_dp->label_dp));
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
uint16_t txt_len = strlen(lv_label_get_text(ext->label));
|
||||
|
||||
if(pos > txt_len) pos = txt_len;
|
||||
|
||||
ta_ext_dp->cursor_pos = pos;
|
||||
ext->cursor_pos = pos;
|
||||
|
||||
/*Position the label to make the cursor visible*/
|
||||
lv_obj_t * label_par_dp = lv_obj_get_parent(ta_ext_dp->label_dp);
|
||||
lv_obj_t * label_par = lv_obj_get_parent(ext->label);
|
||||
point_t cur_pos;
|
||||
lv_tas_t * tas_p = lv_obj_get_style(obj_dp);
|
||||
const font_t * font_p = font_get(tas_p->labels.font);
|
||||
lv_label_get_letter_pos(ta_ext_dp->label_dp, pos, &cur_pos);
|
||||
lv_tas_t * style = lv_obj_get_style(ta);
|
||||
const font_t * font_p = font_get(style->label.font);
|
||||
lv_label_get_letter_pos(ext->label, pos, &cur_pos);
|
||||
|
||||
/*Check the top*/
|
||||
if(lv_obj_get_y(label_par_dp) + cur_pos.y < 0) {
|
||||
lv_obj_set_y(label_par_dp, - cur_pos.y);
|
||||
if(lv_obj_get_y(label_par) + cur_pos.y < 0) {
|
||||
lv_obj_set_y(label_par, - cur_pos.y);
|
||||
}
|
||||
|
||||
/*Check the bottom*/
|
||||
if(lv_obj_get_y(label_par_dp) + cur_pos.y + font_get_height(font_p) > lv_obj_get_height(obj_dp)) {
|
||||
lv_obj_set_y(label_par_dp, -(cur_pos.y - lv_obj_get_height(obj_dp) +
|
||||
font_get_height(font_p) + tas_p->pages.scrable_rects.vpad * 2));
|
||||
if(lv_obj_get_y(label_par) + cur_pos.y + font_get_height(font_p) > lv_obj_get_height(ta)) {
|
||||
lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) +
|
||||
font_get_height(font_p) + style->pages.scrable_rects.vpad * 2));
|
||||
}
|
||||
|
||||
lv_obj_inv(obj_dp);
|
||||
lv_obj_inv(ta);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move the cursor one character right
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
*/
|
||||
void lv_ta_cursor_right(lv_obj_t * obj_dp)
|
||||
void lv_ta_cursor_right(lv_obj_t * ta)
|
||||
{
|
||||
uint16_t cp = lv_ta_get_cursor_pos(obj_dp);
|
||||
uint16_t cp = lv_ta_get_cursor_pos(ta);
|
||||
cp++;
|
||||
lv_ta_set_cursor_pos(obj_dp, cp);
|
||||
lv_ta_set_cursor_pos(ta, cp);
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(obj_dp);
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the cursor one character left
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
*/
|
||||
void lv_ta_cursor_left(lv_obj_t * obj_dp)
|
||||
void lv_ta_cursor_left(lv_obj_t * ta)
|
||||
{
|
||||
uint16_t cp = lv_ta_get_cursor_pos(obj_dp);
|
||||
uint16_t cp = lv_ta_get_cursor_pos(ta);
|
||||
if(cp > 0) {
|
||||
cp--;
|
||||
lv_ta_set_cursor_pos(obj_dp, cp);
|
||||
lv_ta_set_cursor_pos(ta, cp);
|
||||
|
||||
/*It is a valid x step so save it*/
|
||||
lv_ta_save_valid_cursor_x(obj_dp);
|
||||
lv_ta_save_valid_cursor_x(ta);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the cursor one line down
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
*/
|
||||
void lv_ta_cursor_down(lv_obj_t * obj_dp)
|
||||
void lv_ta_cursor_down(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ta_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
point_t pos;
|
||||
|
||||
/*Get the position of the current letter*/
|
||||
lv_label_get_letter_pos(ta_ext_dp->label_dp, lv_ta_get_cursor_pos(obj_dp), &pos);
|
||||
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
|
||||
|
||||
/*Increment the y with one line and keep the valid x*/
|
||||
lv_labels_t * labels_p = lv_obj_get_style(ta_ext_dp->label_dp);
|
||||
const font_t * font_p = font_get(labels_p->font);
|
||||
pos.y += font_get_height(font_p) + labels_p->line_space + 1;
|
||||
pos.x = ta_ext_dp->cursor_valid_x;
|
||||
lv_labels_t * label_style = lv_obj_get_style(ext->label);
|
||||
const font_t * font_p = font_get(label_style->font);
|
||||
pos.y += font_get_height(font_p) + label_style->line_space + 1;
|
||||
pos.x = ext->cursor_valid_x;
|
||||
|
||||
/*Do not go below he last line*/
|
||||
if(pos.y < lv_obj_get_height(ta_ext_dp->label_dp)) {
|
||||
if(pos.y < lv_obj_get_height(ext->label)) {
|
||||
/*Get the letter index on the new cursor position and set it*/
|
||||
uint16_t new_cur_pos = lv_label_get_letter_on(ta_ext_dp->label_dp, &pos);
|
||||
lv_ta_set_cursor_pos(obj_dp, new_cur_pos);
|
||||
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
|
||||
lv_ta_set_cursor_pos(ta, new_cur_pos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the cursor one line up
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
*/
|
||||
void lv_ta_cursor_up(lv_obj_t * obj_dp)
|
||||
void lv_ta_cursor_up(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ta_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
point_t pos;
|
||||
|
||||
/*Get the position of the current letter*/
|
||||
lv_label_get_letter_pos(ta_ext_dp->label_dp, lv_ta_get_cursor_pos(obj_dp), &pos);
|
||||
lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos);
|
||||
|
||||
/*Decrement the y with one line and keep the valid x*/
|
||||
lv_labels_t * labels_p = lv_obj_get_style(ta_ext_dp->label_dp);
|
||||
const font_t * font_p = font_get(labels_p->font);
|
||||
pos.y -= font_get_height(font_p) + labels_p->line_space - 1;
|
||||
pos.x = ta_ext_dp->cursor_valid_x;
|
||||
lv_labels_t * label_style = lv_obj_get_style(ext->label);
|
||||
const font_t * font = font_get(label_style->font);
|
||||
pos.y -= font_get_height(font) + label_style->line_space - 1;
|
||||
pos.x = ext->cursor_valid_x;
|
||||
|
||||
/*Get the letter index on the new cursor position and set it*/
|
||||
uint16_t new_cur_pos = lv_label_get_letter_on(ta_ext_dp->label_dp, &pos);
|
||||
lv_ta_set_cursor_pos(obj_dp, new_cur_pos);
|
||||
uint16_t new_cur_pos = lv_label_get_letter_on(ext->label, &pos);
|
||||
lv_ta_set_cursor_pos(ta, new_cur_pos);
|
||||
}
|
||||
/*=====================
|
||||
* Getter functions
|
||||
@@ -355,33 +354,33 @@ void lv_ta_cursor_up(lv_obj_t * obj_dp)
|
||||
|
||||
/**
|
||||
* Get the text of the i the text area
|
||||
* @param obj_dp obj_dp pointer to a text area object
|
||||
* @param ta obj pointer to a text area object
|
||||
* @return pointer to the text
|
||||
*/
|
||||
const char * lv_ta_get_text(lv_obj_t * obj_dp)
|
||||
const char * lv_ta_get_txt(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ta_dp = lv_obj_get_ext(obj_dp);
|
||||
return lv_label_get_text(ta_dp->label_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
return lv_label_get_text(ext->label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current cursor position in character index
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
* @return the cursor position
|
||||
*/
|
||||
uint16_t lv_ta_get_cursor_pos(lv_obj_t * obj_dp)
|
||||
uint16_t lv_ta_get_cursor_pos(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ta_dp = lv_obj_get_ext(obj_dp);
|
||||
return ta_dp->cursor_pos;
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
return ext->cursor_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with a pointer to a built-in style and/or copy it to a variable
|
||||
* @param style a style name from lv_tas_builtin_t enum
|
||||
* @param copy_p copy the style to this variable. (NULL if unused)
|
||||
* @param copy copy the style to this variable. (NULL if unused)
|
||||
* @return pointer to an lv_tas_t style
|
||||
*/
|
||||
lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy_p)
|
||||
lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy)
|
||||
{
|
||||
static bool style_inited = false;
|
||||
|
||||
@@ -401,9 +400,9 @@ lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy_p)
|
||||
style_p = &lv_tas_def;
|
||||
}
|
||||
|
||||
if(copy_p != NULL) {
|
||||
if(style_p != NULL) memcpy(copy_p, style_p, sizeof(lv_tas_t));
|
||||
else memcpy(copy_p, &lv_tas_def, sizeof(lv_tas_t));
|
||||
if(copy != NULL) {
|
||||
if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_tas_t));
|
||||
else memcpy(copy, &lv_tas_def, sizeof(lv_tas_t));
|
||||
}
|
||||
|
||||
return style_p;
|
||||
@@ -412,10 +411,9 @@ lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy_p)
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the text areas
|
||||
* @param obj_dp pointer to an object
|
||||
* @param ta pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
@@ -423,64 +421,67 @@ lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy_p)
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_ta_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_ta_design(lv_obj_t * ta, const area_t * masp, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return ancestor_design_f(obj_dp, mask_p, mode);
|
||||
return ancestor_design_f(ta, masp, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
/*Draw the object*/
|
||||
ancestor_design_f(obj_dp, mask_p, mode);
|
||||
ancestor_design_f(ta, masp, mode);
|
||||
|
||||
} else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
ancestor_design_f(obj_dp, mask_p, mode);
|
||||
ancestor_design_f(ta, masp, mode);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* An extended label design. Calls the normal label design function and it draws a cursor.
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param mask_p the object will be drawn only in this area
|
||||
* @param label pointer to a text area object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
* LV_DESIGN_DRAW_MAIN: draw the object (always return 'true')
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @return return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_ta_label_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode)
|
||||
static bool lv_ta_label_design(lv_obj_t * label, const area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return label_design_f(obj_dp, mask_p, mode);
|
||||
return label_design_f(label, mask, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
/*Draw the object*/
|
||||
label_design_f(obj_dp, mask_p, mode);
|
||||
label_design_f(label, mask, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
label_design_f(obj_dp, mask_p, mode);
|
||||
label_design_f(label, mask, mode);
|
||||
|
||||
/*Draw the cursor too*/
|
||||
lv_obj_t * ta_dp = lv_obj_get_parent(lv_obj_get_parent(obj_dp));
|
||||
lv_ta_ext_t * ta_ext_dp = lv_obj_get_ext(ta_dp);
|
||||
lv_tas_t * tas_p = lv_obj_get_style(ta_dp);
|
||||
uint16_t cur_pos = lv_ta_get_cursor_pos(ta_dp);
|
||||
point_t letter_pos;
|
||||
lv_label_get_letter_pos(obj_dp, cur_pos, &letter_pos);
|
||||
lv_obj_t * ta = lv_obj_get_parent(lv_obj_get_parent(label));
|
||||
lv_ta_ext_t * ta_ext = lv_obj_get_ext(ta);
|
||||
lv_tas_t * ta_style = lv_obj_get_style(ta);
|
||||
|
||||
area_t cur_area;
|
||||
lv_labels_t * labels_p = lv_obj_get_style(ta_ext_dp->label_dp);
|
||||
cur_area.x1 = letter_pos.x + obj_dp->cords.x1 - (tas_p->cursor_width >> 1);
|
||||
cur_area.y1 = letter_pos.y + obj_dp->cords.y1;
|
||||
cur_area.x2 = letter_pos.x + obj_dp->cords.x1 + (tas_p->cursor_width >> 1);
|
||||
cur_area.y2 = letter_pos.y + obj_dp->cords.y1 + font_get_height(font_get(labels_p->font));
|
||||
if(ta_style->cursor_show != 0) {
|
||||
uint16_t cur_pos = lv_ta_get_cursor_pos(ta);
|
||||
point_t letter_pos;
|
||||
lv_label_get_letter_pos(label, cur_pos, &letter_pos);
|
||||
|
||||
lv_rects_t cur_rects;
|
||||
lv_rects_get(LV_RECTS_DEF, &cur_rects);
|
||||
cur_rects.round = 0;
|
||||
cur_rects.bwidth = 0;
|
||||
cur_rects.objs.color = tas_p->cursor_color;
|
||||
cur_rects.gcolor = tas_p->cursor_color;
|
||||
lv_draw_rect(&cur_area, mask_p, &cur_rects, OPA_COVER);
|
||||
area_t cur_area;
|
||||
lv_labels_t * labels_p = lv_obj_get_style(ta_ext->label);
|
||||
cur_area.x1 = letter_pos.x + label->cords.x1 - (ta_style->cursor_width >> 1);
|
||||
cur_area.y1 = letter_pos.y + label->cords.y1;
|
||||
cur_area.x2 = letter_pos.x + label->cords.x1 + (ta_style->cursor_width >> 1);
|
||||
cur_area.y2 = letter_pos.y + label->cords.y1 + font_get_height(font_get(labels_p->font));
|
||||
|
||||
lv_rects_t cur_rects;
|
||||
lv_rects_get(LV_RECTS_DEF, &cur_rects);
|
||||
cur_rects.round = 0;
|
||||
cur_rects.bwidth = 0;
|
||||
cur_rects.objs.color = ta_style->cursor_color;
|
||||
cur_rects.gcolor = ta_style->cursor_color;
|
||||
lv_draw_rect(&cur_area, mask, &cur_rects, OPA_COVER);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -488,14 +489,14 @@ static bool lv_ta_label_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_desig
|
||||
|
||||
/**
|
||||
* Save the cursor x position as valid. It is important when jumping up/down to a shorter line
|
||||
* @param obj_dp pointer to a text area object
|
||||
* @param ta pointer to a text area object
|
||||
*/
|
||||
static void lv_ta_save_valid_cursor_x(lv_obj_t * obj_dp)
|
||||
static void lv_ta_save_valid_cursor_x(lv_obj_t * ta)
|
||||
{
|
||||
lv_ta_ext_t * ta_ext_dp = lv_obj_get_ext(obj_dp);
|
||||
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
|
||||
point_t cur_pos;
|
||||
lv_label_get_letter_pos(ta_ext_dp->label_dp, ta_ext_dp->cursor_pos, &cur_pos);
|
||||
ta_ext_dp->cursor_valid_x = cur_pos.x;
|
||||
lv_label_get_letter_pos(ext->label, ext->cursor_pos, &cur_pos);
|
||||
ext->cursor_valid_x = cur_pos.x;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,8 +507,8 @@ static void lv_tas_init(void)
|
||||
/*Default style*/
|
||||
lv_pages_get(LV_PAGES_DEF, &lv_tas_def.pages);
|
||||
|
||||
lv_labels_get(LV_LABELS_TXT, &lv_tas_def.labels);
|
||||
lv_tas_def.labels.objs.color = COLOR_MAKE(0x20, 0x20, 0x20);
|
||||
lv_labels_get(LV_LABELS_TXT, &lv_tas_def.label);
|
||||
lv_tas_def.label.objs.color = COLOR_MAKE(0x20, 0x20, 0x20);
|
||||
|
||||
lv_tas_def.cursor_color = COLOR_MAKE(0x10, 0x10, 0x10);
|
||||
lv_tas_def.cursor_width = 2 * LV_STYLE_MULT; /*>1 px for visible cursor*/
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct
|
||||
{
|
||||
lv_pages_t pages; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
lv_labels_t labels;
|
||||
lv_labels_t label;
|
||||
color_t cursor_color;
|
||||
cord_t cursor_width;
|
||||
uint8_t cursor_show :1;
|
||||
@@ -46,7 +46,7 @@ typedef struct
|
||||
{
|
||||
lv_page_ext_t page; /*Ext. of ancestor*/
|
||||
/*New data for this type */
|
||||
lv_obj_t * label_dp;
|
||||
lv_obj_t * label;
|
||||
cord_t cursor_valid_x;
|
||||
uint16_t cursor_pos;
|
||||
}lv_ta_ext_t;
|
||||
@@ -54,22 +54,21 @@ typedef struct
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
lv_obj_t* lv_ta_create(lv_obj_t* par_dp, lv_obj_t * copy_dp);
|
||||
bool lv_ta_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
|
||||
lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy_p);
|
||||
lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy);
|
||||
bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param);
|
||||
lv_tas_t * lv_tas_get(lv_tas_builtin_t style, lv_tas_t * copy);
|
||||
|
||||
void lv_ta_add_char(lv_obj_t * obj_dp, char c);
|
||||
void lv_ta_add_text(lv_obj_t * obj_dp, const char * txt);
|
||||
void lv_ta_del(lv_obj_t * obj_dp);
|
||||
void lv_ta_set_cursor_pos(lv_obj_t * obj_dp, uint16_t pos);
|
||||
void lv_ta_cursor_right (lv_obj_t * obj_dp);
|
||||
void lv_ta_cursor_left(lv_obj_t * obj_dp);
|
||||
void lv_ta_cursor_down(lv_obj_t * obj_dp);
|
||||
void lv_ta_cursor_up(lv_obj_t * obj_dp);
|
||||
void lv_ta_add_char(lv_obj_t * ta, char c);
|
||||
void lv_ta_add_text(lv_obj_t * ta, const char * txt);
|
||||
void lv_ta_del(lv_obj_t * ta);
|
||||
void lv_ta_set_cursor_pos(lv_obj_t * ta, uint16_t pos);
|
||||
void lv_ta_cursor_right (lv_obj_t * ta);
|
||||
void lv_ta_cursor_left(lv_obj_t * taj);
|
||||
void lv_ta_cursor_down(lv_obj_t * ta);
|
||||
void lv_ta_cursor_up(lv_obj_t * ta);
|
||||
|
||||
|
||||
const char * lv_ta_get_txt(lv_obj_t obj_dp);
|
||||
uint16_t lv_ta_get_cursor_pos(lv_obj_t * obj_dp);
|
||||
const char * lv_ta_get_txt(lv_obj_t * ta);
|
||||
uint16_t lv_ta_get_cursor_pos(lv_obj_t * ta);
|
||||
|
||||
|
||||
/**********************
|
||||
|
||||
Reference in New Issue
Block a user