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;
}