// File: /workspace/github_c_makefile_star2_O2/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 0x7994
testb %al, %al
je 0x1d8bf
movq %rbx, %rdi
callq 0x6747
movq %rax, %r14
movzwl 0x82(%rax), %eax
movswl %bp, %r15d
cmpl %r15d, %eax
je 0x1d8b0
leaq 0x33f91(%rip), %rax     # 0x51650
movq (%rax), %r12
movq 0x50(%r14), %rdi
callq 0x18db9
movq %rax, %rdi
callq *%r12
movl %r15d, %ebp
sarl $0xf, %ebp
andl %eax, %ebp
addl %r15d, %ebp
movswl %bp, %ecx
movl $0xffff, %esi           # imm = 0xFFFF
movl %eax, %edx
andl %esi, %edx
cmpl %ecx, %edx
cmovll %eax, %ebp
cmpw $0x7fff, %cx            # imm = 0x7FFF
cmovel %eax, %ebp
movw %bp, 0x82(%r14)
movq 0x50(%r14), %rdi
callq 0x47bc
movq %rax, %r13
movq %rbx, %rdi
callq 0x6316
movq %rax, %r12
movq 0x28(%rax), %r15
movq 0x50(%r14), %rdi
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %ebp
leaq 0x4(%rsp), %rdx
movl %ebp, %esi
callq 0x197e0
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x50e5
movq 0x50(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x50e5
movzbl 0x10(%r15), %ebp
movq %r13, %r15
movq %r13, %rdi
callq 0x4902
movswl %ax, %ecx
leaq 0x4(%rsp), %rax
movzwl 0x2(%rax), %r13d
movswl %r13w, %eax
addl %eax, %ecx
jns 0x1d78d
movzwl 0x16(%r12), %eax
subl %r13d, %eax
movswl %ax, %esi
movq %r15, %rdi
callq 0x51d0
movzwl 0x6(%rsp), %r13d
movswl %r13w, %eax
movswl 0x12(%rsp), %ecx
addl %eax, %ecx
movswl 0x18(%r12), %eax
addl %ecx, %eax
addl %ebp, %eax
movswl 0xe(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1d7cc
movq %rbx, %rdi
callq 0x5332
addl %ebp, %r13d
addw 0x16(%r12), %r13w
addw 0x18(%r12), %r13w
subl %r13d, %eax
movswl %ax, %esi
movq %r15, %rdi
callq 0x51d0
movq %r15, %rdi
callq 0x48ca
movswl %ax, %ecx
movzwl 0x4(%rsp), %r13d
movswl %r13w, %eax
addl %eax, %ecx
movq %r15, %rdi
movzwl %bp, %r15d
cmpl %ebp, %ecx
movq %rdi, 0x18(%rsp)
jge 0x1d80b
movl %r15d, %eax
subl %r13d, %eax
movswl %ax, %esi
callq 0x5192
movzwl 0x4(%rsp), %r13d
movswl %r13w, %eax
movswl 0x10(%rsp), %ecx
addl %eax, %ecx
movswl 0x1c(%r12), %eax
addl %ecx, %eax
addl %ebp, %eax
movswl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1d852
movq %rbx, %rdi
callq 0x5308
addl %r15d, %r13d
addw 0x1a(%r12), %r13w
addw 0x1c(%r12), %r13w
subl %r13d, %eax
movswl %ax, %esi
movq 0x18(%rsp), %rdi
callq 0x5192
movzwl 0x4(%rsp), %r13d
movw %r13w, 0x80(%r14)
movzwl 0x84(%r14), %eax
testw %ax, %ax
je 0x1d8a8
leaq 0x20(%rsp), %rdi
movq %rbx, (%rdi)
leaq -0x78a(%rip), %rcx      # 0x1d0ec
movq %rcx, 0x8(%rdi)
movw %ax, 0x28(%rdi)
andw $0x0, 0x2a(%rdi)
andq $0x0, 0x18(%rdi)
movq $0x1, 0x20(%rdi)
movb $-0x1, 0x30(%rdi)
andl $0x0, 0x2c(%rdi)
leaq 0xa12a(%rip), %rax      # 0x279c9
movq %rax, 0x10(%rdi)
callq 0x27685
movq %rbx, %rdi
callq 0x1df9e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1d87e(%rip), %rdi     # 0x3b144
movq %rbx, %rsi
callq 0x7b01
jmp 0x1d8ce