Experimenting with tabs

This commit is contained in:
Krzosa Karol
2024-07-28 14:30:24 +02:00
parent 0c2683afaa
commit de7f084633
9 changed files with 153 additions and 16 deletions

View File

@@ -354,18 +354,25 @@ void GenerateConfig() {
gruvbox.add({"GruvboxFadedAqua" , "0x427b58ff"}); gruvbox.add({"GruvboxFadedAqua" , "0x427b58ff"});
gruvbox.add({"GruvboxFadedOrange" , "0xaf3a03ff"}); gruvbox.add({"GruvboxFadedOrange" , "0xaf3a03ff"});
gruvbox.add({"_InactiveWindowColor" , "0x0000000F"});
Array<Color> colors = {}; Array<Color> colors = {};
colors.add({"Text" , "GruvboxDark0Hard"}); colors.add({"Text" , "GruvboxDark0Hard"});
colors.add({"Background" , "GruvboxLight0Hard"}); colors.add({"Background" , "GruvboxLight0Hard"});
colors.add({"InactiveWindow" , "_InactiveWindowColor"});
colors.add({"TabText" , "GruvboxDark0Hard"});
colors.add({"TabBackground" , "GruvboxLight0Hard"});
colors.add({"TabBackgroundInactive" , "GruvboxLight2"});
colors.add({"TabSeparator" , "GruvboxLight2"});
colors.add({"TextLineNumbers" , "GruvboxDark4"}); colors.add({"TextLineNumbers" , "GruvboxDark4"});
colors.add({"ScrollbarBackground" , "GruvboxLight2"}); colors.add({"ScrollbarBackground" , "GruvboxLight2"});
colors.add({"ScrollbarScroller" , "GruvboxLight1"}); colors.add({"ScrollbarScroller" , "GruvboxLight1"});
colors.add({"ScrollbarScrollerSelected", "GruvboxLight0Hard"}); colors.add({"ScrollbarScrollerSelected", "GruvboxLight0Hard"});
colors.add({"LineHighlight" , "GruvboxLight1"}); colors.add({"LineHighlight" , "GruvboxLight0Soft"});
colors.add({"MainCaret" , "GruvboxDark0Hard"}); colors.add({"MainCaret" , "GruvboxDark0Hard"});
colors.add({"SubCaret" , "GruvboxGray245"}); colors.add({"SubCaret" , "GruvboxGray245"});
colors.add({"Selection" , "GruvboxLight1"}); colors.add({"Selection" , "GruvboxLight1"});
colors.add({"WhitespaceDuringSelection", "GruvboxLight2"}); colors.add({"WhitespaceDuringSelection", "GruvboxLight4"});
// clang-format on // clang-format on
{ {

View File

@@ -108,3 +108,45 @@ bool Seek(String16 string, String16 find, int64_t *index_out = NULL, SeekFlag fl
return result; return result;
} }
String16 ChopLastSlash(String16 s) {
String16 result = s;
Seek(s, L"/", &result.len, SeekFlag_MatchFindLast);
return result;
}
String16 ChopLastPeriod(String16 s) {
String16 result = s;
Seek(s, L".", &result.len, SeekFlag_MatchFindLast);
return result;
}
String16 SkipToLastSlash(String16 s) {
int64_t pos;
String16 result = s;
if (Seek(s, L"/", &pos, SeekFlag_MatchFindLast)) {
result = Skip(result, pos + 1);
}
return result;
}
String16 SkipToLastPeriod(String16 s) {
int64_t pos;
String16 result = s;
if (Seek(s, L".", &pos, SeekFlag_MatchFindLast)) {
result = Skip(result, pos + 1);
}
return result;
}
String16 CutPrefix(String16 *string, int64_t len) {
String16 result = GetPrefix(*string, len);
*string = Skip(*string, len);
return result;
}
String16 CutPostfix(String16 *string, int64_t len) {
String16 result = GetPostfix(*string, len);
*string = Chop(*string, len);
return result;
}

View File

@@ -355,6 +355,15 @@ void ReportErrorf(const char *fmt, ...) {
ReplaceText(buffer, {}, string16); ReplaceText(buffer, {}, string16);
} }
void ReportConsolef(const char *fmt, ...) {
Scratch scratch;
STRING_FORMAT(scratch, fmt, string);
String16 string16 = ToString16(scratch, string);
Buffer *buffer = GetBuffer("*console*");
ReplaceText(buffer, {}, string16);
ReplaceText(buffer, Rng(string16.len), L"\n");
}
void ReportWarningf(const char *fmt, ...) { void ReportWarningf(const char *fmt, ...) {
Scratch scratch; Scratch scratch;
STRING_FORMAT(scratch, fmt, string); STRING_FORMAT(scratch, fmt, string);

View File

@@ -35,17 +35,23 @@ Color GruvboxFadedBlue = {0x07, 0x66, 0x78, 0xff};
Color GruvboxFadedPurple = {0x8f, 0x3f, 0x71, 0xff}; Color GruvboxFadedPurple = {0x8f, 0x3f, 0x71, 0xff};
Color GruvboxFadedAqua = {0x42, 0x7b, 0x58, 0xff}; Color GruvboxFadedAqua = {0x42, 0x7b, 0x58, 0xff};
Color GruvboxFadedOrange = {0xaf, 0x3a, 0x03, 0xff}; Color GruvboxFadedOrange = {0xaf, 0x3a, 0x03, 0xff};
Color _InactiveWindowColor = {0x00, 0x00, 0x00, 0x0F};
Color ColorText = GruvboxDark0Hard; Color ColorText = GruvboxDark0Hard;
Color ColorBackground = GruvboxLight0Hard; Color ColorBackground = GruvboxLight0Hard;
Color ColorInactiveWindow = _InactiveWindowColor;
Color ColorTabText = GruvboxDark0Hard;
Color ColorTabBackground = GruvboxLight0Hard;
Color ColorTabBackgroundInactive = GruvboxLight2;
Color ColorTabSeparator = GruvboxLight2;
Color ColorTextLineNumbers = GruvboxDark4; Color ColorTextLineNumbers = GruvboxDark4;
Color ColorScrollbarBackground = GruvboxLight2; Color ColorScrollbarBackground = GruvboxLight2;
Color ColorScrollbarScroller = GruvboxLight1; Color ColorScrollbarScroller = GruvboxLight1;
Color ColorScrollbarScrollerSelected = GruvboxLight0Hard; Color ColorScrollbarScrollerSelected = GruvboxLight0Hard;
Color ColorLineHighlight = GruvboxLight1; Color ColorLineHighlight = GruvboxLight0Soft;
Color ColorMainCaret = GruvboxDark0Hard; Color ColorMainCaret = GruvboxDark0Hard;
Color ColorSubCaret = GruvboxGray245; Color ColorSubCaret = GruvboxGray245;
Color ColorSelection = GruvboxLight1; Color ColorSelection = GruvboxLight1;
Color ColorWhitespaceDuringSelection = GruvboxLight2; Color ColorWhitespaceDuringSelection = GruvboxLight4;
String BaseLuaConfig = R"==( String BaseLuaConfig = R"==(
local GruvboxDark0Hard = 0x1d2021ff local GruvboxDark0Hard = 0x1d2021ff
local GruvboxDark0 = 0x282828ff local GruvboxDark0 = 0x282828ff
@@ -84,18 +90,24 @@ local GruvboxFadedBlue = 0x076678ff
local GruvboxFadedPurple = 0x8f3f71ff local GruvboxFadedPurple = 0x8f3f71ff
local GruvboxFadedAqua = 0x427b58ff local GruvboxFadedAqua = 0x427b58ff
local GruvboxFadedOrange = 0xaf3a03ff local GruvboxFadedOrange = 0xaf3a03ff
local _InactiveWindowColor = 0x0000000F
Color = {} Color = {}
Color.Text = GruvboxDark0Hard Color.Text = GruvboxDark0Hard
Color.Background = GruvboxLight0Hard Color.Background = GruvboxLight0Hard
Color.InactiveWindow = _InactiveWindowColor
Color.TabText = GruvboxDark0Hard
Color.TabBackground = GruvboxLight0Hard
Color.TabBackgroundInactive = GruvboxLight2
Color.TabSeparator = GruvboxLight2
Color.TextLineNumbers = GruvboxDark4 Color.TextLineNumbers = GruvboxDark4
Color.ScrollbarBackground = GruvboxLight2 Color.ScrollbarBackground = GruvboxLight2
Color.ScrollbarScroller = GruvboxLight1 Color.ScrollbarScroller = GruvboxLight1
Color.ScrollbarScrollerSelected = GruvboxLight0Hard Color.ScrollbarScrollerSelected = GruvboxLight0Hard
Color.LineHighlight = GruvboxLight1 Color.LineHighlight = GruvboxLight0Soft
Color.MainCaret = GruvboxDark0Hard Color.MainCaret = GruvboxDark0Hard
Color.SubCaret = GruvboxGray245 Color.SubCaret = GruvboxGray245
Color.Selection = GruvboxLight1 Color.Selection = GruvboxLight1
Color.WhitespaceDuringSelection = GruvboxLight2 Color.WhitespaceDuringSelection = GruvboxLight4
-- @todo: should we rewrite linux paths to windows on windows and vice-versa? -- @todo: should we rewrite linux paths to windows on windows and vice-versa?
@@ -222,6 +234,11 @@ end
void ReloadColors() { void ReloadColors() {
ColorText = GetColor("Text", ColorText); ColorText = GetColor("Text", ColorText);
ColorBackground = GetColor("Background", ColorBackground); ColorBackground = GetColor("Background", ColorBackground);
ColorInactiveWindow = GetColor("InactiveWindow", ColorInactiveWindow);
ColorTabText = GetColor("TabText", ColorTabText);
ColorTabBackground = GetColor("TabBackground", ColorTabBackground);
ColorTabBackgroundInactive = GetColor("TabBackgroundInactive", ColorTabBackgroundInactive);
ColorTabSeparator = GetColor("TabSeparator", ColorTabSeparator);
ColorTextLineNumbers = GetColor("TextLineNumbers", ColorTextLineNumbers); ColorTextLineNumbers = GetColor("TextLineNumbers", ColorTextLineNumbers);
ColorScrollbarBackground = GetColor("ScrollbarBackground", ColorScrollbarBackground); ColorScrollbarBackground = GetColor("ScrollbarBackground", ColorScrollbarBackground);
ColorScrollbarScroller = GetColor("ScrollbarScroller", ColorScrollbarScroller); ColorScrollbarScroller = GetColor("ScrollbarScroller", ColorScrollbarScroller);

View File

@@ -168,6 +168,11 @@ int main()
SDL_StartTextInput(window); SDL_StartTextInput(window);
SDL_GL_SetSwapInterval(1); // vsync SDL_GL_SetSwapInterval(1); // vsync
{
float scale = SDL_GetWindowDisplayScale(window);
if (scale != 1.0f) DPIScale = scale;
}
InitRender(); InitRender();
ReloadFont(16); ReloadFont(16);
InitLua(); InitLua();
@@ -268,6 +273,11 @@ int main()
String16 string16 = GetString(*lua_buffer); String16 string16 = GetString(*lua_buffer);
String string = ToString(scratch, string16); String string = ToString(scratch, string16);
if (luaL_dostring(LuaState, string.data) == LUA_OK) { if (luaL_dostring(LuaState, string.data) == LUA_OK) {
if (lua_isstring(LuaState, -1)) {
const char *text = lua_tostring(LuaState, -1);
ReportConsolef(text);
lua_pop(LuaState, 1);
}
ReloadColors(); ReloadColors();
} else { } else {
const char *error_message = lua_tostring(LuaState, -1); const char *error_message = lua_tostring(LuaState, -1);
@@ -289,7 +299,6 @@ int main()
View *view = GetView(window->active_view); View *view = GetView(window->active_view);
UpdateScroll(window, !AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && view->update_scroll); UpdateScroll(window, !AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && view->update_scroll);
DrawWindow(window); DrawWindow(window);
} }
EndFrameRender(ColorBackground); EndFrameRender(ColorBackground);

View File

@@ -58,6 +58,7 @@ struct Window {
Array<ViewID> views; Array<ViewID> views;
Rect2I total_rect; Rect2I total_rect;
Rect2I tabs_rect;
Rect2I scrollbar_rect; Rect2I scrollbar_rect;
Rect2I line_numbers_rect; Rect2I line_numbers_rect;
Rect2I document_rect; Rect2I document_rect;
@@ -72,9 +73,10 @@ struct Window {
bool draw_scrollbar : 1; bool draw_scrollbar : 1;
bool draw_line_numbers : 1; bool draw_line_numbers : 1;
bool draw_tabs : 1;
bool visible : 1; bool visible : 1;
bool fuzzy_search : 1; bool fuzzy_search : 1; // @todo: consider moving this to view and introducing view commands
bool execute_line : 1; bool execute_line : 1;
bool invisible_when_inactive : 1; bool invisible_when_inactive : 1;
bool dont_save_in_active_window_history : 1; bool dont_save_in_active_window_history : 1;
@@ -94,6 +96,7 @@ String WorkingDir;
String ConfigDir; String ConfigDir;
String ExeDir; String ExeDir;
Arena Perm; Arena Perm;
float DPIScale = 1.0f;
String16 EvalString(Allocator allocator, String16 string16); String16 EvalString(Allocator allocator, String16 string16);
Rect2I GetVisibleCells(Window *window); Rect2I GetVisibleCells(Window *window);

View File

@@ -1,15 +1,13 @@
- Save file (utf16->utf8) - Save file (utf16->utf8)
- make sure we only save file buffers - make sure we only save file buffers
- resize windows - resize windows
- color the line number with line highlight
- page up and down should also scroll and leave you in exactly same scroll - page up and down should also scroll and leave you in exactly same scroll
- laying out windows, more choice - laying out windows, more choice
- window borders - window borders
- file dock on left side - file dock on left side
- We can actually combine this with command window and lua, it's just going to be a buffer of - We can actually combine this with command window and lua, it's just going to be a buffer of
- open "asd/asd/asd/asd" - open "asd/asd/asd/asd"
- console buffer with output and errors
- some popup for errors
- good error reporting for user
- word completion - word completion
- Colored strings - Colored strings
- open project files in folder and only show open views in Ctrl+P - open project files in folder and only show open views in Ctrl+P

View File

@@ -10,9 +10,10 @@ void InitWindows(View *null_view) {
Allocator sys_allocator = GetSystemAllocator(); Allocator sys_allocator = GetSystemAllocator();
{ {
Window *w = CreateWindow(); Window *w = CreateWindow();
Buffer *b = CreateBuffer(sys_allocator, "*load_text_a*"); w->draw_tabs = true;
View *v = CreateView(b->id); Buffer *b = CreateBuffer(sys_allocator, "*load_text_a*");
View *v = CreateView(b->id);
LoadTextA(b); LoadTextA(b);
LoadUnicode(b); LoadUnicode(b);
AddView(w, null_view->id); AddView(w, null_view->id);
@@ -21,6 +22,7 @@ void InitWindows(View *null_view) {
{ {
Window *w = CreateWindow(); Window *w = CreateWindow();
w->draw_tabs = true;
Buffer *b = CreateBuffer(sys_allocator, "*console*"); Buffer *b = CreateBuffer(sys_allocator, "*console*");
b->no_history = true; b->no_history = true;
View *v = CreateView(b->id); View *v = CreateView(b->id);
@@ -120,6 +122,7 @@ void LayoutWindows() {
int i = 0; int i = 0;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.5)); Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex * 0.5));
Windows[i].document_rect = Windows[i].total_rect; Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_tabs) Windows[i].tabs_rect = CutTop(&Windows[i].document_rect, (Int)FontLineSpacing);
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10); if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size); if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
} }
@@ -127,6 +130,7 @@ void LayoutWindows() {
int i = 1; int i = 1;
Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex)); Windows[i].total_rect = CutLeft(&screen_rect, (Int)((double)sizex));
Windows[i].document_rect = Windows[i].total_rect; Windows[i].document_rect = Windows[i].total_rect;
if (Windows[i].draw_tabs) Windows[i].tabs_rect = CutTop(&Windows[i].document_rect, (Int)FontLineSpacing);
if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10); if (Windows[i].draw_scrollbar) Windows[i].scrollbar_rect = CutRight(&Windows[i].document_rect, 10);
if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size); if (Windows[i].draw_line_numbers) Windows[i].line_numbers_rect = CutLeft(&Windows[i].document_rect, (Int)line_numbers_size);
} }

View File

@@ -93,9 +93,10 @@ void DrawWindow(Window *window) {
View *view = GetActiveView(window); View *view = GetActiveView(window);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
SetScissor(GetScreenRectF()); SetScissor(GetScreenRectF());
DrawRect(window->total_rect, ColorBackground);
bool is_active = IsActive(window) || window->id.id == GetLastActiveWindow().id; bool is_active = IsActive(window) || window->id.id == GetLastActiveWindow().id;
DrawRect(window->total_rect, ColorBackground);
SetScissor(window->document_rect); SetScissor(window->document_rect);
BeginProfileScope(draw_caret_selection); BeginProfileScope(draw_caret_selection);
Rect2I visible = GetVisibleCells(window); Rect2I visible = GetVisibleCells(window);
@@ -197,8 +198,55 @@ void DrawWindow(Window *window) {
DrawRect(rect, color); DrawRect(rect, color);
} }
if (window->draw_tabs) {
Rect2 rect = ToRect2(window->tabs_rect);
SetScissor(rect);
DrawRect(rect, ColorTabBackgroundInactive);
Int open_views = window->views.len;
Vec2 entire_tab_size = GetSize(rect);
Vec2 tab_size = {200 * DPIScale, entire_tab_size.y};
// Vec2 tab_size = {entire_tab_size.x / (float)open_views, };
// float total = entire_tab_size.x / tab_size.x;
float offset = entire_tab_size.x / (float)window->views.len;
offset = ClampTop(tab_size.x, offset);
float i = (float)window->views.len - 1;
For(window->views) {
Rect2 tab_rect = Rect2FromSize({rect.min.x + offset * i, rect.min.y}, tab_size);
i -= 1.f;
Scratch scratch;
View *view = GetView(it);
Buffer *buffer = GetBuffer(view->active_buffer);
String16 string16 = ToString16(scratch, buffer->name);
string16 = SkipToLastSlash(string16);
Vec2 string_size = GetStringSize(&MainFont, string16);
Vec2 pos = {tab_rect.min.x + (tab_size.x - string_size.x) / 2};
pos.y = tab_rect.min.y;
if (window->active_view.id == it.id) {
DrawRect(tab_rect, ColorTabBackground);
} else {
DrawRect(tab_rect, ColorTabBackgroundInactive);
}
DrawString(&MainFont, string16, pos, ColorTabText);
Rect2 sep = CutRight(&tab_rect, 1);
DrawRect(sep, ColorTabSeparator);
sep = CutLeft(&tab_rect, 1);
DrawRect(sep, ColorTabSeparator);
}
Rect2 sep = CutRight(&rect, 1);
DrawRect(sep, ColorTabSeparator);
}
if (!is_active) { if (!is_active) {
SetScissor(GetScreenRectF()); SetScissor(GetScreenRectF());
DrawRect(window->total_rect, {0, 0, 0, 30}); DrawRect(window->total_rect, ColorInactiveWindow);
} }
} }