Big refactor new layout

This commit is contained in:
Krzosa Karol
2025-12-06 19:12:06 +01:00
parent e6e1ae0223
commit 88a5adaa0a
12 changed files with 182 additions and 737 deletions

View File

@@ -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.

View File

@@ -398,6 +398,6 @@ void ReloadFont() {
Scratch scratch; Scratch scratch;
Atlas atlas = CreateAtlas(scratch, {2048, 2048}); Atlas atlas = CreateAtlas(scratch, {2048, 2048});
PrimaryFont = CreateFont(&atlas, (uint32_t)ClampBottom(2u, (U32)StyleFontSize), StyleFont); 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); SecondaryFont.texture_id = PrimaryFont.texture_id = UploadAtlas(&atlas);
} }

View File

@@ -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 = "") { void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
CheckpointBeforeGoto(set->window);
if (buffer_name.len == 0) { if (buffer_name.len == 0) {
String current_dir = ChopLastSlash(set->buffer->name); String current_dir = ChopLastSlash(set->buffer->name);
buffer_name = GetUniqueBufferName(current_dir, "temp"); 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) { void Command_BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
CheckpointBeforeGoto(set->window);
set->buffer = GetBuffer(buffer_id); set->buffer = GetBuffer(buffer_id);
set->view = WindowOpenBufferView(set->window, set->buffer->name); 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)); 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) { void Command_FuzzySort(View *view, String16 needle) {
Buffer *buffer = GetBuffer(view->active_buffer); 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); Command_Appendf(set.view, "%S\n", it.filename);
} }
} else { } else {
CheckpointBeforeGoto(set.window);
View *view = WindowOpenBufferView(set.window, ores.file_path); View *view = WindowOpenBufferView(set.window, ores.file_path);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
if (ores.line != -1) { if (ores.line != -1) {
@@ -1204,8 +1122,6 @@ int Lua_Cmd(lua_State *L) {
BSet main = GetActiveMainSet(); BSet main = GetActiveMainSet();
if (kind == "console") { if (kind == "console") {
BSet set = GetConsoleSet(); 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_SelectRangeOneCursor(set.view, MakeRange(set.buffer->len));
Command_BeginJump(&set); Command_BeginJump(&set);
Exec(set.view->id, true, cmd, working_dir); Exec(set.view->id, true, cmd, working_dir);
@@ -1217,8 +1133,6 @@ int Lua_Cmd(lua_State *L) {
ActiveWindow = main.window->id; ActiveWindow = main.window->id;
} else { } else {
JumpGarbageBuffer(&main); JumpGarbageBuffer(&main);
main.window->active_goto_list = main.view->id;
main.window->goto_list_pos = 0;
Exec(main.view->id, true, cmd, working_dir); Exec(main.view->id, true, cmd, working_dir);
ActiveWindow = main.window->id; ActiveWindow = main.window->id;
} }
@@ -1366,20 +1280,6 @@ Window *SwitchWindow(int direction) {
return result; 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) { String16 FetchLoadWord(void) {
BSet active = GetActiveSet(); BSet active = GetActiveSet();
Caret caret = active.view->carets[0]; Caret caret = active.view->carets[0];
@@ -1388,24 +1288,3 @@ String16 FetchLoadWord(void) {
String16 string = GetString(active.buffer, range); String16 string = GetString(active.buffer, range);
return string; 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;
}

View File

@@ -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) { void OnCommand(Event event) {
ProfileFunction(); ProfileFunction();
// //
@@ -134,26 +117,33 @@ void OnCommand(Event event) {
Int p = ScreenSpaceToBufferPos(selected.window, selected.view, selected.buffer, mouse); Int p = ScreenSpaceToBufferPos(selected.window, selected.view, selected.buffer, mouse);
Caret &caret = selected.view->carets[0]; Caret &caret = selected.view->carets[0];
caret = SetFrontWithAnchor(caret, DocumentAnchor, p); caret = SetFrontWithAnchor(caret, DocumentAnchor, p);
} }
if (ResizerSelected && Mouse(LEFT_UP)) { if (ResizerSelected.id != -1 && Mouse(LEFT_UP)) {
Assert(DocumentSelected.id == -1); Assert(DocumentSelected.id == -1);
Assert(ScrollbarSelected.id == -1); Assert(ScrollbarSelected.id == -1);
ResizerSelected = NULL; ResizerSelected.id = {-1};
} else if (ResizerSelected) { } else if (ResizerSelected.id != -1) {
Vec2I mouse = MouseVec2I(); Window *window = GetWindow(ResizerSelected);
mouse -= ResizerSelected->total_rect.min; if (window->layout) {
Vec2I size = GetSize(ResizerSelected->total_rect); Vec2I mouse = MouseVec2I();
Vec2 p = ToVec2(mouse) / ToVec2(size); Int offx = mouse.x - window->resizer_rect.min.x;
if (ResizerSelected->kind == WindowSplitKind_Vertical) { window->weight += (double)offx / (double)WindowCalcEvenResizerValue(event.xwindow);
ResizerSelected->value = p.x; window->weight = Clamp(window->weight, 0.1, 100.0);
} else {
ResizerSelected->value = p.y;
} }
} else { } 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 // 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)) { if (Ctrl() && Shift() && Mouse(RIGHT)) {
} else if (Alt() && Ctrl() && 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_document = AreOverlapping(mouse, active.window->document_rect);
bool mouse_in_line_numbers = AreOverlapping(mouse, active.window->line_numbers_rect); bool mouse_in_line_numbers = AreOverlapping(mouse, active.window->line_numbers_rect);
if (mouse_in_document || mouse_in_line_numbers) { if (mouse_in_document || mouse_in_line_numbers) {
CheckpointBeforeGoto(active.window);
DocumentSelected = active.window->id; DocumentSelected = active.window->id;
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse); Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
@@ -295,12 +277,6 @@ void OnCommand(Event event) {
Command_ListCode(); Command_ListCode();
} }
if (CtrlShiftPress(SDLK_BACKSLASH)) {
SplitWindow(WindowSplitKind_Horizontal);
} else if (CtrlPress(SDLK_BACKSLASH)) {
SplitWindow(WindowSplitKind_Vertical);
}
if (CtrlPress(SDLK_0)) { if (CtrlPress(SDLK_0)) {
ToggleVisibility(DebugWindowID); ToggleVisibility(DebugWindowID);
} }
@@ -309,11 +285,6 @@ void OnCommand(Event event) {
if (ActiveWindow != NullWindowID) { if (ActiveWindow != NullWindowID) {
ActiveWindow = NullWindowID; ActiveWindow = NullWindowID;
} else { } else {
if (WindowSplits.value + 0.01 < 0.9) {
WindowSplits.value = (double)0.9;
} else {
WindowSplits.value = (double)0.6;
}
} }
} }
if (CtrlPress(SDLK_1)) { if (CtrlPress(SDLK_1)) {
@@ -462,11 +433,9 @@ void OnCommand(Event event) {
} }
if (CtrlShiftPress(SDLK_TAB)) { if (CtrlShiftPress(SDLK_TAB)) {
GotoForward(main.window);
} else if (ShiftPress(SDLK_TAB)) { } else if (ShiftPress(SDLK_TAB)) {
Command_IndentSelectedLines(active.view, SHIFT_PRESS); Command_IndentSelectedLines(active.view, SHIFT_PRESS);
} else if (CtrlPress(SDLK_TAB)) { } else if (CtrlPress(SDLK_TAB)) {
GotoBackward(main.window);
} else if (Press(SDLK_TAB)) { } else if (Press(SDLK_TAB)) {
Command_IndentSelectedLines(active.view); Command_IndentSelectedLines(active.view);
} }
@@ -508,22 +477,6 @@ void OnCommand(Event event) {
MergeCarets(active.buffer, &active.view->carets); 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)) { if (CtrlPress(SDLK_EQUALS)) {
StyleFontSize += 1; StyleFontSize += 1;
ReloadFont(); ReloadFont();
@@ -536,24 +489,7 @@ void OnCommand(Event event) {
} }
if (CtrlPress(SDLK_E)) { if (CtrlPress(SDLK_E)) {
Command_GotoNextInList(active.window, 1);
} else if (AltPress(SDLK_E)) { } 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)) { if (CtrlShiftPress(SDLK_RETURN)) {
@@ -609,13 +545,7 @@ void OnCommand(Event event) {
Command_Open(name); Command_Open(name);
} }
if (CtrlPress(SDLK_T)) { if (CtrlShiftPress(SDLK_L)) {
ActiveWindow = GetWindow(active.window->title_bar_window)->id;
}
if (CtrlShiftPress(SDLK_L)) {
EncloseSpace(active.view); EncloseSpace(active.view);
} else if (CtrlPress(SDLK_L)) { } else if (CtrlPress(SDLK_L)) {
EncloseLine(active.view); EncloseLine(active.view);
@@ -653,30 +583,14 @@ void OnCommand(Event event) {
Command_Open(FetchLoadWord()); 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 { } else {
Command_Open(FetchLoadWord()); Command_Open(FetchLoadWord());
} }
} }
if (Press(SDLK_ESCAPE)) { if (Press(SDLK_ESCAPE)) {
if (active.window->is_search_bar) { active.view->carets.len = 1;
ActiveWindow = main.window->id; active.view->carets[0] = MakeCaret(GetFront(active.view->carets[0]));
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 // :OnCommandEnding

View File

@@ -116,16 +116,6 @@ int Lua_GetMainDir(lua_State *L) {
return 1; 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) { int Lua_KillWindow(lua_State *L) {
BSet set = GetActiveMainSet(); BSet set = GetActiveMainSet();
set.window->kill = true; set.window->kill = true;
@@ -298,9 +288,6 @@ void ReloadLuaConfigs(bool reload = false) {
ReloadStyle(); ReloadStyle();
ReloadFont(); ReloadFont();
For(Windows) { For(Windows) {
if (it->is_title_bar || it->is_search_bar) {
continue;
}
it->draw_scrollbar = StyleDrawScrollbar; it->draw_scrollbar = StyleDrawScrollbar;
it->draw_line_numbers = StyleDrawLineNumbers; it->draw_line_numbers = StyleDrawLineNumbers;
} }

View File

@@ -14,7 +14,6 @@ luaL_Reg LuaFunctions[] = {
{"GetWorkDir", Lua_GetWorkDir}, {"GetWorkDir", Lua_GetWorkDir},
{"GetExeDir", Lua_GetExeDir}, {"GetExeDir", Lua_GetExeDir},
{"GetMainDir", Lua_GetMainDir}, {"GetMainDir", Lua_GetMainDir},
{"SplitSize", Lua_SplitSize},
{"KillWindow", Lua_KillWindow}, {"KillWindow", Lua_KillWindow},
{"Play", Lua_Play}, {"Play", Lua_Play},
{"TrimTrailingWhitespace", Lua_TrimTrailingWhitespace}, {"TrimTrailingWhitespace", Lua_TrimTrailingWhitespace},
@@ -37,6 +36,5 @@ luaL_Reg LuaFunctions[] = {
{"SetWorkDir", Lua_SetWorkDir}, {"SetWorkDir", Lua_SetWorkDir},
{"ListCommands", Lua_ListCommands}, {"ListCommands", Lua_ListCommands},
{"GetBufferList", Lua_GetBufferList}, {"GetBufferList", Lua_GetBufferList},
{"Split", Lua_Split},
{NULL, NULL}, {NULL, NULL},
}; };

View File

@@ -15,13 +15,13 @@ WindowID DebugWindowID;
ViewID DebugViewID; ViewID DebugViewID;
BufferID DebugBufferID; BufferID DebugBufferID;
WindowSplit WindowSplits; WindowID BarWindowID;
WindowID ActiveWindow;
WindowSplit *ResizerSelected = NULL; WindowID ActiveWindow;
WindowSplit *ResizerHover = NULL;
WindowID ScrollbarSelected = {-1}; WindowID ScrollbarSelected = {-1};
WindowID DocumentSelected = {-1}; WindowID DocumentSelected = {-1};
WindowID ResizerSelected = {-1};
WindowID ResizerHover = {-1};
Caret DocumentAnchor; Caret DocumentAnchor;
Buffer *LuaProjectBuffer; Buffer *LuaProjectBuffer;
@@ -143,56 +143,46 @@ Buffer *CreateBuffer(Allocator allocator, String name, Int size) {
return result; return result;
} }
Window *CreateWind(bool create_command_buffer = true) { Window *CreateWind() {
Allocator allocator = GetSystemAllocator(); Allocator allocator = GetSystemAllocator();
Window *w = AllocType(allocator, Window); Window *w = AllocType(allocator, Window);
w->font = &PrimaryFont; w->font = &PrimaryFont;
w->visible = true; w->visible = true;
w->layout = true;
w->draw_scrollbar = StyleDrawScrollbar; w->draw_scrollbar = StyleDrawScrollbar;
w->draw_line_numbers = StyleDrawLineNumbers; w->draw_line_numbers = StyleDrawLineNumbers;
w->id = AllocWindowID(w); w->id = AllocWindowID(w);
w->weight = 1.0;
Add(&Windows, w); Add(&Windows, w);
return w; return w;
} }
void DestroyWindow(Window *window) { void DestroyWindow(Window *window) {
Allocator allocator = GetSystemAllocator(); // Allocator allocator = GetSystemAllocator();
window->kill = true; // window->kill = true;
WindowSplit *split = window->split_ref; // Window *split = window;
if (split && split->parent) { // if (split && split->parent) {
Assert(split->kind == WindowSplitKind_Window); // Assert(split->kind == WindowSplitKind_Window);
WindowSplit *p = split->parent; // WindowSplit *p = split->parent;
WindowSplit *pp = p->parent; // WindowSplit *pp = p->parent;
WindowSplit *other = p->left == split ? p->right : p->left; // WindowSplit *other = p->left == split ? p->right : p->left;
if (pp) { // if (pp) {
if (pp->left == p) { // if (pp->left == p) {
pp->left = other; // pp->left = other;
} else { // } else {
pp->right = other; // pp->right = other;
} // }
other->parent = pp; // other->parent = pp;
} // }
Dealloc(allocator, p); // Dealloc(allocator, p);
Dealloc(allocator, split); // Dealloc(allocator, split);
} // }
if (!window->is_search_bar && window->search_bar_window.id) { // Dealloc(allocator, window);
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);
} }
View *CreateView(BufferID active_buffer) { View *CreateView(BufferID active_buffer) {
@@ -262,13 +252,6 @@ View *FindView(String name, View *default_view = NULL) {
return default_view; 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 GetBSet(Window *window) {
BSet set = {window}; BSet set = {window};
set.view = GetView(set.window->active_view); set.view = GetView(set.window->active_view);
@@ -282,14 +265,7 @@ BSet GetBSet(WindowID window_id) {
return result; 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) { BSet GetMainSet(Window *window) {
if (window->is_title_bar) window = GetWindow(window->title_bar_window);
BSet result = GetBSet(window); BSet result = GetBSet(window);
return result; return result;
} }
@@ -301,8 +277,8 @@ BSet GetActiveSet() {
BSet GetActiveMainSet() { BSet GetActiveMainSet() {
Window *window = GetWindow(ActiveWindow); Window *window = GetWindow(ActiveWindow);
if (window->is_title_bar) window = GetWindow(window->title_bar_window); // 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_search_bar) window = GetWindow(window->search_bar_window);
return GetBSet(window); return GetBSet(window);
} }
@@ -314,12 +290,6 @@ BSet GetConsoleSet() {
return result; 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() { String Command_GetFilename() {
BSet set = GetActiveMainSet(); BSet set = GetActiveMainSet();
return set.buffer->name; return set.buffer->name;
@@ -440,25 +410,13 @@ View *WindowOpenBufferView(Window *new_parent_window, String name) {
return result; 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) { bool ViewIsReferenced(ViewID view) {
if (view == NullViewID) { if (view == NullViewID) {
return true; return true;
} }
if (ViewIsCrumb(view)) {
return true;
}
For(Windows) { For(Windows) {
if (it->active_view == view || it->active_goto_list == view) { if (it->active_view == view) {
return true; return true;
} }
} }

View File

@@ -194,12 +194,21 @@ void SetMouseCursor(Event event) {
Array<Window *> order = GetWindowZOrder(scratch); Array<Window *> order = GetWindowZOrder(scratch);
Vec2I mouse = MouseVec2I(); Vec2I mouse = MouseVec2I();
if (ResizerSelected) { if (ResizerSelected.id != -1) {
WindowSplit *split = ResizerSelected; Window *window = GetWindow(ResizerSelected);
if (split->kind == WindowSplitKind_Vertical) { 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); SetMouseCursor(SDL_SYSTEM_CURSOR_EW_RESIZE);
} else { } else {
Assert(split->kind == WindowSplitKind_Horizontal);
SetMouseCursor(SDL_SYSTEM_CURSOR_NS_RESIZE); SetMouseCursor(SDL_SYSTEM_CURSOR_NS_RESIZE);
} }
return; 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); SetMouseCursor(SDL_SYSTEM_CURSOR_DEFAULT);
} }
@@ -246,9 +246,6 @@ void Update(Event event) {
} }
OnCommand(event); OnCommand(event);
For(Windows) {
if (it->is_title_bar) ReplaceTitleBarData(it);
}
UpdateProcesses(); UpdateProcesses();
CoUpdate(&event); CoUpdate(&event);
ReloadLuaConfigs(); ReloadLuaConfigs();
@@ -368,7 +365,6 @@ void MainLoop() {
SetMouseCursor(*event); SetMouseCursor(*event);
LayoutWindows(event->xwindow, event->ywindow); // This is here to render changes in title bar size without a frame of delay 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); BeginFrameRender(event->xwindow, event->ywindow);
DrawSplits(&WindowSplits);
Array<Window *> order = GetWindowZOrder(scratch); Array<Window *> order = GetWindowZOrder(scratch);
For(IterateInReverse(&order)) { For(IterateInReverse(&order)) {

View File

@@ -16,69 +16,39 @@ struct View {
String16 prev_search_line; String16 prev_search_line;
}; };
struct GotoCrumb { enum WindowKind {
ViewID view_id; WindowKind_None,
Caret caret; WindowKind_Root,
WindowKind_Leaf,
WindowKind_SplitHori,
WindowKind_SplitVerti,
}; };
struct Window { struct Window {
WindowID id; WindowID id;
ViewID active_view; 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 total_rect;
Rect2I document_rect; Rect2I document_rect;
Rect2I scrollbar_rect; Rect2I scrollbar_rect;
Rect2I line_numbers_rect; Rect2I line_numbers_rect;
Rect2I resizer_rect;
Array<GotoCrumb> goto_history;
Array<GotoCrumb> goto_redo;
ViewID active_goto_list;
Int goto_list_pos;
Font *font; Font *font;
Caret search_bar_anchor;
double mouse_scroller_offset; double mouse_scroller_offset;
int z; int z;
double weight;
Int offset_resizer;
struct { struct {
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 layout : 1;
bool is_title_bar : 1;
bool is_search_bar : 1;
bool deactivate_on_escape : 1;
bool kill : 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 { struct Scroller {
Rect2 rect; Rect2 rect;
double begin; double begin;
@@ -120,7 +90,7 @@ void Command_Eval(String16 string);
String Command_GetMainDir(); String Command_GetMainDir();
void ReportDebugf(const char *fmt, ...); void ReportDebugf(const char *fmt, ...);
void ReplaceWithoutMovingCarets(Buffer *buffer, Range range, String16 string); void ReplaceWithoutMovingCarets(Buffer *buffer, Range range, String16 string);
void Command_Copy(View *view); void Command_Copy(View *view);
void Command_Paste(View *view); void Command_Paste(View *view);

View File

@@ -40,92 +40,3 @@ void UpdateDebugBuffer() {
RawAppendf(buffer, "int changed_on_disk = %d\n", main.buffer->changed_on_disk); RawAppendf(buffer, "int changed_on_disk = %d\n", main.buffer->changed_on_disk);
RawAppendf(buffer, "int garbage = %d\n", main.buffer->garbage); 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);
}
}

View File

@@ -6,102 +6,9 @@ Array<Window *> GetWindowZOrder(Allocator allocator) {
return order; 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) { void SetVisibility(WindowID window_id, bool v) {
Window *window = GetWindow(window_id); Window *window = GetWindow(window_id);
window->visible = v; 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) { bool ToggleVisibility(WindowID window_id) {
@@ -111,78 +18,43 @@ bool ToggleVisibility(WindowID window_id) {
return visible; return visible;
} }
void LoadBigText(Buffer *buffer, int size = 5000000) { Int GetTitleBarSize(Window *window) {
for (int i = 0; i < size; i += 1) { View *view = GetView(window->active_view);
RawReplaceText(buffer, GetBufferEndAsRange(buffer), u"Line number or something of the sort which is here or there or maybe somewhere else\n"); Buffer *buffer = GetBuffer(view->active_buffer);
} float result = (float)buffer->line_starts.len * window->font->line_spacing;
} return (Int)result;
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));
} }
void InitWindows() { void InitWindows() {
WindowSplit *split = &WindowSplits; Scratch scratch;
split->kind = WindowSplitKind_Horizontal;
split->value = (double)0.9;
{ {
Window *window = CreateWind(); Window *window = CreateWind();
window->active_view = NullViewID; window->active_view = CreateView(ScratchBuffer->id)->id;
Assert(window->id.id == 0); window->weight = 1.0;
CreateTitlebar(window->id); {
CreateSearchBar(window->id); Window *window = CreateWind();
window->active_view = TraceView->id;
split->right = CreateSplitForWindow(split, window); CreateWind();
CreateWind();
}
} }
// BAR at the bottom
{ {
Window *window = CreateWind(); Window *window = CreateWind();
Buffer *buffer = ScratchBuffer; BarWindowID = window->id;
View *view = CreateView(buffer->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; window->active_view = view->id;
CreateTitlebar(window->id);
CreateSearchBar(window->id);
ActiveWindow = window->id;
split->left = CreateSplitForWindow(split, window);
} }
// DEBUG WINDOW
{ {
Window *window = CreateWind(); Window *window = CreateWind();
DebugWindowID = window->id; DebugWindowID = window->id;
@@ -190,6 +62,7 @@ void InitWindows() {
window->draw_scrollbar = false; window->draw_scrollbar = false;
window->visible = false; window->visible = false;
window->z = 2; window->z = 2;
window->layout = false;
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug")); Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug"));
DebugBufferID = buffer->id; DebugBufferID = buffer->id;
@@ -199,86 +72,73 @@ void InitWindows() {
DebugViewID = view->id; DebugViewID = view->id;
window->active_view = 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); SetVisibility(window->id, false);
} }
} }
void LayoutWindowSplit(WindowSplit *split, Rect2I rect) { void CalcNiceties(Window *n) {
float scrollbar_size = (10.f * DPIScale); 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) { double WindowCalcEvenResizerValue(Int screen_size_x, Int *out_count = NULL) {
Window *it = split->window; double w = 0;
float line_numbers_size = (float)it->font->char_spacing * 10; Int c = 0;
Assert(it->split_ref); ForItem(n, Windows) {
it->total_rect = rect; if (n->layout) {
w += n->weight;
Window *title_bar_window = GetWindow(it->title_bar_window); c += 1;
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");
} }
if (out_count) *out_count = c;
return (double)screen_size_x / w;
} }
void LayoutWindows(int16_t wx, int16_t wy) { void LayoutWindows(int16_t wx, int16_t wy) {
Rect2I screen_rect = RectI0Size(wx, 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); Rect2 screen_rect = Rect0Size(wx, wy);
Vec2 size = GetSize(screen_rect); Vec2 size = GetSize(screen_rect);
Rect2 a = CutLeft(&screen_rect, 0.3f * size.x); Rect2 a = CutLeft(&screen_rect, 0.3f * size.x);
Rect2 b = CutBottom(&a, 0.4f * size.y); Rect2 b = CutBottom(&a, 0.4f * size.y);
Rect2 c = Shrink(b, 20); Rect2 c = Shrink(b, 20);
n->document_rect = n->total_rect = ToRect2I(c);
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;
} }
// 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;
}
}
} }

View File

@@ -105,7 +105,6 @@ void DrawWindow(Window *window, Event &event) {
Rect2 screen_rect = Rect0Size(event.xwindow, event.ywindow); Rect2 screen_rect = Rect0Size(event.xwindow, event.ywindow);
SetScissor(screen_rect); 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; bool is_active = window->id == ActiveWindow;
Color color_whitespace_during_selection = ColorWhitespaceDuringSelection; Color color_whitespace_during_selection = ColorWhitespaceDuringSelection;
@@ -116,17 +115,6 @@ void DrawWindow(Window *window, Event &event) {
Color color_sub_caret = ColorSubCaret; Color color_sub_caret = ColorSubCaret;
Color color_text_line_numbers = ColorTextLineNumbers; Color color_text_line_numbers = ColorTextLineNumbers;
Color color_text = ColorText; 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); DrawRect(window->total_rect, color_background);
Rect2I combined_document_line_number = window->document_rect; 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,14 +203,12 @@ void DrawWindow(Window *window, Event &event) {
DrawVisibleText(window, color_text); DrawVisibleText(window, color_text);
BeginProfileScope(draw_carets); BeginProfileScope(draw_carets);
if (is_actib) { For(view->carets) {
For(view->carets) { Int front = GetFront(it);
Int front = GetFront(it); XY fxy = PosToXY(buffer, front);
XY fxy = PosToXY(buffer, front); if (fxy.col >= visible.min.x && fxy.col < visible.max.x && fxy.line >= visible.min.y && fxy.line <= visible.max.y) {
if (fxy.col >= visible.min.x && fxy.col < visible.max.x && fxy.line >= visible.min.y && fxy.line <= visible.max.y) { bool main_caret = &it == &view->carets.data[0];
bool main_caret = &it == &view->carets.data[0]; DrawCaret(window, fxy, 0.3f, main_caret ? color_main_caret : color_sub_caret);
DrawCaret(window, fxy, 0.3f, main_caret ? color_main_caret : color_sub_caret);
}
} }
} }
EndProfileScope(); EndProfileScope();
@@ -276,26 +250,14 @@ void DrawWindow(Window *window, Event &event) {
DrawRect(window->total_rect, {255, 255, 255, 25}); DrawRect(window->total_rect, {255, 255, 255, 25});
} }
if (!is_actib) {
SetScissor(screen_rect);
DrawRect(window->total_rect, ColorInactiveWindow); 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);
}