Basic splitting, column concept

This commit is contained in:
Krzosa Karol
2024-08-02 07:43:33 +02:00
parent 0ae0c03775
commit 4cdb8a986a
4 changed files with 111 additions and 68 deletions

View File

@@ -269,9 +269,8 @@ bool GlobalCommand(Event event) {
Vec2I mouse = MouseVec2I(); Vec2I mouse = MouseVec2I();
Window *window = GetActiveWindow(); Window *window = GetActiveWindow();
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect); bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
bool mouse_in_line_numbers = CheckCollisionPointRec(mouse, window->line_numbers_rect);
bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect); bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect);
bool mouse_in_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
window->mouse_in_scrollbar = mouse_in_scrollbar; window->mouse_in_scrollbar = mouse_in_scrollbar;
static SDL_Cursor *SDL_MouseCursor; static SDL_Cursor *SDL_MouseCursor;
@@ -283,9 +282,6 @@ bool GlobalCommand(Event event) {
} else if (mouse_in_scrollbar || window->mouse_selecting_scrollbar) { } else if (mouse_in_scrollbar || window->mouse_selecting_scrollbar) {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT); SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
SDL_SetCursor(SDL_MouseCursor); SDL_SetCursor(SDL_MouseCursor);
} else if (mouse_in_line_numbers) {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
SDL_SetCursor(SDL_MouseCursor);
} else { } else {
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER); SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
SDL_SetCursor(SDL_MouseCursor); SDL_SetCursor(SDL_MouseCursor);
@@ -301,18 +297,6 @@ bool GlobalCommand(Event event) {
Window *window = &Windows[it]; Window *window = &Windows[it];
if (!window->visible) continue; if (!window->visible) continue;
bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect); bool mouse_in_window = CheckCollisionPointRec(mouse, window->total_rect);
if (ActiveWindow.id == window->id.id) {
bool mouse_in_line_numbers = CheckCollisionPointRec(mouse, window->line_numbers_rect);
if (mouse_in_line_numbers) {
// if (Mouse(LEFT)) {
// window->layout_value.x += 0.1f;
// } else if (Mouse(RIGHT)) {
// window->layout_value.x -= 0.1f;
// }
// window->layout_value.x = Clamp(window->layout_value.x, 0.05f, 0.95f);
}
}
if (mouse_in_window) { if (mouse_in_window) {
SetActiveWindow(window->id); SetActiveWindow(window->id);
break; break;
@@ -339,6 +323,12 @@ bool GlobalCommand(Event event) {
} }
} }
if (CtrlShift(SDLK_BACKSLASH)) {
AddRowWindow();
} else if (Ctrl(SDLK_BACKSLASH)) {
AddColumnWindow();
}
if (Ctrl(SDLK_0)) { if (Ctrl(SDLK_0)) {
Window *window = GetWindow(DebugWindowID); Window *window = GetWindow(DebugWindowID);
window->visible = !window->visible; window->visible = !window->visible;

View File

@@ -75,27 +75,20 @@ struct Window {
bool draw_scrollbar : 1; bool draw_scrollbar : 1;
bool draw_line_numbers : 1; bool draw_line_numbers : 1;
bool visible : 1; bool visible : 1;
bool absolute_position : 1;
bool is_title_bar : 1;
bool is_column : 1;
bool fuzzy_search : 1; // @todo: consider moving this to view and introducing view commands bool fuzzy_search : 1; // @todo: consider moving this to view and introducing view commands
bool execute_line : 1; bool execute_line : 1;
bool invisible_when_inactive : 1; bool invisible_when_inactive : 1;
bool dont_save_in_active_window_history : 1; bool dont_save_in_active_window_history : 1;
bool deactivate_on_escape : 1; bool deactivate_on_escape : 1;
bool is_title_bar : 1;
}; };
}; };
struct VisualRow {
float value;
WindowID window;
};
struct VisualColumn {
float value;
Array<VisualRow> rows;
};
struct Scroller { struct Scroller {
Rect2 rect; Rect2 rect;
double begin; double begin;

View File

@@ -1,4 +1,5 @@
- bugs: - bugs:
- scrolling in fullscreen is busted because no space outside of window
- scrolling when clicking on scroller is busted - scrolling when clicking on scroller is busted
- simulation: - simulation:
@@ -17,7 +18,6 @@
- this would allow to create new windows just like that to inform user and so on - this would allow to create new windows just like that to inform user and so on
- window borders as flag - window borders as flag
- Implement console buffer mimicking vscode with ctrl+~ etc. - Implement console buffer mimicking vscode with ctrl+~ etc.
- Reverse order of append in console buffer - it should be appending from top to bottom and scrolling
- Modify error popups to not focus, introduce a interaction timer which after some time will make window invisible - Modify error popups to not focus, introduce a interaction timer which after some time will make window invisible
- Implement shell interaction in a console buffer - Implement shell interaction in a console buffer
@@ -51,4 +51,4 @@
- Search all buffers - Search all buffers
- Search and replace - Search and replace
- Search result buffer - Search result buffer
- yeet sheet

View File

@@ -1,4 +1,24 @@
Array<VisualColumn> VisualColumns = {}; struct VisualColumn {
Window *window;
Array<Window *> rows;
};
Array<VisualColumn> GetVisualColumns(Allocator allocator) {
Array<VisualColumn> columns = {allocator};
ForItem(window, Windows) {
if (!window.visible || window.absolute_position || window.is_title_bar) continue;
if (window.is_column) {
Add(&columns, {&window, {allocator}});
VisualColumn *col = GetLast(columns);
Add(&col->rows, &window);
} else if (columns.len) {
VisualColumn *col = GetLast(columns);
Add(&col->rows, &window);
}
}
return columns;
}
Array<Int> GetWindowZOrder(Allocator allocator) { Array<Int> GetWindowZOrder(Allocator allocator) {
Array<Int> order = {allocator}; Array<Int> order = {allocator};
@@ -39,11 +59,37 @@ Int GetTitleBarSize(Window *window) {
return (Int)result; return (Int)result;
} }
void AddColumnWindow() {
Window *window = CreateWindow();
window->is_column = true;
View *view = OpenBufferView("*scratch*");
SetActiveView(window, view->id);
CreateInfobar(window);
}
void AddRowWindow() {
Window *window = CreateWindow();
WindowID window_id = window->id;
View *view = OpenBufferView("*scratch*");
SetActiveView(window, view->id);
CreateInfobar(window);
Window *active_window = GetActiveWindow();
int64_t active_window_index = GetIndex(Windows, *active_window);
window = GetWindow(window_id);
Window window_copy = *window;
Remove(&Windows, *window);
Insert(&Windows, window_copy, active_window_index + 1);
}
void InitWindows(View *null_view) { void InitWindows(View *null_view) {
Allocator sys_allocator = GetSystemAllocator(); Allocator sys_allocator = GetSystemAllocator();
{ {
Window *window = CreateWindow(); Window *window = CreateWindow();
window->is_column = true;
// window->draw_line_numbers = false; // window->draw_line_numbers = false;
Buffer *buffer = CreateBuffer(sys_allocator, "*load_text_a*"); Buffer *buffer = CreateBuffer(sys_allocator, "*load_text_a*");
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
@@ -57,16 +103,22 @@ void InitWindows(View *null_view) {
{ {
Window *window = CreateWindow(); Window *window = CreateWindow();
window->is_column = true;
Buffer *buffer = CreateBuffer(sys_allocator, "*console*"); Buffer *buffer = CreateBuffer(sys_allocator, "*console*");
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
SetActiveView(window, view->id); SetActiveView(window, view->id);
CreateInfobar(window); CreateInfobar(window);
} }
// AddRowWindow();
// AddRowWindow();
// AddRowWindow();
{ {
Window *window = CreateWindow(); Window *window = CreateWindow();
window->draw_line_numbers = false; window->draw_line_numbers = false;
Buffer *buffer = CreateBuffer(sys_allocator, "*debug*"); Buffer *buffer = CreateBuffer(sys_allocator, "*debug*");
window->absolute_position = true;
window->draw_line_numbers = false; window->draw_line_numbers = false;
window->draw_scrollbar = false; window->draw_scrollbar = false;
window->dont_save_in_active_window_history = true; window->dont_save_in_active_window_history = true;
@@ -86,6 +138,7 @@ void InitWindows(View *null_view) {
w->fuzzy_search = true; w->fuzzy_search = true;
w->execute_line = true; w->execute_line = true;
w->invisible_when_inactive = true; w->invisible_when_inactive = true;
w->absolute_position = true;
w->dont_save_in_active_window_history = true; w->dont_save_in_active_window_history = true;
w->deactivate_on_escape = true; w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, "*commands*"); Buffer *b = CreateBuffer(sys_allocator, "*commands*");
@@ -101,6 +154,7 @@ void InitWindows(View *null_view) {
w->draw_scrollbar = false; w->draw_scrollbar = false;
w->draw_line_numbers = false; w->draw_line_numbers = false;
w->visible = false; w->visible = false;
w->absolute_position = true;
w->dont_save_in_active_window_history = true; w->dont_save_in_active_window_history = true;
w->invisible_when_inactive = true; w->invisible_when_inactive = true;
w->deactivate_on_escape = true; w->deactivate_on_escape = true;
@@ -118,6 +172,7 @@ void InitWindows(View *null_view) {
w->visible = false; w->visible = false;
w->dont_save_in_active_window_history = true; w->dont_save_in_active_window_history = true;
w->invisible_when_inactive = true; w->invisible_when_inactive = true;
w->absolute_position = true;
w->deactivate_on_escape = true; w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, "*popup*"); Buffer *b = CreateBuffer(sys_allocator, "*popup*");
b->no_history = true; b->no_history = true;
@@ -134,36 +189,41 @@ void LayoutWindows() {
float ScrollBarSize = (10.f * DPIScale); float ScrollBarSize = (10.f * DPIScale);
Rect2I screen_rect = GetScreenRectI(); Rect2I screen_rect = GetScreenRectI();
float line_numbers_size = (float)FontCharSpacing * 10; float line_numbers_size = (float)FontCharSpacing * 10;
double sizex = (double)GetSize(screen_rect).x; float sizex = (float)GetSize(screen_rect).x;
{ Window *search_window = GetWindow(SearchWindowID);
Window *window = GetWindow(SearchWindowID); if (search_window->visible) {
Rect2I sr = screen_rect; Rect2I rect = CutBottom(&screen_rect, FontLineSpacing);
Rect2I rect = CutBottom(&sr, FontLineSpacing); search_window->total_rect = rect;
window->total_rect = rect; search_window->document_rect = search_window->total_rect;
window->document_rect = window->total_rect;
window->z = 1;
} }
{ Scratch scratch;
int i = 0; Array<VisualColumn> columns = GetVisualColumns(scratch);
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.5));
Window *title_bar_window = GetWindow(Windows[i].title_bar_window); float delta_column = 1.0f / (float)columns.len;
title_bar_window->total_rect = CutBottom(&Windows[i].total_rect, GetTitleBarSize(title_bar_window)); ForItem(col, columns) {
Windows[i].document_rect = Windows[i].total_rect; Rect2I rect = CutLeft(&screen_rect, (Int)(delta_column * sizex));
title_bar_window->document_rect = title_bar_window->total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, (Int)ScrollBarSize); float sizey = (float)GetSize(rect).y;
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size); float delta_row = 1.0f / (float)col.rows.len;
ForItem(row, col.rows) {
row->total_rect = CutTop(&rect, (Int)(delta_row * sizey));
} }
{
int i = 2;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex));
Window *title_bar_window = GetWindow(Windows[i].title_bar_window);
title_bar_window->total_rect = CutBottom(&Windows[i].total_rect, GetTitleBarSize(title_bar_window));
title_bar_window->document_rect = title_bar_window->total_rect;
Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, (Int)ScrollBarSize);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
} }
For(Windows) {
Window *window = &it;
if (!window->visible || window->absolute_position || window->is_title_bar) continue;
Window *title_bar_window = GetWindow(window->title_bar_window);
title_bar_window->total_rect = CutBottom(&window->total_rect, GetTitleBarSize(title_bar_window));
title_bar_window->document_rect = title_bar_window->total_rect;
window->document_rect = window->total_rect;
if (window->draw_scrollbar) window->scrollbar_rect = CutRight(&window->document_rect, (Int)ScrollBarSize);
if (window->draw_line_numbers) window->line_numbers_rect = CutLeft(&window->document_rect, (Int)line_numbers_size);
}
{ {
Window *window = GetWindow(DebugWindowID); Window *window = GetWindow(DebugWindowID);
Rect2 screen_rect = GetScreenRectF(); Rect2 screen_rect = GetScreenRectF();