// File: /workspace/github_c_makefile_star2_O1/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 0x6ad8
movq %rax, %r14
movb 0x66(%rax), %al
testb $0x1, %al
jne 0xc73b
orb $0x1, %al
movb %al, 0x66(%r14)
movq %rbx, %rdi
callq 0x26288
movq %rax, %rdi
movl $0x1, %esi
callq 0x604d
movq %rbx, %rdi
movl $0x1, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc07f
callq 0x3784
movq %rax, %r15
movq %rax, %rdi
callq 0x378c
cmpb $0x4, %al
jne 0xc77a
movzwl 0x62(%r14), %eax
movw %ax, 0x64(%r14)
movq %rbx, %rdi
callq 0x4ea3
movq %rax, %r12
movq %rax, %rdi
callq 0x2b2b
testb %al, %al
je 0xc77a
movq %r12, %rdi
xorl %esi, %esi
callq 0x27ad
movq %r15, %rdi
callq 0x378c
cmpb $0x1, %al
je 0xc796
movq %r15, %rdi
callq 0x378c
cmpb $0x3, %al
jne 0xc83f
movq %rbx, 0x18(%rsp)
leaq 0x24(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3832
movq 0x50(%r14), %rdi
movzwl 0x22(%rdi), %eax
subw %ax, 0x2(%r12)
movzwl 0x20(%rdi), %eax
subw %ax, (%r12)
movq %r12, %rsi
callq 0x1af91
movl %eax, %ebp
movq %r14, 0x10(%rsp)
movq 0x50(%r14), %rdi
callq 0x1a239
movl $0x0, 0xc(%rsp)
xorl %ebx, %ebx
testw %bp, %bp
je 0xc828
movq %rax, %r15
movzwl %bp, %r14d
leaq 0xc(%rsp), %r12
movl %r14d, %ebp
xorl %r13d, %r13d
movq %r15, %rdi
movq %r12, %rsi
leaq 0x46e28(%rip), %rax     # 0x53630
callq *(%rax)
cmpl $0xa, %eax
sete %al
cmpl %r14d, %ebx
setne %cl
andb %al, %cl
movzbl %cl, %eax
addl %eax, %r13d
movl 0xc(%rsp), %ebx
decl %ebp
jne 0xc7fb
jmp 0xc82b
xorl %r13d, %r13d
movq 0x10(%rsp), %r14
movw %r13w, 0x62(%r14)
movw %r13w, 0x64(%r14)
movq 0x18(%rsp), %rbx
movzwl 0x62(%r14), %eax
leaq 0x20(%rsp), %rdx
movl %eax, (%rdx)
movq %rbx, %rdi
movl $0xe, %esi
callq 0x4fea
cmpb $0x1, %al
jne 0xc893
movb 0x66(%r14), %al
testb $0x8, %al
jne 0xc88b
andb $-0xa, %al
movb %al, 0x66(%r14)
movq %rbx, %rdi
callq 0x26288
movq %rax, %rdi
xorl %esi, %esi
callq 0x604d
movq %rbx, %rdi
movl $0x1, %esi
callq 0xc07f
jmp 0xc893
movq %rbx, %rdi
callq 0x4c36
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq