From 370b74e5335745ea01fc7bb6d5425360d26ca0ce Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Thu, 26 Nov 2020 09:00:32 -0500 Subject: do tabs properly --- buffer.c | 8 +++++++- main.c | 2 +- test.txt | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test.txt diff --git a/buffer.c b/buffer.c index 0a19aa5..f98e3f3 100644 --- a/buffer.c +++ b/buffer.c @@ -163,6 +163,8 @@ void text_buffer_render(TextBuffer *buffer, float x1, float y1, float x2, float // what x coordinate to start rendering the text from float render_start_x = x1 - (float)buffer->scroll_x * char_height; + u32 column = 0; + TextRenderState text_state = { .x = render_start_x, .y = y1 + text_font_char_height(font), .min_x = x1, .min_y = y1, @@ -199,14 +201,18 @@ void text_buffer_render(TextBuffer *buffer, float x1, float y1, float x2, float case L'\n': text_state.x = render_start_x; text_state.y += text_font_char_height(font); + column = 0; break; case L'\r': break; // for CRLF line endings case L'\t': - for (int i = 0; i < 4; ++i) + do { text_render_char(font, L' ', &text_state); + ++column; + } while (column % 4); break; default: text_render_char(font, c, &text_state); + ++column; break; } } diff --git a/main.c b/main.c index 3544919..6831229 100644 --- a/main.c +++ b/main.c @@ -69,7 +69,7 @@ int main(void) { text_buffer_create(&text_buffer, font); { - FILE *fp = fopen("main.c", "r"); + FILE *fp = fopen("test.txt", "r"); assert(fp); bool success = text_buffer_load_file(&text_buffer, fp); fclose(fp); diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..b5d2be8 --- /dev/null +++ b/test.txt @@ -0,0 +1,3 @@ +12 33 100 4 +7 66 2 88 +3 33 333 3333 -- cgit v1.2.3