intermediate
This commit is contained in:
parent
bc7f0a1f7b
commit
6675f39303
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -320,7 +320,7 @@ STB_TEXTEDIT_INSERTCHARS :: (obj: *STB_TEXTEDIT_STRING, i: s32, c: *STB_TEXTEDIT
|
|||||||
return true;
|
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;
|
// text : *u8 = obj.text.data;
|
||||||
// line_start : *u8 = text + n;
|
// line_start : *u8 = text + n;
|
||||||
// len := obj.text.count - (line_start - text);
|
// 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 := 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.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}, " ");
|
// words := split(.{len, line_start}, " ");
|
||||||
|
|
||||||
|
|||||||
@ -569,7 +569,7 @@ SegmentText :: (font: *Font, Codepoints: *u32, CodepointCount: u64) -> Vector2,
|
|||||||
// return 0;
|
// 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;
|
textp : *u8 = text.data;
|
||||||
line_start : *u8 = textp + n;
|
line_start : *u8 = textp + n;
|
||||||
|
|||||||
24
src/ui.jai
24
src/ui.jai
@ -413,7 +413,7 @@ ui_size_label :: (label: *Label, max_width: float) {
|
|||||||
label_size : Vector2;
|
label_size : Vector2;
|
||||||
idx : u32;
|
idx : u32;
|
||||||
while idx < label.text.count {
|
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 {
|
if max_width > 0.0 && label_size.x + word_size.x > max_width {
|
||||||
break;
|
break;
|
||||||
@ -457,12 +457,25 @@ ui_draw_label :: (using label: *Label) {
|
|||||||
// Restore modified GL state
|
// Restore modified GL state
|
||||||
// restore_opengl_state(*opengl_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};
|
//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);
|
//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 {
|
// for line : lines {
|
||||||
// render_text(font, line.text, .{draw_pos.x, draw_pos.y - line.size.y + line.max_descent}, colour = font_colour);
|
// 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);
|
// 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) {
|
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;
|
idx : u32;
|
||||||
|
|
||||||
while idx < text.count {
|
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;
|
idx += read;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,7 +856,6 @@ ui_text_input :: (s: string, font_colour := Vector4.{1, 1, 1, 1}) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
row : StbTexteditRow;
|
row : StbTexteditRow;
|
||||||
|
|
||||||
i : s32;
|
i : s32;
|
||||||
|
|
||||||
while i < text_input.text.count {
|
while i < text_input.text.count {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user