cursor line wrapping
This commit is contained in:
38
edit.jai
38
edit.jai
@@ -81,7 +81,7 @@ render_edit_buffer :: () {
|
|||||||
for line_buffer: visible_lines {
|
for line_buffer: visible_lines {
|
||||||
Simp.set_shader_for_text();
|
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;
|
prefix: string;
|
||||||
suffix: string;
|
suffix: string;
|
||||||
@@ -102,17 +102,12 @@ render_edit_buffer :: () {
|
|||||||
|
|
||||||
if has_cursor_on_line {
|
if has_cursor_on_line {
|
||||||
Simp.set_shader_for_color();
|
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(
|
Simp.immediate_quad(
|
||||||
cast(float) start, cast(float) top_of_line + line_height,
|
cast(float) start, cast(float) top_of_line + line_height,
|
||||||
cast(float) start + 1, cast(float) top_of_line,
|
cast(float) start + 1, cast(float) top_of_line,
|
||||||
White);
|
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.set_shader_for_text();
|
||||||
Simp.prepare_text(my_font, suffix);
|
Simp.prepare_text(my_font, suffix);
|
||||||
Simp.draw_prepared_text(my_font, start, top_of_line, White);
|
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) {
|
handle_arrow :: (key_code: Input.Key_Code) {
|
||||||
visible_lines := get_visible_lines();
|
visible_lines := get_visible_lines();
|
||||||
|
|
||||||
max_chars :: 100;
|
|
||||||
|
|
||||||
if key_code == {
|
if key_code == {
|
||||||
case .ARROW_UP;
|
case .ARROW_UP;
|
||||||
cursor_y = ifx cursor_y == 0
|
cursor_y = ifx cursor_y == 0
|
||||||
@@ -153,13 +146,23 @@ handle_arrow :: (key_code: Input.Key_Code) {
|
|||||||
else cursor_y + 1;
|
else cursor_y + 1;
|
||||||
|
|
||||||
case .ARROW_LEFT;
|
case .ARROW_LEFT;
|
||||||
cursor_x = ifx cursor_x == 0
|
if cursor_x == 0 && cursor_y != 0 {
|
||||||
then 0
|
prev_line := visible_lines[cursor_y - 1];
|
||||||
else cursor_x - 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;
|
case .ARROW_RIGHT;
|
||||||
cursor_x = ifx cursor_x == max_chars
|
line := visible_lines[cursor_y];
|
||||||
then max_chars
|
len := builder_string_length(*line);
|
||||||
else cursor_x + 1;
|
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);
|
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 "Basic";
|
||||||
#import "File";
|
#import "File";
|
||||||
#import "Math";
|
#import "Math";
|
||||||
|
|||||||
Reference in New Issue
Block a user