// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_ta.c
// Function: lv_ta_set_cursor_pos
void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
{
    LV_ASSERT_OBJ(ta, LV_OBJX_NAME);

    lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
    if(ext->cursor.pos == pos) return;

    uint16_t len = lv_txt_get_encoded_length(lv_label_get_text(ext->label));

    if(pos < 0) pos = len + pos;

    if(pos > len || pos == LV_TA_CURSOR_LAST) pos = len;

    ext->cursor.pos = pos;

    /*Position the label to make the cursor visible*/
    lv_obj_t * label_par = lv_obj_get_parent(ext->label);
    lv_point_t cur_pos;
    const lv_style_t * style = lv_obj_get_style(ta);
    const lv_font_t * font_p = style->text.font;
    lv_area_t label_cords;
    lv_area_t ta_cords;
    lv_label_get_letter_pos(ext->label, pos, &cur_pos);
    lv_obj_get_coords(ta, &ta_cords);
    lv_obj_get_coords(ext->label, &label_cords);

    /*Check the top*/
    lv_coord_t font_h = lv_font_get_line_height(font_p);
    if(lv_obj_get_y(label_par) + cur_pos.y < 0) {
        lv_obj_set_y(label_par, -cur_pos.y + style->body.padding.top);
    }

    /*Check the bottom*/
    if(label_cords.y1 + cur_pos.y + font_h + style->body.padding.bottom > ta_cords.y2) {
        lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) + font_h + style->body.padding.top +
                                  style->body.padding.bottom));
    }
    /*Check the left (use the font_h as general unit)*/
    if(lv_obj_get_x(label_par) + cur_pos.x < font_h) {
        lv_obj_set_x(label_par, -cur_pos.x + font_h);
    }

    /*Check the right (use the font_h as general unit)*/
    if(label_cords.x1 + cur_pos.x + font_h + style->body.padding.right > ta_cords.x2) {
        lv_obj_set_x(label_par, -(cur_pos.x - lv_obj_get_width(ta) + font_h + style->body.padding.left +
                                  style->body.padding.right));
    }

    ext->cursor.valid_x = cur_pos.x;

#if LV_USE_ANIMATION
    if(ext->cursor.blink_time) {
        /*Reset cursor blink animation*/
        lv_anim_t a;
        a.var            = ta;
        a.exec_cb        = (lv_anim_exec_xcb_t)cursor_blink_anim;
        a.time           = ext->cursor.blink_time;
        a.act_time       = 0;
        a.ready_cb       = NULL;
        a.start          = 1;
        a.end            = 0;
        a.repeat         = 1;
        a.repeat_pause   = 0;
        a.playback       = 1;
        a.playback_pause = 0;
        a.path_cb        = lv_anim_path_step;
        lv_anim_create(&a);
    }
#endif

    refr_cursor_area(ta);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0x80e4
testb %al, %al
je 0x1f812
movq %rbx, %rdi
callq 0x6af7
movq %rax, %r14
movzwl 0x82(%rax), %eax
movswl %bp, %r15d
cmpl %r15d, %eax
je 0x1f803
leaq 0x34044(%rip), %rax     # 0x53650
movq (%rax), %r12
movq 0x50(%r14), %rdi
callq 0x1aa00
movq %rax, %rdi
callq *%r12
movl %r15d, %ebp
sarl $0xf, %ebp
andl %eax, %ebp
addl %r15d, %ebp
movswl %bp, %ecx
movl $0xffff, %edi           # imm = 0xFFFF
movl %eax, %edx
andl %edi, %edx
movl %ebp, %esi
andl %edi, %esi
cmpl %ecx, %edx
cmovll %eax, %ebp
cmpl $0x7fff, %esi           # imm = 0x7FFF
cmovel %eax, %ebp
movw %bp, 0x82(%r14)
movq 0x50(%r14), %rdi
callq 0x4ab5
movq %rax, %r12
movq %rbx, %rdi
callq 0x66b6
movq %rax, %r15
movq 0x28(%rax), %r13
movq 0x50(%r14), %rdi
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %ebp
movq %rsp, %rdx
movl %ebp, %esi
callq 0x1b484
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x542b
movq 0x50(%r14), %rdi
leaq 0x18(%rsp), %rsi
callq 0x542b
movzbl 0x10(%r13), %ebp
movq %r12, %rdi
callq 0x4c15
movswl %ax, %ecx
movq %rsp, %rax
movzwl 0x2(%rax), %r13d
movswl %r13w, %eax
addl %eax, %ecx
movq %r12, 0x8(%rsp)
jns 0x1f6dc
movzwl 0x16(%r15), %eax
subl %r13d, %eax
movswl %ax, %esi
movq %r12, %rdi
callq 0x5519
movzwl 0x2(%rsp), %r13d
movswl %r13w, %eax
movswl 0x1a(%rsp), %ecx
addl %eax, %ecx
movswl 0x18(%r15), %eax
addl %ecx, %eax
addl %ebp, %eax
movswl 0x16(%rsp), %ecx
movl %ebp, 0x4(%rsp)
movzwl %bp, %ebp
cmpl %ecx, %eax
jle 0x1f721
movq %rbx, %rdi
callq 0x5697
addl %ebp, %r13d
addw 0x16(%r15), %r13w
addw 0x18(%r15), %r13w
subl %r13d, %eax
movswl %ax, %esi
movq 0x8(%rsp), %rdi
callq 0x5519
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x4bdd
movswl %ax, %ecx
movzwl (%rsp), %r13d
movswl %r13w, %eax
addl %eax, %ecx
cmpl 0x4(%rsp), %ecx
jge 0x1f759
subl %r13d, %ebp
movswl %bp, %esi
movq %r12, %rdi
callq 0x54db
movzwl (%rsp), %r13d
movswl %r13w, %eax
movswl 0x18(%rsp), %ecx
addl %eax, %ecx
movswl 0x1c(%r15), %eax
addl %ecx, %eax
movl 0x4(%rsp), %ebp
addl %ebp, %eax
movswl 0x14(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1f79e
movq %rbx, %rdi
callq 0x566d
addl %ebp, %r13d
addw 0x1a(%r15), %r13w
addw 0x1c(%r15), %r13w
subl %r13d, %eax
movswl %ax, %esi
movq %r12, %rdi
callq 0x54db
movzwl (%rsp), %r13d
movw %r13w, 0x80(%r14)
movzwl 0x84(%r14), %eax
testw %ax, %ax
je 0x1f7fb
leaq 0x20(%rsp), %rdi
movq %rbx, (%rdi)
leaq -0x7bc(%rip), %rcx      # 0x1f006
movq %rcx, 0x8(%rdi)
movw %ax, 0x28(%rdi)
movw $0x0, 0x2a(%rdi)
movq $0x0, 0x18(%rdi)
movq $0x1, 0x20(%rdi)
movb $-0x1, 0x30(%rdi)
movl $0x0, 0x2c(%rdi)
leaq 0xa762(%rip), %rax      # 0x29f54
movq %rax, 0x10(%rdi)
callq 0x29bb4
movq %rbx, %rdi
callq 0x1ff6e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1f9cb(%rip), %rdi     # 0x3f1e4
movq %rbx, %rsi
callq 0x8294
jmp 0x1f821