diff --git a/.build/mexplore-debug.lib b/.build/mexplore-debug.lib index 05e5155..958e306 100644 Binary files a/.build/mexplore-debug.lib and b/.build/mexplore-debug.lib differ diff --git a/.build/mexplore-debug_0_w3.obj b/.build/mexplore-debug_0_w3.obj index 4c45a71..a376be6 100644 Binary files a/.build/mexplore-debug_0_w3.obj and b/.build/mexplore-debug_0_w3.obj differ diff --git a/.build/mexplore-debug_1_w3.obj b/.build/mexplore-debug_1_w3.obj index 6dbbc56..27cfc07 100644 Binary files a/.build/mexplore-debug_1_w3.obj and b/.build/mexplore-debug_1_w3.obj differ diff --git a/.build/mexplore-debug_2_w3.obj b/.build/mexplore-debug_2_w3.obj index 9fade17..f2366c2 100644 Binary files a/.build/mexplore-debug_2_w3.obj and b/.build/mexplore-debug_2_w3.obj differ diff --git a/.build/mexplore-debug_3_w3.obj b/.build/mexplore-debug_3_w3.obj index c66de87..26693fa 100644 Binary files a/.build/mexplore-debug_3_w3.obj and b/.build/mexplore-debug_3_w3.obj differ diff --git a/bin/mexplore-debug.exe b/bin/mexplore-debug.exe index 972c7a3..1072a00 100644 Binary files a/bin/mexplore-debug.exe and b/bin/mexplore-debug.exe differ diff --git a/bin/mexplore-debug.pdb b/bin/mexplore-debug.pdb index 8be7c1a..94abc2b 100644 Binary files a/bin/mexplore-debug.pdb and b/bin/mexplore-debug.pdb differ diff --git a/src/stb_textedit.jai b/src/stb_textedit.jai index f1605de..5b7cde2 100644 --- a/src/stb_textedit.jai +++ b/src/stb_textedit.jai @@ -320,7 +320,7 @@ STB_TEXTEDIT_INSERTCHARS :: (obj: *STB_TEXTEDIT_STRING, i: s32, c: *STB_TEXTEDIT return true; } -STB_TEXTEDIT_LAYOUTROW :: (row: *StbTexteditRow, obj: *STB_TEXTEDIT_STRING, n: s32) { +STB_TEXTEDIT_LAYOUTROW :: (row: *StbTexteditRow, obj: *STB_TEXTEDIT_STRING, n: u32) { // text : *u8 = obj.text.data; // line_start : *u8 = text + n; // len := obj.text.count - (line_start - text); @@ -338,14 +338,23 @@ STB_TEXTEDIT_LAYOUTROW :: (row: *StbTexteditRow, obj: *STB_TEXTEDIT_STRING, n: s // } //size, max_descent, read := SegmentText(obj.font, text_utf32.data, xx text_utf32.count); - size, max_descent, read := calculate_string_draw_size(obj.font, string.{obj.text.count, obj.text.data}, xx n, obj.max_size.x); + idx : u32; + while row.x1 < obj.max_size.x { + size, max_descent, read := next_word_size(obj.font, string.{obj.text.count, obj.text.data}, n + idx, obj.max_size.x); + + if row.x1 + size.x > obj.max_size.x { + break; + } + + row.x1 += size.x; + row.baseline_y_delta = max(row.baseline_y_delta, size.y); + row.ymin = max(row.ymin, max_descent); + row.ymax = max(row.ymax, size.y - row.ymin); + row.num_chars += read; + idx += read; + } row.x0 = 0.0; - row.x1 = size.x; - row.baseline_y_delta = size.y; - row.ymin = max_descent; - row.ymax = size.y - max_descent; - row.num_chars = xx read; // words := split(.{len, line_start}, " "); diff --git a/src/text.jai b/src/text.jai index 7c31c79..7b6a48b 100644 --- a/src/text.jai +++ b/src/text.jai @@ -569,7 +569,7 @@ SegmentText :: (font: *Font, Codepoints: *u32, CodepointCount: u64) -> Vector2, // return 0; // } -calculate_string_draw_size :: (font: *Font, text: string, n: u32, max_width: float = 0.0) -> Vector2, float, u32 { +next_word_size :: (font: *Font, text: string, n: u32, max_width: float = 0.0) -> Vector2, float, u32 { textp : *u8 = text.data; line_start : *u8 = textp + n; diff --git a/src/ui.jai b/src/ui.jai index 7eafb97..644902a 100644 --- a/src/ui.jai +++ b/src/ui.jai @@ -413,7 +413,7 @@ ui_size_label :: (label: *Label, max_width: float) { label_size : Vector2; idx : u32; while idx < label.text.count { - word_size, word_ascent, read := calculate_string_draw_size(label.font, label.text, idx, max_width); + word_size, word_ascent, read := next_word_size(label.font, label.text, idx, max_width); if max_width > 0.0 && label_size.x + word_size.x > max_width { break; @@ -457,12 +457,25 @@ ui_draw_label :: (using label: *Label) { // Restore modified GL state // restore_opengl_state(*opengl_state); - //midline : Vector2 = pos + Vector2.{cast(float, margin + padding), xx (size.y / 2.0)}; + r : StbTexteditRow; + n : s32 = STB_TEXTEDIT_STRINGLEN(str); + + midline : Vector2 = pos + Vector2.{cast(float, margin + padding), xx (size.y / 2.0)}; + + while i < n { + STB_TEXTEDIT_LAYOUTROW(*r, str, i); + if r.num_chars <= 0 + break; + + render_text(font, text, .{xx midline.x, xx (midline.y - label_size.y / 2.0 + max_descent)}, colour = font_colour); + + midline.y += r.baseline_y_delta; + } //label_size := Vector2.{xx Simp.prepare_text(font, text), xx font.character_height}; //Simp.draw_prepared_text(font, xx midline.x, xx (midline.y - label_size.y / 2.0), font_colour); - draw_pos : Vector2 = last_frame_pos + v2(cast(float, margin + padding)) + .{0.0, text_size.y}; + //draw_pos : Vector2 = last_frame_pos + v2(cast(float, margin + padding)) + .{0.0, text_size.y}; // for line : lines { // render_text(font, line.text, .{draw_pos.x, draw_pos.y - line.size.y + line.max_descent}, colour = font_colour); @@ -471,8 +484,6 @@ ui_draw_label :: (using label: *Label) { // label_size, max_ascent, max_descent := calculate_string_draw_size(label.font, label.text, true); - // render_text(font, text, .{xx midline.x, xx (midline.y - label_size.y / 2.0 + max_descent)}, colour = font_colour); - } ui_icon :: (s: string, texture: *Texture, size: Vector2) { @@ -611,7 +622,7 @@ ui_button :: (s: string = "", icon_texture: *Texture = null, font_colour := Vect idx : u32; while idx < text.count { - label_size, max_descent, read := calculate_string_draw_size(button.font, button.text, idx, button.max_size.x); + label_size, max_descent, read := next_word_size(button.font, button.text, idx, button.max_size.x); idx += read; } @@ -845,7 +856,6 @@ ui_text_input :: (s: string, font_colour := Vector4.{1, 1, 1, 1}) { // } row : StbTexteditRow; - i : s32; while i < text_input.text.count {