mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
fix(align) fix lv_obj_align_to
This commit is contained in:
parent
8017f47227
commit
93b38e92be
@ -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 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_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 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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user