summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-28 20:40:52 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-28 20:40:52 -0500
commit31b5649b131695300f39563640c4af8f0d3032cb (patch)
tree71f4c2d2c0b2e56a36e7c86f250869c6daa16eda
parent0e57122ecfd554131fd6ad54fcbb556733bf6c88 (diff)
more tabs
-rw-r--r--main.c3
-rw-r--r--ted-base.c18
-rw-r--r--ted.h3
3 files changed, 17 insertions, 7 deletions
diff --git a/main.c b/main.c
index 8248ac3..686a515 100644
--- a/main.c
+++ b/main.c
@@ -464,7 +464,8 @@ int main(int argc, char **argv) {
{
float x1 = 50, y1 = 50, x2 = window_width-50, y2 = window_height-50;
- buffer_render(&ted->buffers[ted->active_node->tabs[0]], x1, y1, x2, y2);
+ Node *node = ted->active_node;
+ buffer_render(&ted->buffers[node->tabs[node->active_tab]], x1, y1, x2, y2);
if (text_has_err()) {
ted_seterr(ted, "Couldn't render text: %s", text_get_err());
}
diff --git a/ted-base.c b/ted-base.c
index a9cf725..371096f 100644
--- a/ted-base.c
+++ b/ted-base.c
@@ -95,6 +95,7 @@ static i32 ted_new_buffer(Ted *ted) {
for (i32 i = 0; i < TED_MAX_BUFFERS; ++i) {
if (!buffers_used[i]) {
buffers_used[i] = true;
+ buffer_create(&ted->buffers[i], ted);
return i;
}
}
@@ -125,14 +126,19 @@ static WarnUnusedResult TextBuffer *ted_open_file(Ted *ted, char const *filename
ted_seterr(ted, "Too many buffers open!");
return NULL;
} else {
- arr_add(ted->active_node->tabs, (u16)new_buffer_index);
- TextBuffer *new_buffer = &ted->buffers[new_buffer_index];
- if (buffer_load_file(new_buffer, filename)) {
- ted->active_buffer = new_buffer;
- return new_buffer;
+ Node *node = ted->active_node;
+ if (arr_len(node->tabs) < TED_MAX_TABS) {
+ arr_add(node->tabs, (u16)new_buffer_index);
+ TextBuffer *new_buffer = &ted->buffers[new_buffer_index];
+ if (node->tabs && buffer_load_file(new_buffer, filename)) {
+ ted->active_buffer = new_buffer;
+ node->active_tab = (u16)(arr_len(node->tabs) - 1);
+ return new_buffer;
+ }
} else {
- return NULL;
+ ted_seterr(ted, "Too many tabs.");
}
+ return NULL;
}
}
diff --git a/ted.h b/ted.h
index 58b5324..9228d00 100644
--- a/ted.h
+++ b/ted.h
@@ -103,12 +103,15 @@ typedef struct {
// a node is a collection of tabs OR a split of two nodes
typedef struct Node {
u16 *tabs; // dynamic array of indices into ted->buffers, or NULL if this is a split
+ u16 active_tab;
u16 left; // index into ted->nodes
u16 right;
} Node;
#define TED_MAX_BUFFERS 256
#define TED_MAX_NODES 256
+// max tabs per node
+#define TED_MAX_TABS 100
typedef struct Ted {
Font *font_bold;
Font *font;