From b3b50715b4aedd4aec444277fb84f8da3056ce7e Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Thu, 8 Aug 2024 06:35:37 +0200 Subject: [PATCH] Add dynamic array debug - resize on every item added, fix window bug --- src/basic/basic.h | 12 ++++++++++-- src/text_editor/management.cpp | 6 +----- src/text_editor/todo.txt | 6 +----- src/text_editor/window.cpp | 19 ++++++++++--------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/basic/basic.h b/src/basic/basic.h index 57e7b62..c7708b1 100644 --- a/src/basic/basic.h +++ b/src/basic/basic.h @@ -358,6 +358,14 @@ Slice GetSlice(Slice &arr, int64_t first_index = 0, int64_t one_past_last_ return result; } +// Make arrays resize on every item +#define ARRAY_DEBUG 1 +#if ARRAY_DEBUG + #define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF +#else + #define ARRAY_IF_DEBUG_ELSE(IF, ELSE) ELSE +#endif + template struct Array { Allocator allocator; @@ -408,7 +416,7 @@ void Reserve(Array *arr, int64_t size) { template void TryGrowing(Array *arr) { if (arr->len + 1 > arr->cap) { - int64_t new_size = ClampBottom((int64_t)16, arr->cap * 2); + int64_t new_size = ClampBottom((int64_t)16, arr->cap ARRAY_IF_DEBUG_ELSE(+1, *2)); Reserve(arr, new_size); } } @@ -416,7 +424,7 @@ void TryGrowing(Array *arr) { template void TryGrowing(Array *arr, int64_t item_count) { if (arr->len + item_count > arr->cap) { - int64_t new_size = ClampBottom((int64_t)16, (arr->cap + item_count) * 2); + int64_t new_size = ClampBottom((int64_t)16, (arr->cap + item_count) ARRAY_IF_DEBUG_ELSE(+1, *2)); Reserve(arr, new_size); } } diff --git a/src/text_editor/management.cpp b/src/text_editor/management.cpp index aa7b697..a423715 100644 --- a/src/text_editor/management.cpp +++ b/src/text_editor/management.cpp @@ -219,12 +219,8 @@ Buffer *BufferOpenFile(String path) { buffer = CreateBuffer(sys_allocator, path, 4096 * 2); buffer->is_directory = true; - int i = 1; for (FileIter it = IterateFiles(scratch, path); IsValid(it); Advance(&it)) { - IKnowWhatImDoing_Appendf(buffer, "%.*s", FmtString(it.filename)); - if ((i % 8) == 0) IKnowWhatImDoing_Append(buffer, L"\n"); - else IKnowWhatImDoing_Append(buffer, L" "); - i += 1; + IKnowWhatImDoing_Appendf(buffer, "%.*s ", FmtString(it.filename)); } } else { path = GetAbsolutePath(sys_allocator, path); diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 3579050..e484b0a 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,5 +1,3 @@ -- delete raylib utils, delete WaitForExit? -- remove pointers from ids since they will quickly get invalidated, move fully to array stuff - Attach BufferID to process, append to that buffer - kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433 - AppendToConsole should scroll only if caret is at end and one caret otherwise the carets should not change @@ -15,9 +13,6 @@ - drag and drop file into the window - exe icon -- combine glyph and selection rendering -- debugging: resize dynamic array on every item add - - search as a command to execute which is going to be in the title bar - search backwards @@ -41,6 +36,7 @@ - draw indentation levels like in sublime (those lines) - we render chars one by one so seems relatively easy to figure out if whitespace belongs to beginning of line (make sure to add max value like 40 because of big files) - code sections, visual demarkation if beginning of line has a very specific text + goto next / goto prev section hotkey! - change size of command window because it's wacky +- combine glyph and selection rendering diff --git a/src/text_editor/window.cpp b/src/text_editor/window.cpp index 240ab7b..c78674b 100644 --- a/src/text_editor/window.cpp +++ b/src/text_editor/window.cpp @@ -38,7 +38,7 @@ Array GetWindowZOrder(Allocator allocator) { return order; } -Window *CreateTitlebar(Window *parent_window) { +Window *CreateTitlebar(WindowID parent_window_id) { Window *window = CreateWindow(); window->draw_scrollbar = false; window->dont_save_in_active_window_history = true; @@ -53,6 +53,7 @@ Window *CreateTitlebar(Window *parent_window) { View *v = CreateView(b->id); window->active_view = v->id; + Window *parent_window = GetWindow(parent_window_id); parent_window->title_bar_window = window->id; window->title_bar_window = parent_window->id; @@ -74,7 +75,7 @@ void AddColumnWindow() { window->is_column = true; View *view = OpenBufferView("*scratch*"); window->active_view = view->id; - CreateTitlebar(window); + CreateTitlebar(window->id); } void AddRowWindow() { @@ -83,7 +84,7 @@ void AddRowWindow() { View *view = OpenBufferView("*scratch*"); window->active_view = view->id; - CreateTitlebar(window); + CreateTitlebar(window->id); Window *active_window = GetActiveWindow(); int64_t active_window_index = GetIndex(Windows, *active_window); @@ -133,7 +134,7 @@ void InitWindows() { LoadUnicode(buffer); // LoadBigTextAndBigLine(buffer, 10000000); window->active_view = view->id; - CreateTitlebar(window); + CreateTitlebar(window->id); } { @@ -146,7 +147,7 @@ void InitWindows() { View *view = CreateView(buffer->id); window->active_view = view->id; - CreateTitlebar(window); + CreateTitlebar(window->id); SetVisibility(window, false); ConsoleWindowID = window->id; @@ -166,7 +167,7 @@ void InitWindows() { View *view = CreateView(buffer->id); window->z = 2; window->active_view = view->id; - Window *titlebar = CreateTitlebar(window); + Window *titlebar = CreateTitlebar(window->id); titlebar->z = 2; SetVisibility(window, false); DebugWindowID = window->id; @@ -189,7 +190,7 @@ void InitWindows() { w->active_view = v->id; w->z = 1; - Window *titlebar = CreateTitlebar(w); + Window *titlebar = CreateTitlebar(w->id); titlebar->z = 1; SetVisibility(w, false); @@ -209,7 +210,7 @@ void InitWindows() { View *v = CreateView(b->id); w->active_view = v->id; - CreateTitlebar(w); + CreateTitlebar(w->id); SetVisibility(w, false); SearchBufferID = b->id; @@ -231,7 +232,7 @@ void InitWindows() { View *v = CreateView(b->id); w->active_view = v->id; - Window *infobar = CreateTitlebar(w); + Window *infobar = CreateTitlebar(w->id); infobar->z = 2; SetVisibility(w, false);