summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-11-26 09:00:32 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-11-26 09:00:32 -0500
commit370b74e5335745ea01fc7bb6d5425360d26ca0ce (patch)
tree56bf42a10f7ab9e910ab494eadca56e26652e914
parent346acd202547c3ecb315ff7980f505643bacc77e (diff)
do tabs properly
-rw-r--r--buffer.c8
-rw-r--r--main.c2
-rw-r--r--test.txt3
3 files changed, 11 insertions, 2 deletions
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