// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_page.c
// Function: lv_page_focus
void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, lv_anim_enable_t anim_en)
{
    lv_page_ext_t * ext = lv_obj_get_ext_attr(page);

#if LV_USE_ANIMATION
    /* Be sure there is no position changing animation in progress
     * because it can overide the current changes*/
    lv_anim_del(page, (lv_anim_exec_xcb_t)lv_obj_set_x);
    lv_anim_del(page, (lv_anim_exec_xcb_t)lv_obj_set_y);
    lv_anim_del(ext->scrl, (lv_anim_exec_xcb_t)lv_obj_set_x);
    lv_anim_del(ext->scrl, (lv_anim_exec_xcb_t)lv_obj_set_y);
#endif

    const lv_style_t * style      = lv_page_get_style(page, LV_PAGE_STYLE_BG);
    const lv_style_t * style_scrl = lv_page_get_style(page, LV_PAGE_STYLE_SCRL);

    /*If obj is higher then the page focus where the "error" is smaller*/
    lv_coord_t obj_y      = obj->coords.y1 - ext->scrl->coords.y1;
    lv_coord_t obj_h      = lv_obj_get_height(obj);
    lv_coord_t scrlable_y = lv_obj_get_y(ext->scrl);
    lv_coord_t page_h     = lv_obj_get_height(page);

    lv_coord_t top_err = -(scrlable_y + obj_y);
    lv_coord_t bot_err = scrlable_y + obj_y + obj_h - page_h;

    /*Out of the page on the top*/
    if((obj_h <= page_h && top_err > 0) || (obj_h > page_h && top_err < bot_err)) {
        /*Calculate a new position and let some space above*/
        scrlable_y = -(obj_y - style_scrl->body.padding.top - style->body.padding.top);
        scrlable_y += style_scrl->body.padding.top;
    }
    /*Out of the page on the bottom*/
    else if((obj_h <= page_h && bot_err > 0) || (obj_h > page_h && top_err >= bot_err)) {
        /*Calculate a new position and let some space below*/
        scrlable_y = -(obj_y + style_scrl->body.padding.bottom + style->body.padding.bottom);
        scrlable_y -= style_scrl->body.padding.bottom;
        scrlable_y += page_h - obj_h;
    }

    /*If obj is wider then the page focus where the "error" is smaller*/
    lv_coord_t obj_x      = obj->coords.x1 - ext->scrl->coords.x1;
    lv_coord_t obj_w      = lv_obj_get_width(obj);
    lv_coord_t scrlable_x = lv_obj_get_x(ext->scrl);
    lv_coord_t page_w     = lv_obj_get_width(page);

    lv_coord_t left_err  = -(scrlable_x + obj_x);
    lv_coord_t right_err = scrlable_x + obj_x + obj_w - page_w;

    /*Out of the page on the left*/
    if((obj_w <= page_w && left_err > 0) || (obj_w > page_w && left_err < right_err)) {
        /*Calculate a new position and let some space above*/
        scrlable_x = -(obj_x - style_scrl->body.padding.left - style->body.padding.left);
        scrlable_x += style_scrl->body.padding.left;
    }
    /*Out of the page on the rigth*/
    else if((obj_w <= page_w && right_err > 0) || (obj_w > page_w && left_err >= right_err)) {
        /*Calculate a new position and let some space below*/
        scrlable_x = -(obj_x + style_scrl->body.padding.right + style->body.padding.right);
        scrlable_x -= style_scrl->body.padding.right;
        scrlable_x += page_w - obj_w;
    }

    if(anim_en == LV_ANIM_OFF || lv_page_get_anim_time(page) == 0) {
        lv_obj_set_y(ext->scrl, scrlable_y);
        lv_obj_set_x(ext->scrl, scrlable_x);
    } else {
#if LV_USE_ANIMATION
        lv_anim_t a;
        a.act_time = 0;
        a.start    = lv_obj_get_y(ext->scrl);
        a.end      = scrlable_y;
        a.time     = lv_page_get_anim_time(page);
        a.ready_cb = NULL;
        a.playback = 0;
        a.repeat   = 0;
        a.var      = ext->scrl;
        a.path_cb  = lv_anim_path_linear;
        a.exec_cb  = (lv_anim_exec_xcb_t)lv_obj_set_y;
        lv_anim_create(&a);

        a.start   = lv_obj_get_x(ext->scrl);
        a.end     = scrlable_x;
        a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_x;
        lv_anim_create(&a);
#endif
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, 0x1c(%rsp)
movq %rsi, %rbp
movq %rdi, %r15
callq 0x6747
movq %rax, %rbx
leaq -0x1f793(%rip), %r14    # 0x5192
movq %r15, %rdi
movq %r14, %rsi
callq 0x27715
leaq -0x1f767(%rip), %r12    # 0x51d0
movq %r15, %rdi
movq %r12, %rsi
callq 0x27715
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x27715
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x27715
movq %r15, %rdi
xorl %esi, %esi
callq 0x24149
movq %rax, 0x10(%rsp)
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x24149
movq %rax, 0x8(%rsp)
movzwl 0x22(%rbp), %r12d
movq 0x8(%rbx), %rax
subw 0x22(%rax), %r12w
movq %rbp, %rdi
callq 0x5332
movl %eax, %r14d
movq 0x8(%rbx), %rdi
callq 0x4902
movl %eax, %r13d
movq %r15, %rdi
callq 0x5332
leal (%r12,%r13), %esi
movl %r14d, %edx
subw %ax, %dx
movl %esi, %ecx
negl %ecx
movswl %cx, %ecx
cmpw %ax, %r14w
jg 0x249c1
testl %ecx, %ecx
jg 0x249d8
addl %esi, %edx
movswl %dx, %edx
cmpw %ax, %r14w
jle 0x24b3e
cmpl %edx, %ecx
jge 0x24b3e
movq 0x8(%rsp), %rax
movzwl 0x16(%rax), %eax
movq 0x10(%rsp), %rcx
movzwl 0x16(%rcx), %ecx
subl %r12d, %ecx
leal (%rcx,%rax,2), %r13d
movzwl 0x20(%rbp), %r12d
movq 0x8(%rbx), %rax
subw 0x20(%rax), %r12w
movq %rbp, %rdi
callq 0x5308
movl %eax, %r14d
movq 0x8(%rbx), %rdi
callq 0x48ca
movl %eax, %ebp
movq %r15, %rdi
callq 0x5308
leal (%r12,%rbp), %esi
movl %r14d, %edx
subw %ax, %dx
movl %esi, %ecx
negl %ecx
movswl %cx, %ecx
cmpw %ax, %r14w
jg 0x24a38
testl %ecx, %ecx
jg 0x24a4f
addl %esi, %edx
movswl %dx, %edx
cmpw %ax, %r14w
jle 0x24b8a
cmpl %edx, %ecx
jge 0x24b8a
movq 0x8(%rsp), %rax
movzwl 0x1a(%rax), %eax
movq 0x10(%rsp), %rcx
movzwl 0x1a(%rcx), %ecx
subl %r12d, %ecx
leal (%rcx,%rax,2), %ebp
cmpb $0x0, 0x1c(%rsp)
je 0x24b17
movq %r15, %rdi
callq 0x246b8
testw %ax, %ax
je 0x24b17
leaq 0x20(%rsp), %r14
andw $0x0, 0x2a(%r14)
movq 0x8(%rbx), %rdi
callq 0x4902
cwtl
movl %eax, 0x20(%r14)
movswl %r13w, %eax
movl %eax, 0x24(%r14)
movq %r15, %rdi
callq 0x246b8
movw %ax, 0x28(%r14)
andq $0x0, 0x18(%r14)
movb $0x0, 0x30(%r14)
movq 0x8(%rbx), %rax
movq %rax, (%r14)
leaq 0x2b90(%rip), %rax      # 0x27659
movq %rax, 0x10(%r14)
leaq -0x1f904(%rip), %rax    # 0x51d0
movq %rax, 0x8(%r14)
movq %r14, %rdi
callq 0x27685
movq 0x8(%rbx), %rdi
callq 0x48ca
cwtl
movl %eax, 0x20(%r14)
movswl %bp, %eax
movl %eax, 0x24(%r14)
leaq -0x1f96a(%rip), %rax    # 0x5192
movq %rax, 0x8(%r14)
movq %r14, %rdi
callq 0x27685
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %rdi
movswl %r13w, %esi
callq 0x51d0
movq 0x8(%rbx), %rdi
movswl %bp, %esi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5192
cmpl %edx, %ecx
setl %cl
cmpw %ax, %r14w
setle %sil
setg %dil
testw %dx, %dx
setle %dl
orb %dil, %dl
cmpb $0x1, %dl
jne 0x24b66
orb %cl, %sil
jne 0x249f1
addl %r12d, %r14d
movq 0x10(%rsp), %rcx
addw 0x18(%rcx), %r14w
movq 0x8(%rsp), %rcx
movzwl 0x18(%rcx), %ecx
leal (%r14,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, %r13d
jmp 0x249f1
cmpl %edx, %ecx
setl %cl
cmpw %ax, %r14w
setle %sil
setg %dil
testw %dx, %dx
setle %dl
orb %dil, %dl
cmpb $0x1, %dl
jne 0x24bb2
orb %cl, %sil
jne 0x24a67
addl %r12d, %r14d
movq 0x10(%rsp), %rcx
addw 0x1c(%rcx), %r14w
movq 0x8(%rsp), %rcx
movzwl 0x1c(%rcx), %ecx
leal (%r14,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, %ebp
jmp 0x24a67