1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

Rectangle padding added

This commit is contained in:
Gabor 2016-06-15 09:38:20 +02:00
parent c476355967
commit 151b7cbb95
9 changed files with 265 additions and 153 deletions

View File

@ -15,8 +15,6 @@
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define LV_OBJ_DEF_LENGTH 80
#define LV_OBJ_DEF_HEIGHT 60
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@ -111,6 +109,7 @@ void lv_obj_inv(lv_obj_t* obj_dp)
*/ */
void lv_obj_refr_style(lv_obj_t* obj_dp) void lv_obj_refr_style(lv_obj_t* obj_dp)
{ {
lv_obj_inv(obj_dp);
obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, NULL); obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, NULL);
lv_obj_inv(obj_dp); lv_obj_inv(obj_dp);
@ -186,9 +185,9 @@ lv_obj_t* lv_obj_create(lv_obj_t* parent_dp, lv_obj_t * copy_dp)
new_obj_dp->cords.x1 = parent_dp->cords.x1; new_obj_dp->cords.x1 = parent_dp->cords.x1;
new_obj_dp->cords.y1 = parent_dp->cords.y1; new_obj_dp->cords.y1 = parent_dp->cords.y1;
new_obj_dp->cords.x2 = parent_dp->cords.x1 + new_obj_dp->cords.x2 = parent_dp->cords.x1 +
LV_OBJ_DEF_LENGTH * LV_DOWNSCALE; LV_OBJ_DEF_WIDTH;
new_obj_dp->cords.y2 = parent_dp->cords.y1 + new_obj_dp->cords.y2 = parent_dp->cords.y1 +
LV_OBJ_DEF_HEIGHT * LV_DOWNSCALE; LV_OBJ_DEF_HEIGHT;
/*Set appearance*/ /*Set appearance*/
new_obj_dp->style_p = lv_objs_get(LV_OBJS_DEF, NULL); new_obj_dp->style_p = lv_objs_get(LV_OBJS_DEF, NULL);
@ -750,6 +749,7 @@ void lv_obj_set_style(lv_obj_t* obj_dp, void * style_p)
obj_dp->style_p = style_p; obj_dp->style_p = style_p;
obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, NULL); obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, NULL);
//obj_dp->signal_f(lv_obj_get_parent(obj_dp, )
lv_obj_inv(obj_dp); lv_obj_inv(obj_dp);
} }

View File

@ -39,6 +39,9 @@
#define LV_STYLE_MULT 1 #define LV_STYLE_MULT 1
#endif #endif
#define LV_OBJ_DEF_WIDTH (80 * LV_DOWNSCALE)
#define LV_OBJ_DEF_HEIGHT (60 * LV_DOWNSCALE)
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/

View File

