From afdd3834b9e059b996986ac2c84ab7887ef5112c Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Wed, 24 Jul 2024 07:30:36 +0200 Subject: [PATCH] Info bar and exec bar --- src/text_editor/commands_window.cpp | 25 ++++++++++++++- src/text_editor/text_editor.cpp | 50 ++++++++++++++++++----------- src/text_editor/text_editor.h | 4 +++ 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index bd185d8..b9e3d0e 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -361,7 +361,7 @@ void HandleActiveWindowBindings(Window *window) { ReplaceText(buffer, {0, buffer->len}, GetString(*temp_buffer)); } - if (window->fuzzy_search) { + if (window->execute_line) { if (Press(KEY_ENTER)) { Int line = PosToLine(*buffer, GetFront(view.carets[0])); Range range = GetLineRange(*buffer, line); @@ -531,3 +531,26 @@ void ChangeActiveWindowAndScroll(Array &order) { } } } + +void ReplaceInfobarData() { + Window *window = GetWindow(InfoBarWindowID); + View *view = GetView(window->active_view); + Buffer *buffer = GetBuffer(view->buffer_id); + + XY xy = {}; + String name = {}; + { + Window *window = GetActiveWindow(); + View *view = GetActiveView(window); + Buffer *buffer = GetBuffer(view->buffer_id); + Scratch scratch; + Caret caret = view->carets[0]; + xy = PosToXY(*buffer, GetFront(caret)); + name = buffer->name; + } + + Scratch scratch; + String s = Format(scratch, "line: %5lld col: %5lld name: %.*s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name)); + String16 string = ToString16(scratch, s); + ReplaceText(buffer, {0, buffer->len}, string); +} \ No newline at end of file diff --git a/src/text_editor/text_editor.cpp b/src/text_editor/text_editor.cpp index b92eeca..da6dcdf 100644 --- a/src/text_editor/text_editor.cpp +++ b/src/text_editor/text_editor.cpp @@ -114,12 +114,32 @@ int main(void) { View *v = CreateView(b->id); AddView(w, v->id); } + { + Window *w = CreateWindow(); + w->draw_scrollbar = false; + w->draw_line_numbers = false; + Buffer *b = CreateBuffer(sys_allocator, "*infobar*"); + View *v = CreateView(b->id); + AddView(w, v->id); + InfoBarWindowID = w->id; + } + { + Window *w = CreateWindow(); + w->draw_scrollbar = false; + w->draw_line_numbers = false; + w->execute_line = true; + Buffer *b = CreateBuffer(sys_allocator, "*execbar*"); + View *v = CreateView(b->id); + AddView(w, v->id); + ExecBarWindowID = w->id; + } { Window *w = CreateWindow(); w->draw_scrollbar = false; w->draw_line_numbers = false; w->visible = false; w->fuzzy_search = true; + w->execute_line = true; Buffer *b = CreateBuffer(sys_allocator, "*commands*"); View *v = CreateView(b->id); ReplaceText(b, GetEndAsRange(*b), L"\n"); @@ -160,7 +180,17 @@ int main(void) { if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size); } { - int i = 3; + int i = 3; + Windows[i].total_rect = CutLeft(&infobar_rect, GetSize(infobar_rect).x / 2); + Windows[i].document_rect = Windows[i].total_rect; + } + { + int i = 4; + Windows[i].total_rect = infobar_rect; + Windows[i].document_rect = Windows[i].total_rect; + } + { + int i = 5; Rect2 screen_rect = GetScreenRectF(); Vec2 size = GetSize(screen_rect); CutTop(&screen_rect, size.y * 0.05f); @@ -180,29 +210,13 @@ int main(void) { Array order = GetWindowZOrder(scratch); HandleGlobalCommands(); ChangeActiveWindowAndScroll(order); + ReplaceInfobarData(); For(IterateInReverse(&order)) { Window &window = Windows[it]; HandleWindowBindings(&window); DrawWindow(window); } SetMouseCursor(); - - { - Rect2I r = infobar_rect; - DrawRectangleRec(ToRectangle(r), ColorScrollbarBackground); - { - Window *window = GetActiveWindow(); - View *view = GetActiveView(window); - Buffer *buffer = GetBuffer(view->buffer_id); - Vec2 p = ToVec2(r.min); - Scratch scratch; - Caret caret = view->carets[0]; - XY xy = PosToXY(*buffer, GetFront(caret)); - String s = Format(scratch, "-- line: %lld col: %lld", (long long)xy.line + 1ll, (long long)xy.col + 1ll); - String16 string = ToString16(scratch, s); - DrawString(MenuFont, string, p, MenuFontSize, 1, ColorText); - } - } EndDrawing(); } CloseWindow(); diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 9388267..2d871bb 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -64,7 +64,9 @@ struct Window { bool draw_scrollbar : 1; bool draw_line_numbers : 1; bool visible : 1; + bool fuzzy_search : 1; + bool execute_line : 1; }; }; @@ -83,6 +85,8 @@ WindowID NullWindowID = {0}; BufferID NullBufferID = {0}; ViewID NullViewID = {0}; WindowID CommandWindowID = {0}; +WindowID InfoBarWindowID = {0}; +WindowID ExecBarWindowID = {0}; Array Buffers = {}; Array Views = {};