layouts moved to rectangles

This commit is contained in:
Kiss-Vamosi Gabor
2016-06-22 20:39:07 +02:00
parent aca6529455
commit 708051423f
8 changed files with 302 additions and 352 deletions

View File

@@ -27,9 +27,6 @@
static void lv_obj_pos_child_refr(lv_obj_t* obj_dp, cord_t x_diff, cord_t y_diff);
static void lv_style_refr_core(void * style_p, lv_obj_t* obj_dp);
static bool lv_obj_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
static void lv_obj_refr_layout(lv_obj_t * obj_dp);
static void lv_layout_col(lv_obj_t * obj_dp);
static void lv_layout_row(lv_obj_t * obj_dp);
/**********************
* STATIC VARIABLES
@@ -311,18 +308,6 @@ bool lv_obj_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
switch(sign) {
case LV_SIGNAL_CHILD_CHG:
if(obj_dp->child_chg_off != 0) valid = false;
else lv_obj_refr_layout(obj_dp);
break;
case LV_SIGNAL_CORD_CHG:
if(param == NULL)
{
break;
}
if(lv_obj_get_width(obj_dp) != area_get_width(param) ||
lv_obj_get_height(obj_dp) != area_get_height(param)) {
lv_obj_refr_layout(obj_dp);
}
break;
default:
break;
@@ -607,44 +592,6 @@ void lv_obj_set_height_us(lv_obj_t* obj_dp, cord_t h)
lv_obj_set_size(obj_dp, lv_obj_get_width(obj_dp), h * LV_DOWNSCALE);
}
/**
* Set a layout for an object.
* @param obj_dp pointer to an object
* @param layout type of the layout (an element from lv_layout_t)
*/
void lv_obj_set_layout(lv_obj_t* obj_dp, lv_layout_t layout)
{
obj_dp->layout_type = layout;
/*Send signal to refresh the layout*/
obj_dp->signal_f(obj_dp, LV_SIGNAL_CHILD_CHG, NULL);
}
/**
* Set the layout spacing for an object.
* @param obj_dp pointer to an object
* @param space space between object on the layout (space / 2 on edges)
*/
void lv_obj_set_layout_space(lv_obj_t * obj_dp, cord_t space)
{
obj_dp->layout_space = space;
/*Send signal to refresh the layout*/
obj_dp->signal_f(obj_dp, LV_SIGNAL_CHILD_CHG, NULL);
}
/**
* Set the layout spacing for an object.
* The space will be upscaled to compensate LV_DOWNSCALE
* @param obj_dp pointer to an object
* @param space space between object on the layout (space / 2 on edges)
*/
void lv_obj_set_layout_space_us(lv_obj_t * obj_dp, cord_t space)
{
lv_obj_set_layout_space(obj_dp, space * LV_DOWNSCALE);
}
/**
* Align an object to an other object.
* @param obj_dp pointer to an object to align
@@ -1132,26 +1079,6 @@ cord_t lv_obj_get_height(lv_obj_t* obj_dp)
return area_get_height(&obj_dp->cords);
}
/**
* Get the layout type of an object
* @param obj_dp pointer to an object
* @return type of the layout (from lv_layout_t)
*/
lv_layout_t lv_obj_get_layout(lv_obj_t * obj_dp)
{
return obj_dp->layout_type;
}
/**
* Get the layout space of an object
* @param obj_dp pointer to an object
* @return the layout space
*/
cord_t lv_obj_get_layout_space(lv_obj_t * obj_dp)
{
return obj_dp->layout_space;
}
/*-----------------
* Appearance get
*---------------*/
@@ -1373,146 +1300,3 @@ static void lv_style_refr_core(void * style_p, lv_obj_t* obj_dp)
}
/**
* Refresh the layout of an object
* @param obj_dp pointer to an object which layout should be refreshed
*/
static void lv_obj_refr_layout(lv_obj_t * obj_dp)
{
lv_layout_t type = obj_dp->layout_type;
if(type == LV_LAYOUT_OFF) return;
if(type == LV_LAYOUT_COL_L || type == LV_LAYOUT_COL_M || type == LV_LAYOUT_COL_R) {
lv_layout_col(obj_dp);
} else if(type == LV_LAYOUT_ROW_T || type == LV_LAYOUT_ROW_M || type == LV_LAYOUT_ROW_B) {
lv_layout_row(obj_dp);
}
}
/**
* Handle column type layouts
* @param obj_dp pointer to an object which layout should be handled
*/
static void lv_layout_col(lv_obj_t * obj_dp)
{
lv_layout_t type = lv_obj_get_layout(obj_dp);
cord_t space = lv_obj_get_layout_space(obj_dp); /*Space between objects*/
cord_t margin = abs(space); /*Margin by the parent*/
lv_obj_t * child;
/*Recalculate space in justified mode*/
if(space < 0) {
uint32_t h_tot = 0;
uint32_t obj_cnt = 0;
LL_READ(obj_dp->child_ll, child) {
h_tot += lv_obj_get_height(child);
obj_cnt ++;
}
if(obj_cnt == 0) return;
space = lv_obj_get_height(obj_dp) - h_tot;
if(obj_cnt == 5) {
obj_cnt = 5;
}
space = space / (cord_t)obj_cnt;
}
/*Adjust margin and get the alignment type*/
lv_align_t align;
switch(type) {
case LV_LAYOUT_COL_L:
align = LV_ALIGN_IN_TOP_LEFT;
margin = margin / 2;
break;
case LV_LAYOUT_COL_M:
align = LV_ALIGN_IN_TOP_MID;
margin = 0;
break;
case LV_LAYOUT_COL_R:
align = LV_ALIGN_IN_TOP_RIGHT;
margin = -(margin / 2);
break;
default:
align = LV_ALIGN_IN_TOP_LEFT;
margin = 0;
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 = space / 2;
LL_READ_BACK(obj_dp->child_ll, child) {
lv_obj_align(child, obj_dp, align, margin , last_cord);
last_cord += lv_obj_get_height(child) + space;
}
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_layout_row(lv_obj_t * obj_dp)
{
lv_layout_t type = lv_obj_get_layout(obj_dp);
cord_t space = lv_obj_get_layout_space(obj_dp); /*Space between objects*/
cord_t margin = abs(space); /*Margin by the parent*/
lv_obj_t * child;
/*Recalculate space in justified mode*/
if(space < 0) {
uint32_t w_tot = 0;
uint32_t obj_cnt = 0;
LL_READ(obj_dp->child_ll, child) {
w_tot += lv_obj_get_width(child);
obj_cnt ++;
}
if(obj_cnt == 0) return;
space = lv_obj_get_width(obj_dp) - w_tot;
space = space / (cord_t)obj_cnt;
}
/*Adjust margin and get the alignment type*/
lv_align_t align;
switch(type) {
case LV_LAYOUT_ROW_T:
align = LV_ALIGN_IN_TOP_LEFT;
margin = margin / 2;
break;
case LV_LAYOUT_ROW_M:
align = LV_ALIGN_IN_LEFT_MID;
margin = 0;
break;
case LV_LAYOUT_ROW_B:
align = LV_ALIGN_IN_BOTTOM_LEFT;
margin = -(margin / 2);
break;
default:
align = LV_ALIGN_IN_TOP_LEFT;
margin = 0;
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 = space / 2;
LL_READ_BACK(obj_dp->child_ll, child) {
lv_obj_align(child, obj_dp, align, last_cord, margin);
last_cord += lv_obj_get_width(child) + space;
}
obj_dp->child_chg_off = 0;
}

View File

@@ -70,18 +70,6 @@ typedef enum
LV_SIGNAL_STYLE_CHG,
}lv_signal_t;
typedef enum
{
LV_LAYOUT_OFF = 0,
LV_LAYOUT_COL_L,
LV_LAYOUT_COL_M,
LV_LAYOUT_COL_R,
LV_LAYOUT_ROW_T,
LV_LAYOUT_ROW_M,
LV_LAYOUT_ROW_B,
}lv_layout_t;
typedef bool (* lv_signal_f_t) (struct __LV_OBJ_T* obj_dp, lv_signal_t sign, void * param);
typedef struct __LV_OBJ_T
@@ -101,10 +89,6 @@ typedef struct __LV_OBJ_T
void * free_p; /*Application specific pointer (set it freely)*/
#endif
/*Layout settings*/
cord_t layout_space;
uint8_t layout_type;
/*Attributes and states*/
uint8_t click_en :1; /*1: can be pressed by a display input device*/
uint8_t drag_en :1; /*1: enable the dragging*/
@@ -189,9 +173,6 @@ 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_set_layout(lv_obj_t* obj_dp, lv_layout_t layout);
void lv_obj_set_layout_space(lv_obj_t * obj_dp, cord_t space);
void lv_obj_set_layout_space_us(lv_obj_t * obj_dp, cord_t space);
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);
/*Appearance set*/
@@ -228,8 +209,6 @@ 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);
lv_layout_t lv_obj_get_layout(lv_obj_t * obj_dp);
cord_t lv_obj_get_layout_space(lv_obj_t * obj_dp);
/*Appearance get*/
bool lv_obj_get_hidden(lv_obj_t* obj_dp);
opa_t lv_obj_get_opa(lv_obj_t* obj_dp);