@ -25,6 +25,7 @@
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
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* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
static void lv_btn_style_load(lv_obj_t * obj_dp);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@ -35,52 +36,54 @@ static bool lv_btn_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod
*-----------------*/ *-----------------*/
static lv_btns_t lv_btns_def = static lv_btns_t lv_btns_def =
{ {
.rel.mcolor = COLOR_MAKE(0x40, 0x60, 0x80), .rel.gcolor = COLOR_BLACK, .mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x40, 0x60, 0x80),
.rel.bcolor = COLOR_WHITE, .rel.bwidth = 2 * LV_STYLE_MULT, .rel.bopa = 50, .gcolor[LV_BTN_STATE_REL] = COLOR_BLACK,
.rel.round = 4 * LV_STYLE_MULT, .rel.empty = 0, .bcolor[LV_BTN_STATE_REL] = COLOR_WHITE,
.pr.mcolor = COLOR_MAKE(0x60, 0x80, 0xa0), .pr.gcolor = COLOR_MAKE(0x20, 0x30, 0x40), .mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x60, 0x80, 0xa0),
.pr.bcolor = COLOR_WHITE, .pr.bwidth = 2 * LV_STYLE_MULT, .pr.bopa = 50, .gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x30, 0x40),
.pr.round = 4 * LV_STYLE_MULT, .pr.empty = 0, .bcolor[LV_BTN_STATE_PR] = COLOR_WHITE,
.tgl_rel.mcolor = COLOR_MAKE(0x80,0x00,0x00), .tgl_rel.gcolor = COLOR_MAKE(0x20, 0x20, 0x20), .mcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x80,0x00,0x00),
.tgl_rel.bcolor = COLOR_WHITE, .tgl_rel.bwidth = 2 * LV_STYLE_MULT, .tgl_rel.bopa = 50, .gcolor[LV_BTN_STATE_TGL_REL] = COLOR_MAKE(0x20, 0x20, 0x20),
.tgl_rel.round = 4 * LV_STYLE_MULT, .tgl_rel.empty = 0, .bcolor[LV_BTN_STATE_TGL_REL] = COLOR_WHITE,
.tgl_pr.mcolor = COLOR_MAKE(0xf0, 0x26, 0x26), .tgl_pr.gcolor = COLOR_MAKE(0x40, 0x40, 0x40), .mcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0xf0, 0x26, 0x26),
.tgl_pr.bcolor = COLOR_WHITE, .tgl_pr.bwidth = 2 * LV_STYLE_MULT, .tgl_pr.bopa = 50, .gcolor[LV_BTN_STATE_TGL_PR] = COLOR_MAKE(0x40, 0x40, 0x40),
.tgl_pr.round = 4 * LV_STYLE_MULT, .tgl_pr.empty = 0, .bcolor[LV_BTN_STATE_TGL_PR] = COLOR_WHITE,
.ina.mcolor = COLOR_SILVER, .ina.gcolor = COLOR_GRAY, .mcolor[LV_BTN_STATE_INA] = COLOR_SILVER,
.ina.bcolor = COLOR_WHITE, .ina.bwidth = 2 * LV_STYLE_MULT, .ina.bopa = 50, .gcolor[LV_BTN_STATE_INA] = COLOR_GRAY,
.ina.round = 4 * LV_STYLE_MULT, .ina.empty = 0, .bcolor[LV_BTN_STATE_INA] = COLOR_WHITE,
.bwidth = 2 * LV_STYLE_MULT,
.bopa = 50,
.empty = 0,
.round = 4 * LV_STYLE_MULT,
.hpad = 10 * LV_STYLE_MULT,
.vpad = 15 * LV_STYLE_MULT,
}; };
static lv_btns_t lv_btns_transp = static lv_btns_t lv_btns_transp =
{ {
.rel.bwidth = 0, .rel.empty = 1, .rel.round = 0, .bwidth = 0,
.pr.bwidth = 0, .pr.empty = 1, .rel.round = 0, .empty = 1,
.tgl_rel.bwidth = 0, .tgl_rel.empty = 1, .rel.round = 0, .hpad = 10 * LV_STYLE_MULT,
.tgl_pr.bwidth = 0, .tgl_pr.empty = 1, .rel.round = 0, .vpad = 15 * LV_STYLE_MULT,
.ina.bwidth = 0, .ina.empty = 1, .rel.round = 0,
}; };
static lv_btns_t lv_btns_border = static lv_btns_t lv_btns_border =
{ {
.rel.bcolor = COLOR_BLACK, .rel.bwidth = 2 * LV_STYLE_MULT, .rel.bopa = 100, .bcolor[LV_BTN_STATE_REL] = COLOR_BLACK,
.rel.round = 4 * LV_STYLE_MULT, .rel.empty = 1, .bcolor[LV_BTN_STATE_PR] = COLOR_BLACK,
.bcolor[LV_BTN_STATE_TGL_REL] = COLOR_BLACK,
.pr.bcolor = COLOR_GRAY, .pr.bwidth = 2 * LV_STYLE_MULT, .pr.bopa = 100, .bcolor[LV_BTN_STATE_TGL_PR] = COLOR_BLACK,
.pr.round = 4 * LV_STYLE_MULT, .pr.empty = 1, .bcolor[LV_BTN_STATE_INA] = COLOR_GRAY,
.bwidth = 2 * LV_STYLE_MULT,
.tgl_rel.bcolor = COLOR_SILVER, .tgl_rel.bwidth = 2 * LV_STYLE_MULT, .tgl_rel.bopa = 100, .empty = 1,
.tgl_rel.round = 4 * LV_STYLE_MULT, .tgl_rel.empty = 1, .bopa = 50,
.round = 4 * LV_STYLE_MULT,
.tgl_pr.bcolor = COLOR_GRAY, .tgl_pr.bwidth = 2 * LV_STYLE_MULT, .tgl_pr.bopa = 100, .hpad = 10 * LV_STYLE_MULT,
.tgl_pr.round = 4 * LV_STYLE_MULT, .tgl_pr.empty = 1, .vpad = 15 * LV_STYLE_MULT,
.ina.bcolor = COLOR_GRAY, .ina.bwidth = 2 * LV_STYLE_MULT, .ina.bopa = 100,
.ina.round = 4 * LV_STYLE_MULT, .ina.empty = 1,
}; };
/********************** /**********************
@ -101,7 +104,7 @@ lv_obj_t* lv_btn_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
{ {
lv_obj_t* new_obj; lv_obj_t* new_obj;
new_obj = lv_obj_create(par_dp, copy_dp); new_obj = lv_rect_create(par_dp, copy_dp);
/*Allocate the extended data*/ /*Allocate the extended data*/
lv_obj_alloc_ext(new_obj, sizeof(lv_btn_ext_t)); lv_obj_alloc_ext(new_obj, sizeof(lv_btn_ext_t));
lv_obj_set_signal_f(new_obj, lv_btn_signal); lv_obj_set_signal_f(new_obj, lv_btn_signal);
@ -113,7 +116,7 @@ lv_obj_t* lv_btn_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
/*If no copy do the basic initialization*/ /*If no copy do the basic initialization*/
if(copy_dp == NULL) if(copy_dp == NULL)
{ {
btn_ext_dp->state = LV_BTN_REL; btn_ext_dp->state = LV_BTN_STATE_REL;
btn_ext_dp->pr_action = NULL; btn_ext_dp->pr_action = NULL;
btn_ext_dp->rel_action = NULL; btn_ext_dp->rel_action = NULL;
btn_ext_dp->lpr_action = NULL; btn_ext_dp->lpr_action = NULL;
@ -122,12 +125,12 @@ lv_obj_t* lv_btn_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
} }
/*Copy 'copy_dp'*/ /*Copy 'copy_dp'*/
else{ else{
lv_btn_ext_t * ori_btnd_dp = lv_obj_get_ext(copy_dp); lv_btn_ext_t * ori_btn_ext = lv_obj_get_ext(copy_dp);
btn_ext_dp->state = ori_btnd_dp->state; btn_ext_dp->state = ori_btn_ext->state;
btn_ext_dp->pr_action = ori_btnd_dp->pr_action; btn_ext_dp->pr_action = ori_btn_ext->pr_action;
btn_ext_dp->rel_action = ori_btnd_dp->rel_action; btn_ext_dp->rel_action = ori_btn_ext->rel_action;
btn_ext_dp->lpr_action = ori_btnd_dp->lpr_action; btn_ext_dp->lpr_action = ori_btn_ext->lpr_action;
btn_ext_dp->tgl = ori_btnd_dp->tgl; btn_ext_dp->tgl = ori_btn_ext->tgl;
} }
return new_obj; return new_obj;
@ -143,8 +146,13 @@ bool lv_btn_signal(lv_obj_t * obj_dp, lv_signal_t sign, void* param)
{ {
bool valid; bool valid;
/*Be sure the corresponding style is loaded*/
if(sign == LV_SIGNAL_STYLE_CHG) {
lv_btn_style_load(obj_dp);
}
/* Include the ancient signal function */ /* Include the ancient signal function */
valid = lv_obj_signal(obj_dp, sign, param); valid = lv_rect_signal(obj_dp, sign, param);
/* The object can be deleted so check its validity and then /* The object can be deleted so check its validity and then
* make the object specific signal handling */ * make the object specific signal handling */
@ -156,26 +164,26 @@ bool lv_btn_signal(lv_obj_t * obj_dp, lv_signal_t sign, void* param)
switch (sign){ switch (sign){
case LV_SIGNAL_PRESSED: case LV_SIGNAL_PRESSED:
/*Refresh the state*/ /*Refresh the state*/
if(btn_ext_dp->state == LV_BTN_REL) { if(btn_ext_dp->state == LV_BTN_STATE_REL) {
btn_ext_dp->state = LV_BTN_PR; lv_btn_set_state(obj_dp, LV_BTN_STATE_PR);
} else if(btn_ext_dp->state == LV_BTN_TGL_REL) { } else if(btn_ext_dp->state == LV_BTN_STATE_TGL_REL) {
btn_ext_dp->state = LV_BTN_TGL_PR; lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_PR);
} }
lv_obj_inv(obj_dp); lv_obj_inv(obj_dp);
btn_ext_dp->lpr_exec = 0; btn_ext_dp->lpr_exec = 0;
/*Call the press action, here 'param' is the caller dispi*/ /*Call the press action, here 'param' is the caller dispi*/
if(btn_ext_dp->pr_action != NULL && state != LV_BTN_INA) { if(btn_ext_dp->pr_action != NULL && state != LV_BTN_STATE_INA) {
valid = btn_ext_dp->pr_action(obj_dp, param); valid = btn_ext_dp->pr_action(obj_dp, param);
} }
break; break;
case LV_SIGNAL_PRESS_LOST: case LV_SIGNAL_PRESS_LOST:
/*Refresh the state*/ /*Refresh the state*/
if(btn_ext_dp->state == LV_BTN_PR) { if(btn_ext_dp->state == LV_BTN_STATE_PR) {
btn_ext_dp->state = LV_BTN_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
} else if(btn_ext_dp->state == LV_BTN_TGL_PR) { } else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR) {
btn_ext_dp->state = LV_BTN_TGL_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
} }
lv_obj_inv(obj_dp); lv_obj_inv(obj_dp);
break; break;
@ -184,25 +192,25 @@ bool lv_btn_signal(lv_obj_t * obj_dp, lv_signal_t sign, void* param)
/*If not dragged and it was not long press action then /*If not dragged and it was not long press action then
*change state and run the action*/ *change state and run the action*/
if(lv_dispi_is_dragging(param) == false && btn_ext_dp->lpr_exec == 0) { if(lv_dispi_is_dragging(param) == false && btn_ext_dp->lpr_exec == 0) {
if(btn_ext_dp->state == LV_BTN_PR && tgl == false) { if(btn_ext_dp->state == LV_BTN_STATE_PR && tgl == false) {
btn_ext_dp->state = LV_BTN_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
} else if(btn_ext_dp->state == LV_BTN_TGL_PR && tgl == false) { } else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR && tgl == false) {
btn_ext_dp->state = LV_BTN_TGL_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
} else if(btn_ext_dp->state == LV_BTN_PR && tgl == true) { } else if(btn_ext_dp->state == LV_BTN_STATE_PR && tgl == true) {
btn_ext_dp->state = LV_BTN_TGL_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
} else if(btn_ext_dp->state == LV_BTN_TGL_PR && tgl == true) { } else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR && tgl == true) {
btn_ext_dp->state = LV_BTN_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
} }
if(btn_ext_dp->rel_action != NULL && state != LV_BTN_INA) { if(btn_ext_dp->rel_action != NULL && state != LV_BTN_STATE_INA) {
valid = btn_ext_dp->rel_action(obj_dp, param); valid = btn_ext_dp->rel_action(obj_dp, param);
} }
} else { /*If dragged change back the state*/ } else { /*If dragged change back the state*/
if(btn_ext_dp->state == LV_BTN_PR) { if(btn_ext_dp->state == LV_BTN_STATE_PR) {
btn_ext_dp->state = LV_BTN_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_REL);
} else if(btn_ext_dp->state == LV_BTN_TGL_PR) { } else if(btn_ext_dp->state == LV_BTN_STATE_TGL_PR) {
btn_ext_dp->state = LV_BTN_TGL_REL; lv_btn_set_state(obj_dp, LV_BTN_STATE_TGL_REL);
} }
} }
@ -210,11 +218,15 @@ bool lv_btn_signal(lv_obj_t * obj_dp, lv_signal_t sign, void* param)
break; break;
case LV_SIGNAL_LONG_PRESS: case LV_SIGNAL_LONG_PRESS:
/*Call the long press action, here 'param' is the caller dispi*/ /*Call the long press action, here 'param' is the caller dispi*/
if(btn_ext_dp->lpr_action != NULL && state != LV_BTN_INA) { if(btn_ext_dp->lpr_action != NULL && state != LV_BTN_STATE_INA) {
btn_ext_dp->lpr_exec = 1; btn_ext_dp->lpr_exec = 1;
valid = btn_ext_dp->lpr_action(obj_dp, param); valid = btn_ext_dp->lpr_action(obj_dp, param);
} }
break; break;
case LV_SIGNAL_STYLE_CHG:
/*Load the currently active style*/
lv_btn_style_load(obj_dp);
break;
default: default:
/*Do nothing*/ /*Do nothing*/
break; break;
@ -250,6 +262,7 @@ void lv_btn_set_state(lv_obj_t* obj_dp, lv_btn_state_t state)
lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp); lv_btn_ext_t * btn_p = lv_obj_get_ext(obj_dp);
btn_p->state = state; btn_p->state = state;
lv_btn_style_load(obj_dp);
lv_obj_inv(obj_dp); lv_obj_inv(obj_dp);
} }
@ -364,38 +377,11 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p)
*/ */
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* obj_dp, const area_t * mask_p, 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(obj_dp);
lv_rects_t * rects_p;
switch(lv_btn_get_state(obj_dp)) {
case LV_BTN_REL:
rects_p = &btns_p->rel;
break;
case LV_BTN_PR:
rects_p = &btns_p->pr;
break;
case LV_BTN_TGL_PR:
rects_p = &btns_p->tgl_pr;
break;
case LV_BTN_TGL_REL:
rects_p = &btns_p->tgl_rel;
break;
case LV_BTN_INA:
rects_p = &btns_p->ina;
break;
default:
rects_p = &btns_p->rel;
break;
}
/* Because of the radius it is not sure the area is covered*/ /* Because of the radius it is not sure the area is covered*/
if(mode == LV_DESIGN_COVER_CHK) { if(mode == LV_DESIGN_COVER_CHK) {
uint16_t r = rects_p->round; uint16_t r = btns_p->rects.round;
area_t area_tmp; area_t area_tmp;
/*Check horizontally without radius*/ /*Check horizontally without radius*/
@ -418,9 +404,30 @@ static bool lv_btn_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod
lv_obj_get_cords(obj_dp, &area); lv_obj_get_cords(obj_dp, &area);
/*Draw the rectangle*/ /*Draw the rectangle*/
lv_draw_rect(&area, mask_p, rects_p, opa); lv_draw_rect(&area, mask_p, &btns_p->rects, opa);
return true; return true;
} }
/**
* Load the corresponding style according to the state to 'rects' in 'lv_btns_t'
* @param obj_dp pointer to a button object
*/
static void lv_btn_style_load(lv_obj_t * obj_dp)
{
lv_btn_state_t state = lv_btn_get_state(obj_dp);
lv_btns_t * btns_p = lv_obj_get_style(obj_dp);
/*Init the style*/
lv_rects_get(LV_RECTS_DEF, &btns_p->rects);
btns_p->rects.mcolor = btns_p->mcolor[state];
btns_p->rects.gcolor = btns_p->gcolor[state];
btns_p->rects.bcolor = btns_p->bcolor[state];
btns_p->rects.bwidth = btns_p->bwidth;
btns_p->rects.bopa = btns_p->bopa;
btns_p->rects.round = btns_p->round;
btns_p->rects.empty = btns_p->empty;
btns_p->rects.hpad= btns_p->hpad;
btns_p->rects.vpad= btns_p->vpad;
}
#endif #endif

