Skip to content

Commit

Permalink
fix(align) fix lv_obj_align_to
Browse files Browse the repository at this point in the history
  • Loading branch information
kisvegabor committed Jun 16, 2021
1 parent 8017f47 commit 93b38e9
Showing 1 changed file with 52 additions and 48 deletions.
100 changes: 52 additions & 48 deletions src/core/lv_obj_pos.c
Expand Up @@ -341,123 +341,127 @@ void lv_obj_align_to(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv

lv_coord_t x = 0;
lv_coord_t y = 0;

lv_obj_t * parent = lv_obj_get_parent(obj);
lv_coord_t pborder = lv_obj_get_style_border_width(parent, LV_PART_MAIN);
lv_coord_t pleft = lv_obj_get_style_pad_left(parent, LV_PART_MAIN) + pborder;
lv_coord_t ptop = lv_obj_get_style_pad_top(parent, LV_PART_MAIN) + pborder;

lv_coord_t border_width = lv_obj_get_style_border_width(parent, LV_PART_MAIN);
lv_coord_t pleft = lv_obj_get_style_pad_left(parent, LV_PART_MAIN) + border_width;
lv_coord_t ptop = lv_obj_get_style_pad_top(parent, LV_PART_MAIN) + border_width;
lv_coord_t bborder = lv_obj_get_style_border_width(base, LV_PART_MAIN);
lv_coord_t bleft = lv_obj_get_style_pad_left(base, LV_PART_MAIN) + bborder;
lv_coord_t btop = lv_obj_get_style_pad_top(base, LV_PART_MAIN) + bborder;

if(align == LV_ALIGN_DEFAULT) {
if(lv_obj_get_style_base_dir(parent, LV_PART_MAIN) == LV_BASE_DIR_RTL) align = LV_ALIGN_TOP_RIGHT;
if(lv_obj_get_style_base_dir(base, LV_PART_MAIN) == LV_BASE_DIR_RTL) align = LV_ALIGN_TOP_RIGHT;
else align = LV_ALIGN_TOP_LEFT;
}

switch(align) {
case LV_ALIGN_CENTER:
x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2;
x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft;
y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop;
break;
case LV_ALIGN_TOP_LEFT:
x = 0;
y = 0;
x = bleft;
y = btop;
break;
case LV_ALIGN_TOP_MID:
x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = 0;
x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft;
y = btop;
break;

case LV_ALIGN_TOP_RIGHT:
x = lv_obj_get_content_width(base) - lv_obj_get_width(obj);
y = 0;
x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft;
y = btop;
break;

case LV_ALIGN_BOTTOM_LEFT:
x = 0;
y = lv_obj_get_content_height(base) - lv_obj_get_height(obj);
x = bleft;
y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop;
break;
case LV_ALIGN_BOTTOM_MID:
x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = lv_obj_get_content_height(base) - lv_obj_get_height(obj);
x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft;
y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop;
break;

case LV_ALIGN_BOTTOM_RIGHT:
x = lv_obj_get_content_width(base) - lv_obj_get_width(obj);
y = lv_obj_get_content_height(base) - lv_obj_get_height(obj);
x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft;
y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop;
break;

case LV_ALIGN_LEFT_MID:
x = 0;
y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2;
x = bleft;
y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop;
break;

case LV_ALIGN_RIGHT_MID:
x = lv_obj_get_content_width(base) - lv_obj_get_width(obj);
y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2;
x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft;
y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop;
break;

case LV_ALIGN_OUT_TOP_LEFT:
x = -pleft;
y = -lv_obj_get_height(obj) - ptop;
x = 0;
y = -lv_obj_get_height(obj);
break;

case LV_ALIGN_OUT_TOP_MID:
x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2 - pleft;
y = -lv_obj_get_height(obj) - ptop;
x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = -lv_obj_get_height(obj);
break;

case LV_ALIGN_OUT_TOP_RIGHT:
x = lv_obj_get_width(base) - lv_obj_get_width(obj) - pleft;
y = -lv_obj_get_height(obj) - ptop;
x = lv_obj_get_width(base) - lv_obj_get_width(obj);
y = -lv_obj_get_height(obj);
break;

case LV_ALIGN_OUT_BOTTOM_LEFT:
x = - pleft;
y = lv_obj_get_height(base) - ptop;
x = 0;
y = lv_obj_get_height(base);
break;

case LV_ALIGN_OUT_BOTTOM_MID:
x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2 - pleft;
y = lv_obj_get_height(base) - ptop;
x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2;
y = lv_obj_get_height(base);
break;

case LV_ALIGN_OUT_BOTTOM_RIGHT:
x = lv_obj_get_width(base) - lv_obj_get_width(obj) - pleft;
y = lv_obj_get_height(base) - ptop;
x = lv_obj_get_width(base) - lv_obj_get_width(obj);
y = lv_obj_get_height(base);
break;

case LV_ALIGN_OUT_LEFT_TOP:
x = -lv_obj_get_width(obj) - pleft;
y = - ptop;
x = -lv_obj_get_width(obj);
y = 0;
break;

case LV_ALIGN_OUT_LEFT_MID:
x = -lv_obj_get_width(obj) - pleft;
y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2 - ptop;
x = -lv_obj_get_width(obj);
y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
break;

case LV_ALIGN_OUT_LEFT_BOTTOM:
x = -lv_obj_get_width(obj) - pleft;
y = lv_obj_get_height(base) - lv_obj_get_height(obj) - ptop;
x = -lv_obj_get_width(obj);
y = lv_obj_get_height(base) - lv_obj_get_height(obj);
break;

case LV_ALIGN_OUT_RIGHT_TOP:
x = lv_obj_get_width(base) - pleft;
y = - ptop;
x = lv_obj_get_width(base);
y = 0;
break;

case LV_ALIGN_OUT_RIGHT_MID:
x = lv_obj_get_width(base) - pleft;
y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2 - ptop;
x = lv_obj_get_width(base);
y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2;
break;

case LV_ALIGN_OUT_RIGHT_BOTTOM:
x = lv_obj_get_width(base) - pleft;
y = lv_obj_get_height(base) - lv_obj_get_height(obj) - ptop;
x = lv_obj_get_width(base);
y = lv_obj_get_height(base) - lv_obj_get_height(obj);
break;
}

x += x_ofs + base->coords.x1 - parent->coords.x1 + lv_obj_get_scroll_left(parent);
y += y_ofs + base->coords.y1 - parent->coords.y1 + lv_obj_get_scroll_top(parent);
x += x_ofs + base->coords.x1 - parent->coords.x1 + lv_obj_get_scroll_left(parent) - pleft;
y += y_ofs + base->coords.y1 - parent->coords.y1 + lv_obj_get_scroll_top(parent) - ptop;
lv_obj_set_style_align(obj, LV_ALIGN_TOP_LEFT, 0);
lv_obj_set_pos(obj, x, y);

Expand Down

0 comments on commit 93b38e9

Please sign in to comment.