| 779 | } |
| 780 | |
| 781 | void input_field(LfInputField* input, InputFieldType type, const char* file, int32_t line) { |
| 782 | if(!input->buf) return; |
| 783 | |
| 784 | if(!input->_init) { |
| 785 | lf_input_field_unselect_all(input); |
| 786 | input->_init = true; |
| 787 | } |
| 788 | |
| 789 | LfUIElementProps props = get_props_for(state.theme.inputfield_props); |
| 790 | LfFont font = get_current_font(); |
| 791 | |
| 792 | state.pos_ptr.x += props.margin_left; |
| 793 | state.pos_ptr.y += props.margin_top; |
| 794 | |
| 795 | float wrap_point = state.pos_ptr.x + input->width - props.padding; |
| 796 | |
| 797 | if(input->selected) { |
| 798 | if(lf_mouse_button_went_down(GLFW_MOUSE_BUTTON_LEFT) && (lf_get_mouse_x_delta() == 0 && lf_get_mouse_y_delta() == 0)) { |
| 799 | LfTextProps selected_props = lf_text_render((vec2s){ |
| 800 | state.pos_ptr.x + props.padding, |
| 801 | state.pos_ptr.y + props.padding |
| 802 | }, input->buf, font, LF_NO_COLOR, |
| 803 | wrap_point, (vec2s){lf_get_mouse_x(), lf_get_mouse_y()}, true, false, -1, -1); |
| 804 | input->cursor_index = selected_props.rendered_count; |
| 805 | lf_input_field_unselect_all(input); |
| 806 | input->mouse_selection_end = input->cursor_index; |
| 807 | input->mouse_selection_start = input->cursor_index; |
| 808 | } else if(lf_mouse_button_is_down(GLFW_MOUSE_BUTTON_LEFT) && (lf_get_mouse_x_delta() != 0 || lf_get_mouse_y_delta() != 0)) { |
| 809 | if(input->mouse_dir == 0) { |
| 810 | input->mouse_dir = (lf_get_mouse_x_delta() < 0) ? -1 : 1; |
| 811 | input->mouse_selection_end = input->cursor_index; |
| 812 | input->mouse_selection_start = input->cursor_index; |
| 813 | } |
| 814 | LfTextProps selected_props = lf_text_render((vec2s){ |
| 815 | state.pos_ptr.x + props.padding, |
| 816 | state.pos_ptr.y + props.padding |
| 817 | }, input->buf, font, LF_NO_COLOR, wrap_point, (vec2s){lf_get_mouse_x(), lf_get_mouse_y()}, true, false, -1, -1); |
| 818 | |
| 819 | input->cursor_index = selected_props.rendered_count; |
| 820 | |
| 821 | if(input->mouse_dir == -1) |
| 822 | input->mouse_selection_start = input->cursor_index; |
| 823 | else if(input->mouse_dir == 1) |
| 824 | input->mouse_selection_end = input->cursor_index; |
| 825 | |
| 826 | input->selection_start = input->mouse_selection_start; |
| 827 | input->selection_end = input->mouse_selection_end; |
| 828 | |
| 829 | if(input->mouse_selection_start == input->mouse_selection_end) { |
| 830 | input->mouse_dir = (lf_get_mouse_x_delta() < 0) ? -1 : 1; |
| 831 | } |
| 832 | } else if(lf_mouse_button_is_released(GLFW_MOUSE_BUTTON_LEFT)){ |
| 833 | input->mouse_dir = 0; |
| 834 | } |
| 835 | if(lf_char_event().happened && lf_char_event().charcode >= 0 && lf_char_event().charcode <= 127 && |
| 836 | strlen(input->buf) + 1 <= input->buf_size && (input->max_chars ? strlen(input->buf) + 1 <= input->max_chars : true)) { |
| 837 | if(input->insert_override_callback) { |
| 838 | input->insert_override_callback(input); |
no test coverage detected