View File

@ -25,20 +25,26 @@
typedef enum typedef enum
{ {
LV_BTN_PR, LV_BTN_STATE_PR,
LV_BTN_REL, LV_BTN_STATE_REL,
LV_BTN_TGL_PR, LV_BTN_STATE_TGL_PR,
LV_BTN_TGL_REL, LV_BTN_STATE_TGL_REL,
LV_BTN_INA, LV_BTN_STATE_INA,
LV_BTN_STATE_NUM,
}lv_btn_state_t; }lv_btn_state_t;
typedef struct typedef struct
{ {
lv_rects_t rel; lv_rects_t rects; /*To be compatible with the ancestor*/
lv_rects_t pr; color_t mcolor[LV_BTN_STATE_NUM];
lv_rects_t tgl_rel; color_t gcolor[LV_BTN_STATE_NUM];
lv_rects_t tgl_pr; color_t bcolor[LV_BTN_STATE_NUM];
lv_rects_t ina; cord_t bwidth;
cord_t round;
opa_t bopa;
uint8_t empty;
cord_t hpad;
cord_t vpad;
}lv_btns_t; }lv_btns_t;
typedef enum typedef enum
@ -50,6 +56,7 @@ typedef enum
typedef struct typedef struct
{ {
lv_rect_ext_t rect_ext;
bool (*pr_action)(lv_obj_t*, lv_dispi_t *); bool (*pr_action)(lv_obj_t*, lv_dispi_t *);
bool (*rel_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 *); bool (*lpr_action)(lv_obj_t*, lv_dispi_t *);

View File

@ -207,6 +207,9 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text)
lv_obj_set_width(obj_dp, longest_line); lv_obj_set_width(obj_dp, longest_line);
} }
lv_obj_t * parent_dp = lv_obj_get_parent(obj_dp);
parent_dp->signal_f(parent_dp, LV_SIGNAL_CHILD_CHG, obj_dp);
lv_obj_inv(obj_dp); lv_obj_inv(obj_dp);
} }

