Bring back status bar with new design, fixing bugs

This commit is contained in:
Krzosa Karol
2025-12-07 10:40:30 +01:00
parent 88a5adaa0a
commit df84d1605d
12 changed files with 227 additions and 124 deletions

View File

@@ -323,10 +323,6 @@ function MatchGotoBuild(s, meta)
end end
function MatchExec(s, meta) function MatchExec(s, meta)
if meta ~= "exec" then
return nil
end
if s:match(".exe$") or s:match(".bat$") or s:match(".sh$") then if s:match(".exe$") or s:match(".bat$") or s:match(".sh$") then
return {kind = "exec_console", cmd = s, working_dir = GetMainDir()} return {kind = "exec_console", cmd = s, working_dir = GetMainDir()}
end end

View File

@@ -13,7 +13,6 @@ Needs to change:
- How to design Command view? - How to design Command view?
- How to design popup view (input field)? - How to design popup view (input field)?
- How to design search view? or search and replace view? - How to design search view? or search and replace view?
- Window management, splitting, GC
Things I like: Things I like:
- Basic editing - Basic editing

View File

@@ -642,7 +642,7 @@ void SaveBuffer(Buffer *buffer) {
} }
} }
void Command_Save() { void Command_Save() {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
SaveBuffer(set.buffer); SaveBuffer(set.buffer);
} }
int Lua_Save(lua_State *L) { int Lua_Save(lua_State *L) {
@@ -889,7 +889,7 @@ void ReopenBuffer(Buffer *buffer) {
} }
void Command_Reopen() { void Command_Reopen() {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
ReopenBuffer(set.buffer); ReopenBuffer(set.buffer);
ActiveWindow = set.window->id; ActiveWindow = set.window->id;
} }
@@ -917,7 +917,7 @@ void New(Window *window, String name = "") {
} }
void Command_New(String name = "") { void Command_New(String name = "") {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
New(main.window, name); New(main.window, name);
} }
@@ -950,7 +950,7 @@ void NewDir(Window *window, String name = "") {
int Lua_NewDir(lua_State *L) { int Lua_NewDir(lua_State *L) {
String name = lua_tostring(L, 1); String name = lua_tostring(L, 1);
lua_pop(L, 1); lua_pop(L, 1);
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
NewDir(main.window, name); NewDir(main.window, name);
return 0; return 0;
} }
@@ -996,7 +996,7 @@ void ListFilesRecursive(Buffer *buffer, String dir) {
} }
void Command_ListCode(String dir = WorkDir) { void Command_ListCode(String dir = WorkDir) {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
JumpGarbageBuffer(&main); JumpGarbageBuffer(&main);
ListFilesRecursive(main.buffer, dir); ListFilesRecursive(main.buffer, dir);
main.view->fuzzy_search = true; main.view->fuzzy_search = true;
@@ -1021,7 +1021,7 @@ View *Command_ExecHidden(String buffer_name, String cmd, String working_dir) {
} }
BSet Command_Exec(String cmd, String working_dir, bool set_active = true) { BSet Command_Exec(String cmd, String working_dir, bool set_active = true) {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
if (set_active) ActiveWindow = set.window->id; if (set_active) ActiveWindow = set.window->id;
JumpGarbageBuffer(&set); JumpGarbageBuffer(&set);
Exec(set.view->id, true, cmd, working_dir); Exec(set.view->id, true, cmd, working_dir);
@@ -1080,7 +1080,7 @@ BSet Command_Open(Window *window, String path, String meta, bool set_active = tr
} }
BSet Command_Open(String path, String meta) { BSet Command_Open(String path, String meta) {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
main = Command_Open(main.window, path, meta); main = Command_Open(main.window, path, meta);
return main; return main;
} }
@@ -1119,7 +1119,7 @@ int Lua_Cmd(lua_State *L) {
String kind = lua_tostring(L, -1); String kind = lua_tostring(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
if (kind == "console") { if (kind == "console") {
BSet set = GetConsoleSet(); BSet set = GetConsoleSet();
Command_SelectRangeOneCursor(set.view, MakeRange(set.buffer->len)); Command_SelectRangeOneCursor(set.view, MakeRange(set.buffer->len));
@@ -1141,7 +1141,7 @@ int Lua_Cmd(lua_State *L) {
} }
void Command_ListBuffers() { void Command_ListBuffers() {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
ActiveWindow = main.window->id; ActiveWindow = main.window->id;
JumpGarbageBuffer(&main); JumpGarbageBuffer(&main);
For(Buffers) { For(Buffers) {
@@ -1158,7 +1158,7 @@ int Lua_ListBuffers(lua_State *L) {
} }
void Command_ListViews() { void Command_ListViews() {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
ActiveWindow = main.window->id; ActiveWindow = main.window->id;
JumpGarbageBuffer(&main); JumpGarbageBuffer(&main);
For(Views) { For(Views) {
@@ -1200,7 +1200,7 @@ void SetProjectFile(Buffer *buffer) {
} }
int Lua_SetProjectFile(lua_State *L) { int Lua_SetProjectFile(lua_State *L) {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
SetProjectFile(set.buffer); SetProjectFile(set.buffer);
return 0; return 0;
} }
@@ -1208,7 +1208,7 @@ int Lua_SetProjectFile(lua_State *L) {
int Lua_SetWorkDir(lua_State *L) { int Lua_SetWorkDir(lua_State *L) {
String dir = lua_tostring(L, -1); String dir = lua_tostring(L, -1);
if (dir.len == 0) { if (dir.len == 0) {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
WorkDir = ChopLastSlash(set.buffer->name); WorkDir = ChopLastSlash(set.buffer->name);
} else { } else {
WorkDir = dir; WorkDir = dir;
@@ -1217,7 +1217,7 @@ int Lua_SetWorkDir(lua_State *L) {
} }
int Lua_ListCommands(lua_State *L) { int Lua_ListCommands(lua_State *L) {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
Command_BeginJump(&main); Command_BeginJump(&main);
for (int i = 0; LuaFunctions[i].name != NULL; i += 1) { for (int i = 0; LuaFunctions[i].name != NULL; i += 1) {
Command_Appendf(main.view, "%20s() ", LuaFunctions[i].name); Command_Appendf(main.view, "%20s() ", LuaFunctions[i].name);

View File

@@ -266,7 +266,7 @@ void OnCommand(Event event) {
} }
if (CtrlPress(SDLK_W)) { if (CtrlPress(SDLK_W)) {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
main.window->kill = true; main.window->kill = true;
} }
@@ -308,7 +308,7 @@ void OnCommand(Event event) {
} }
} }
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
BSet active = GetActiveSet(); BSet active = GetActiveSet();
Int buffer_change_id = active.buffer->change_id; Int buffer_change_id = active.buffer->change_id;
@@ -529,6 +529,11 @@ void OnCommand(Event event) {
} }
} }
if (CtrlPress(SDLK_F)) {
Window *window = GetWindow(SearchBarWindowID);
window->visible = !window->visible;
}
// if (CtrlPress(SDLK_N)) { // if (CtrlPress(SDLK_N)) {
// Command_New(); // Command_New();
// } // }

View File

@@ -324,10 +324,6 @@ function MatchGotoBuild(s, meta)
end end
function MatchExec(s, meta) function MatchExec(s, meta)
if meta ~= "exec" then
return nil
end
if s:match(".exe$") or s:match(".bat$") or s:match(".sh$") then if s:match(".exe$") or s:match(".bat$") or s:match(".sh$") then
return {kind = "exec_console", cmd = s, working_dir = GetMainDir()} return {kind = "exec_console", cmd = s, working_dir = GetMainDir()}
end end

View File

@@ -24,7 +24,7 @@ int Lua_Print(lua_State *L) {
} }
int Lua_Kill(lua_State *L) { int Lua_Kill(lua_State *L) {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
KillProcess(main.view); KillProcess(main.view);
return 0; return 0;
} }
@@ -52,7 +52,7 @@ int Lua_BufferExists(lua_State *L) {
int Lua_GetSelection(lua_State *L) { int Lua_GetSelection(lua_State *L) {
Scratch scratch; Scratch scratch;
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
String16 string16 = GetString(main.buffer, main.view->carets[0].range); String16 string16 = GetString(main.buffer, main.view->carets[0].range);
String string = ToString(scratch, string16); String string = ToString(scratch, string16);
lua_pushlstring(L, string.data, string.len); lua_pushlstring(L, string.data, string.len);
@@ -61,7 +61,7 @@ int Lua_GetSelection(lua_State *L) {
int Lua_GetEntireBuffer(lua_State *L) { int Lua_GetEntireBuffer(lua_State *L) {
Scratch scratch; Scratch scratch;
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
String16 string16 = GetString(main.buffer); String16 string16 = GetString(main.buffer);
String string = ToString(scratch, string16); String string = ToString(scratch, string16);
lua_pushlstring(L, string.data, string.len); lua_pushlstring(L, string.data, string.len);
@@ -76,13 +76,13 @@ int Lua_GetClipboard(lua_State *L) {
} }
int Lua_GetFilename(lua_State *L) { int Lua_GetFilename(lua_State *L) {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
lua_pushlstring(L, main.buffer->name.data, main.buffer->name.len); lua_pushlstring(L, main.buffer->name.data, main.buffer->name.len);
return 1; return 1;
} }
int Lua_GetLine(lua_State *L) { int Lua_GetLine(lua_State *L) {
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
Caret caret = main.view->carets[0]; Caret caret = main.view->carets[0];
Int front = GetFront(caret); Int front = GetFront(caret);
Int line = PosToLine(main.buffer, front); Int line = PosToLine(main.buffer, front);
@@ -117,7 +117,7 @@ int Lua_GetMainDir(lua_State *L) {
} }
int Lua_KillWindow(lua_State *L) { int Lua_KillWindow(lua_State *L) {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
set.window->kill = true; set.window->kill = true;
return 0; return 0;
} }

View File

@@ -15,9 +15,13 @@ WindowID DebugWindowID;
ViewID DebugViewID; ViewID DebugViewID;
BufferID DebugBufferID; BufferID DebugBufferID;
WindowID BarWindowID; WindowID StatusBarWindowID;
WindowID SearchBarWindowID;
ViewID SearchViewID;
BufferID SearchBufferID;
WindowID ActiveWindow; WindowID ActiveWindow;
WindowID LastActiveLayoutWindowID;
WindowID ScrollbarSelected = {-1}; WindowID ScrollbarSelected = {-1};
WindowID DocumentSelected = {-1}; WindowID DocumentSelected = {-1};
WindowID ResizerSelected = {-1}; WindowID ResizerSelected = {-1};
@@ -151,40 +155,13 @@ Window *CreateWind() {
w->layout = true; w->layout = true;
w->draw_scrollbar = StyleDrawScrollbar; w->draw_scrollbar = StyleDrawScrollbar;
w->draw_line_numbers = StyleDrawLineNumbers; w->draw_line_numbers = StyleDrawLineNumbers;
w->draw_line_highlight = true;
w->id = AllocWindowID(w); w->id = AllocWindowID(w);
w->weight = 1.0; w->weight = 1.0;
Add(&Windows, w); Add(&Windows, w);
return w; return w;
} }
void DestroyWindow(Window *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;
// if (pp) {
// if (pp->left == p) {
// pp->left = other;
// } else {
// pp->right = other;
// }
// other->parent = pp;
// }
// Dealloc(allocator, p);
// Dealloc(allocator, split);
// }
// Dealloc(allocator, window);
}
View *CreateView(BufferID active_buffer) { View *CreateView(BufferID active_buffer) {
Allocator al = GetSystemAllocator(); Allocator al = GetSystemAllocator();
View *view = AllocType(al, View); View *view = AllocType(al, View);
@@ -265,21 +242,13 @@ BSet GetBSet(WindowID window_id) {
return result; return result;
} }
BSet GetMainSet(Window *window) {
BSet result = GetBSet(window);
return result;
}
BSet GetActiveSet() { BSet GetActiveSet() {
Window *window = GetWindow(ActiveWindow); Window *window = GetWindow(ActiveWindow);
return GetBSet(window); return GetBSet(window);
} }
BSet GetActiveMainSet() { BSet GetLastActiveLayoutSet() {
Window *window = GetWindow(ActiveWindow); return GetBSet(LastActiveLayoutWindowID);
// 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);
} }
BSet GetConsoleSet() { BSet GetConsoleSet() {
@@ -291,7 +260,7 @@ BSet GetConsoleSet() {
} }
String Command_GetFilename() { String Command_GetFilename() {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
return set.buffer->name; return set.buffer->name;
} }
@@ -301,7 +270,7 @@ String GetDir(Buffer *buffer) {
} }
String Command_GetMainDir() { String Command_GetMainDir() {
BSet set = GetActiveMainSet(); BSet set = GetLastActiveLayoutSet();
String name = ChopLastSlash(set.buffer->name); String name = ChopLastSlash(set.buffer->name);
return name; return name;
} }
@@ -437,6 +406,14 @@ bool BufferIsReferenced(BufferID buffer_id) {
void GarbageCollect() { void GarbageCollect() {
Allocator sys_allocator = GetSystemAllocator(); Allocator sys_allocator = GetSystemAllocator();
if (ActiveWindow.id != LastActiveLayoutWindowID.id) {
Window *window = GetWindow(ActiveWindow);
if (window->layout) {
LastActiveLayoutWindowID = ActiveWindow;
}
}
For(Buffers) { For(Buffers) {
if (it->file_mod_time) { if (it->file_mod_time) {
int64_t new_file_mod_time = GetFileModTime(it->name); int64_t new_file_mod_time = GetFileModTime(it->name);
@@ -484,8 +461,8 @@ void GarbageCollect() {
IterRemove(Windows) { IterRemove(Windows) {
IterRemovePrepare(Windows); IterRemovePrepare(Windows);
if (it->kill) { if (it->kill) {
DestroyWindow(it); Dealloc(sys_allocator, it);
remove_item = true; remove_item = true;
} }
} }
} }

View File

@@ -249,8 +249,9 @@ void Update(Event event) {
UpdateProcesses(); UpdateProcesses();
CoUpdate(&event); CoUpdate(&event);
ReloadLuaConfigs(); ReloadLuaConfigs();
CallLuaOnUpdate(&event); StatusBarUpdate();
UpdateDebugBuffer(); UpdateDebugBuffer();
CallLuaOnUpdate(&event);
GarbageCollect(); GarbageCollect();
For(IterateInReverse(&order)) { For(IterateInReverse(&order)) {

View File

@@ -16,14 +16,6 @@ struct View {
String16 prev_search_line; String16 prev_search_line;
}; };
enum WindowKind {
WindowKind_None,
WindowKind_Root,
WindowKind_Leaf,
WindowKind_SplitHori,
WindowKind_SplitVerti,
};
struct Window { struct Window {
WindowID id; WindowID id;
ViewID active_view; ViewID active_view;
@@ -34,15 +26,17 @@ struct Window {
Rect2I line_numbers_rect; Rect2I line_numbers_rect;
Rect2I resizer_rect; Rect2I resizer_rect;
Font *font; Font *font;
double mouse_scroller_offset; double mouse_scroller_offset;
int z; int z;
double weight; double weight;
Int offset_resizer; Int status_bar_last_buffer_change_id;
struct { struct {
bool draw_scrollbar : 1; bool draw_scrollbar : 1;
bool draw_line_numbers : 1; bool draw_line_numbers : 1;
bool draw_darker : 1;
bool draw_line_highlight : 1;
bool visible : 1; bool visible : 1;
bool layout : 1; bool layout : 1;
bool kill : 1; bool kill : 1;

View File

@@ -5,7 +5,7 @@ void UpdateDebugBuffer() {
View *view = GetView(window->active_view); View *view = GetView(window->active_view);
if (view->active_buffer.id == buffer->id.id) return; if (view->active_buffer.id == buffer->id.id) return;
BSet main = GetActiveMainSet(); BSet main = GetLastActiveLayoutSet();
Scratch scratch; Scratch scratch;
String s = Format(scratch, "wid: %d\nvid: %d\nbid: %d\nframe: %lld\n", (int)main.window->id.id, (int)main.view->id.id, (int)main.buffer->id.id, (long long)FrameID); String s = Format(scratch, "wid: %d\nvid: %d\nbid: %d\nframe: %lld\n", (int)main.window->id.id, (int)main.view->id.id, (int)main.buffer->id.id, (long long)FrameID);
@@ -40,3 +40,74 @@ 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 StatusBarUpdate() {
Window *status_bar_window = GetWindow(StatusBarWindowID, NULL);
if (status_bar_window == NULL) {
return;
}
Scratch scratch;
BSet main = GetLastActiveLayoutSet();
BSet title = GetBSet(status_bar_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 (title.window->id == ActiveWindow) {
if (title.buffer->change_id == title.window->status_bar_last_buffer_change_id) {
return;
}
String16 buffer_name = GetString(title.buffer, replace_range);
buffer_name = Skip(buffer_name, 1);
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;
}
Int buffer_pos = XYToPos(main.buffer, {column, line});
Caret &caret = main.view->carets[0];
if (GetFront(caret) != buffer_pos) {
caret = MakeCaret(buffer_pos);
}
title.window->status_bar_last_buffer_change_id = title.buffer->change_id;
return;
}
Caret caret = main.view->carets[0];
XY xy = PosToXY(main.buffer, GetFront(caret));
// 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" |");
}
// 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 Kill()", 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));
}

View File

@@ -40,18 +40,37 @@ void InitWindows() {
} }
} }
// BAR at the bottom // SEARCH BAR
{ {
Window *window = CreateWind(); Window *window = CreateWind();
BarWindowID = window->id; SearchBarWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, "search_bar");
SearchBufferID = buffer->id;
View *view = CreateView(buffer->id);
SearchViewID = view->id;
window->active_view = view->id;
window->draw_line_numbers = false;
window->draw_scrollbar = false;
window->draw_darker = true;
window->draw_line_highlight = false;
window->layout = false;
window->visible = false;
}
// STATUS BAR at the bottom
{
Window *window = CreateWind();
StatusBarWindowID = window->id;
Buffer *buffer = CreateBuffer(SysAllocator, "status_bar");
View *view = CreateView(buffer->id);
window->active_view = view->id;
buffer->no_history = true;
window->font = &SecondaryFont; window->font = &SecondaryFont;
window->draw_line_numbers = false; window->draw_line_numbers = false;
window->draw_scrollbar = false; window->draw_scrollbar = false;
window->draw_line_highlight = false;
window->draw_darker = true;
window->layout = false; window->layout = false;
Buffer *buffer = CreateBuffer(SysAllocator, "bar");
buffer->no_history = true;
View *view = CreateView(buffer->id);
window->active_view = view->id;
} }
// DEBUG WINDOW // DEBUG WINDOW
@@ -101,11 +120,20 @@ void LayoutWindows(int16_t wx, int16_t wy) {
// bar at the bottom // bar at the bottom
{ {
Window *n = GetWindow(BarWindowID); Window *n = GetWindow(StatusBarWindowID);
Int barsize = GetTitleBarSize(n); Int barsize = GetTitleBarSize(n);
n->document_rect = n->total_rect = CutBottom(&screen_rect, barsize); n->document_rect = n->total_rect = CutBottom(&screen_rect, barsize);
} }
// search bar
{
Window *n = GetWindow(SearchBarWindowID);
if (n->visible) {
Int barsize = GetTitleBarSize(n);
n->document_rect = n->total_rect = CutBottom(&screen_rect, barsize);
}
}
// floating debug window // floating debug window
{ {
Window *n = GetWindow(DebugWindowID); Window *n = GetWindow(DebugWindowID);
@@ -119,26 +147,26 @@ void LayoutWindows(int16_t wx, int16_t wy) {
} }
// Column layout // Column layout
if (1) { Int c = 0;
Int c = 0; double size = WindowCalcEvenResizerValue(wx, &c);
double size = WindowCalcEvenResizerValue(wx, &c); if (c == 0) {
if (c == 0) { return;
return; }
int i = 0;
ForItem(n, Windows) {
if (!n->layout) {
continue;
} }
int i = 0; n->total_rect = n->document_rect = CutLeft(&screen_rect, (Int)(size * n->weight));
ForItem(n, Windows) { if (i != (c - 1)) {
if (!n->layout) { Int resizer_size = (Int)(PrimaryFont.char_spacing*0.5f);
continue; n->resizer_rect = CutRight(&n->document_rect, resizer_size);
} } else {
n->resizer_rect = {};
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;
} }
CalcNiceties(n);
i += 1;
} }
} }

View File

@@ -46,7 +46,7 @@ void DrawVisibleText(Window *window, Color tint) {
Rect2I visible = GetVisibleCells(window); Rect2I visible = GetVisibleCells(window);
for (Int line_index = visible.min.y; line_index < visible.max.y && line_index >= 0 && line_index < buffer->line_starts.len; line_index += 1) { for (Int line_index = visible.min.y; line_index < visible.max.y && line_index >= 0 && line_index < buffer->line_starts.len; line_index += 1) {
String16 line_string = GetLineString(buffer, line_index); String16 line_string = GetLineString(buffer, line_index);
Vec2I pos = Vec2I{visible.min.x, line_index} * (Int)window->font->line_spacing - view->scroll + window->document_rect.min; Vec2I pos = Vec2I{visible.min.x, line_index} * Vec2I{(Int)window->font->char_spacing, (Int)window->font->line_spacing} - view->scroll + window->document_rect.min;
float text_offset_x = 0; float text_offset_x = 0;
for (Int col_index = visible.min.x; col_index < visible.max.x && col_index >= 0 && col_index < line_string.len; col_index += 1) { for (Int col_index = visible.min.x; col_index < visible.max.x && col_index >= 0 && col_index < line_string.len; col_index += 1) {
@@ -106,6 +106,7 @@ void DrawWindow(Window *window, Event &event) {
SetScissor(screen_rect); SetScissor(screen_rect);
bool is_active = window->id == ActiveWindow; bool is_active = window->id == ActiveWindow;
bool active_layed_out_doc = window->id == LastActiveLayoutWindowID;
Color color_whitespace_during_selection = ColorWhitespaceDuringSelection; Color color_whitespace_during_selection = ColorWhitespaceDuringSelection;
Color color_background = ColorBackground; Color color_background = ColorBackground;
@@ -115,7 +116,24 @@ 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->draw_darker) {
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);
if (window->draw_darker) {
Rect2I rect = window->total_rect;
DrawRect(CutTop(&rect, 1), ColorResizerOutline);
}
Rect2I combined_document_line_number = window->document_rect; Rect2I combined_document_line_number = window->document_rect;
if (window->draw_line_numbers) combined_document_line_number.min.x = window->line_numbers_rect.min.x; if (window->draw_line_numbers) combined_document_line_number.min.x = window->line_numbers_rect.min.x;
@@ -170,6 +188,18 @@ void DrawWindow(Window *window, Event &event) {
} }
} }
} }
} else if (window->draw_line_highlight) {
//
// 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);
} }
} }
@@ -202,16 +232,19 @@ void DrawWindow(Window *window, Event &event) {
EndProfileScope(); EndProfileScope();
DrawVisibleText(window, color_text); DrawVisibleText(window, color_text);
BeginProfileScope(draw_carets); // Draw caret "|" markings
For(view->carets) { if (is_active) {
Int front = GetFront(it); BeginProfileScope(draw_carets);
XY fxy = PosToXY(buffer, front); For(view->carets) {
if (fxy.col >= visible.min.x && fxy.col < visible.max.x && fxy.line >= visible.min.y && fxy.line <= visible.max.y) { Int front = GetFront(it);
bool main_caret = &it == &view->carets.data[0]; XY fxy = PosToXY(buffer, front);
DrawCaret(window, fxy, 0.3f, main_caret ? color_main_caret : color_sub_caret); 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];
DrawCaret(window, fxy, 0.3f, main_caret ? color_main_caret : color_sub_caret);
}
} }
EndProfileScope();
} }
EndProfileScope();
// Draw line numbers // Draw line numbers
if (window->draw_line_numbers) { if (window->draw_line_numbers) {
@@ -245,15 +278,18 @@ void DrawWindow(Window *window, Event &event) {
DrawRect(rect, color); DrawRect(rect, color);
} }
if (window->z == 1) { // color the floating object to make it stand out
if (window->z >= 1) {
SetScissor(window->total_rect); SetScissor(window->total_rect);
DrawRect(window->total_rect, {255, 255, 255, 25}); DrawRect(window->total_rect, {255, 255, 255, 25});
} }
// darken the inactive windows
if (!is_active) {
SetScissor(screen_rect);
DrawRect(window->total_rect, ColorInactiveWindow);
}
SetScissor(screen_rect);
DrawRect(window->total_rect, ColorInactiveWindow);
// Draw resizer rect // Draw resizer rect
{ {
Rect2I rect = window->resizer_rect; Rect2I rect = window->resizer_rect;