simpilfy flex constants

This commit is contained in:
Gabor Kiss-Vamosi
2020-10-22 14:19:49 +02:00
parent 4eb222f7be
commit e3fedd29c9
4 changed files with 33 additions and 28 deletions

View File

@@ -36,17 +36,19 @@ static void place_content(lv_coord_t place, lv_coord_t max_size, lv_coord_t trac
* GLOBAL FUNCTIONS
**********************/
void lv_obj_set_flex_cont(lv_obj_t * obj, lv_flex_dir_t flex_dir)
void lv_obj_set_flex_cont(lv_obj_t * obj, lv_flex_dir_t flex_dir, lv_flex_place_t flex_place)
{
if(obj->flex_dir == flex_dir) return;
obj->flex_dir = flex_dir;
obj->flex_place = flex_place;
_lv_flex_refresh(obj);
}
void lv_obj_set_flex_item(lv_obj_t * obj, lv_flex_place_t place)
{
lv_obj_set_pos(obj, place, place);
lv_coord_t f = _LV_COORD_FELX(place);
lv_obj_set_pos(obj, f, f);
}
void _lv_flex_refresh(lv_obj_t * cont)
@@ -62,7 +64,7 @@ void _lv_flex_refresh(lv_obj_t * cont)
lv_coord_t * cross_pos = (main_dir == LV_DIR_HOR ? &abs_y : &abs_x);
lv_coord_t row_place = LV_FLEX_START;
lv_coord_t place = cont->flex_place;
lv_coord_t all_track_size = 0;
lv_coord_t gap = 0;
uint32_t row_cnt = 0;
@@ -72,7 +74,7 @@ void _lv_flex_refresh(lv_obj_t * cont)
lv_obj_t * next_track_first_item;
bool rev = cont->flex_dir & LV_FLEX_REVERSE;
if(row_place != LV_FLEX_START) {
if(place != LV_FLEX_START) {
track_first_item = rev ? _lv_ll_get_head(&cont->child_ll) : _lv_ll_get_tail(&cont->child_ll);
while(track_first_item) {
@@ -84,7 +86,7 @@ void _lv_flex_refresh(lv_obj_t * cont)
}
lv_coord_t max_cross_size = (main_dir == LV_DIR_HOR ? lv_obj_get_height_fit(cont) : lv_obj_get_width_fit(cont));
place_content(row_place, max_cross_size, all_track_size,row_cnt, cross_pos, &gap);
place_content(place, max_cross_size, all_track_size,row_cnt, cross_pos, &gap);
}
track_first_item = rev ? _lv_ll_get_head(&cont->child_ll) : _lv_ll_get_tail(&cont->child_ll);

View File

@@ -32,12 +32,12 @@ extern "C" {
**********************/
typedef enum {
LV_FLEX_START = _LV_COORD_FELX(0),
LV_FLEX_END = _LV_COORD_FELX(1),
LV_FLEX_CENTER = _LV_COORD_FELX(2),
LV_FLEX_SPACE_EVENLY = _LV_COORD_FELX(3),
LV_FLEX_SPACE_AROUND = _LV_COORD_FELX(4),
LV_FLEX_SPACE_BETWEEN = _LV_COORD_FELX(5),
LV_FLEX_START,
LV_FLEX_END,
LV_FLEX_CENTER,
LV_FLEX_SPACE_EVENLY,
LV_FLEX_SPACE_AROUND,
LV_FLEX_SPACE_BETWEEN,
}lv_flex_place_t;
typedef enum {
@@ -50,7 +50,7 @@ typedef enum {
* GLOBAL PROTOTYPES
**********************/
void lv_obj_set_flex_cont(lv_obj_t * obj, lv_flex_dir_t flex_dir);
void lv_obj_set_flex_cont(lv_obj_t * obj, lv_flex_dir_t flex_dir, lv_flex_place_t flex_place);
void lv_obj_set_flex_item(lv_obj_t * obj, lv_flex_place_t place);
void _lv_flex_refresh(lv_obj_t * cont);

View File

@@ -256,7 +256,9 @@ struct _lv_obj_t {
const lv_grid_t * grid;
uint8_t flex_dir;
uint8_t flex_dir : 4;
uint8_t flex_place : 4;
};

View File

@@ -263,15 +263,15 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co
lv_coord_t y;
switch(align) {
case LV_ALIGN_CENTER:
x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width_fit(obj) / 2;
y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height_fit(obj) / 2;
x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
break;
case LV_ALIGN_IN_TOP_LEFT:
x = 0;
y = 0;
break;
case LV_ALIGN_IN_TOP_MID:
x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width_fit(obj) / 2;
x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = 0;
break;
@@ -282,26 +282,26 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co
case LV_ALIGN_IN_BOTTOM_LEFT:
x = 0;
y = lv_obj_get_height_fit(base) - lv_obj_get_height_fit(obj);
y = lv_obj_get_height(base) - lv_obj_get_height(obj);
break;
case LV_ALIGN_IN_BOTTOM_MID:
x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width_fit(obj) / 2;
y = lv_obj_get_height_fit(base) - lv_obj_get_height_fit(obj);
x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = lv_obj_get_height(base) - lv_obj_get_height(obj);
break;
case LV_ALIGN_IN_BOTTOM_RIGHT:
x = lv_obj_get_width_fit(base) - lv_obj_get_width_fit(obj);
y = lv_obj_get_height_fit(base) - lv_obj_get_height_fit(obj);
x = lv_obj_get_width(base) - lv_obj_get_width(obj);
y = lv_obj_get_height(base) - lv_obj_get_height(obj);
break;
case LV_ALIGN_IN_LEFT_MID:
x = 0;
y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height_fit(obj) / 2;
y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
break;
case LV_ALIGN_IN_RIGHT_MID:
x = lv_obj_get_width_fit(base) - lv_obj_get_width_fit(obj);
y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height_fit(obj) / 2;
x = lv_obj_get_width(base) - lv_obj_get_width(obj);
y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
break;
case LV_ALIGN_OUT_TOP_LEFT:
@@ -360,13 +360,14 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co
break;
case LV_ALIGN_OUT_RIGHT_BOTTOM:
x = lv_obj_get_width_fit(base);
y = lv_obj_get_height_fit(base) - lv_obj_get_height_fit(obj);
x = lv_obj_get_width(base);
y = lv_obj_get_height(base) - lv_obj_get_height(obj);
break;
}
x += x_ofs + base->coords.x1;
y += y_ofs + base->coords.y1;
lv_obj_t * parent = lv_obj_get_parent(obj);
x += x_ofs + base->coords.x1 - parent->coords.x1 - lv_obj_get_style_pad_left(parent, LV_OBJ_PART_MAIN);
y += y_ofs + base->coords.y1 - parent->coords.y1 - lv_obj_get_style_pad_top(parent, LV_OBJ_PART_MAIN);
lv_obj_set_pos(obj, x, y);
}