| 815 | } |
| 816 | |
| 817 | void LineEdit::UpdateTextClipping() |
| 818 | { |
| 819 | Canvas* canvas = GetCanvas(); |
| 820 | |
| 821 | Size text_size = GetVisualTextSize(canvas, clip_start_offset, (int)text.size() - clip_start_offset); |
| 822 | |
| 823 | if (cursor_pos < clip_start_offset) |
| 824 | clip_start_offset = cursor_pos; |
| 825 | |
| 826 | Rect cursor_rect = GetCursorRect(); |
| 827 | |
| 828 | UTF8Reader utf8_reader(text.data(), text.length()); |
| 829 | double width = GetWidth(); |
| 830 | while (cursor_rect.x + cursor_rect.width > width) |
| 831 | { |
| 832 | utf8_reader.set_position(clip_start_offset); |
| 833 | utf8_reader.next(); |
| 834 | clip_start_offset = (int)utf8_reader.position(); |
| 835 | if (clip_start_offset == text.size()) |
| 836 | break; |
| 837 | cursor_rect = GetCursorRect(); |
| 838 | } |
| 839 | |
| 840 | // Get number of chars of current text fitting in the lineedit. |
| 841 | int search_upper = (int)text.size(); |
| 842 | int search_lower = clip_start_offset; |
| 843 | |
| 844 | while (true) |
| 845 | { |
| 846 | int midpoint = (search_lower + search_upper) / 2; |
| 847 | |
| 848 | utf8_reader.set_position(midpoint); |
| 849 | utf8_reader.move_to_leadbyte(); |
| 850 | if (midpoint != utf8_reader.position()) |
| 851 | utf8_reader.next(); |
| 852 | midpoint = (int)utf8_reader.position(); |
| 853 | |
| 854 | if (midpoint == search_lower || midpoint == search_upper) |
| 855 | break; |
| 856 | |
| 857 | Size midpoint_size = GetVisualTextSize(canvas, clip_start_offset, midpoint - clip_start_offset); |
| 858 | |
| 859 | if (width < midpoint_size.width) |
| 860 | search_upper = midpoint; |
| 861 | else |
| 862 | search_lower = midpoint; |
| 863 | } |
| 864 | clip_end_offset = search_upper; |
| 865 | |
| 866 | if (cursor_rect.x < 0.0) |
| 867 | { |
| 868 | clip_start_offset = cursor_pos; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | Rect LineEdit::GetCursorRect() |
| 873 | { |
nothing calls this directly
no test coverage detected