* Splits the given text in lines of maxwidth width using the given delimiter. * @param str The text to split. * @param maxwidth The maximum width the text will have. * @param delimiter The char used as delimiter. * @return The number of lines. */
| 871 | * @return The number of lines. |
| 872 | */ |
| 873 | uint16 GUI_SplitText(char *str, uint16 maxwidth, char delimiter) |
| 874 | { |
| 875 | uint16 lines = 0; |
| 876 | |
| 877 | if (str == NULL) return 0; |
| 878 | |
| 879 | while (*str != '\0') { |
| 880 | uint16 width = 0; |
| 881 | |
| 882 | lines++; |
| 883 | |
| 884 | while (width < maxwidth && *str != delimiter && *str != '\r' && *str != '\0') width += Font_GetCharWidth(*str++); |
| 885 | |
| 886 | if (width >= maxwidth) { |
| 887 | while (*str != 0x20 && *str != delimiter && *str != '\r' && *str != '\0') width -= Font_GetCharWidth(*str--); |
| 888 | } |
| 889 | |
| 890 | if (*str != '\0') *str++ = delimiter; |
| 891 | } |
| 892 | |
| 893 | return lines; |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * Draws a sprite. |
no test coverage detected