View File

@ -39,6 +39,8 @@ static lv_pages_t lv_pages_def =
.bg_rects.bwidth = 0 * LV_STYLE_MULT, .bg_rects.bwidth = 0 * LV_STYLE_MULT,
.bg_rects.round = 2 * LV_STYLE_MULT, .bg_rects.round = 2 * LV_STYLE_MULT,
.bg_rects.empty = 0, .bg_rects.empty = 0,
.bg_rects.hpad = 10,
.bg_rects.vpad = 10,
.sb_rects.mcolor = COLOR_BLACK, .sb_rects.mcolor = COLOR_BLACK,
.sb_rects.gcolor = COLOR_BLACK, .sb_rects.gcolor = COLOR_BLACK,
@ -68,6 +70,8 @@ static lv_pages_t lv_pages_paper =
.bg_rects.bwidth = 2 * LV_STYLE_MULT, .bg_rects.bwidth = 2 * LV_STYLE_MULT,
.bg_rects.round = 0 * LV_STYLE_MULT, .bg_rects.round = 0 * LV_STYLE_MULT,
.bg_rects.empty = 0, .bg_rects.empty = 0,
.bg_rects.hpad = 20 * LV_STYLE_MULT,
.bg_rects.vpad = 20 * LV_STYLE_MULT,
.sb_rects.mcolor = COLOR_BLACK, .sb_rects.mcolor = COLOR_BLACK,
.sb_rects.gcolor = COLOR_BLACK, .sb_rects.gcolor = COLOR_BLACK,
@ -85,12 +89,13 @@ static lv_pages_t lv_pages_paper =
.margin_ver = 15 * LV_STYLE_MULT, .margin_ver = 15 * LV_STYLE_MULT,
.padding_hor = 10 * LV_STYLE_MULT, .padding_hor = 10 * LV_STYLE_MULT,
.padding_ver = 10 * LV_STYLE_MULT, .padding_ver = 10 * LV_STYLE_MULT,
}; };
static lv_pages_t lv_pages_transp = static lv_pages_t lv_pages_transp =
{ {
.bg_rects.empty = 1, .bg_rects.empty = 1,
.bg_rects.hpad = 1,
.bg_rects.vpad = 1,
.sb_rects.mcolor = COLOR_BLACK, .sb_rects.mcolor = COLOR_BLACK,
.sb_rects.gcolor = COLOR_BLACK, .sb_rects.gcolor = COLOR_BLACK,
@ -133,14 +138,14 @@ lv_obj_t* lv_page_create(lv_obj_t * par_dp, lv_obj_t * ori_dp)
new_dp = lv_rect_create(par_dp, ori_dp); new_dp = lv_rect_create(par_dp, ori_dp);
/*Init the new object*/ /*Init the new object*/
lv_page_t * page_p = lv_obj_alloc_ext(new_dp, sizeof(lv_page_t)); lv_page_ext_t * page_p = lv_obj_alloc_ext(new_dp, sizeof(lv_page_ext_t));
/*Init the main rectangle if it is not copied*/ /*Init the main rectangle if it is not copied*/
if(ori_dp == NULL) { if(ori_dp == NULL) {
lv_obj_set_size(new_dp, 100,200);
lv_obj_set_drag(new_dp, true); lv_obj_set_drag(new_dp, true);
lv_obj_set_drag_throw(new_dp, true); lv_obj_set_drag_throw(new_dp, true);
lv_obj_set_style(new_dp, &lv_pages_def); lv_obj_set_style(new_dp, &lv_pages_def);
lv_rect_set_pad_en(new_dp, true, true);
} else { } else {
lv_obj_set_style(new_dp, lv_obj_get_style(ori_dp)); lv_obj_set_style(new_dp, lv_obj_get_style(ori_dp));
} }
@ -198,10 +203,9 @@ bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
bool refr_y = false; bool refr_y = false;
area_t page_cords; area_t page_cords;
area_t par_cords; area_t par_cords;
lv_obj_t * i;
lv_obj_t * par_dp = lv_obj_get_parent(obj_dp); lv_obj_t * par_dp = lv_obj_get_parent(obj_dp);
lv_page_t * page_ext_p = lv_obj_get_ext(obj_dp); 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_pages_t * pages_p = lv_obj_get_style(obj_dp);
switch(sign) { switch(sign) {
@ -268,36 +272,6 @@ bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param)
} }
break; break;
case LV_SIGNAL_CHILD_CHG:
page_cords.x1 = LV_CORD_MAX;
page_cords.y1 = LV_CORD_MAX;
page_cords.x2 = LV_CORD_MIN;
page_cords.y2 = LV_CORD_MIN;
LL_READ(obj_dp->child_ll, i) {
page_cords.x1 = min(page_cords.x1, i->cords.x1);
page_cords.y1 = min(page_cords.y1, i->cords.y1);
page_cords.x2 = max(page_cords.x2, i->cords.x2);
page_cords.y2 = max(page_cords.y2, i->cords.y2);
}
/*If the value is not the init value then the page has >=1 child.*/
if(page_cords.x1 != LV_CORD_MAX) {
page_cords.x1 -= pages_p->padding_hor;
page_cords.x2 += pages_p->padding_hor;
page_cords.y1 -= pages_p->padding_ver;
page_cords.y2 += pages_p->padding_ver;
area_cpy(&obj_dp->cords, &page_cords);
lv_obj_set_pos(obj_dp, lv_obj_get_x(obj_dp),
lv_obj_get_y(obj_dp));
} else {
lv_obj_set_size(obj_dp, 10, 10);
}
lv_obj_inv(par_dp);
break;
case LV_SIGNAL_STYLE_CHG: case LV_SIGNAL_STYLE_CHG:
/* Set the styles only if they are different else infinite loop /* Set the styles only if they are different else infinite loop
@ -397,7 +371,7 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy)
*/ */
static void lv_page_sb_refresh(lv_obj_t* page_dp) static void lv_page_sb_refresh(lv_obj_t* page_dp)
{ {
lv_page_t * page_p = lv_obj_get_ext(page_dp); lv_page_ext_t * page_p = lv_obj_get_ext(page_dp);
lv_pages_t * pages_p = lv_obj_get_style(page_dp); lv_pages_t * pages_p = lv_obj_get_style(page_dp);
lv_obj_t* par_dp = lv_obj_get_parent(page_dp); lv_obj_t* par_dp = lv_obj_get_parent(page_dp);
cord_t size_tmp; cord_t size_tmp;

View File

@ -45,9 +45,10 @@ typedef struct
typedef struct typedef struct
{ {
lv_rect_ext_t rect_exp;
lv_obj_t* sbh_dp; /*Horizontal scrollbar*/ lv_obj_t* sbh_dp; /*Horizontal scrollbar*/
lv_obj_t* sbv_dp; /*Vertical scrollbar*/ lv_obj_t* sbv_dp; /*Vertical scrollbar*/
}lv_page_t; }lv_page_ext_t;
typedef enum typedef enum
{ {

View File

@ -12,6 +12,7 @@
#include "lv_rect.h" #include "lv_rect.h"
#include "../lv_draw/lv_draw.h" #include "../lv_draw/lv_draw.h"
#include "../lv_draw/lv_draw_vbasic.h" #include "../lv_draw/lv_draw_vbasic.h"
#include "misc/math/math_base.h"
/********************* /*********************
* DEFINES * DEFINES
@ -32,14 +33,17 @@ static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo
static lv_rects_t lv_rects_def = static lv_rects_t lv_rects_def =
{ .mcolor = COLOR_MAKE(0x50, 0x70, 0x90), .gcolor = COLOR_MAKE(0x20, 0x40, 0x60), { .mcolor = COLOR_MAKE(0x50, 0x70, 0x90), .gcolor = COLOR_MAKE(0x20, 0x40, 0x60),
.bcolor = COLOR_WHITE, .bwidth = 2 * LV_STYLE_MULT, .bopa = 50, .bcolor = COLOR_WHITE, .bwidth = 2 * LV_STYLE_MULT, .bopa = 50,
.round = 4 * LV_STYLE_MULT, .empty = 0 }; .round = 4 * LV_STYLE_MULT, .empty = 0,
.hpad = 0, .vpad = 0 };
static lv_rects_t lv_rects_transp = static lv_rects_t lv_rects_transp =
{ .bwidth = 0, .empty = 0 }; { .bwidth = 0, .empty = 0,
.hpad = 0, .vpad = 0 };
static lv_rects_t lv_rects_border = static lv_rects_t lv_rects_border =
{ .bcolor = COLOR_BLACK, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100, { .bcolor = COLOR_BLACK, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100,
.round = 4 * LV_STYLE_MULT, .empty = 1 }; .round = 4 * LV_STYLE_MULT, .empty = 1,
.hpad = 0, .vpad = 0};
/********************** /**********************
* MACROS * MACROS
@ -64,13 +68,20 @@ lv_obj_t* lv_rect_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
/*Create a basic object*/ /*Create a basic object*/
lv_obj_t* new_obj_dp = lv_obj_create(par_dp, copy_dp); lv_obj_t* new_obj_dp = lv_obj_create(par_dp, copy_dp);
dm_assert(new_obj_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_design_f(new_obj_dp, lv_rect_design);
lv_obj_set_signal_f(new_obj_dp, lv_rect_signal); lv_obj_set_signal_f(new_obj_dp, lv_rect_signal);
/*Init the new rectangle*/ /*Init the new rectangle*/
if(copy_dp == NULL) { if(copy_dp == NULL) {
lv_obj_set_style(new_obj_dp, &lv_rects_def); lv_obj_set_style(new_obj_dp, &lv_rects_def);
rect_ext_dp->hpad_en = 0;
rect_ext_dp->vpad_en = 0;
} else {
lv_rect_ext_t * ori_rect_ext = lv_obj_get_ext(copy_dp);
rect_ext_dp->hpad_en = ori_rect_ext->hpad_en;
rect_ext_dp->vpad_en = ori_rect_ext->vpad_en;
} }
return new_obj_dp; return new_obj_dp;
@ -88,11 +99,61 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
/* Include the ancient signal function */ /* Include the ancient signal function */
valid = lv_obj_signal(obj_dp, sign, param); valid = lv_obj_signal(obj_dp, sign, param);
area_t rect_cords;
lv_rects_t * rests_p = lv_obj_get_style(obj_dp);
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
lv_obj_t * i;
/* The object can be deleted so check its validity and then /* The object can be deleted so check its validity and then
* make the object specific signal handling */ * make the object specific signal handling */
if(valid != false) { if(valid != false) {
switch(sign) { switch(sign) {
case LV_SIGNAL_STYLE_CHG: /*Recalculate the padding if the style changed*/
case LV_SIGNAL_CHILD_CHG:
if(ext_p->hpad_en == 0 &&
ext_p->vpad_en == 0) {
break;
}
/*Search the side coordinates of the children*/
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) {
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(rests_p->hpad != 0) {
rect_cords.x1 -= rests_p->hpad;
rect_cords.x2 += rests_p->hpad;
} else {
rect_cords.x1 = obj_dp->cords.x1;
rect_cords.x2 = obj_dp->cords.x2;
}
if(rests_p->vpad != 0) {
rect_cords.y1 -= rests_p->vpad;
rect_cords.y2 += rests_p->vpad;
} else {
rect_cords.y1 = obj_dp->cords.y1;
rect_cords.y2 = obj_dp->cords.y2;
}
area_cpy(&obj_dp->cords, &rect_cords);
lv_obj_set_pos(obj_dp, lv_obj_get_x(obj_dp),
lv_obj_get_y(obj_dp));
} else {
lv_obj_set_size(obj_dp, LV_OBJ_DEF_WIDTH, LV_OBJ_DEF_HEIGHT);
}
break;
default: default:
break; break;
} }
@ -101,6 +162,52 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
return valid; return valid;
} }
/*=====================
* Setter functions
*====================*/
/**
* Enable the horizontal or vertical padding
* @param obj_dp 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_pad_en(lv_obj_t * obj_dp, bool hor_en, bool ver_en)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
ext_p->hpad_en = hor_en == false ? 0 : 1;
ext_p->vpad_en = ver_en == false ? 0 : 1;
obj_dp->signal_f(obj_dp, LV_SIGNAL_STYLE_CHG, obj_dp);
}
/*=====================
* Getter functions
*====================*/
/**
* Get horizontal padding enable attribute of a rectangle
* @param obj_dp pointer to a rectangle object
* @return true: horizontal padding is enabled
*/
bool lv_rect_get_hpad_en(lv_obj_t * obj_dp)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
return ext_p->hpad_en == 0 ? false : true;
}
/**
* Get vertical padding enable attribute of a rectangle
* @param obj_dp pointer to a rectangle object
* @return true: vertical padding is enabled
*/
bool lv_rect_get_vpad_en(lv_obj_t * obj_dp)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
return ext_p->vpad_en == 0 ? false : true;
}
/** /**
* Return with a pointer to a built-in style and/or copy it to a variable * 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 style a style name from lv_rects_builtin_t enum
@ -109,7 +216,7 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
*/ */
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_p)
{ {
lv_rects_t *style_p; lv_rects_t * style_p;
switch(style) { switch(style) {
case LV_RECTS_DEF: case LV_RECTS_DEF:

View File

@ -29,6 +29,8 @@ typedef struct
color_t gcolor; color_t gcolor;
color_t bcolor; color_t bcolor;
uint16_t bwidth; uint16_t bwidth;
cord_t hpad;
cord_t vpad;
uint8_t bopa; uint8_t bopa;
uint8_t empty :1; uint8_t empty :1;
uint16_t round; uint16_t round;
@ -37,7 +39,8 @@ typedef struct
typedef struct typedef struct
{ {
uint8_t hpad_en:1;
uint8_t vpad_en:1;
}lv_rect_ext_t; }lv_rect_ext_t;
typedef enum typedef enum
@ -53,6 +56,13 @@ typedef enum
/*Create function*/ /*Create function*/
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_dp, lv_obj_t * copy_dp);
bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param); bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
void lv_rect_set_pad_en(lv_obj_t * obj_dp, bool hor_en, bool ver_en);
bool lv_rect_get_hpad_en(lv_obj_t * obj_dp);
bool lv_rect_get_vpad_en(lv_obj_t * obj_dp);
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_p);
/********************** /**********************