// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_page.c
// Function: lv_page_scrollable_signal
static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_signal(scrl, sign, param);
    if(res != LV_RES_OK) return res;
    if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, "");

    lv_obj_t * page               = lv_obj_get_parent(scrl);
    const lv_style_t * page_style = lv_obj_get_style(page);
    lv_page_ext_t * page_ext      = lv_obj_get_ext_attr(page);

    if(sign == LV_SIGNAL_CORD_CHG) {
        /*Limit the position of the scrollable object to be always visible
         * (Do not let its edge inner then its parent respective edge)*/
        lv_coord_t new_x = lv_obj_get_x(scrl);
        lv_coord_t new_y = lv_obj_get_y(scrl);
        bool refr_x      = false;
        bool refr_y      = false;
        lv_area_t page_coords;
        lv_area_t scrl_coords;
        lv_obj_get_coords(scrl, &scrl_coords);
        lv_obj_get_coords(page, &page_coords);

        lv_area_t * ori_coords = (lv_area_t *)param;
        lv_coord_t diff_x      = scrl->coords.x1 - ori_coords->x1;
        lv_coord_t diff_y      = scrl->coords.y1 - ori_coords->y1;
        lv_coord_t hpad        = page_style->body.padding.left + page_style->body.padding.right;
        lv_coord_t vpad        = page_style->body.padding.top + page_style->body.padding.bottom;
        lv_obj_t * page_parent = lv_obj_get_parent(page);

        lv_indev_t * indev = lv_indev_get_act();
        lv_point_t drag_vect;
        lv_indev_get_vect(indev, &drag_vect);

        /* Start the scroll propagation if there is drag vector on the indev, but the drag is not
         * started yet and the scrollable is in a corner. It will enable the scroll propagation only
         * when a new scroll begins and not when the scrollable is already being scrolled.*/
        if(page_ext->scroll_prop && page_ext->scroll_prop_ip == 0 && lv_indev_is_dragging(indev) == false) {
            if(((drag_vect.y > 0 && scrl_coords.y1 == page_coords.y1 + page_style->body.padding.top) ||
                (drag_vect.y < 0 && scrl_coords.y2 == page_coords.y2 - page_style->body.padding.bottom)) &&
               ((drag_vect.x > 0 && scrl_coords.x1 == page_coords.x1 + page_style->body.padding.left) ||
                (drag_vect.x < 0 && scrl_coords.x2 == page_coords.x2 - page_style->body.padding.right))) {

                if(lv_obj_get_parent(page_parent) != NULL) { /*Do not propagate the scroll to a screen*/
                    page_ext->scroll_prop_ip = 1;
                }
            }
        }

        /*scrollable width smaller then page width? -> align to left*/
        if(lv_area_get_width(&scrl_coords) + hpad <= lv_area_get_width(&page_coords)) {
            if(scrl_coords.x1 != page_coords.x1 + page_style->body.padding.left) {
                new_x  = page_style->body.padding.left;
                refr_x = true;
            }
        } else {
            /*If the scroll propagation is in progress revert the original coordinates (don't let
             * the page scroll)*/
            if(page_ext->scroll_prop_ip) {
                if(drag_vect.x == diff_x) { /*`scrl` is bouncing: drag pos. it somewhere and here it
                                               is reverted. Handle only the pos. because of drag*/
                    new_x  = ori_coords->x1 - page_coords.x1;
                    refr_x = true;
                }
            }
            /*The edges of the scrollable can not be in the page (minus hpad) */
            else if(scrl_coords.x2 < page_coords.x2 - page_style->body.padding.right) {
                new_x = lv_area_get_width(&page_coords) - lv_area_get_width(&scrl_coords) -
                        page_style->body.padding.right; /* Right align */
                refr_x = true;
#if LV_USE_ANIMATION
                if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 &&
                   page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 &&
                   page_ext->edge_flash.bottom_ip == 0) {
                    lv_page_start_edge_flash(page);
                    page_ext->edge_flash.right_ip = 1;
                }
#endif
            } else if(scrl_coords.x1 > page_coords.x1 + page_style->body.padding.left) {
                new_x  = page_style->body.padding.left; /*Left align*/
                refr_x = true;
#if LV_USE_ANIMATION
                if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 &&
                   page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 &&
                   page_ext->edge_flash.bottom_ip == 0) {
                    lv_page_start_edge_flash(page);
                    page_ext->edge_flash.left_ip = 1;
                }
#endif
            }
        }

        /*scrollable height smaller then page height? -> align to top*/
        if(lv_area_get_height(&scrl_coords) + vpad <= lv_area_get_height(&page_coords)) {
            if(scrl_coords.y1 != page_coords.y1 + page_style->body.padding.top) {
                new_y  = page_style->body.padding.top;
                refr_y = true;
            }
        } else {
            /*If the scroll propagation is in progress revert the original coordinates (don't let
             * the page scroll)*/
            if(page_ext->scroll_prop_ip) {
                if(drag_vect.y == diff_y) { /*`scrl` is bouncing: drag pos. it somewhere and here it
                                               is reverted. Handle only the pos. because of drag*/
                    new_y  = ori_coords->y1 - page_coords.y1;
                    refr_y = true;
                }
            }
            /*The edges of the scrollable can not be in the page (minus vpad) */
            else if(scrl_coords.y2 < page_coords.y2 - page_style->body.padding.bottom) {
                new_y = lv_area_get_height(&page_coords) - lv_area_get_height(&scrl_coords) -
                        page_style->body.padding.bottom; /* Bottom align */
                refr_y = true;
#if LV_USE_ANIMATION
                if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 &&
                   page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 &&
                   page_ext->edge_flash.bottom_ip == 0) {
                    lv_page_start_edge_flash(page);
                    page_ext->edge_flash.bottom_ip = 1;
                }
#endif
            } else if(scrl_coords.y1 > page_coords.y1 + page_style->body.padding.top) {
                new_y  = page_style->body.padding.top; /*Top align*/
                refr_y = true;
#if LV_USE_ANIMATION
                if(page_ext->edge_flash.enabled && page_ext->edge_flash.left_ip == 0 &&
                   page_ext->edge_flash.right_ip == 0 && page_ext->edge_flash.top_ip == 0 &&
                   page_ext->edge_flash.bottom_ip == 0) {
                    lv_page_start_edge_flash(page);
                    page_ext->edge_flash.top_ip = 1;
                }
#endif
            }
        }

        if(refr_x || refr_y) {
            lv_obj_set_pos(scrl, new_x, new_y);

            if(page_ext->scroll_prop_ip) {
                if(refr_y) lv_obj_set_y(page_parent, lv_obj_get_y(page_parent) + diff_y);
                if(refr_x) lv_obj_set_x(page_parent, lv_obj_get_x(page_parent) + diff_x);
            }
        }

        lv_page_sb_refresh(page);
    } else if(sign == LV_SIGNAL_DRAG_END) {

        /*Scroll propagation is finished on drag end*/
        page_ext->scroll_prop_ip = 0;

        /*Hide scrollbars if required*/
        if(page_ext->sb.mode == LV_SB_MODE_DRAG) {
            lv_disp_t * disp = lv_obj_get_disp(page);
            lv_area_t sb_area_tmp;
            if(page_ext->sb.hor_draw) {
                lv_area_copy(&sb_area_tmp, &page_ext->sb.hor_area);
                sb_area_tmp.x1 += page->coords.x1;
                sb_area_tmp.y1 += page->coords.y1;
                sb_area_tmp.x2 += page->coords.x1;
                sb_area_tmp.y2 += page->coords.y1;
                lv_inv_area(disp, &sb_area_tmp);
                page_ext->sb.hor_draw = 0;
            }
            if(page_ext->sb.ver_draw) {
                lv_area_copy(&sb_area_tmp, &page_ext->sb.ver_area);
                sb_area_tmp.x1 += page->coords.x1;
                sb_area_tmp.y1 += page->coords.y1;
                sb_area_tmp.x2 += page->coords.x1;
                sb_area_tmp.y2 += page->coords.y1;
                lv_inv_area(disp, &sb_area_tmp);
                page_ext->sb.ver_draw = 0;
            }
        }
    }

    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r13
