Debug buffer, scroll highlight

This commit is contained in:
Krzosa Karol
2024-07-27 15:04:21 +02:00
parent 8b00f15710
commit d5e392c3bc
10 changed files with 69 additions and 20 deletions

View File

@@ -168,6 +168,7 @@ void ReplaceText(Buffer *buffer, Range range, String16 string) {
Assert(range.max >= range.min);
Assert(range.max >= 0 && range.max <= buffer->len);
Assert(range.min >= 0 && range.min <= buffer->len);
buffer->dirty = true;
Int size_to_remove = range.max - range.min;
Int size_to_add = string.len;

View File

@@ -44,7 +44,7 @@ Color ColorScrollbarScroller = GruvboxLight1;
Color ColorScrollbarScrollerSelected = GruvboxLight0Hard;
Color ColorLineHighlight = GruvboxLight1;
Color ColorMainCaret = GruvboxBrightRed;
Color ColorMainCaret = GruvboxDark0Hard;
Color ColorSubCaret = GruvboxGray245;
Color ColorSelection = GruvboxLight1;
Color ColorWhitespaceDuringSelection = GruvboxLight2;

View File

@@ -236,6 +236,7 @@ bool GlobalCommand(Event event) {
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect);
window->mouse_in_scrollbar = mouse_in_scrollbar;
static SDL_Cursor *SDL_MouseCursor;
if (SDL_MouseCursor) SDL_DestroyCursor(SDL_MouseCursor);

View File

@@ -216,6 +216,23 @@ void MergeCarets(View *view, Range *mouse_selection_anchor) {
Swap(&view->carets[first_caret_index], &view->carets[0]);
}
void ReplaceDebugbarData() {
Buffer *buffer = GetBuffer("*debug*");
Window *window = GetActiveWindow();
View *view = GetActiveView(window);
if (view->active_buffer.id == buffer->id.id) return;
Window *last_window = GetWindow(GetLastActiveWindow());
View *last_view = GetActiveView(last_window);
Buffer *last_buffer = GetBuffer(last_view->active_buffer);
Scratch scratch;
String s = Format(scratch, "wid: %d\nvid: %d\nbid: %d\nframe: %lld", (int)last_window->id.id, (int)last_view->id.id, (int)last_buffer->id.id, (long long)FrameID);
String16 string = ToString16(scratch, s);
ReplaceText(buffer, GetRange(*buffer), string);
}
void ReplaceInfobarData() {
Window *window = GetWindow(InfoBarWindowID);
if (IsActive(window)) return;
@@ -234,10 +251,13 @@ void ReplaceInfobarData() {
String16 buffer_string = GetString(*buffer);
Range replace_range = {0, buffer->len};
if (!Seek(buffer_string, L"|", &replace_range.max)) {
ReplaceText(buffer, GetEndAsRange(*buffer), L"|");
// ReplaceText(buffer, GetEndAsRange(*buffer), L"|");
}
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s wid: %d vid: %d bid: %d frame%lld", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), (int)last_window->id.id, (int)last_view->id.id, (int)last_buffer->id.id, (long long)FrameID);
const char *dirty = "";
if (last_buffer->dirty) dirty = "!";
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s%s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), dirty);
String16 string = ToString16(scratch, s);
ReplaceText(buffer, replace_range, string);
Command_SelectRangeOneCursor(view, {});
@@ -512,6 +532,18 @@ void WindowCommand(Event event, Window *window, View *view) {
}
}
if (Ctrl(SDLK_S) && buffer->dirty) {
String16 string16 = GetString(*buffer);
Scratch scratch;
String string = ToString(scratch, string16);
bool success = WriteFile(buffer->name, string);
if (success) {
} else {
String msg = Format(scratch, "Failed to save file with name: %.*s", FmtString(buffer->name));
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Failed to save!", msg.data, NULL);
}
}
if (!Mouse(NONE)) {
ProfileScope(mouse);

View File

@@ -14,7 +14,7 @@ WindowID InfoBarWindowID = {0};
WindowID SearchWindowID = {0};
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
WindowID ActiveWindow; // @todo: maybe NextActiveWindow and change at end of frame
WindowID ActiveWindow;
Int CaretChangeID;
Int LastFrameIDWhenSwitchedActiveWindow;

View File

@@ -178,6 +178,7 @@ int main()
View *view = GetActiveView(window);
view->main_caret_on_begin_frame = view->carets[0];
view->update_scroll = true;
window->mouse_in_scrollbar = false;
}
SDL_Event event;
@@ -201,6 +202,7 @@ int main()
}
ReplaceInfobarData();
ReplaceDebugbarData();
For(IterateInReverse(&order)) {
Window *window = &Windows[it];

View File

@@ -36,6 +36,7 @@ struct Buffer {
Array<HistoryEntry> redo_stack;
int debug_edit_phase;
bool no_history;
bool dirty;
};
struct View {
@@ -66,6 +67,8 @@ struct Window {
struct {
bool mouse_selecting_scrollbar : 1;
bool mouse_selecting : 1;
bool mouse_in_scrollbar : 1;
bool draw_scrollbar : 1;
bool draw_line_numbers : 1;
bool visible : 1;

View File

@@ -1,12 +1,17 @@
- Save file (utf16->utf8)
- Some kind of plumbing, linking
- resize windows
- laying out windows, more choice
- window borders
- file dock on left side
- We can actually combine this with command window and lua, it's just going to be a buffer of
- open "asd/asd/asd/asd"
- Ctrl + F
- Rework window views to contain a history of past views
- word completion
- Colored strings
- font cache and on demand unicode loads
- font cache and on demand unicode loads
- Search all buffers
- Search and replace
- Search result buffer

View File

@@ -10,6 +10,7 @@ void InitWindows() {
Allocator sys_allocator = GetSystemAllocator();
{
Buffer *buffer = CreateBuffer(sys_allocator, "*scratch*");
View *view = CreateView(buffer->id);
}
{
@@ -27,12 +28,18 @@ void InitWindows() {
LoadUnicode(b);
AddView(w, v->id);
}
{
Window *w = CreateWindow();
Buffer *b = GetBuffer({0});
View *v = CreateView(b->id);
AddView(w, v->id);
Window *window = CreateWindow();
Buffer *buffer = CreateBuffer(sys_allocator, "*debug*");
window->draw_line_numbers = false;
window->draw_scrollbar = false;
window->dont_save_in_active_window_history = true;
buffer->no_history = true;
View *view = CreateView(buffer->id);
AddView(window, view->id);
}
{
Window *w = CreateWindow();
w->draw_scrollbar = false;
@@ -84,6 +91,7 @@ void LayoutWindows() {
Rect2I screen_rect = GetScreenRectI();
Rect2I infobar_rect = CutBottom(&screen_rect, (Int)FontLineSpacing);
float line_numbers_size = GetStringSize(&MainFont, L"1234567891").x;
double sizex = (double)GetSize(screen_rect).x;
{
int i = 5;
Rect2I sr = screen_rect;
@@ -94,21 +102,21 @@ void LayoutWindows() {
}
{
int i = 0;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.33));
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.46));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
int i = 1;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 0.5));
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.46));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
}
{
int i = 2;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)GetSize(screen_rect).x * 1.0));
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex));
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);

View File

@@ -187,16 +187,13 @@ void DrawWindow(Window *window) {
// Draw scrollbar
if (window->draw_scrollbar) {
SetScissor(window->scrollbar_rect);
// Vec2 mouse = GetMousePosition();
// bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, ToRectangle(window->scrollbar_rect));
DrawRect(window->scrollbar_rect, ColorScrollbarBackground);
Scroller scroller = ComputeScrollerRect(window);
Rect2 rect = Shrink(scroller.rect, 2);
Color color = ColorScrollbarScroller;
// if (!window->mouse_selecting && (window->mouse_selecting_scrollbar || mouse_in_scrollbar)) {
// if (is_active) color = ColorScrollbarScrollerSelected;
// }
if (!window->mouse_selecting && (window->mouse_selecting_scrollbar || window->mouse_in_scrollbar)) {
if (is_active) color = ColorScrollbarScrollerSelected;
}
DrawRect(rect, color);
}