From 1dabb59a6592a653fb7930e1d13e26c68b8b7b34 Mon Sep 17 00:00:00 2001 From: Grant Horner Date: Tue, 21 Apr 2026 16:24:56 -0400 Subject: [PATCH] render cursor on y axis --- edit.jai | 81 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/edit.jai b/edit.jai index c8d4af8..e71b32e 100644 --- a/edit.jai +++ b/edit.jai @@ -12,6 +12,11 @@ window_height := 600; first_line := 0; +cursor_x := 0; +cursor_y := 0; + +White :: Vector4.{1, 1, 1, 1}; + main :: () { args := get_command_line_arguments(); assert(args.count == 2, "The file name must be passed as a CLI argument"); @@ -38,20 +43,7 @@ main :: () { Input.update_window_events(); - for Input.get_window_resizes() { - Simp.update_window(it.window); - if it.window == window { - should_reinit := (it.width != window_width) || (it.height != window_height); - - window_width = it.width; - window_height = it.height; - - if should_reinit { - my_init_fonts(); - } - } - } - + handle_window_resizes(window); for event : Input.events_this_frame { if event.type == .QUIT { @@ -62,6 +54,11 @@ main :: () { if event.type == .KEYBOARD && event.key_pressed { if event.key_code == { case .ESCAPE; should_quit = true; + + case .ARROW_UP; #through; + case .ARROW_DOWN; #through; + case .ARROW_LEFT; #through; + case .ARROW_RIGHT; handle_arrow(event.key_code); } } } @@ -82,14 +79,64 @@ main :: () { render_edit_buffer :: () { num_lines_in_screen := window_height / line_height - 1; viewable_lines := array_view(lines, first_line, num_lines_in_screen); - Simp.set_shader_for_text(); - color :: Vector4.{1, 1, 1, 1}; for line_buffer: viewable_lines { + Simp.set_shader_for_text(); line := builder_to_line(*line_buffer); Simp.prepare_text(my_font, line); - Simp.draw_prepared_text(my_font, 5, window_height - (it_index + 1) * line_height, color); + top_of_line := window_height - (it_index + 1) * line_height; + Simp.draw_prepared_text(my_font, 5, top_of_line, White); + + if it_index == cursor_y { + Simp.set_shader_for_color(); + Simp.immediate_quad( + 5., cast(float) top_of_line + line_height, + 6., cast(float) top_of_line, + White); + } + } +} + +handle_window_resizes :: (window: Window_Type) { + for Input.get_window_resizes() { + Simp.update_window(it.window); + if it.window == window { + should_reinit := (it.width != window_width) || (it.height != window_height); + + window_width = it.width; + window_height = it.height; + + if should_reinit { + my_init_fonts(); + } + } + } +} + +handle_arrow :: (key_code: Input.Key_Code) { + num_lines_in_screen := window_height / line_height - 1; + viewable_lines := array_view(lines, first_line, num_lines_in_screen); + + max_chars := 30; + + if key_code == { + case .ARROW_UP; + cursor_y = ifx cursor_y == 0 + then 0 + else cursor_y - 1; + case .ARROW_DOWN; + cursor_y = ifx cursor_y == viewable_lines.count + then viewable_lines.count + else cursor_y + 1; + case .ARROW_LEFT; + cursor_x = ifx cursor_x == 0 + then 0 + else cursor_x - 1; + case .ARROW_RIGHT; + cursor_y = ifx cursor_x == max_chars + then max_chars + else cursor_x + 1; } }