movl %esi, %r15d
movq %rdi, %r12
callq *0x3b099(%rip)          # 0x5e468
movl %eax, %ebx
cmpb $0x1, %al
jne 0x23890
cmpb $0x7, %r15b
jne 0x233fc
leaq 0x1c05f(%rip), %rsi     # 0x3f445
movq %r13, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x684b
movq %r12, %rdi
callq 0x47bc
movq %rax, %r14
movq %rax, %rdi
callq 0x6316
movq %rax, %rbp
movq %r14, %rdi
callq 0x6747
movb $0x1, %bl
cmpb $0xf, %r15b
je 0x23558
movzbl %r15b, %ecx
cmpl $0x2, %ecx
jne 0x23890
movq %r12, %rdi
movq %rax, 0x28(%rsp)
callq 0x48ca
movl %eax, 0x4c(%rsp)
movq %r12, %rdi
callq 0x4902
movl %eax, 0x34(%rsp)
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x50e5
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x50e5
movzwl 0x20(%r12), %eax
movzwl 0x22(%r12), %ecx
subw (%r13), %ax
movl %eax, 0x48(%rsp)
subw 0x2(%r13), %cx
movl %ecx, 0x44(%rsp)
movzwl 0x18(%rbp), %eax
movq %r14, %rdi
movzwl 0x1c(%rbp), %r14d
addw 0x1a(%rbp), %r14w
addw 0x16(%rbp), %ax
movw %ax, 0xe(%rsp)
movq %rdi, 0x38(%rsp)
callq 0x47bc
movq %rax, 0x50(%rsp)
callq 0x35b3
movq %rax, %r15
leaq 0x1c(%rsp), %rsi
movq %rax, %rdi
callq 0x36ac
movq 0x28(%rsp), %r11
movb 0x4a(%r11), %al
andb $0x3, %al
cmpb $0x1, %al
jne 0x23629
movq %r15, %rdi
callq 0x3691
movq 0x28(%rsp), %r11
testb %al, %al
jne 0x23629
cmpw $0x0, 0x1e(%rsp)
jle 0x235f3
movswl 0x22(%rsp), %eax
movswl 0x12(%rsp), %ecx
movswl 0x16(%rbp), %edx
addl %ecx, %edx
cmpl %eax, %edx
jne 0x23629
cmpw $0x0, 0x1c(%rsp)
jle 0x2360f
movswl 0x20(%rsp), %eax
movswl 0x10(%rsp), %ecx
movswl 0x1a(%rbp), %edx
addl %ecx, %edx
cmpl %eax, %edx
jne 0x23629
movq 0x50(%rsp), %rdi
callq 0x47bc
movq 0x28(%rsp), %r11
testq %rax, %rax
je 0x23629
orb $0x2, 0x4a(%r11)
jmp 0x23629
andb $-0x3, 0x4a(%rax)
movb 0x28(%rax), %cl
andb $0x1c, %cl
cmpb $0x8, %cl
jne 0x23890
movq %r14, %rdi
movq %rax, %r12
callq 0x4d17
movq %r12, %rcx
movq %rax, %r15
movb 0x28(%r12), %al
testb $0x1, %al
je 0x235b9
movq 0x20(%r14), %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movq 0x18(%rcx), %xmm1
paddw %xmm0, %xmm1
leaq 0x10(%rsp), %rsi
movq %xmm1, (%rsi)
movq %r15, %rdi
callq 0x6cff
movq %r12, %rcx
movb 0x28(%r12), %al
andb $-0x2, %al
movb %al, 0x28(%r12)
testb $0x2, %al
je 0x23890
movq 0x20(%r14), %xmm0
pshufd $0x50, %xmm0, %xmm0     # xmm0 = xmm0[0,0,1,1]
movq 0x20(%rcx), %xmm1
paddw %xmm0, %xmm1
leaq 0x10(%rsp), %rsi
movq %xmm1, (%rsi)
movq %r15, %rdi
movq %rcx, %r14
callq 0x6cff
andb $-0x3, 0x28(%r14)
jmp 0x23890
jns 0x23629
movswl 0x26(%rsp), %eax
movswl 0x16(%rsp), %ecx
movswl 0x18(%rbp), %edx
subl %edx, %ecx
cmpl %eax, %ecx
je 0x23512
jmp 0x23629
jns 0x23629
movswl 0x24(%rsp), %eax
movswl 0x14(%rsp), %ecx
movswl 0x1c(%rbp), %edx
subl %edx, %ecx
cmpl %eax, %ecx
je 0x23536
movswl 0x24(%rsp), %esi
movswl 0x20(%rsp), %eax
movl %esi, %ecx
subl %eax, %ecx
incl %ecx
movswl %cx, %edx
movswl %r14w, %r9d
addl %edx, %r9d
movswl 0x14(%rsp), %r8d
movswl 0x10(%rsp), %edx
movl %r8d, %edi
subl %edx, %edi
incl %edi
movswl %di, %r10d
cmpl %r10d, %r9d
jle 0x236b0
testb $0x2, 0x4a(%r11)
movl 0x4c(%rsp), %r10d
jne 0x2376b
movswl 0x1c(%rbp), %r9d
subl %r9d, %r8d
cmpl %esi, %r8d
jle 0x237a7
addl %r9d, %ecx
subl %ecx, %edi
movl %edi, %r10d
movb 0x40(%r11), %al
andb $0x1f, %al
movb $0x1, %r15b
cmpb $0x1, %al
jne 0x236c5
movq 0x38(%rsp), %rdi
movl %r10d, %r14d
callq 0x24c93
movl %r14d, %r10d
movq 0x28(%rsp), %r11
orb $0x8, 0x40(%r11)
jmp 0x236c5
movswl 0x1a(%rbp), %ecx
addl %ecx, %edx
cmpl %eax, %edx
setne %r15b
movl 0x4c(%rsp), %r10d
cmovnel %ecx, %r10d
movzwl 0xe(%rsp), %edi
movswl 0x26(%rsp), %esi
movswl 0x22(%rsp), %eax
movl %esi, %ecx
subl %eax, %ecx
incl %ecx
movswl %cx, %edx
movswl %di, %r8d
addl %edx, %r8d
movswl 0x16(%rsp), %edi
movswl 0x12(%rsp), %edx
movl %edi, %r14d
subl %edx, %r14d
incl %r14d
movswl %r14w, %r9d
cmpl %r9d, %r8d
jle 0x23751
testb $0x2, 0x4a(%r11)
jne 0x2378f
movswl 0x18(%rbp), %r8d
subl %r8d, %edi
cmpl %esi, %edi
jle 0x237e0
addl %r8d, %ecx
subl %ecx, %r14d
movb 0x40(%r11), %al
andb $0x1f, %al
movb $0x1, %bpl
cmpb $0x1, %al
jne 0x23826
movq 0x38(%rsp), %rdi
movl %r10d, %r13d
callq 0x24c93
movl %r13d, %r10d
movq 0x28(%rsp), %r11
orb $0x4, 0x40(%r11)
jmp 0x23826
movswl 0x16(%rbp), %ecx
addl %ecx, %edx
cmpl %eax, %edx
setne %bpl
movl 0x34(%rsp), %r14d
cmovnel %ecx, %r14d
jmp 0x2381c
movl 0x48(%rsp), %eax
cmpw %ax, 0x1c(%rsp)
movzwl 0xe(%rsp), %edi
jne 0x238a1
movzwl (%r13), %r10d
subl %edx, %r10d
movb $0x1, %r15b
jmp 0x236ca
movl 0x44(%rsp), %eax
cmpw %ax, 0x1e(%rsp)
jne 0x23815
movzwl 0x2(%r13), %r14d
subl %edx, %r14d
movb $0x1, %bpl
jmp 0x23826
movswl 0x1a(%rbp), %r14d
addl %r14d, %edx
cmpl %eax, %edx
jge 0x238a9
movb 0x40(%r11), %al
andb $0x1f, %al
movb $0x1, %r15b
cmpb $0x1, %al
jne 0x237d8
movq 0x38(%rsp), %rdi
callq 0x24c93
movq 0x28(%rsp), %r11
orb $0x10, 0x40(%r11)
movl %r14d, %r10d
jmp 0x236c5
movswl 0x16(%rbp), %r14d
addl %r14d, %edx
cmpl %eax, %edx
jge 0x23815
movb 0x40(%r11), %al
andb $0x1f, %al
movb $0x1, %bpl
cmpb $0x1, %al
jne 0x23826
movq 0x38(%rsp), %rdi
movl %r10d, %r13d
callq 0x24c93
movl %r13d, %r10d
movq 0x28(%rsp), %r11
orb $0x2, 0x40(%r11)
jmp 0x23826
xorl %ebp, %ebp
movl 0x34(%rsp), %r14d
movl %r15d, %eax
orb %bpl, %al
cmpb $0x1, %al
jne 0x23886
movswl %r10w, %esi
movswl %r14w, %edx
movq %r12, %rdi
movq %r11, %r14
callq 0x47df
testb $0x2, 0x4a(%r14)
je 0x23886
testb %bpl, %bpl
je 0x23863
movq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x4902
movl 0x44(%rsp), %ecx
addl %eax, %ecx
movswl %cx, %esi
movq %r14, %rdi
callq 0x51d0
testb %r15b, %r15b
je 0x23886
movq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x48ca
movl 0x48(%rsp), %ecx
addl %eax, %ecx
movswl %cx, %esi
movq %r14, %rdi
callq 0x5192
movq 0x38(%rsp), %rdi
callq 0x241b6
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
jmp 0x236ca
xorl %r15d, %r15d
jmp 0x236c5