// File: /workspace/github_c_makefile_star2_O3/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 0x6af7
movq %rax, %r14
movb 0x66(%rax), %al
testb $0x1, %al
jne 0xc674
orb $0x1, %al
movb %al, 0x66(%r14)
movq %rbx, %rdi
callq 0x2695e
movq %rax, %rdi
movl $0x1, %esi
callq 0x606c
movq %rbx, %rdi
movl $0x1, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbfb8
callq 0x378a
movq %rax, %r15
movq %rax, %rdi
callq 0x3792
cmpb $0x4, %al
jne 0xc6b3
movzwl 0x62(%r14), %eax
movw %ax, 0x64(%r14)
movq %rbx, %rdi
callq 0x4ed1
movq %rax, %r12
movq %rax, %rdi
callq 0x2b0b
testb %al, %al
je 0xc6b3
movq %r12, %rdi
xorl %esi, %esi
callq 0x27a6
movq %r15, %rdi
callq 0x3792
cmpb $0x1, %al
je 0xc6cf
movq %r15, %rdi
callq 0x3792
cmpb $0x3, %al
jne 0xc77a
movq %rbx, 0x18(%rsp)
leaq 0x24(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3838
movq 0x50(%r14), %rdi
movq 0x20(%rdi), %xmm0
movd (%r12), %xmm1
psubw %xmm0, %xmm1
movd %xmm1, (%r12)
movq %r12, %rsi
callq 0x1b78e
movl %eax, %ebp
movq %r14, 0x10(%rsp)
movq 0x50(%r14), %rdi
callq 0x1aa00
movl $0x0, 0xc(%rsp)
xorl %ebx, %ebx
testw %bp, %bp
je 0xc762
movq %rax, %r15
movzwl %bp, %r14d
leaq 0xc(%rsp), %r12
movl %r14d, %r13d
xorl %ebp, %ebp
movq %r15, %rdi
movq %r12, %rsi
leaq 0x46eee(%rip), %rax     # 0x53630
callq *(%rax)
cmpl $0xa, %eax
sete %al
cmpl %r14d, %ebx
setne %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %ebp
movl 0xc(%rsp), %ebx
decl %r13d
jne 0xc735
jmp 0xc764
xorl %ebp, %ebp
movq 0x10(%rsp), %r14
movw %bp, 0x62(%r14)
movw %bp, 0x64(%r14)
movq 0x18(%rsp), %rbx
jmp 0xc77f
movzwl 0x62(%r14), %ebp
movzwl %bp, %eax
leaq 0x20(%rsp), %rdx
movl %eax, (%rdx)
movq %rbx, %rdi
movl $0xe, %esi
callq 0x5018
cmpb $0x1, %al
jne 0xc7d1
movb 0x66(%r14), %al
testb $0x8, %al
jne 0xc7c9
andb $-0xa, %al
movb %al, 0x66(%r14)
movq %rbx, %rdi
callq 0x2695e
movq %rax, %rdi
xorl %esi, %esi
callq 0x606c
movq %rbx, %rdi
movl $0x1, %esi
callq 0xbfb8
jmp 0xc7d1
movq %rbx, %rdi
callq 0x4c4d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq