// File: /workspace/github_c_makefile_star2_O1/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 0x80d4
testb %al, %al
je 0x1f034
movq %rbx, %rdi
callq 0x6ad8
movq %rax, %r14
movzwl 0x82(%rax), %eax
movswl %bp, %r15d
cmpl %r15d, %eax
je 0x1f025
leaq 0x34812(%rip), %rax     # 0x53650
movq (%rax), %r12
movq 0x50(%r14), %rdi
callq 0x1a239
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 0x4abf
movq %rax, %r15
movq %rbx, %rdi
callq 0x6697
movq %rax, %r12
movq 0x28(%rax), %r13
movq 0x50(%r14), %rdi
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %ebp
leaq 0x4(%rsp), %rdx
movl %ebp, %esi
callq 0x1ace1
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5427
movq 0x50(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x5427
movzbl 0x10(%r13), %ebp
movq %r15, %rdi
callq 0x4bfe
movswl %ax, %ecx
leaq 0x4(%rsp), %rax
movswl 0x2(%rax), %eax
addl %eax, %ecx
jns 0x1eefe
movzwl 0x16(%r12), %ecx
subl %eax, %ecx
movswl %cx, %esi
movq %r15, %rdi
callq 0x5501
movswl 0x12(%rsp), %eax
movswl 0x6(%rsp), %r13d
movswl 0x18(%r12), %ecx
addl %r13d, %eax
addl %ecx, %eax
addl %ebp, %eax
movswl 0xe(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1ef44
movq %rbx, %rdi
callq 0x567b
addl %ebp, %r13d
addw 0x16(%r12), %r13w
addw 0x18(%r12), %r13w
subl %r13d, %eax
movswl %ax, %esi
movq %r15, %rdi
callq 0x5501
movq %r15, %rdi
callq 0x4bc6
movswl %ax, %ecx
movswl 0x4(%rsp), %eax
addl %eax, %ecx
movzwl %bp, %r13d
cmpl %ebp, %ecx
jge 0x1ef6e
movl %r13d, %ecx
subl %eax, %ecx
movswl %cx, %esi
movq %r15, %rdi
callq 0x54c3
movq %r15, 0x18(%rsp)
movswl 0x10(%rsp), %eax
movswl 0x4(%rsp), %r15d
movswl 0x1c(%r12), %ecx
addl %r15d, %eax
addl %ecx, %eax
addl %ebp, %eax
movswl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jle 0x1efbb
movq %rbx, %rdi
callq 0x5651
addl %r13d, %r15d
addw 0x1a(%r12), %r15w
addw 0x1c(%r12), %r15w
subl %r15d, %eax
movswl %ax, %esi
movq 0x18(%rsp), %rdi
callq 0x54c3
movzwl 0x4(%rsp), %eax
movw %ax, 0x80(%r14)
movzwl 0x84(%r14), %eax
testw %ax, %ax
je 0x1f01d
leaq 0x20(%rsp), %rdi
movq %rbx, (%rdi)
leaq -0x7da(%rip), %rcx      # 0x1e80a
movq %rcx, 0x8(%rdi)
movw %ax, 0x28(%rdi)
movw $0x0, 0x2a(%rdi)
movq $0x0, 0x18(%rdi)
movq $0x1, 0x20(%rdi)
orb $0x3, 0x30(%rdi)
movl $0x0, 0x2c(%rdi)
leaq 0xa896(%rip), %rax      # 0x298aa
movq %rax, 0x10(%rdi)
callq 0x29521
movq %rbx, %rdi
callq 0x1f77a
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x200f9(%rip), %rdi     # 0x3f134
movq %rbx, %rsi
callq 0x829e
jmp 0x1f043