Big refactor new layout
This commit is contained in:
@@ -32,6 +32,16 @@ Linux
|
||||
|
||||
|
||||
|
||||
Commands TODO:
|
||||
- Search
|
||||
- Ctrl + F
|
||||
- Next occurence: Enter
|
||||
- Prev occurence: Shift + Enter
|
||||
- next occurence: F3
|
||||
- prev occurence: Shift + F3
|
||||
- Console: OK concept but constrain
|
||||
- Turned off by default
|
||||
- Special: non editable, hotkeys don't work etc.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -398,6 +398,6 @@ void ReloadFont() {
|
||||
Scratch scratch;
|
||||
Atlas atlas = CreateAtlas(scratch, {2048, 2048});
|
||||
PrimaryFont = CreateFont(&atlas, (uint32_t)ClampBottom(2u, (U32)StyleFontSize), StyleFont);
|
||||
SecondaryFont = CreateFont(&atlas, 10, StyleFont);
|
||||
SecondaryFont = CreateFont(&atlas, 12, StyleFont);
|
||||
SecondaryFont.texture_id = PrimaryFont.texture_id = UploadAtlas(&atlas);
|
||||
}
|
||||
|
||||
@@ -1,47 +1,4 @@
|
||||
void CheckpointBeforeGoto(Window *window, View *view) {
|
||||
Add(&window->goto_history, {view->id, view->carets[0]});
|
||||
window->goto_redo.len = 0;
|
||||
}
|
||||
|
||||
void CheckpointBeforeGoto(Window *window) {
|
||||
CheckpointBeforeGoto(window, GetView(window->active_view));
|
||||
}
|
||||
|
||||
GotoCrumb GetCrumb(Array<GotoCrumb> *cr) {
|
||||
for (; cr->len;) {
|
||||
GotoCrumb c = Pop(cr);
|
||||
View *view = FindView(c.view_id);
|
||||
if (view) return c;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void GotoBackward(Window *window) {
|
||||
BSet set = GetBSet(window);
|
||||
if (window->goto_history.len <= 0) return;
|
||||
Add(&window->goto_redo, {set.view->id, set.view->carets[0]});
|
||||
|
||||
GotoCrumb c = GetCrumb(&window->goto_history);
|
||||
window->active_view = c.view_id;
|
||||
View *view = GetView(c.view_id);
|
||||
view->carets[0] = c.caret;
|
||||
UpdateScroll(window, true);
|
||||
}
|
||||
|
||||
void GotoForward(Window *window) {
|
||||
BSet set = GetBSet(window);
|
||||
if (window->goto_redo.len <= 0) return;
|
||||
Add(&window->goto_history, {set.view->id, set.view->carets[0]});
|
||||
|
||||
GotoCrumb c = GetCrumb(&window->goto_redo);
|
||||
window->active_view = c.view_id;
|
||||
View *view = GetView(c.view_id);
|
||||
view->carets[0] = c.caret;
|
||||
UpdateScroll(window, true);
|
||||
}
|
||||
|
||||
void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
|
||||
CheckpointBeforeGoto(set->window);
|
||||
if (buffer_name.len == 0) {
|
||||
String current_dir = ChopLastSlash(set->buffer->name);
|
||||
buffer_name = GetUniqueBufferName(current_dir, "temp");
|
||||
@@ -52,7 +9,6 @@ void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
|
||||
}
|
||||
|
||||
void Command_BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
|
||||
CheckpointBeforeGoto(set->window);
|
||||
set->buffer = GetBuffer(buffer_id);
|
||||
set->view = WindowOpenBufferView(set->window, set->buffer->name);
|
||||
}
|
||||
@@ -899,43 +855,6 @@ void Command_Find(View *seek_view, String16 needle, bool forward = true) {
|
||||
IF_DEBUG(AssertRanges(seek_view->carets));
|
||||
}
|
||||
|
||||
void Command_GotoNextInList(Window *window, Int line_offset = 1) {
|
||||
Assert(line_offset == 1 || line_offset == -1);
|
||||
View *active_view = GetView(window->active_view);
|
||||
|
||||
View *view_goto = GetView(window->active_goto_list);
|
||||
window->active_view = view_goto->id;
|
||||
|
||||
Buffer *buffer_goto = GetBuffer(view_goto->active_buffer);
|
||||
int64_t pos = window->goto_list_pos;
|
||||
Int line = PosToLine(buffer_goto, pos);
|
||||
|
||||
bool opened = false;
|
||||
for (Int i = line + line_offset; i >= 0 && i < buffer_goto->line_starts.len; i += line_offset) {
|
||||
Range line_range = GetLineRangeWithoutNL(buffer_goto, i);
|
||||
String16 line = GetString(buffer_goto, line_range);
|
||||
view_goto->carets[0] = MakeCaret(line_range.min);
|
||||
window->goto_list_pos = line_range.min;
|
||||
line = Trim(line);
|
||||
|
||||
MergeCarets(buffer_goto, &view_goto->carets);
|
||||
IF_DEBUG(AssertRanges(view_goto->carets));
|
||||
if (line.len == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BSet set = Command_Open(line, "goto_build");
|
||||
if (set.window == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
opened = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!opened) window->active_view = active_view->id;
|
||||
}
|
||||
|
||||
void Command_FuzzySort(View *view, String16 needle) {
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
|
||||
@@ -1132,7 +1051,6 @@ BSet Command_Open(Window *window, String path, String meta, bool set_active = tr
|
||||
Command_Appendf(set.view, "%S\n", it.filename);
|
||||
}
|
||||
} else {
|
||||
CheckpointBeforeGoto(set.window);
|
||||
View *view = WindowOpenBufferView(set.window, ores.file_path);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
if (ores.line != -1) {
|
||||
@@ -1204,8 +1122,6 @@ int Lua_Cmd(lua_State *L) {
|
||||
BSet main = GetActiveMainSet();
|
||||
if (kind == "console") {
|
||||
BSet set = GetConsoleSet();
|
||||
main.window->active_goto_list = set.view->id;
|
||||
main.window->goto_list_pos = set.buffer->len;
|
||||
Command_SelectRangeOneCursor(set.view, MakeRange(set.buffer->len));
|
||||
Command_BeginJump(&set);
|
||||
Exec(set.view->id, true, cmd, working_dir);
|
||||
@@ -1217,8 +1133,6 @@ int Lua_Cmd(lua_State *L) {
|
||||
ActiveWindow = main.window->id;
|
||||
} else {
|
||||
JumpGarbageBuffer(&main);
|
||||
main.window->active_goto_list = main.view->id;
|
||||
main.window->goto_list_pos = 0;
|
||||
Exec(main.view->id, true, cmd, working_dir);
|
||||
ActiveWindow = main.window->id;
|
||||
}
|
||||
@@ -1366,20 +1280,6 @@ Window *SwitchWindow(int direction) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String16 GetSearchString(Window *window) {
|
||||
if (!window->is_search_bar) {
|
||||
if (window->search_bar_window.id == 0) {
|
||||
return {};
|
||||
}
|
||||
window = GetWindow(window->search_bar_window);
|
||||
}
|
||||
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
String16 string = GetString(buffer);
|
||||
return string;
|
||||
}
|
||||
|
||||
String16 FetchLoadWord(void) {
|
||||
BSet active = GetActiveSet();
|
||||
Caret caret = active.view->carets[0];
|
||||
@@ -1388,24 +1288,3 @@ String16 FetchLoadWord(void) {
|
||||
String16 string = GetString(active.buffer, range);
|
||||
return string;
|
||||
}
|
||||
|
||||
void SplitWindow(WindowSplitKind kind) {
|
||||
Window *window = CreateWind();
|
||||
View *view = OpenBufferView(ScratchBuffer->name);
|
||||
window->active_view = view->id;
|
||||
CreateTitlebar(window->id);
|
||||
CreateSearchBar(window->id);
|
||||
|
||||
Window *active_window = GetActiveWind();
|
||||
SplitWindowEx(NULL, &WindowSplits, active_window, window, kind);
|
||||
ActiveWindow = window->id;
|
||||
}
|
||||
|
||||
int Lua_Split(lua_State *L) {
|
||||
lua_Integer kind = lua_tointeger(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (kind == 1 || kind == 2) {
|
||||
SplitWindow((WindowSplitKind)kind);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -46,23 +46,6 @@ void UpdateScroll(Window *window, bool update_caret_scrolling) {
|
||||
}
|
||||
}
|
||||
|
||||
void ResizerDetectMouse(Event event, WindowSplit *split) {
|
||||
if (split == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vec2I mouse = MouseVec2I();
|
||||
bool mouse_in_rect = AreOverlapping(mouse, split->resizer_rect);
|
||||
if (mouse_in_rect) {
|
||||
ResizerHover = split;
|
||||
if (Mouse(LEFT)) {
|
||||
ResizerSelected = split;
|
||||
}
|
||||
}
|
||||
ResizerDetectMouse(event, split->left);
|
||||
ResizerDetectMouse(event, split->right);
|
||||
}
|
||||
|
||||
void OnCommand(Event event) {
|
||||
ProfileFunction();
|
||||
//
|
||||
@@ -134,26 +117,33 @@ void OnCommand(Event event) {
|
||||
|
||||
Int p = ScreenSpaceToBufferPos(selected.window, selected.view, selected.buffer, mouse);
|
||||
Caret &caret = selected.view->carets[0];
|
||||
|
||||
caret = SetFrontWithAnchor(caret, DocumentAnchor, p);
|
||||
}
|
||||
|
||||
if (ResizerSelected && Mouse(LEFT_UP)) {
|
||||
if (ResizerSelected.id != -1 && Mouse(LEFT_UP)) {
|
||||
Assert(DocumentSelected.id == -1);
|
||||
Assert(ScrollbarSelected.id == -1);
|
||||
ResizerSelected = NULL;
|
||||
} else if (ResizerSelected) {
|
||||
ResizerSelected.id = {-1};
|
||||
} else if (ResizerSelected.id != -1) {
|
||||
Window *window = GetWindow(ResizerSelected);
|
||||
if (window->layout) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
mouse -= ResizerSelected->total_rect.min;
|
||||
Vec2I size = GetSize(ResizerSelected->total_rect);
|
||||
Vec2 p = ToVec2(mouse) / ToVec2(size);
|
||||
if (ResizerSelected->kind == WindowSplitKind_Vertical) {
|
||||
ResizerSelected->value = p.x;
|
||||
} else {
|
||||
ResizerSelected->value = p.y;
|
||||
Int offx = mouse.x - window->resizer_rect.min.x;
|
||||
window->weight += (double)offx / (double)WindowCalcEvenResizerValue(event.xwindow);
|
||||
window->weight = Clamp(window->weight, 0.1, 100.0);
|
||||
}
|
||||
} else {
|
||||
ResizerDetectMouse(event, &WindowSplits);
|
||||
ResizerHover = {-1};
|
||||
For(Windows) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
bool mouse_in_rect = AreOverlapping(mouse, it->resizer_rect);
|
||||
if (mouse_in_rect) {
|
||||
ResizerHover = it->id;
|
||||
if (Mouse(LEFT)) {
|
||||
ResizerSelected = it->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set active window on click
|
||||
@@ -171,13 +161,6 @@ void OnCommand(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Mouse(X2)) {
|
||||
GotoForward(GetActiveMainSet().window);
|
||||
}
|
||||
if (Mouse(X1)) {
|
||||
GotoBackward(GetActiveMainSet().window);
|
||||
}
|
||||
|
||||
if (Ctrl() && Shift() && Mouse(RIGHT)) {
|
||||
|
||||
} else if (Alt() && Ctrl() && Mouse(RIGHT)) {
|
||||
@@ -227,7 +210,6 @@ void OnCommand(Event event) {
|
||||
bool mouse_in_document = AreOverlapping(mouse, active.window->document_rect);
|
||||
bool mouse_in_line_numbers = AreOverlapping(mouse, active.window->line_numbers_rect);
|
||||
if (mouse_in_document || mouse_in_line_numbers) {
|
||||
CheckpointBeforeGoto(active.window);
|
||||
DocumentSelected = active.window->id;
|
||||
|
||||
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
|
||||
@@ -295,12 +277,6 @@ void OnCommand(Event event) {
|
||||
Command_ListCode();
|
||||
}
|
||||
|
||||
if (CtrlShiftPress(SDLK_BACKSLASH)) {
|
||||
SplitWindow(WindowSplitKind_Horizontal);
|
||||
} else if (CtrlPress(SDLK_BACKSLASH)) {
|
||||
SplitWindow(WindowSplitKind_Vertical);
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_0)) {
|
||||
ToggleVisibility(DebugWindowID);
|
||||
}
|
||||
@@ -309,11 +285,6 @@ void OnCommand(Event event) {
|
||||
if (ActiveWindow != NullWindowID) {
|
||||
ActiveWindow = NullWindowID;
|
||||
} else {
|
||||
if (WindowSplits.value + 0.01 < 0.9) {
|
||||
WindowSplits.value = (double)0.9;
|
||||
} else {
|
||||
WindowSplits.value = (double)0.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CtrlPress(SDLK_1)) {
|
||||
@@ -462,11 +433,9 @@ void OnCommand(Event event) {
|
||||
}
|
||||
|
||||
if (CtrlShiftPress(SDLK_TAB)) {
|
||||
GotoForward(main.window);
|
||||
} else if (ShiftPress(SDLK_TAB)) {
|
||||
Command_IndentSelectedLines(active.view, SHIFT_PRESS);
|
||||
} else if (CtrlPress(SDLK_TAB)) {
|
||||
GotoBackward(main.window);
|
||||
} else if (Press(SDLK_TAB)) {
|
||||
Command_IndentSelectedLines(active.view);
|
||||
}
|
||||
@@ -508,22 +477,6 @@ void OnCommand(Event event) {
|
||||
MergeCarets(active.buffer, &active.view->carets);
|
||||
}
|
||||
|
||||
if (CtrlShiftPress(SDLK_N)) {
|
||||
Scratch scratch;
|
||||
String16 search_string = GetSearchString(main.window);
|
||||
Caret caret = FindPrev(main.buffer, search_string, main.view->carets[0]);
|
||||
BSet search = GetBSet(main.window->search_bar_window);
|
||||
search.window->search_bar_anchor = caret;
|
||||
Command_SelectRangeOneCursor(main.view, caret);
|
||||
} else if (CtrlPress(SDLK_N)) {
|
||||
Scratch scratch;
|
||||
String16 search_string = GetSearchString(main.window);
|
||||
Caret caret = FindNext(main.buffer, search_string, main.view->carets[0]);
|
||||
BSet search = GetBSet(main.window->search_bar_window);
|
||||
search.window->search_bar_anchor = caret;
|
||||
Command_SelectRangeOneCursor(main.view, caret);
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_EQUALS)) {
|
||||
StyleFontSize += 1;
|
||||
ReloadFont();
|
||||
@@ -536,24 +489,7 @@ void OnCommand(Event event) {
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_E)) {
|
||||
Command_GotoNextInList(active.window, 1);
|
||||
} else if (AltPress(SDLK_E)) {
|
||||
Command_GotoNextInList(active.window, -1);
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_F)) {
|
||||
if (!active.window->is_search_bar) {
|
||||
BSet search = GetBSet(main.window->search_bar_window);
|
||||
String16 string = GetString(main.buffer, main.view->carets[0].range);
|
||||
if (string.len) {
|
||||
Command_SelectEntireBuffer(search.view);
|
||||
Command_Replace(search.view, string);
|
||||
}
|
||||
Command_SelectEntireBuffer(search.view);
|
||||
search.window->visible = 1;
|
||||
search.window->search_bar_anchor = main.view->carets[0];
|
||||
ActiveWindow = search.window->id;
|
||||
}
|
||||
}
|
||||
|
||||
if (CtrlShiftPress(SDLK_RETURN)) {
|
||||
@@ -609,12 +545,6 @@ void OnCommand(Event event) {
|
||||
Command_Open(name);
|
||||
}
|
||||
|
||||
if (CtrlPress(SDLK_T)) {
|
||||
ActiveWindow = GetWindow(active.window->title_bar_window)->id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (CtrlShiftPress(SDLK_L)) {
|
||||
EncloseSpace(active.view);
|
||||
} else if (CtrlPress(SDLK_L)) {
|
||||
@@ -653,31 +583,15 @@ void OnCommand(Event event) {
|
||||
Command_Open(FetchLoadWord());
|
||||
}
|
||||
|
||||
{
|
||||
Range rng = GetLineRangeWithoutNL(active.buffer, active.buffer->line_starts.len - 1);
|
||||
GetLast(active.window->goto_history)->caret = MakeCaret(rng.max, rng.min);
|
||||
}
|
||||
} else {
|
||||
Command_Open(FetchLoadWord());
|
||||
}
|
||||
}
|
||||
|
||||
if (Press(SDLK_ESCAPE)) {
|
||||
if (active.window->is_search_bar) {
|
||||
ActiveWindow = main.window->id;
|
||||
active.window->visible = 0;
|
||||
} else if (active.window->deactivate_on_escape) {
|
||||
ActiveWindow = main.window->id;
|
||||
} else {
|
||||
active.view->carets.len = 1;
|
||||
active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (active.window->is_search_bar && buffer_change_id != active.buffer->change_id) {
|
||||
main.view->carets[0] = active.window->search_bar_anchor;
|
||||
Command_Find(main.view, GetSearchString(main.window), true);
|
||||
}
|
||||
|
||||
// :OnCommandEnding
|
||||
MergeCarets(active.buffer, &active.view->carets);
|
||||
|
||||
@@ -116,16 +116,6 @@ int Lua_GetMainDir(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Lua_SplitSize(lua_State *L) {
|
||||
lua_Number num = lua_tonumber(L, 1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
BSet set = GetActiveMainSet();
|
||||
WindowSplit *split = set.window->split_ref;
|
||||
split->parent->value = num;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Lua_KillWindow(lua_State *L) {
|
||||
BSet set = GetActiveMainSet();
|
||||
set.window->kill = true;
|
||||
@@ -298,9 +288,6 @@ void ReloadLuaConfigs(bool reload = false) {
|
||||
ReloadStyle();
|
||||
ReloadFont();
|
||||
For(Windows) {
|
||||
if (it->is_title_bar || it->is_search_bar) {
|
||||
continue;
|
||||
}
|
||||
it->draw_scrollbar = StyleDrawScrollbar;
|
||||
it->draw_line_numbers = StyleDrawLineNumbers;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ luaL_Reg LuaFunctions[] = {
|
||||
{"GetWorkDir", Lua_GetWorkDir},
|
||||
{"GetExeDir", Lua_GetExeDir},
|
||||
{"GetMainDir", Lua_GetMainDir},
|
||||
{"SplitSize", Lua_SplitSize},
|
||||
{"KillWindow", Lua_KillWindow},
|
||||
{"Play", Lua_Play},
|
||||
{"TrimTrailingWhitespace", Lua_TrimTrailingWhitespace},
|
||||
@@ -37,6 +36,5 @@ luaL_Reg LuaFunctions[] = {
|
||||
{"SetWorkDir", Lua_SetWorkDir},
|
||||
{"ListCommands", Lua_ListCommands},
|
||||
{"GetBufferList", Lua_GetBufferList},
|
||||
{"Split", Lua_Split},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -15,13 +15,13 @@ WindowID DebugWindowID;
|
||||
ViewID DebugViewID;
|
||||
BufferID DebugBufferID;
|
||||
|
||||
WindowSplit WindowSplits;
|
||||
WindowID ActiveWindow;
|
||||
WindowID BarWindowID;
|
||||
|
||||
WindowSplit *ResizerSelected = NULL;
|
||||
WindowSplit *ResizerHover = NULL;
|
||||
WindowID ActiveWindow;
|
||||
WindowID ScrollbarSelected = {-1};
|
||||
WindowID DocumentSelected = {-1};
|
||||
WindowID ResizerSelected = {-1};
|
||||
WindowID ResizerHover = {-1};
|
||||
Caret DocumentAnchor;
|
||||
|
||||
Buffer *LuaProjectBuffer;
|
||||
@@ -143,56 +143,46 @@ Buffer *CreateBuffer(Allocator allocator, String name, Int size) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Window *CreateWind(bool create_command_buffer = true) {
|
||||
Window *CreateWind() {
|
||||
Allocator allocator = GetSystemAllocator();
|
||||
Window *w = AllocType(allocator, Window);
|
||||
w->font = &PrimaryFont;
|
||||
w->visible = true;
|
||||
w->layout = true;
|
||||
w->draw_scrollbar = StyleDrawScrollbar;
|
||||
w->draw_line_numbers = StyleDrawLineNumbers;
|
||||
w->id = AllocWindowID(w);
|
||||
w->weight = 1.0;
|
||||
Add(&Windows, w);
|
||||
return w;
|
||||
}
|
||||
|
||||
void DestroyWindow(Window *window) {
|
||||
Allocator allocator = GetSystemAllocator();
|
||||
window->kill = true;
|
||||
WindowSplit *split = window->split_ref;
|
||||
if (split && split->parent) {
|
||||
Assert(split->kind == WindowSplitKind_Window);
|
||||
// Allocator allocator = GetSystemAllocator();
|
||||
// window->kill = true;
|
||||
// Window *split = window;
|
||||
// if (split && split->parent) {
|
||||
// Assert(split->kind == WindowSplitKind_Window);
|
||||
|
||||
WindowSplit *p = split->parent;
|
||||
WindowSplit *pp = p->parent;
|
||||
WindowSplit *other = p->left == split ? p->right : p->left;
|
||||
// WindowSplit *p = split->parent;
|
||||
// WindowSplit *pp = p->parent;
|
||||
// WindowSplit *other = p->left == split ? p->right : p->left;
|
||||
|
||||
if (pp) {
|
||||
if (pp->left == p) {
|
||||
pp->left = other;
|
||||
} else {
|
||||
pp->right = other;
|
||||
}
|
||||
other->parent = pp;
|
||||
}
|
||||
// if (pp) {
|
||||
// if (pp->left == p) {
|
||||
// pp->left = other;
|
||||
// } else {
|
||||
// pp->right = other;
|
||||
// }
|
||||
// other->parent = pp;
|
||||
// }
|
||||
|
||||
Dealloc(allocator, p);
|
||||
Dealloc(allocator, split);
|
||||
}
|
||||
// Dealloc(allocator, p);
|
||||
// Dealloc(allocator, split);
|
||||
// }
|
||||
|
||||
|
||||
if (!window->is_search_bar && window->search_bar_window.id) {
|
||||
Window *s = GetWindow(window->search_bar_window, NULL);
|
||||
s->kill = true;
|
||||
}
|
||||
|
||||
if (!window->is_title_bar && window->title_bar_window.id) {
|
||||
Window *s = GetWindow(window->title_bar_window, NULL);
|
||||
s->kill = true;
|
||||
}
|
||||
|
||||
Dealloc(&window->goto_history);
|
||||
Dealloc(&window->goto_redo);
|
||||
Dealloc(allocator, window);
|
||||
// Dealloc(allocator, window);
|
||||
}
|
||||
|
||||
View *CreateView(BufferID active_buffer) {
|
||||
@@ -262,13 +252,6 @@ View *FindView(String name, View *default_view = NULL) {
|
||||
return default_view;
|
||||
}
|
||||
|
||||
Window *GetTitlebarWindow(WindowID id) {
|
||||
Window *window = GetWindow(id);
|
||||
if (!window->is_title_bar) window = GetWindow(window->title_bar_window);
|
||||
Assert(window->is_title_bar);
|
||||
return window;
|
||||
}
|
||||
|
||||
BSet GetBSet(Window *window) {
|
||||
BSet set = {window};
|
||||
set.view = GetView(set.window->active_view);
|
||||
@@ -282,14 +265,7 @@ BSet GetBSet(WindowID window_id) {
|
||||
return result;
|
||||
}
|
||||
|
||||
BSet GetTitleSet(Window *window) {
|
||||
if (!window->is_title_bar) window = GetWindow(window->title_bar_window);
|
||||
BSet result = GetBSet(window);
|
||||
return result;
|
||||
}
|
||||
|
||||
BSet GetMainSet(Window *window) {
|
||||
if (window->is_title_bar) window = GetWindow(window->title_bar_window);
|
||||
BSet result = GetBSet(window);
|
||||
return result;
|
||||
}
|
||||
@@ -301,8 +277,8 @@ BSet GetActiveSet() {
|
||||
|
||||
BSet GetActiveMainSet() {
|
||||
Window *window = GetWindow(ActiveWindow);
|
||||
if (window->is_title_bar) window = GetWindow(window->title_bar_window);
|
||||
if (window->is_search_bar) window = GetWindow(window->search_bar_window);
|
||||
// if (window->is_title_bar) window = GetWindow(window->title_bar_window);
|
||||
// if (window->is_search_bar) window = GetWindow(window->search_bar_window);
|
||||
return GetBSet(window);
|
||||
}
|
||||
|
||||
@@ -314,12 +290,6 @@ BSet GetConsoleSet() {
|
||||
return result;
|
||||
}
|
||||
|
||||
BSet GetActiveTitleSet() {
|
||||
Window *window = GetWindow(ActiveWindow);
|
||||
if (!window->is_title_bar) window = GetWindow(window->title_bar_window);
|
||||
return GetBSet(window);
|
||||
}
|
||||
|
||||
String Command_GetFilename() {
|
||||
BSet set = GetActiveMainSet();
|
||||
return set.buffer->name;
|
||||
@@ -440,25 +410,13 @@ View *WindowOpenBufferView(Window *new_parent_window, String name) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ViewIsCrumb(ViewID view_id) {
|
||||
ForItem(window, Windows) {
|
||||
For(window->goto_history) if (it.view_id == view_id) return true;
|
||||
For(window->goto_redo) if (it.view_id == view_id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ViewIsReferenced(ViewID view) {
|
||||
if (view == NullViewID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ViewIsCrumb(view)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
For(Windows) {
|
||||
if (it->active_view == view || it->active_goto_list == view) {
|
||||
if (it->active_view == view) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,12 +194,21 @@ void SetMouseCursor(Event event) {
|
||||
Array<Window *> order = GetWindowZOrder(scratch);
|
||||
Vec2I mouse = MouseVec2I();
|
||||
|
||||
if (ResizerSelected) {
|
||||
WindowSplit *split = ResizerSelected;
|
||||
if (split->kind == WindowSplitKind_Vertical) {
|
||||
if (ResizerSelected.id != -1) {
|
||||
Window *window = GetWindow(ResizerSelected);
|
||||
if (window->layout) {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||
} else {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (ResizerHover.id != -1) {
|
||||
Window *window = GetWindow(ResizerHover);
|
||||
if (window->layout) {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||
} else {
|
||||
Assert(split->kind == WindowSplitKind_Horizontal);
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||
}
|
||||
return;
|
||||
@@ -219,16 +228,7 @@ void SetMouseCursor(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ResizerHover) {
|
||||
WindowSplit *split = ResizerHover;
|
||||
if (split->kind == WindowSplitKind_Vertical) {
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
|
||||
} else {
|
||||
Assert(split->kind == WindowSplitKind_Horizontal);
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SetMouseCursor(SDL_SYSTEM_CURSOR_DEFAULT);
|
||||
}
|
||||
@@ -246,9 +246,6 @@ void Update(Event event) {
|
||||
}
|
||||
|
||||
OnCommand(event);
|
||||
For(Windows) {
|
||||
if (it->is_title_bar) ReplaceTitleBarData(it);
|
||||
}
|
||||
UpdateProcesses();
|
||||
CoUpdate(&event);
|
||||
ReloadLuaConfigs();
|
||||
@@ -368,7 +365,6 @@ void MainLoop() {
|
||||
SetMouseCursor(*event);
|
||||
LayoutWindows(event->xwindow, event->ywindow); // This is here to render changes in title bar size without a frame of delay
|
||||
BeginFrameRender(event->xwindow, event->ywindow);
|
||||
DrawSplits(&WindowSplits);
|
||||
|
||||
Array<Window *> order = GetWindowZOrder(scratch);
|
||||
For(IterateInReverse(&order)) {
|
||||
|
||||
@@ -16,69 +16,39 @@ struct View {
|
||||
String16 prev_search_line;
|
||||
};
|
||||
|
||||
struct GotoCrumb {
|
||||
ViewID view_id;
|
||||
Caret caret;
|
||||
enum WindowKind {
|
||||
WindowKind_None,
|
||||
WindowKind_Root,
|
||||
WindowKind_Leaf,
|
||||
WindowKind_SplitHori,
|
||||
WindowKind_SplitVerti,
|
||||
};
|
||||
|
||||
struct Window {
|
||||
WindowID id;
|
||||
ViewID active_view;
|
||||
WindowSplit *split_ref;
|
||||
|
||||
WindowID title_bar_window;
|
||||
Int title_bar_last_buffer_change_id; // @todo: bring back the changes to title bar?
|
||||
|
||||
WindowID search_bar_window;
|
||||
|
||||
Rect2I total_rect;
|
||||
Rect2I document_rect;
|
||||
Rect2I scrollbar_rect;
|
||||
Rect2I line_numbers_rect;
|
||||
|
||||
Array<GotoCrumb> goto_history;
|
||||
Array<GotoCrumb> goto_redo;
|
||||
|
||||
ViewID active_goto_list;
|
||||
Int goto_list_pos;
|
||||
Rect2I resizer_rect;
|
||||
|
||||
Font *font;
|
||||
Caret search_bar_anchor;
|
||||
double mouse_scroller_offset;
|
||||
int z;
|
||||
double weight;
|
||||
Int offset_resizer;
|
||||
|
||||
struct {
|
||||
bool draw_scrollbar : 1;
|
||||
bool draw_line_numbers : 1;
|
||||
bool visible : 1;
|
||||
|
||||
bool is_title_bar : 1;
|
||||
bool is_search_bar : 1;
|
||||
|
||||
bool deactivate_on_escape : 1;
|
||||
|
||||
bool layout : 1;
|
||||
bool kill : 1;
|
||||
};
|
||||
};
|
||||
|
||||
enum WindowSplitKind {
|
||||
WindowSplitKind_Window,
|
||||
WindowSplitKind_Vertical,
|
||||
WindowSplitKind_Horizontal,
|
||||
};
|
||||
|
||||
struct WindowSplit {
|
||||
WindowSplitKind kind;
|
||||
WindowSplit *left;
|
||||
WindowSplit *right;
|
||||
WindowSplit *parent;
|
||||
Rect2I total_rect;
|
||||
Rect2I resizer_rect;
|
||||
|
||||
Window *window;
|
||||
double value;
|
||||
};
|
||||
|
||||
struct Scroller {
|
||||
Rect2 rect;
|
||||
double begin;
|
||||
|
||||
@@ -40,92 +40,3 @@ void UpdateDebugBuffer() {
|
||||
RawAppendf(buffer, "int changed_on_disk = %d\n", main.buffer->changed_on_disk);
|
||||
RawAppendf(buffer, "int garbage = %d\n", main.buffer->garbage);
|
||||
}
|
||||
|
||||
void ReplaceTitleBarData(Window *window) {
|
||||
Scratch scratch;
|
||||
BSet main = GetMainSet(window);
|
||||
BSet title = GetBSet(window);
|
||||
title.view->scroll.y = 0;
|
||||
|
||||
String16 buffer_string = GetString(title.buffer);
|
||||
Range replace_range = {0, title.buffer->len};
|
||||
bool found_separator = Seek(buffer_string, u" |", &replace_range.max);
|
||||
|
||||
// Parse the title and line
|
||||
if (window->id == ActiveWindow) {
|
||||
if (title.buffer->change_id == title.window->title_bar_last_buffer_change_id) {
|
||||
return;
|
||||
}
|
||||
String16 buffer_name = GetString(title.buffer, replace_range);
|
||||
buffer_name = Trim(buffer_name);
|
||||
|
||||
Int column = ChopNumber(&buffer_name);
|
||||
if (column == -1) return;
|
||||
|
||||
Int line = ChopNumber(&buffer_name);
|
||||
if (line == -1) {
|
||||
line = column;
|
||||
column = 0;
|
||||
}
|
||||
|
||||
String name = ToString(scratch, buffer_name);
|
||||
if (name != main.buffer->name) {
|
||||
name = GetAbsolutePath(scratch, name);
|
||||
if (FindBuffer(name)) {
|
||||
title.window->title_bar_last_buffer_change_id = title.buffer->change_id;
|
||||
ReportConsolef("there is already buffer with name: %S", name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (name != main.buffer->name) {
|
||||
main.buffer->name = Intern(&GlobalInternTable, name);
|
||||
title.window->title_bar_last_buffer_change_id = title.buffer->change_id;
|
||||
main.buffer->file_mod_time = 0;
|
||||
main.buffer->changed_on_disk = false;
|
||||
main.buffer->dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
Int buffer_pos = XYToPos(main.buffer, {column, line});
|
||||
Caret &caret = main.view->carets[0];
|
||||
if (GetFront(caret) != buffer_pos) {
|
||||
caret = MakeCaret(buffer_pos);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Caret caret = main.view->carets[0];
|
||||
XY xy = PosToXY(main.buffer, GetFront(caret));
|
||||
|
||||
Array<Caret> caret_copy = Copy(GetSystemAllocator(), title.view->carets);
|
||||
defer {
|
||||
Dealloc(&title.view->carets);
|
||||
title.view->carets = caret_copy;
|
||||
};
|
||||
|
||||
// add separator at the end of buffer
|
||||
if (!found_separator) {
|
||||
Command_SelectRangeOneCursor(title.view, GetBufferEndAsRange(title.buffer));
|
||||
Array<Edit> edits = Command_ReplaceEx(scratch, title.view, u" |");
|
||||
AdjustCarets(edits, &caret_copy);
|
||||
}
|
||||
|
||||
|
||||
// replace data up to separator with filename and stuff
|
||||
const char *reopen = main.buffer->changed_on_disk ? " Reopen()" : "";
|
||||
String s = Format(scratch, "%S:%lld:%lld%s", main.buffer->name, (long long)xy.line + 1ll, (long long)xy.col + 1ll, reopen);
|
||||
For (ActiveProcesses) {
|
||||
if (it.view_id == main.view->id.id) {
|
||||
s = Format(scratch, "%S %lld", s, (long long)it.id);
|
||||
}
|
||||
}
|
||||
|
||||
String16 string = ToString16(scratch, s);
|
||||
String16 string_to_replace = GetString(title.buffer, replace_range);
|
||||
if (string_to_replace != string) {
|
||||
Command_SelectRangeOneCursor(title.view, replace_range);
|
||||
Array<Edit> edits = Command_ReplaceEx(scratch, title.view, string);
|
||||
Command_SelectRangeOneCursor(title.view, MakeRange(0));
|
||||
AdjustCarets(edits, &caret_copy);
|
||||
}
|
||||
}
|
||||
@@ -6,102 +6,9 @@ Array<Window *> GetWindowZOrder(Allocator allocator) {
|
||||
return order;
|
||||
}
|
||||
|
||||
Window *CreateSearchBar(WindowID parent_window_id) {
|
||||
Window *window = CreateWind(false);
|
||||
window->draw_scrollbar = false;
|
||||
window->deactivate_on_escape = true;
|
||||
window->is_search_bar = true;
|
||||
|
||||
static int BarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "%S/searchbar%d", WorkDir, ++BarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
window->active_view = v->id;
|
||||
|
||||
Window *parent_window = GetWindow(parent_window_id);
|
||||
parent_window->search_bar_window = window->id;
|
||||
window->search_bar_window = parent_window->id;
|
||||
window->z = parent_window->z + 1;
|
||||
window->visible = false;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
Window *CreateTitlebar(WindowID parent_window_id) {
|
||||
Window *window = CreateWind(false);
|
||||
window->font = &SecondaryFont;
|
||||
window->draw_scrollbar = false;
|
||||
window->deactivate_on_escape = true;
|
||||
window->is_title_bar = true;
|
||||
|
||||
static int TitlebarCount;
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
String name = Format(sys_allocator, "%S/titlebar%d", WorkDir, ++TitlebarCount);
|
||||
|
||||
Buffer *b = CreateBuffer(sys_allocator, name);
|
||||
View *v = CreateView(b->id);
|
||||
window->active_view = v->id;
|
||||
|
||||
Window *parent_window = GetWindow(parent_window_id);
|
||||
parent_window->title_bar_window = window->id;
|
||||
window->title_bar_window = parent_window->id;
|
||||
|
||||
void ReplaceTitleBarData(Window * window);
|
||||
ReplaceTitleBarData(window);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
Int GetTitleBarSize(Window *window) {
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
float result = (float)buffer->line_starts.len * window->font->line_spacing;
|
||||
return (Int)result;
|
||||
}
|
||||
|
||||
WindowSplit *CreateSplitForWindow(WindowSplit *parent, Window *window) {
|
||||
WindowSplit *split = AllocType(SysAllocator, WindowSplit);
|
||||
split->kind = WindowSplitKind_Window;
|
||||
split->window = window;
|
||||
split->parent = parent;
|
||||
window->split_ref = split;
|
||||
return split;
|
||||
}
|
||||
|
||||
void SplitWindowEx(WindowSplit **node, WindowSplit *split, Window *target, Window *new_window, WindowSplitKind kind) {
|
||||
if (split->kind == WindowSplitKind_Horizontal || split->kind == WindowSplitKind_Vertical) {
|
||||
SplitWindowEx(&split->left, split->left, target, new_window, kind);
|
||||
SplitWindowEx(&split->right, split->right, target, new_window, kind);
|
||||
} else {
|
||||
Assert(split->kind == WindowSplitKind_Window);
|
||||
if (target != split->window) {
|
||||
return;
|
||||
}
|
||||
|
||||
WindowSplit *hori = AllocType(SysAllocator, WindowSplit);
|
||||
hori->parent = node[0]->parent;
|
||||
hori->kind = kind;
|
||||
hori->value = 0.5;
|
||||
hori->left = *node;
|
||||
hori->right = CreateSplitForWindow(hori, new_window);
|
||||
*node = hori;
|
||||
}
|
||||
}
|
||||
|
||||
void SetVisibility(WindowID window_id, bool v) {
|
||||
Window *window = GetWindow(window_id);
|
||||
window->visible = v;
|
||||
|
||||
if (window->title_bar_window.id != 0) {
|
||||
Window *title_bar = GetWindow(window->title_bar_window);
|
||||
title_bar->visible = v;
|
||||
}
|
||||
if (window->search_bar_window.id != 0) {
|
||||
Window *search_bar = GetWindow(window->search_bar_window);
|
||||
search_bar->visible = v;
|
||||
}
|
||||
}
|
||||
|
||||
bool ToggleVisibility(WindowID window_id) {
|
||||
@@ -111,78 +18,43 @@ bool ToggleVisibility(WindowID window_id) {
|
||||
return visible;
|
||||
}
|
||||
|
||||
void LoadBigText(Buffer *buffer, int size = 5000000) {
|
||||
for (int i = 0; i < size; i += 1) {
|
||||
RawReplaceText(buffer, GetBufferEndAsRange(buffer), u"Line number or something of the sort which is here or there or maybe somewhere else\n");
|
||||
}
|
||||
}
|
||||
|
||||
void LoadBigLine(Buffer *buffer, int size = 5000000) {
|
||||
for (int i = 0; i < size; i += 1) {
|
||||
RawReplaceText(buffer, GetBufferEndAsRange(buffer), u"Line number or something of the sort which is here or there or maybe somewhere else | ");
|
||||
}
|
||||
}
|
||||
|
||||
void LoadBigTextAndBigLine(Buffer *buffer, int size = 2500000) {
|
||||
LoadBigLine(buffer, size);
|
||||
LoadBigText(buffer, size);
|
||||
}
|
||||
|
||||
void LoadTextA(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
for (int i = 0; i < 1000; i += 1) {
|
||||
String s = Format(scratch, "line1: %d line2: %d line3: %d line4: %d line5: %d line6: %d line1: %d line2: %d line3: %d line4: %d line5: %d line6: %d\r\n", i, i, i, i, i, i, i, i, i, i, i, i);
|
||||
String16 s16 = ToString16(scratch, s);
|
||||
RawReplaceText(buffer, GetBufferEndAsRange(buffer), s16);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadLine(Buffer *buffer) {
|
||||
Scratch scratch;
|
||||
String s = "Line number and so on óźćż";
|
||||
RawReplaceText(buffer, {}, ToString16(scratch, s));
|
||||
}
|
||||
|
||||
void LoadTestBufferMessage(Buffer *buffer) {
|
||||
String text = R"===(
|
||||
|
||||
commit 225d1ffc067da0723898ade68fb9492bbe308feb
|
||||
https://www.lua.org/manual/5.4/
|
||||
|
||||
)===";
|
||||
Scratch scratch;
|
||||
RawReplaceText(buffer, {}, ToString16(scratch, text));
|
||||
|
||||
// RawReplaceText(buffer, GetBufferEndAsRange(buffer), ToString16(scratch, text));
|
||||
Int GetTitleBarSize(Window *window) {
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
float result = (float)buffer->line_starts.len * window->font->line_spacing;
|
||||
return (Int)result;
|
||||
}
|
||||
|
||||
void InitWindows() {
|
||||
WindowSplit *split = &WindowSplits;
|
||||
split->kind = WindowSplitKind_Horizontal;
|
||||
split->value = (double)0.9;
|
||||
Scratch scratch;
|
||||
|
||||
{
|
||||
Window *window = CreateWind();
|
||||
window->active_view = NullViewID;
|
||||
Assert(window->id.id == 0);
|
||||
CreateTitlebar(window->id);
|
||||
CreateSearchBar(window->id);
|
||||
|
||||
split->right = CreateSplitForWindow(split, window);
|
||||
window->active_view = CreateView(ScratchBuffer->id)->id;
|
||||
window->weight = 1.0;
|
||||
{
|
||||
Window *window = CreateWind();
|
||||
window->active_view = TraceView->id;
|
||||
CreateWind();
|
||||
CreateWind();
|
||||
}
|
||||
}
|
||||
|
||||
// BAR at the bottom
|
||||
{
|
||||
Window *window = CreateWind();
|
||||
Buffer *buffer = ScratchBuffer;
|
||||
BarWindowID = window->id;
|
||||
window->font = &SecondaryFont;
|
||||
window->draw_line_numbers = false;
|
||||
window->draw_scrollbar = false;
|
||||
window->layout = false;
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, "bar");
|
||||
buffer->no_history = true;
|
||||
View *view = CreateView(buffer->id);
|
||||
window->active_view = view->id;
|
||||
CreateTitlebar(window->id);
|
||||
CreateSearchBar(window->id);
|
||||
ActiveWindow = window->id;
|
||||
|
||||
split->left = CreateSplitForWindow(split, window);
|
||||
}
|
||||
|
||||
// DEBUG WINDOW
|
||||
{
|
||||
Window *window = CreateWind();
|
||||
DebugWindowID = window->id;
|
||||
@@ -190,6 +62,7 @@ void InitWindows() {
|
||||
window->draw_scrollbar = false;
|
||||
window->visible = false;
|
||||
window->z = 2;
|
||||
window->layout = false;
|
||||
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug"));
|
||||
DebugBufferID = buffer->id;
|
||||
@@ -199,86 +72,73 @@ void InitWindows() {
|
||||
DebugViewID = view->id;
|
||||
window->active_view = view->id;
|
||||
|
||||
Window *titlebar = CreateTitlebar(window->id);
|
||||
Window *searchbar = CreateSearchBar(window->id);
|
||||
titlebar->z = 2;
|
||||
searchbar->z = 2;
|
||||
|
||||
SetVisibility(window->id, false);
|
||||
}
|
||||
}
|
||||
|
||||
void LayoutWindowSplit(WindowSplit *split, Rect2I rect) {
|
||||
void CalcNiceties(Window *n) {
|
||||
float scrollbar_size = (10.f * DPIScale);
|
||||
float resizer_size = (float)PrimaryFont.char_spacing*0.5f;
|
||||
float line_numbers_size = (float)n->font->char_spacing * 10.f;
|
||||
if (n->draw_scrollbar) n->scrollbar_rect = CutRight(&n->document_rect, (Int)scrollbar_size);
|
||||
if (n->draw_line_numbers) n->line_numbers_rect = CutLeft(&n->document_rect, (Int)line_numbers_size);
|
||||
}
|
||||
|
||||
if (split->kind == WindowSplitKind_Window) {
|
||||
Window *it = split->window;
|
||||
float line_numbers_size = (float)it->font->char_spacing * 10;
|
||||
Assert(it->split_ref);
|
||||
it->total_rect = rect;
|
||||
|
||||
Window *title_bar_window = GetWindow(it->title_bar_window);
|
||||
title_bar_window->total_rect = CutBottom(&it->total_rect, GetTitleBarSize(title_bar_window));
|
||||
title_bar_window->document_rect = title_bar_window->total_rect;
|
||||
|
||||
Rect2I save_rect = it->document_rect;
|
||||
CutLeft(&save_rect, GetSize(save_rect).x/2);
|
||||
Window *search_bar_window = GetWindow(it->search_bar_window);
|
||||
search_bar_window->total_rect = CutTop(&save_rect, GetTitleBarSize(search_bar_window));
|
||||
search_bar_window->document_rect = search_bar_window->total_rect;
|
||||
|
||||
it->document_rect = it->total_rect;
|
||||
if (it->draw_scrollbar) it->scrollbar_rect = CutRight(&it->document_rect, (Int)scrollbar_size);
|
||||
if (it->draw_line_numbers) it->line_numbers_rect = CutLeft(&it->document_rect, (Int)line_numbers_size);
|
||||
} else if (split->kind == WindowSplitKind_Vertical) {
|
||||
Rect2I rect2 = {0};
|
||||
split->total_rect = rect;
|
||||
rect2 = CutLeft(&rect, (Int)round((double)GetSize(rect).x * split->value));
|
||||
split->resizer_rect = CutRight(&rect2, (Int)resizer_size);
|
||||
|
||||
LayoutWindowSplit(split->left, rect2);
|
||||
LayoutWindowSplit(split->right, rect);
|
||||
} else if (split->kind == WindowSplitKind_Horizontal) {
|
||||
Rect2I rect2 = {0};
|
||||
split->total_rect = rect;
|
||||
rect2 = CutTop(&rect, (Int)round((double)GetSize(rect).y * split->value));
|
||||
split->resizer_rect = CutTop(&rect, (Int)resizer_size);
|
||||
|
||||
LayoutWindowSplit(split->left, rect2);
|
||||
LayoutWindowSplit(split->right, rect);
|
||||
} else {
|
||||
Assert(!"Invalid codepath");
|
||||
double WindowCalcEvenResizerValue(Int screen_size_x, Int *out_count = NULL) {
|
||||
double w = 0;
|
||||
Int c = 0;
|
||||
ForItem(n, Windows) {
|
||||
if (n->layout) {
|
||||
w += n->weight;
|
||||
c += 1;
|
||||
}
|
||||
}
|
||||
if (out_count) *out_count = c;
|
||||
return (double)screen_size_x / w;
|
||||
}
|
||||
|
||||
void LayoutWindows(int16_t wx, int16_t wy) {
|
||||
Rect2I screen_rect = RectI0Size(wx, wy);
|
||||
LayoutWindowSplit(&WindowSplits, screen_rect);
|
||||
|
||||
// layout debug window
|
||||
// bar at the bottom
|
||||
{
|
||||
Window *window = GetWindow(DebugWindowID);
|
||||
Window *n = GetWindow(BarWindowID);
|
||||
Int barsize = GetTitleBarSize(n);
|
||||
n->document_rect = n->total_rect = CutBottom(&screen_rect, barsize);
|
||||
}
|
||||
|
||||
// floating debug window
|
||||
{
|
||||
Window *n = GetWindow(DebugWindowID);
|
||||
Rect2 screen_rect = Rect0Size(wx, wy);
|
||||
Vec2 size = GetSize(screen_rect);
|
||||
|
||||
Rect2 a = CutLeft(&screen_rect, 0.3f * size.x);
|
||||
Rect2 b = CutBottom(&a, 0.4f * size.y);
|
||||
Rect2 c = Shrink(b, 20);
|
||||
|
||||
window->total_rect = ToRect2I(c);
|
||||
|
||||
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;
|
||||
|
||||
Rect2I save_rect = window->document_rect;
|
||||
CutLeft(&save_rect, GetSize(save_rect).x/2);
|
||||
Window *search_bar_window = GetWindow(window->search_bar_window);
|
||||
search_bar_window->total_rect = CutTop(&save_rect, GetTitleBarSize(search_bar_window));
|
||||
search_bar_window->document_rect = search_bar_window->total_rect;
|
||||
|
||||
window->document_rect = window->total_rect;
|
||||
n->document_rect = n->total_rect = ToRect2I(c);
|
||||
}
|
||||
|
||||
// Column layout
|
||||
if (1) {
|
||||
Int c = 0;
|
||||
double size = WindowCalcEvenResizerValue(wx, &c);
|
||||
if (c == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
ForItem(n, Windows) {
|
||||
if (!n->layout) {
|
||||
continue;
|
||||
}
|
||||
|
||||
n->total_rect = n->document_rect = CutLeft(&screen_rect, (Int)(size * n->weight));
|
||||
if (i != (c - 1)) {
|
||||
Int resizer_size = (Int)(PrimaryFont.char_spacing*0.5f);
|
||||
n->resizer_rect = CutRight(&n->document_rect, resizer_size);
|
||||
}
|
||||
CalcNiceties(n);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,6 @@ void DrawWindow(Window *window, Event &event) {
|
||||
Rect2 screen_rect = Rect0Size(event.xwindow, event.ywindow);
|
||||
SetScissor(screen_rect);
|
||||
|
||||
bool is_actib = window->id == ActiveWindow || window->title_bar_window == ActiveWindow || window->search_bar_window == ActiveWindow;
|
||||
bool is_active = window->id == ActiveWindow;
|
||||
|
||||
Color color_whitespace_during_selection = ColorWhitespaceDuringSelection;
|
||||
@@ -116,17 +115,6 @@ void DrawWindow(Window *window, Event &event) {
|
||||
Color color_sub_caret = ColorSubCaret;
|
||||
Color color_text_line_numbers = ColorTextLineNumbers;
|
||||
Color color_text = ColorText;
|
||||
if (window->is_title_bar || window->is_search_bar) {
|
||||
if (is_active) {
|
||||
color_background = ColorTitleBarActiveBackground;
|
||||
} else {
|
||||
color_background = ColorTitleBarBackground;
|
||||
}
|
||||
color_selection = ColorTitleBarSelection;
|
||||
color_text = ColorTitleBarText;
|
||||
color_line_highlight = ColorTitleBarBackground;
|
||||
}
|
||||
|
||||
DrawRect(window->total_rect, color_background);
|
||||
|
||||
Rect2I combined_document_line_number = window->document_rect;
|
||||
@@ -182,18 +170,6 @@ void DrawWindow(Window *window, Event &event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!window->is_title_bar && !window->is_search_bar) {
|
||||
//
|
||||
// Draw highlight
|
||||
Int front = GetFront(it);
|
||||
XY fxy = PosToXY(buffer, front);
|
||||
Vec2I pos = XYToWorldPos(window, XYLine(fxy.line));
|
||||
Vec2I scrolled_pos = pos - view->scroll + window->document_rect.min;
|
||||
Rect2 rect = {
|
||||
{(float)window->total_rect.min.x, (float)scrolled_pos.y},
|
||||
{(float)window->total_rect.max.x, (float)scrolled_pos.y + (float)window->font->line_spacing}
|
||||
};
|
||||
DrawRect(rect, color_line_highlight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +203,6 @@ void DrawWindow(Window *window, Event &event) {
|
||||
DrawVisibleText(window, color_text);
|
||||
|
||||
BeginProfileScope(draw_carets);
|
||||
if (is_actib) {
|
||||
For(view->carets) {
|
||||
Int front = GetFront(it);
|
||||
XY fxy = PosToXY(buffer, front);
|
||||
@@ -236,7 +211,6 @@ void DrawWindow(Window *window, Event &event) {
|
||||
DrawCaret(window, fxy, 0.3f, main_caret ? color_main_caret : color_sub_caret);
|
||||
}
|
||||
}
|
||||
}
|
||||
EndProfileScope();
|
||||
|
||||
// Draw line numbers
|
||||
@@ -276,26 +250,14 @@ void DrawWindow(Window *window, Event &event) {
|
||||
DrawRect(window->total_rect, {255, 255, 255, 25});
|
||||
}
|
||||
|
||||
if (!is_actib) {
|
||||
|
||||
|
||||
SetScissor(screen_rect);
|
||||
DrawRect(window->total_rect, ColorInactiveWindow);
|
||||
// Draw resizer rect
|
||||
{
|
||||
Rect2I rect = window->resizer_rect;
|
||||
DrawRect(rect, ColorResizerBackground);
|
||||
DrawRect(CutRight(&rect, 1), ColorResizerOutline);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSplits(WindowSplit *split) {
|
||||
if (split == NULL) {
|
||||
return;
|
||||
}
|
||||
Rect2I rect = split->resizer_rect;
|
||||
DrawRect(split->resizer_rect, ColorResizerBackground);
|
||||
if (split->kind == WindowSplitKind_Vertical) {
|
||||
Rect2I s = CutRight(&rect, 1);
|
||||
DrawRect(s, ColorResizerOutline);
|
||||
} else if (split->kind == WindowSplitKind_Horizontal) {
|
||||
Rect2I s = CutBottom(&rect, 1);
|
||||
DrawRect(s, ColorResizerOutline);
|
||||
}
|
||||
|
||||
DrawSplits(split->left);
|
||||
DrawSplits(split->right);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user