cursor line wrapping

This commit is contained in:
2026-04-22 12:13:42 -04:00
parent fb3bcb4904
commit 6d954bd1b7

View File

@@ -81,7 +81,7 @@ render_edit_buffer :: () {
for line_buffer: visible_lines {
Simp.set_shader_for_text();
line_str := builder_to_string(*line_buffer, do_reset = false,, temp);
line_str := tbuilder_to_string(*line_buffer);
prefix: string;
suffix: string;
@@ -102,17 +102,12 @@ render_edit_buffer :: () {
if has_cursor_on_line {
Simp.set_shader_for_color();
start := ifx suffix.count == 0 then Left_Max else prefix_width + Left_Max;
start := ifx cursor_x == 0 then Left_Max else prefix_width + Left_Max;
Simp.immediate_quad(
cast(float) start, cast(float) top_of_line + line_height,
cast(float) start + 1, cast(float) top_of_line,
White);
print("----------------\n");
print("cursor_x: %\n", cursor_x);
print("Prefix width: %\n", prefix_width);
print("Suffix: %\n", suffix);
Simp.set_shader_for_text();
Simp.prepare_text(my_font, suffix);
Simp.draw_prepared_text(my_font, start, top_of_line, White);
@@ -140,8 +135,6 @@ handle_window_resizes :: (window: Window_Type) {
handle_arrow :: (key_code: Input.Key_Code) {
visible_lines := get_visible_lines();
max_chars :: 100;
if key_code == {
case .ARROW_UP;
cursor_y = ifx cursor_y == 0
@@ -153,13 +146,23 @@ handle_arrow :: (key_code: Input.Key_Code) {
else cursor_y + 1;
case .ARROW_LEFT;
cursor_x = ifx cursor_x == 0
then 0
else cursor_x - 1;
if cursor_x == 0 && cursor_y != 0 {
prev_line := visible_lines[cursor_y - 1];
len := builder_string_length(*prev_line);
cursor_y = max(0, cursor_y - 1);
cursor_x = len;
} else if cursor_x != 0 {
cursor_x -= 1;
}
case .ARROW_RIGHT;
cursor_x = ifx cursor_x == max_chars
then max_chars
else cursor_x + 1;
line := visible_lines[cursor_y];
len := builder_string_length(*line);
if cursor_x == len {
cursor_x = 0;
cursor_y += 1;
} else {
cursor_x += 1;
}
}
}
@@ -252,6 +255,11 @@ my_init_fonts :: () {
assert(my_font != null);
}
tbuilder_to_string :: (builder: *String_Builder) -> string {
s := builder_to_string(builder, do_reset = false,, temp);
return s;
}
#import "Basic";
#import "File";
#import "Math";