Remove window view children

This commit is contained in:
Krzosa Karol
2024-07-30 06:56:54 +02:00
parent c48abbf5c9
commit 7b13dff29c
7 changed files with 82 additions and 79 deletions

View File

@@ -231,12 +231,13 @@ bool GlobalCommand(Event event) {
ProfileFunction(); ProfileFunction();
bool run_window_command = true; bool run_window_command = true;
if (Mouse(MOVE)) { if (Mouse(MOVE)) {
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_scrollbar = CheckCollisionPointRec(mouse, window->scrollbar_rect);
bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect); bool mouse_in_line_numbers = CheckCollisionPointRec(mouse, window->line_numbers_rect);
window->mouse_in_scrollbar = mouse_in_scrollbar; bool mouse_in_total = CheckCollisionPointRec(mouse, window->total_rect);
window->mouse_in_scrollbar = mouse_in_scrollbar;
static SDL_Cursor *SDL_MouseCursor; static SDL_Cursor *SDL_MouseCursor;
if (SDL_MouseCursor) SDL_DestroyCursor(SDL_MouseCursor); if (SDL_MouseCursor) SDL_DestroyCursor(SDL_MouseCursor);
@@ -247,6 +248,9 @@ 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);
@@ -262,6 +266,18 @@ 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;

View File

@@ -237,12 +237,6 @@ String DebugWindowList(Allocator allocator) {
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
String string = Format(scratch, "window = %lld active_view = %lld buffer_name = %.*s", (long long)it.id.id, (long long)it.active_view.id, FmtString(buffer->name)); String string = Format(scratch, "window = %lld active_view = %lld buffer_name = %.*s", (long long)it.id.id, (long long)it.active_view.id, FmtString(buffer->name));
Add(&strings, string); Add(&strings, string);
ForItem(child_view_id, it.views) {
View *child_view = GetView(child_view_id);
Buffer *child_buffer = GetBuffer(child_view->active_buffer);
String child_string = Format(scratch, " view = %lld buffer = %lld name = %.*s", (long long)child_view->id.id, (long long)child_buffer->id.id, FmtString(child_buffer->name));
Add(&strings, child_string);
}
} }
String result = Merge(allocator, strings, "\n"); String result = Merge(allocator, strings, "\n");
return result; return result;

View File

@@ -50,7 +50,7 @@ int LuaOpen(lua_State *L) {
Int col = strtoll(col_string.data, NULL, 10); Int col = strtoll(col_string.data, NULL, 10);
Window *window = GetWindow(GetLastActiveWindow()); Window *window = GetWindow(GetLastActiveWindow());
View *view = ViewOpenFile(window, file_path); View *view = WindowOpenBufferView(window, file_path);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
view->carets[0] = MakeCaret(XYToPos(*buffer, {col - 1, line - 1})); view->carets[0] = MakeCaret(XYToPos(*buffer, {col - 1, line - 1}));
UpdateScroll(window, true); UpdateScroll(window, true);
@@ -84,9 +84,7 @@ int LuaOpenBigBuffer(lua_State *L) {
// @todo: ViewOpenBuffer - new or old view for specified buffer // @todo: ViewOpenBuffer - new or old view for specified buffer
Buffer *buffer = CreateBuffer(GetSystemAllocator(), "big", 2500000 * 4); Buffer *buffer = CreateBuffer(GetSystemAllocator(), "big", 2500000 * 4);
LoadBigTextAndBigLine(buffer); LoadBigTextAndBigLine(buffer);
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
AddView(window, view->id);
window->active_view = view->id; window->active_view = view->id;
SetActiveWindow(window->id); SetActiveWindow(window->id);

View File

@@ -48,10 +48,7 @@ inline bool IsNull(Buffer *buffer) { return buffer->id.id == NullBufferID.id;
inline bool IsActive(Window *window) { return window->id.id == ActiveWindow.id; } inline bool IsActive(Window *window) { return window->id.id == ActiveWindow.id; }
inline bool IsActive(Window *window, View *view) { return window->active_view.id == view->id.id; } inline bool IsActive(Window *window, View *view) { return window->active_view.id == view->id.id; }
inline Window *GetActiveWindow() { return GetWindow(ActiveWindow); } inline Window *GetActiveWindow() { return GetWindow(ActiveWindow); }
inline View *GetActiveView(Window *window) { inline View *GetActiveView(Window *window) { return GetView(window->active_view); }
if (window->active_view.id == 0) return GetView(window->views[0]);
else return GetView(window->active_view);
}
void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 4096) { void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 4096) {
buffer->id = AllocBufferID(); buffer->id = AllocBufferID();
@@ -83,12 +80,6 @@ Window *CreateWindow() {
return w; return w;
} }
void AddView(Window *w, ViewID view) {
if (w->active_view.id == 0) w->active_view = view;
For(w->views) if (it.id == view.id) return;
Add(&w->views, view);
}
View *CreateView(BufferID active_buffer) { View *CreateView(BufferID active_buffer) {
View *w = Alloc(&Views); View *w = Alloc(&Views);
w->id = AllocViewID(); w->id = AllocViewID();
@@ -117,16 +108,21 @@ bool SetActiveWindow(WindowID window) {
return false; return false;
} }
Window *FindParentWindow(ViewID view_id) { Window *GetWindowWithView(ViewID view_id) {
ForItem(window, Windows) { ForItem(window, Windows) {
if (window.active_view.id == view_id.id) { if (window.active_view.id == view_id.id) {
return &window; return &window;
} else { }
ForItem(child_view, window.views) { }
if (child_view.id == view_id.id) { return NULL;
return &window; }
}
} Window *GetWindowWithView(String buffer_name) {
For(Windows) {
View *it_view = GetView(it.active_view);
Buffer *it_buffer = GetBuffer(it_view->active_buffer);
if (it_buffer->name == buffer_name) {
return ⁢
} }
} }
return NULL; return NULL;
@@ -203,49 +199,43 @@ Buffer *BufferOpenFile(String path) {
return buffer; return buffer;
} }
View *_WindowOpenViewAndBuffer(Window *window, String name, bool set_active = true) { View *OpenBufferView(String name) {
Buffer *buffer = BufferOpenFile(name); Buffer *buffer = BufferOpenFile(name);
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
Add(&window->views, view->id);
if (set_active) window->active_view = view->id;
return view; return view;
} }
void UnlinkView(Window *window, ViewID view) { View *WindowOpenBufferView(Window *new_parent_window, String name) {
For(window->views) { // @todo: window history
if (it.id == view.id) { // For(new_parent_window->views) {
UnorderedRemove(&window->views, it); // View *it_view = GetView(it);
break; // Buffer *it_buffer = GetBuffer(it_view->active_buffer);
} // if (it_buffer->name == name) {
} // new_parent_window->active_view = it;
Assert(window->active_view.id != view.id); // return it_view;
} // }
// }
View *ViewOpenFile(Window *new_parent_window, String name) {
For(new_parent_window->views) {
View *it_view = GetView(it);
Buffer *it_buffer = GetBuffer(it_view->active_buffer);
if (it_buffer->name == name) {
new_parent_window->active_view = it;
return it_view;
}
}
View *view = FindViewWithBufferName(name); View *view = FindViewWithBufferName(name);
if (!view) return _WindowOpenViewAndBuffer(new_parent_window, name); if (!view) {
View *result = OpenBufferView(name);
new_parent_window->active_view = result->id;
return result;
}
Window *window = FindParentWindow(view->id); Window *window = GetWindowWithView(view->id);
if (!window) { if (!window) {
Add(&new_parent_window->views, view->id);
new_parent_window->active_view = view->id; new_parent_window->active_view = view->id;
return view; return view;
} }
bool view_actively_used = window->active_view.id == view->id.id; bool view_actively_used = window->active_view.id == view->id.id;
if (view_actively_used) return _WindowOpenViewAndBuffer(new_parent_window, name); if (view_actively_used) {
View *result = OpenBufferView(name);
new_parent_window->active_view = result->id;
return result;
}
UnlinkView(window, view->id);
Add(&new_parent_window->views, view->id);
new_parent_window->active_view = view->id; new_parent_window->active_view = view->id;
return view; return view;
} }

View File

@@ -53,9 +53,8 @@ struct View {
}; };
struct Window { struct Window {
WindowID id; WindowID id;
ViewID active_view; ViewID active_view;
Array<ViewID> views;
Rect2I total_rect; Rect2I total_rect;
Rect2I scrollbar_rect; Rect2I scrollbar_rect;

View File

@@ -1,4 +1,5 @@
- Windows - Windows
- Mark windows as absolute or non-automatic layout and then just loop through windows
- Remove view children, replace with view history - Remove view children, replace with view history
- layouting, resize windows - layouting, resize windows
- column based, choose number of columns and then evenly split - we can adjust sizes using mouse - column based, choose number of columns and then evenly split - we can adjust sizes using mouse
@@ -8,6 +9,10 @@
- is this even practical if we have tab based design? - is this even practical if we have tab based design?
- 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
- files
- load directory
- file lister
- plumbing - plumbing
- add rule which first tries to look for open buffers and then if that fails we go look for files - add rule which first tries to look for open buffers and then if that fails we go look for files
@@ -21,7 +26,6 @@
- open selected string or auto enclosed word when right clicking or middle (this needs to be also handled on keyboard level) - open selected string or auto enclosed word when right clicking or middle (this needs to be also handled on keyboard level)
- file lister
- page up and down should also scroll and leave you in exactly same scroll - page up and down should also scroll and leave you in exactly same scroll

View File

@@ -15,16 +15,15 @@ void InitWindows(View *null_view) {
View *v = CreateView(b->id); View *v = CreateView(b->id);
LoadTextA(b); LoadTextA(b);
LoadUnicode(b); LoadUnicode(b);
AddView(w, null_view->id); w->active_view = v->id;
AddView(w, v->id);
} }
{ {
Window *w = CreateWindow(); Window *w = CreateWindow();
Buffer *b = CreateBuffer(sys_allocator, "*console*"); Buffer *b = CreateBuffer(sys_allocator, "*console*");
b->no_history = true; b->no_history = true;
View *v = CreateView(b->id); View *v = CreateView(b->id);
AddView(w, v->id); w->active_view = v->id;
} }
{ {
@@ -36,8 +35,8 @@ void InitWindows(View *null_view) {
window->visible = false; window->visible = false;
buffer->no_history = true; buffer->no_history = true;
View *view = CreateView(buffer->id); View *view = CreateView(buffer->id);
AddView(window, view->id); window->active_view = view->id;
DebugWindowID = window->id; DebugWindowID = window->id;
} }
{ {
@@ -49,8 +48,8 @@ void InitWindows(View *null_view) {
Buffer *b = CreateBuffer(sys_allocator, "*infobar*"); Buffer *b = CreateBuffer(sys_allocator, "*infobar*");
b->no_history = true; b->no_history = true;
View *v = CreateView(b->id); View *v = CreateView(b->id);
AddView(w, v->id); w->active_view = v->id;
InfoBarWindowID = w->id; InfoBarWindowID = w->id;
} }
{ {
@@ -65,7 +64,8 @@ void InitWindows(View *null_view) {
w->deactivate_on_escape = true; w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, "*commands*"); Buffer *b = CreateBuffer(sys_allocator, "*commands*");
View *v = CreateView(b->id); View *v = CreateView(b->id);
AddView(w, v->id); w->active_view = v->id;
CommandWindowID = w->id; CommandWindowID = w->id;
Command_EvalLua(v, L"list_buffers()"); Command_EvalLua(v, L"list_buffers()");
} }
@@ -80,7 +80,8 @@ void InitWindows(View *null_view) {
w->deactivate_on_escape = true; w->deactivate_on_escape = true;
Buffer *b = CreateBuffer(sys_allocator, "*search*"); Buffer *b = CreateBuffer(sys_allocator, "*search*");
View *v = CreateView(b->id); View *v = CreateView(b->id);
AddView(w, v->id); w->active_view = v->id;
SearchWindowID = w->id; SearchWindowID = w->id;
} }
@@ -95,7 +96,8 @@ void InitWindows(View *null_view) {
Buffer *b = CreateBuffer(sys_allocator, "*popup*"); Buffer *b = CreateBuffer(sys_allocator, "*popup*");
b->no_history = true; b->no_history = true;
View *v = CreateView(b->id); View *v = CreateView(b->id);
AddView(w, v->id); w->active_view = v->id;
PopupWindowID = w->id; PopupWindowID = w->id;
} }