Break text into new lines on a few additional characters.
@@ -28,6 +28,12 @@ inline bool text_is_space(char c) {
//////////////////////////////////////////
+inline bool text_is_breakable(char c) {
+ return c==' ' || c=='-' || c=='/' || c=='\\' || c=='|' || c=='\n' || c == '\r' || c== '\t';
+}
+
+//////////////////////////////////////////
+
void text_buffer_ensure_capacity(text_buffer_t &buffer, size_t characters) {
if (buffer.vert_count + characters * 4 <= buffer.vert_cap)
return;
@@ -205,15 +211,16 @@ float text_step_line_length(const char *start, int32_t *out_char_count, const te
float last_width = 0;
const char *last_at = start;
const char *ch = start;
- bool was_space = false;
+ bool was_break = false;
while (true) {
char curr = *ch;
- bool is_space = text_is_space(curr);
+ bool is_break = text_is_breakable(curr);
- // We prefer to line break at spaces, rather than in the middle of words
- if (is_space || curr == '\0') {
- if (!was_space)
+ // We prefer to line break at spaces and other breakable characters,
+ // rather than in the middle of words
+ if (is_break || curr == '\0') {
+ if (!was_break)
last_width = curr_width;
last_at = curr != '\0' ? ch+1 : ch;
}
@@ -226,8 +233,8 @@ float text_step_line_length(const char *start, int32_t *out_char_count, const te
float next_width = char_info.xadvance*step.style->size + curr_width;
// Check if it steps out of bounds
- if (!is_space && next_width > step.bounds.x) {
- // If there were no spaces in this line, set to the previous character
+ if (!is_break && next_width > step.bounds.x) {
+ // If there were no breaks in this line, set to the previous character
if (last_width == 0) {
last_width = curr_width;
last_at = ch;
@@ -238,7 +245,7 @@ float text_step_line_length(const char *start, int32_t *out_char_count, const te
// Next character!
curr_width = next_width;
- was_space = is_space;
+ was_break = is_break;
ch++;
}