View File

@@ -62,6 +62,7 @@ static lv_btns_t lv_btns_def =
.rects.round = 4 * LV_STYLE_MULT,
.rects.hpad = 10 * LV_STYLE_MULT,
.rects.vpad = 15 * LV_STYLE_MULT,
.rects.opad = 5 * LV_STYLE_MULT,
};
static lv_btns_t lv_btns_transp =
{
@@ -69,6 +70,7 @@ static lv_btns_t lv_btns_transp =
.rects.empty = 1,
.rects.hpad = 10 * LV_STYLE_MULT,
.rects.vpad = 15 * LV_STYLE_MULT,
.rects.opad = 10 * LV_STYLE_MULT,
};
static lv_btns_t lv_btns_border =
@@ -84,6 +86,7 @@ static lv_btns_t lv_btns_border =
.rects.round = 4 * LV_STYLE_MULT,
.rects.hpad = 10 * LV_STYLE_MULT,
.rects.vpad = 15 * LV_STYLE_MULT,
.rects.vpad = 10 * LV_STYLE_MULT,
};
/**********************
@@ -122,8 +125,7 @@ lv_obj_t* lv_btn_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
btn_ext_dp->lpr_action = NULL;
btn_ext_dp->tgl = 0;
lv_obj_set_style(new_obj_dp, &lv_btns_def);
lv_obj_set_layout(new_obj_dp, LV_LAYOUT_COL_M);
lv_obj_set_layout_space_us(new_obj_dp, -40); /*Justified align*/
lv_rect_set_layout(new_obj_dp, LV_LAYOUT_CENTER);
}
/*Copy 'copy_dp'*/
else{

View File

@@ -10,6 +10,8 @@
#if USE_LV_LIST != 0
#include "lv_list.h"
#include "lv_rect.h"
#include "lv_label.h"
/*********************
* DEFINES
@@ -32,16 +34,20 @@ static lv_lists_t lv_lists_def =
/*Page style*/
.pages.bg_rects.objs.color = COLOR_WHITE, .pages.bg_rects.gcolor = COLOR_SILVER, .pages.bg_rects.bcolor = COLOR_GRAY,
.pages.bg_rects.bopa = 50, .pages.bg_rects.bwidth = 0 * LV_STYLE_MULT, .pages.bg_rects.round = 2 * LV_STYLE_MULT,
.pages.bg_rects.empty = 0, .pages.bg_rects.hpad = 0, .pages.bg_rects.vpad = 0,
.pages.bg_rects.empty = 0,
.pages.bg_rects.vpad = 40,
.pages.bg_rects.hpad = 20,
.pages.bg_rects.opad = 10,
.pages.sb_rects.objs.color = COLOR_BLACK, .pages.sb_rects.gcolor = COLOR_BLACK, .pages.sb_rects.bcolor = COLOR_WHITE,
.pages.sb_rects.bopa = 50, .pages.sb_rects.bwidth = 1 * LV_STYLE_MULT, .pages.sb_rects.round = 5 * LV_STYLE_MULT,
.pages.sb_rects.empty = 0, .pages.sb_width= 8 * LV_STYLE_MULT, .pages.sb_opa=50, .pages.sb_mode = LV_PAGE_SB_MODE_ON,
.pages.margin_hor = 0 * LV_STYLE_MULT, .pages.margin_ver = 0 * LV_STYLE_MULT,
.pages.margin_ver = 0 * LV_STYLE_MULT,
.pages.margin_ver = 0 * LV_STYLE_MULT,
/*List style*/
.list_layout = LV_LAYOUT_COL_M, .list_layout_space = 0 * LV_STYLE_MULT,
.list_layout = LV_LAYOUT_CENTER,
/*List element style*/
.liste_btns.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0xa0, 0xa0, 0xa0), .liste_btns.gcolor[LV_BTN_STATE_REL] = COLOR_WHITE, .liste_btns.bcolor[LV_BTN_STATE_REL] = COLOR_WHITE,
@@ -51,9 +57,11 @@ static lv_lists_t lv_lists_def =
.liste_btns.mcolor[LV_BTN_STATE_INA] = COLOR_SILVER, .liste_btns.gcolor[LV_BTN_STATE_INA] = COLOR_GRAY, .liste_btns.bcolor[LV_BTN_STATE_INA] = COLOR_WHITE,
.liste_btns.rects.bwidth = 2 * LV_STYLE_MULT, .liste_btns.rects.bopa = 50,
.liste_btns.rects.empty = 0, .liste_btns.rects.round = 4 * LV_STYLE_MULT,
.liste_btns.rects.hpad = 10 * LV_STYLE_MULT, .liste_btns.rects.vpad = 15 * LV_STYLE_MULT,
.liste_btns.rects.hpad = 10 * LV_STYLE_MULT,
.liste_btns.rects.vpad = 20 * LV_STYLE_MULT,
.liste_btns.rects.opad = 5 * LV_STYLE_MULT,
.liste_layout = LV_LAYOUT_ROW_M, .liste_layout_space = 50 * LV_STYLE_MULT,
.liste_layout = LV_LAYOUT_ROW_M,
};
/**********************
@@ -82,8 +90,7 @@ lv_obj_t* lv_list_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
/*Init the new list object*/
lv_obj_set_style(new_obj_dp, &lv_lists_def.pages);
lv_obj_set_layout(new_obj_dp, lv_lists_def.list_layout);
lv_obj_set_layout_space(new_obj_dp, lv_lists_def.list_layout_space);
lv_rect_set_layout(new_obj_dp, lv_lists_def.list_layout);
return new_obj_dp;
}
@@ -114,12 +121,23 @@ bool lv_list_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
}
void lv_list_add(lv_obj_t * obj_dp)
void lv_list_add(lv_obj_t * obj_dp, const char * img_fn, const char * txt, void (*release) (lv_obj_t *))
{
lv_obj_t * liste;
liste = lv_btn_create(obj_dp, NULL);
lv_obj_set_style(liste, &lv_lists_def.liste_btns);
//lv_btn_set_rel_action(liste, release);
lv_page_glue_obj(liste, true);
lv_rect_set_layout(liste, lv_lists_def.liste_layout);
lv_rect_set_fit(liste, true, true);
if(img_fn != NULL) {
}
lv_obj_t * label = lv_label_create(liste, NULL);
lv_label_set_text(label, txt);
}
/**

View File

@@ -49,6 +49,9 @@ typedef enum
typedef struct
{
lv_page_ext_t page_ext;
uint8_t fit_size :1; /*Automatically set the size of list elements to the holder */
uint8_t sel_en :1; /*Enable selecting list elements by toggling them */
uint8_t sel_one :1; /*Enable to select only one list element*/
}lv_list_ext_t;
@@ -57,7 +60,7 @@ typedef struct
**********************/
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);
void lv_list_add(lv_obj_t * obj_dp);
void lv_list_add(lv_obj_t * obj_dp, const char * img_fn, const char * txt, void (*release) (lv_obj_t *));
lv_lists_t * lv_lists_get(lv_lists_builtin_t style, lv_lists_t * copy_p);
/**********************

View File

@@ -141,7 +141,7 @@ lv_obj_t* lv_page_create(lv_obj_t * par_dp, lv_obj_t * ori_dp)
lv_obj_set_drag(new_dp, true);
lv_obj_set_drag_throw(new_dp, true);
lv_obj_set_style(new_dp, &lv_pages_def);
lv_rect_set_pad_en(new_dp, true, true);
lv_rect_set_fit(new_dp, true, true);
} else {
lv_obj_set_style(new_dp, lv_obj_get_style(ori_dp));
}

View File

@@ -26,6 +26,11 @@
* STATIC PROTOTYPES
**********************/
static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
static void lv_rect_refr_layout(lv_obj_t * obj_dp);
static void lv_layout_col(lv_obj_t * obj_dp);
static void lv_layout_row(lv_obj_t * obj_dp);
static void lv_layout_center(lv_obj_t * obj_dp);
static void lv_rect_refr_autofit(lv_obj_t * obj_dp);
/**********************
* STATIC VARIABLES
@@ -34,16 +39,16 @@ static lv_rects_t lv_rects_def =
{ .objs.color = COLOR_MAKE(0x20, 0x30, 0x40), .gcolor = COLOR_MAKE(0x50, 0x70, 0x90),
.bcolor = COLOR_WHITE, .bwidth = 2 * LV_STYLE_MULT, .bopa = 50,
.round = 4 * LV_STYLE_MULT, .empty = 0,
.hpad = 0 * LV_STYLE_MULT, .vpad = 0 * LV_STYLE_MULT };
.hpad = 0 * LV_STYLE_MULT, .vpad = 0 * LV_STYLE_MULT, .opad = 0 * LV_STYLE_MULT };
static lv_rects_t lv_rects_transp =
{ .bwidth = 0, .empty = 1,
.hpad = 0, .vpad = 0};
.hpad = 0, .vpad = 0, .opad = 0};
static lv_rects_t lv_rects_border =
{ .bcolor = COLOR_BLACK, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100,
.round = 4 * LV_STYLE_MULT, .empty = 1,
.hpad = 10 * LV_STYLE_MULT, .vpad = 10 * LV_STYLE_MULT};
.hpad = 10 * LV_STYLE_MULT, .vpad = 10 * LV_STYLE_MULT, .opad = 10 * LV_STYLE_MULT};
/**********************
* MACROS
@@ -76,12 +81,12 @@ lv_obj_t* lv_rect_create(lv_obj_t* par_dp, lv_obj_t * copy_dp)
/*Init the new rectangle*/
if(copy_dp == NULL) {
lv_obj_set_style(new_obj_dp, &lv_rects_def);
rect_ext_dp->hpad_en = 0;
rect_ext_dp->vpad_en = 0;
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->hpad_en = ori_rect_ext->hpad_en;
rect_ext_dp->vpad_en = ori_rect_ext->vpad_en;
rect_ext_dp->hfit_en = ori_rect_ext->hfit_en;
rect_ext_dp->vfit_en = ori_rect_ext->vfit_en;
}
return new_obj_dp;
@@ -99,13 +104,6 @@ bool lv_rect_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param)
/* Include the ancient signal function */
valid = lv_obj_signal(obj_dp, sign, param);
area_t rect_cords;
area_t ori;
lv_rects_t * rects_p = lv_obj_get_style(obj_dp);
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
lv_obj_t * i;
cord_t hpad = rects_p->hpad;
cord_t vpad = rects_p->vpad;
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
@@ -113,88 +111,16 @@ 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:
if(ext_p->hpad_en == 0 &&
ext_p->vpad_en == 0) {
break;
lv_rect_refr_layout(obj_dp);
lv_rect_refr_autofit(obj_dp);
break;
case LV_SIGNAL_CORD_CHG:
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);
}
break;
/*Override the padding values according to the layout settings*/
cord_t layout_space = lv_obj_get_layout_space(obj_dp);
lv_layout_t layout_type = lv_obj_get_layout(obj_dp);
if(lv_obj_get_layout(obj_dp) != LV_LAYOUT_OFF) {
/* Non-justified case: use the half layout space because
* the layout use this as well on the edges.
* Else padding and layout makes an infinite loop */
if(layout_space >= 0) {
hpad = layout_space / 2;
vpad = hpad;
} else { /*Justified cases*/
/*The rectangle can increase infinitely with wrong settings*/
/*COL layouts: set vpad to 0 */
/*ROW layouts: set hpad to 0 */
if(layout_type == LV_LAYOUT_COL_L ||
layout_type == LV_LAYOUT_COL_M ||
layout_type == LV_LAYOUT_COL_R) {
vpad = 0;
hpad = (-layout_space) / 2;
} else if(layout_type == LV_LAYOUT_ROW_T ||
layout_type == LV_LAYOUT_ROW_M ||
layout_type == LV_LAYOUT_ROW_B) {
hpad = 0;
vpad = (-layout_space) / 2;
} else {
/*Never happens*/
break;
}
}
}
/*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) {
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->hpad_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->vpad_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;
}
area_cpy(&obj_dp->cords, &rect_cords);
/*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);
} else {
lv_obj_set_size(obj_dp, LV_OBJ_DEF_WIDTH, LV_OBJ_DEF_HEIGHT);
}
break;
@@ -210,18 +136,28 @@ 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_layout_t layout)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
ext_p->layout = layout;
/*Send a signal to run the paddig calculations*/
obj_dp->signal_f(obj_dp, LV_SIGNAL_CHILD_CHG, NULL);
}
/**
* 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)
void lv_rect_set_fit(lv_obj_t * obj_dp, 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->hpad_en = hor_en == false ? 0 : 1;
ext_p->vpad_en = ver_en == false ? 0 : 1;
ext_p->hfit_en = hor_en == false ? 0 : 1;
ext_p->vfit_en = ver_en == false ? 0 : 1;
/*Send a signal to run the paddig calculations*/
lv_obj_t * par_dp = lv_obj_get_parent(obj_dp);
@@ -232,6 +168,12 @@ void lv_rect_set_pad_en(lv_obj_t * obj_dp, bool hor_en, bool ver_en)
* Getter functions
*====================*/
lv_layout_t lv_rect_get_layout(lv_obj_t * obj_dp)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
return ext_p->layout;
}
/**
* Get horizontal padding enable attribute of a rectangle
* @param obj_dp pointer to a rectangle object
@@ -240,7 +182,7 @@ 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)
{
lv_rect_ext_t * ext_p = lv_obj_get_ext(obj_dp);
return ext_p->hpad_en == 0 ? false : true;
return ext_p->hfit_en == 0 ? false : true;
}
/**
@@ -251,7 +193,7 @@ bool lv_rect_get_hpad_en(lv_obj_t * obj_dp)
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 ext_p->vfit_en == 0 ? false : true;
}
@@ -335,5 +277,212 @@ static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo
return true;
}
/**
* 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_layout_t type = lv_rect_get_layout(obj_dp);
if(type == LV_LAYOUT_OFF) return;
if(type == LV_LAYOUT_COL_L || type == LV_LAYOUT_COL_M || type == LV_LAYOUT_COL_R) {
lv_layout_col(obj_dp);
} else if(type == LV_LAYOUT_ROW_T || type == LV_LAYOUT_ROW_M || type == LV_LAYOUT_ROW_B) {
lv_layout_row(obj_dp);
} else if(type == LV_LAYOUT_CENTER) {
lv_layout_center(obj_dp);
}
}
/**
* Handle column type layouts
* @param obj_dp pointer to an object which layout should be handled
*/
static void lv_layout_col(lv_obj_t * obj_dp)
{
lv_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_LAYOUT_COL_L:
hpad_corr = rects_p->hpad;
align = LV_ALIGN_IN_TOP_LEFT;
break;
case LV_LAYOUT_COL_M:
hpad_corr = 0;
align = LV_ALIGN_IN_TOP_MID;
break;
case LV_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) {
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_layout_row(lv_obj_t * obj_dp)
{
lv_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_LAYOUT_ROW_T:
vpad_corr = rects_p->vpad;
align = LV_ALIGN_IN_TOP_LEFT;
break;
case LV_LAYOUT_ROW_M:
vpad_corr = 0;
align = LV_ALIGN_IN_LEFT_MID;
break;
case LV_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) {
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;
}
static void lv_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) {
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;
}
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) {
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;
}
area_cpy(&obj_dp->cords, &rect_cords);
/*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);
} else {
lv_obj_set_size(obj_dp, LV_OBJ_DEF_WIDTH, LV_OBJ_DEF_HEIGHT);
}
}
#endif

View File

@@ -23,6 +23,18 @@
* TYPEDEFS
**********************/
typedef enum
{
LV_LAYOUT_OFF = 0,
LV_LAYOUT_COL_L,
LV_LAYOUT_COL_M,
LV_LAYOUT_COL_R,
LV_LAYOUT_ROW_T,
LV_LAYOUT_ROW_M,
LV_LAYOUT_ROW_B,
LV_LAYOUT_CENTER,
}lv_layout_t;
typedef struct
{
lv_objs_t objs;
@@ -31,6 +43,7 @@ typedef struct
uint16_t bwidth;
cord_t hpad;
cord_t vpad;
cord_t opad;
uint16_t round;
uint8_t bopa;
uint8_t empty :1;
@@ -39,8 +52,9 @@ typedef struct
typedef struct
{
uint8_t hpad_en:1;
uint8_t vpad_en:1;
uint8_t hfit_en:1;
uint8_t vfit_en:1;
lv_layout_t layout;
}lv_rect_ext_t;
typedef enum
@@ -57,9 +71,10 @@ typedef enum
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);
void lv_rect_set_pad_en(lv_obj_t * obj_dp, bool hor_en, bool ver_en);
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_layout_t layout);
lv_layout_t lv_rect_get_layout(lv_obj_t * obj_dp);
bool lv_rect_get_hpad_en(lv_obj_t * obj_dp);
bool lv_rect_get_vpad_en(lv_obj_t * obj_dp);