// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_ddlist.c
// Function: release_handler
static lv_res_t release_handler(lv_obj_t * ddlist)
{
    lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);

    if(ext->opened == 0) { /*Open the list*/
        ext->opened = 1;
        lv_obj_set_drag(lv_page_get_scrl(ddlist), true);
        lv_ddlist_refr_size(ddlist, true);
    } else {

        lv_indev_t * indev = lv_indev_get_act();
#if LV_USE_GROUP
        /*Leave edit mode once a new item is selected*/
        if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) {
            ext->sel_opt_id_ori = ext->sel_opt_id;
            lv_group_t * g      = lv_obj_get_group(ddlist);
            if(lv_group_get_editing(g)) {
                lv_group_set_editing(g, false);
            }
        }
#endif

        /*Search the clicked option (For KEYPAD and ENCODER the new value should be already set)*/
        if(lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER || lv_indev_get_type(indev) == LV_INDEV_TYPE_BUTTON) {
            lv_point_t p;
            lv_indev_get_point(indev, &p);
            p.y -= ext->label->coords.y1;
            p.x -= ext->label->coords.x1;
            uint16_t letter_i;
            letter_i = lv_label_get_letter_on(ext->label, &p);

            uint16_t new_opt  = 0;
            const char * txt  = lv_label_get_text(ext->label);
            uint32_t i        = 0;
            uint32_t i_prev   = 0;

            uint32_t letter_cnt = 0;
            uint32_t letter;
            for(letter_cnt = 0; letter_cnt < letter_i; letter_cnt++) {
                letter = lv_txt_encoded_next(txt, &i);
                /*Count he lines to reach the clicked letter. But ignore the last '\n' because it
                 * still belongs to the clicked line*/
                if(letter == '\n' && i_prev != letter_i) new_opt++;
                i_prev = i;
            }

            ext->sel_opt_id     = new_opt;
            ext->sel_opt_id_ori = ext->sel_opt_id;
        }

        uint32_t id  = ext->sel_opt_id; /*Just to use uint32_t in event data*/
        lv_res_t res = lv_event_send(ddlist, LV_EVENT_VALUE_CHANGED, &id);
        if(res != LV_RES_OK) return res;

        if(ext->stay_open == 0) {
            ext->opened = 0;
            lv_obj_set_drag(lv_page_get_scrl(ddlist), false);
            lv_ddlist_refr_size(ddlist, true);
        } else {
            lv_obj_invalidate(ddlist);
        }
    }

    return LV_RES_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0x6747
movq %rax, %r14
movb 0x66(%rax), %al
testb $0x1, %al
jne 0xbc6d
orb $0x1, %al
movb %al, 0x66(%r14)
movq %rbx, %rdi
callq 0x245d9
pushq $0x1
popq %rbp
movq %rax, %rdi
movl %ebp, %esi
callq 0x5ce4
movq %rbx, %rdi
movl %ebp, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb5f7
callq 0x35b3
movq %rax, %r15
movq %rax, %rdi
callq 0x35bb
cmpb $0x4, %al
jne 0xbcac
movzwl 0x62(%r14), %eax
movw %ax, 0x64(%r14)
movq %rbx, %rdi
callq 0x4b8e
movq %rax, %r12
movq %rax, %rdi
callq 0x2aaa
testb %al, %al
je 0xbcac
movq %r12, %rdi
xorl %esi, %esi
callq 0x275c
movq %r15, %rdi
callq 0x35bb
cmpb $0x1, %al
je 0xbcc8
movq %r15, %rdi
callq 0x35bb
cmpb $0x3, %al
jne 0xbd6c
movq %rbx, 0x18(%rsp)
leaq 0x24(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3661
movq 0x50(%r14), %rdi
movq 0x20(%rdi), %xmm0
movd (%r12), %xmm1
psubw %xmm0, %xmm1
movd %xmm1, (%r12)
movq %r12, %rsi
callq 0x19a81
movl %eax, %ebp
movq %r14, 0x10(%rsp)
movq 0x50(%r14), %rdi
callq 0x18db9
movq %rax, %r15
leaq 0xc(%rsp), %rax
andl $0x0, (%rax)
movzwl %bp, %r14d
xorl %r12d, %r12d
leaq 0x45909(%rip), %rbx     # 0x51630
movl %r14d, %r13d
xorl %ebp, %ebp
subl $0x1, %r13d
jb 0xbd56
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq *(%rbx)
cmpl $0xa, %eax
sete %al
cmpl %r14d, %r12d
setne %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %ebp
movl 0xc(%rsp), %r12d
jmp 0xbd2c
movq 0x10(%rsp), %r14
movw %bp, 0x62(%r14)
movw %bp, 0x64(%r14)
movq 0x18(%rsp), %rbx
jmp 0xbd71
movzwl 0x62(%r14), %ebp
movzwl %bp, %eax
leaq 0x20(%rsp), %rdx
movl %eax, (%rdx)
pushq $0xe
popq %rsi
movq %rbx, %rdi
callq 0x4caf
cmpb $0x1, %al
jne 0xbdbf
movb 0x66(%r14), %al
testb $0x8, %al
jne 0xbdb7
andb $-0xa, %al
movb %al, 0x66(%r14)
movq %rbx, %rdi
callq 0x245d9
movq %rax, %rdi
xorl %esi, %esi
callq 0x5ce4
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xb5f7
jmp 0xbdbf
movq %rbx, %rdi
callq 0x493a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq