Remove window view children
This commit is contained in:
@@ -231,12 +231,13 @@ bool GlobalCommand(Event event) {
|
||||
ProfileFunction();
|
||||
bool run_window_command = true;
|
||||
if (Mouse(MOVE)) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
Window *window = GetActiveWindow();
|
||||
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;
|
||||
Vec2I mouse = MouseVec2I();
|
||||
Window *window = GetActiveWindow();
|
||||
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);
|
||||
window->mouse_in_scrollbar = mouse_in_scrollbar;
|
||||
|
||||
static SDL_Cursor *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) {
|
||||
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
||||
SDL_SetCursor(SDL_MouseCursor);
|
||||
} else if (mouse_in_line_numbers) {
|
||||
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||
SDL_SetCursor(SDL_MouseCursor);
|
||||
} else {
|
||||
SDL_MouseCursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_POINTER);
|
||||
SDL_SetCursor(SDL_MouseCursor);
|
||||
@@ -262,6 +266,18 @@ bool GlobalCommand(Event event) {
|
||||
Window *window = &Windows[it];
|
||||
if (!window->visible) continue;
|
||||
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) {
|
||||
SetActiveWindow(window->id);
|
||||
break;
|
||||
|
||||
@@ -237,12 +237,6 @@ String DebugWindowList(Allocator allocator) {
|
||||
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));
|
||||
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");
|
||||
return result;
|
||||
|
||||
@@ -50,7 +50,7 @@ int LuaOpen(lua_State *L) {
|
||||
Int col = strtoll(col_string.data, NULL, 10);
|
||||
|
||||
Window *window = GetWindow(GetLastActiveWindow());
|
||||
View *view = ViewOpenFile(window, file_path);
|
||||
View *view = WindowOpenBufferView(window, file_path);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
view->carets[0] = MakeCaret(XYToPos(*buffer, {col - 1, line - 1}));
|
||||
UpdateScroll(window, true);
|
||||
@@ -84,9 +84,7 @@ int LuaOpenBigBuffer(lua_State *L) {
|
||||
// @todo: ViewOpenBuffer - new or old view for specified buffer
|
||||
Buffer *buffer = CreateBuffer(GetSystemAllocator(), "big", 2500000 * 4);
|
||||
LoadBigTextAndBigLine(buffer);
|
||||
View *view = CreateView(buffer->id);
|
||||
|
||||
AddView(window, view->id);
|
||||
View *view = CreateView(buffer->id);
|
||||
window->active_view = view->id;
|
||||
|
||||
SetActiveWindow(window->id);
|
||||
|
||||
@@ -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, View *view) { return window->active_view.id == view->id.id; }
|
||||
inline Window *GetActiveWindow() { return GetWindow(ActiveWindow); }
|
||||
inline View *GetActiveView(Window *window) {
|
||||
if (window->active_view.id == 0) return GetView(window->views[0]);
|
||||
else return GetView(window->active_view);
|
||||
}
|
||||
inline View *GetActiveView(Window *window) { return GetView(window->active_view); }
|
||||
|
||||
void InitBuffer(Allocator allocator, Buffer *buffer, String name, Int size = 4096) {
|
||||
buffer->id = AllocBufferID();
|
||||
@@ -83,12 +80,6 @@ Window *CreateWindow() {
|
||||
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 *w = Alloc(&Views);
|
||||
w->id = AllocViewID();
|
||||
@@ -117,16 +108,21 @@ bool SetActiveWindow(WindowID window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Window *FindParentWindow(ViewID view_id) {
|
||||
Window *GetWindowWithView(ViewID view_id) {
|
||||
ForItem(window, Windows) {
|
||||
if (window.active_view.id == view_id.id) {
|
||||
return &window;
|
||||
} else {
|
||||
ForItem(child_view, window.views) {
|
||||
if (child_view.id == view_id.id) {
|
||||
return &window;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -203,49 +199,43 @@ Buffer *BufferOpenFile(String path) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
View *_WindowOpenViewAndBuffer(Window *window, String name, bool set_active = true) {
|
||||
View *OpenBufferView(String name) {
|
||||
Buffer *buffer = BufferOpenFile(name);
|
||||
View *view = CreateView(buffer->id);
|
||||
Add(&window->views, view->id);
|
||||
if (set_active) window->active_view = view->id;
|
||||
return view;
|
||||
}
|
||||
|
||||
void UnlinkView(Window *window, ViewID view) {
|
||||
For(window->views) {
|
||||
if (it.id == view.id) {
|
||||
UnorderedRemove(&window->views, it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert(window->active_view.id != view.id);
|
||||
}
|
||||
|
||||
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 *WindowOpenBufferView(Window *new_parent_window, String name) {
|
||||
// @todo: window history
|
||||
// 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);
|
||||
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) {
|
||||
Add(&new_parent_window->views, view->id);
|
||||
new_parent_window->active_view = view->id;
|
||||
return view;
|
||||
}
|
||||
|
||||
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;
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -53,9 +53,8 @@ struct View {
|
||||
};
|
||||
|
||||
struct Window {
|
||||
WindowID id;
|
||||
ViewID active_view;
|
||||
Array<ViewID> views;
|
||||
WindowID id;
|
||||
ViewID active_view;
|
||||
|
||||
Rect2I total_rect;
|
||||
Rect2I scrollbar_rect;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
- Windows
|
||||
- Mark windows as absolute or non-automatic layout and then just loop through windows
|
||||
- Remove view children, replace with view history
|
||||
- layouting, resize windows
|
||||
- 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?
|
||||
- this would allow to create new windows just like that to inform user and so on
|
||||
- window borders as flag
|
||||
|
||||
- files
|
||||
- load directory
|
||||
- file lister
|
||||
|
||||
- plumbing
|
||||
- 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)
|
||||
|
||||
|
||||
- file lister
|
||||
|
||||
- page up and down should also scroll and leave you in exactly same scroll
|
||||
|
||||
|
||||
@@ -15,16 +15,15 @@ void InitWindows(View *null_view) {
|
||||
View *v = CreateView(b->id);
|
||||
LoadTextA(b);
|
||||
LoadUnicode(b);
|
||||
AddView(w, null_view->id);
|
||||
AddView(w, v->id);
|
||||
w->active_view = v->id;
|
||||
}
|
||||
|
||||
{
|
||||
Window *w = CreateWindow();
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*console*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
AddView(w, v->id);
|
||||
Window *w = CreateWindow();
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*console*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
w->active_view = v->id;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -36,8 +35,8 @@ void InitWindows(View *null_view) {
|
||||
window->visible = false;
|
||||
buffer->no_history = true;
|
||||
View *view = CreateView(buffer->id);
|
||||
AddView(window, view->id);
|
||||
DebugWindowID = window->id;
|
||||
window->active_view = view->id;
|
||||
DebugWindowID = window->id;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -49,8 +48,8 @@ void InitWindows(View *null_view) {
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*infobar*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
AddView(w, v->id);
|
||||
InfoBarWindowID = w->id;
|
||||
w->active_view = v->id;
|
||||
InfoBarWindowID = w->id;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -65,7 +64,8 @@ void InitWindows(View *null_view) {
|
||||
w->deactivate_on_escape = true;
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*commands*");
|
||||
View *v = CreateView(b->id);
|
||||
AddView(w, v->id);
|
||||
w->active_view = v->id;
|
||||
|
||||
CommandWindowID = w->id;
|
||||
Command_EvalLua(v, L"list_buffers()");
|
||||
}
|
||||
@@ -80,7 +80,8 @@ void InitWindows(View *null_view) {
|
||||
w->deactivate_on_escape = true;
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*search*");
|
||||
View *v = CreateView(b->id);
|
||||
AddView(w, v->id);
|
||||
w->active_view = v->id;
|
||||
|
||||
SearchWindowID = w->id;
|
||||
}
|
||||
|
||||
@@ -95,7 +96,8 @@ void InitWindows(View *null_view) {
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*popup*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
AddView(w, v->id);
|
||||
w->active_view = v->id;
|
||||
|
||||
PopupWindowID = w->id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user